Search in sources :

Example 1 with Incident

use of org.apache.camel.component.servicenow.model.Incident in project camel by apache.

the class ServiceNowTableTest method testRetrieveSome.

@Test
public void testRetrieveSome() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:servicenow");
    mock.expectedMessageCount(1);
    template().sendBodyAndHeaders("direct:servicenow", null, kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE).put(ServiceNowParams.SYSPARM_LIMIT, 10).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").build());
    mock.assertIsSatisfied();
    Exchange exchange = mock.getExchanges().get(0);
    List<Incident> items = exchange.getIn().getBody(List.class);
    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));
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Incident(org.apache.camel.component.servicenow.model.Incident) Test(org.junit.Test)

Example 2 with Incident

use of org.apache.camel.component.servicenow.model.Incident in project camel by apache.

the class ServiceNowTableTest method testIncidentWorkflow.

@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, kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_CREATE).put(ServiceNowParams.PARAM_TABLE_NAME, "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
    // ************************
    {
        LOGGER.info("Search the record {}", sysId);
        mock.reset();
        mock.expectedMessageCount(1);
        template().sendBodyAndHeaders("direct:servicenow", null, kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").put(ServiceNowParams.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
    // ************************
    {
        LOGGER.info("Update the record {}", sysId);
        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, kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_MODIFY).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").put(ServiceNowParams.PARAM_SYS_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
    // ************************
    {
        LOGGER.info("Retrieve the record {}", sysId);
        mock.reset();
        mock.expectedMessageCount(1);
        template().sendBodyAndHeaders("direct:servicenow", null, kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").put(ServiceNowParams.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
    // ************************
    {
        LOGGER.info("Search the record {}", sysId);
        mock.reset();
        mock.expectedMessageCount(1);
        template().sendBodyAndHeaders("direct:servicenow", null, kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").put(ServiceNowParams.PARAM_SYS_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
    // ************************
    {
        LOGGER.info("Delete the record {}", sysId);
        mock.reset();
        mock.expectedMessageCount(1);
        template().sendBodyAndHeaders("direct:servicenow", null, kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_DELETE).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").put(ServiceNowParams.PARAM_SYS_ID, sysId).build());
        mock.assertIsSatisfied();
    }
    // ************************
    // Retrieve by id, should fail
    // ************************
    {
        LOGGER.info("Find the record {}, should fail", sysId);
        try {
            template().sendBodyAndHeaders("direct:servicenow", null, kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE).put(ServiceNowParams.PARAM_SYS_ID, sysId).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").build());
            fail("Record " + number + " should have been deleted");
        } catch (CamelExecutionException e) {
            assertTrue(e.getCause() instanceof ServiceNowException);
        // we are good
        }
    }
}
Also used : CamelExecutionException(org.apache.camel.CamelExecutionException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) List(java.util.List) Incident(org.apache.camel.component.servicenow.model.Incident) Test(org.junit.Test)

Example 3 with Incident

use of org.apache.camel.component.servicenow.model.Incident in project camel by apache.

the class ServiceNowTest method testVersionedApiRequest.

@Test
public void testVersionedApiRequest() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:servicenow");
    mock.reset();
    mock.expectedMessageCount(1);
    Incident incident = new Incident();
    incident.setDescription("my incident");
    incident.setShortDescription("An incident");
    incident.setSeverity(1);
    incident.setImpact(1);
    template().sendBodyAndHeaders("direct:servicenow", incident, kvBuilder().put(ServiceNowConstants.RESOURCE, ServiceNowConstants.RESOURCE_TABLE).put(ServiceNowConstants.API_VERSION, "v1").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_CREATE).put(ServiceNowConstants.REQUEST_MODEL, Incident.class).put(ServiceNowConstants.RESPONSE_MODEL, JsonNode.class).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").build());
    mock.assertIsSatisfied();
    Object body = mock.getExchanges().get(0).getIn().getBody();
    assertNotNull(body);
    assertTrue(body instanceof JsonNode);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) JsonNode(com.fasterxml.jackson.databind.JsonNode) Incident(org.apache.camel.component.servicenow.model.Incident) Test(org.junit.Test)

Example 4 with Incident

use of org.apache.camel.component.servicenow.model.Incident in project camel by apache.

the class ServiceNowBlueprintEndpointAuthTest method testAuth.

@Test
public void testAuth() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:servicenow");
    mock.expectedMessageCount(1);
    template().sendBodyAndHeaders("direct:servicenow", null, ServiceNowTestSupport.kvBuilder().put(ServiceNowConstants.RESOURCE, "table").put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE).put(ServiceNowParams.SYSPARM_LIMIT, 10).put(ServiceNowParams.PARAM_TABLE_NAME, "incident").build());
    mock.assertIsSatisfied();
    Exchange exchange = mock.getExchanges().get(0);
    List<Incident> items = exchange.getIn().getBody(List.class);
    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));
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Incident(org.apache.camel.component.servicenow.model.Incident) Test(org.junit.Test)

Example 5 with Incident

use of org.apache.camel.component.servicenow.model.Incident in project camel by apache.

the class ServiceNowTableTest method testRetrieveSomeWithDefaults.

@Test
public void testRetrieveSomeWithDefaults() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:servicenow-defaults");
    mock.expectedMessageCount(1);
    template().sendBodyAndHeaders("direct:servicenow-defaults", null, kvBuilder().put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_RETRIEVE).put(ServiceNowParams.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);
}
Also used : Exchange(org.apache.camel.Exchange) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Incident(org.apache.camel.component.servicenow.model.Incident) Test(org.junit.Test)

Aggregations

MockEndpoint (org.apache.camel.component.mock.MockEndpoint)6 Incident (org.apache.camel.component.servicenow.model.Incident)6 Test (org.junit.Test)6 Exchange (org.apache.camel.Exchange)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 List (java.util.List)1 CamelExecutionException (org.apache.camel.CamelExecutionException)1