Search in sources :

Example 16 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)

Example 17 with RestClient

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

the class AAIResourcesClientTest method testGetOneNoResults.

@Test
public void testGetOneNoResults() {
    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.empty());
    Optional<GenericVnf> result = aaiClient.getOne(GenericVnfs.class, GenericVnf.class, uri);
    assertFalse(result.isPresent());
}
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 18 with RestClient

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

the class GraphInventoryResourcesClient method exists.

/**
 * returns false if the object does not exist in GraphInventory
 *
 * @param uri
 * @return
 */
public boolean exists(Uri uri) {
    GraphInventoryResourceUri<?, ?> forceMinimal = (Uri) uri.clone();
    forceMinimal.format(Format.COUNT);
    forceMinimal.limit(1);
    try {
        RestClient giRC = client.createClient(forceMinimal);
        return giRC.get().getStatus() == Status.OK.getStatusCode();
    } catch (NotFoundException e) {
        return false;
    }
}
Also used : RestClient(org.onap.so.client.RestClient) NotFoundException(javax.ws.rs.NotFoundException) HttpAwareUri(org.onap.aaiclient.client.graphinventory.entities.uri.HttpAwareUri) GraphInventorySingleResourceUri(org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventorySingleResourceUri) GraphInventoryPluralResourceUri(org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventoryPluralResourceUri) GraphInventoryResourceUri(org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventoryResourceUri)

Example 19 with RestClient

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

the class GraphInventoryResourcesClient method connect.

/**
 * Adds a relationship between two objects in GraphInventory with a given edge label
 *
 * @param uriA
 * @param uriB
 * @param edge label
 * @return
 */
public void connect(SingleUri uriA, SingleUri uriB, EdgeLabel label) {
    GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?> uriAClone = (SingleUri) uriA.clone();
    RestClient giRC = client.createClient(uriAClone.relationshipAPI());
    giRC.put(this.buildRelationship(uriB, label));
}
Also used : RestClient(org.onap.so.client.RestClient)

Example 20 with RestClient

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

the class GraphInventoryResourcesClient method connect.

/**
 * Adds a relationship between two objects in GraphInventory
 *
 * @param uriA
 * @param uriB
 * @return
 */
public void connect(SingleUri uriA, SingleUri uriB) {
    GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?> uriAClone = (SingleUri) uriA.clone();
    RestClient giRC = client.createClient(uriAClone.relationshipAPI());
    giRC.put(this.buildRelationship(uriB));
}
Also used : RestClient(org.onap.so.client.RestClient)

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