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());
}
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")));
}
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")));
}
Aggregations