@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"))); }
@Override protected String getMappingKey(Message request) { if (request instanceof HttpMessage) { String requestPath = ((HttpMessage) request).getPath(); if (requestPath != null) { for (HttpOperationScenario scenario : scenarioList) { if (scenario.getPath().equals(requestPath)) { if (scenario.getMethod().name().equals(((HttpMessage) request).getRequestMethod().name())) { return scenario.getOperation().getOperationId(); } } } for (HttpOperationScenario scenario : scenarioList) { if (pathMatcher.match(scenario.getPath(), requestPath)) { if (scenario.getMethod().name().equals(((HttpMessage) request).getRequestMethod().name())) { return scenario.getOperation().getOperationId(); } } } } } return super.getMappingKey(request); }
HttpRequestPathScenarioMapper extends AbstractScenarioMapper implements ScenarioListAware { @Override protected String getMappingKey(Message request) { if (request instanceof HttpMessage) { String requestPath = ((HttpMessage) request).getPath(); if (requestPath != null) { for (HttpOperationScenario scenario : scenarioList) { if (scenario.getPath().equals(requestPath)) { if (scenario.getMethod().name().equals(((HttpMessage) request).getRequestMethod().name())) { return scenario.getOperation().getOperationId(); } } } for (HttpOperationScenario scenario : scenarioList) { if (pathMatcher.match(scenario.getPath(), requestPath)) { if (scenario.getMethod().name().equals(((HttpMessage) request).getRequestMethod().name())) { return scenario.getOperation().getOperationId(); } } } } } return super.getMappingKey(request); } }
HttpRequestPathScenarioMapper extends AbstractScenarioMapper implements ScenarioListAware { @Override protected String getMappingKey(Message request) { if (request instanceof HttpMessage) { String requestPath = ((HttpMessage) request).getPath(); if (requestPath != null) { for (HttpOperationScenario scenario : scenarioList) { if (scenario.getPath().equals(requestPath)) { if (scenario.getMethod().name().equals(((HttpMessage) request).getRequestMethod().name())) { return scenario.getOperation().getOperationId(); } } } for (HttpOperationScenario scenario : scenarioList) { if (pathMatcher.match(scenario.getPath(), requestPath)) { if (scenario.getMethod().name().equals(((HttpMessage) request).getRequestMethod().name())) { return scenario.getOperation().getOperationId(); } } } } } return super.getMappingKey(request); }  }
HttpRequestPathScenarioMapper extends AbstractScenarioMapper implements ScenarioListAware { @Override protected String getMappingKey(Message request) { if (request instanceof HttpMessage) { String requestPath = ((HttpMessage) request).getPath(); if (requestPath != null) { for (HttpOperationScenario scenario : scenarioList) { if (scenario.getPath().equals(requestPath)) { if (scenario.getMethod().name().equals(((HttpMessage) request).getRequestMethod().name())) { return scenario.getOperation().getOperationId(); } } } for (HttpOperationScenario scenario : scenarioList) { if (pathMatcher.match(scenario.getPath(), requestPath)) { if (scenario.getMethod().name().equals(((HttpMessage) request).getRequestMethod().name())) { return scenario.getOperation().getOperationId(); } } } } } return super.getMappingKey(request); }  List<HttpOperationScenario> getHttpScenarios(); void setHttpScenarios(List<HttpOperationScenario> httpScenarios); @Override void setScenarioList(List<SimulatorScenario> scenarioList); void setConfiguration(SimulatorConfigurationProperties configuration); }
HttpRequestPathScenarioMapper extends AbstractScenarioMapper implements ScenarioListAware { @Override protected String getMappingKey(Message request) { if (request instanceof HttpMessage) { String requestPath = ((HttpMessage) request).getPath(); if (requestPath != null) { for (HttpOperationScenario scenario : scenarioList) { if (scenario.getPath().equals(requestPath)) { if (scenario.getMethod().name().equals(((HttpMessage) request).getRequestMethod().name())) { return scenario.getOperation().getOperationId(); } } } for (HttpOperationScenario scenario : scenarioList) { if (pathMatcher.match(scenario.getPath(), requestPath)) { if (scenario.getMethod().name().equals(((HttpMessage) request).getRequestMethod().name())) { return scenario.getOperation().getOperationId(); } } } } } return super.getMappingKey(request); }  List<HttpOperationScenario> getHttpScenarios(); void setHttpScenarios(List<HttpOperationScenario> httpScenarios); @Override void setScenarioList(List<SimulatorScenario> scenarioList); void setConfiguration(SimulatorConfigurationProperties configuration);  }