Repository: camel Updated Branches: refs/heads/camel-2.18.x 9916ee431 -> fa1789a36
http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogCategoriesProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogCategoriesProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogCategoriesProcessor.java new file mode 100644 index 0000000..aa361dc --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogCategoriesProcessor.java @@ -0,0 +1,66 @@ +/** + * 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.releases.helsinki; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.component.servicenow.AbstractServiceNowProcessor; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.component.servicenow.ServiceNowParams; +import org.apache.camel.util.ObjectHelper; + +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_RETRIEVE; + +class HelsinkiServiceNowServiceCatalogCategoriesProcessor extends AbstractServiceNowProcessor { + + HelsinkiServiceNowServiceCatalogCategoriesProcessor(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint); + + addDispatcher(ACTION_RETRIEVE, this::retrieveCategory); + } + + /* + * This method retrieves all the information about a requested category. + * + * Method: + * - GET + * + * URL Format: + * - /sn_sc/servicecatalog/categories/{sys_id} + */ + private void retrieveCategory(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("servicecatalog") + .path("categories") + .path(ObjectHelper.notNull(sysId, "sysId")) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke(HttpMethod.GET); + + setBodyAndHeaders(in, model, response); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogItemsProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogItemsProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogItemsProcessor.java new file mode 100644 index 0000000..106f38d --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogItemsProcessor.java @@ -0,0 +1,199 @@ +/** + * 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.releases.helsinki; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.component.servicenow.AbstractServiceNowProcessor; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.component.servicenow.ServiceNowParams; +import org.apache.camel.util.ObjectHelper; + +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_CREATE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_RETRIEVE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_SUBJECT_CART; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_SUBJECT_CHECKOUT_GUIDE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_SUBJECT_PRODUCER; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_SUBJECT_SUBMIT_GUIDE; + +class HelsinkiServiceNowServiceCatalogItemsProcessor extends AbstractServiceNowProcessor { + + HelsinkiServiceNowServiceCatalogItemsProcessor(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint); + + addDispatcher(ACTION_RETRIEVE, ACTION_SUBJECT_SUBMIT_GUIDE, this::submitItemGuide); + addDispatcher(ACTION_RETRIEVE, ACTION_SUBJECT_CHECKOUT_GUIDE, this::checkoutItemGuide); + addDispatcher(ACTION_RETRIEVE, this::retrieveItems); + addDispatcher(ACTION_CREATE, ACTION_SUBJECT_CART, this::addItemToCart); + addDispatcher(ACTION_CREATE, ACTION_SUBJECT_PRODUCER, this::submitItemProducer); + } + + /* + * This method retrieves a list of catalogs to which the user has access or + * a single one if sys_id is defined. + * + * Method: + * - GET + * + * URL Format: + * - /sn_sc/servicecatalog/items + * - /sn_sc/servicecatalog/items/{sys_id} + */ + private void retrieveItems(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + Response response = ObjectHelper.isEmpty(sysId) + ? client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("servicecatalog") + .path("items") + .query(ServiceNowParams.SYSPARM_CATEGORY, in) + .query(ServiceNowParams.SYSPARM_TYPE, in) + .query(ServiceNowParams.SYSPARM_LIMIT, in) + .query(ServiceNowParams.SYSPARM_TEXT, in) + .query(ServiceNowParams.SYSPARM_OFFSET, in) + .query(ServiceNowParams.SYSPARM_CATALOG, in) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke(HttpMethod.GET) + : client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("items") + .path("items") + .path(sysId) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke(HttpMethod.GET); + + setBodyAndHeaders(in, model, response); + } + + /* + * This method retrieves a list of items based on the needs described for an + * order guide. + * + * Method: + * - POST + * + * URL Format: + * - /sn_sc/servicecatalog/items/{sys_id}/submit_guide + */ + private void submitItemGuide(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("servicecatalog") + .path("items") + .path(ObjectHelper.notNull(sysId, "sysId")) + .path("submit_guide") + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke(HttpMethod.POST, in.getMandatoryBody()); + + setBodyAndHeaders(in, model, response); + } + + /* + * This method retrieves an array of contents requested for checkout. + * + * Method: + * - POST + * + * URL Format: + * - /sn_sc/servicecatalog/items/{sys_id}/checkout_guide + */ + private void checkoutItemGuide(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("servicecatalog") + .path("items") + .path(ObjectHelper.notNull(sysId, "sysId")) + .path("submit_guide") + .invoke(HttpMethod.POST, in.getMandatoryBody()); + + setBodyAndHeaders(in, model, response); + } + + /* + * This method adds an item to the cart of the current user. + * + * Method: + * - POST + * + * URL Format: + * - /sn_sc/servicecatalog/items/{sys_id}/add_to_cart + */ + private void addItemToCart(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("servicecatalog") + .path("items") + .path(ObjectHelper.notNull(sysId, "sysId")) + .path("add_to_cart") + .invoke(HttpMethod.POST); + + setBodyAndHeaders(in, model, response); + } + + /* + * This method creates a record and returns the Table API relative path and + * redirect url to access the created record. + * + * Method: + * - POST + * + * URL Format: + * - /sn_sc/servicecatalog/items/{sys_id}/submit_producer + */ + private void submitItemProducer(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("servicecatalog") + .path("items") + .path(ObjectHelper.notNull(sysId, "sysId")) + .path("submit_producer") + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke(HttpMethod.POST, in.getMandatoryBody()); + + setBodyAndHeaders(in, model, response); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogProcessor.java new file mode 100644 index 0000000..152b71f --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowServiceCatalogProcessor.java @@ -0,0 +1,110 @@ +/** + * 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.releases.helsinki; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.component.servicenow.AbstractServiceNowProcessor; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.component.servicenow.ServiceNowParams; +import org.apache.camel.util.ObjectHelper; + +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_RETRIEVE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_SUBJECT_CATEGORIES; + +class HelsinkiServiceNowServiceCatalogProcessor extends AbstractServiceNowProcessor { + + HelsinkiServiceNowServiceCatalogProcessor(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint); + + addDispatcher(ACTION_RETRIEVE, ACTION_SUBJECT_CATEGORIES, this::retrieveCatalogsCategories); + addDispatcher(ACTION_RETRIEVE, this::retrieveCatalogs); + } + + /* + * This method retrieves a list of catalogs to which the user has access or + * a single one if sys_id is defined. + * + * Method: + * - GET + * + * URL Format: + * - /sn_sc/servicecatalog/catalogs + * - /sn_sc/servicecatalog/catalogs/{sys_id} + */ + private void retrieveCatalogs(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + Response response = ObjectHelper.isEmpty(sysId) + ? client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("servicecatalog") + .path("catalogs") + .query(ServiceNowParams.SYSPARM_LIMIT, in) + .query(ServiceNowParams.SYSPARM_QUERY, in) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke(HttpMethod.GET) + : client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("servicecatalog") + .path("catalogs") + .path(sysId) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke(HttpMethod.GET); + + setBodyAndHeaders(in, model, response); + } + + /* + * This method retrieves a list of categories for a catalog. + * + * Method: + * - GET + * + * URL Format: + * - /sn_sc/servicecatalog/catalogs/{sys_id}/categories + */ + private void retrieveCatalogsCategories(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final Class<?> model = getModel(in); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("sn_sc") + .path("servicecatalog") + .path("catalogs") + .path(ObjectHelper.notNull(sysId, "sysId")) + .path("categories") + .query(ServiceNowParams.SYSPARM_TOP_LEVEL_ONLY, in) + .query(ServiceNowParams.SYSPARM_LIMIT, in) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .query(ServiceNowParams.SYSPARM_OFFSET, in) + .invoke(HttpMethod.GET); + + setBodyAndHeaders(in, model, response); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowTableProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowTableProcessor.java b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowTableProcessor.java new file mode 100644 index 0000000..ee912ae --- /dev/null +++ b/components/camel-servicenow/src/main/java/org/apache/camel/component/servicenow/releases/helsinki/HelsinkiServiceNowTableProcessor.java @@ -0,0 +1,191 @@ +/** + * 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.releases.helsinki; + +import javax.ws.rs.HttpMethod; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.component.servicenow.AbstractServiceNowProcessor; +import org.apache.camel.component.servicenow.ServiceNowEndpoint; +import org.apache.camel.component.servicenow.ServiceNowParams; +import org.apache.camel.util.ObjectHelper; + +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_CREATE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_DELETE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_MODIFY; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_RETRIEVE; +import static org.apache.camel.component.servicenow.ServiceNowConstants.ACTION_UPDATE; + +class HelsinkiServiceNowTableProcessor extends AbstractServiceNowProcessor { + HelsinkiServiceNowTableProcessor(ServiceNowEndpoint endpoint) throws Exception { + super(endpoint); + + addDispatcher(ACTION_RETRIEVE, this::retrieveRecord); + addDispatcher(ACTION_CREATE, this::createRecord); + addDispatcher(ACTION_MODIFY, this::modifyRecord); + addDispatcher(ACTION_DELETE, this::deleteRecord); + addDispatcher(ACTION_UPDATE, this::updateRecord); + } + + /* + * GET + * https://instance.service-now.com/api/now/table/{tableName} + * https://instance.service-now.com/api/now/table/{tableName}/{sys_id} + */ + private void retrieveRecord(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final String tableName = in.getHeader(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), config.getTable(), String.class); + final Class<?> model = getModel(in, tableName); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + Response response = ObjectHelper.isEmpty(sysId) + ? client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("table") + .path(tableName) + .query(ServiceNowParams.SYSPARM_QUERY, in) + .query(ServiceNowParams.SYSPARM_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_EXCLUDE_REFERENCE_LINK, in) + .query(ServiceNowParams.SYSPARM_SUPPRESS_PAGINATION_HEADER, in) + .query(ServiceNowParams.SYSPARM_FIELDS, in) + .query(ServiceNowParams.SYSPARM_LIMIT, in) + .query(ServiceNowParams.SYSPARM_OFFSET, in) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke(HttpMethod.GET) + : client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("table") + .path(tableName) + .path(sysId) + .query(ServiceNowParams.SYSPARM_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_EXCLUDE_REFERENCE_LINK, in) + .query(ServiceNowParams.SYSPARM_FIELDS, in) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke(HttpMethod.GET); + + setBodyAndHeaders(exchange.getIn(), model, response); + } + + /* + * POST + * https://instance.service-now.com/api/now/table/{tableName} + */ + private void createRecord(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final String tableName = in.getHeader(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), config.getTable(), String.class); + final Class<?> model = getModel(in, tableName); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + validateBody(in, model); + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("table") + .path(tableName) + .query(ServiceNowParams.SYSPARM_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_EXCLUDE_REFERENCE_LINK, in) + .query(ServiceNowParams.SYSPARM_FIELDS, in) + .query(ServiceNowParams.SYSPARM_INPUT_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_SUPPRESS_AUTO_SYS_FIELD, in) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke(HttpMethod.POST, in.getMandatoryBody()); + + setBodyAndHeaders(exchange.getIn(), model, response); + } + + /* + * PUT + * https://instance.service-now.com/api/now/table/{tableName}/{sys_id} + */ + private void modifyRecord(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final String tableName = in.getHeader(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), config.getTable(), String.class); + final Class<?> model = getModel(in, tableName); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + validateBody(in, model); + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("table") + .path(tableName) + .path(ObjectHelper.notNull(sysId, "sysId")) + .query(ServiceNowParams.SYSPARM_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_EXCLUDE_REFERENCE_LINK, in) + .query(ServiceNowParams.SYSPARM_FIELDS, in) + .query(ServiceNowParams.SYSPARM_INPUT_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_SUPPRESS_AUTO_SYS_FIELD, in) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke(HttpMethod.PUT, in.getMandatoryBody()); + + setBodyAndHeaders(exchange.getIn(), model, response); + } + + /* + * DELETE + * https://instance.service-now.com/api/now/table/{tableName}/{sys_id} + */ + private void deleteRecord(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final String tableName = in.getHeader(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), config.getTable(), String.class); + final Class<?> model = getModel(in, tableName); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("table") + .path(tableName) + .path(ObjectHelper.notNull(sysId, "sysId")) + .invoke(HttpMethod.DELETE, null); + + setBodyAndHeaders(exchange.getIn(), model, response); + } + + /* + * PATCH + * instance://instance.service-now.com/api/now/table/{tableName}/{sys_id} + */ + private void updateRecord(Exchange exchange) throws Exception { + final Message in = exchange.getIn(); + final String tableName = in.getHeader(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), config.getTable(), String.class); + final Class<?> model = getModel(in, tableName); + final String sysId = in.getHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), String.class); + + validateBody(in, model); + Response response = client.reset() + .types(MediaType.APPLICATION_JSON_TYPE) + .path("now") + .path("table") + .path(tableName) + .path(ObjectHelper.notNull(sysId, "sysId")) + .query(ServiceNowParams.SYSPARM_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_EXCLUDE_REFERENCE_LINK, in) + .query(ServiceNowParams.SYSPARM_FIELDS, in) + .query(ServiceNowParams.SYSPARM_INPUT_DISPLAY_VALUE, in) + .query(ServiceNowParams.SYSPARM_SUPPRESS_AUTO_SYS_FIELD, in) + .query(ServiceNowParams.SYSPARM_VIEW, in) + .invoke("PATCH", in.getMandatoryBody()); + + setBodyAndHeaders(exchange.getIn(), model, response); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowAttachmentTest.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowAttachmentTest.java b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowAttachmentTest.java new file mode 100644 index 0000000..19f140f --- /dev/null +++ b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowAttachmentTest.java @@ -0,0 +1,133 @@ +/** + * 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.io.InputStream; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.camel.Exchange; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.servicenow.model.AttachmentMeta; +import org.junit.Test; + +import static org.apache.camel.util.ResourceHelper.resolveResourceAsInputStream; + +public class ServiceNowAttachmentTest extends ServiceNowTestSupport { + @Produce(uri = "direct:servicenow") + ProducerTemplate template; + + @Test + public void testAttachment() throws Exception { + List<AttachmentMeta> attachmentMetaList = template.requestBodyAndHeaders( + "direct:servicenow", + null, + new KVBuilder() + .put(ServiceNowConstants.RESOURCE, ServiceNowConstants.RESOURCE_ATTACHMENT) + .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE) + .put(ServiceNowConstants.MODEL, AttachmentMeta.class) + .put(ServiceNowParams.SYSPARM_QUERY, "content_type=application/octet-stream") + .put(ServiceNowParams.SYSPARM_LIMIT, 1) + .build(), + List.class + ); + + assertFalse(attachmentMetaList.isEmpty()); + + Exchange getExistingResult = template.send( + "direct:servicenow", + e -> { + e.getIn().setHeader(ServiceNowConstants.RESOURCE, ServiceNowConstants.RESOURCE_ATTACHMENT); + e.getIn().setHeader(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_CONTENT); + e.getIn().setHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), attachmentMetaList.get(0).getId()); + } + ); + + assertNotNull(getExistingResult.getIn().getHeader(ServiceNowConstants.CONTENT_META)); + assertNotNull(getExistingResult.getIn().getBody()); + assertTrue(getExistingResult.getIn().getBody() instanceof InputStream); + + Map<String, String> contentMeta = getExistingResult.getIn().getHeader(ServiceNowConstants.CONTENT_META, Map.class); + assertEquals(contentMeta.get("file_name"), attachmentMetaList.get(0).getFileName()); + assertEquals(contentMeta.get("table_name"), attachmentMetaList.get(0).getTableName()); + assertEquals(contentMeta.get("sys_id"), attachmentMetaList.get(0).getId()); + + Exchange putResult = template.send( + "direct:servicenow", + e -> { + e.getIn().setHeader(ServiceNowConstants.RESOURCE, ServiceNowConstants.RESOURCE_ATTACHMENT); + e.getIn().setHeader(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_UPLOAD); + e.getIn().setHeader(ServiceNowConstants.MODEL, AttachmentMeta.class); + e.getIn().setHeader(ServiceNowConstants.CONTENT_TYPE, "application/octet-stream"); + e.getIn().setHeader(ServiceNowParams.PARAM_FILE_NAME.getHeader(), UUID.randomUUID().toString()); + e.getIn().setHeader(ServiceNowParams.PARAM_TABLE_NAME.getHeader(), attachmentMetaList.get(0).getTableName()); + e.getIn().setHeader(ServiceNowParams.PARAM_TABLE_SYS_ID.getHeader(), attachmentMetaList.get(0).getTableSysId()); + e.getIn().setBody(resolveResourceAsInputStream(e.getContext().getClassResolver(), "classpath:my-content.txt")); + } + ); + + Exchange getCreatedResult = template.send( + "direct:servicenow", + e -> { + e.getIn().setHeader(ServiceNowConstants.RESOURCE, ServiceNowConstants.RESOURCE_ATTACHMENT); + e.getIn().setHeader(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_CONTENT); + e.getIn().setHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), putResult.getIn().getBody(AttachmentMeta.class).getId()); + } + ); + + assertNotNull(getCreatedResult.getIn().getHeader(ServiceNowConstants.CONTENT_META)); + assertNotNull(getCreatedResult.getIn().getBody()); + assertTrue(getCreatedResult.getIn().getBody() instanceof InputStream); + + Exchange deleteResult = template.send( + "direct:servicenow", + e -> { + e.getIn().setHeader(ServiceNowConstants.RESOURCE, ServiceNowConstants.RESOURCE_ATTACHMENT); + e.getIn().setHeader(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_DELETE); + e.getIn().setHeader(ServiceNowParams.PARAM_SYS_ID.getHeader(), putResult.getIn().getBody(AttachmentMeta.class).getId()); + } + ); + + if (deleteResult.getException() != null) { + throw deleteResult.getException(); + } + } + + // ************************************************************************* + // + // ************************************************************************* + + @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}}") + .to("log:org.apache.camel.component.servicenow?level=INFO&showAll=true") + .to("mock:servicenow"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowScorecardTest.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowScorecardTest.java b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowScorecardTest.java new file mode 100644 index 0000000..abacc24 --- /dev/null +++ b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowScorecardTest.java @@ -0,0 +1,67 @@ +/** + * 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.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.servicenow.model.Scorecard; +import org.junit.Test; + +public class ServiceNowScorecardTest extends ServiceNowTestSupport { + @Produce(uri = "direct:servicenow") + ProducerTemplate template; + + @Test + public void testScorecard() throws Exception { + List<Scorecard> scorecardList = template.requestBodyAndHeaders( + "direct:servicenow", + null, + new KVBuilder() + .put(ServiceNowConstants.RESOURCE, ServiceNowConstants.RESOURCE_SCORECARDS) + .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE) + .put(ServiceNowConstants.ACTION_SUBJECT, ServiceNowConstants.ACTION_SUBJECT_PERFORMANCE_ANALYTICS) + .put(ServiceNowConstants.MODEL, Scorecard.class) + .build(), + List.class + ); + + assertFalse(scorecardList.isEmpty()); + } + + // ************************************************************************* + // + // ************************************************************************* + + @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}}") + .to("log:org.apache.camel.component.servicenow?level=INFO&showAll=true") + .to("mock:servicenow"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowServiceCatalogTest.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowServiceCatalogTest.java b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowServiceCatalogTest.java new file mode 100644 index 0000000..e605a86 --- /dev/null +++ b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowServiceCatalogTest.java @@ -0,0 +1,97 @@ +/** + * 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 java.util.Map; + +import org.apache.camel.CamelExecutionException; +import org.apache.camel.Produce; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.junit.Test; + +public class ServiceNowServiceCatalogTest extends ServiceNowTestSupport { + @Produce(uri = "direct:servicenow") + ProducerTemplate template; + + @Test + public void testRetrieveServiceCatalogsAndCategories() throws Exception { + List<Map> result1 = template.requestBodyAndHeaders( + "direct:servicenow", + null, + new KVBuilder() + .put(ServiceNowConstants.RESOURCE, ServiceNowConstants.RESOURCE_SERVICE_CATALOG) + .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE) + .build(), + List.class + ); + + assertFalse(result1.isEmpty()); + + List<Map> result2 = template.requestBodyAndHeaders( + "direct:servicenow", + null, + new KVBuilder() + .put(ServiceNowConstants.RESOURCE, ServiceNowConstants.RESOURCE_SERVICE_CATALOG) + .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE) + .put(ServiceNowConstants.ACTION_SUBJECT, ServiceNowConstants.ACTION_SUBJECT_CATEGORIES) + .put(ServiceNowParams.PARAM_SYS_ID, result1.get(0).get("sys_id")) + .build(), + List.class + ); + + assertFalse(result2.isEmpty()); + } + + @Test(expected = CamelExecutionException.class) + public void testWrongSubject() throws Exception { + List<Map> result = template.requestBodyAndHeaders( + "direct:servicenow", + null, + new KVBuilder() + .put(ServiceNowConstants.RESOURCE, ServiceNowConstants.RESOURCE_SERVICE_CATALOG) + .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE) + .put(ServiceNowConstants.ACTION_SUBJECT, "Invalid") + .build(), + List.class + ); + + assertFalse(result.isEmpty()); + } + + // ************************************************************************* + // + // ************************************************************************* + + @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}}") + .to("log:org.apache.camel.component.servicenow?level=INFO&showAll=true") + .to("mock:servicenow"); + } + }; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTableTest.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTableTest.java b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTableTest.java index 5075511..4697750 100644 --- a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTableTest.java +++ b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTableTest.java @@ -38,8 +38,8 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { new KVBuilder() .put(ServiceNowConstants.RESOURCE, "table") .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE) - .put(ServiceNowConstants.SYSPARM_LIMIT, "10") - .put(ServiceNowConstants.TABLE, "incident") + .put(ServiceNowParams.SYSPARM_LIMIT, 10) + .put(ServiceNowParams.PARAM_TABLE_NAME, "incident") .build() ); @@ -50,6 +50,9 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { assertNotNull(items); assertTrue(items.size() <= 10); + assertNotNull(exchange.getIn().getHeader(ServiceNowConstants.OFFSET_FIRST)); + assertNotNull(exchange.getIn().getHeader(ServiceNowConstants.OFFSET_NEXT)); + assertNotNull(exchange.getIn().getHeader(ServiceNowConstants.OFFSET_LAST)); } @Test @@ -62,7 +65,7 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { null, new KVBuilder() .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE) - .put(ServiceNowConstants.SYSPARM_LIMIT, "10") + .put(ServiceNowParams.SYSPARM_LIMIT, 10) .build() ); @@ -103,7 +106,7 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { new KVBuilder() .put(ServiceNowConstants.RESOURCE, "table") .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_CREATE) - .put(ServiceNowConstants.TABLE, "incident") + .put(ServiceNowParams.PARAM_TABLE_NAME, "incident") .build() ); @@ -114,9 +117,9 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { number = incident.getNumber(); LOGGER.info("****************************************************"); - LOGGER.info("* Incident created"); - LOGGER.info("* sysid = {}", sysId); - LOGGER.info("* number = {}", number); + LOGGER.info(" Incident created"); + LOGGER.info(" sysid = {}", sysId); + LOGGER.info(" number = {}", number); LOGGER.info("****************************************************"); } @@ -125,6 +128,8 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { // ************************ { + LOGGER.info("Search the record {}", sysId); + mock.reset(); mock.expectedMessageCount(1); @@ -134,8 +139,8 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { new KVBuilder() .put(ServiceNowConstants.RESOURCE, "table") .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE) - .put(ServiceNowConstants.TABLE, "incident") - .put(ServiceNowConstants.SYSPARM_QUERY, "number=" + number) + .put(ServiceNowParams.PARAM_TABLE_NAME, "incident") + .put(ServiceNowParams.SYSPARM_QUERY, "number=" + number) .build() ); @@ -152,6 +157,8 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { // ************************ { + LOGGER.info("Update the record {}", sysId); + mock.reset(); mock.expectedMessageCount(1); @@ -167,8 +174,8 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { new KVBuilder() .put(ServiceNowConstants.RESOURCE, "table") .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_MODIFY) - .put(ServiceNowConstants.TABLE, "incident") - .put(ServiceNowConstants.SYSPARM_ID, sysId) + .put(ServiceNowParams.PARAM_TABLE_NAME, "incident") + .put(ServiceNowParams.PARAM_SYS_ID, sysId) .build() ); @@ -186,6 +193,8 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { // ************************ { + LOGGER.info("Retrieve the record {}", sysId); + mock.reset(); mock.expectedMessageCount(1); @@ -195,8 +204,8 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { new KVBuilder() .put(ServiceNowConstants.RESOURCE, "table") .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE) - .put(ServiceNowConstants.TABLE, "incident") - .put(ServiceNowConstants.SYSPARM_QUERY, "number=" + number) + .put(ServiceNowParams.PARAM_TABLE_NAME, "incident") + .put(ServiceNowParams.SYSPARM_QUERY, "number=" + number) .build() ); @@ -216,6 +225,8 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { // ************************ { + LOGGER.info("Search the record {}", sysId); + mock.reset(); mock.expectedMessageCount(1); @@ -225,8 +236,8 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { new KVBuilder() .put(ServiceNowConstants.RESOURCE, "table") .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE) - .put(ServiceNowConstants.TABLE, "incident") - .put(ServiceNowConstants.SYSPARM_ID, sysId) + .put(ServiceNowParams.PARAM_TABLE_NAME, "incident") + .put(ServiceNowParams.PARAM_SYS_ID, sysId) .build() ); @@ -244,6 +255,8 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { // ************************ { + LOGGER.info("Delete the record {}", sysId); + mock.reset(); mock.expectedMessageCount(1); @@ -253,8 +266,8 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { new KVBuilder() .put(ServiceNowConstants.RESOURCE, "table") .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_DELETE) - .put(ServiceNowConstants.TABLE, "incident") - .put(ServiceNowConstants.SYSPARM_ID, sysId) + .put(ServiceNowParams.PARAM_TABLE_NAME, "incident") + .put(ServiceNowParams.PARAM_SYS_ID, sysId) .build() ); @@ -262,10 +275,12 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { } // ************************ - // Retrieve it via query, should fail + // Retrieve by id, should fail // ************************ { + LOGGER.info("Find the record {}, should fail", sysId); + try { template().sendBodyAndHeaders( "direct:servicenow", @@ -273,12 +288,12 @@ public class ServiceNowTableTest extends ServiceNowTestSupport { new KVBuilder() .put(ServiceNowConstants.RESOURCE, "table") .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE) - .put(ServiceNowConstants.SYSPARM_QUERY, "number=" + number) - .put(ServiceNowConstants.TABLE, "incident") + .put(ServiceNowParams.PARAM_SYS_ID, sysId) + .put(ServiceNowParams.PARAM_TABLE_NAME, "incident") .build() ); - fail("Record +" + number + " should have been deleted"); + fail("Record " + number + " should have been deleted"); } catch (CamelExecutionException e) { assertTrue(e.getCause() instanceof ServiceNowException); // we are good http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTest.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTest.java b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTest.java index 2b4730a..1f831c2 100644 --- a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTest.java +++ b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTest.java @@ -35,8 +35,8 @@ public class ServiceNowTest extends ServiceNowTestSupport { new KVBuilder() .put(ServiceNowConstants.RESOURCE, "table") .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE) - .put(ServiceNowConstants.SYSPARM_QUERY, "number=" + UUID.randomUUID().toString()) - .put(ServiceNowConstants.TABLE, "incident") + .put(ServiceNowParams.SYSPARM_QUERY, "number=" + UUID.randomUUID().toString()) + .put(ServiceNowParams.PARAM_TABLE_NAME, "incident") .build() ); } catch (CamelExecutionException e) { @@ -56,8 +56,8 @@ public class ServiceNowTest extends ServiceNowTestSupport { new KVBuilder() .put(ServiceNowConstants.RESOURCE, "table") .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE) - .put(ServiceNowConstants.SYSPARM_QUERY, "number=" + UUID.randomUUID().toString()) - .put(ServiceNowConstants.TABLE, "notExistingTable") + .put(ServiceNowParams.SYSPARM_QUERY, "number=" + UUID.randomUUID().toString()) + .put(ServiceNowParams.PARAM_TABLE_NAME, "notExistingTable") .build() ); } catch (CamelExecutionException e) { @@ -79,7 +79,7 @@ public class ServiceNowTest extends ServiceNowTestSupport { new KVBuilder() .put(ServiceNowConstants.RESOURCE, "table") .put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_CREATE) - .put(ServiceNowConstants.TABLE, "incident") + .put(ServiceNowParams.PARAM_TABLE_NAME, "incident") .build() ); http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTestSupport.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTestSupport.java b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTestSupport.java index 706fb22..2aaf9e4 100644 --- a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTestSupport.java +++ b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/ServiceNowTestSupport.java @@ -38,7 +38,7 @@ class ServiceNowTestSupport extends CamelTestSupport { private final Map<String, Object> headers; public KVBuilder() { - this(new HashMap<String, Object>()); + this(new HashMap<>()); } private KVBuilder(Map<String, Object> headers) { @@ -54,6 +54,11 @@ class ServiceNowTestSupport extends CamelTestSupport { return this; } + public KVBuilder put(ServiceNowParam key, Object val) { + headers.put(key.getHeader(), val); + return this; + } + public Map<String, Object> build() { return Collections.unmodifiableMap(this.headers); } http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/AttachmentMeta.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/AttachmentMeta.java b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/AttachmentMeta.java new file mode 100644 index 0000000..21fbb38 --- /dev/null +++ b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/AttachmentMeta.java @@ -0,0 +1,92 @@ +/** + * 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.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class AttachmentMeta { + @JsonProperty("sys_id") + private String id; + + @JsonProperty("download_link") + private String downloadLink; + + @JsonProperty("table_name") + private String tableName; + + @JsonProperty("table_sys_id") + private String tableSysId; + + @JsonProperty("compressed") + private Boolean compressed; + + @JsonProperty("file_name") + private String fileName; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDownloadLink() { + return downloadLink; + } + + public void setDownloadLink(String downloadLink) { + this.downloadLink = downloadLink; + } + + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + public String getTableSysId() { + return tableSysId; + } + + public void setTableSysId(String tableSysId) { + this.tableSysId = tableSysId; + } + + public Boolean getCompressed() { + return compressed; + } + + public void setCompressed(Boolean compressed) { + this.compressed = compressed; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/Incident.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/Incident.java b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/Incident.java index 54c8904..c909413 100644 --- a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/Incident.java +++ b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/Incident.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.camel.component.servicenow.model; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/Scorecard.java ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/Scorecard.java b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/Scorecard.java new file mode 100644 index 0000000..dabb23e --- /dev/null +++ b/components/camel-servicenow/src/test/java/org/apache/camel/component/servicenow/model/Scorecard.java @@ -0,0 +1,46 @@ +/** + * 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.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Scorecard { + @JsonProperty("name") + private String name; + @JsonProperty("description") + private String description; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/f655c941/components/camel-servicenow/src/test/resources/my-content.txt ---------------------------------------------------------------------- diff --git a/components/camel-servicenow/src/test/resources/my-content.txt b/components/camel-servicenow/src/test/resources/my-content.txt new file mode 100644 index 0000000..63b8767 --- /dev/null +++ b/components/camel-servicenow/src/test/resources/my-content.txt @@ -0,0 +1,16 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- \ No newline at end of file