com.consol.citrus.exceptions.CitrusRuntimeException Java Examples
The following examples show how to use
com.consol.citrus.exceptions.CitrusRuntimeException.
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: DefaultConnectionFactoryCreator.java From yaks with Apache License 2.0 | 6 votes |
@Override public ConnectionFactory create(Map<String, String> properties) { String className = properties.remove("type"); Assert.notNull(className, "Missing connection factory type information"); try { Class<?> type = Class.forName(className); if (!(ConnectionFactory.class.isAssignableFrom(type))) { throw new IllegalStateException(String.format("Unsupported type information %s - must be of type %s", type.getName(), ConnectionFactory.class.getName())); } Collection<String> constructorArgs = properties.values(); Constructor<? extends ConnectionFactory> constructor = Arrays.stream(type.getConstructors()) .filter(c -> c.getParameterCount() == constructorArgs.size() && Arrays.stream(c.getParameterTypes()).allMatch(paramType -> paramType.equals(String.class))) .map(c -> (Constructor<? extends ConnectionFactory>) c) .findFirst() .orElseThrow(() -> new IllegalStateException("Unable to find matching constructor on connection factory")); return constructor.newInstance(constructorArgs.toArray(new Object[0])); } catch (InstantiationException | InvocationTargetException | IllegalAccessException | ClassNotFoundException e) { throw new CitrusRuntimeException(e); } }
Example #2
Source File: HttpRequestAnnotationScenarioMapperTest.java From citrus-simulator with Apache License 2.0 | 6 votes |
@Test public void testGetMappingKey() { scenarioMapper.setScenarioList(Arrays.asList(new IssueScenario(), new FooScenario(), new GetFooScenario(), new PutFooScenario(), new OtherScenario())); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/foo")), "FooScenario"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/foo").method(HttpMethod.GET)), "GetFooScenario"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/foo").method(HttpMethod.PUT)), "PutFooScenario"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/other")), "OtherScenario"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.GET)), "IssueScenario"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.DELETE)), "IssueScenario"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.PUT)), "default"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar")), "default"); Assert.assertEquals(scenarioMapper.getMappingKey(null), "default"); scenarioMapper.setUseDefaultMapping(false); Assert.assertThrows(CitrusRuntimeException.class, () -> scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar").method(HttpMethod.PUT))); Assert.assertThrows(CitrusRuntimeException.class, () -> scenarioMapper.getMappingKey(new HttpMessage().path("/issues/bar"))); Assert.assertThrows(CitrusRuntimeException.class, () -> scenarioMapper.getMappingKey(null)); }
Example #3
Source File: ActivityService.java From citrus-simulator with Apache License 2.0 | 6 votes |
public void completeTestAction(TestCase testCase, TestAction testAction) { if (skipTestAction(testAction)) { return; } ScenarioExecution te = lookupScenarioExecution(testCase); Iterator<ScenarioAction> iterator = te.getScenarioActions().iterator(); ScenarioAction lastScenarioAction = null; while (iterator.hasNext()) { lastScenarioAction = iterator.next(); } if (lastScenarioAction == null) { throw new CitrusRuntimeException(String.format("No test action found with name %s", testAction.getName())); } if (!lastScenarioAction.getName().equals(testAction.getName())) { throw new CitrusRuntimeException(String.format("Expected to find last test action with name %s but got %s", testAction.getName(), lastScenarioAction.getName())); } lastScenarioAction.setEndDate(getTimeNow()); }
Example #4
Source File: SoapMessageHelper.java From citrus-simulator with Apache License 2.0 | 6 votes |
/** * Creates a new SOAP message representation from given payload resource. Constructs a SOAP envelope * with empty header and payload as body. * * @param message * @return * @throws IOException */ public Message createSoapMessage(Message message) { try { String payload = message.getPayload().toString(); LOG.info("Creating SOAP message from payload: " + payload); WebServiceMessage soapMessage = soapMessageFactory.createWebServiceMessage(); transformerFactory.newTransformer().transform( new StringSource(payload), soapMessage.getPayloadResult()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); soapMessage.writeTo(bos); return new SoapMessage(new String(bos.toByteArray()), message.getHeaders()); } catch (Exception e) { throw new CitrusRuntimeException("Failed to create SOAP message from payload resource", e); } }
Example #5
Source File: HttpClientSteps.java From yaks with Apache License 2.0 | 6 votes |
/** * Get secure http client implementation with trust all strategy and noop host name verifier. * @return */ private org.apache.http.client.HttpClient sslClient() { try { SSLContext sslcontext = SSLContexts .custom() .loadTrustMaterial(TrustAllStrategy.INSTANCE) .build(); SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory( sslcontext, NoopHostnameVerifier.INSTANCE); return HttpClients .custom() .setSSLSocketFactory(sslSocketFactory) .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE) .build(); } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { throw new CitrusRuntimeException("Failed to create http client for ssl connection", e); } }
Example #6
Source File: WebHookToFtp_IT.java From syndesis with Apache License 2.0 | 6 votes |
@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 #7
Source File: Project.java From citrus-admin with Apache License 2.0 | 6 votes |
/** * Load settings from project info file. */ public void loadSettings() { try (FileInputStream fileInput = new FileInputStream(getProjectInfoFile())) { String projectInfo = FileUtils.readToString(fileInput); // support legacy build configuration projectInfo = projectInfo.replaceAll("com\\.consol\\.citrus\\.admin\\.model\\.build\\.maven\\.MavenBuildConfiguration", MavenBuildContext.class.getName()); Project project = Jackson2ObjectMapperBuilder.json().build().readerFor(Project.class).readValue(projectInfo); setName(project.getName()); setDescription(project.getDescription()); setSettings(project.getSettings()); setVersion(project.getVersion()); } catch (IOException e) { throw new CitrusRuntimeException("Failed to read project settings file", e); } }
Example #8
Source File: JUnit4TestReportLoader.java From citrus-admin with Apache License 2.0 | 5 votes |
@Override public TestReport getLatest(Project activeProject, Test test) { TestReport report = new TestReport(); if (hasTestResults(activeProject)) { try { String testResultsContent = getTestResultsAsString(activeProject); if (StringUtils.hasText(testResultsContent)) { Document testResults = XMLUtils.parseMessagePayload(testResultsContent); Element testCase = (Element) XPathUtils.evaluateAsNode(testResults, "/testsuite/testcase[@classname = '" + test.getPackageName() + "." + test.getClassName() + "']", null); TestResult result = getResult(test, testCase); report.setTotal(1); if (result.getStatus().equals(TestStatus.PASS)) { report.setPassed(1L); } else if (result.getStatus().equals(TestStatus.FAIL)) { report.setFailed(1L); } else if (result.getStatus().equals(TestStatus.SKIP)) { report.setSkipped(1L); } report.getResults().add(result); } } catch (CitrusRuntimeException e) { log.warn("No results found for test: " + test.getPackageName() + "." + test.getClassName() + "#" + test.getMethodName()); } } return report; }
Example #9
Source File: ScenarioMappersTest.java From citrus-simulator with Apache License 2.0 | 5 votes |
@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 #10
Source File: HttpRequestPathScenarioMapperTest.java From citrus-simulator with Apache License 2.0 | 5 votes |
@Test public void testGetMappingKey() { Operation operation = Mockito.mock(Operation.class); scenarioMapper.setScenarioList(Arrays.asList(new HttpOperationScenario("/issues/foos", HttpMethod.GET, operation, Collections.emptyMap()), new HttpOperationScenario("/issues/foos", HttpMethod.POST, operation, Collections.emptyMap()), new HttpOperationScenario("/issues/foo/{id}", HttpMethod.GET, operation, Collections.emptyMap()), new HttpOperationScenario("/issues/foo/detail", HttpMethod.GET, operation, Collections.emptyMap()), new HttpOperationScenario("/issues/bars", HttpMethod.GET, operation, Collections.emptyMap()), new HttpOperationScenario("/issues/bar/{id}", HttpMethod.GET, operation, Collections.emptyMap()), new HttpOperationScenario("/issues/bar/detail", HttpMethod.GET, operation, Collections.emptyMap()))); when(operation.getOperationId()) .thenReturn("fooListScenario") .thenReturn("fooListPostScenario") .thenReturn("barListScenario") .thenReturn("fooScenario") .thenReturn("barScenario") .thenReturn("fooDetailScenario") .thenReturn("barDetailScenario"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET)), "default"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.POST)), "default"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues")), "default"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/foos")), "fooListScenario"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.POST).path("/issues/foos")), "fooListPostScenario"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.PUT).path("/issues/foos")), "default"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/bars")), "barListScenario"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.DELETE).path("/issues/bars")), "default"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/foo/1")), "fooScenario"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/bar/1")), "barScenario"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/foo/detail")), "fooDetailScenario"); Assert.assertEquals(scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues/bar/detail")), "barDetailScenario"); scenarioMapper.setUseDefaultMapping(false); Assert.assertThrows(CitrusRuntimeException.class, () -> scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET))); Assert.assertThrows(CitrusRuntimeException.class, () -> scenarioMapper.getMappingKey(new HttpMessage().method(HttpMethod.GET).path("/issues"))); }
Example #11
Source File: AbstractScenarioMapper.java From citrus-simulator with Apache License 2.0 | 5 votes |
@Override protected String getMappingKey(Message request) { if (properties != null && useDefaultMapping) { return properties.getDefaultScenario(); } else { throw new CitrusRuntimeException("Failed to get mapping key"); } }
Example #12
Source File: TestCaseServiceTest.java From citrus-admin with Apache License 2.0 | 5 votes |
@Test public void testGetTestDetailXml() throws Exception { reset(project); when(project.getSettings()).thenReturn(ConfigurationProvider.load(ProjectSettings.class)); when(project.getProjectHome()).thenReturn(new ClassPathResource("projects/sample").getFile().getAbsolutePath()); when(project.getAbsolutePath("foo/FooTest.xml")).thenReturn(new ClassPathResource("projects/sample/src/test/resources/foo/FooTest.xml").getFile().getAbsolutePath()); TestDetail testDetail = testCaseService.getTestDetail(project, new com.consol.citrus.admin.model.Test("foo", "FooTest", "fooTest", "FooTest", TestType.XML)); Assert.assertEquals(testDetail.getName(), "FooTest"); Assert.assertEquals(testDetail.getPackageName(), "foo"); Assert.assertEquals(testDetail.getSourceFiles().size(), 2L); Assert.assertEquals(testDetail.getSourceFiles().get(0), "foo/FooTest.java"); Assert.assertEquals(testDetail.getSourceFiles().get(1), "foo/FooTest.xml"); Assert.assertEquals(testDetail.getType(), TestType.XML); Assert.assertEquals(testDetail.getAuthor(), "Christoph"); Assert.assertEquals(testDetail.getLastModified().longValue(), 1315222929000L); Assert.assertEquals(testDetail.getDescription(), "This is a sample test"); Assert.assertTrue(testDetail.getFile().endsWith("foo/FooTest")); Assert.assertEquals(testDetail.getActions().size(), 3L); Assert.assertEquals(testDetail.getActions().get(0).getType(), "echo"); Assert.assertEquals(testDetail.getActions().get(1).getType(), "send"); Assert.assertEquals(testDetail.getActions().get(2).getType(), "send"); 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"); Assert.assertEquals(testDetail.getActions().get(1).getProperties().size(), 9L); Assert.assertEquals(testDetail.getActions().get(1).getProperties().stream().filter(property -> property.getName().equals("endpoint")).findFirst().orElseThrow(CitrusRuntimeException::new).getValue(), "sampleEndpoint"); Assert.assertEquals(testDetail.getActions().get(1).getProperties().stream().filter(property -> property.getName().equals("message")).findFirst().orElseThrow(CitrusRuntimeException::new).getValue(), "Hello"); Assert.assertEquals(testDetail.getActions().get(2).getProperties().size(), 9L); Assert.assertEquals(testDetail.getActions().get(2).getProperties().stream().filter(property -> property.getName().equals("endpoint")).findFirst().orElseThrow(CitrusRuntimeException::new).getValue(), "samplePayloadEndpoint"); Assert.assertEquals(testDetail.getActions().get(2).getProperties().stream().filter(property -> property.getName().equals("message")).findFirst().orElseThrow(CitrusRuntimeException::new).getValue(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Test xmlns=\"http://www.citrusframework.org\" xmlns:spring=\"http://www.springframework.org/schema/beans\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">Hello</Test>"); }
Example #13
Source File: TestCaseServiceTest.java From citrus-admin with Apache License 2.0 | 5 votes |
/** * Finds package by name and validates test list size. * @param testPackages * @param name * @param size */ private void assertTestPackage(List<TestGroup> testPackages, String name, long size) { TestGroup testGroup = testPackages.stream() .filter(group -> group.getName().equals(name)) .findFirst() .orElseThrow(() -> new CitrusRuntimeException("Missing test package for name: " + name)); Assert.assertEquals(testGroup.getTests().size(), size); }
Example #14
Source File: TestCaseServiceTest.java From citrus-admin with Apache License 2.0 | 5 votes |
/** * Finds package by name and provides test cases in that package as list. * @param testPackages * @param packageName * @return */ private List<com.consol.citrus.admin.model.Test> getTests(List<TestGroup> testPackages, String packageName) { return testPackages.stream() .filter(group -> group.getName().equals(packageName)) .findFirst() .orElseThrow(() -> new CitrusRuntimeException("Missing test package for name: " + packageName)) .getTests(); }
Example #15
Source File: TestFailureHook.java From yaks with Apache License 2.0 | 5 votes |
@After(order = Integer.MAX_VALUE) public void checkTestFailure(Scenario scenario) { if (scenario.isFailed()) { runner.run(new AbstractTestAction() { @Override public void doExecute(TestContext context) { context.getExceptions().add(new CitrusRuntimeException( String.format("Scenario %s:%s status %s", scenario.getId(), scenario.getLine(), scenario.getStatus().toString()))); } }); } }
Example #16
Source File: GzipServletFilter.java From syndesis with Apache License 2.0 | 5 votes |
@Override public int read() { try { return gzipStream.read(); } catch (IOException e) { throw new CitrusRuntimeException("Failed to read gzip input stream", e); } }
Example #17
Source File: GzipServletFilter.java From syndesis with Apache License 2.0 | 5 votes |
@Override public boolean isFinished() { try { return gzipStream.available() == 0; } catch (IOException e) { throw new CitrusRuntimeException("Failed to check gzip intput stream availability", e); } }
Example #18
Source File: HttpServerSteps.java From yaks with Apache License 2.0 | 5 votes |
@Given("^HTTP server \"([^\"\\s]+)\"$") public void setServer(String id) { if (!citrus.getCitrusContext().getReferenceResolver().isResolvable(id)) { throw new CitrusRuntimeException("Unable to find http server for id: " + id); } httpServer = citrus.getCitrusContext().getReferenceResolver().resolve(id, HttpServer.class); }
Example #19
Source File: HttpClientSteps.java From yaks with Apache License 2.0 | 5 votes |
@Given("^HTTP client \"([^\"\\s]+)\"$") public void setClient(String id) { if (!citrus.getCitrusContext().getReferenceResolver().isResolvable(id)) { throw new CitrusRuntimeException("Unable to find http client for id: " + id); } httpClient = citrus.getCitrusContext().getReferenceResolver().resolve(id, HttpClient.class); }
Example #20
Source File: ProjectService.java From citrus-admin with Apache License 2.0 | 5 votes |
/** * Save project information to file system. * @param project */ public void saveProjectInfo(Project project) { try (FileOutputStream fos = new FileOutputStream(project.getProjectInfoFile())) { fos.write(Jackson2ObjectMapperBuilder.json().build().writer().withDefaultPrettyPrinter().writeValueAsBytes(project)); fos.flush(); } catch (IOException e) { throw new CitrusRuntimeException("Unable to open project info file", e); } }
Example #21
Source File: JdbcSteps.java From yaks with Apache License 2.0 | 5 votes |
@Given("^(?:D|d)ata source: ([^\"\\s]+)$") public void setDataSource(String id) { if (!citrus.getCitrusContext().getReferenceResolver().isResolvable(id)) { throw new CitrusRuntimeException("Unable to find data source for id: " + id); } dataSource = citrus.getCitrusContext().getReferenceResolver().resolve(id, DataSource.class); }
Example #22
Source File: JdbcSteps.java From yaks with Apache License 2.0 | 5 votes |
@Given("^SQL query: (.+)$") public void addQueryStatement(String statement) { if (statement.trim().toUpperCase().startsWith("SELECT")) { sqlQueryStatements.add(statement); } else { throw new CitrusRuntimeException("Invalid SQL query - please use proper 'SELECT' statement"); } }
Example #23
Source File: JdbcSteps.java From yaks with Apache License 2.0 | 5 votes |
@When("^(?:execute |perform )?SQL update: (.+)$") public void executeUpdate(String statement) { if (statement.trim().toUpperCase().startsWith("SELECT")) { throw new CitrusRuntimeException("Invalid SQL update statement - please use SQL query for 'SELECT' statements"); } else { runner.run(sql(dataSource).statement(statement)); } }
Example #24
Source File: CreateIntegrationTestAction.java From yaks with Apache License 2.0 | 4 votes |
private void createIntegration(TestContext context) { final Integration.Builder integrationBuilder = new Integration.Builder() .name(context.replaceDynamicContentInString(integrationName)) .source(context.replaceDynamicContentInString(source)); if (dependencies != null && !dependencies.isEmpty()) { integrationBuilder.dependencies(Arrays.asList(context.replaceDynamicContentInString(dependencies).split(","))); } if (traits != null && !traits.isEmpty()) { final Map<String, Integration.TraitConfig> traitConfigMap = new HashMap<>(); for(String t : context.replaceDynamicContentInString(traits).split(",")){ //traitName.key=value if(!validateTraitFormat(t)) { throw new IllegalArgumentException("Trait" + t + "does not match format traitName.key=value"); } final String[] trait = t.split("\\.",2); final String[] traitConfig = trait[1].split("=", 2); if(traitConfigMap.containsKey(trait[0])) { traitConfigMap.get(trait[0]).add(traitConfig[0], traitConfig[1]); } else { traitConfigMap.put(trait[0], new Integration.TraitConfig(traitConfig[0], traitConfig[1])); } } integrationBuilder.traits(traitConfigMap); } final Integration i = integrationBuilder.build(); final CustomResourceDefinitionContext crdContext = getIntegrationCRD(); try { Map<String, Object> result = client.customResource(crdContext).createOrReplace(CamelKHelper.namespace(), mapper.writeValueAsString(i)); if (result.get("message") != null) { throw new CitrusRuntimeException(result.get("message").toString()); } } catch (IOException e) { throw new CitrusRuntimeException("Failed to create Camel-K integration via JSON object", e); } LOG.info(String.format("Successfully created Camel-K integration '%s'", i.getMetadata().getName())); }
Example #25
Source File: ScenarioMappersTest.java From citrus-simulator with Apache License 2.0 | 4 votes |
@Override public String extractMappingKey(Message request) { return Optional.ofNullable(request.getHeader(name)) .map(Object::toString) .orElseThrow(CitrusRuntimeException::new); }
Example #26
Source File: DefaultConnectionFactoryCreatorTest.java From yaks with Apache License 2.0 | 4 votes |
@Test(expected = CitrusRuntimeException.class) public void shouldHandleUnsupportedTypeInformation() { Map<String, String> connectionSettings = new LinkedHashMap<>(); connectionSettings.put("type", "org.unknown.Type"); connectionFactoryCreator.create(connectionSettings); }
Example #27
Source File: ScenarioMappersTest.java From citrus-simulator with Apache License 2.0 | 4 votes |
@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"))); }
Example #28
Source File: ActivityService.java From citrus-simulator with Apache License 2.0 | 4 votes |
private ScenarioExecution lookupScenarioExecution(TestCase testCase) { return scenarioExecutionRepository.findById(lookupScenarioExecutionId(testCase)).orElseThrow(() -> new CitrusRuntimeException(String.format("Failed to look up scenario execution for test %s", testCase.getName()))); }
Example #29
Source File: ActivityService.java From citrus-simulator with Apache License 2.0 | 4 votes |
public ScenarioExecution getScenarioExecutionById(Long id) { return scenarioExecutionRepository.findById(id).orElseThrow(() -> new CitrusRuntimeException(String.format("Failed to find scenario execution for id %s", id))); }
Example #30
Source File: MessageService.java From citrus-simulator with Apache License 2.0 | 4 votes |
public Message getMessageById(Long id) { return messageRepository.findById(id).orElseThrow(() -> new CitrusRuntimeException(String.format("Failed to find message for id %s", id))); }