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=efff07bf47f9847d371bb64f4cd6c8bc3281f12a;hpb=71393bb2bf9fb10962723e61cf0e70d9aa202645;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 efff07b..9fa5fe1 100644 --- a/src/test/java/org/onap/aai/sa/rest/DocumentTest.java +++ b/src/test/java/org/onap/aai/sa/rest/DocumentTest.java @@ -71,7 +71,7 @@ public class DocumentTest { DocumentApi documentApi; @Before - public void setUp(){ + public void setUp() { MockitoAnnotations.initMocks(this); documentApi = new DocumentApi(searchServiceApi); } @@ -80,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; @@ -97,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 @@ -117,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"; @@ -144,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"; @@ -170,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"; @@ -197,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"; @@ -224,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()); @@ -251,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; @@ -269,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()); } @@ -289,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()); } @@ -309,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()); } @@ -336,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()); } @@ -356,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()); } @@ -376,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()); } @@ -403,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()); } @@ -423,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()); } @@ -443,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()); } @@ -469,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; @@ -486,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()); } @@ -506,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()); } @@ -526,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()); } @@ -545,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()); } @@ -564,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()); } @@ -574,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); @@ -584,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()); } @@ -603,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()); } @@ -621,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()); } @@ -640,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()); }