com.consol.citrus.message.DefaultMessage Java Examples

The following examples show how to use com.consol.citrus.message.DefaultMessage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebHookToFtp_IT.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Override
public void doExecute(TestContext testContext) {
    Path publicUserDir = getFtpUserHome().resolve("public");
    Assert.assertTrue( "Missing ftp user home directory", publicUserDir.toFile().exists());

    File ftpUploadFile = publicUserDir.resolve(UPLOAD_FILENAME).toFile();
    Assert.assertTrue(String.format("Missing ftp upload file '%s'", UPLOAD_FILENAME), ftpUploadFile.exists());
    try {
        JsonTextMessageValidator validator = new JsonTextMessageValidator();
        validator.validateMessage(new DefaultMessage(FileUtils.readToString(ftpUploadFile)),
                                    new DefaultMessage("{\"message\" : \"${first_name},${company},${email}\"}"),
                                    testContext,
                                    new JsonMessageValidationContext());
    } catch (IOException e) {
        throw new CitrusRuntimeException(String.format("Failed to verify ftp upload file '%s'", UPLOAD_FILENAME), e);
    }
}
 
Example #2
Source File: WebSocketPushEventsListenerTest.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void testOnInboundMessage() throws Exception {
    Message inbound = new DefaultMessage("Hello Citrus!");

    reset(restTemplate, context);
    when(restTemplate.exchange(eq("http://localhost:8080/api/connector/message/inbound?processId=MySampleTest"), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))).thenAnswer(invocation -> {
        HttpEntity request = (HttpEntity) invocation.getArguments()[2];

        Assert.assertEquals(request.getBody().toString(), inbound.toString());

        return ResponseEntity.ok().build();
    });

    when(context.getVariables()).thenReturn(Collections.singletonMap(Citrus.TEST_NAME_VARIABLE, "MySampleTest"));
    when(context.getVariable(Citrus.TEST_NAME_VARIABLE)).thenReturn("MySampleTest");

    pushMessageListener.onInboundMessage(inbound, context);
    verify(restTemplate).exchange(eq("http://localhost:8080/api/connector/message/inbound?processId=MySampleTest"), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class));
}
 
Example #3
Source File: WebSocketPushEventsListenerTest.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void testOnOutboundMessage() throws Exception {
    Message outbound = new DefaultMessage("Hello Citrus!");

    reset(restTemplate, context);
    when(restTemplate.exchange(eq("http://localhost:8080/api/connector/message/outbound?processId=MySampleTest"), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))).thenAnswer(invocation -> {
        HttpEntity request = (HttpEntity) invocation.getArguments()[2];

        Assert.assertEquals(request.getBody().toString(), outbound.toString());

        return ResponseEntity.ok().build();
    });

    when(context.getVariables()).thenReturn(Collections.singletonMap(Citrus.TEST_NAME_VARIABLE, "MySampleTest"));
    when(context.getVariable(Citrus.TEST_NAME_VARIABLE)).thenReturn("MySampleTest");

    pushMessageListener.onOutboundMessage(outbound, context);
    verify(restTemplate).exchange(eq("http://localhost:8080/api/connector/message/outbound?processId=MySampleTest"), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class));
}
 
Example #4
Source File: WebSocketPushEventsListenerTest.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoContext() throws Exception {
    Message inbound = new DefaultMessage("Hello Citrus!");

    reset(restTemplate, context);
    when(restTemplate.exchange(eq("http://localhost:8080/api/connector/message/inbound?processId="), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class))).thenAnswer(invocation -> {
        HttpEntity request = (HttpEntity) invocation.getArguments()[2];

        Assert.assertEquals(request.getBody().toString(), inbound.toString());

        return ResponseEntity.ok().build();
    });

    pushMessageListener.onInboundMessage(inbound, null);
    pushMessageListener.onInboundMessage(inbound, context);

    verify(restTemplate, times(2)).exchange(eq("http://localhost:8080/api/connector/message/inbound?processId="), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class));
}
 
Example #5
Source File: ScenarioMappersTest.java    From citrus-simulator with Apache License 2.0 5 votes vote down vote up
@Test
public void testDefaultMapping() {
    ScenarioMappers mapperChain = ScenarioMappers.of(new HeaderMapper("foo"));
    Assert.assertThrows(CitrusRuntimeException.class, () -> mapperChain.getMappingKey(new DefaultMessage()));

    SimulatorConfigurationProperties configurationProperties = new SimulatorConfigurationProperties();
    configurationProperties.setDefaultScenario(DEFAULT_SCENARIO);
    mapperChain.setSimulatorConfigurationProperties(configurationProperties);

    Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage()), DEFAULT_SCENARIO);

    mapperChain.setUseDefaultMapping(false);
    Assert.assertThrows(CitrusRuntimeException.class, () -> mapperChain.getMappingKey(new DefaultMessage()));
}
 
Example #6
Source File: ScenarioMappersTest.java    From citrus-simulator with Apache License 2.0 4 votes vote down vote up
@Test
public void testMappingChain() throws Exception {
    ScenarioMappers mapperChain = ScenarioMappers.of(new HeaderMapper("foo"),
            new ContentBasedXPathScenarioMapper().addXPathExpression("/foo"),
            new ContentBasedJsonPathScenarioMapper().addJsonPathExpression("$.foo"),
            new HttpRequestPathScenarioMapper(),
            new HttpRequestAnnotationScenarioMapper(),
            new HeaderMapper("bar"));

    SimulatorConfigurationProperties configurationProperties = new SimulatorConfigurationProperties();
    configurationProperties.setDefaultScenario(DEFAULT_SCENARIO);
    mapperChain.setSimulatorConfigurationProperties(configurationProperties);

    mapperChain.setScenarioList(Arrays.asList(new FooScenario(), new BarScenario(), new OtherScenario()));
    mapperChain.afterPropertiesSet();

    Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage()), DEFAULT_SCENARIO);
    Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("foo").setHeader("foo", "something")), DEFAULT_SCENARIO);
    Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage().setHeader("foo", FooScenario.SCENARIO_NAME)), FooScenario.SCENARIO_NAME);
    Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage().setHeader("foo", FooScenario.SCENARIO_NAME)
                                                                      .setHeader("bar", BarScenario.SCENARIO_NAME)), FooScenario.SCENARIO_NAME);
    Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage().setHeader("foo", "something")
                                                                      .setHeader("bar", BarScenario.SCENARIO_NAME)), BarScenario.SCENARIO_NAME);
    Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage().setHeader("bar", BarScenario.SCENARIO_NAME)), BarScenario.SCENARIO_NAME);

    Assert.assertEquals(mapperChain.getMappingKey(new HttpMessage().path("/other").method(HttpMethod.GET).setHeader("foo", FooScenario.SCENARIO_NAME)), FooScenario.SCENARIO_NAME);
    Assert.assertEquals(mapperChain.getMappingKey(new HttpMessage().path("/other").method(HttpMethod.GET).setHeader("foo", "something")), OtherScenario.SCENARIO_NAME);
    Assert.assertEquals(mapperChain.getMappingKey(new HttpMessage().path("/other").method(HttpMethod.GET).setHeader("bar", BarScenario.SCENARIO_NAME)), OtherScenario.SCENARIO_NAME);

    Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("{ \"foo\": \"something\" }")), DEFAULT_SCENARIO);
    Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("{ \"foo\": \"something\" }")), DEFAULT_SCENARIO);
    Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("{ \"bar\": \"" + FooScenario.SCENARIO_NAME  + "\" }")), DEFAULT_SCENARIO);
    Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("{ \"foo\": \"" + FooScenario.SCENARIO_NAME + "\" }")), FooScenario.SCENARIO_NAME);
    Assert.assertEquals(mapperChain.getMappingKey(new HttpMessage("{ \"foo\": \"" + FooScenario.SCENARIO_NAME + "\" }").path("/other").method(HttpMethod.GET)), FooScenario.SCENARIO_NAME);

    Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("<foo>something</foo>")), DEFAULT_SCENARIO);
    Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("<bar>" + FooScenario.SCENARIO_NAME  + "</bar>")), DEFAULT_SCENARIO);
    Assert.assertEquals(mapperChain.getMappingKey(new DefaultMessage("<foo>" + FooScenario.SCENARIO_NAME + "</foo>")), FooScenario.SCENARIO_NAME);
    Assert.assertEquals(mapperChain.getMappingKey(new HttpMessage("<foo>" + FooScenario.SCENARIO_NAME + "</foo>").path("/other").method(HttpMethod.GET)), FooScenario.SCENARIO_NAME);

    mapperChain.setUseDefaultMapping(false);
    Assert.assertThrows(CitrusRuntimeException.class, () -> mapperChain.getMappingKey(new DefaultMessage()));
    Assert.assertThrows(CitrusRuntimeException.class, () -> mapperChain.getMappingKey(new DefaultMessage().setHeader("foo", "something")));
}