X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fsa%2Frest%2FDocumentTest.java;h=e780e3b06d3a46099de996eea94d1e40afe621b6;hb=5ea47abeeb1713b56006fd69b1564cbd4c4220c7;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..e780e3b 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; @@ -29,21 +33,21 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.onap.aai.sa.searchdbabstraction.elasticsearch.config.ElasticSearchConfig; import org.onap.aai.sa.searchdbabstraction.elasticsearch.dao.DocumentStoreDataEntity; import org.onap.aai.sa.searchdbabstraction.elasticsearch.dao.DocumentStoreInterface; +import org.onap.aai.sa.searchdbabstraction.elasticsearch.dao.ElasticSearchHttpController; import org.onap.aai.sa.searchdbabstraction.elasticsearch.exception.DocumentStoreOperationException; 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; +import java.util.Properties; public class DocumentTest { @@ -71,8 +75,11 @@ public class DocumentTest { DocumentApi documentApi; + @Mock + ElasticSearchHttpController httpController; + @Before - public void setUp(){ + public void setUp() { MockitoAnnotations.initMocks(this); documentApi = new DocumentApi(searchServiceApi); } @@ -81,14 +88,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,12 +105,13 @@ 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()); } + @SuppressWarnings("unchecked") @Test public void testProcessPost_NotNullContent() throws Exception { String transactionId = "transactionId-1"; @@ -118,12 +126,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 +154,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 +181,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()); } -// + + @SuppressWarnings("unchecked") @Test public void testProcessSearchWithGet_ValidateThrowsException() throws Exception { String transactionId = "transactionId-1"; @@ -198,13 +209,13 @@ 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 +236,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 +263,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,12 +281,13 @@ 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()); } + @SuppressWarnings("unchecked") @Test public void testProcessPut_RequestThrowsException() throws Exception { String transactionId = "transactionId-1"; @@ -290,8 +302,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,13 +322,12 @@ 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()); } - @Ignore @Test public void testProcessPut_ResultInvalid() throws Exception { String transactionId = "transactionId-1"; @@ -335,14 +346,15 @@ public class DocumentTest { Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) .thenReturn(true); - Mockito.when(documentStore.updateDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class), + Mockito.when(documentStore.createDocument(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()); } + @SuppressWarnings("unchecked") @Test public void testProcessDelete_RequestThrowsException() throws Exception { String transactionId = "transactionId-1"; @@ -357,8 +369,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 +389,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,12 +416,13 @@ 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()); } + @SuppressWarnings("unchecked") @Test public void testProcessGet_RequestThrowsException() throws Exception { String transactionId = "transactionId-1"; @@ -424,8 +437,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 +457,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 +483,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,12 +500,13 @@ 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()); } + @SuppressWarnings("unchecked") @Test public void testQueryWithGetWithPayload_RequestThrowsException() throws Exception { String transactionId = "transactionId-1"; @@ -507,8 +521,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 +541,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,12 +560,13 @@ 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()); } + @SuppressWarnings("unchecked") @Test public void testCreateProcessIndex_IndexApi_RequestThrowsException() throws Exception { String transactionId = "transactionId-1"; @@ -565,8 +580,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 +590,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 +600,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,11 +619,12 @@ 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()); } + @SuppressWarnings("unchecked") @Test public void testProcessDelete_IndexApi_RequestThrowsException() throws Exception { String transactionId = "transactionId-1"; @@ -622,11 +638,12 @@ 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()); } + @SuppressWarnings("unchecked") @Test public void testProcessDelete_IndexApi_DeleteIndexException() throws Exception { String transactionId = "transactionId-1"; @@ -641,8 +658,70 @@ 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()); } -} + + @Test + public void testUserAuthorization() throws Exception { + String transactionId = "transactionId-1"; + String remoteAddr = "http://127.0.0.1"; + String content = "content"; + // Mockito.when(headers.getRequestHeaders()).thenReturn(multivaluedMap);; + Mockito.when(multivaluedMap.getFirst(Mockito.anyString())).thenReturn(transactionId); + Mockito.when(request.getRemoteAddr()).thenReturn(remoteAddr); + Mockito.when(request.getMethod()).thenReturn("testMethod"); + Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("http://127.0.0.1")); + Mockito.when(request.getRemoteHost()).thenReturn("localhost"); + Mockito.when(searchServiceApi.validateRequest(Mockito.any(HttpHeaders.class), + Mockito.any(HttpServletRequest.class), Mockito.any(ApiUtils.Action.class), Mockito.anyString())) + .thenCallRealMethod(); + + Mockito.doAnswer(new Answer() { + public ElasticSearchConfig answer(InvocationOnMock invocation) { + Properties properties = new Properties(); + return new ElasticSearchConfig(properties); + } + }).when(httpController).getElasticSearchConfig(); + + searchServiceApi.documentStore = httpController; + + ResponseEntity response = + documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + + Mockito.doAnswer(new Answer() { + public ElasticSearchConfig answer(InvocationOnMock invocation) { + Properties properties = new Properties(); + properties.put(ElasticSearchConfig.ES_AUTH_ENABLED, "true"); + return new ElasticSearchConfig(properties); + } + }).when(httpController).getElasticSearchConfig(); + + + response = documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FORBIDDEN.value() == response.getStatusCodeValue()); + + Mockito.doAnswer(new Answer() { + public ElasticSearchConfig answer(InvocationOnMock invocation) { + Properties properties = new Properties(); + properties.put(ElasticSearchConfig.ES_AUTH_ENABLED, "false"); + return new ElasticSearchConfig(properties); + } + }).when(httpController).getElasticSearchConfig(); + + DocumentOperationResult result = new DocumentOperationResult(); + result.setResultCode(302); + result.setError(new ErrorResult("type-1", "reason-1")); + result.setFailureCause("test-failure"); + Mockito.when(documentStore.createDocument(Mockito.anyString(), Mockito.any(DocumentStoreDataEntity.class), + Mockito.anyBoolean())).thenReturn(result); + response = documentApi.processPut(content, request, headers, httpResponse, "index", "id-1", documentStore); + Assert.assertNotNull(response); + Assert.assertTrue(HttpStatus.FOUND.value() == response.getStatusCodeValue()); + + } +} \ No newline at end of file