From 72df5f7ce8a9d671a953a71e8eec13ceff39567a Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Fri, 30 Aug 2019 12:08:57 +0100 Subject: [PATCH] Move from TestNG to JUnit 5 and AssertJ This commit was mostly created via the conversion tool --- modules/common/pom.xml | 19 +- .../com/opengamma/sdk/common/BasicTest.java | 38 +-- .../sdk/common/ServiceInvokerTest.java | 20 +- .../com/opengamma/sdk/common/VersionTest.java | 8 +- modules/margin/pom.xml | 19 +- .../sdk/margin/MarginCalcRequestTest.java | 20 +- .../sdk/margin/MarginClientTest.java | 113 ++++---- .../margin/MarginDetailDeserializerTest.java | 13 +- .../sdk/margin/PortfolioDataFileTest.java | 48 ++-- .../sdk/margin/TenorStringConverterTest.java | 12 +- .../sdk/margin/it/MarginClientRemoteIT.java | 249 ++++++++++-------- modules/pom.xml | 14 +- 12 files changed, 319 insertions(+), 254 deletions(-) diff --git a/modules/common/pom.xml b/modules/common/pom.xml index bb4ae0c..77caf94 100644 --- a/modules/common/pom.xml +++ b/modules/common/pom.xml @@ -36,8 +36,23 @@ - org.testng - testng + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.assertj + assertj-core test diff --git a/modules/common/src/test/java/com/opengamma/sdk/common/BasicTest.java b/modules/common/src/test/java/com/opengamma/sdk/common/BasicTest.java index 0596aa6..e751fd9 100644 --- a/modules/common/src/test/java/com/opengamma/sdk/common/BasicTest.java +++ b/modules/common/src/test/java/com/opengamma/sdk/common/BasicTest.java @@ -6,12 +6,10 @@ package com.opengamma.sdk.common; import static com.opengamma.sdk.common.ServiceInvoker.SERVICE_URL; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertThrows; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; import com.opengamma.sdk.common.auth.AuthClient; import com.opengamma.sdk.common.auth.AuthenticationException; @@ -23,30 +21,32 @@ /** * Test. */ -@Test public class BasicTest { private static final Credentials CREDENTIALS = Credentials.ofApiKey("user", "pw"); private static final Credentials BAD_CREDENTIALS = Credentials.ofApiKey("bad", "pw"); + @Test public void testBasics() { - assertThrows(NullPointerException.class, () -> ServiceInvoker.of(null)); + assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> ServiceInvoker.of(null)); } + @Test public void testAuthGood() { AuthClient mockAuth = new TestingAuthClient(); @SuppressWarnings("resource") ServiceInvoker invoker = ServiceInvoker.builder(CREDENTIALS) .authClientFactory(inv -> mockAuth) .build(); - assertEquals(invoker.getServiceUrl(), SERVICE_URL); - assertEquals(invoker.getHttpClient().interceptors().size(), 4); - assertTrue(invoker.getHttpClient().followRedirects()); - assertFalse(invoker.getExecutor().isShutdown()); + assertThat(invoker.getServiceUrl()).isEqualTo(SERVICE_URL); + assertThat(invoker.getHttpClient().interceptors()).hasSize(4); + assertThat(invoker.getHttpClient().followRedirects()).isTrue(); + assertThat(invoker.getExecutor().isShutdown()).isFalse(); invoker.close(); - assertTrue(invoker.getExecutor().isShutdown()); + assertThat(invoker.getExecutor().isShutdown()).isTrue(); } + @Test public void testAuthGoodHttpFactory() { AuthClient mockAuth = new TestingAuthClient(); try (ServiceInvoker invoker = ServiceInvoker.builder(CREDENTIALS) @@ -54,23 +54,25 @@ public void testAuthGoodHttpFactory() { builder -> builder.addInterceptor(chain -> chain.proceed(chain.request())).followRedirects(false).build()) .authClientFactory(inv -> mockAuth) .build()) { - assertEquals(invoker.getServiceUrl(), SERVICE_URL); - assertEquals(invoker.getHttpClient().interceptors().size(), 5); // logging, user-agent & auth& retry plus one from test - assertFalse(invoker.getHttpClient().followRedirects()); + assertThat(invoker.getServiceUrl()).isEqualTo(SERVICE_URL); + assertThat(invoker.getHttpClient().interceptors()).hasSize(5); // logging, user-agent & auth& retry plus one from test + assertThat(invoker.getHttpClient().followRedirects()).isFalse(); } } + @Test public void testAuthGoodHttpClient() { AuthClient mockAuth = new TestingAuthClient(); try (ServiceInvoker invoker = ServiceInvoker.builder(CREDENTIALS) .httpClient(new OkHttpClient()) .authClientFactory(inv -> mockAuth) .build()) { - assertEquals(invoker.getServiceUrl(), SERVICE_URL); - assertEquals(invoker.getHttpClient().interceptors().size(), 3); // user-agent & auth & retry + assertThat(invoker.getServiceUrl()).isEqualTo(SERVICE_URL); + assertThat(invoker.getHttpClient().interceptors()).hasSize(3); // user-agent & auth & retry } } + @Test public void testAuthBad() { AuthClient mockAuth = new TestingAuthClient(); try (ServiceInvoker serviceInvoker = ServiceInvoker.builder(BAD_CREDENTIALS).authClientFactory(inv -> mockAuth).build()) { @@ -78,7 +80,7 @@ public void testAuthBad() { .url(serviceInvoker.getServiceUrl().resolve("/test")) .get() .build(); - assertThrows(AuthenticationException.class, () -> serviceInvoker.getHttpClient().newCall(testRequest).execute()); + assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() -> serviceInvoker.getHttpClient().newCall(testRequest).execute()); } } diff --git a/modules/common/src/test/java/com/opengamma/sdk/common/ServiceInvokerTest.java b/modules/common/src/test/java/com/opengamma/sdk/common/ServiceInvokerTest.java index f80c7da..063adc2 100644 --- a/modules/common/src/test/java/com/opengamma/sdk/common/ServiceInvokerTest.java +++ b/modules/common/src/test/java/com/opengamma/sdk/common/ServiceInvokerTest.java @@ -5,12 +5,11 @@ */ package com.opengamma.sdk.common; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.opengamma.sdk.common.auth.Credentials; @@ -23,12 +22,11 @@ /** * Test {@link ServiceInvoker}. */ -@Test public class ServiceInvokerTest { private MockWebServer server; - @BeforeMethod + @BeforeEach public void setUp() throws Exception { server = new MockWebServer(); server.start(18080); @@ -46,7 +44,7 @@ public void setUp() throws Exception { server.enqueue(new MockResponse().setResponseCode(200).setBody("{}")); } - @AfterMethod + @AfterEach public void tearDown() throws Exception { server.shutdown(); } @@ -63,9 +61,9 @@ public void testNewRequestWithReauthenticationSequence() throws Exception { .get() .build(); Response response = invoker.getHttpClient().newCall(request).execute(); - assertEquals(response.code(), 200); - assertEquals(response.message(), "OK"); - assertTrue(response.isSuccessful()); + assertThat(response.code()).isEqualTo(200); + assertThat(response.message()).isEqualTo("OK"); + assertThat(response.isSuccessful()).isTrue(); } } } diff --git a/modules/common/src/test/java/com/opengamma/sdk/common/VersionTest.java b/modules/common/src/test/java/com/opengamma/sdk/common/VersionTest.java index ff8d003..1cdfe94 100644 --- a/modules/common/src/test/java/com/opengamma/sdk/common/VersionTest.java +++ b/modules/common/src/test/java/com/opengamma/sdk/common/VersionTest.java @@ -5,18 +5,18 @@ */ package com.opengamma.sdk.common; -import static org.testng.Assert.assertFalse; +import static org.assertj.core.api.Assertions.assertThat; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; /** * Test {@link Version}. */ -@Test public class VersionTest { + @Test public void test_version() { - assertFalse(Version.getVersionString().isEmpty()); + assertThat(Version.getVersionString().isEmpty()).isFalse(); // this line fails when tests are run in IntelliJ (works in Eclipse) // assertEquals(Version.getVersionString().contains("$"), false); } diff --git a/modules/margin/pom.xml b/modules/margin/pom.xml index 52a853f..07711c3 100644 --- a/modules/margin/pom.xml +++ b/modules/margin/pom.xml @@ -42,8 +42,23 @@ - org.testng - testng + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.assertj + assertj-core test diff --git a/modules/margin/src/test/java/com/opengamma/sdk/margin/MarginCalcRequestTest.java b/modules/margin/src/test/java/com/opengamma/sdk/margin/MarginCalcRequestTest.java index c777cf1..455a7c4 100644 --- a/modules/margin/src/test/java/com/opengamma/sdk/margin/MarginCalcRequestTest.java +++ b/modules/margin/src/test/java/com/opengamma/sdk/margin/MarginCalcRequestTest.java @@ -6,18 +6,17 @@ package com.opengamma.sdk.margin; import static com.opengamma.sdk.margin.MarginCalcRequestType.PARSE_INPUTS; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.nio.file.Paths; import java.time.LocalDate; import java.util.Arrays; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; /** * Test. */ -@Test public class MarginCalcRequestTest { private static final LocalDate VAL_DATE = LocalDate.of(2017, 6, 1); @@ -25,6 +24,7 @@ public class MarginCalcRequestTest { PortfolioDataFile.of(Paths.get("src/test/resources/lch-trades.txt")); //------------------------------------------------------------------------- + @Test @SuppressWarnings("deprecation") public void test_of3() { MarginCalcRequest test = MarginCalcRequest.of(VAL_DATE, "GBP", Arrays.asList(PORTFOLIO)); @@ -35,10 +35,11 @@ public void test_of3() { .reportingCurrency("GBP") .portfolioData(PORTFOLIO) .build(); - assertEquals(test, expected); - assertEquals(test.getType(), MarginCalcRequestType.STANDARD); + assertThat(test).isEqualTo(expected); + assertThat(test.getType()).isEqualTo(MarginCalcRequestType.STANDARD); } + @Test @SuppressWarnings("deprecation") public void test_of4() { MarginCalcRequest test = MarginCalcRequest.of(VAL_DATE, "GBP", Arrays.asList(PORTFOLIO), "MYPARTY"); @@ -50,10 +51,11 @@ public void test_of4() { .portfolioData(PORTFOLIO) .fpmlPartySelectionRegex("MYPARTY") .build(); - assertEquals(test, expected); - assertEquals(test.getType(), MarginCalcRequestType.STANDARD); + assertThat(test).isEqualTo(expected); + assertThat(test.getType()).isEqualTo(MarginCalcRequestType.STANDARD); } + @Test @SuppressWarnings("deprecation") public void test_of5() { MarginCalcRequest test = MarginCalcRequest.of(VAL_DATE, "GBP", Arrays.asList(PORTFOLIO), PARSE_INPUTS, true); @@ -65,8 +67,8 @@ public void test_of5() { .applyClientMultiplier(true) .portfolioData(PORTFOLIO) .build(); - assertEquals(test, expected); - assertEquals(test.getType(), MarginCalcRequestType.PARSE_INPUTS); + assertThat(test).isEqualTo(expected); + assertThat(test.getType()).isEqualTo(MarginCalcRequestType.PARSE_INPUTS); } } diff --git a/modules/margin/src/test/java/com/opengamma/sdk/margin/MarginClientTest.java b/modules/margin/src/test/java/com/opengamma/sdk/margin/MarginClientTest.java index 4c4340a..04d94b5 100644 --- a/modules/margin/src/test/java/com/opengamma/sdk/margin/MarginClientTest.java +++ b/modules/margin/src/test/java/com/opengamma/sdk/margin/MarginClientTest.java @@ -5,10 +5,8 @@ */ package com.opengamma.sdk.margin; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertThrows; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import java.io.IOException; import java.io.UncheckedIOException; @@ -23,9 +21,9 @@ import java.util.concurrent.TimeUnit; import org.joda.beans.ser.JodaBeanSer; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import com.opengamma.sdk.common.ServiceInvoker; import com.opengamma.sdk.common.auth.Credentials; @@ -40,7 +38,6 @@ /** * Test. */ -@Test public class MarginClientTest { private static final Credentials CREDENTIALS = Credentials.ofApiKey("user", "password"); @@ -113,18 +110,19 @@ public class MarginClientTest { private MockWebServer server; //------------------------------------------------------------------------- - @BeforeMethod + @BeforeEach public void setUp() throws IOException { server = new MockWebServer(); server.start(); } - @AfterMethod + @AfterEach public void tearDown() throws IOException { server.shutdown(); } //------------------------------------------------------------------------- + @Test public void test_listCcps() { server.enqueue(new MockResponse() .setHeader("Content-Type", "application/json") @@ -135,13 +133,14 @@ public void test_listCcps() { MarginClient client = MarginClient.of(invoker); CcpsResult ccps = client.listCcps(); - assertEquals(ccps.getCcpNames().size(), 2); - assertEquals(ccps.getCcpNames().get(0), Ccp.LCH.name()); - assertEquals(ccps.getCcpNames().get(1), "RUBBISH"); - assertTrue(ccps.isCcpAvailable(Ccp.LCH)); - assertFalse(ccps.isCcpAvailable(Ccp.CME)); + assertThat(ccps.getCcpNames()).hasSize(2); + assertThat(ccps.getCcpNames().get(0)).isEqualTo(Ccp.LCH.name()); + assertThat(ccps.getCcpNames().get(1)).isEqualTo("RUBBISH"); + assertThat(ccps.isCcpAvailable(Ccp.LCH)).isTrue(); + assertThat(ccps.isCcpAvailable(Ccp.CME)).isFalse(); } + @Test public void test_getCcpInfo() { server.enqueue(new MockResponse() .setHeader("Content-Type", "application/json") @@ -155,13 +154,14 @@ public void test_getCcpInfo() { String expectedCurrency = "GBP"; CcpInfo ccpInfo = client.getCcpInfo(Ccp.LCH); - assertEquals(ccpInfo.getCalculationCurrencies(), Collections.singletonList(expectedCurrency)); - assertEquals(ccpInfo.getReportingCurrencies(), Collections.singletonList(expectedCurrency)); - assertEquals(ccpInfo.getDefaultCurrency(), expectedCurrency); - assertEquals(ccpInfo.getValuationDates(), Collections.singletonList(expectedValuationDate)); - assertEquals(ccpInfo.getLatestValuationDate(), expectedValuationDate); + assertThat(ccpInfo.getCalculationCurrencies()).isEqualTo(Collections.singletonList(expectedCurrency)); + assertThat(ccpInfo.getReportingCurrencies()).isEqualTo(Collections.singletonList(expectedCurrency)); + assertThat(ccpInfo.getDefaultCurrency()).isEqualTo(expectedCurrency); + assertThat(ccpInfo.getValuationDates()).isEqualTo(Collections.singletonList(expectedValuationDate)); + assertThat(ccpInfo.getLatestValuationDate()).isEqualTo(expectedValuationDate); } + @Test public void test_listCcps_fail() throws Exception { server.enqueue(new MockResponse() .setResponseCode(500) @@ -172,10 +172,11 @@ public void test_listCcps_fail() throws Exception { ServiceInvoker invoker = createInvoker(); MarginClient client = MarginClient.of(invoker); - assertThrows(IllegalStateException.class, () -> client.listCcps()); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> client.listCcps()); } //------------------------------------------------------------------------- + @Test @SuppressWarnings("deprecation") public void test_calculate() throws Exception { server.enqueue(new MockResponse() @@ -195,12 +196,13 @@ public void test_calculate() throws Exception { MarginClient client = MarginClient.of(invoker); MarginCalcResult result = client.calculate(Ccp.LCH, REQUEST); - assertEquals(result.getStatus(), MarginCalcResultStatus.COMPLETED); - assertEquals(result.getType(), MarginCalcRequestType.STANDARD); - assertEquals(result.getCalculationTypes(), set(MarginCalcType.MARGIN)); - assertEquals(result.getValuationDate(), VAL_DATE); + assertThat(result.getStatus()).isEqualTo(MarginCalcResultStatus.COMPLETED); + assertThat(result.getType()).isEqualTo(MarginCalcRequestType.STANDARD); + assertThat(result.getCalculationTypes()).isEqualTo(set(MarginCalcType.MARGIN)); + assertThat(result.getValuationDate()).isEqualTo(VAL_DATE); } + @Test public void test_calculate_with_retries_failing() throws Exception { server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.NO_RESPONSE)); server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.NO_RESPONSE)); @@ -208,11 +210,12 @@ public void test_calculate_with_retries_failing() throws Exception { ServiceInvoker invoker = createInvoker(1, 1); MarginClient client = MarginClient.of(invoker); - assertThrows(UncheckedIOException.class, () -> client.listCcps()); - assertThrows(UncheckedIOException.class, () -> client.getCcpInfo(Ccp.LCH)); - assertThrows(UncheckedIOException.class, () -> client.calculate(Ccp.LCH, REQUEST)); + assertThatExceptionOfType(UncheckedIOException.class).isThrownBy(() -> client.listCcps()); + assertThatExceptionOfType(UncheckedIOException.class).isThrownBy(() -> client.getCcpInfo(Ccp.LCH)); + assertThatExceptionOfType(UncheckedIOException.class).isThrownBy(() -> client.calculate(Ccp.LCH, REQUEST)); } + @Test @SuppressWarnings("deprecation") public void test_calculate_with_retries_succeeding() throws Exception { server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.NO_RESPONSE)); @@ -236,10 +239,10 @@ public void test_calculate_with_retries_succeeding() throws Exception { MarginClient client = MarginClient.of(invoker); MarginCalcResult result = client.calculate(Ccp.LCH, REQUEST); - assertEquals(result.getStatus(), MarginCalcResultStatus.COMPLETED); - assertEquals(result.getType(), MarginCalcRequestType.STANDARD); - assertEquals(result.getCalculationTypes(), set(MarginCalcType.MARGIN)); - assertEquals(result.getValuationDate(), VAL_DATE); + assertThat(result.getStatus()).isEqualTo(MarginCalcResultStatus.COMPLETED); + assertThat(result.getType()).isEqualTo(MarginCalcRequestType.STANDARD); + assertThat(result.getCalculationTypes()).isEqualTo(set(MarginCalcType.MARGIN)); + assertThat(result.getValuationDate()).isEqualTo(VAL_DATE); } // This method handles two concurrent HTTP requests, thus defines the MockWebServer in a different way. @@ -248,6 +251,7 @@ public void test_calculate_with_retries_succeeding() throws Exception { // * POST - /margin/v1/ccps/lch/calculations - delta portfolios // * (for each portfolio) GET - /margin/v1/ccps/lch/calculations/[calcID] - until the status is COMPLETED. // * (for each portfolio) DELETE - /margin/v1/ccps/lch/calculations/[calcID] + @Test @SuppressWarnings("deprecation") public void test_calculate_whatif() throws Exception { Dispatcher webServerDispatcher = new Dispatcher() { @@ -313,16 +317,17 @@ public MockResponse dispatch(RecordedRequest request) throws InterruptedExceptio MarginCalcRequest.of(VAL_DATE, "GBP", Collections.singletonList(lchPortfolioFile)); MarginWhatIfCalcResult result = client.calculateWhatIf(Ccp.LCH, REQUEST, Collections.singletonList(lchPortfolioFile)); //Using the same portfolio for delta as well - assertEquals(result.getStatus(), MarginCalcResultStatus.COMPLETED); - assertEquals(result.getType(), MarginCalcRequestType.STANDARD); - assertEquals(result.getCalculationTypes(), set(MarginCalcType.MARGIN)); - assertEquals(result.getValuationDate(), VAL_DATE); - - assertEquals(result.getBaseSummary().getMargin(), 125.0); //Hard coded result, not relevant for portfolio - assertEquals(result.getCombinedSummary().getMargin(), 260.0); //Hard coded result, not relevant for portfolio - assertEquals(result.getDeltaSummary().getMargin(), 135.0); + assertThat(result.getStatus()).isEqualTo(MarginCalcResultStatus.COMPLETED); + assertThat(result.getType()).isEqualTo(MarginCalcRequestType.STANDARD); + assertThat(result.getCalculationTypes()).isEqualTo(set(MarginCalcType.MARGIN)); + assertThat(result.getValuationDate()).isEqualTo(VAL_DATE); + + assertThat(result.getBaseSummary().getMargin()).isEqualTo(125.0); //Hard coded result, not relevant for portfolio + assertThat(result.getCombinedSummary().getMargin()).isEqualTo(260.0); //Hard coded result, not relevant for portfolio + assertThat(result.getDeltaSummary().getMargin()).isEqualTo(135.0); } + @Test public void test_calculate_postFail() throws Exception { server.enqueue(new MockResponse() .setResponseCode(500) @@ -333,9 +338,10 @@ public void test_calculate_postFail() throws Exception { ServiceInvoker invoker = createInvoker(); MarginClient client = MarginClient.of(invoker); - assertThrows(IllegalStateException.class, () -> client.calculate(Ccp.LCH, REQUEST)); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> client.calculate(Ccp.LCH, REQUEST)); } + @Test public void test_calculate_getFail() throws Exception { server.enqueue(new MockResponse() .setResponseCode(202) @@ -350,9 +356,10 @@ public void test_calculate_getFail() throws Exception { ServiceInvoker invoker = createInvoker(); MarginClient client = MarginClient.of(invoker); - assertThrows(IllegalStateException.class, () -> client.calculate(Ccp.LCH, REQUEST)); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> client.calculate(Ccp.LCH, REQUEST)); } + @Test public void test_calculate_deleteFail() throws Exception { server.enqueue(new MockResponse() .setResponseCode(202) @@ -375,6 +382,7 @@ public void test_calculate_deleteFail() throws Exception { } //------------------------------------------------------------------------- + @Test public void test_delete_fail() throws Exception { server.enqueue(new MockResponse() .setResponseCode(500) @@ -385,10 +393,11 @@ public void test_delete_fail() throws Exception { ServiceInvoker invoker = createInvoker(); MarginClient client = MarginClient.of(invoker); - assertThrows(IllegalStateException.class, () -> client.deleteCalculation(Ccp.LCH, "789")); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> client.deleteCalculation(Ccp.LCH, "789")); } //------------------------------------------------------------------------- + @Test @SuppressWarnings("deprecation") public void test_calculateAsync() throws Exception { server.enqueue(new MockResponse() @@ -410,12 +419,13 @@ public void test_calculateAsync() throws Exception { CompletableFuture future = client.calculateAsync(Ccp.LCH, REQUEST); MarginCalcResult result = future.join(); - assertEquals(result.getStatus(), MarginCalcResultStatus.COMPLETED); - assertEquals(result.getType(), MarginCalcRequestType.STANDARD); - assertEquals(result.getCalculationTypes(), set(MarginCalcType.MARGIN)); - assertEquals(result.getValuationDate(), VAL_DATE); + assertThat(result.getStatus()).isEqualTo(MarginCalcResultStatus.COMPLETED); + assertThat(result.getType()).isEqualTo(MarginCalcRequestType.STANDARD); + assertThat(result.getCalculationTypes()).isEqualTo(set(MarginCalcType.MARGIN)); + assertThat(result.getValuationDate()).isEqualTo(VAL_DATE); } + @Test public void test_calculateAsync_createError() throws Exception { server.enqueue(new MockResponse() .setResponseCode(500)); @@ -425,10 +435,11 @@ public void test_calculateAsync_createError() throws Exception { MarginClient client = MarginClient.of(invoker); CompletableFuture future = client.calculateAsync(Ccp.LCH, REQUEST); - assertThrows(CompletionException.class, () -> future.join()); - assertEquals(server.getRequestCount(), 1); + assertThatExceptionOfType(CompletionException.class).isThrownBy(() -> future.join()); + assertThat(server.getRequestCount()).isEqualTo(1); } + @Test public void test_calculateAsync_pollingError() throws Exception { server.enqueue(new MockResponse() .setResponseCode(202) @@ -447,8 +458,8 @@ public void test_calculateAsync_pollingError() throws Exception { MarginClient client = MarginClient.of(invoker); CompletableFuture future = client.calculateAsync(Ccp.LCH, REQUEST); - assertThrows(CompletionException.class, () -> future.join()); - assertEquals(server.getRequestCount(), 4); + assertThatExceptionOfType(CompletionException.class).isThrownBy(() -> future.join()); + assertThat(server.getRequestCount()).isEqualTo(4); } private ServiceInvoker createInvoker() { diff --git a/modules/margin/src/test/java/com/opengamma/sdk/margin/MarginDetailDeserializerTest.java b/modules/margin/src/test/java/com/opengamma/sdk/margin/MarginDetailDeserializerTest.java index d1fa9ae..35c457f 100644 --- a/modules/margin/src/test/java/com/opengamma/sdk/margin/MarginDetailDeserializerTest.java +++ b/modules/margin/src/test/java/com/opengamma/sdk/margin/MarginDetailDeserializerTest.java @@ -5,10 +5,9 @@ */ package com.opengamma.sdk.margin; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; /** * Test {@link MarginDetailDeserializer}. @@ -17,13 +16,13 @@ public class MarginDetailDeserializerTest { @Test public void testSupportedCcp() { - assertTrue(MarginDetailDeserializer.of(Ccp.LCH).isPresent()); - assertTrue(MarginDetailDeserializer.of(Ccp.of("LCH_TEST")).isPresent()); + assertThat(MarginDetailDeserializer.of(Ccp.LCH).isPresent()).isTrue(); + assertThat(MarginDetailDeserializer.of(Ccp.of("LCH_TEST")).isPresent()).isTrue(); } @Test public void testUnsupportedCcp() { - assertFalse(MarginDetailDeserializer.of(Ccp.EUREX).isPresent()); - assertFalse(MarginDetailDeserializer.of(Ccp.of("UNKNOWN")).isPresent()); + assertThat(MarginDetailDeserializer.of(Ccp.EUREX).isPresent()).isFalse(); + assertThat(MarginDetailDeserializer.of(Ccp.of("UNKNOWN")).isPresent()).isFalse(); } } diff --git a/modules/margin/src/test/java/com/opengamma/sdk/margin/PortfolioDataFileTest.java b/modules/margin/src/test/java/com/opengamma/sdk/margin/PortfolioDataFileTest.java index e7480be..4787c95 100644 --- a/modules/margin/src/test/java/com/opengamma/sdk/margin/PortfolioDataFileTest.java +++ b/modules/margin/src/test/java/com/opengamma/sdk/margin/PortfolioDataFileTest.java @@ -5,9 +5,7 @@ */ package com.opengamma.sdk.margin; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -24,21 +22,22 @@ import org.joda.beans.Bean; import org.joda.beans.ser.JodaBeanSer; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; /** * Test {@link PortfolioDataFile}. */ -@Test @SuppressWarnings("deprecation") public class PortfolioDataFileTest { + @Test public void test_ofString_small() { PortfolioDataFile test = PortfolioDataFile.of("name.txt", "a=b"); - assertEquals(test.getName(), "name.txt.gz.base64"); - assertEquals(test.getData(), "H4sIAAAAAAAAAEu0TQIAzzAAfwMAAAA="); + assertThat(test.getName()).isEqualTo("name.txt.gz.base64"); + assertThat(test.getData()).isEqualTo("H4sIAAAAAAAAAEu0TQIAzzAAfwMAAAA="); } + @Test public void test_ofString_large() { Random random = new Random(1); StringBuilder buf = new StringBuilder(1_200_000); @@ -47,60 +46,67 @@ public void test_ofString_large() { } String str = buf.toString(); PortfolioDataFile test = PortfolioDataFile.of("name.txt", str); - assertEquals(test.getName(), "name.txt.gz.base64"); - assertEquals(test.getData(), Base64.getEncoder().encodeToString(gzip(str))); + assertThat(test.getName()).isEqualTo("name.txt.gz.base64"); + assertThat(test.getData()).isEqualTo(Base64.getEncoder().encodeToString(gzip(str))); } //------------------------------------------------------------------------- + @Test public void test_ofPath_CSV() { Path path = Paths.get("src/test/resources/simple.csv"); PortfolioDataFile test = PortfolioDataFile.of(path); - assertTrue(test.getName().endsWith("simple.csv.gz.base64")); - assertEquals(test.getData(), Base64.getEncoder().encodeToString(gzip(path))); + assertThat(test.getName().endsWith("simple.csv.gz.base64")).isTrue(); + assertThat(test.getData()).isEqualTo(Base64.getEncoder().encodeToString(gzip(path))); } + @Test public void test_ofPath_XML() { Path path = Paths.get("src/test/resources/simple.xml"); PortfolioDataFile test = PortfolioDataFile.of(path); - assertTrue(test.getName().endsWith("simple.xml.gz.base64")); - assertEquals(test.getData(), Base64.getEncoder().encodeToString(gzip(path))); + assertThat(test.getName().endsWith("simple.xml.gz.base64")).isTrue(); + assertThat(test.getData()).isEqualTo(Base64.getEncoder().encodeToString(gzip(path))); } + @Test public void test_ofPath_XLS() { Path path = Paths.get("src/test/resources/simple.xls"); PortfolioDataFile test = PortfolioDataFile.of(path); - assertTrue(test.getName().endsWith("simple.xls.gz.base64")); - assertEquals(test.getData(), Base64.getEncoder().encodeToString(gzip(path))); + assertThat(test.getName().endsWith("simple.xls.gz.base64")).isTrue(); + assertThat(test.getData()).isEqualTo(Base64.getEncoder().encodeToString(gzip(path))); } + @Test public void test_ofPath_XLSX() { Path path = Paths.get("src/test/resources/simple.xlsx"); PortfolioDataFile test = PortfolioDataFile.of(path); - assertTrue(test.getName().endsWith("simple.xlsx.gz.base64")); - assertEquals(test.getData(), Base64.getEncoder().encodeToString(gzip(path))); + assertThat(test.getName().endsWith("simple.xlsx.gz.base64")).isTrue(); + assertThat(test.getData()).isEqualTo(Base64.getEncoder().encodeToString(gzip(path))); } //------------------------------------------------------------------------- + @Test public void test_ofBean_unchanged() { Bean bean = PortfolioDataFile.of("name.txt", "a=b"); PortfolioDataFile test = PortfolioDataFile.of(bean); - assertSame(test, bean); + assertThat(test).isSameAs(bean); } + @Test public void test_ofBean_trade() { Bean bean = TradeValue.of(1, "GBP", 2); String xml = JodaBeanSer.COMPACT.xmlWriter().write(bean); PortfolioDataFile test = PortfolioDataFile.of(bean); - assertEquals(test, PortfolioDataFile.of("TradeValue.xml", xml)); + assertThat(test).isEqualTo(PortfolioDataFile.of("TradeValue.xml", xml)); } //------------------------------------------------------------------------- + @Test public void test_ofCombined() { Path path1 = Paths.get("src/test/resources/simple.xml"); Path path2 = Paths.get("src/test/resources/simple.xls"); PortfolioDataFile test = PortfolioDataFile.ofCombined(Arrays.asList(path1, path2)); - assertEquals(test.getName(), "JavaSDK.zip.base64"); - assertEquals(test.getData(), Base64.getEncoder().encodeToString(zip(path1, path2))); + assertThat(test.getName()).isEqualTo("JavaSDK.zip.base64"); + assertThat(test.getData()).isEqualTo(Base64.getEncoder().encodeToString(zip(path1, path2))); } private static byte[] gzip(String str) { diff --git a/modules/margin/src/test/java/com/opengamma/sdk/margin/TenorStringConverterTest.java b/modules/margin/src/test/java/com/opengamma/sdk/margin/TenorStringConverterTest.java index 77e2231..d83dbcd 100644 --- a/modules/margin/src/test/java/com/opengamma/sdk/margin/TenorStringConverterTest.java +++ b/modules/margin/src/test/java/com/opengamma/sdk/margin/TenorStringConverterTest.java @@ -5,23 +5,23 @@ */ package com.opengamma.sdk.margin; -import static org.testng.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; import java.time.Period; -import org.testng.annotations.Test; +import org.junit.jupiter.api.Test; /** * Test lenient period converter. */ -@Test public class TenorStringConverterTest { + @Test public void test() { TenorStringConverter test = new TenorStringConverter(); - assertEquals(test.convertFromString(Period.class, "P3M"), Period.ofMonths(3)); - assertEquals(test.convertFromString(Period.class, "3M"), Period.ofMonths(3)); - assertEquals(test.convertToString(Period.ofMonths(3)), "P3M"); + assertThat(test.convertFromString(Period.class, "P3M")).isEqualTo(Period.ofMonths(3)); + assertThat(test.convertFromString(Period.class, "3M")).isEqualTo(Period.ofMonths(3)); + assertThat(test.convertToString(Period.ofMonths(3))).isEqualTo("P3M"); } } diff --git a/modules/margin/src/test/java/com/opengamma/sdk/margin/it/MarginClientRemoteIT.java b/modules/margin/src/test/java/com/opengamma/sdk/margin/it/MarginClientRemoteIT.java index bc58a09..489ee50 100644 --- a/modules/margin/src/test/java/com/opengamma/sdk/margin/it/MarginClientRemoteIT.java +++ b/modules/margin/src/test/java/com/opengamma/sdk/margin/it/MarginClientRemoteIT.java @@ -5,9 +5,9 @@ */ package com.opengamma.sdk.margin.it; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.Offset.offset; +import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.io.IOException; import java.nio.file.Paths; @@ -17,9 +17,14 @@ import java.util.HashSet; import java.util.Set; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +import org.junit.jupiter.api.TestMethodOrder; import com.opengamma.sdk.common.ServiceInvoker; import com.opengamma.sdk.common.auth.Credentials; @@ -51,8 +56,9 @@ * Run as a formal integration test via maven failsafe. * Requires two environment variables, hence is run via a maven profile. */ -@Test @SuppressWarnings("deprecation") +@TestInstance(Lifecycle.PER_CLASS) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class MarginClientRemoteIT { // this test uses TestNG dependsOn so the individual tests are linked // this allows the latest valuation date to be tested without repeatedly calling getCcpInfo remotely @@ -65,7 +71,7 @@ public class MarginClientRemoteIT { private LocalDate valDate; //------------------------------------------------------------------------- - @BeforeClass + @BeforeAll public void setUp() throws IOException { String apiKey = System.getenv("MARGIN_API_DEV_ID"); String secret = System.getenv("MARGIN_API_DEV_SECRET"); @@ -76,42 +82,48 @@ public void setUp() throws IOException { marginClient = MarginClient.of(invoker); } - @AfterClass + @AfterAll public void tearDown() throws IOException { - invoker.close(); + if (invoker != null) { + invoker.close(); + } marginClient = null; } //------------------------------------------------------------------------- + @Test + @Order(1) public void test_listCcps() { CcpsResult ccps = marginClient.listCcps(); - assertTrue(ccps.getCcpNames().size() > 2); - assertTrue(ccps.getCcpNames().contains(Ccp.LCH.toString())); - assertTrue(ccps.getCcps().size() > 2); - assertTrue(ccps.getCcps().contains(Ccp.LCH)); - assertTrue(ccps.isCcpAvailable(Ccp.LCH)); + assertThat(ccps.getCcpNames().size() > 2).isTrue(); + assertThat(ccps.getCcpNames().contains(Ccp.LCH.toString())).isTrue(); + assertThat(ccps.getCcps().size() > 2).isTrue(); + assertThat(ccps.getCcps().contains(Ccp.LCH)).isTrue(); + assertThat(ccps.isCcpAvailable(Ccp.LCH)).isTrue(); } - @Test(dependsOnMethods = "test_listCcps") + @Test + @Order(2) public void test_getCcpInfo() { CcpInfo ccpInfo = marginClient.getCcpInfo(Ccp.LCH); - assertTrue(ccpInfo.getReportingCurrencies().contains("GBP")); - assertTrue(ccpInfo.getCalculationCurrencies().contains("GBP")); - assertEquals(ccpInfo.getDefaultCurrency(), "GBP"); - assertTrue(ccpInfo.getValuationDates().size() > 1); - assertTrue(ccpInfo.getCalculationTypes().contains(MarginCalcType.PORTFOLIO_SUMMARY)); - assertTrue(ccpInfo.getCalculationTypes().contains(MarginCalcType.MARGIN)); - assertTrue(ccpInfo.getCalculationTypes().contains(MarginCalcType.MARGIN_DETAIL)); - assertTrue(ccpInfo.getCalculationTypes().contains(MarginCalcType.PRESENT_VALUE)); - assertTrue(ccpInfo.getCalculationTypes().contains(MarginCalcType.DELTA)); - assertTrue(ccpInfo.getCalculationTypes().contains(MarginCalcType.GAMMA)); + assertThat(ccpInfo.getReportingCurrencies().contains("GBP")).isTrue(); + assertThat(ccpInfo.getCalculationCurrencies().contains("GBP")).isTrue(); + assertThat(ccpInfo.getDefaultCurrency()).isEqualTo("GBP"); + assertThat(ccpInfo.getValuationDates().size() > 1).isTrue(); + assertThat(ccpInfo.getCalculationTypes().contains(MarginCalcType.PORTFOLIO_SUMMARY)).isTrue(); + assertThat(ccpInfo.getCalculationTypes().contains(MarginCalcType.MARGIN)).isTrue(); + assertThat(ccpInfo.getCalculationTypes().contains(MarginCalcType.MARGIN_DETAIL)).isTrue(); + assertThat(ccpInfo.getCalculationTypes().contains(MarginCalcType.PRESENT_VALUE)).isTrue(); + assertThat(ccpInfo.getCalculationTypes().contains(MarginCalcType.DELTA)).isTrue(); + assertThat(ccpInfo.getCalculationTypes().contains(MarginCalcType.GAMMA)).isTrue(); valDate = ccpInfo.getLatestValuationDate(); } //------------------------------------------------------------------------- - @Test(dependsOnMethods = "test_getCcpInfo") + @Test + @Order(10) public void test_calculate_portfolioSummary() throws Exception { - assert valDate != null; + assumeTrue(valDate != null); MarginCalcRequest request = MarginCalcRequest.builder() .calculationTypes(MarginCalcType.PORTFOLIO_SUMMARY) .valuationDate(valDate) @@ -119,22 +131,23 @@ public void test_calculate_portfolioSummary() throws Exception { .portfolioData(PORTFOLIO) .build(); MarginCalcResult result = marginClient.calculate(Ccp.LCH, request); - assertEquals(result.getStatus(), MarginCalcResultStatus.COMPLETED); - assertEquals(result.getType(), MarginCalcRequestType.PARSE_INPUTS); - assertEquals(result.getCalculationTypes(), set(MarginCalcType.PORTFOLIO_SUMMARY)); - assertEquals(result.getValuationDate(), valDate); - assertEquals(result.getReportingCurrency(), "GBP"); - assertEquals(result.getCalculationCurrency(), "GBP"); - assertEquals(result.getMode(), MarginCalcMode.SPOT); - assertEquals(result.getPortfolioItems().size(), 4); - assertFalse(result.getMargin().isPresent()); - assertFalse(result.getMarginDetail().isPresent()); - assertFalse(result.getTradeValuations().isPresent()); + assertThat(result.getStatus()).isEqualTo(MarginCalcResultStatus.COMPLETED); + assertThat(result.getType()).isEqualTo(MarginCalcRequestType.PARSE_INPUTS); + assertThat(result.getCalculationTypes()).isEqualTo(set(MarginCalcType.PORTFOLIO_SUMMARY)); + assertThat(result.getValuationDate()).isEqualTo(valDate); + assertThat(result.getReportingCurrency()).isEqualTo("GBP"); + assertThat(result.getCalculationCurrency()).isEqualTo("GBP"); + assertThat(result.getMode()).isEqualTo(MarginCalcMode.SPOT); + assertThat(result.getPortfolioItems()).hasSize(4); + assertThat(result.getMargin().isPresent()).isFalse(); + assertThat(result.getMarginDetail().isPresent()).isFalse(); + assertThat(result.getTradeValuations().isPresent()).isFalse(); } - @Test(dependsOnMethods = "test_getCcpInfo") + @Test + @Order(10) public void test_calculate_margin() throws Exception { - assert valDate != null; + assumeTrue(valDate != null); MarginCalcRequest request = MarginCalcRequest.builder() .calculationTypes(MarginCalcType.MARGIN) .valuationDate(valDate) @@ -142,30 +155,31 @@ public void test_calculate_margin() throws Exception { .portfolioData(PORTFOLIO) .build(); MarginCalcResult result = marginClient.calculate(Ccp.LCH, request); - assertEquals(result.getStatus(), MarginCalcResultStatus.COMPLETED); - assertEquals(result.getType(), MarginCalcRequestType.STANDARD); - assertEquals(result.getCalculationTypes(), set(MarginCalcType.MARGIN)); - assertEquals(result.getValuationDate(), valDate); - assertEquals(result.getReportingCurrency(), "GBP"); - assertEquals(result.getCalculationCurrency(), "GBP"); - assertEquals(result.getMode(), MarginCalcMode.SPOT); - assertEquals(result.getPortfolioItems().size(), 0); - assertTrue(result.getMargin().isPresent()); - assertFalse(result.getMarginDetail().isPresent()); - assertFalse(result.getTradeValuations().isPresent()); + assertThat(result.getStatus()).isEqualTo(MarginCalcResultStatus.COMPLETED); + assertThat(result.getType()).isEqualTo(MarginCalcRequestType.STANDARD); + assertThat(result.getCalculationTypes()).isEqualTo(set(MarginCalcType.MARGIN)); + assertThat(result.getValuationDate()).isEqualTo(valDate); + assertThat(result.getReportingCurrency()).isEqualTo("GBP"); + assertThat(result.getCalculationCurrency()).isEqualTo("GBP"); + assertThat(result.getMode()).isEqualTo(MarginCalcMode.SPOT); + assertThat(result.getPortfolioItems()).hasSize(0); + assertThat(result.getMargin().isPresent()).isTrue(); + assertThat(result.getMarginDetail().isPresent()).isFalse(); + assertThat(result.getTradeValuations().isPresent()).isFalse(); MarginSummary margin = result.getMargin().get(); - assertTrue(margin.getMargin() != 0); - assertTrue(margin.getMarginDetails().size() > 2); - assertEquals(margin.getBreakdown().getTotalMargin(), margin.getMargin(), 1e-8); - assertTrue(margin.getBreakdown().getBaseMargin() != 0); - assertTrue(margin.getBreakdown().getAddOns() != 0); - assertEquals(margin.getBreakdown().getNetLiquidatingValue(), 0, 1e-8); + assertThat(margin.getMargin() != 0).isTrue(); + assertThat(margin.getMarginDetails().size() > 2).isTrue(); + assertThat(margin.getBreakdown().getTotalMargin()).isCloseTo(margin.getMargin(), offset(1e-8)); + assertThat(margin.getBreakdown().getBaseMargin() != 0).isTrue(); + assertThat(margin.getBreakdown().getAddOns() != 0).isTrue(); + assertThat(margin.getBreakdown().getNetLiquidatingValue()).isCloseTo(0, offset(1e-8)); } - @Test(dependsOnMethods = "test_getCcpInfo") + @Test + @Order(10) public void test_calculate_marginDetail() throws Exception { - assert valDate != null; + assumeTrue(valDate != null); MarginCalcRequest request = MarginCalcRequest.builder() .calculationTypes(MarginCalcType.MARGIN_DETAIL) .valuationDate(valDate) @@ -173,38 +187,39 @@ public void test_calculate_marginDetail() throws Exception { .portfolioData(PORTFOLIO) .build(); MarginCalcResult result = marginClient.calculate(Ccp.LCH, request); - assertEquals(result.getStatus(), MarginCalcResultStatus.COMPLETED); - assertEquals(result.getType(), MarginCalcRequestType.STANDARD); - assertEquals(result.getCalculationTypes(), set(MarginCalcType.MARGIN_DETAIL)); - assertEquals(result.getValuationDate(), valDate); - assertEquals(result.getReportingCurrency(), "GBP"); - assertEquals(result.getCalculationCurrency(), "GBP"); - assertEquals(result.getMode(), MarginCalcMode.SPOT); - assertEquals(result.getPortfolioItems().size(), 0); - assertFalse(result.getMargin().isPresent()); - assertTrue(result.getMarginDetail().isPresent()); - assertFalse(result.getTradeValuations().isPresent()); + assertThat(result.getStatus()).isEqualTo(MarginCalcResultStatus.COMPLETED); + assertThat(result.getType()).isEqualTo(MarginCalcRequestType.STANDARD); + assertThat(result.getCalculationTypes()).isEqualTo(set(MarginCalcType.MARGIN_DETAIL)); + assertThat(result.getValuationDate()).isEqualTo(valDate); + assertThat(result.getReportingCurrency()).isEqualTo("GBP"); + assertThat(result.getCalculationCurrency()).isEqualTo("GBP"); + assertThat(result.getMode()).isEqualTo(MarginCalcMode.SPOT); + assertThat(result.getPortfolioItems()).hasSize(0); + assertThat(result.getMargin().isPresent()).isFalse(); + assertThat(result.getMarginDetail().isPresent()).isTrue(); + assertThat(result.getTradeValuations().isPresent()).isFalse(); LchMarginDetail margin = (LchMarginDetail) result.getMarginDetail().get(); - assertEquals(margin.getCcp(), Ccp.LCH); - assertTrue(margin.getTotalMargin() != 0); - assertEquals(margin.getBaseScenarioIds().size(), 6); - assertTrue(margin.getIndices().size() > 2); + assertThat(margin.getCcp()).isEqualTo(Ccp.LCH); + assertThat(margin.getTotalMargin() != 0).isTrue(); + assertThat(margin.getBaseScenarioIds()).hasSize(6); + assertThat(margin.getIndices().size() > 2).isTrue(); LchMarginIndex index = margin.getIndices().get(0); - assertTrue(index.getIndexName().length() > 4); - assertTrue(index.getDiversifiedBaseMargin() != 0); - assertTrue(index.getUndiversifiedBaseMargin() != 0); - assertEquals(index.getIndexScenarioIds().size(), 6); - assertTrue(margin.getScenarios().size() >= 6); + assertThat(index.getIndexName().length() > 4).isTrue(); + assertThat(index.getDiversifiedBaseMargin() != 0).isTrue(); + assertThat(index.getUndiversifiedBaseMargin() != 0).isTrue(); + assertThat(index.getIndexScenarioIds()).hasSize(6); + assertThat(margin.getScenarios().size() >= 6).isTrue(); LchMarginScenario scenario = margin.getScenarios().get(0); - assertTrue(scenario.getId().length() > 0); - assertTrue(scenario.getScaledPortfolioPnl() != 0); - assertTrue(scenario.getUnscaledPortfolioPnl() != 0); + assertThat(scenario.getId().length() > 0).isTrue(); + assertThat(scenario.getScaledPortfolioPnl() != 0).isTrue(); + assertThat(scenario.getUnscaledPortfolioPnl() != 0).isTrue(); } - @Test(dependsOnMethods = "test_getCcpInfo") + @Test + @Order(10) public void test_calculate_pv() throws Exception { - assert valDate != null; + assumeTrue(valDate != null); MarginCalcRequest request = MarginCalcRequest.builder() .calculationTypes(MarginCalcType.PRESENT_VALUE, MarginCalcType.DELTA) .valuationDate(valDate) @@ -212,44 +227,44 @@ public void test_calculate_pv() throws Exception { .portfolioData(PORTFOLIO) .build(); MarginCalcResult result = marginClient.calculate(Ccp.LCH, request); - assertEquals(result.getStatus(), MarginCalcResultStatus.COMPLETED); - assertEquals(result.getType(), MarginCalcRequestType.STANDARD); - assertEquals(result.getCalculationTypes(), set(MarginCalcType.PRESENT_VALUE, MarginCalcType.DELTA)); - assertEquals(result.getValuationDate(), valDate); - assertEquals(result.getReportingCurrency(), "GBP"); - assertEquals(result.getCalculationCurrency(), "GBP"); - assertEquals(result.getMode(), MarginCalcMode.SPOT); - assertEquals(result.getPortfolioItems().size(), 0); - assertFalse(result.getMargin().isPresent()); - assertFalse(result.getMarginDetail().isPresent()); - assertTrue(result.getTradeValuations().isPresent()); + assertThat(result.getStatus()).isEqualTo(MarginCalcResultStatus.COMPLETED); + assertThat(result.getType()).isEqualTo(MarginCalcRequestType.STANDARD); + assertThat(result.getCalculationTypes()).isEqualTo(set(MarginCalcType.PRESENT_VALUE, MarginCalcType.DELTA)); + assertThat(result.getValuationDate()).isEqualTo(valDate); + assertThat(result.getReportingCurrency()).isEqualTo("GBP"); + assertThat(result.getCalculationCurrency()).isEqualTo("GBP"); + assertThat(result.getMode()).isEqualTo(MarginCalcMode.SPOT); + assertThat(result.getPortfolioItems()).hasSize(0); + assertThat(result.getMargin().isPresent()).isFalse(); + assertThat(result.getMarginDetail().isPresent()).isFalse(); + assertThat(result.getTradeValuations().isPresent()).isTrue(); TradeValuations vals = result.getTradeValuations().get(); - assertTrue(vals.getTotalPresentValue() != 0); - assertTrue(vals.getTotalDelta().isPresent()); - assertTrue(vals.getBucketedDelta().isPresent()); - assertFalse(vals.getTotalGamma().isPresent()); - assertFalse(vals.getBucketedGamma().isPresent()); - assertTrue(vals.getTotalDelta().getAsDouble() != 0); - assertEquals(vals.getBucketedDelta().get().size(), 3); - assertEquals(vals.getTrades().size(), 4); + assertThat(vals.getTotalPresentValue() != 0).isTrue(); + assertThat(vals.getTotalDelta().isPresent()).isTrue(); + assertThat(vals.getBucketedDelta().isPresent()).isTrue(); + assertThat(vals.getTotalGamma().isPresent()).isFalse(); + assertThat(vals.getBucketedGamma().isPresent()).isFalse(); + assertThat(vals.getTotalDelta().getAsDouble() != 0).isTrue(); + assertThat(vals.getBucketedDelta().get()).hasSize(3); + assertThat(vals.getTrades()).hasSize(4); TradeValuation val = vals.getTrades().get(0); - assertTrue(val.getValue().isPresent()); - assertTrue(val.getDelta().isPresent()); - assertFalse(val.getGamma().isPresent()); + assertThat(val.getValue().isPresent()).isTrue(); + assertThat(val.getDelta().isPresent()).isTrue(); + assertThat(val.getGamma().isPresent()).isFalse(); TradeValue value = val.getValue().get(); - assertTrue(value.getPresentValue() != 0); - assertEquals(value.getTradeCurrency().length(), 3); - assertTrue(value.getPresentValueTradeCurrency() != 0); + assertThat(value.getPresentValue() != 0).isTrue(); + assertThat(value.getTradeCurrency().length()).isEqualTo(3); + assertThat(value.getPresentValueTradeCurrency() != 0).isTrue(); TradeSensitivity delta = val.getDelta().get(); - assertTrue(delta.getSensitivity() != 0); - assertTrue(delta.getCurveSensitivity().size() > 0); + assertThat(delta.getSensitivity() != 0).isTrue(); + assertThat(delta.getCurveSensitivity().size() > 0).isTrue(); TradeCurveSensitivity curve = delta.getCurveSensitivity().get(0); - assertEquals(curve.getCurrency().length(), 3); - assertTrue(curve.getCurveName().length() > 4); - assertTrue(curve.getSensitivity() != 0); - assertTrue(curve.getTenorSensitivity().size() > 4); - assertTrue(curve.getTenorSensitivity().get(Period.ofMonths(12)) != 0); + assertThat(curve.getCurrency().length()).isEqualTo(3); + assertThat(curve.getCurveName().length() > 4).isTrue(); + assertThat(curve.getSensitivity() != 0).isTrue(); + assertThat(curve.getTenorSensitivity().size() > 4).isTrue(); + assertThat(curve.getTenorSensitivity().get(Period.ofMonths(12)) != 0).isTrue(); } //------------------------------------------------------------------------- diff --git a/modules/pom.xml b/modules/pom.xml index 8d92ded..b3fddbd 100644 --- a/modules/pom.xml +++ b/modules/pom.xml @@ -204,6 +204,13 @@ + + org.junit + junit-bom + ${junit5.version} + pom + import + org.assertj assertj-core @@ -219,11 +226,6 @@ mockwebserver ${okhttp.version} - - org.testng - testng - ${testng.version} - ch.qos.logback logback-classic @@ -394,12 +396,12 @@ 2.2.1 2.7.1 2.6.2 + 5.5.1 1.2.3 3.0.0 1.7.28 3.14.2 1.17.4 - 6.14.2 1.1