Search in sources :

Example 21 with RestClient

use of org.onap.so.client.RestClient in project so by onap.

the class AAIResourcesClientTest method testGetOne.

@Test
public void testGetOne() {
    GenericVnf vnf = new GenericVnf();
    vnf.setVnfId("my-vnf-id");
    GenericVnfs vnfs = new GenericVnfs();
    vnfs.getGenericVnf().add(vnf);
    AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs());
    RestClient restClientMock = mock(RestClient.class);
    doReturn(restClientMock).when(client).createClient(uri);
    when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.of(vnfs));
    Optional<GenericVnf> result = aaiClient.getOne(GenericVnfs.class, GenericVnf.class, uri);
    assertEquals("my-vnf-id", result.get().getVnfId());
}
Also used : GenericVnf(org.onap.aai.domain.yang.GenericVnf) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) GenericVnfs(org.onap.aai.domain.yang.GenericVnfs) RestClient(org.onap.so.client.RestClient) Test(org.junit.Test)

Example 22 with RestClient

use of org.onap.so.client.RestClient in project so by onap.

the class AAIRestClientTest method cachePutTest.

@Test
public void cachePutTest() throws URISyntaxException, InterruptedException {
    wireMockRule.stubFor(put(urlPathMatching("/cached/1")).willReturn(aResponse().withStatus(200)));
    wireMockRule.stubFor(get(urlPathMatching("/cached/1")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody("{}")));
    AAIProperties props = new AAIProperties() {

        @Override
        public URL getEndpoint() throws MalformedURLException {
            return new URL(String.format("http://localhost:%s", wireMockRule.port()));
        }

        @Override
        public String getSystemName() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public boolean isCachingEnabled() {
            return true;
        }

        @Override
        public AAIVersion getDefaultVersion() {
            return AAIVersion.LATEST;
        }

        @Override
        public String getAuth() {
            return null;
        }

        @Override
        public String getKey() {
            return null;
        }
    };
    RestClient client = new AAIRestClient(props, new URI("/cached/1"), new MultivaluedHashMap<>());
    Response response = client.get();
    response.readEntity(String.class);
    client.put("wow");
    client.get();
    response.readEntity(String.class);
    verify(2, getRequestedFor(urlEqualTo("/cached/1")));
}
Also used : WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) Response(javax.ws.rs.core.Response) RestClient(org.onap.so.client.RestClient) URI(java.net.URI) URL(java.net.URL) Test(org.junit.Test)

Example 23 with RestClient

use of org.onap.so.client.RestClient in project so by onap.

the class AAIRestClientTest method cacheGetTest.

@Test
public void cacheGetTest() throws URISyntaxException, InterruptedException {
    wireMockRule.stubFor(get(urlPathMatching("/cached")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/plain").withBody("value")));
    AAIProperties props = new AAIProperties() {

        @Override
        public URL getEndpoint() throws MalformedURLException {
            return new URL(String.format("http://localhost:%s", wireMockRule.port()));
        }

        @Override
        public String getSystemName() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public boolean isCachingEnabled() {
            return true;
        }

        @Override
        public AAIVersion getDefaultVersion() {
            return AAIVersion.LATEST;
        }

        @Override
        public String getAuth() {
            return null;
        }

        @Override
        public String getKey() {
            return null;
        }
    };
    RestClient client = new AAIRestClient(props, new URI("/cached"), new MultivaluedHashMap<>());
    Response response = client.get();
    response.readEntity(String.class);
    response = client.get();
    response.readEntity(String.class);
    verify(1, getRequestedFor(urlEqualTo("/cached")));
}
Also used : WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) Response(javax.ws.rs.core.Response) RestClient(org.onap.so.client.RestClient) URI(java.net.URI) URL(java.net.URL) Test(org.junit.Test)

Aggregations

RestClient (org.onap.so.client.RestClient)23 Test (org.junit.Test)8 Response (javax.ws.rs.core.Response)7 GenericVnf (org.onap.aai.domain.yang.GenericVnf)6 AAIPluralResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri)6 GenericVnfs (org.onap.aai.domain.yang.GenericVnfs)5 StackInfo (org.onap.so.openstack.beans.StackInfo)4 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)2 URI (java.net.URI)2 URL (java.net.URL)2 NotFoundException (javax.ws.rs.NotFoundException)2 BulkProcessFailed (org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed)2 CreateStackParam (com.woorea.openstack.heat.model.CreateStackParam)1 Stack (com.woorea.openstack.heat.model.Stack)1 Map (java.util.Map)1 GenericType (javax.ws.rs.core.GenericType)1 SingleTransactionResponse (org.onap.aaiclient.client.aai.entities.singletransaction.SingleTransactionResponse)1 GraphInventoryPluralResourceUri (org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventoryPluralResourceUri)1 GraphInventoryResourceUri (org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventoryResourceUri)1 GraphInventorySingleResourceUri (org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventorySingleResourceUri)1