X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fsa%2Frest%2FDocumentTest.java;h=9fa5fe1aca6bca3621c386a558d55069b7aa3d8b;hb=15af66b115f3e8046b2d0f2634fb77b3d835f730;hp=83ba5a7fff9cacd52cd62948a32399e651e980dd;hpb=ce701746049abfd94a87b46e43f296faf32d6213;p=aai%2Fsearch-data-service.git diff --git a/src/test/java/org/onap/aai/sa/rest/DocumentTest.java b/src/test/java/org/onap/aai/sa/rest/DocumentTest.java index 83ba5a7..9fa5fe1 100644 --- a/src/test/java/org/onap/aai/sa/rest/DocumentTest.java +++ b/src/test/java/org/onap/aai/sa/rest/DocumentTest.java @@ -21,6 +21,10 @@ package org.onap.aai.sa.rest; import com.fasterxml.jackson.core.JsonProcessingException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +// import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MultivaluedMap; import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; @@ -36,15 +40,10 @@ import org.onap.aai.sa.searchdbabstraction.entity.DocumentOperationResult; import org.onap.aai.sa.searchdbabstraction.entity.ErrorResult; import org.onap.aai.sa.searchdbabstraction.entity.SearchHits; import org.onap.aai.sa.searchdbabstraction.entity.SearchOperationResult; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -// import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MultivaluedMap; -import org.springframework.http.HttpHeaders; - public class DocumentTest { @@ -72,7 +71,7 @@ public class DocumentTest { DocumentApi documentApi; @Before - public void setUp(){ + public void setUp() { MockitoAnnotations.initMocks(this); documentApi = new DocumentApi(searchServiceApi); } @@ -81,14 +80,14 @@ public class DocumentTest { public void testDocumentClass_AllMethods() throws JsonProcessingException { Document doc = new Document(); doc.setField("name-1", "value-1"); - Assert.assertTrue(doc.getFields().size()==1); + Assert.assertTrue(doc.getFields().size() == 1); Assert.assertTrue(doc.toJson().contains("value-1")); Assert.assertNotNull(doc.toString()); Assert.assertTrue(doc.toString().contains("name-1")); } @Test - public void testProcessPost_NullContent(){ + public void testProcessPost_NullContent() { String transactionId = "transactionId-1"; String remoteAddr = "http://127.0.0.1"; String content = null; @@ -98,10 +97,10 @@ public class DocumentTest { Mockito.when(request.getMethod()).thenReturn("testMethod"); Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - ResponseEntity response = documentApi.processPost(content, request, headers, httpResponse, "index", - documentStore); + ResponseEntity response = + documentApi.processPost(content, request, headers, httpResponse, "index", documentStore); Assert.assertNotNull(response); - Assert.assertTrue( HttpStatus.BAD_REQUEST.value () == response.getStatusCodeValue ()); + Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue()); } @Test @@ -118,12 +117,13 @@ public class DocumentTest { Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenThrow(IllegalArgumentException.class); - ResponseEntity response = documentApi.processPost(content, request, headers, httpResponse, "index", - documentStore); + ResponseEntity response = + documentApi.processPost(content, request, headers, httpResponse, "index", documentStore); Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.FORBIDDEN.value () == response.getStatusCodeValue ()); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); } -// + + // @Test public void testProcessPost_ValidRequest() throws Exception { String transactionId = "transactionId-1"; @@ -145,12 +145,13 @@ public class DocumentTest { Mockito.when(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class), Mockito.anyBoolean())).thenReturn(result); Mockito.doNothing().when(httpResponse).setHeader(Mockito.anyString(), Mockito.anyString()); - ResponseEntity response = documentApi.processPost(content, request, headers, httpResponse, "index", - documentStore); + ResponseEntity response = + documentApi.processPost(content, request, headers, httpResponse, "index", documentStore); Assert.assertNotNull(response); - Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value () == response.getStatusCodeValue ()); + Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue()); } -// + + // @Test public void testProcessSearchWithGet_Created() throws Exception { String transactionId = "transactionId-1"; @@ -171,13 +172,14 @@ public class DocumentTest { Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenReturn(true); Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result); - ResponseEntityresponse = documentApi.processSearchWithGet(content, request, headers, "index-1", - "query-text", documentStore); + ResponseEntity response = + documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.CREATED.value() == response.getStatusCodeValue()); } -// + + // @Test public void testProcessSearchWithGet_ValidateThrowsException() throws Exception { String transactionId = "transactionId-1"; @@ -198,13 +200,14 @@ public class DocumentTest { Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenThrow(IllegalArgumentException.class); Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result); - ResponseEntityresponse = documentApi.processSearchWithGet(content, request, headers, "index-1", - "query-text", documentStore); + ResponseEntity response = + documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); } -// + + // @Test public void testProcessSearchWithGet_ValidateIsFalse() throws Exception { String transactionId = "transactionId-1"; @@ -225,8 +228,8 @@ public class DocumentTest { Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenReturn(false); Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result); - ResponseEntityresponse = documentApi.processSearchWithGet(content, request, headers, "index-1", - "query-text", documentStore); + ResponseEntity response = + documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); @@ -252,15 +255,15 @@ public class DocumentTest { Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenReturn(true); Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result); - ResponseEntityresponse = documentApi.processSearchWithGet(content, request, headers, "index-1", - "query-text", documentStore); + ResponseEntity response = + documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue()); } @Test - public void testProcessPut_NullContent(){ + public void testProcessPut_NullContent() { String transactionId = "transactionId-1"; String remoteAddr = "http://127.0.0.1"; String content = null; @@ -270,8 +273,8 @@ public class DocumentTest { Mockito.when(request.getMethod()).thenReturn("testMethod"); Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - ResponseEntityresponse = documentApi.processPut(content, request, headers, httpResponse, "index","id-1", - documentStore); + ResponseEntity response = + documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue()); } @@ -290,8 +293,8 @@ public class DocumentTest { Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenThrow(IllegalArgumentException.class); - ResponseEntityresponse = documentApi.processPut(content, request, headers, httpResponse, "index","id-1", - documentStore); + ResponseEntity response = + documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); } @@ -310,8 +313,8 @@ public class DocumentTest { Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenReturn(false); - ResponseEntityresponse = documentApi.processPut(content, request, headers, httpResponse, "index","id-1", - documentStore); + ResponseEntity response = + documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); } @@ -337,8 +340,8 @@ public class DocumentTest { .thenReturn(true); Mockito.when(documentStore.updateDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class), Mockito.anyBoolean())).thenReturn(result); - ResponseEntityresponse = documentApi.processPut(content, request, headers, httpResponse, "index","id-1", - documentStore); + ResponseEntity response = + documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue()); } @@ -357,8 +360,8 @@ public class DocumentTest { Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenThrow(IllegalArgumentException.class); - ResponseEntityresponse = documentApi.processDelete(content, request, headers, httpResponse, "index","id-1", - documentStore); + ResponseEntity response = + documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); } @@ -377,8 +380,8 @@ public class DocumentTest { Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenReturn(false); - ResponseEntityresponse = documentApi.processDelete(content, request, headers, httpResponse, "index","id-1", - documentStore); + ResponseEntity response = + documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); } @@ -404,8 +407,8 @@ public class DocumentTest { .thenReturn(true); Mockito.when(documentStore.deleteDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class))) .thenReturn(result); - ResponseEntityresponse = documentApi.processDelete(content, request, headers, httpResponse, "index","id-1", - documentStore); + ResponseEntity response = + documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue()); } @@ -424,8 +427,8 @@ public class DocumentTest { Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenThrow(IllegalArgumentException.class); - ResponseEntityresponse = documentApi.processGet(content, request, headers, httpResponse, "index","id-1", - documentStore); + ResponseEntity response = + documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); } @@ -444,8 +447,8 @@ public class DocumentTest { Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenReturn(false); - ResponseEntityresponse = documentApi.processGet(content, request, headers, httpResponse, "index","id-1", - documentStore); + ResponseEntity response = + documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); } @@ -470,14 +473,14 @@ public class DocumentTest { .thenReturn(true); Mockito.when(documentStore.getDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class))) .thenReturn(result); - ResponseEntityresponse = documentApi.processGet(content, request, headers, httpResponse, "index","id-1", - documentStore); + ResponseEntity response = + documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue()); } @Test - public void testQueryWithGetWithPayload_NullContent(){ + public void testQueryWithGetWithPayload_NullContent() { String transactionId = "transactionId-1"; String remoteAddr = "http://127.0.0.1"; String content = null; @@ -487,8 +490,8 @@ public class DocumentTest { Mockito.when(request.getMethod()).thenReturn("testMethod"); Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); Mockito.when(request.getRemoteHost()).thenReturn("localhost"); - ResponseEntityresponse = documentApi.queryWithGetWithPayload(content, request, headers, "index-1", - documentStore); + ResponseEntity response = + documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue()); } @@ -507,8 +510,8 @@ public class DocumentTest { Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenThrow(IllegalArgumentException.class); - ResponseEntityresponse = documentApi.queryWithGetWithPayload(content, request, headers, "index-1", - documentStore); + ResponseEntity response = + documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); } @@ -527,8 +530,8 @@ public class DocumentTest { Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenReturn(false); - ResponseEntityresponse = documentApi.queryWithGetWithPayload(content, request, headers, "index-1", - documentStore); + ResponseEntity response = + documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); } @@ -546,8 +549,8 @@ public class DocumentTest { Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenReturn(false); - ResponseEntityresponse = indexApi.processCreateIndex("document-1", request, headers, "index-1", - documentStore); + ResponseEntity response = + indexApi.processCreateIndex("document-1", request, headers, "index-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); } @@ -565,8 +568,8 @@ public class DocumentTest { Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenThrow(IllegalArgumentException.class); - ResponseEntityresponse = indexApi.processCreateIndex("document-1", request, headers, "index-1", - documentStore); + ResponseEntity response = + indexApi.processCreateIndex("document-1", request, headers, "index-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); } @@ -575,7 +578,7 @@ public class DocumentTest { public void testCreateProcessIndex_IndexApi_NullDocument() throws Exception { String transactionId = "transactionId-1"; String remoteAddr = "http://127.0.0.1"; - String documentSchema= null; + String documentSchema = null; // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); @@ -585,8 +588,8 @@ public class DocumentTest { Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenReturn(true); - ResponseEntityresponse = indexApi.processCreateIndex(documentSchema, request, headers, "index-1", - documentStore); + ResponseEntity response = + indexApi.processCreateIndex(documentSchema, request, headers, "index-1", documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue()); } @@ -604,7 +607,7 @@ public class DocumentTest { Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenReturn(false); - ResponseEntityresponse = indexApi.processDelete("document-1", request, headers, documentStore); + ResponseEntity response = indexApi.processDelete("document-1", request, headers, documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); } @@ -622,7 +625,7 @@ public class DocumentTest { Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenThrow(IllegalArgumentException.class); - ResponseEntityresponse = indexApi.processDelete("document-1", request, headers, documentStore); + ResponseEntity response = indexApi.processDelete("document-1", request, headers, documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); } @@ -641,7 +644,7 @@ public class DocumentTest { Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenReturn(true); Mockito.when(documentStore.deleteIndex(Mockito.anyString())).thenThrow(DocumentStoreOperationException.class); - ResponseEntityresponse = indexApi.processDelete("document-1", request, headers, documentStore); + ResponseEntity response = indexApi.processDelete("document-1", request, headers, documentStore); Assert.assertNotNull(response); Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue()); }