You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2016/11/10 17:21:24 UTC
camel git commit: CAMEL-10467: camel-servicenow : ServiceNowConstants
not backward-compatible (2.18.0 --> 2.18.1)
Repository: camel
Updated Branches:
refs/heads/camel-2.18.x 629f0815b -> fd41114dd
CAMEL-10467: camel-servicenow : ServiceNowConstants not backward-compatible (2.18.0 --> 2.18.1)
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/fd41114d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/fd41114d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/fd41114d
Branch: refs/heads/camel-2.18.x
Commit: fd41114ddeaf752d809791cdcac2322bc9feec15
Parents: 629f081
Author: lburgazzoli <lb...@gmail.com>
Authored: Thu Nov 10 18:20:20 2016 +0100
Committer: lburgazzoli <lb...@gmail.com>
Committed: Thu Nov 10 18:20:20 2016 +0100
----------------------------------------------------------------------
.../servicenow/ServiceNowConstants.java | 91 ++++++
...viceNowTableWithDeprecatedConstantsTest.java | 323 +++++++++++++++++++
.../ServiceNowTestWithDeprecatedConstants.java | 111 +++++++
3 files changed, 525 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/fd41114d/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
index e699dd7..e5f93c3 100644
--- a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
+++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/ServiceNowConstants.java
@@ -69,6 +69,97 @@ public final class ServiceNowConstants {
public static final String LINK_FIRST = "first";
public static final String LINK_LAST = "last";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.PARAM_TABLE_NAME
+ */
+ public static final String TABLE = "CamelServiceNowTable";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.PARAM_SYS_ID
+ */
+ public static final String SYSPARM_ID = "CamelServiceNowSysId";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_QUERY
+ */
+ public static final String SYSPARM_QUERY = "CamelServiceNowQuery";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_DISPLAY_VALUE
+ */
+ public static final String SYSPARM_DISPLAY_VALUE = "CamelServiceNowDisplayValue";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_INPUT_DISPLAY_VALUE
+ */
+ public static final String SYSPARM_INPUT_DISPLAY_VALUE = "CamelServiceNowInputDisplayValue";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_EXCLUDE_REFERENCE_LINK
+ */
+ public static final String SYSPARM_EXCLUDE_REFERENCE_LINK = "CamelServiceNowExcludeReferenceLink";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_FIELDS
+ */
+ public static final String SYSPARM_FIELDS = "CamelServiceNowFields";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_MIN_FIELDS
+ */
+ public static final String SYSPARM_MIN_FIELDS = "CamelServiceNowMinFields";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_MAX_FIELDS
+ */
+ public static final String SYSPARM_MAX_FIELDS = "CamelServiceNowMaxFields";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_SUM_FIELDS
+ */
+ public static final String SYSPARM_SUM_FIELDS = "CamelServiceNowSumFields";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_AVG_FIELDS
+ */
+ public static final String SYSPARM_AVG_FIELDS = "CamelServiceNowAvgFields";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_LIMIT
+ */
+ public static final String SYSPARM_LIMIT = "CamelServiceNowLimit";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_VIEW
+ */
+ public static final String SYSPARM_VIEW = "CamelServiceNowView";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_SUPPRESS_AUTO_SYS_FIELD
+ */
+ public static final String SYSPARM_SUPPRESS_AUTO_SYS_FIELD = "CamelServiceNowSuppressAutoSysField";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_COUNT
+ */
+ public static final String SYSPARM_COUNT = "CamelServiceNowCount";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_GROUP_BY
+ */
+ public static final String SYSPARM_GROUP_BY = "CamelServiceNowGroupBy";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_ORDER_BY
+ */
+ public static final String SYSPARM_ORDER_BY = "CamelServiceNowOrderBy";
+
+ /**
+ * @deprecated As of release 2.18.1, replaced by ServiceNowParams.SYSPARM_HAVING
+ */
+ public static final String SYSPARM_HAVING = "CamelServiceNowHaving";
+
private ServiceNowConstants() {
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/fd41114d/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTableWithDeprecatedConstantsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTableWithDeprecatedConstantsTest.java b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTableWithDeprecatedConstantsTest.java
new file mode 100644
index 0000000..2f26810
--- /dev/null
+++ b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTableWithDeprecatedConstantsTest.java
@@ -0,0 +1,323 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.camel.component.servicenow;
+
+import java.util.List;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.servicenow.model.Incident;
+import org.junit.Test;
+
+public class ServiceNowTableWithDeprecatedConstantsTest extends ServiceNowTestSupport {
+
+ @Test
+ public void testRetrieveSome() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:servicenow");
+ mock.expectedMessageCount(1);
+
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE)
+ .put(ServiceNowConstants.SYSPARM_LIMIT, "10")
+ .put(ServiceNowConstants.TABLE, "incident")
+ .build()
+ );
+
+ mock.assertIsSatisfied();
+
+ Exchange exchange = mock.getExchanges().get(0);
+ List<Incident> items = exchange.getIn().getBody(List.class);
+
+ assertNotNull(items);
+ assertTrue(items.size() <= 10);
+ }
+
+ @Test
+ public void testRetrieveSomeWithDefaults() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:servicenow-defaults");
+ mock.expectedMessageCount(1);
+
+ template().sendBodyAndHeaders(
+ "direct:servicenow-defaults",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE)
+ .put(ServiceNowConstants.SYSPARM_LIMIT, "10")
+ .build()
+ );
+
+ mock.assertIsSatisfied();
+
+ Exchange exchange = mock.getExchanges().get(0);
+ List<Incident> items = exchange.getIn().getBody(List.class);
+
+ assertNotNull(items);
+ assertTrue(items.size() <= 10);
+ }
+
+ @Test
+ public void testIncidentWorkflow() throws Exception {
+
+ Incident incident = null;
+ String sysId;
+ String number;
+ MockEndpoint mock = getMockEndpoint("mock:servicenow");
+
+ // ************************
+ // Create incident
+ // ************************
+
+ {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ incident = new Incident();
+ incident.setDescription("my incident");
+ incident.setShortDescription("An incident");
+ incident.setSeverity(1);
+ incident.setImpact(1);
+
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ incident,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_CREATE)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .build()
+ );
+
+ mock.assertIsSatisfied();
+
+ incident = mock.getExchanges().get(0).getIn().getBody(Incident.class);
+ sysId = incident.getId();
+ number = incident.getNumber();
+
+ LOGGER.info("****************************************************");
+ LOGGER.info("* Incident created");
+ LOGGER.info("* sysid = {}", sysId);
+ LOGGER.info("* number = {}", number);
+ LOGGER.info("****************************************************");
+ }
+
+ // ************************
+ // Search for the incident
+ // ************************
+
+ {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .put(ServiceNowConstants.SYSPARM_QUERY, "number=" + number)
+ .build()
+ );
+
+ mock.assertIsSatisfied();
+
+ List<Incident> incidents = mock.getExchanges().get(0).getIn().getBody(List.class);
+ assertEquals(1, incidents.size());
+ assertEquals(number, incidents.get(0).getNumber());
+ assertEquals(sysId, incidents.get(0).getId());
+ }
+
+ // ************************
+ // Modify the incident
+ // ************************
+
+ {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ incident = new Incident();
+ incident.setDescription("my incident");
+ incident.setShortDescription("The incident");
+ incident.setSeverity(2);
+ incident.setImpact(3);
+
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ incident,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_MODIFY)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .put(ServiceNowConstants.SYSPARM_ID, sysId)
+ .build()
+ );
+
+ mock.assertIsSatisfied();
+
+ incident = mock.getExchanges().get(0).getIn().getBody(Incident.class);
+ assertEquals(number, incident.getNumber());
+ assertEquals(2, incident.getSeverity());
+ assertEquals(3, incident.getImpact());
+ assertEquals("The incident", incident.getShortDescription());
+ }
+
+ // ************************
+ // Retrieve it via query
+ // ************************
+
+ {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .put(ServiceNowConstants.SYSPARM_QUERY, "number=" + number)
+ .build()
+ );
+
+ mock.assertIsSatisfied();
+
+ List<Incident> incidents = mock.getExchanges().get(0).getIn().getBody(List.class);
+ assertEquals(1, incidents.size());
+ assertEquals(number, incidents.get(0).getNumber());
+ assertEquals(sysId, incidents.get(0).getId());
+ assertEquals(2, incidents.get(0).getSeverity());
+ assertEquals(3, incidents.get(0).getImpact());
+ assertEquals("The incident", incidents.get(0).getShortDescription());
+ }
+
+ // ************************
+ // Retrieve by sys id
+ // ************************
+
+ {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .put(ServiceNowConstants.SYSPARM_ID, sysId)
+ .build()
+ );
+
+ mock.assertIsSatisfied();
+
+ incident = mock.getExchanges().get(0).getIn().getBody(Incident.class);
+ assertEquals(2, incident.getSeverity());
+ assertEquals(3, incident.getImpact());
+ assertEquals("The incident", incident.getShortDescription());
+ assertEquals(number, incident.getNumber());
+ }
+
+ // ************************
+ // Delete it
+ // ************************
+
+ {
+ mock.reset();
+ mock.expectedMessageCount(1);
+
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_DELETE)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .put(ServiceNowConstants.SYSPARM_ID, sysId)
+ .build()
+ );
+
+ mock.assertIsSatisfied();
+ }
+
+ // ************************
+ // Retrieve by id, should fail
+ // ************************
+
+ {
+ LOGGER.info("Find the record {}, should fail", sysId);
+
+ try {
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE)
+ .put(ServiceNowConstants.SYSPARM_ID, sysId)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .build()
+ );
+
+ fail("Record " + number + " should have been deleted");
+ } catch (CamelExecutionException e) {
+ assertTrue(e.getCause() instanceof ServiceNowException);
+ // we are good
+ }
+ }
+ }
+
+ // *************************************************************************
+ //
+ // *************************************************************************
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:servicenow")
+ .to("servicenow:{{env:SERVICENOW_INSTANCE}}"
+ + "?userName={{env:SERVICENOW_USERNAME}}"
+ + "&password={{env:SERVICENOW_PASSWORD}}"
+ //+ "&oauthClientId={{env:SERVICENOW_OAUTH2_CLIENT_ID}}"
+ //+ "&oauthClientSecret={{env:SERVICENOW_OAUTH2_CLIENT_SECRET}}"
+ + "&model.incident=org.apache.camel.component.servicenow.model.Incident")
+ .to("log:org.apache.camel.component.servicenow?level=INFO&showAll=true")
+ .to("mock:servicenow");
+ from("direct:servicenow-defaults")
+ .to("servicenow:{{env:SERVICENOW_INSTANCE}}"
+ + "?userName={{env:SERVICENOW_USERNAME}}"
+ + "&password={{env:SERVICENOW_PASSWORD}}"
+ //+ "&oauthClientId={{env:SERVICENOW_OAUTH2_CLIENT_ID}}"
+ //+ "&oauthClientSecret={{env:SERVICENOW_OAUTH2_CLIENT_SECRET}}"
+ + "&model.incident=org.apache.camel.component.servicenow.model.Incident"
+ + "&resource=table"
+ + "&table=incident")
+ .to("log:org.apache.camel.component.servicenow?level=INFO&showAll=true")
+ .to("mock:servicenow-defaults");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/fd41114d/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTestWithDeprecatedConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTestWithDeprecatedConstants.java b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTestWithDeprecatedConstants.java
new file mode 100644
index 0000000..793bdf0
--- /dev/null
+++ b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTestWithDeprecatedConstants.java
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.servicenow;
+
+import java.util.UUID;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class ServiceNowTestWithDeprecatedConstants extends ServiceNowTestSupport {
+
+ @Test
+ public void testExceptions() throws Exception {
+ // 404
+ try {
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE)
+ .put(ServiceNowConstants.SYSPARM_QUERY, "number=" + UUID.randomUUID().toString())
+ .put(ServiceNowConstants.TABLE, "incident")
+ .build()
+ );
+ } catch (CamelExecutionException e) {
+ assertTrue(e.getCause() instanceof ServiceNowException);
+
+ ServiceNowException sne = (ServiceNowException)e.getCause();
+ assertEquals("failure", sne.getStatus());
+ assertTrue(sne.getMessage().contains("No Record found"));
+ assertTrue(sne.getDetail().contains("Records matching query not found"));
+ }
+
+ // 400
+ try {
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ null,
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE)
+ .put(ServiceNowConstants.SYSPARM_QUERY, "number=" + UUID.randomUUID().toString())
+ .put(ServiceNowConstants.TABLE, "notExistingTable")
+ .build()
+ );
+ } catch (CamelExecutionException e) {
+ assertTrue(e.getCause() instanceof ServiceNowException);
+
+ ServiceNowException sne = (ServiceNowException)e.getCause();
+ assertEquals("failure", sne.getStatus());
+ assertTrue(sne.getMessage().contains("Invalid table notExistingTable"));
+ assertNull(sne.getDetail());
+ }
+ }
+
+ @Test
+ public void testBodyMismatch() throws Exception {
+ try {
+ template().sendBodyAndHeaders(
+ "direct:servicenow",
+ "NotAnIncidentObject",
+ new KVBuilder()
+ .put(ServiceNowConstants.RESOURCE, "table")
+ .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_CREATE)
+ .put(ServiceNowConstants.TABLE, "incident")
+ .build()
+ );
+
+ fail("Should fail as body is not compatible with model defined in route for table incident");
+ } catch (CamelExecutionException e) {
+ assertTrue(e.getCause() instanceof IllegalArgumentException);
+ }
+ }
+
+ // *************************************************************************
+ //
+ // *************************************************************************
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:servicenow")
+ .to("servicenow:{{env:SERVICENOW_INSTANCE}}"
+ + "?userName={{env:SERVICENOW_USERNAME}}"
+ + "&password={{env:SERVICENOW_PASSWORD}}"
+ //+ "&oauthClientId={{env:SERVICENOW_OAUTH2_CLIENT_ID}}"
+ //+ "&oauthClientSecret={{env:SERVICENOW_OAUTH2_CLIENT_SECRET}}"
+ + "&model.incident=org.apache.camel.component.servicenow.model.Incident")
+ .to("log:org.apache.camel.component.servicenow?level=INFO&showAll=true")
+ .to("mock:servicenow");
+ }
+ };
+ }
+}