+\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