diff options
author | jonmv <venstad@gmail.com> | 2022-12-07 16:29:50 +0100 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2022-12-07 16:29:50 +0100 |
commit | fe296c7af938127815e2c33e3e816546aa82f0a3 (patch) | |
tree | 8d56fcb4f0daf628ee134c0b4bc9d4de01021a85 /vespa-feed-client | |
parent | 7e3f8b212a589cbdb196fb4f4b0a7a81b4b7af13 (diff) |
Avoid platform-specific error message in test
Diffstat (limited to 'vespa-feed-client')
-rw-r--r-- | vespa-feed-client/src/test/java/ai/vespa/feed/client/impl/HttpFeedClientTest.java | 105 |
1 files changed, 54 insertions, 51 deletions
diff --git a/vespa-feed-client/src/test/java/ai/vespa/feed/client/impl/HttpFeedClientTest.java b/vespa-feed-client/src/test/java/ai/vespa/feed/client/impl/HttpFeedClientTest.java index f2298a322fe..a0b3049c2a0 100644 --- a/vespa-feed-client/src/test/java/ai/vespa/feed/client/impl/HttpFeedClientTest.java +++ b/vespa-feed-client/src/test/java/ai/vespa/feed/client/impl/HttpFeedClientTest.java @@ -88,26 +88,27 @@ class HttpFeedClientTest { assertNull(request.body()); HttpResponse response = HttpResponse.of(412, - ("{\n" + - " \"pathId\": \"/document/v1/ns/type/docid/0\",\n" + - " \"id\": \"id:ns:type::0\",\n" + - " \"message\": \"Relax, take it easy.\",\n" + - " \"trace\": [\n" + - " {\n" + - " \"message\": \"For there is nothing that we can do.\"\n" + - " },\n" + - " {\n" + - " \"fork\": [\n" + - " {\n" + - " \"message\": \"Relax, take is easy.\"\n" + - " },\n" + - " {\n" + - " \"message\": \"Blame it on me or blame it on you.\"\n" + - " }\n" + - " ]\n" + - " }\n" + - " ]\n" + - "}").getBytes(UTF_8)); + (""" + { + "pathId": "/document/v1/ns/type/docid/0", + "id": "id:ns:type::0", + "message": "Relax, take it easy.", + "trace": [ + { + "message": "For there is nothing that we can do." + }, + { + "fork": [ + { + "message": "Relax, take is easy." + }, + { + "message": "Blame it on me or blame it on you." + } + ] + } + ] + }""").getBytes(UTF_8)); return CompletableFuture.completedFuture(response); } catch (Throwable thrown) { @@ -122,21 +123,22 @@ class HttpFeedClientTest { assertEquals(Result.Type.conditionNotMet, result.type()); assertEquals(id, result.documentId()); assertEquals(Optional.of("Relax, take it easy."), result.resultMessage()); - assertEquals(Optional.of("[\n" + - " {\n" + - " \"message\": \"For there is nothing that we can do.\"\n" + - " },\n" + - " {\n" + - " \"fork\": [\n" + - " {\n" + - " \"message\": \"Relax, take is easy.\"\n" + - " },\n" + - " {\n" + - " \"message\": \"Blame it on me or blame it on you.\"\n" + - " }\n" + - " ]\n" + - " }\n" + - " ]"), result.traceMessage()); + assertEquals(Optional.of(""" + [ + { + "message": "For there is nothing that we can do." + }, + { + "fork": [ + { + "message": "Relax, take is easy." + }, + { + "message": "Blame it on me or blame it on you." + } + ] + } + ]"""), result.traceMessage()); // Put is a POST, and a Vespa error is a ResultException. dispatch.set((documentId, request) -> { @@ -147,12 +149,13 @@ class HttpFeedClientTest { assertEquals("json", new String(request.body(), UTF_8)); HttpResponse response = HttpResponse.of(502, - ("{\n" + - " \"pathId\": \"/document/v1/ns/type/docid/0\",\n" + - " \"id\": \"id:ns:type::0\",\n" + - " \"message\": \"Ooops! ... I did it again.\",\n" + - " \"trace\": [ { \"message\": \"I played with your heart. Got lost in the game.\" } ]\n" + - "}").getBytes(UTF_8)); + (""" + { + "pathId": "/document/v1/ns/type/docid/0", + "id": "id:ns:type::0", + "message": "Ooops! ... I did it again.", + "trace": [ { "message": "I played with your heart. Got lost in the game." } ] + }""").getBytes(UTF_8)); return CompletableFuture.completedFuture(response); } catch (Throwable thrown) { @@ -184,12 +187,13 @@ class HttpFeedClientTest { assertEquals("json", new String(request.body(), UTF_8)); HttpResponse response = HttpResponse.of(500, - ("{\n" + - " \"pathId\": \"/document/v1/ns/type/docid/0\",\n" + - " \"id\": \"id:ns:type::0\",\n" + - " \"message\": \"Alla ska i jorden.\",\n" + - " \"trace\": [ { \"message\": \"Din tid den kom, och senn så for den.\" } ]\n" + - "}").getBytes(UTF_8)); + (""" + { + "pathId": "/document/v1/ns/type/docid/0", + "id": "id:ns:type::0", + "message": "Alla ska i jorden.", + "trace": [ { "message": "Din tid den kom, och senn så for den." } ] + }""").getBytes(UTF_8)); return CompletableFuture.completedFuture(response); } catch (Throwable thrown) { @@ -208,10 +212,9 @@ class HttpFeedClientTest { @Test void testHandshake() { - assertEquals("failed handshake with server: java.net.UnknownHostException: dummy: nodename nor servname provided, or not known", - assertThrows(FeedException.class, - () -> new HttpFeedClient(new FeedClientBuilderImpl(Collections.singletonList(URI.create("https://dummy:123"))), null)) - .getMessage()); + assertTrue(assertThrows(FeedException.class, + () -> new HttpFeedClient(new FeedClientBuilderImpl(Collections.singletonList(URI.create("https://dummy:123"))), null)) + .getMessage().startsWith("failed handshake with server: java.net.UnknownHostException")); } } |