Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions modules/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,23 @@

<!-- Testing -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,62 +21,66 @@
/**
* 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)
.httpClientFactory(
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()) {
Request testRequest = new Request.Builder()
.url(serviceInvoker.getServiceUrl().resolve("/test"))
.get()
.build();
assertThrows(AuthenticationException.class, () -> serviceInvoker.getHttpClient().newCall(testRequest).execute());
assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() -> serviceInvoker.getHttpClient().newCall(testRequest).execute());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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();
}
Expand All @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
19 changes: 17 additions & 2 deletions modules/margin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,23 @@

<!-- Testing -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
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);
private static final PortfolioDataFile PORTFOLIO =
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));
Expand All @@ -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");
Expand All @@ -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);
Expand All @@ -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);
}

}
Loading