Add unit tests to increase sonar coverage
[aai/search-data-service.git] / src / test / java / org / onap / aai / sa / rest / DocumentTest.java
diff --git a/src/test/java/org/onap/aai/sa/rest/DocumentTest.java b/src/test/java/org/onap/aai/sa/rest/DocumentTest.java
new file mode 100644 (file)
index 0000000..2f502f9
--- /dev/null
@@ -0,0 +1,644 @@
+/**\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ */\r
+package org.onap.aai.sa.rest;\r
+\r
+import com.fasterxml.jackson.core.JsonProcessingException;\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.InjectMocks;\r
+import org.mockito.Mock;\r
+import org.mockito.Mockito;\r
+import org.mockito.MockitoAnnotations;\r
+import org.onap.aai.sa.searchdbabstraction.elasticsearch.dao.DocumentStoreDataEntity;\r
+import org.onap.aai.sa.searchdbabstraction.elasticsearch.dao.DocumentStoreInterface;\r
+import org.onap.aai.sa.searchdbabstraction.elasticsearch.exception.DocumentStoreOperationException;\r
+import org.onap.aai.sa.searchdbabstraction.entity.DocumentOperationResult;\r
+import org.onap.aai.sa.searchdbabstraction.entity.ErrorResult;\r
+import org.onap.aai.sa.searchdbabstraction.entity.SearchHits;\r
+import org.onap.aai.sa.searchdbabstraction.entity.SearchOperationResult;\r
+\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.HttpServletResponse;\r
+import javax.ws.rs.core.HttpHeaders;\r
+import javax.ws.rs.core.MultivaluedMap;\r
+import javax.ws.rs.core.Response;\r
+\r
+public class DocumentTest {\r
+\r
+    @Mock\r
+    SearchServiceApi searchServiceApi;\r
+\r
+    @Mock\r
+    HttpServletRequest request;\r
+\r
+    @Mock\r
+    HttpHeaders headers;\r
+\r
+    @Mock\r
+    HttpServletResponse httpResponse;\r
+\r
+    @Mock\r
+    DocumentStoreInterface documentStore;\r
+\r
+    @Mock\r
+    MultivaluedMap<String, String> multivaluedMap;\r
+\r
+    @InjectMocks\r
+    IndexApi indexApi;\r
+\r
+    DocumentApi documentApi;\r
+\r
+    @Before\r
+    public void setUp(){\r
+        MockitoAnnotations.initMocks(this);\r
+        documentApi = new DocumentApi(searchServiceApi);\r
+    }\r
+\r
+    @Test\r
+    public void testDocumentClass_AllMethods() throws JsonProcessingException {\r
+        Document doc = new Document();\r
+        doc.setField("name-1", "value-1");\r
+        Assert.assertTrue(doc.getFields().size()==1);\r
+        Assert.assertTrue(doc.toJson().contains("value-1"));\r
+        Assert.assertNotNull(doc.toString());\r
+        Assert.assertTrue(doc.toString().contains("name-1"));\r
+    }\r
+\r
+    @Test\r
+    public void testProcessPost_NullContent(){\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = null;\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Response response = documentApi.processPost(content, request, headers, httpResponse, "index",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.BAD_REQUEST.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testProcessPost_NotNullContent() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenThrow(IllegalArgumentException.class);\r
+        Response response = documentApi.processPost(content, request, headers, httpResponse, "index",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FORBIDDEN.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testProcessPost_ValidRequest() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        DocumentOperationResult result = new DocumentOperationResult();\r
+        result.setResultCode(150);\r
+        result.setError(new ErrorResult("type-1", "reason-1"));\r
+        result.setFailureCause("test-failure");\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenReturn(true);\r
+        Mockito.when(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class),\r
+                Mockito.anyBoolean())).thenReturn(result);\r
+        Mockito.doNothing().when(httpResponse).setHeader(Mockito.anyString(), Mockito.anyString());\r
+        Response response = documentApi.processPost(content, request, headers, httpResponse, "index",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testProcessSearchWithGet_Created() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        SearchOperationResult result = new SearchOperationResult();\r
+        result.setResultCode(201);\r
+        SearchHits hits = new SearchHits();\r
+        hits.setTotalHits("2");\r
+        result.setSearchResult(hits);\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenReturn(true);\r
+        Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result);\r
+        Response response = documentApi.processSearchWithGet(content, request, headers, "index-1",\r
+                "query-text", documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.CREATED.getStatusCode() == response.getStatus());\r
+\r
+    }\r
+\r
+    @Test\r
+    public void testProcessSearchWithGet_ValidateThrowsException() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        SearchOperationResult result = new SearchOperationResult();\r
+        result.setResultCode(201);\r
+        SearchHits hits = new SearchHits();\r
+        hits.setTotalHits("2");\r
+        result.setSearchResult(hits);\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenThrow(IllegalArgumentException.class);\r
+        Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result);\r
+        Response response = documentApi.processSearchWithGet(content, request, headers, "index-1",\r
+                "query-text", documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FORBIDDEN.getStatusCode() == response.getStatus());\r
+\r
+    }\r
+\r
+    @Test\r
+    public void testProcessSearchWithGet_ValidateIsFalse() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        SearchOperationResult result = new SearchOperationResult();\r
+        result.setResultCode(201);\r
+        SearchHits hits = new SearchHits();\r
+        hits.setTotalHits("2");\r
+        result.setSearchResult(hits);\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenReturn(false);\r
+        Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result);\r
+        Response response = documentApi.processSearchWithGet(content, request, headers, "index-1",\r
+                "query-text", documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FORBIDDEN.getStatusCode() == response.getStatus());\r
+\r
+    }\r
+\r
+    @Test\r
+    public void testProcessSearchWithGet_InvalidResult() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        SearchOperationResult result = new SearchOperationResult();\r
+        result.setResultCode(302);\r
+        SearchHits hits = new SearchHits();\r
+        hits.setTotalHits("2");\r
+        result.setSearchResult(hits);\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenReturn(true);\r
+        Mockito.when(documentStore.search(Mockito.anyString(), Mockito.anyString())).thenReturn(result);\r
+        Response response = documentApi.processSearchWithGet(content, request, headers, "index-1",\r
+                "query-text", documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FOUND.getStatusCode() == response.getStatus());\r
+\r
+    }\r
+\r
+    @Test\r
+    public void testProcessPut_NullContent(){\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = null;\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Response response = documentApi.processPut(content, request, headers, httpResponse, "index","id-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.BAD_REQUEST.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testProcessPut_RequestThrowsException() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenThrow(IllegalArgumentException.class);\r
+        Response response = documentApi.processPut(content, request, headers, httpResponse, "index","id-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FORBIDDEN.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testProcessPut_RequestInvalid() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenReturn(false);\r
+        Response response = documentApi.processPut(content, request, headers, httpResponse, "index","id-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FORBIDDEN.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testProcessPut_ResultInvalid() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        DocumentOperationResult result = new DocumentOperationResult();\r
+        result.setResultCode(302);\r
+        result.setError(new ErrorResult("type-1", "reason-1"));\r
+        result.setFailureCause("test-failure");\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenReturn(true);\r
+        Mockito.when(documentStore.updateDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class),\r
+                Mockito.anyBoolean())).thenReturn(result);\r
+        Response response = documentApi.processPut(content, request, headers, httpResponse, "index","id-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FOUND.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testProcessDelete_RequestThrowsException() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenThrow(IllegalArgumentException.class);\r
+        Response response = documentApi.processDelete(content, request, headers, httpResponse, "index","id-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FORBIDDEN.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testProcessDelete_RequestInvalid() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenReturn(false);\r
+        Response response = documentApi.processDelete(content, request, headers, httpResponse, "index","id-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FORBIDDEN.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testProcessDelete_ResultInvalid() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        DocumentOperationResult result = new DocumentOperationResult();\r
+        result.setResultCode(302);\r
+        result.setError(new ErrorResult("type-1", "reason-1"));\r
+        result.setFailureCause("test-failure");\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenReturn(true);\r
+        Mockito.when(documentStore.deleteDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class)))\r
+                .thenReturn(result);\r
+        Response response = documentApi.processDelete(content, request, headers, httpResponse, "index","id-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FOUND.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testProcessGet_RequestThrowsException() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenThrow(IllegalArgumentException.class);\r
+        Response response = documentApi.processGet(content, request, headers, httpResponse, "index","id-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FORBIDDEN.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testProcessGet_RequestInvalid() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenReturn(false);\r
+        Response response = documentApi.processGet(content, request, headers, httpResponse, "index","id-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FORBIDDEN.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testProcessGet_ResultInvalid() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        DocumentOperationResult result = new DocumentOperationResult();\r
+        result.setResultCode(302);\r
+        result.setError(new ErrorResult("type-1", "reason-1"));\r
+        result.setFailureCause("test-failure");\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenReturn(true);\r
+        Mockito.when(documentStore.getDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class)))\r
+                .thenReturn(result);\r
+        Response response = documentApi.processGet(content, request, headers, httpResponse, "index","id-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FOUND.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testQueryWithGetWithPayload_NullContent(){\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = null;\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Response response = documentApi.queryWithGetWithPayload(content, request, headers, "index-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.BAD_REQUEST.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testQueryWithGetWithPayload_RequestThrowsException() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenThrow(IllegalArgumentException.class);\r
+        Response response = documentApi.queryWithGetWithPayload(content, request, headers, "index-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FORBIDDEN.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testQueryWithGetWithPayload_RequestInvalid() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String content = "content";\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenReturn(false);\r
+        Response response = documentApi.queryWithGetWithPayload(content, request, headers, "index-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FORBIDDEN.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testCreateProcessIndex_IndexApi_RequestInvalid() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenReturn(false);\r
+        Response response = indexApi.processCreateIndex("document-1", request, headers, "index-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FORBIDDEN.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testCreateProcessIndex_IndexApi_RequestThrowsException() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenThrow(IllegalArgumentException.class);\r
+        Response response = indexApi.processCreateIndex("document-1", request, headers, "index-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FORBIDDEN.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testCreateProcessIndex_IndexApi_NullDocument() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        String documentSchema= null;\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenReturn(true);\r
+        Response response = indexApi.processCreateIndex(documentSchema, request, headers, "index-1",\r
+                documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testProcessDelete_IndexApi_RequestInvalid() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenReturn(false);\r
+        Response response = indexApi.processDelete("document-1", request, headers, documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FORBIDDEN.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testProcessDelete_IndexApi_RequestThrowsException() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenThrow(IllegalArgumentException.class);\r
+        Response response = indexApi.processDelete("document-1", request, headers, documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.FORBIDDEN.getStatusCode() == response.getStatus());\r
+    }\r
+\r
+    @Test\r
+    public void testProcessDelete_IndexApi_DeleteIndexException() throws Exception {\r
+        String transactionId = "transactionId-1";\r
+        String remoteAddr = "http://127.0.0.1";\r
+        Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);\r
+        Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId);\r
+        Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr);\r
+        Mockito.when(request.getMethod()).thenReturn("testMethod");\r
+        Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1"));\r
+        Mockito.when(request.getRemoteHost()).thenReturn("localhost");\r
+        Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
+                Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
+                .thenReturn(true);\r
+        Mockito.when(documentStore.deleteIndex(Mockito.anyString())).thenThrow(DocumentStoreOperationException.class);\r
+        Response response = indexApi.processDelete("document-1", request, headers, documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() == response.getStatus());\r
+    }\r
+}\r