@Test public void complexFieldPropertyErrorMessage() { PropertyMatches matches = PropertyMatches.forField("counter", SampleFieldProperties.class); String msg = matches.buildErrorMessage(); assertThat(msg, containsString("counter")); assertThat(msg, containsString("counter1")); assertThat(msg, containsString("counter2")); assertThat(msg, containsString("counter3")); }
private void assertToStringForWebMappingWithPathAndValue(WebMapping webMapping) { String string = webMapping.toString(); assertThat(string, startsWith("@" + WebMapping.class.getName() + "(")); assertThat(string, containsString("value=[/test]")); assertThat(string, containsString("path=[/test]")); assertThat(string, containsString("name=bar")); assertThat(string, containsString("method=")); assertThat(string, containsString("[GET, POST]")); assertThat(string, endsWith(")")); }
@Test public void headerContainsWithMissingHeader() throws Exception { AssertionError error = assertThrows(AssertionError.class, () -> MockRestRequestMatchers.header("foo", containsString("baz")).match(this.request)); assertThat(error.getMessage(), containsString("but was null")); }
@Override public void perform() { given(). then(). statusCode(Status.OK.getStatusCode()). header("Allow", allOf( containsString("GET"), containsString("OPTIONS"), containsString("POST"), containsString("PUT"), containsString("DELETE"), containsString("PATCH"))). when(). options(testURL.toExternalForm()); } }).inspect(new SetupAuth(new User("testuser")));
@Test public void synthesizeAnnotationWithAttributeAliasForAttributeOfDifferentType() throws Exception { AliasForAttributeOfDifferentType annotation = AliasForAttributeOfDifferentTypeClass.class.getAnnotation(AliasForAttributeOfDifferentType.class); exception.expect(AnnotationConfigurationException.class); exception.expectMessage(startsWith("Misconfigured aliases")); exception.expectMessage(containsString(AliasForAttributeOfDifferentType.class.getName())); exception.expectMessage(containsString("attribute 'foo'")); exception.expectMessage(containsString("attribute 'bar'")); exception.expectMessage(containsString("same return type")); synthesizeAnnotation(annotation); }
@Test public void complexBeanPropertyErrorMessage() { PropertyMatches matches = PropertyMatches.forProperty("counter", SampleBeanProperties.class); String msg = matches.buildErrorMessage(); assertThat(msg, containsString("counter")); assertThat(msg, containsString("counter1")); assertThat(msg, containsString("counter2")); assertThat(msg, containsString("counter3")); }
@Override public void perform() { given(). then(). statusCode(Status.OK.getStatusCode()). header("Allow", allOf( not(containsString("POST")), not(containsString("PUT")), not(containsString("DELETE")), not(containsString("PATCH")))). when(). options(testURL.toExternalForm()); } }).inspect(new SetupAuth(null));
private void assertExceptionContainsFullyQualifiedPath(ClassPathResource resource) { try { resource.getInputStream(); fail("FileNotFoundException expected for resource: " + resource); } catch (IOException ex) { assertThat(ex, instanceOf(FileNotFoundException.class)); assertThat(ex.getMessage(), containsString(FQ_RESOURCE_PATH)); } }
@Test public void synthesizeAnnotationWithAttributeAliasForWithMissingDefaultValues() throws Exception { AliasForWithMissingDefaultValues annotation = AliasForWithMissingDefaultValuesClass.class.getAnnotation(AliasForWithMissingDefaultValues.class); exception.expect(AnnotationConfigurationException.class); exception.expectMessage(startsWith("Misconfigured aliases")); exception.expectMessage(containsString(AliasForWithMissingDefaultValues.class.getName())); exception.expectMessage(containsString("attribute 'foo' in annotation")); exception.expectMessage(containsString("attribute 'bar' in annotation")); exception.expectMessage(containsString("default values")); synthesizeAnnotation(annotation); }
@Test public void simpleBeanPropertyErrorMessage() { PropertyMatches matches = PropertyMatches.forProperty("naem", SampleBeanProperties.class); String msg = matches.buildErrorMessage(); assertThat(msg, containsString("naem")); assertThat(msg, containsString("name")); assertThat(msg, containsString("setter")); assertThat(msg, not(containsString("field"))); }
@Test public void shouldProvideOptions() throws Exception { given(). then(). statusCode(Response.Status.OK.getStatusCode()). headers("Allow", containsString("GET")). headers("Allow", not(containsString("POST"))). when(). options(baseURL + "api/test"); } }
private MockResponse formRequest(RecordedRequest request) { assertEquals("application/x-www-form-urlencoded;charset=UTF-8", request.getHeader("Content-Type")); String body = request.getBody().readUtf8(); assertThat(body, Matchers.containsString("name+1=value+1")); assertThat(body, Matchers.containsString("name+2=value+2%2B1")); assertThat(body, Matchers.containsString("name+2=value+2%2B2")); return new MockResponse().setResponseCode(200); }
@Test public void headerContainsWithMissingValue() throws Exception { this.request.getHeaders().put("foo", Arrays.asList("bar", "baz")); AssertionError error = assertThrows(AssertionError.class, () -> MockRestRequestMatchers.header("foo", containsString("bx")).match(this.request)); assertThat(error.getMessage(), containsString("was \"bar\"")); }
@Test public void simpleFieldPropertyErrorMessage() { PropertyMatches matches = PropertyMatches.forField("naem", SampleFieldProperties.class); String msg = matches.buildErrorMessage(); assertThat(msg, containsString("naem")); assertThat(msg, containsString("name")); assertThat(msg, containsString("field")); assertThat(msg, not(containsString("setter"))); }
@Test @Ignore("manual test cause the Aspect need to have this class in it's cutpoint") public void testException() { // checks that the RuntimeException is converted to a TalendRuntimeException by the aspect given() // .expect() // .statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).log().ifValidationFails() // .when()// .get("/tests/exception")// .then()// .body("code", containsString(CommonErrorCodes.UNEXPECTED_EXCEPTION.toString())) .body("message", equalTo("global_error_test")); }
@Test public void queryParamMissingValue() throws Exception { this.request.setURI(new URI("http://foo.com/a?foo=bar&foo=baz")); AssertionError error = assertThrows(AssertionError.class, () -> MockRestRequestMatchers.queryParam("foo", "bad").match(this.request)); assertThat(error.getMessage(), containsString("expected:<bad> but was:<bar>")); }
@Test public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); assertThat(code, containsString("private class Inner {")); assertThat(code, containsString("return new TestOuterConstructorCall$TestCls(this);")); assertThat(code, not(containsString("synthetic"))); } }
@Test public void testGetConnectors_badDefinition() throws Exception { given().expect() // .statusCode(400) // .log().ifValidationFails() // // TODO: check returned error .body(Matchers.containsString("definitionClass")) // .get(getVersionPrefix() + "/properties/{name}/connectors", DATA_SET_DEFINITION_NAME); }
@Test public void synthesizeAnnotationWithAttributeAliasWithMirroredAliasForWrongAttribute() throws Exception { AliasForWithMirroredAliasForWrongAttribute annotation = AliasForWithMirroredAliasForWrongAttributeClass.class.getAnnotation(AliasForWithMirroredAliasForWrongAttribute.class); exception.expect(AnnotationConfigurationException.class); exception.expectMessage(startsWith("Attribute 'bar' in")); exception.expectMessage(containsString(AliasForWithMirroredAliasForWrongAttribute.class.getName())); exception.expectMessage(either(containsString("must be declared as an @AliasFor [foo], not [quux]")). or(containsString("is declared as an @AliasFor nonexistent attribute 'quux'"))); synthesizeAnnotation(annotation); }
@Test public void description() { Resource resource = new PathResource(TEST_FILE); assertThat(resource.getDescription(), containsString("path [")); assertThat(resource.getDescription(), containsString(TEST_FILE)); }