Repository: camel
Updated Branches:
  refs/heads/master e37135fbc -> e821b56ec


ServiceNow: simplify the json-schema and allow to customize date/time format


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/e821b56e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/e821b56e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/e821b56e

Branch: refs/heads/master
Commit: e821b56ec311c7600eb72ea6d372f074846c5442
Parents: e37135f
Author: lburgazzoli <lburgazz...@gmail.com>
Authored: Sun Aug 6 10:14:32 2017 +0200
Committer: lburgazzoli <lburgazz...@gmail.com>
Committed: Sun Aug 6 10:14:32 2017 +0200

----------------------------------------------------------------------
 .../servicenow/ServiceNowConstants.java         |  2 +-
 .../servicenow/ServiceNowMetaDataExtension.java |  2 +-
 .../ServiceNowMetaDataExtensionTest.java        | 87 ++------------------
 .../component/servicenow/ServiceNowTest.java    | 82 ++++++++++++++++++
 4 files changed, 90 insertions(+), 83 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e821b56e/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
----------------------------------------------------------------------
diff --git 
a/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
 
b/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
index e2272ec..955f389 100644
--- 
a/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
+++ 
b/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
@@ -39,7 +39,7 @@ public final class ServiceNowConstants {
 
     public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
     public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss";
-    public static final String DEFAULT_DATE_TIME_FORMAT = "yyyy-MM-dd 
HH:mm:ss";
+    public static final String DEFAULT_DATE_TIME_FORMAT = DEFAULT_DATE_FORMAT 
+ " " + DEFAULT_TIME_FORMAT;
 
     public static final String ATTACHMENT_META_HEADER = 
"X-Attachment-Metadata";
 

http://git-wip-us.apache.org/repos/asf/camel/blob/e821b56e/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtension.java
----------------------------------------------------------------------
diff --git 
a/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtension.java
 
b/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtension.java
index d910d24..9b40df4 100644
--- 
a/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtension.java
+++ 
b/components/camel-servicenow/camel-servicenow-component/src/main/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtension.java
@@ -91,7 +91,7 @@ final class ServiceNowMetaDataExtension extends 
AbstractMetaDataExtension {
             }
 
             // Schema
-            root.put("$schema", "http://json-schema.org/draft-04/schema#";);
+            root.put("$schema", "http://json-schema.org/schema#";);
             root.put("id", String.format("urn:jsonschema:%s:%s)", baseUrn, 
context.getObjectName()));
             root.put("type", "object");
             root.put("additionalProperties", false);

http://git-wip-us.apache.org/repos/asf/camel/blob/e821b56e/components/camel-servicenow/camel-servicenow-component/src/test/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtensionTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-servicenow/camel-servicenow-component/src/test/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtensionTest.java
 
b/components/camel-servicenow/camel-servicenow-component/src/test/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtensionTest.java
index bdf7049..9e5b0c9 100644
--- 
a/components/camel-servicenow/camel-servicenow-component/src/test/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtensionTest.java
+++ 
b/components/camel-servicenow/camel-servicenow-component/src/test/java/org/apache/camel/component/servicenow/ServiceNowMetaDataExtensionTest.java
@@ -16,10 +16,6 @@
  */
 package org.apache.camel.component.servicenow;
 
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.temporal.ChronoUnit;
 import java.util.Map;
 
 import com.fasterxml.jackson.databind.JsonNode;
@@ -71,7 +67,12 @@ public class ServiceNowMetaDataExtensionTest extends 
ServiceNowTestSupport {
         Assert.assertNotNull(result.getAttribute("time.format"));
         Assert.assertNotNull(result.getAttribute("date-time.format"));
         Assert.assertEquals(JsonNode.class, 
result.getAttribute(MetaDataExtension.MetaData.JAVA_TYPE));
-        
Assert.assertTrue(result.getPayload(JsonNode.class).hasNonNull("properties"));
+        Assert.assertNotNull(result.getPayload(JsonNode.class));
+        
Assert.assertNotNull(result.getPayload(JsonNode.class).get("properties"));
+        Assert.assertNotNull(result.getPayload(JsonNode.class).get("$schema"));
+        Assert.assertEquals("http://json-schema.org/schema#";, 
result.getPayload(JsonNode.class).get("$schema").asText());
+        Assert.assertNotNull(result.getPayload(JsonNode.class).get("id"));
+        Assert.assertNotNull(result.getPayload(JsonNode.class).get("type"));
 
         LOGGER.debug(
             new 
ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(result.getPayload())
@@ -86,80 +87,4 @@ public class ServiceNowMetaDataExtensionTest extends 
ServiceNowTestSupport {
 
         getExtension().meta(parameters);
     }
-
-    // *********************************
-    // Date/Time
-    // *********************************
-
-    @Test
-    public void testDateTimeWithDefaults() throws Exception {
-        final ServiceNowConfiguration configuration = new 
ServiceNowConfiguration();
-
-        ObjectMapper mapper = configuration.getOrCreateMapper();
-        DateTimeBean bean = new DateTimeBean();
-        String serialized = mapper.writeValueAsString(bean);
-
-        LOGGER.debug(serialized);
-
-        DateTimeBean deserialized = mapper.readValue(serialized, 
DateTimeBean.class);
-
-        Assert.assertEquals(bean.dateTime, deserialized.dateTime);
-        Assert.assertEquals(bean.date, deserialized.date);
-        Assert.assertEquals(bean.time, deserialized.time);
-    }
-
-    @Test
-    public void testDateTimeWithCustomFormats() throws Exception {
-        final ServiceNowConfiguration configuration = new 
ServiceNowConfiguration();
-        configuration.setDateFormat("yyyyMMdd");
-        configuration.setTimeFormat("HHmmss");
-
-        ObjectMapper mapper = configuration.getOrCreateMapper();
-        DateTimeBean bean = new DateTimeBean();
-        String serialized = mapper.writeValueAsString(bean);
-
-        LOGGER.debug(serialized);
-
-        DateTimeBean deserialized = mapper.readValue(serialized, 
DateTimeBean.class);
-
-        Assert.assertEquals(bean.dateTime, deserialized.dateTime);
-        Assert.assertEquals(bean.date, deserialized.date);
-        Assert.assertEquals(bean.time, deserialized.time);
-    }
-
-    public static class DateTimeBean {
-        LocalDateTime dateTime;
-        LocalDate date;
-        LocalTime time;
-
-        public DateTimeBean() {
-            dateTime = LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS);
-            date = dateTime.toLocalDate();
-            time = dateTime.toLocalTime();
-        }
-
-        public LocalDateTime getDateTime() {
-            return dateTime;
-        }
-
-        public void setDateTime(LocalDateTime dateTime) {
-            this.dateTime = dateTime;
-        }
-
-        public LocalDate getDate() {
-            return date;
-        }
-
-        public void setDate(LocalDate date) {
-            this.date = date;
-        }
-
-        public LocalTime getTime() {
-            return time;
-        }
-
-        public void setTime(LocalTime time) {
-            this.time = time;
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/e821b56e/components/camel-servicenow/camel-servicenow-component/src/test/java/org/apache/camel/component/servicenow/ServiceNowTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-servicenow/camel-servicenow-component/src/test/java/org/apache/camel/component/servicenow/ServiceNowTest.java
 
b/components/camel-servicenow/camel-servicenow-component/src/test/java/org/apache/camel/component/servicenow/ServiceNowTest.java
index 426a8bfa..fc46ce3 100644
--- 
a/components/camel-servicenow/camel-servicenow-component/src/test/java/org/apache/camel/component/servicenow/ServiceNowTest.java
+++ 
b/components/camel-servicenow/camel-servicenow-component/src/test/java/org/apache/camel/component/servicenow/ServiceNowTest.java
@@ -16,13 +16,19 @@
  */
 package org.apache.camel.component.servicenow;
 
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.temporal.ChronoUnit;
 import java.util.UUID;
 
 import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.camel.CamelExecutionException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.component.servicenow.model.Incident;
+import org.junit.Assert;
 import org.junit.Test;
 
 public class ServiceNowTest extends ServiceNowTestSupport {
@@ -156,6 +162,82 @@ public class ServiceNowTest extends ServiceNowTestSupport {
         assertTrue(body instanceof JsonNode);
     }
 
+    // *********************************
+    // Date/Time
+    // *********************************
+
+    @Test
+    public void testDateTimeWithDefaults() throws Exception {
+        final ServiceNowConfiguration configuration = new 
ServiceNowConfiguration();
+
+        ObjectMapper mapper = configuration.getOrCreateMapper();
+        DateTimeBean bean = new DateTimeBean();
+        String serialized = mapper.writeValueAsString(bean);
+
+        LOGGER.debug(serialized);
+
+        DateTimeBean deserialized = mapper.readValue(serialized, 
DateTimeBean.class);
+
+        Assert.assertEquals(bean.dateTime, deserialized.dateTime);
+        Assert.assertEquals(bean.date, deserialized.date);
+        Assert.assertEquals(bean.time, deserialized.time);
+    }
+
+    @Test
+    public void testDateTimeWithCustomFormats() throws Exception {
+        final ServiceNowConfiguration configuration = new 
ServiceNowConfiguration();
+        configuration.setDateFormat("yyyyMMdd");
+        configuration.setTimeFormat("HHmmss");
+
+        ObjectMapper mapper = configuration.getOrCreateMapper();
+        DateTimeBean bean = new DateTimeBean();
+        String serialized = mapper.writeValueAsString(bean);
+
+        LOGGER.debug(serialized);
+
+        DateTimeBean deserialized = mapper.readValue(serialized, 
DateTimeBean.class);
+
+        Assert.assertEquals(bean.dateTime, deserialized.dateTime);
+        Assert.assertEquals(bean.date, deserialized.date);
+        Assert.assertEquals(bean.time, deserialized.time);
+    }
+
+    public static class DateTimeBean {
+        LocalDateTime dateTime;
+        LocalDate date;
+        LocalTime time;
+
+        public DateTimeBean() {
+            dateTime = LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS);
+            date = dateTime.toLocalDate();
+            time = dateTime.toLocalTime();
+        }
+
+        public LocalDateTime getDateTime() {
+            return dateTime;
+        }
+
+        public void setDateTime(LocalDateTime dateTime) {
+            this.dateTime = dateTime;
+        }
+
+        public LocalDate getDate() {
+            return date;
+        }
+
+        public void setDate(LocalDate date) {
+            this.date = date;
+        }
+
+        public LocalTime getTime() {
+            return time;
+        }
+
+        public void setTime(LocalTime time) {
+            this.time = time;
+        }
+    }
+
     // 
*************************************************************************
     //
     // 
*************************************************************************

Reply via email to