diff options
Diffstat (limited to 'common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java')
-rw-r--r-- | common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java | 140 |
1 files changed, 67 insertions, 73 deletions
diff --git a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java index 46e4c98b3e..55da6e7d52 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java +++ b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientWithServiceInstanceUriTest.java @@ -28,14 +28,11 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; - import java.util.List; import java.util.Optional; - import javax.ws.rs.core.GenericType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; - import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -48,80 +45,77 @@ import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.aai.entities.uri.ServiceInstanceUri; import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl; - import com.github.tomakehurst.wiremock.junit.WireMockRule; @RunWith(MockitoJUnitRunner.class) public class AAIResourcesClientWithServiceInstanceUriTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Spy - public AAIClient client; - - @InjectMocks - public AAIResourcesClient aaiClient = new AAIResourcesClient(); - - private ServiceInstanceUri uri; - @Before - public void setUp() { - doReturn(new DefaultAAIPropertiesImpl(wireMockRule.port())).when(client).getRestProperties(); - wireMockRule.stubFor(get(urlMatching("/aai/v[0-9]+/nodes.*")) - .willReturn(aResponse() - .withStatus(404) - .withHeader("Content-Type", "application/json") - .withHeader("Mock", "true"))); - - uri = spy((ServiceInstanceUri)AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "id")); - doReturn(aaiClient).when(uri).getResourcesClient(); - } - - @Test - public void getWithClass() { - AAIResourcesClient client = aaiClient; - Optional<String> result = client.get(String.class, uri); - - assertThat(result.isPresent(), equalTo(false)); - } - - @Test - public void getFullResponse() { - AAIResourcesClient client = aaiClient; - Response result = client.getFullResponse(uri); - assertThat(result.getStatus(), equalTo(Status.NOT_FOUND.getStatusCode())); - } - - @Test - public void getWithGenericType() { - AAIResourcesClient client = aaiClient; - Optional<List<String>> result = client.get(new GenericType<List<String>>() {}, uri); - assertThat(result.isPresent(), equalTo(false)); - } - - @Test - public void getAAIWrapper() { - AAIResourcesClient client = aaiClient; - AAIResultWrapper result = client.get(uri); - assertThat(result.isEmpty(), equalTo(true)); - } - - @Test - public void getWithException() { - AAIResourcesClient client = aaiClient; - this.thrown.expect(IllegalArgumentException.class); - AAIResultWrapper result = client.get(uri, IllegalArgumentException.class); - } - - @Test - public void existsTest() { - AAIResourcesClient client = aaiClient; - doReturn(uri).when(uri).clone(); - boolean result = client.exists(uri); - assertThat(result, equalTo(false)); - } + @Rule + public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Spy + public AAIClient client; + + @InjectMocks + public AAIResourcesClient aaiClient = new AAIResourcesClient(); + + private ServiceInstanceUri uri; + + @Before + public void setUp() { + doReturn(new DefaultAAIPropertiesImpl(wireMockRule.port())).when(client).getRestProperties(); + wireMockRule.stubFor(get(urlMatching("/aai/v[0-9]+/nodes.*")).willReturn( + aResponse().withStatus(404).withHeader("Content-Type", "application/json").withHeader("Mock", "true"))); + + uri = spy((ServiceInstanceUri) AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, "id")); + doReturn(aaiClient).when(uri).getResourcesClient(); + } + + @Test + public void getWithClass() { + AAIResourcesClient client = aaiClient; + Optional<String> result = client.get(String.class, uri); + + assertThat(result.isPresent(), equalTo(false)); + } + + @Test + public void getFullResponse() { + AAIResourcesClient client = aaiClient; + Response result = client.getFullResponse(uri); + assertThat(result.getStatus(), equalTo(Status.NOT_FOUND.getStatusCode())); + } + + @Test + public void getWithGenericType() { + AAIResourcesClient client = aaiClient; + Optional<List<String>> result = client.get(new GenericType<List<String>>() {}, uri); + assertThat(result.isPresent(), equalTo(false)); + } + + @Test + public void getAAIWrapper() { + AAIResourcesClient client = aaiClient; + AAIResultWrapper result = client.get(uri); + assertThat(result.isEmpty(), equalTo(true)); + } + + @Test + public void getWithException() { + AAIResourcesClient client = aaiClient; + this.thrown.expect(IllegalArgumentException.class); + AAIResultWrapper result = client.get(uri, IllegalArgumentException.class); + } + + @Test + public void existsTest() { + AAIResourcesClient client = aaiClient; + doReturn(uri).when(uri).clone(); + boolean result = client.exists(uri); + assertThat(result, equalTo(false)); + } } |