diff options
Diffstat (limited to 'so-cnf-adapter-application')
3 files changed, 46 insertions, 7 deletions
diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java index e3431ef..430a5e5 100644 --- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java +++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/rest/CnfAdapterRest.java @@ -115,6 +115,15 @@ public class CnfAdapterRest { } + @ResponseBody + @RequestMapping(value = {"/api/cnf-adapter/v1/instance/{instanceId}/query"}, method = RequestMethod.GET, + produces = "application/json") + public String getInstanceQueryByInstanceId(@PathVariable("instanceId") String instanceId) { + logger.info("getInstanceQueryByInstanceId called."); + + return cnfAdapterService.getInstanceQueryByInstanceId(instanceId); + } + @RequestMapping(value = {"/api/cnf-adapter/v1/instance"}, method = RequestMethod.GET, produces = "application/json") public String getInstanceByRBNameOrRBVersionOrProfileName( @RequestParam(value = "rb-name", required = false) String rbName, diff --git a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/CnfAdapterService.java b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/CnfAdapterService.java index d1314dd..bfb84c3 100644 --- a/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/CnfAdapterService.java +++ b/so-cnf-adapter-application/src/main/java/org/onap/so/adapters/cnf/service/CnfAdapterService.java @@ -72,7 +72,7 @@ public class CnfAdapterService { } throw e; } catch (HttpStatusCodeException e) { - logger.error("Error in Multicloud, e"); + logger.error("Error in Multicloud", e); throw e; } } @@ -115,7 +115,7 @@ public class CnfAdapterService { } throw e; } catch (HttpStatusCodeException e) { - logger.error("Error in Multicloud, e"); + logger.error("Error in Multicloud", e); throw e; } } @@ -143,7 +143,7 @@ public class CnfAdapterService { } throw e; } catch (HttpStatusCodeException e) { - logger.error("Error in Multicloud, e"); + logger.error("Error in Multicloud", e); throw e; } } @@ -171,12 +171,30 @@ public class CnfAdapterService { } throw e; } catch (HttpStatusCodeException e) { - logger.error("Error in Multicloud, e"); + logger.error("Error in Multicloud", e); throw e; } } + public String getInstanceQueryByInstanceId(String instanceId) { + logger.info("CnfAdapterService getInstanceQueryByInstanceId called"); + ResponseEntity<String> instanceResponse = null; + try { + String uri = "http://multicloud-k8s:9015"; + String path = "/v1/instance/" + instanceId + "/query"; + String endpoint = UriBuilder.fromUri(uri).path(path).build().toString(); + HttpEntity<?> requestEntity = new HttpEntity<>(getHttpHeaders()); + instanceResponse = restTemplate.exchange(endpoint, HttpMethod.GET, requestEntity, String.class); + return instanceResponse.getBody(); + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException(e.getResponseBodyAsString()); + } + throw e; + } + } + public String getInstanceByRBNameOrRBVersionOrProfileName(String rbName, String rbVersion, String profileName) throws JsonParseException, JsonMappingException, IOException { @@ -201,7 +219,7 @@ public class CnfAdapterService { } throw e; } catch (HttpStatusCodeException e) { - logger.error("Error in Multicloud, e"); + logger.error("Error in Multicloud", e); throw e; } } @@ -229,7 +247,7 @@ public class CnfAdapterService { } throw e; } catch (HttpStatusCodeException e) { - logger.error("Error in Multicloud, e"); + logger.error("Error in Multicloud", e); throw e; } } diff --git a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java index a04d236..cfd6ba1 100644 --- a/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java +++ b/so-cnf-adapter-application/src/test/java/org/onap/so/adapters/cnf/rest/CnfAdapterRestTest.java @@ -31,13 +31,13 @@ import org.onap.so.adapters.cnf.service.CnfAdapterService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.util.ReflectionTestUtils; import org.springframework.web.multipart.MultipartFile; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Java6Assertions.assertThat; @RunWith(SpringRunner.class) @@ -135,6 +135,17 @@ public class CnfAdapterRestTest { } @Test + public void getInstanceQueryByInstanceIdTest() { + String instanceId = "123"; + String queryResponseMock = "queryResponseMock"; + + Mockito.when(cnfAdapterService.getInstanceQueryByInstanceId(instanceId)).thenReturn(queryResponseMock); + + String result = cnfAdapterRest.getInstanceQueryByInstanceId(instanceId); + assertThat(result).isEqualTo(queryResponseMock); + } + + @Test public void getInstanceByRBNameOrRBVersionOrProfileNameTest() throws Exception { String rbName = "xyz"; @@ -560,3 +571,4 @@ public class CnfAdapterRestTest { } + |