X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=aai-core%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2FHttpTestUtil.java;h=92cb59c5c95d72315279c934359b3aa7848d17d5;hb=8fb7aa6480d4d7becbbab5fcfabd6af3f57e7d74;hp=1fd85fb7a5111b52681ebaea20498da0107afe7b;hpb=a86d6a6644d6de3f3f814cd6e25cfe2213d5dd05;p=aai%2Faai-common.git diff --git a/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java b/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java index 1fd85fb7..92cb59c5 100644 --- a/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java +++ b/aai-core/src/test/java/org/onap/aai/HttpTestUtil.java @@ -52,11 +52,11 @@ import static org.mockito.Mockito.when; public class HttpTestUtil extends RESTAPI { - + protected HttpEntry traversalHttpEntry; - + protected HttpEntry traversalUriHttpEntry; - + private static final EELFLogger logger = EELFManager.getInstance().getLogger(HttpTestUtil.class); protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); @@ -77,7 +77,7 @@ public class HttpTestUtil extends RESTAPI { this.queryStyle = qs; traversalHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); traversalUriHttpEntry = SpringContextAware.getBean("traversalUriHttpEntry", HttpEntry.class); - + } public void init(){ @@ -121,7 +121,10 @@ public class HttpTestUtil extends RESTAPI { try { - uri = uri.replaceAll("/aai/", ""); + if(uri.startsWith("/aai/")){ + uri = uri.substring(5); + } + logger.info("Starting the put request for the uri {} with payload {}", uri, payload); String [] arr = uri.split("/"); @@ -142,7 +145,7 @@ public class HttpTestUtil extends RESTAPI { Mockito.when(uriInfo.getPath()).thenReturn(uri); DBConnectionType type = DBConnectionType.REALTIME; - + traversalHttpEntry.setHttpEntryProperties(version, type); Loader loader = traversalHttpEntry.getLoader(); dbEngine = traversalHttpEntry.getDbEngine(); @@ -179,9 +182,9 @@ public class HttpTestUtil extends RESTAPI { response = responsesTuple.getValue1().get(0).getValue1(); } catch (AAIException e) { - response = this.consumerExceptionResponseGenerator(httpHeaders, uriInfo, HttpMethod.PUT, e); - success = false; - } catch(Exception e){ + response = this.consumerExceptionResponseGenerator(httpHeaders, uriInfo, HttpMethod.PUT, e); + success = false; + } catch(Exception e){ AAIException ex = new AAIException("AAI_4000", e); response = this.consumerExceptionResponseGenerator(httpHeaders, uriInfo, HttpMethod.PUT, ex); success = false; @@ -206,7 +209,7 @@ public class HttpTestUtil extends RESTAPI { return response; } - public Response doGet(String uri) throws UnsupportedEncodingException, AAIException { + public Response doGet(String uri, String depth){ this.init(); Response response = null; @@ -215,8 +218,11 @@ public class HttpTestUtil extends RESTAPI { try { - uri = uri.replaceAll("/aai/", ""); - logger.info("Starting the GET request for the uri {} with depth {}", uri, "all"); + if(uri.startsWith("/aai/")){ + uri = uri.substring(5); + } + + logger.info("Starting the GET request for the uri {} with depth {}", uri, depth); String [] arr = uri.split("/"); @@ -240,21 +246,29 @@ public class HttpTestUtil extends RESTAPI { dbEngine = traversalHttpEntry.getDbEngine(); URI uriObject = UriBuilder.fromPath(uri).build(); - URIToObject uriToObject = new URIToObject(loader, uriObject); - String objType = uriToObject.getEntityName(); - queryParameters.add("depth", "all"); + if(depth != null){ + queryParameters.add("depth", depth); + } + QueryParser uriQuery = dbEngine.getQueryBuilder().createQueryFromURI(uriObject, queryParameters); Mockito.when(uriInfo.getPath()).thenReturn(uri); + URIToObject uriToObject = new URIToObject(loader, uriObject); + String objType = ""; + if (!uriQuery.getContainerType().equals("")) { + objType = uriQuery.getContainerType(); + } else { + objType = uriQuery.getResultType(); + } logger.info("Unmarshalling the payload to this {}", objType); Introspector obj = loader.introspectorFromName(objType); DBRequest dbRequest = - new DBRequest.Builder(HttpMethod.GET, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION") - .build(); + new DBRequest.Builder(HttpMethod.GET, uriObject, uriQuery, obj, httpHeaders, uriInfo, "JUNIT-TRANSACTION") + .build(); List dbRequestList = new ArrayList<>(); dbRequestList.add(dbRequest); @@ -288,6 +302,10 @@ public class HttpTestUtil extends RESTAPI { return response; } + public Response doGet(String uri) throws UnsupportedEncodingException, AAIException { + return this.doGet(uri, "all"); + } + public Response doDelete(String uri, String resourceVersion) throws UnsupportedEncodingException, AAIException { this.init(); @@ -321,7 +339,7 @@ public class HttpTestUtil extends RESTAPI { Mockito.when(uriInfo.getPath()).thenReturn(uri); DBConnectionType type = DBConnectionType.REALTIME; traversalHttpEntry.setHttpEntryProperties(version, type); - + traversalHttpEntry.setHttpEntryProperties(version, type); Loader loader = traversalHttpEntry.getLoader(); dbEngine = traversalHttpEntry.getDbEngine();