diff options
author | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2022-07-29 14:27:17 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@yahooinc.com> | 2022-07-29 14:27:17 +0200 |
commit | ab58e59d91f626fcf99df282029337576820bee5 (patch) | |
tree | cc8a1ba9585493c6dcbbd5759c2f52198e8c179b /clustercontroller-utils | |
parent | 7312f8968060ef3fc9b1e64ac74dd4144ff2bf74 (diff) |
Convert clustercontroller-utils to junit5
Diffstat (limited to 'clustercontroller-utils')
12 files changed, 279 insertions, 271 deletions
diff --git a/clustercontroller-utils/pom.xml b/clustercontroller-utils/pom.xml index a1f0b1c21c2..0d8e30d3693 100644 --- a/clustercontroller-utils/pom.xml +++ b/clustercontroller-utils/pom.xml @@ -14,11 +14,6 @@ <packaging>container-plugin</packaging> <dependencies> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.codehaus.jettison</groupId> <artifactId>jettison</artifactId> </dependency> @@ -35,6 +30,16 @@ <scope>provided</scope> </dependency> <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <scope>provided</scope> diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/async/AsyncTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/async/AsyncTest.java index 7cea1adced6..739b8d4bf15 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/async/AsyncTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/async/AsyncTest.java @@ -1,19 +1,20 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.utils.communication.async; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.LinkedList; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class AsyncTest { @Test - public void testListeners() { + void testListeners() { AsyncOperationImpl<String> op = new AsyncOperationImpl<>("test"); class Listener implements AsyncCallback<String> { boolean called = false; + @Override public void done(AsyncOperation<String> op) { called = true; @@ -40,7 +41,7 @@ public class AsyncTest { } @Test - public void testMultipleResultSetters() { + void testMultipleResultSetters() { { AsyncOperationImpl<String> op = new AsyncOperationImpl<>("test"); op.setResult("foo"); @@ -65,7 +66,7 @@ public class AsyncTest { } @Test - public void testPartialResultOnFailure() { + void testPartialResultOnFailure() { AsyncOperationImpl<String> op = new AsyncOperationImpl<>("test"); op.setFailure(new Exception("bar"), "foo"); assertEquals("foo", op.getResult()); @@ -74,14 +75,16 @@ public class AsyncTest { } @Test - public void testListenImpl() { + void testListenImpl() { class ListenImpl extends AsyncOperationListenImpl<String> { public ListenImpl(AsyncOperation<String> op) { super(op); } - }; + } + ; class Listener implements AsyncCallback<String> { int calls = 0; + @Override public void done(AsyncOperation<String> op) { ++calls; @@ -98,7 +101,7 @@ public class AsyncTest { } @Test - public void testRedirectedOperation() { + void testRedirectedOperation() { { final AsyncOperationImpl<String> op = new AsyncOperationImpl<>("test", "desc"); AsyncOperation<Integer> deleteRequest = new RedirectedAsyncOperation<String, Integer>(op) { @@ -147,7 +150,7 @@ public class AsyncTest { } @Test - public void testRedirectOnSuccessOperation() { + void testRedirectOnSuccessOperation() { { final AsyncOperationImpl<Integer> target = new AsyncOperationImpl<>("foo"); SuccessfulAsyncCallback<String, Integer> callback = new SuccessfulAsyncCallback<String, Integer>(target) { @@ -243,17 +246,17 @@ public class AsyncTest { } @Test - public void testStressCompletionAndRegisterToDetectRace() throws Exception { + void testStressCompletionAndRegisterToDetectRace() throws Exception { int iterations = 1000; Object monitor = new Object(); Completer completer = new Completer(monitor); Listener listener = new Listener(monitor); Thread t1 = new Thread(completer); Thread t2 = new Thread(listener); - try{ + try { t1.start(); t2.start(); - for (int i=0; i<iterations; ++i) { + for (int i = 0; i < iterations; ++i) { AsyncOperationImpl<String> op = new AsyncOperationImpl<>("test"); synchronized (monitor) { completer.op = op; @@ -261,7 +264,10 @@ public class AsyncTest { monitor.notifyAll(); } while (completer.op != null || listener.op != null) { - try{ Thread.sleep(0); } catch (InterruptedException e) {} + try { + Thread.sleep(0); + } catch (InterruptedException e) { + } } } } finally { diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpRequestTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpRequestTest.java index 2583c3392c4..41328494f52 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpRequestTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpRequestTest.java @@ -1,11 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.utils.communication.http; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class HttpRequestTest { @@ -21,7 +19,7 @@ public class HttpRequestTest { } @Test - public void testEquality() { + void testEquality() { assertEquals(createRequest(), createRequest()); assertNotSame(createRequest(), createRequest().setHost("localhost")); assertNotSame(createRequest(), createRequest().setPort(40)); @@ -31,16 +29,16 @@ public class HttpRequestTest { } @Test - public void testVerifyComplete() { + void testVerifyComplete() { // To be a complete request, an HTTP request must include: // - A path // - The HTTP operation type - try{ + try { new HttpRequest().setPath("/foo").verifyComplete(); assertTrue(false); } catch (IllegalStateException e) { } - try{ + try { new HttpRequest().setHttpOperation(HttpRequest.HttpOp.GET).verifyComplete(); assertTrue(false); } catch (IllegalStateException e) { @@ -49,7 +47,7 @@ public class HttpRequestTest { } @Test - public void testMerge() { + void testMerge() { { HttpRequest base = new HttpRequest() .setHttpOperation(HttpRequest.HttpOp.POST) @@ -92,25 +90,25 @@ public class HttpRequestTest { } @Test - public void testNonExistingHeader() { + void testNonExistingHeader() { assertEquals("foo", new HttpRequest().getHeader("asd", "foo")); assertEquals("foo", new HttpRequest().addHttpHeader("bar", "foo").getHeader("asd", "foo")); } @Test - public void testOption() { + void testOption() { assertEquals("bar", new HttpRequest().addUrlOption("foo", "bar").getOption("foo", "foo")); assertEquals("foo", new HttpRequest().getOption("asd", "foo")); } @Test - public void testToString() { + void testToString() { assertEquals("GET? http://localhost:8080/", - new HttpRequest() - .setScheme("http") - .setHost("localhost") - .setPort(8080) - .toString(true)); + new HttpRequest() + .setScheme("http") + .setHost("localhost") + .setPort(8080) + .toString(true)); assertEquals("POST http://localhost/", new HttpRequest() .setScheme("http") @@ -127,7 +125,7 @@ public class HttpRequestTest { } @Test - public void testNothingButGetCoverage() { + void testNothingButGetCoverage() { assertEquals(false, new HttpRequest().equals(new Object())); new HttpRequest().getHeaders(); new HttpRequest().setUrlOptions(new HttpRequest().getUrlOptions()); diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpResultTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpResultTest.java index 59fd4521efb..3a08d735a4e 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpResultTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/HttpResultTest.java @@ -1,14 +1,14 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.utils.communication.http; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class HttpResultTest { @Test - public void testSuccess() { + void testSuccess() { assertEquals(false, new HttpResult().setHttpCode(199, "foo").isSuccess()); assertEquals(true, new HttpResult().setHttpCode(200, "foo").isSuccess()); assertEquals(true, new HttpResult().setHttpCode(299, "foo").isSuccess()); @@ -16,7 +16,7 @@ public class HttpResultTest { } @Test - public void testToString() { + void testToString() { assertEquals("HTTP 200/OK", new HttpResult().setContent("Foo").toString()); assertEquals("HTTP 200/OK\n\nFoo", new HttpResult().setContent("Foo").toString(true)); assertEquals("HTTP 200/OK", new HttpResult().toString(true)); @@ -24,7 +24,7 @@ public class HttpResultTest { } @Test - public void testNothingButGetCoverage() { + void testNothingButGetCoverage() { new HttpResult().getHeaders(); } diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/JsonHttpResultTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/JsonHttpResultTest.java index 2e8f9ea9b58..19fc27669af 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/JsonHttpResultTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/JsonHttpResultTest.java @@ -3,31 +3,31 @@ package com.yahoo.vespa.clustercontroller.utils.communication.http; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class JsonHttpResultTest { @Test - public void testCopyConstructor() { + void testCopyConstructor() { assertEquals("{}", new JsonHttpResult(new HttpResult()).getJson().toString()); } @Test - public void testOutput() { + void testOutput() { assertEquals("HTTP 200/OK\n" - + "\n" - + "JSON: {\"foo\": 3}", - new JsonHttpResult(new HttpResult().setContent("{ \"foo\" : 3 }")).toString(true)); + + "\n" + + "JSON: {\"foo\": 3}", + new JsonHttpResult(new HttpResult().setContent("{ \"foo\" : 3 }")).toString(true)); assertEquals("HTTP 200/OK\n" - + "\n" - + "{ \"foo\" : }", + + "\n" + + "{ \"foo\" : }", new JsonHttpResult(new HttpResult().setContent("{ \"foo\" : }")).toString(true)); } @Test - public void testNonJsonOutput() { + void testNonJsonOutput() { JsonHttpResult result = new JsonHttpResult(); result.setContent("Foo"); StringBuilder sb = new StringBuilder(); @@ -36,7 +36,7 @@ public class JsonHttpResultTest { } @Test - public void testInvalidJsonOutput() { + void testInvalidJsonOutput() { JsonHttpResult result = new JsonHttpResult(); result.setJson(new JSONObject() { @Override diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/writer/HttpWriterTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/writer/HttpWriterTest.java index 2c9d9296aae..52b632c6eb8 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/writer/HttpWriterTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/writer/HttpWriterTest.java @@ -1,10 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.utils.communication.http.writer; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class HttpWriterTest { @@ -19,34 +19,34 @@ public class HttpWriterTest { + "</html>\n"; @Test - public void testStructure() { + void testStructure() { HttpWriter writer = new HttpWriter(); String header = defaultHeader.replace(defaultTitle, "Untitled page"); assertEquals(header + defaultFooter, writer.toString()); } @Test - public void testTitle() { + void testTitle() { HttpWriter writer = new HttpWriter().addTitle(defaultTitle); assertEquals(defaultHeader + defaultFooter, writer.toString()); } @Test - public void testParagraph() { + void testParagraph() { String paragraph = "This is a paragraph"; String paragraph2 = "More text"; HttpWriter writer = new HttpWriter().addTitle(defaultTitle).write(paragraph).write(paragraph2); String content = " <p>\n" - + " " + paragraph + "\n" - + " </p>\n" - + " <p>\n" - + " " + paragraph2 + "\n" - + " </p>\n"; + + " " + paragraph + "\n" + + " </p>\n" + + " <p>\n" + + " " + paragraph2 + "\n" + + " </p>\n"; assertEquals(defaultHeader + content + defaultFooter, writer.toString()); } @Test - public void testLink() { + void testLink() { String name = "My link"; String link = "/foo/bar?hmm"; HttpWriter writer = new HttpWriter().addTitle(defaultTitle).writeLink(name, link); @@ -55,15 +55,15 @@ public class HttpWriterTest { } @Test - public void testErrors() { - try{ + void testErrors() { + try { HttpWriter writer = new HttpWriter().addTitle(defaultTitle); writer.toString(); writer.write("foo"); assertTrue(false); } catch (IllegalStateException e) { } - try{ + try { new HttpWriter().write("foo").addTitle("bar"); assertTrue(false); } catch (IllegalStateException e) { diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java index 0f6e9e235dc..d0378dd9065 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/StateRestAPITest.java @@ -9,12 +9,11 @@ import com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.*; import com.yahoo.vespa.clustercontroller.utils.staterestapi.server.RestApiHandler; import com.yahoo.vespa.clustercontroller.utils.test.TestTransport; import org.codehaus.jettison.json.JSONObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Optional; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class StateRestAPITest { @@ -60,96 +59,96 @@ public class StateRestAPITest { AsyncOperation<HttpResult> op = testTransport.getClient().execute(request); AsyncUtils.waitFor(op); if (!op.isSuccess()) { // Don't call getCause() unless it fails - assertTrue(op.getCause().toString(), op.isSuccess()); + assertTrue(op.isSuccess(), op.getCause().toString()); } assertTrue(op.getResult() != null); return op.getResult(); } private JSONObject executeOkJsonRequest(HttpRequest request) { HttpResult result = execute(request); - assertEquals(result.toString(true), 200, result.getHttpReturnCode()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(200, result.getHttpReturnCode(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); return (JSONObject) result.getContent(); } @Test - public void testTopLevelList() throws Exception { + void testTopLevelList() throws Exception { setupDummyStateApi(); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2")); - assertEquals(result.toString(true), 200, result.getHttpReturnCode()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(200, result.getHttpReturnCode(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); String expected = "{\"cluster\": {\n" - + " \"foo\": {\"link\": \"\\/cluster\\/v2\\/foo\"},\n" - + " \"bar\": {\"link\": \"\\/cluster\\/v2\\/bar\"}\n" - + "}}"; + + " \"foo\": {\"link\": \"\\/cluster\\/v2\\/foo\"},\n" + + " \"bar\": {\"link\": \"\\/cluster\\/v2\\/bar\"}\n" + + "}}"; assertEquals(expected, ((JSONObject) result.getContent()).toString(2)); } @Test - public void testClusterState() throws Exception { + void testClusterState() throws Exception { setupDummyStateApi(); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo")); - assertEquals(result.toString(true), 200, result.getHttpReturnCode()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(200, result.getHttpReturnCode(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); String expected = "{\"node\": {\n" - + " \"1\": {\"link\": \"\\/cluster\\/v2\\/foo\\/1\"},\n" - + " \"3\": {\"link\": \"\\/cluster\\/v2\\/foo\\/3\"}\n" - + "}}"; + + " \"1\": {\"link\": \"\\/cluster\\/v2\\/foo\\/1\"},\n" + + " \"3\": {\"link\": \"\\/cluster\\/v2\\/foo\\/3\"}\n" + + "}}"; assertEquals(expected, ((JSONObject) result.getContent()).toString(2)); } @Test - public void testNodeState() throws Exception { + void testNodeState() throws Exception { setupDummyStateApi(); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo/3")); - assertEquals(result.toString(true), 200, result.getHttpReturnCode()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(200, result.getHttpReturnCode(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); String expected = "{\n" - + " \"attributes\": {\"group\": \"mygroup\"},\n" - + " \"state\": {\"current\": {\n" - + " \"state\": \"up\",\n" - + " \"reason\": \"\"\n" - + " }},\n" - + " \"metrics\": {\"doc-count\": 8}\n" - + "}"; + + " \"attributes\": {\"group\": \"mygroup\"},\n" + + " \"state\": {\"current\": {\n" + + " \"state\": \"up\",\n" + + " \"reason\": \"\"\n" + + " }},\n" + + " \"metrics\": {\"doc-count\": 8}\n" + + "}"; assertEquals(expected, ((JSONObject) result.getContent()).toString(2)); } @Test - public void testRecursiveMode() throws Exception { + void testRecursiveMode() throws Exception { setupDummyStateApi(); { JSONObject json = executeOkJsonRequest( new HttpRequest().setPath("/cluster/v2").addUrlOption("recursive", "true")); String expected = "{\"cluster\": {\n" + - " \"foo\": {\"node\": {\n" + - " \"1\": {\n" + - " \"attributes\": {\"group\": \"mygroup\"},\n" + - " \"state\": {\"current\": {\n" + - " \"state\": \"initializing\",\n" + - " \"reason\": \"\"\n" + - " }},\n" + - " \"metrics\": {\"doc-count\": 5}\n" + - " },\n" + - " \"3\": {\n" + - " \"attributes\": {\"group\": \"mygroup\"},\n" + - " \"state\": {\"current\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " }},\n" + - " \"metrics\": {\"doc-count\": 8}\n" + - " }\n" + - " }},\n" + - " \"bar\": {\"node\": {\"2\": {\n" + - " \"attributes\": {\"group\": \"mygroup\"},\n" + - " \"state\": {\"current\": {\n" + - " \"state\": \"down\",\n" + - " \"reason\": \"\"\n" + - " }},\n" + - " \"metrics\": {\"doc-count\": 0}\n" + - " }}}\n" + - "}}"; + " \"foo\": {\"node\": {\n" + + " \"1\": {\n" + + " \"attributes\": {\"group\": \"mygroup\"},\n" + + " \"state\": {\"current\": {\n" + + " \"state\": \"initializing\",\n" + + " \"reason\": \"\"\n" + + " }},\n" + + " \"metrics\": {\"doc-count\": 5}\n" + + " },\n" + + " \"3\": {\n" + + " \"attributes\": {\"group\": \"mygroup\"},\n" + + " \"state\": {\"current\": {\n" + + " \"state\": \"up\",\n" + + " \"reason\": \"\"\n" + + " }},\n" + + " \"metrics\": {\"doc-count\": 8}\n" + + " }\n" + + " }},\n" + + " \"bar\": {\"node\": {\"2\": {\n" + + " \"attributes\": {\"group\": \"mygroup\"},\n" + + " \"state\": {\"current\": {\n" + + " \"state\": \"down\",\n" + + " \"reason\": \"\"\n" + + " }},\n" + + " \"metrics\": {\"doc-count\": 0}\n" + + " }}}\n" + + "}}"; assertEquals(expected, json.toString(2)); } { @@ -157,17 +156,17 @@ public class StateRestAPITest { new HttpRequest().setPath("/cluster/v2").addUrlOption("recursive", "1")); String expected = "{\"cluster\": {\n" + - " \"foo\": {\"node\": {\n" + - " \"1\": {\"link\": \"\\/cluster\\/v2\\/foo\\/1\"},\n" + - " \"3\": {\"link\": \"\\/cluster\\/v2\\/foo\\/3\"}\n" + - " }},\n" + - " \"bar\": {\"node\": {\"2\": {\"link\": \"\\/cluster\\/v2\\/bar\\/2\"}}}\n" + - "}}"; + " \"foo\": {\"node\": {\n" + + " \"1\": {\"link\": \"\\/cluster\\/v2\\/foo\\/1\"},\n" + + " \"3\": {\"link\": \"\\/cluster\\/v2\\/foo\\/3\"}\n" + + " }},\n" + + " \"bar\": {\"node\": {\"2\": {\"link\": \"\\/cluster\\/v2\\/bar\\/2\"}}}\n" + + "}}"; // Verify that the actual link does not contain backslash. It's just an artifact of // jettison json output. assertEquals("/cluster/v2/foo/1", - json.getJSONObject("cluster").getJSONObject("foo").getJSONObject("node") - .getJSONObject("1").getString("link")); + json.getJSONObject("cluster").getJSONObject("foo").getJSONObject("node") + .getJSONObject("1").getString("link")); assertEquals(expected, json.toString(2)); } { @@ -175,23 +174,23 @@ public class StateRestAPITest { new HttpRequest().setPath("/cluster/v2/foo").addUrlOption("recursive", "1")); String expected = "{\"node\": {\n" + - " \"1\": {\n" + - " \"attributes\": {\"group\": \"mygroup\"},\n" + - " \"state\": {\"current\": {\n" + - " \"state\": \"initializing\",\n" + - " \"reason\": \"\"\n" + - " }},\n" + - " \"metrics\": {\"doc-count\": 5}\n" + - " },\n" + - " \"3\": {\n" + - " \"attributes\": {\"group\": \"mygroup\"},\n" + - " \"state\": {\"current\": {\n" + - " \"state\": \"up\",\n" + - " \"reason\": \"\"\n" + - " }},\n" + - " \"metrics\": {\"doc-count\": 8}\n" + - " }\n" + - "}}"; + " \"1\": {\n" + + " \"attributes\": {\"group\": \"mygroup\"},\n" + + " \"state\": {\"current\": {\n" + + " \"state\": \"initializing\",\n" + + " \"reason\": \"\"\n" + + " }},\n" + + " \"metrics\": {\"doc-count\": 5}\n" + + " },\n" + + " \"3\": {\n" + + " \"attributes\": {\"group\": \"mygroup\"},\n" + + " \"state\": {\"current\": {\n" + + " \"state\": \"up\",\n" + + " \"reason\": \"\"\n" + + " }},\n" + + " \"metrics\": {\"doc-count\": 8}\n" + + " }\n" + + "}}"; assertEquals(expected, json.toString(2)); } { @@ -199,9 +198,9 @@ public class StateRestAPITest { new HttpRequest().setPath("/cluster/v2/foo").addUrlOption("recursive", "false")); String expected = "{\"node\": {\n" + - " \"1\": {\"link\": \"\\/cluster\\/v2\\/foo\\/1\"},\n" + - " \"3\": {\"link\": \"\\/cluster\\/v2\\/foo\\/3\"}\n" + - "}}"; + " \"1\": {\"link\": \"\\/cluster\\/v2\\/foo\\/1\"},\n" + + " \"3\": {\"link\": \"\\/cluster\\/v2\\/foo\\/3\"}\n" + + "}}"; assertEquals(expected, json.toString(2)); } } @@ -217,15 +216,15 @@ public class StateRestAPITest { json.put("response-wait", responseWait.get()); } HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo/3").setPostContent(json)); - assertEquals(result.toString(true), 200, result.getHttpReturnCode()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(200, result.getHttpReturnCode(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); StringBuilder print = new StringBuilder(); result.printContent(print); return print.toString(); } @Test - public void testSetNodeState() throws Exception { + void testSetNodeState() throws Exception { setupDummyStateApi(); { JSONObject json = new JSONObject().put("state", new JSONObject() @@ -233,8 +232,8 @@ public class StateRestAPITest { .put("state", "retired") .put("reason", "No reason"))); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo/3").setPostContent(json)); - assertEquals(result.toString(true), 200, result.getHttpReturnCode()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(200, result.getHttpReturnCode(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); } { JSONObject json = executeOkJsonRequest(new HttpRequest().setPath("/cluster/v2/foo/3")); @@ -246,14 +245,14 @@ public class StateRestAPITest { + " }},\n" + " \"metrics\": {\"doc-count\": 8}\n" + "}"; - assertEquals(json.toString(2), expected, json.toString(2)); + assertEquals(expected, json.toString(2), json.toString(2)); } { JSONObject json = new JSONObject().put("state", new JSONObject() .put("current", new JSONObject())); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo/3").setPostContent(json)); - assertEquals(result.toString(true), 200, result.getHttpReturnCode()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(200, result.getHttpReturnCode(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); } { JSONObject json = executeOkJsonRequest(new HttpRequest().setPath("/cluster/v2/foo/3")); @@ -265,12 +264,12 @@ public class StateRestAPITest { + " }},\n" + " \"metrics\": {\"doc-count\": 8}\n" + "}"; - assertEquals(json.toString(2), expected, json.toString(2)); + assertEquals(expected, json.toString(2), json.toString(2)); } } @Test - public void set_node_state_response_wait_type_is_propagated_to_handler() throws Exception { + void set_node_state_response_wait_type_is_propagated_to_handler() throws Exception { setupDummyStateApi(); { String result = retireAndExpectHttp200Response(Optional.of("wait-until-cluster-acked")); @@ -291,7 +290,7 @@ public class StateRestAPITest { } @Test - public void set_node_state_response_wait_type_is_cluster_acked_by_default() throws Exception { + void set_node_state_response_wait_type_is_cluster_acked_by_default() throws Exception { setupDummyStateApi(); String result = retireAndExpectHttp200Response(Optional.empty()); assertEquals(result, @@ -302,92 +301,92 @@ public class StateRestAPITest { } @Test - public void testMissingUnits() throws Exception { + void testMissingUnits() throws Exception { setupDummyStateApi(); { HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/unknown")); - assertEquals(result.toString(true), 404, result.getHttpReturnCode()); - assertEquals(result.toString(true), "No such resource 'unknown'.", result.getHttpReturnCodeDescription()); + assertEquals(404, result.getHttpReturnCode(), result.toString(true)); + assertEquals("No such resource 'unknown'.", result.getHttpReturnCodeDescription(), result.toString(true)); String expected = "{\"message\":\"No such resource 'unknown'.\"}"; assertEquals(expected, result.getContent().toString()); } { HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo/1234")); - assertEquals(result.toString(true), 404, result.getHttpReturnCode()); - assertEquals(result.toString(true), "No such resource 'foo/1234'.", result.getHttpReturnCodeDescription()); + assertEquals(404, result.getHttpReturnCode(), result.toString(true)); + assertEquals("No such resource 'foo/1234'.", result.getHttpReturnCodeDescription(), result.toString(true)); String expected = "{\"message\":\"No such resource 'foo\\/1234'.\"}"; assertEquals(expected, result.getContent().toString()); } } @Test - public void testUnknownMaster() throws Exception { + void testUnknownMaster() throws Exception { setupDummyStateApi(); stateApi.induceException(new UnknownMasterException()); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2")); - assertEquals(result.toString(true), 503, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Service Unavailable", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(503, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Service Unavailable", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); String expected = "{\"message\":\"No known master cluster controller currently exists.\"}"; assertEquals(expected, result.getContent().toString()); - assertTrue(result.getHeader("Location") == null); + assertNull(result.getHeader("Location")); } @Test - public void testOtherMaster() throws Exception { + void testOtherMaster() throws Exception { setupDummyStateApi(); { stateApi.induceException(new OtherMasterException("example.com", 80)); HttpResult result = execute(new HttpRequest().setScheme("https").setPath("/cluster/v2").addUrlOption(" %=?&", "&?%=").addUrlOption("foo", "bar")); - assertEquals(result.toString(true), 307, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Temporary Redirect", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "https://example.com:80/cluster/v2?%20%25%3D%3F%26=%26%3F%25%3D&foo=bar", result.getHeader("Location")); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(307, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Temporary Redirect", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("https://example.com:80/cluster/v2?%20%25%3D%3F%26=%26%3F%25%3D&foo=bar", result.getHeader("Location"), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); String expected = "{\"message\":\"Cluster controller not master. Use master at example.com:80.\"}"; assertEquals(expected, result.getContent().toString()); } { stateApi.induceException(new OtherMasterException("example.com", 80)); HttpResult result = execute(new HttpRequest().setScheme("http").setPath("/cluster/v2/foo")); - assertEquals(result.toString(true), 307, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Temporary Redirect", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "http://example.com:80/cluster/v2/foo", result.getHeader("Location")); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(307, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Temporary Redirect", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("http://example.com:80/cluster/v2/foo", result.getHeader("Location"), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); String expected = "{\"message\":\"Cluster controller not master. Use master at example.com:80.\"}"; assertEquals(expected, result.getContent().toString()); } } @Test - public void testRuntimeException() throws Exception { + void testRuntimeException() throws Exception { setupDummyStateApi(); stateApi.induceException(new RuntimeException("Moahaha")); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2")); - assertEquals(result.toString(true), 500, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Failed to process request", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(500, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Failed to process request", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); String expected = "{\"message\":\"java.lang.RuntimeException: Moahaha\"}"; assertEquals(expected, result.getContent().toString()); } @Test - public void testClientFailures() throws Exception { + void testClientFailures() throws Exception { setupDummyStateApi(); { stateApi.induceException(new InvalidContentException("Foo bar")); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2")); - assertEquals(result.toString(true), 400, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Content of HTTP request had invalid data", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(400, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Content of HTTP request had invalid data", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); String expected = "{\"message\":\"Foo bar\"}"; assertEquals(expected, result.getContent().toString()); } { stateApi.induceException(new InvalidOptionValueException("foo", "bar", "Foo can not be bar")); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2")); - assertEquals(result.toString(true), 400, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Option 'foo' have invalid value 'bar'", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(400, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Option 'foo' have invalid value 'bar'", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); String expected = "{\"message\":\"Option 'foo' have invalid value 'bar': Foo can not be bar\"}"; assertEquals(expected, result.getContent().toString()); } @@ -396,94 +395,94 @@ public class StateRestAPITest { path[0] = "foo"; stateApi.induceException(new OperationNotSupportedForUnitException(path, "Foo")); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2")); - assertEquals(result.toString(true), 405, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Operation not supported for resource", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(405, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Operation not supported for resource", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); String expected = "{\"message\":\"[foo]: Foo\"}"; assertEquals(expected, result.getContent().toString()); } } @Test - public void testInternalFailure() throws Exception { + void testInternalFailure() throws Exception { setupDummyStateApi(); { stateApi.induceException(new InternalFailure("Foo")); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2")); - assertEquals(result.toString(true), 500, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Failed to process request", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(500, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Failed to process request", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); String expected = "{\"message\":\"Internal failure. Should not happen: Foo\"}"; assertEquals(expected, result.getContent().toString()); } } @Test - public void testInvalidRecursiveValues() throws Exception { + void testInvalidRecursiveValues() throws Exception { setupDummyStateApi(); { HttpResult result = execute(new HttpRequest().setPath("/cluster/v2").addUrlOption("recursive", "-5")); - assertEquals(result.toString(true), 400, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Option 'recursive' have invalid value '-5'", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(400, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Option 'recursive' have invalid value '-5'", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); String expected = "{\"message\":\"Option 'recursive' have invalid value '-5': Recursive option must be true, false, 0 or a positive integer\"}"; assertEquals(expected, result.getContent().toString()); } { HttpResult result = execute(new HttpRequest().setPath("/cluster/v2").addUrlOption("recursive", "foo")); - assertEquals(result.toString(true), 400, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Option 'recursive' have invalid value 'foo'", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(400, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Option 'recursive' have invalid value 'foo'", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); String expected = "{\"message\":\"Option 'recursive' have invalid value 'foo': Recursive option must be true, false, 0 or a positive integer\"}"; assertEquals(expected, result.getContent().toString()); } } @Test - public void testInvalidJsonInSetStateRequest() throws Exception { + void testInvalidJsonInSetStateRequest() throws Exception { setupDummyStateApi(); { JSONObject json = new JSONObject(); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo/3").setPostContent(json)); - assertEquals(result.toString(true), 400, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Content of HTTP request had invalid data", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); - assertTrue(result.toString(true), result.getContent().toString().contains("Set state requests must contain a state object")); + assertEquals(400, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Content of HTTP request had invalid data", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); + assertTrue(result.getContent().toString().contains("Set state requests must contain a state object"), result.toString(true)); } { JSONObject json = new JSONObject().put("state", 5); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo/3").setPostContent(json)); - assertEquals(result.toString(true), 400, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Content of HTTP request had invalid data", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); - assertTrue(result.toString(true), result.getContent().toString().contains("value of state is not a json object")); + assertEquals(400, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Content of HTTP request had invalid data", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); + assertTrue(result.getContent().toString().contains("value of state is not a json object"), result.toString(true)); } { JSONObject json = new JSONObject().put("state", new JSONObject() .put("current", 5)); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo/3").setPostContent(json)); - assertEquals(result.toString(true), 400, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Content of HTTP request had invalid data", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); - assertTrue(result.toString(true), result.getContent().toString().contains("value of state->current is not a json object")); + assertEquals(400, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Content of HTTP request had invalid data", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); + assertTrue(result.getContent().toString().contains("value of state->current is not a json object"), result.toString(true)); } { JSONObject json = new JSONObject().put("state", new JSONObject() .put("current", new JSONObject().put("state", 5))); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo/3").setPostContent(json)); - assertEquals(result.toString(true), 400, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Content of HTTP request had invalid data", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); - assertTrue(result.toString(true), result.getContent().toString().contains("value of state->current->state is not a string")); + assertEquals(400, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Content of HTTP request had invalid data", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); + assertTrue(result.getContent().toString().contains("value of state->current->state is not a string"), result.toString(true)); } { JSONObject json = new JSONObject().put("state", new JSONObject() .put("current", new JSONObject().put("state", "down").put("reason", 5))); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo/3").setPostContent(json)); - assertEquals(result.toString(true), 400, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Content of HTTP request had invalid data", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); - assertTrue(result.toString(true), result.getContent().toString().contains("value of state->current->reason is not a string")); + assertEquals(400, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Content of HTTP request had invalid data", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); + assertTrue(result.getContent().toString().contains("value of state->current->reason is not a string"), result.toString(true)); } { String result = retireAndExpectHttp400Response("Non existing condition", "no-wait"); @@ -506,21 +505,21 @@ public class StateRestAPITest { .put("condition", condition) .put("response-wait", responseWait); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2/foo/3").setPostContent(json)); - assertEquals(result.toString(true), 400, result.getHttpReturnCode()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(400, result.getHttpReturnCode(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); StringBuilder print = new StringBuilder(); result.printContent(print); return print.toString(); } @Test - public void testInvalidPathPrefix() throws Exception { + void testInvalidPathPrefix() throws Exception { DummyBackend backend = new DummyBackend(); stateApi = new DummyStateApi(backend); populateDummyBackend(backend); testTransport = new TestTransport(); RestApiHandler handler = new RestApiHandler(stateApi); - try{ + try { handler.setDefaultPathPrefix("cluster/v2"); assertTrue(false); } catch (IllegalArgumentException e) { @@ -528,14 +527,14 @@ public class StateRestAPITest { } @Test - public void deadline_exceeded_exception_returns_http_504_error() throws Exception { + void deadline_exceeded_exception_returns_http_504_error() throws Exception { setupDummyStateApi(); stateApi.induceException(new DeadlineExceededException("argh!")); HttpResult result = execute(new HttpRequest().setPath("/cluster/v2")); - assertEquals(result.toString(true), 504, result.getHttpReturnCode()); - assertEquals(result.toString(true), "Gateway Timeout", result.getHttpReturnCodeDescription()); - assertEquals(result.toString(true), "application/json", result.getHeader("Content-Type")); + assertEquals(504, result.getHttpReturnCode(), result.toString(true)); + assertEquals("Gateway Timeout", result.getHttpReturnCodeDescription(), result.toString(true)); + assertEquals("application/json", result.getHeader("Content-Type"), result.toString(true)); String expected = "{\"message\":\"argh!\"}"; assertEquals(expected, result.getContent().toString()); } diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/RestApiHandlerTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/RestApiHandlerTest.java index 2826c70f40a..6363264ce3e 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/RestApiHandlerTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/staterestapi/server/RestApiHandlerTest.java @@ -2,16 +2,16 @@ package com.yahoo.vespa.clustercontroller.utils.staterestapi.server; import com.yahoo.vespa.clustercontroller.utils.staterestapi.errors.InvalidContentException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.time.Duration; import java.util.Optional; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class RestApiHandlerTest { @Test - public void testParsingOfTimeout() throws InvalidContentException { + void testParsingOfTimeout() throws InvalidContentException { assertEquals(Optional.empty(), RestApiHandler.parseTimeout(null)); assertEquals(Optional.of(Duration.ofMillis(12500)), RestApiHandler.parseTimeout("12.5")); assertEquals(Optional.of(Duration.ofMillis(0)), RestApiHandler.parseTimeout("-1")); diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/CertainlyCloneableTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/CertainlyCloneableTest.java index f81c4ba7a96..e14562d42c0 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/CertainlyCloneableTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/CertainlyCloneableTest.java @@ -1,10 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.utils.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class CertainlyCloneableTest { @@ -15,8 +15,8 @@ public class CertainlyCloneableTest { } @Test - public void testSimple() { - try{ + void testSimple() { + try { Foo f = new Foo(); f.clone(); fail("Control should not get here"); diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/ClockTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/ClockTest.java index ef338d35eb3..c791723615c 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/ClockTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/ClockTest.java @@ -1,14 +1,14 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.utils.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ClockTest { @Test - public void testNothingButGetCoverage() { + void testNothingButGetCoverage() { long s = new Clock().getTimeInSecs(); long ms = new Clock().getTimeInMillis(); assertTrue(ms >= 1000 * s); diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/JSONObjectWrapperTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/JSONObjectWrapperTest.java index a5f57510194..f09907e7fcd 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/JSONObjectWrapperTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/JSONObjectWrapperTest.java @@ -1,16 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.utils.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class JSONObjectWrapperTest { @Test - public void testExceptionWrapping() { + void testExceptionWrapping() { JSONObjectWrapper wrapper = new JSONObjectWrapper(); - try{ + try { wrapper.put(null, "foo"); } catch (NullPointerException e) { assertEquals("Null key.", e.getMessage()); diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/MetricReporterTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/MetricReporterTest.java index b29de4c972c..33164aaf53e 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/MetricReporterTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/util/MetricReporterTest.java @@ -1,12 +1,12 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.clustercontroller.utils.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Map; import java.util.TreeMap; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class MetricReporterTest { @@ -31,10 +31,10 @@ public class MetricReporterTest { sb.append(" )\n"); return new Context() {}; } - }; + } @Test - public void testNoMetricReporter() { + void testNoMetricReporter() { NoMetricReporter reporter = new NoMetricReporter(); reporter.add("foo", 3, null); reporter.set("foo", 3, null); @@ -42,7 +42,7 @@ public class MetricReporterTest { } @Test - public void testPrefix() { + void testPrefix() { MetricReporterMock mock = new MetricReporterMock(); ComponentMetricReporter c = new ComponentMetricReporter(mock, "prefix"); c.addDimension("urk", "fy"); @@ -50,14 +50,14 @@ public class MetricReporterTest { c.set("bar", 1); assertEquals( "createContext( )\n" + - "createContext( urk=fy )\n" + - "add(prefixfoo, 2)\n" + - "set(prefixbar, 1)\n", mock.sb.toString()); + "createContext( urk=fy )\n" + + "add(prefixfoo, 2)\n" + + "set(prefixbar, 1)\n", mock.sb.toString()); } @Test - public void testWithContext() { + void testWithContext() { MetricReporterMock mock = new MetricReporterMock(); ComponentMetricReporter c = new ComponentMetricReporter(mock, "prefix"); c.addDimension("urk", "fy"); @@ -67,27 +67,27 @@ public class MetricReporterTest { c.set("bar", 1, c.createContext(myContext)); assertEquals( "createContext( )\n" + - "createContext( urk=fy )\n" + - "createContext( myvar=3 urk=fy )\n" + - "add(prefixfoo, 2)\n" + - "createContext( myvar=3 urk=fy )\n" + - "set(prefixbar, 1)\n", mock.sb.toString()); + "createContext( urk=fy )\n" + + "createContext( myvar=3 urk=fy )\n" + + "add(prefixfoo, 2)\n" + + "createContext( myvar=3 urk=fy )\n" + + "set(prefixbar, 1)\n", mock.sb.toString()); } @Test - public void testDefaultContext() { + void testDefaultContext() { MetricReporterMock mock = new MetricReporterMock(); ComponentMetricReporter c = new ComponentMetricReporter(mock, "prefix"); c.addDimension("urk", "fy"); c.add("foo", 2, c.createContext(null)); assertEquals( "createContext( )\n" + - "createContext( urk=fy )\n" + - "add(prefixfoo, 2)\n", mock.sb.toString()); + "createContext( urk=fy )\n" + + "add(prefixfoo, 2)\n", mock.sb.toString()); } @Test - public void testContextOverlap() { + void testContextOverlap() { MetricReporterMock mock = new MetricReporterMock(); ComponentMetricReporter c = new ComponentMetricReporter(mock, "prefix"); c.addDimension("urk", "fy"); @@ -96,9 +96,9 @@ public class MetricReporterTest { c.add("foo", 2, c.createContext(myContext)); assertEquals( "createContext( )\n" + - "createContext( urk=fy )\n" + - "createContext( urk=yes )\n" + - "add(prefixfoo, 2)\n", mock.sb.toString()); + "createContext( urk=fy )\n" + + "createContext( urk=yes )\n" + + "add(prefixfoo, 2)\n", mock.sb.toString()); } } |