@Test public void testThriftServiceRegistrationBean() throws Exception { final HelloService.Iface client = Clients.newClient(newUrl("tbinary+h1c") + "/thrift", HelloService.Iface.class); assertThat(client.hello("world")).isEqualTo("hello world"); final HttpClient httpClient = HttpClient.of(newUrl("h1c")); final HttpResponse response = httpClient.get("/internal/docs/specification.json"); final AggregatedHttpMessage msg = response.aggregate().get(); assertThat(msg.status()).isEqualTo(HttpStatus.OK); assertThatJson(msg.content().toStringUtf8()) .node("services[1].exampleHttpHeaders[0].x-additional-header").isStringEqualTo("headerVal"); }
@Test public void failure() { final AggregatedHttpMessage response = client.get("/hello/a").aggregate().join(); assertThat(response.status()).isEqualTo(HttpStatus.BAD_REQUEST); assertThatJson(response.content().toStringUtf8()) .node("message") .isEqualTo("hello.name: name should have between 3 and 10 characters"); } }
@Test public void testMessageConverterService() { AggregatedHttpMessage res; String body; // JSON for (final String path : Arrays.asList("/messageConverter/node/node", "/messageConverter/node/obj", "/messageConverter/obj/obj", "/messageConverter/obj/future")) { res = client.execute(HttpHeaders.of(HttpMethod.POST, path) .contentType(MediaType.JSON_UTF_8), "{\"name\":\"armeria\"}").aggregate().join(); assertThat(res.status()).isEqualTo(HttpStatus.OK); assertThat(res.headers().contentType().is(MediaType.JSON_UTF_8)).isTrue(); body = res.content().toStringUtf8(); assertThatJson(body).node("result").isStringEqualTo("success"); assertThatJson(body).node("from").isStringEqualTo("armeria"); } // custom(text protocol) res = client.execute(HttpHeaders.of(HttpMethod.POST, "/messageConverter/custom") .contentType(MediaType.PLAIN_TEXT_UTF_8), "armeria").aggregate().join(); assertThat(res.status()).isEqualTo(HttpStatus.OK); assertThat(res.headers().contentType().is(MediaType.PLAIN_TEXT_UTF_8)).isTrue(); assertThat(res.content().toStringUtf8()).isEqualTo("success:armeria"); }
@Test void isStringShouldFailOnNull() { assertThatThrownBy(() -> assertThatJson("{\"test\":null}").node("test").isStringEqualTo("1")) .hasMessage("Node \"test\" has invalid type, expected: <string> but was: <null>."); }
@Test void equalsShouldFailOnStringAndANumber() { assertThatThrownBy(() -> assertThatJson("{\"test\":\"1\"}").node("test").isEqualTo("1")) .hasMessage("JSON documents are different:\n" + "Different value found in node \"test\", expected: <1> but was: <\"1\">.\n"); }
@Test void intValueShouldFailIfDoesNotMatch() { assertThatThrownBy(() -> assertThatJson("{\"test\":1}").node("test").matches(equalTo(valueOf(2)))) .hasMessage("Node \"test\" does not match.\nExpected: <2>\n but: was <1>"); }
@Test void shouldReportMissingArrayItemsWhenIgnoringOrder() { assertThatThrownBy(() -> assertThatJson("{\"test\":[1]}").node("test").when(IGNORING_ARRAY_ORDER).isEqualTo("[1, 2, 3]")) .hasMessage("JSON documents are different:\n" + "Array \"test\" has different length, expected: <3> but was: <1>.\n" + "Array \"test\" has different content. Missing values: [2, 3], extra values: [], expected: <[1,2,3]> but was: <[1]>\n"); }
@Test void testNodeAbsent() { assertThatThrownBy(() -> assertThatJson("{\"test1\":2, \"test2\":1}").node("test2").isAbsent()) .hasMessage("Different value found in node \"test2\", expected: <node to be absent> but was: <1>."); }
@Test void testMoreNodes() { assertThatThrownBy(() -> assertThatJson("{\"test1\":2, \"test2\":1}").node("test1").isEqualTo(2).node("test2").isEqualTo(2)) .hasMessage("JSON documents are different:\nDifferent value found in node \"test2\", expected: <2> but was: <1>.\n"); }
@Test void shouldAcceptEscapedPathAndShowCorrectErrorMessage() { assertThatThrownBy(() -> assertThatJson("{\"foo.bar\":\"boo\"}").node("foo\\.bar").isEqualTo("baz")) .hasMessage("JSON documents are different:\n" + "Different value found in node \"foo\\.bar\", expected: <\"baz\"> but was: <\"boo\">.\n"); }
@Test void isObjectShouldFailOnMissing() { assertThatThrownBy(() -> assertThatJson("{\"test\":{\"a\":true}}").node("test.b").isObject()) .hasMessage("Different value found in node \"test.b\", expected: <object> but was: <missing>."); }
@Test void stringValueShouldFailIfDoesNotMatch() { assertThatThrownBy(() -> assertThatJson("{\"test\":\"one\"}").node("test").matches(equalTo("two"))) .hasMessage("Node \"test\" does not match.\nExpected: \"two\"\n but: was \"one\""); }
@Test void floatValueShouldFailIfDoesNotMatch() { assertThatThrownBy(() -> assertThatJson("{\"test\":1}").node("test").matches(equalTo(valueOf(2)))) .hasMessage("Node \"test\" does not match.\nExpected: <2>\n but: was <1>"); }
@Test void shouldReportExtraArrayItemsWhenNotIgnoringOrder() { assertThatThrownBy(() -> assertThatJson("{\"test\":[1,2,3]}").node("test").isEqualTo("[1]")) .hasMessage("JSON documents are different:\n" + "Array \"test\" has different length, expected: <1> but was: <3>.\n" + "Array \"test\" has different content. Extra values: [2, 3], expected: <[1]> but was: <[1,2,3]>\n"); }
@Test void isPresentShouldTreatNullAsAbsentWhenSpecified() { assertThatThrownBy(() -> assertThatJson("{\"test1\":2, \"test2\":null}").when(TREATING_NULL_AS_ABSENT).node("test2").isPresent()) .hasMessage("Different value found in node \"test2\", expected: <node to be present> but was: <missing>."); }
@Test void testNodePresent() { assertThatThrownBy(() -> assertThatJson("{\"test1\":2, \"test2\":1}").node("test3").isPresent()) .hasMessage("Different value found in node \"test3\", expected: <node to be present> but was: <missing>."); }
public SELF hasJsonMessage(String message) throws UnsupportedEncodingException { JsonFluentAssert.assertThatJson(actual.getContentAsString()).node("message").isEqualTo(message); return myself; }
public SELF hasJsonAttribute(String attribute, Object object) throws UnsupportedEncodingException { JsonFluentAssert.assertThatJson(actual.getContentAsString()).node(attribute).isEqualTo(object); return myself; }
@Test public void shouldMigrateV1ToV2_ByChangingEnablePipelineLockingTrue_To_LockBehaviorLockOnFailure() throws Exception { ConfigRepoDocumentMother documentMother = new ConfigRepoDocumentMother(); String oldJSON = documentMother.versionOneWithLockingSetTo(true); String transformedJSON = migrator.migrate(oldJSON, 2); assertThatJson(transformedJSON).node("target_version").isEqualTo("\"2\""); assertThatJson(transformedJSON).node("pipelines[0].name").isEqualTo("firstpipe"); assertThatJson(transformedJSON).node("pipelines[0].lock_behavior").isEqualTo("lockOnFailure"); assertThatJson(transformedJSON).node("errors").isArray().ofLength(0); }
@Test public void shouldMigrateV1ToV2_ByChangingEnablePipelineLockingFalse_To_LockBehaviorNone() throws Exception { ConfigRepoDocumentMother documentMother = new ConfigRepoDocumentMother(); String oldJSON = documentMother.versionOneWithLockingSetTo(false); String transformedJSON = migrator.migrate(oldJSON, 2); assertThatJson(transformedJSON).node("target_version").isEqualTo("\"2\""); assertThatJson(transformedJSON).node("pipelines[0].name").isEqualTo("firstpipe"); assertThatJson(transformedJSON).node("pipelines[0].lock_behavior").isEqualTo("none"); assertThatJson(transformedJSON).node("errors").isArray().ofLength(0); }