From 46ed827dc42ec61bda29463ce653f9e7ee8f75db Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Thu, 1 Mar 2018 09:35:07 +0100 Subject: Use new junit --- .../utils/communication/async/AsyncTest.java | 38 +++++++++------------- .../http/AsyncHttpClientWithBaseTest.java | 15 ++++++--- .../utils/communication/http/HttpRequestTest.java | 16 +++++++-- .../utils/communication/http/HttpResultTest.java | 10 ++++-- .../http/JsonAsyncHttpClientTest.java | 17 ++++++++-- .../communication/http/JsonHttpResultTest.java | 11 +++++-- .../http/LoggingAsyncHttpClientTest.java | 15 ++++++--- .../http/ProxyAsyncHttpClientTest.java | 10 ++++-- .../utils/communication/http/RequestQueueTest.java | 10 ++++-- .../communication/http/TimeoutHandlerTest.java | 19 +++++++++-- .../communication/http/writer/HttpWriterTest.java | 19 +++++++++-- 11 files changed, 129 insertions(+), 51 deletions(-) (limited to 'clustercontroller-utils') 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 9d8bb6d10e4..2817c83a041 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,14 +1,15 @@ // Copyright 2017 Yahoo Holdings. 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 junit.framework.TestCase; -import org.junit.Ignore; import org.junit.Test; import java.util.LinkedList; -public class AsyncTest extends TestCase { +import static org.junit.Assert.*; +public class AsyncTest { + + @Test public void testListeners() { AsyncOperationImpl op = new AsyncOperationImpl<>("test"); class Listener implements AsyncCallback { @@ -28,16 +29,17 @@ public class AsyncTest extends TestCase { op.unregister(l1); op.setResult("foo"); op.register(l4); - // Listener that is unregistered is not called + // Listener that is unregistered is not called assertEquals(false, l1.called); - // Listener that is registered is called + // Listener that is registered is called assertEquals(true, l2.called); - // Multiple listeners supported + // Multiple listeners supported assertEquals(true, l3.called); - // Listener called directly when registered after result is set + // Listener called directly when registered after result is set assertEquals(true, l4.called); } + @Test public void testMultipleResultSetters() { { AsyncOperationImpl op = new AsyncOperationImpl<>("test"); @@ -62,6 +64,7 @@ public class AsyncTest extends TestCase { } } + @Test public void testPartialResultOnFailure() { AsyncOperationImpl op = new AsyncOperationImpl<>("test"); op.setFailure(new Exception("bar"), "foo"); @@ -70,6 +73,7 @@ public class AsyncTest extends TestCase { assertEquals("bar", op.getCause().getMessage()); } + @Test public void testListenImpl() { class ListenImpl extends AsyncOperationListenImpl { public ListenImpl(AsyncOperation op) { @@ -93,6 +97,7 @@ public class AsyncTest extends TestCase { assertEquals(1, l1.calls); } + @Test public void testRedirectedOperation() { { final AsyncOperationImpl op = new AsyncOperationImpl<>("test", "desc"); @@ -141,6 +146,7 @@ public class AsyncTest extends TestCase { } } + @Test public void testRedirectOnSuccessOperation() { { final AsyncOperationImpl target = new AsyncOperationImpl<>("foo"); @@ -236,6 +242,7 @@ public class AsyncTest extends TestCase { } } + @Test public void testStressCompletionAndRegisterToDetectRace() throws Exception { int iterations = 1000; Object monitor = new Object(); @@ -247,7 +254,7 @@ public class AsyncTest extends TestCase { t1.start(); t2.start(); for (int i=0; i op = new AsyncOperationImpl<>("test"); + AsyncOperationImpl op = new AsyncOperationImpl<>("test"); synchronized (monitor) { completer.op = op; listener.op = op; @@ -263,23 +270,8 @@ public class AsyncTest extends TestCase { t1.join(); t2.join(); } - /* - System.out.println("Done with " + iterations + " iterations. " - + "Registered prior " + listener.priorReg + " times. " - + "Unset " + listener.unset + " times. "); - // */ assertEquals(0, listener.unset); assertEquals(iterations, listener.counter); } - public void ignoreTestExceptionOnCallback() throws Exception { - AsyncOperationImpl impl = new AsyncOperationImpl<>("foo"); - impl.register(new AsyncCallback() { - @Override - public void done(AsyncOperation op) { - throw new RuntimeException("Foo"); - } - }); - impl.setResult(null); - } } diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/AsyncHttpClientWithBaseTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/AsyncHttpClientWithBaseTest.java index e04eb1c043d..685ad492052 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/AsyncHttpClientWithBaseTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/AsyncHttpClientWithBaseTest.java @@ -3,10 +3,15 @@ package com.yahoo.vespa.clustercontroller.utils.communication.http; import com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperation; import com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperationImpl; -import junit.framework.TestCase; +import org.junit.Test; -public class AsyncHttpClientWithBaseTest extends TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; +public class AsyncHttpClientWithBaseTest { + + @Test public void testOverride() { class HttpClient implements AsyncHttpClient { HttpRequest lastRequest; @@ -39,11 +44,13 @@ public class AsyncHttpClientWithBaseTest extends TestCase { base.close(); } + @Test public void testClientMustBeSet() { - try{ - new AsyncHttpClientWithBase(null); + try { + new AsyncHttpClientWithBase<>(null); assertTrue(false); } catch (IllegalArgumentException e) { } } + } 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 9d51954e567..7baff0453b0 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,9 +1,13 @@ // Copyright 2017 Yahoo Holdings. 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 junit.framework.TestCase; +import org.junit.Test; -public class HttpRequestTest extends TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; + +public class HttpRequestTest { private HttpRequest createRequest() { return new HttpRequest() @@ -16,6 +20,7 @@ public class HttpRequestTest extends TestCase { .setTimeout(25); } + @Test public void testEquality() { assertEquals(createRequest(), createRequest()); assertNotSame(createRequest(), createRequest().setHost("localhost")); @@ -25,6 +30,7 @@ public class HttpRequestTest extends TestCase { assertNotSame(createRequest(), createRequest().setHttpOperation(HttpRequest.HttpOp.DELETE)); } + @Test public void testVerifyComplete() { // To be a complete request, an HTTP request must include: // - A path @@ -42,6 +48,7 @@ public class HttpRequestTest extends TestCase { new HttpRequest().setHttpOperation(HttpRequest.HttpOp.GET).setPath("/bar").verifyComplete(); } + @Test public void testMerge() { { HttpRequest base = new HttpRequest() @@ -84,16 +91,19 @@ public class HttpRequestTest extends TestCase { } } + @Test public void testNonExistingHeader() { assertEquals("foo", new HttpRequest().getHeader("asd", "foo")); assertEquals("foo", new HttpRequest().addHttpHeader("bar", "foo").getHeader("asd", "foo")); } + @Test public void testOption() { assertEquals("bar", new HttpRequest().addUrlOption("foo", "bar").getOption("foo", "foo")); assertEquals("foo", new HttpRequest().getOption("asd", "foo")); } + @Test public void testToString() { assertEquals("GET? http://localhost:8080/", new HttpRequest() @@ -113,9 +123,11 @@ public class HttpRequestTest extends TestCase { .toString(true)); } + @Test public 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 6f165e8d35c..f137e9b9580 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,10 +1,13 @@ // Copyright 2017 Yahoo Holdings. 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 junit.framework.TestCase; +import org.junit.Test; -public class HttpResultTest extends TestCase { +import static org.junit.Assert.assertEquals; +public class HttpResultTest { + + @Test public void testSuccess() { assertEquals(false, new HttpResult().setHttpCode(199, "foo").isSuccess()); assertEquals(true, new HttpResult().setHttpCode(200, "foo").isSuccess()); @@ -12,6 +15,7 @@ public class HttpResultTest extends TestCase { assertEquals(false, new HttpResult().setHttpCode(300, "foo").isSuccess()); } + @Test public void testToString() { assertEquals("HTTP 200/OK", new HttpResult().setContent("Foo").toString()); assertEquals("HTTP 200/OK\n\nFoo", new HttpResult().setContent("Foo").toString(true)); @@ -19,7 +23,9 @@ public class HttpResultTest extends TestCase { assertEquals("HTTP 200/OK", new HttpResult().setContent("").toString(true)); } + @Test public void testNothingButGetCoverage() { new HttpResult().getHeaders(); } + } diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/JsonAsyncHttpClientTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/JsonAsyncHttpClientTest.java index 5fa8ac87da6..3d3cd517020 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/JsonAsyncHttpClientTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/JsonAsyncHttpClientTest.java @@ -3,11 +3,16 @@ package com.yahoo.vespa.clustercontroller.utils.communication.http; import com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperation; import com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperationImpl; -import junit.framework.TestCase; import org.codehaus.jettison.json.JSONObject; +import org.junit.Test; -public class JsonAsyncHttpClientTest extends TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +public class JsonAsyncHttpClientTest { + + @Test public void testJSONInJSONOut() throws Exception { DummyAsyncHttpClient dummy = new DummyAsyncHttpClient( new HttpResult().setContent(new JSONObject().put("bar", 42))); @@ -27,6 +32,7 @@ public class JsonAsyncHttpClientTest extends TestCase { client.close(); } + @Test public void testStringInJSONOut() throws Exception { DummyAsyncHttpClient dummy = new DummyAsyncHttpClient( new HttpResult().setContent(new JSONObject().put("bar", 42).toString())); @@ -40,6 +46,7 @@ public class JsonAsyncHttpClientTest extends TestCase { assertEquals(new JSONObject().put("bar", 42).toString(), result.getResult().getJson().toString()); } + @Test public void testIllegalJsonIn() throws Exception { DummyAsyncHttpClient dummy = new DummyAsyncHttpClient( new HttpResult().setContent(new JSONObject().put("bar", 42))); @@ -56,6 +63,7 @@ public class JsonAsyncHttpClientTest extends TestCase { } } + @Test public void testIllegalJSONOut() throws Exception { DummyAsyncHttpClient dummy = new DummyAsyncHttpClient( new HttpResult().setContent("my illegal json")); @@ -69,7 +77,8 @@ public class JsonAsyncHttpClientTest extends TestCase { assertEquals("{\"error\":\"Invalid JSON in output: A JSONObject text must begin with '{' at character 1 of my illegal json\",\"output\":\"my illegal json\"}", result.getResult().getJson().toString()); } - public void testEmptyReply() throws Exception { + @Test + public void testEmptyReply() { class Client implements AsyncHttpClient { AsyncOperationImpl lastOp; @Override @@ -87,6 +96,7 @@ public class JsonAsyncHttpClientTest extends TestCase { assertNull(op.getResult()); } + @Test public void testNotVerifyingJson() throws Exception { DummyAsyncHttpClient dummy = new DummyAsyncHttpClient( new HttpResult().setContent(new JSONObject().put("bar", 42))); @@ -105,4 +115,5 @@ public class JsonAsyncHttpClientTest extends TestCase { result.toString(); client.close(); } + } 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 07b11214301..8265247b124 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 @@ -1,16 +1,20 @@ // Copyright 2017 Yahoo Holdings. 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 junit.framework.TestCase; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; +import org.junit.Test; -public class JsonHttpResultTest extends TestCase { +import static org.junit.Assert.assertEquals; +public class JsonHttpResultTest { + + @Test public void testCopyConstructor() { assertEquals("{}", new JsonHttpResult(new HttpResult()).getJson().toString()); } + @Test public void testOutput() { assertEquals("HTTP 200/OK\n" + "\n" @@ -22,6 +26,7 @@ public class JsonHttpResultTest extends TestCase { new JsonHttpResult(new HttpResult().setContent("{ \"foo\" : }")).toString(true)); } + @Test public void testNonJsonOutput() { JsonHttpResult result = new JsonHttpResult(); result.setContent("Foo"); @@ -30,6 +35,7 @@ public class JsonHttpResultTest extends TestCase { assertEquals("Foo", sb.toString()); } + @Test public void testInvalidJsonOutput() { JsonHttpResult result = new JsonHttpResult(); result.setJson(new JSONObject() { @@ -42,4 +48,5 @@ public class JsonHttpResultTest extends TestCase { result.printContent(sb); assertEquals("JSON: {}", sb.toString()); } + } diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/LoggingAsyncHttpClientTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/LoggingAsyncHttpClientTest.java index 0191c29dd66..37841f7ca29 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/LoggingAsyncHttpClientTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/LoggingAsyncHttpClientTest.java @@ -3,12 +3,15 @@ package com.yahoo.vespa.clustercontroller.utils.communication.http; import com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperation; import com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperationImpl; -import junit.framework.TestCase; +import org.junit.Test; import java.util.logging.Level; import java.util.logging.Logger; -public class LoggingAsyncHttpClientTest extends TestCase { +import static org.junit.Assert.assertEquals; + +public class LoggingAsyncHttpClientTest { + class HttpClient implements AsyncHttpClient { AsyncOperationImpl lastOp; @Override @@ -20,11 +23,13 @@ public class LoggingAsyncHttpClientTest extends TestCase { } } - public void testWithoutDebugLog() throws Exception { + @Test + public void testWithoutDebugLog() { doRequests(); } - public void testWithDebugLog() throws Exception { + @Test + public void testWithDebugLog() { Logger log = Logger.getLogger(LoggingAsyncHttpClient.class.getName()); log.setLevel(Level.FINE); doRequests(); @@ -45,6 +50,6 @@ public class LoggingAsyncHttpClientTest extends TestCase { client.lastOp.setFailure(new Exception("foo")); assertEquals("foo", op.getCause().getMessage()); } - } + } diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/ProxyAsyncHttpClientTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/ProxyAsyncHttpClientTest.java index d231dadc9b1..062fd4aaa32 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/ProxyAsyncHttpClientTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/ProxyAsyncHttpClientTest.java @@ -1,11 +1,15 @@ // Copyright 2017 Yahoo Holdings. 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 junit.framework.TestCase; import org.codehaus.jettison.json.JSONObject; +import org.junit.Test; -public class ProxyAsyncHttpClientTest extends TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +public class ProxyAsyncHttpClientTest { + + @Test public void testSimple() throws Exception { // Can't really test much here, but verifies that the code runs. DummyAsyncHttpClient dummy = new DummyAsyncHttpClient( @@ -28,6 +32,7 @@ public class ProxyAsyncHttpClientTest extends TestCase { dummy.lastRequest); } + @Test public void testNoAndEmptyPath() throws Exception { DummyAsyncHttpClient dummy = new DummyAsyncHttpClient( new HttpResult().setContent(new JSONObject().put("bar", 42))); @@ -40,4 +45,5 @@ public class ProxyAsyncHttpClientTest extends TestCase { } client.execute(new HttpRequest().setHost("local").setPath("")); } + } diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/RequestQueueTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/RequestQueueTest.java index e3b6f7f7528..230920df53f 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/RequestQueueTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/RequestQueueTest.java @@ -4,11 +4,14 @@ package com.yahoo.vespa.clustercontroller.utils.communication.http; import com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncCallback; import com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperation; import com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperationImpl; -import junit.framework.TestCase; +import org.junit.Test; import java.util.LinkedList; -public class RequestQueueTest extends TestCase { +import static org.junit.Assert.assertEquals; + +public class RequestQueueTest { + public static class Request { public final HttpRequest request; public final AsyncOperationImpl result; @@ -33,6 +36,7 @@ public class RequestQueueTest extends TestCase { public void close() {} }; + @Test public void testNormalUsage() { TestClient client = new TestClient(); RequestQueue queue = new RequestQueue<>(client, 4); @@ -82,6 +86,7 @@ public class RequestQueueTest extends TestCase { } } + @Test public void testWaitUntilEmpty() throws Exception { TestClient client = new TestClient(); RequestQueue queue = new RequestQueue<>(client, 4); @@ -105,4 +110,5 @@ public class RequestQueueTest extends TestCase { } assertEquals(1, result.size()); } + } diff --git a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/TimeoutHandlerTest.java b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/TimeoutHandlerTest.java index 8c567a25b3a..72a2a4eab8a 100644 --- a/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/TimeoutHandlerTest.java +++ b/clustercontroller-utils/src/test/java/com/yahoo/vespa/clustercontroller/utils/communication/http/TimeoutHandlerTest.java @@ -5,14 +5,19 @@ import com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperatio import com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncOperationImpl; import com.yahoo.vespa.clustercontroller.utils.communication.async.AsyncUtils; import com.yahoo.vespa.clustercontroller.utils.test.FakeClock; -import junit.framework.TestCase; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.Executor; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -public class TimeoutHandlerTest extends TestCase { +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class TimeoutHandlerTest { public class TestClient implements AsyncHttpClient { AsyncOperationImpl lastOp; @@ -29,6 +34,7 @@ public class TimeoutHandlerTest extends TestCase { private FakeClock clock; private TimeoutHandler handler; + @Before public void setUp() { executor = new ThreadPoolExecutor(10, 100, 100, TimeUnit.SECONDS, new ArrayBlockingQueue(1000)); clock = new FakeClock(); @@ -36,11 +42,13 @@ public class TimeoutHandlerTest extends TestCase { handler = new TimeoutHandler<>(executor, clock, client); } + @After public void tearDown() { handler.close(); executor.shutdown(); } + @Test public void testTimeout() { AsyncOperation op = handler.execute(new HttpRequest().setTimeout(1000)); assertFalse(op.isDone()); @@ -59,6 +67,7 @@ public class TimeoutHandlerTest extends TestCase { assertTrue(op.getCause().getMessage(), op.getCause().getMessage().contains("Operation timeout")); } + @Test public void testNoTimeout() { AsyncOperation op = handler.execute(new HttpRequest().setTimeout(1000)); clock.adjust(999); @@ -70,6 +79,7 @@ public class TimeoutHandlerTest extends TestCase { assertEquals("foo", op.getResult().getContent()); } + @Test public void testNoTimeoutFailing() { AsyncOperation op = handler.execute(new HttpRequest().setTimeout(1000)); clock.adjust(999); @@ -81,6 +91,7 @@ public class TimeoutHandlerTest extends TestCase { assertEquals("foo", op.getCause().getMessage()); } + @Test public void testProvokeCompletedOpPurgeInTimeoutList() { AsyncOperation op1 = handler.execute(new HttpRequest().setTimeout(1000)); AsyncOperationImpl op1Internal = client.lastOp; @@ -97,6 +108,7 @@ public class TimeoutHandlerTest extends TestCase { assertEquals(false, op2.isSuccess()); } + @Test public void testNothingButGetCoverage() { AsyncOperation op = handler.execute(new HttpRequest().setTimeout(1000)); op.getProgress(); @@ -111,4 +123,5 @@ public class TimeoutHandlerTest extends TestCase { client.lastOp.setResult(new HttpResult().setContent("foo")); AsyncUtils.waitFor(op); } + } 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 b358c3cbbb5..5ef6239894c 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,9 +1,13 @@ // Copyright 2017 Yahoo Holdings. 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 junit.framework.TestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class HttpWriterTest { -public class HttpWriterTest extends TestCase { private static String defaultTitle = "My Title"; private static String defaultHeader = "\n" + " \n" @@ -14,16 +18,20 @@ public class HttpWriterTest extends TestCase { private static String defaultFooter = " \n" + "\n"; - + @Test public void testStructure() { HttpWriter writer = new HttpWriter(); String header = defaultHeader.replace(defaultTitle, "Untitled page"); assertEquals(header + defaultFooter, writer.toString()); } + + @Test public void testTitle() { HttpWriter writer = new HttpWriter().addTitle(defaultTitle); assertEquals(defaultHeader + defaultFooter, writer.toString()); } + + @Test public void testParagraph() { String paragraph = "This is a paragraph"; String paragraph2 = "More text"; @@ -36,6 +44,8 @@ public class HttpWriterTest extends TestCase { + "

\n"; assertEquals(defaultHeader + content + defaultFooter, writer.toString()); } + + @Test public void testLink() { String name = "My link"; String link = "/foo/bar?hmm"; @@ -43,6 +53,8 @@ public class HttpWriterTest extends TestCase { String content = " " + name + "\n"; assertEquals(defaultHeader + content + defaultFooter, writer.toString()); } + + @Test public void testErrors() { try{ HttpWriter writer = new HttpWriter().addTitle(defaultTitle); @@ -57,4 +69,5 @@ public class HttpWriterTest extends TestCase { } catch (IllegalStateException e) { } } + } -- cgit v1.2.3