WilmaStub { @Override public String toString() { String generatedName = "generated name"; String conditionContent = ""; if (requestCondition != null) { conditionContent = requestCondition.toString(); } String responseContent = ""; String usedTemplate = ""; if (responseDescriptor != null) { responseContent = responseDescriptor.responseDescriptorToString(); usedTemplate = responseDescriptor.templateToString(); } String stubConfigurationFormatterString = "{ \"wilmaStubConfiguration\": { \n" + " \"groupName\": \"" + groupName + "\""; if (responseDescriptor != null) { stubConfigurationFormatterString += ",\n \"dialogDescriptors\": [{ \"name\": \"" + generatedName + "\"," + " \"usage\": \"always\", \"comment\": \"" + generatedName + "\"," + "\n \"conditionDescriptor\": " + conditionContent + ",\n \"responseDescriptor\": " + responseContent + "}]," + "\n \"templates\": [ " + usedTemplate + " ]"; } if (interceptorDescriptor != null) { stubConfigurationFormatterString += ",\n " + interceptorDescriptor.toString(); } stubConfigurationFormatterString += "\n }\n}"; return stubConfigurationFormatterString; } WilmaStub(String groupName, RequestCondition requestCondition, ResponseDescriptor responseDescriptor, InterceptorDescriptor interceptorDescriptor); @Override String toString(); void validateConfiguration(); String getGroupName();  }
@Test public void testCreateStubSimpleMockFromJsonFile() throws StubConfigurationException { wilmaStub = new WilmaStubBuilder() .forRequestsLike().textInUrl("/blah") .willRespondWith().jsonFileResponse("filename").withStatus(200) .build(); Assert.assertTrue(wilmaStub.toString().contains("application/json"), "Bad mime type was set."); }
@Test public void testCreateStubSimpleMockFromXmlFile() throws StubConfigurationException { wilmaStub = new WilmaStubBuilder() .forRequestsLike().textInUrl("/blah") .willRespondWith().xmlFileResponse("filename").withStatus(200) .build(); Assert.assertTrue(wilmaStub.toString().contains("application/xml"), "Bad mime type was set."); Assert.assertTrue(!wilmaStub.toString().contains("interceptor"), "Should not contain any interceptor related entry."); }
@Test public void testCreateStubOfInterceptorA() throws StubConfigurationException { ConfigurationParameter[] conditionParameters = new ConfigurationParameter[1]; conditionParameters[0] = new ConfigurationParameter("somewhereinheader"); ConfigurationParameterArray configurationParameterArray = new ConfigurationParameterArray(conditionParameters); wilmaStub = new WilmaStubBuilder() .forRequestsLike().textInUrl("/blah") .willRespondWith().xmlFileResponse("filename").withStatus(200) .addInterceptor("interceptorName", "interceptorClass") .addInterceptor("interceptorName", "interceptorClass", configurationParameterArray) .build(); Assert.assertTrue(wilmaStub.toString().contains("application/xml"), "Bad mime type was set."); }
@Test public void testCreateStubOfInterceptorB() throws StubConfigurationException { ConfigurationParameter[] conditionParameters = new ConfigurationParameter[1]; conditionParameters[0] = new ConfigurationParameter("somewhereinheader"); ConfigurationParameterArray configurationParameterArray = new ConfigurationParameterArray(conditionParameters); wilmaStub = new WilmaStubBuilder() .forRequestsLike().textInUrl("/blah") .willRespondWith().xmlFileResponse("filename").withStatus(200) .addInterceptor("interceptorName", "interceptorClass", configurationParameterArray) .addInterceptor("interceptorName", "interceptorClass") .build(); Assert.assertTrue(wilmaStub.toString().contains("application/xml"), "Bad mime type was set."); }
@Test public void testCreateStubOfInterceptorMinimalA() throws StubConfigurationException { wilmaStub = new WilmaStubBuilder() .addInterceptor("interceptorName", "interceptorClass") .build(); Assert.assertTrue(wilmaStub.toString().contains("interceptorName"), "Interceptor is missing."); }
@Test public void testCreateStubOfInterceptorMinimalB() throws StubConfigurationException { ConfigurationParameter[] conditionParameters = new ConfigurationParameter[1]; conditionParameters[0] = new ConfigurationParameter("somewhereinheader"); ConfigurationParameterArray configurationParameterArray = new ConfigurationParameterArray(conditionParameters); wilmaStub = new WilmaStubBuilder() .addInterceptor("interceptorName", "interceptorClass", configurationParameterArray) .build(); Assert.assertTrue(wilmaStub.toString().contains("interceptorName"), "Interceptor is missing."); }
@Test public void testCreateStubSimpleMockFromHtmlFile() throws StubConfigurationException { wilmaStub = new WilmaStubBuilder() .forRequestsLike().textInUrl("/blah") .willRespondWith().htmlFileResponse("filename").withStatus(200) .build(); Assert.assertTrue(wilmaStub.toString().contains("text/html"), "Bad mime type was set."); }
@Test public void testCreateStubSimpleMockFromTextFile() throws StubConfigurationException { wilmaStub = new WilmaStubBuilder() .forRequestsLike().textInUrl("/blah") .willRespondWith().textFileResponse("filename").withStatus(200) .build(); Assert.assertTrue(wilmaStub.toString().contains("text/plain"), "Bad mime type was set."); }