com.consol.citrus.Citrus Java Examples

The following examples show how to use com.consol.citrus.Citrus. 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: 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 #2
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 #3
Source File: ReceiveMessageActionConverter.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
@Override
public TestActionModel convert(ReceiveModel model) {
    TestActionModel action = super.convert(model);

    if (model.getMessage() != null) {
        action.add(new Property<>("message.name", "message.name", "MessageName", model.getMessage().getName(), false));

        action.add(new Property<>("message.type", "message.type", "MessageType", Optional.ofNullable(model.getMessage().getType()).orElse(Citrus.DEFAULT_MESSAGE_TYPE).toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    } else {
        action.add(new Property<>("message.name", "message.name", "MessageName", null, false));
        action.add(new Property<>("message.type", "message.type", "MessageType", Citrus.DEFAULT_MESSAGE_TYPE.toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    }

    return action;
}
 
Example #4
Source File: WsSendMessageActionConverter.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
@Override
public TestActionModel convert(SendModel model) {
    TestActionModel action = super.convert(model);

    if (model.getMessage() != null) {
        action.add(new Property<>("message.name", "message.name", "MessageName", model.getMessage().getName(), false));

        action.add(new Property<>("message.type", "message.type", "MessageType", Optional.ofNullable(model.getMessage().getType()).orElse(Citrus.DEFAULT_MESSAGE_TYPE).toLowerCase(), true)
                            .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    } else {
        action.add(new Property<>("message.name", "message.name", "MessageName", null, false));
        action.add(new Property<>("message.type", "message.type", "MessageType", Citrus.DEFAULT_MESSAGE_TYPE.toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    }

    return action;
}
 
Example #5
Source File: WsReceiveMessageActionConverter.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
@Override
public TestActionModel convert(ReceiveModel model) {
    TestActionModel action = super.convert(model);

    if (model.getMessage() != null) {
        action.add(new Property<>("message.name", "message.name", "MessageName", model.getMessage().getName(), false));

        action.add(new Property<>("message.type", "message.type", "MessageType", Optional.ofNullable(model.getMessage().getType()).orElse(Citrus.DEFAULT_MESSAGE_TYPE).toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    } else {
        action.add(new Property<>("message.name", "message.name", "MessageName", null, false));
        action.add(new Property<>("message.type", "message.type", "MessageType", Citrus.DEFAULT_MESSAGE_TYPE.toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    }

    return action;
}
 
Example #6
Source File: AllureCitrusTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
@Step("Run test case {testDesigner}")
private AllureResults run(final TestDesigner testDesigner) {
    final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
            CitrusSpringConfig.class, AllureCitrusConfig.class
    );
    final Citrus citrus = Citrus.newInstance(applicationContext);
    final TestContext testContext = citrus.createTestContext();

    final TestActionListeners listeners = applicationContext.getBean(TestActionListeners.class);
    final AllureLifecycle defaultLifecycle = Allure.getLifecycle();
    final AllureLifecycle lifecycle = applicationContext.getBean(AllureLifecycle.class);
    try {
        Allure.setLifecycle(lifecycle);
        final TestCase testCase = testDesigner.getTestCase();
        testCase.setTestActionListeners(listeners);

        citrus.run(testCase, testContext);
    } catch (Exception ignored) {
    } finally {
        Allure.setLifecycle(defaultLifecycle);
    }

    return applicationContext.getBean(AllureResultsWriterStub.class);
}
 
Example #7
Source File: SendMessageActionConverter.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
@Override
public TestActionModel convert(SendModel model) {
    TestActionModel action = super.convert(model);

    if (model.getMessage() != null) {
        action.add(new Property<>("message.name", "message.name", "MessageName", model.getMessage().getName(), false));

        action.add(new Property<>("message.type", "message.type", "MessageType", Optional.ofNullable(model.getMessage().getType()).orElse(Citrus.DEFAULT_MESSAGE_TYPE).toLowerCase(), true)
                            .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    } else {
        action.add(new Property<>("message.name", "message.name", "MessageName", null, false));
        action.add(new Property<>("message.type", "message.type", "MessageType", Citrus.DEFAULT_MESSAGE_TYPE.toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    }

    return action;
}
 
Example #8
Source File: Project.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
/**
 * Provides all Citrus artifact coordinates in Maven canonical format.
 * @return
 */
private List<String> getCitrusArtifacts() {
    return Stream.of("citrus-core",
            "citrus-jms",
            "citrus-jdbc",
            "citrus-http",
            "citrus-websocket",
            "citrus-ws",
            "citrus-ftp",
            "citrus-ssh",
            "citrus-camel",
            "citrus-docker",
            "citrus-kubernetes",
            "citrus-selenium",
            "citrus-zookeeper",
            "citrus-cucumber",
            "citrus-rmi",
            "citrus-jmx",
            "citrus-restdocs",
            "citrus-mail",
            "citrus-vertx",
            "citrus-java-dsl").map(name -> String.format("com.consol.citrus:%s:%s", name, Citrus.getVersion())).collect(Collectors.toList());
}
 
Example #9
Source File: FileBrowserServiceTest.java    From citrus-admin with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecodeDirectoryUrl() throws Exception {
    String path = testling.decodeDirectoryUrl(URLEncoder.encode("/request/test/1", Citrus.CITRUS_FILE_ENCODING), "");
    Assert.assertEquals(path, "/request/test/1/");

    path = testling.decodeDirectoryUrl(URLEncoder.encode("/request/test/1", Citrus.CITRUS_FILE_ENCODING), "/Users/home");
    Assert.assertEquals(path, "/request/test/1/");

    path = testling.decodeDirectoryUrl(URLEncoder.encode("/", Citrus.CITRUS_FILE_ENCODING), "/Users/home");
    Assert.assertEquals(path, "/Users/home/");

    path = testling.decodeDirectoryUrl(URLEncoder.encode("", Citrus.CITRUS_FILE_ENCODING), "/Users/home");
    Assert.assertEquals(path, "");

    path = testling.decodeDirectoryUrl(URLEncoder.encode("/", Citrus.CITRUS_FILE_ENCODING), "");
    Assert.assertEquals(path, "");
}
 
Example #10
Source File: SendResponseActionConverter.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
@Override
public TestActionModel convert(SendResponseModel model) {
    TestActionModel action = super.convert(model);

    ResponseHeadersType headers = model.getHeaders();
    if (headers != null) {
        action.add(new Property<>("status", "status", "Status", model.getHeaders().getStatus(), true)
                    .options(Stream.of(HttpStatus.values()).map(HttpStatus::toString).collect(Collectors.toList())));
        action.add(new Property<>("reason", "reason", "Reason", model.getHeaders().getReasonPhrase(), false)
                    .options(Stream.of(HttpStatus.values()).map(HttpStatus::getReasonPhrase).collect(Collectors.toList())));

        action.add(new Property<>("version", "version", "Version", Optional.ofNullable(model.getHeaders().getVersion()).orElse("HTTP/1.1"), false));
    }

    if (model.getBody() != null) {
        action.add(new Property<>("message.name", "message.name", "MessageName", model.getBody().getName(), false));

        action.add(new Property<>("message.type", "message.type", "MessageType", Optional.ofNullable(model.getBody().getType()).orElse(Citrus.DEFAULT_MESSAGE_TYPE).toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    } else {
        action.add(new Property<>("message.name", "message.name", "MessageName", null, false));
        action.add(new Property<>("message.type", "message.type", "MessageType", Citrus.DEFAULT_MESSAGE_TYPE.toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    }

    return action;
}
 
Example #11
Source File: ReceiveResponseActionConverter.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
@Override
public TestActionModel convert(ReceiveResponseModel model) {
    TestActionModel action = super.convert(model);

    ResponseHeadersType headers = model.getHeaders();
    if (headers != null) {
        action.add(new Property<>("status", "status", "Status", model.getHeaders().getStatus(), true)
                    .options(Stream.of(HttpStatus.values()).map(HttpStatus::toString).collect(Collectors.toList())));
        action.add(new Property<>("reason", "reason", "Reason", model.getHeaders().getReasonPhrase(), false)
                    .options(Stream.of(HttpStatus.values()).map(HttpStatus::getReasonPhrase).collect(Collectors.toList())));

        action.add(new Property<>("version", "version", "Version", Optional.ofNullable(model.getHeaders().getVersion()).orElse("HTTP/1.1"), false));
    }

    if (model.getBody() != null) {
        action.add(new Property<>("message.name", "message.name", "MessageName", model.getBody().getName(), false));

        action.add(new Property<>("message.type", "message.type", "MessageType", Optional.ofNullable(model.getBody().getType()).orElse(Citrus.DEFAULT_MESSAGE_TYPE).toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    } else {
        action.add(new Property<>("message.name", "message.name", "MessageName", null, false));
        action.add(new Property<>("message.type", "message.type", "MessageType", Citrus.DEFAULT_MESSAGE_TYPE.toLowerCase(), true)
                .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
    }

    return action;
}
 
Example #12
Source File: FileBrowserService.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
/**
 * Decodes file path url.
 * @param url
 * @param rootDirectory
 * @return
 */
public String decodeDirectoryUrl(String url, String rootDirectory) {
    String directory;

    try {
        directory = URLDecoder.decode(url, Citrus.CITRUS_FILE_ENCODING);
    } catch (UnsupportedEncodingException e) {
        throw new ApplicationRuntimeException("Unable to decode directory URL", e);
    }

    if (directory.equals("/")) {
        if (StringUtils.hasText(rootDirectory)) {
            directory = rootDirectory;
        } else {
            return "";
        }
    }

    if (!StringUtils.hasText(directory)) {
        return "";
    } else if (directory.charAt(directory.length() - 1) == WINDOWS_SEPARATOR) {
        directory = directory.substring(0, directory.length() - 1) + "/";
    } else if (directory.charAt(directory.length() - 1) != UNIX_SEPARATOR) {
        directory += "/";
    }

    return directory;
}
 
Example #13
Source File: TestCaseServiceTest.java    From citrus-admin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTestDetailJava() throws Exception {
    reset(project);
    when(project.getName()).thenReturn("citrus-core");
    when(project.getVersion()).thenReturn(Citrus.getVersion());
    when(project.isMavenProject()).thenReturn(true);
    when(project.getSettings()).thenReturn(ConfigurationProvider.load(ProjectSettings.class));
    String projectHome = new ClassPathResource("projects/maven").getFile().getAbsolutePath();
    when(project.getProjectHome()).thenReturn(projectHome);
    when(project.getJavaDirectory()).thenReturn(projectHome + "projects/maven/src/test/java/");
    when(project.getMavenPomFile()).thenReturn(new ClassPathResource("projects/maven/pom.xml").getFile());
    when(project.getClassLoader()).thenReturn(ClassLoader.getSystemClassLoader());

    TestDetail testDetail = testCaseService.getTestDetail(project, new com.consol.citrus.admin.model.Test("com.consol.citrus.admin.javadsl", "CitrusJavaTest", "fooTest", "CitrusJavaTest.fooTest", TestType.JAVA));

    Assert.assertEquals(testDetail.getName(), "CitrusJavaTest.fooTest");
    Assert.assertEquals(testDetail.getPackageName(), "com.consol.citrus.admin.javadsl");
    Assert.assertEquals(testDetail.getSourceFiles().size(), 1L);
    Assert.assertEquals(testDetail.getSourceFiles().get(0), "com/consol/citrus/admin/javadsl/CitrusJavaTest.java");
    Assert.assertEquals(testDetail.getType(), TestType.JAVA);
    Assert.assertTrue(testDetail.getFile().endsWith("javadsl/CitrusJavaTest"));
    Assert.assertEquals(testDetail.getActions().size(), 1L);
    Assert.assertEquals(testDetail.getActions().get(0).getType(), "echo");

    Assert.assertEquals(testDetail.getActions().get(0).getProperties().size(), 2L);
    Assert.assertEquals(testDetail.getActions().get(0).getProperties().get(0).getName(), "description");
    Assert.assertEquals(testDetail.getActions().get(0).getProperties().get(1).getName(), "message");
}
 
Example #14
Source File: SimulatorAutoConfiguration.java    From citrus-simulator with Apache License 2.0 4 votes vote down vote up
@Bean
public Citrus citrus(ApplicationContext applicationContext) {
    return Citrus.newInstance(applicationContext);
}
 
Example #15
Source File: ScenarioExecutionService.java    From citrus-simulator with Apache License 2.0 4 votes vote down vote up
@Autowired
public ScenarioExecutionService(ActivityService activityService, ApplicationContext applicationContext, Citrus citrus) {
    this.activityService = activityService;
    this.applicationContext = applicationContext;
    this.citrus = citrus;
}
 
Example #16
Source File: ReceiveRequestActionConverter.java    From citrus-admin with Apache License 2.0 4 votes vote down vote up
@Override
public TestActionModel convert(ReceiveRequestModel model) {
    TestActionModel action = super.convert(model);

    action.add(new Property<>("method", "method", "Method", getRequestMethod(model), true)
            .options(Stream.of(RequestMethod.values()).map(RequestMethod::name).collect(Collectors.toList())));

    ServerRequestType request = getRequestType(model);
    if (request != null) {
        action.add(new Property<>("path", "path", "Path", request.getPath(), false));

        if (request.getBody() != null) {
            if (StringUtils.hasText(request.getBody().getData())) {
                action.add(new Property<>("body", "body", "Body", request.getBody().getData().trim(), false));
            } else if (request.getBody().getPayload() != null) {
                action.add(new Property<>("body", "body", "Body", PayloadElementParser.parseMessagePayload(request.getBody().getPayload().getAnies().get(0)), false));
            } else if (request.getBody().getResource() != null &&
                    StringUtils.hasText(request.getBody().getResource().getFile())) {
                action.add(new Property<>("body", "body", "Body", request.getBody().getResource().getFile(), false));
            } else {
                action.add(new Property<>("body", "body", "Body", null, false));
            }

            action.add(new Property<>("message.name", "message.name", "MessageName", request.getBody().getName(), false));

            action.add(new Property<>("message.type", "message.type", "MessageType", Optional.ofNullable(request.getBody().getType()).orElse(Citrus.DEFAULT_MESSAGE_TYPE).toLowerCase(), true)
                    .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
        } else {
            action.add(new Property<>("body", "body", "Body", null, false));
        }

        if (request.getHeaders() != null) {
            action.add(new Property<>("headers", "headers", "Headers", request.getHeaders().getHeaders().stream().map(header -> header.getName() + "=" + header.getValue()).collect(Collectors.joining(",")), false));
        } else {
            action.add(new Property<>("headers", "headers", "Headers", null, false));
        }

        if (!CollectionUtils.isEmpty(request.getParams())) {
            action.add(new Property<>("query.params", "query.params", "QueryParams", request.getParams().stream().map(param -> param.getName() + "=" + param.getValue()).collect(Collectors.joining(",")), false));
        }
    }

    return action;
}
 
Example #17
Source File: SendRequestActionConverter.java    From citrus-admin with Apache License 2.0 4 votes vote down vote up
@Override
public TestActionModel convert(SendRequestModel model) {
    TestActionModel action = super.convert(model);

    action.add(new Property<>("method", "method", "Method", getRequestMethod(model), true)
                    .options(Stream.of(RequestMethod.values()).map(RequestMethod::name).collect(Collectors.toList())));

    ClientRequestType request = getRequestType(model);
    if (request != null) {
        action.add(new Property<>("path", "path", "Path", request.getPath(), false));

        if (request.getBody() != null) {
            if (StringUtils.hasText(request.getBody().getData())) {
                action.add(new Property<>("body", "body", "Body", request.getBody().getData().trim(), false));
            } else if (request.getBody().getPayload() != null) {
                action.add(new Property<>("body", "body", "Body", PayloadElementParser.parseMessagePayload(request.getBody().getPayload().getAnies().get(0)), false));
            } else if (request.getBody().getResource() != null &&
                    StringUtils.hasText(request.getBody().getResource().getFile())) {
                action.add(new Property<>("body", "body", "Body", request.getBody().getResource().getFile(), false));
            } else {
                action.add(new Property<>("body", "body", "Body", null, false));
            }

            action.add(new Property<>("message.name", "message.name", "MessageName", request.getBody().getName(), false));

            action.add(new Property<>("message.type", "message.type", "MessageType", Optional.ofNullable(request.getBody().getType()).orElse(Citrus.DEFAULT_MESSAGE_TYPE).toLowerCase(), true)
                    .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
        } else {
            action.add(new Property<>("body", "body", "Body", null, false));
            action.add(new Property<>("message.name", "message.name", "MessageName", null, false));
            action.add(new Property<>("message.type", "message.type", "MessageType", Citrus.DEFAULT_MESSAGE_TYPE.toLowerCase(), true)
                    .options(Stream.of(MessageType.values()).map(MessageType::name).map(String::toLowerCase).collect(Collectors.toList())));
        }

        if (request.getHeaders() != null) {
            action.add(new Property<>("headers", "headers", "Headers", request.getHeaders().getHeaders().stream().map(header -> header.getName() + "=" + header.getValue()).collect(Collectors.joining(",")), false));
        } else {
            action.add(new Property<>("headers", "headers", "Headers", null, false));
        }

        if (!CollectionUtils.isEmpty(request.getParams())) {
            action.add(new Property<>("query.params", "query.params", "QueryParams", request.getParams().stream().map(param -> param.getName() + "=" + param.getValue()).collect(Collectors.joining(",")), false));
        }
    }

    return action;
}