Search service configurable index settings
[aai/search-data-service.git] / src / test / java / org / onap / aai / sa / rest / DocumentTest.java
index 83ba5a7..e780e3b 100644 (file)
 package org.onap.aai.sa.rest;\r
 \r
 import com.fasterxml.jackson.core.JsonProcessingException;\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 org.junit.Assert;\r
 import org.junit.Before;\r
 import org.junit.Ignore;\r
@@ -29,21 +33,21 @@ import org.mockito.InjectMocks;
 import org.mockito.Mock;\r
 import org.mockito.Mockito;\r
 import org.mockito.MockitoAnnotations;\r
+import org.mockito.invocation.InvocationOnMock;\r
+import org.mockito.stubbing.Answer;\r
+import org.onap.aai.sa.searchdbabstraction.elasticsearch.config.ElasticSearchConfig;\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.dao.ElasticSearchHttpController;\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
+import org.springframework.http.HttpHeaders;\r
 import org.springframework.http.HttpStatus;\r
 import org.springframework.http.ResponseEntity;\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 org.springframework.http.HttpHeaders;\r
+import java.util.Properties;\r
 \r
 \r
 public class DocumentTest {\r
@@ -71,8 +75,11 @@ public class DocumentTest {
 \r
     DocumentApi documentApi;\r
 \r
+    @Mock\r
+    ElasticSearchHttpController httpController;\r
+\r
     @Before\r
-    public void setUp(){\r
+    public void setUp() {\r
         MockitoAnnotations.initMocks(this);\r
         documentApi = new DocumentApi(searchServiceApi);\r
     }\r
@@ -81,14 +88,14 @@ public class DocumentTest {
     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.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
+    public void testProcessPost_NullContent() {\r
         String transactionId = "transactionId-1";\r
         String remoteAddr = "http://127.0.0.1";\r
         String content = null;\r
@@ -98,12 +105,13 @@ public class DocumentTest {
         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
-        ResponseEntity<String> response = documentApi.processPost(content, request, headers, httpResponse, "index",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processPost(content, request, headers, httpResponse, "index", documentStore);\r
         Assert.assertNotNull(response);\r
-        Assert.assertTrue( HttpStatus.BAD_REQUEST.value () == response.getStatusCodeValue ());\r
+        Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue());\r
     }\r
 \r
+    @SuppressWarnings("unchecked")\r
     @Test\r
     public void testProcessPost_NotNullContent() throws Exception {\r
         String transactionId = "transactionId-1";\r
@@ -118,12 +126,13 @@ public class DocumentTest {
         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
-        ResponseEntity response = documentApi.processPost(content, request, headers, httpResponse, "index",\r
-                documentStore);\r
+        ResponseEntity<?> response =\r
+                documentApi.processPost(content, request, headers, httpResponse, "index", documentStore);\r
         Assert.assertNotNull(response);\r
-        Assert.assertTrue(HttpStatus.FORBIDDEN.value () == response.getStatusCodeValue ());\r
+        Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
     }\r
-//\r
+\r
+    //\r
     @Test\r
     public void testProcessPost_ValidRequest() throws Exception {\r
         String transactionId = "transactionId-1";\r
@@ -145,12 +154,13 @@ public class DocumentTest {
         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
-        ResponseEntity<String> response = documentApi.processPost(content, request, headers, httpResponse, "index",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processPost(content, request, headers, httpResponse, "index", documentStore);\r
         Assert.assertNotNull(response);\r
-        Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value () == response.getStatusCodeValue ());\r
+        Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue());\r
     }\r
-//\r
+\r
+    //\r
     @Test\r
     public void testProcessSearchWithGet_Created() throws Exception {\r
         String transactionId = "transactionId-1";\r
@@ -171,13 +181,14 @@ public class DocumentTest {
                 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
-        ResponseEntity<String>response = documentApi.processSearchWithGet(content, request, headers, "index-1",\r
-                "query-text", documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.CREATED.value() == response.getStatusCodeValue());\r
 \r
     }\r
-//\r
+\r
+    @SuppressWarnings("unchecked")\r
     @Test\r
     public void testProcessSearchWithGet_ValidateThrowsException() throws Exception {\r
         String transactionId = "transactionId-1";\r
@@ -198,13 +209,13 @@ public class DocumentTest {
                 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
-        ResponseEntity<String>response = documentApi.processSearchWithGet(content, request, headers, "index-1",\r
-                "query-text", documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
 \r
     }\r
-//\r
+\r
     @Test\r
     public void testProcessSearchWithGet_ValidateIsFalse() throws Exception {\r
         String transactionId = "transactionId-1";\r
@@ -225,8 +236,8 @@ public class DocumentTest {
                 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
-        ResponseEntity<String>response = documentApi.processSearchWithGet(content, request, headers, "index-1",\r
-                "query-text", documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
 \r
@@ -252,15 +263,15 @@ public class DocumentTest {
                 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
-        ResponseEntity<String>response = documentApi.processSearchWithGet(content, request, headers, "index-1",\r
-                "query-text", documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processSearchWithGet(content, request, headers, "index-1", "query-text", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());\r
 \r
     }\r
 \r
     @Test\r
-    public void testProcessPut_NullContent(){\r
+    public void testProcessPut_NullContent() {\r
         String transactionId = "transactionId-1";\r
         String remoteAddr = "http://127.0.0.1";\r
         String content = null;\r
@@ -270,12 +281,13 @@ public class DocumentTest {
         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
-        ResponseEntity<String>response = documentApi.processPut(content, request, headers, httpResponse, "index","id-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue());\r
     }\r
 \r
+    @SuppressWarnings("unchecked")\r
     @Test\r
     public void testProcessPut_RequestThrowsException() throws Exception {\r
         String transactionId = "transactionId-1";\r
@@ -290,8 +302,8 @@ public class DocumentTest {
         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
-        ResponseEntity<String>response = documentApi.processPut(content, request, headers, httpResponse, "index","id-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
     }\r
@@ -310,13 +322,12 @@ public class DocumentTest {
         Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
                 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
                 .thenReturn(false);\r
-        ResponseEntity<String>response = documentApi.processPut(content, request, headers, httpResponse, "index","id-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
     }\r
 \r
-    @Ignore\r
     @Test\r
     public void testProcessPut_ResultInvalid() throws Exception {\r
         String transactionId = "transactionId-1";\r
@@ -335,14 +346,15 @@ public class DocumentTest {
         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.when(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class),\r
                 Mockito.anyBoolean())).thenReturn(result);\r
-        ResponseEntity<String>response = documentApi.processPut(content, request, headers, httpResponse, "index","id-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());\r
     }\r
 \r
+    @SuppressWarnings("unchecked")\r
     @Test\r
     public void testProcessDelete_RequestThrowsException() throws Exception {\r
         String transactionId = "transactionId-1";\r
@@ -357,8 +369,8 @@ public class DocumentTest {
         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
-        ResponseEntity<String>response = documentApi.processDelete(content, request, headers, httpResponse, "index","id-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
     }\r
@@ -377,8 +389,8 @@ public class DocumentTest {
         Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
                 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
                 .thenReturn(false);\r
-        ResponseEntity<String>response = documentApi.processDelete(content, request, headers, httpResponse, "index","id-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
     }\r
@@ -404,12 +416,13 @@ public class DocumentTest {
                 .thenReturn(true);\r
         Mockito.when(documentStore.deleteDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class)))\r
                 .thenReturn(result);\r
-        ResponseEntity<String>response = documentApi.processDelete(content, request, headers, httpResponse, "index","id-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processDelete(content, request, headers, httpResponse, "index", "id-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());\r
     }\r
 \r
+    @SuppressWarnings("unchecked")\r
     @Test\r
     public void testProcessGet_RequestThrowsException() throws Exception {\r
         String transactionId = "transactionId-1";\r
@@ -424,8 +437,8 @@ public class DocumentTest {
         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
-        ResponseEntity<String>response = documentApi.processGet(content, request, headers, httpResponse, "index","id-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
     }\r
@@ -444,8 +457,8 @@ public class DocumentTest {
         Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
                 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
                 .thenReturn(false);\r
-        ResponseEntity<String>response = documentApi.processGet(content, request, headers, httpResponse, "index","id-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
     }\r
@@ -470,14 +483,14 @@ public class DocumentTest {
                 .thenReturn(true);\r
         Mockito.when(documentStore.getDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class)))\r
                 .thenReturn(result);\r
-        ResponseEntity<String>response = documentApi.processGet(content, request, headers, httpResponse, "index","id-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.processGet(content, request, headers, httpResponse, "index", "id-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());\r
     }\r
 \r
     @Test\r
-    public void testQueryWithGetWithPayload_NullContent(){\r
+    public void testQueryWithGetWithPayload_NullContent() {\r
         String transactionId = "transactionId-1";\r
         String remoteAddr = "http://127.0.0.1";\r
         String content = null;\r
@@ -487,12 +500,13 @@ public class DocumentTest {
         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
-        ResponseEntity<String>response = documentApi.queryWithGetWithPayload(content, request, headers, "index-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.BAD_REQUEST.value() == response.getStatusCodeValue());\r
     }\r
 \r
+    @SuppressWarnings("unchecked")\r
     @Test\r
     public void testQueryWithGetWithPayload_RequestThrowsException() throws Exception {\r
         String transactionId = "transactionId-1";\r
@@ -507,8 +521,8 @@ public class DocumentTest {
         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
-        ResponseEntity<String>response = documentApi.queryWithGetWithPayload(content, request, headers, "index-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
     }\r
@@ -527,8 +541,8 @@ public class DocumentTest {
         Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
                 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
                 .thenReturn(false);\r
-        ResponseEntity<String>response = documentApi.queryWithGetWithPayload(content, request, headers, "index-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                documentApi.queryWithGetWithPayload(content, request, headers, "index-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
     }\r
@@ -546,12 +560,13 @@ public class DocumentTest {
         Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
                 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
                 .thenReturn(false);\r
-        ResponseEntity<String>response = indexApi.processCreateIndex("document-1", request, headers, "index-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                indexApi.processCreateIndex("document-1", request, headers, "index-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
     }\r
 \r
+    @SuppressWarnings("unchecked")\r
     @Test\r
     public void testCreateProcessIndex_IndexApi_RequestThrowsException() throws Exception {\r
         String transactionId = "transactionId-1";\r
@@ -565,8 +580,8 @@ public class DocumentTest {
         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
-        ResponseEntity<String>response = indexApi.processCreateIndex("document-1", request, headers, "index-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                indexApi.processCreateIndex("document-1", request, headers, "index-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
     }\r
@@ -575,7 +590,7 @@ public class DocumentTest {
     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
+        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
@@ -585,8 +600,8 @@ public class DocumentTest {
         Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
                 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
                 .thenReturn(true);\r
-        ResponseEntity<String>response = indexApi.processCreateIndex(documentSchema, request, headers, "index-1",\r
-                documentStore);\r
+        ResponseEntity<String> response =\r
+                indexApi.processCreateIndex(documentSchema, request, headers, "index-1", documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue());\r
     }\r
@@ -604,11 +619,12 @@ public class DocumentTest {
         Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class),\r
                 Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString()))\r
                 .thenReturn(false);\r
-        ResponseEntity<String>response = indexApi.processDelete("document-1", request, headers, documentStore);\r
+        ResponseEntity<String> response = indexApi.processDelete("document-1", request, headers, documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
     }\r
 \r
+    @SuppressWarnings("unchecked")\r
     @Test\r
     public void testProcessDelete_IndexApi_RequestThrowsException() throws Exception {\r
         String transactionId = "transactionId-1";\r
@@ -622,11 +638,12 @@ public class DocumentTest {
         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
-        ResponseEntity<String>response = indexApi.processDelete("document-1", request, headers, documentStore);\r
+        ResponseEntity<String> response = indexApi.processDelete("document-1", request, headers, documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
     }\r
 \r
+    @SuppressWarnings("unchecked")\r
     @Test\r
     public void testProcessDelete_IndexApi_DeleteIndexException() throws Exception {\r
         String transactionId = "transactionId-1";\r
@@ -641,8 +658,70 @@ public class DocumentTest {
                 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
-        ResponseEntity<String>response = indexApi.processDelete("document-1", request, headers, documentStore);\r
+        ResponseEntity<String> response = indexApi.processDelete("document-1", request, headers, documentStore);\r
         Assert.assertNotNull(response);\r
         Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.value() == response.getStatusCodeValue());\r
     }\r
-}\r
+\r
+    @Test\r
+    public void testUserAuthorization() 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
+                .thenCallRealMethod();\r
+\r
+        Mockito.doAnswer(new Answer<ElasticSearchConfig>() {\r
+            public ElasticSearchConfig answer(InvocationOnMock invocation) {\r
+                Properties properties = new Properties();\r
+                return new ElasticSearchConfig(properties);\r
+            }\r
+        }).when(httpController).getElasticSearchConfig();\r
+\r
+        searchServiceApi.documentStore = httpController;\r
+\r
+        ResponseEntity<String> response =\r
+                documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
+\r
+        Mockito.doAnswer(new Answer<ElasticSearchConfig>() {\r
+            public ElasticSearchConfig answer(InvocationOnMock invocation) {\r
+                Properties properties = new Properties();\r
+                properties.put(ElasticSearchConfig.ES_AUTH_ENABLED, "true");\r
+                return new ElasticSearchConfig(properties);\r
+            }\r
+        }).when(httpController).getElasticSearchConfig();\r
+\r
+\r
+        response = documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue());\r
+\r
+        Mockito.doAnswer(new Answer<ElasticSearchConfig>() {\r
+            public ElasticSearchConfig answer(InvocationOnMock invocation) {\r
+                Properties properties = new Properties();\r
+                properties.put(ElasticSearchConfig.ES_AUTH_ENABLED, "false");\r
+                return new ElasticSearchConfig(properties);\r
+            }\r
+        }).when(httpController).getElasticSearchConfig();\r
+\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(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class),\r
+                Mockito.anyBoolean())).thenReturn(result);\r
+        response = documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore);\r
+        Assert.assertNotNull(response);\r
+        Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue());\r
+\r
+    }\r
+}
\ No newline at end of file