diff --git a/indexer-service-azure/pom.xml b/indexer-service-azure/pom.xml index fe573509aef660f67cad2cade0ce437c4697ac5b..8ce9dc791d6af2cff89e0576f2824f05ea336d0f 100644 --- a/indexer-service-azure/pom.xml +++ b/indexer-service-azure/pom.xml @@ -12,10 +12,18 @@ <artifactId>indexer-service-azure</artifactId> <dependencies> + + <dependency> + <groupId>com.slb</groupId> + <artifactId>indexer-service-root</artifactId> + <version>0.0.1-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + <dependency> <groupId>com.slb.core</groupId> - <artifactId>indexer-search-core-service-azure</artifactId> - <version>1.0-SNAPSHOT</version> + <artifactId>indexer-search-core-azure</artifactId> + <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> diff --git a/indexer-service-azure/src/main/java/org/opendes/util/indexer/RequestInfoImpl.java b/indexer-service-azure/src/main/java/org/opendes/util/indexer/RequestInfoImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..014db97d4f635e0c3435a50ca0e62aacb1138921 --- /dev/null +++ b/indexer-service-azure/src/main/java/org/opendes/util/indexer/RequestInfoImpl.java @@ -0,0 +1,78 @@ +package org.opendes.util.indexer; + +import com.google.common.base.Strings; +import com.slb.core.model.AppEngineHeaders; +import com.slb.core.model.DeploymentEnvironment; +import com.slb.core.util.HeadersInfo; +import org.apache.http.HttpStatus; +import org.opendes.client.api.DpsHeaders; +import org.opendes.indexer.util.IRequestInfo; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Map; + +import static org.opendes.client.api.DpsHeaders.AUTHORIZATION; + +public class RequestInfoImpl implements IRequestInfo { + + @Autowired + private HeadersInfo headersInfo; + @Autowired + private ServiceAccountJwtClientImpl serviceAccountJwtClient; + + private static final String expectedCronHeaderValue = "true"; + + @Override + public DpsHeaders getHeaders() { + + return this.headersInfo.getHeaders(); + } + + @Override + public String getPartitionId() { + return this.headersInfo.getPartitionId(); + } + + @Override + public Map<String, String> getHeadersMap() { + return this.headersInfo.getHeadersMap(); + } + + @Override + public Map<String, String> getHeadersMapWithDwdAuthZ() { + return getHeadersWithDwdAuthZ().getHeaders(); + } + + @Override + public DpsHeaders getHeadersWithDwdAuthZ() { + DpsHeaders output = this.headersInfo.getHeaders(); + output.put(AUTHORIZATION, this.checkOrGetAuthorizationHeader()); + return output; + } + + @Override + public boolean isCronRequest() { + String appEngineCronHeader = this.headersInfo.getHeadersMap().getOrDefault(AppEngineHeaders.CRON_SERVICE, null); + return expectedCronHeaderValue.equalsIgnoreCase(appEngineCronHeader); + } + + @Override + public boolean isTaskQueueRequest() { + if (!this.headersInfo.getHeadersMap().containsKey(AppEngineHeaders.TASK_QUEUE_NAME)) return false; + + String queueId = this.headersInfo.getHeadersMap().get(AppEngineHeaders.TASK_QUEUE_NAME); + return queueId.endsWith(Constants.INDEXER_QUEUE_IDENTIFIER); + } + + private String checkOrGetAuthorizationHeader() { + if (Config.getDeploymentEnvironment() == DeploymentEnvironment.LOCAL) { + String authHeader = this.headersInfo.getHeaders().getAuthorization(); + if (Strings.isNullOrEmpty(authHeader)) { + throw new AppException(HttpStatus.SC_UNAUTHORIZED, "Invalid authorization header", "Authorization token cannot be empty"); + } + return authHeader; + } else { + return "Bearer " + this.serviceAccountJwtClient.getIdToken(); + } + } +} diff --git a/indexer-service-gcp/pom.xml b/indexer-service-gcp/pom.xml index 33c637e3822f2fcae2c22407403797f2890cc995..33929686a30a25245e8fed0c42de721b5a11f686 100644 --- a/indexer-service-gcp/pom.xml +++ b/indexer-service-gcp/pom.xml @@ -12,7 +12,7 @@ <groupId>com.slb</groupId> <artifactId>indexer-service-gcp</artifactId> - <version>0.0.1-SNAPSHOT</version> + <version>1.1-SNAPSHOT</version> <name>indexer-service-gcp</name> <dependencies> diff --git a/indexer-service-gcp/src/main/java/org/opendes/indexer/publish/PublisherImpl.java b/indexer-service-gcp/src/main/java/org/opendes/indexer/publish/PublisherImpl.java index 44ddba28ac3d2a55d4264ed788a3c48836b9b307..bd0084ed6d3da554e361937c0af258c2c74a3857 100644 --- a/indexer-service-gcp/src/main/java/org/opendes/indexer/publish/PublisherImpl.java +++ b/indexer-service-gcp/src/main/java/org/opendes/indexer/publish/PublisherImpl.java @@ -51,15 +51,6 @@ public class PublisherImpl implements IPublisher { private static final String TOPIC_ID = "indexing-progress"; - private static final RetrySettings RETRY_SETTINGS = RetrySettings.newBuilder() - .setTotalTimeout(Duration.ofSeconds(30)) - .setInitialRetryDelay(Duration.ofSeconds(2)) - .setRetryDelayMultiplier(2) - .setMaxRetryDelay(Duration.ofSeconds(5)) - .setInitialRpcTimeout(Duration.ofSeconds(10)) - .setRpcTimeoutMultiplier(2) - .setMaxRpcTimeout(Duration.ofSeconds(10)) - .build(); @Autowired private ITenantFactory tenantStorageFactory; @@ -68,13 +59,13 @@ public class PublisherImpl implements IPublisher { private PubSubExtensions pubSubExtensions; @Override - public PubsubMessage publishStatusChangedTagsToTopic(Map<String, String> headers, JobStatus indexerBatchStatus) throws Exception { + public PubsubMessage publishStatusChangedTagsToTopic(DpsHeaders headers, JobStatus indexerBatchStatus) throws Exception { if (Config.getDeploymentEnvironment() == DeploymentEnvironment.LOCAL) return null; - String tenant = headers.get(DpsHeaders.DATA_PARITION_ID); + String tenant = headers.getPartitionId(); if(Strings.isNullOrEmpty(tenant)) - tenant = headers.get(DpsHeaders.ACCOUNT_ID); + tenant = headers.getAccountId(); Publisher publisher = this.getPublisher(tenant); if (publisher == null) { @@ -86,7 +77,18 @@ public class PublisherImpl implements IPublisher { return pubsubMessage; } - private PubsubMessage getPubsubMessage(Map<String, String> headers, JobStatus indexerBatchStatus) { + private static final RetrySettings RETRY_SETTINGS = RetrySettings.newBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .setInitialRetryDelay(Duration.ofSeconds(2)) + .setRetryDelayMultiplier(2) + .setMaxRetryDelay(Duration.ofSeconds(5)) + .setInitialRpcTimeout(Duration.ofSeconds(10)) + .setRpcTimeoutMultiplier(2) + .setMaxRpcTimeout(Duration.ofSeconds(10)) + .build(); + + + private PubsubMessage getPubsubMessage(DpsHeaders headers, JobStatus indexerBatchStatus) { Gson gson = new GsonBuilder().create(); Type listType = new TypeToken<List<RecordStatus>>() {}.getType(); @@ -94,16 +96,16 @@ public class PublisherImpl implements IPublisher { ByteString statusChangedTagsData = ByteString.copyFromUtf8(statusChangedTagsJson.toString()); PubsubMessage.Builder builder = PubsubMessage.newBuilder(); - String tenant = headers.get(DpsHeaders.DATA_PARITION_ID); + String tenant = headers.getPartitionId(); //This code it to provide backward compatibility to slb-account-id if(!Strings.isNullOrEmpty(tenant)) { - builder.putAttributes(DpsHeaders.DATA_PARITION_ID, headers.get(DpsHeaders.DATA_PARITION_ID)); + builder.putAttributes(DpsHeaders.DATA_PARITION_ID, headers.getPartitionId()); } else { - builder.putAttributes(DpsHeaders.ACCOUNT_ID, headers.get(DpsHeaders.ACCOUNT_ID)); + builder.putAttributes(DpsHeaders.ACCOUNT_ID, headers.getAccountId()); } - builder.putAttributes(DpsHeaders.CORRELATION_ID, headers.get(DpsHeaders.CORRELATION_ID)); - builder.putAttributes(AppEngineHeaders.CLOUD_TRACE_CONTEXT, headers.get(AppEngineHeaders.CLOUD_TRACE_CONTEXT)); + builder.putAttributes(DpsHeaders.CORRELATION_ID, headers.getCorrelationId()); + builder.putAttributes(AppEngineHeaders.CLOUD_TRACE_CONTEXT, headers.getHeaders().get(AppEngineHeaders.CLOUD_TRACE_CONTEXT)); builder.setData(statusChangedTagsData); return builder.build(); diff --git a/indexer-service-gcp/src/main/java/org/opendes/indexer/util/RequestInfoImpl.java b/indexer-service-gcp/src/main/java/org/opendes/indexer/util/RequestInfoImpl.java index 849e7b45f2ee5ac34ab199be8433cbfdda727bd9..8d3139ed6cb27fcc56c8d0116852659b1cda2beb 100644 --- a/indexer-service-gcp/src/main/java/org/opendes/indexer/util/RequestInfoImpl.java +++ b/indexer-service-gcp/src/main/java/org/opendes/indexer/util/RequestInfoImpl.java @@ -1,6 +1,5 @@ package org.opendes.indexer.util; - import com.google.common.base.Strings; import com.slb.core.model.AppEngineHeaders; import com.slb.core.model.DeploymentEnvironment; @@ -11,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired; import java.util.Map; +import static org.opendes.client.api.DpsHeaders.*; + public class RequestInfoImpl implements IRequestInfo { @Autowired @@ -38,9 +39,14 @@ public class RequestInfoImpl implements IRequestInfo { @Override public Map<String, String> getHeadersMapWithDwdAuthZ() { + return getHeadersWithDwdAuthZ().getHeaders(); + } + + @Override + public DpsHeaders getHeadersWithDwdAuthZ() { DpsHeaders output = this.headersInfo.getHeaders(); - output.put(DpsHeaders.AUTHORIZATION, this.checkOrGetAuthorizationHeader()); - return output.getHeaders(); + output.put(AUTHORIZATION, this.checkOrGetAuthorizationHeader()); + return output; } @Override diff --git a/indexer-service-root/pom.xml b/indexer-service-root/pom.xml index d7df6ea6eb800d0bb419ba6c85708aecefdb43b2..6bbc88c52fd3c045d1ca0408efe08da14b4f8a25 100644 --- a/indexer-service-root/pom.xml +++ b/indexer-service-root/pom.xml @@ -34,7 +34,6 @@ <artifactId>indexer-search-service-core-root</artifactId> <version>1.0-SNAPSHOT</version> </dependency> - <!-- spring boot dependencies --> <dependency> <groupId>org.springframework.boot</groupId> @@ -85,11 +84,7 @@ <version>6.6.2</version> </dependency> - <dependency> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - <optional>true</optional> - </dependency> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> @@ -175,6 +170,7 @@ <scope>test</scope> </dependency> + <!-- Test Dependencies --> <dependency> <groupId>junit</groupId> @@ -222,6 +218,24 @@ <version>1.2.0</version> <scope>test</scope> </dependency> + <dependency> + <groupId>com.google.api.grpc</groupId> + <artifactId>proto-google-cloud-pubsub-v1</artifactId> + <version>1.60.0</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>com.google.api.grpc</groupId> + <artifactId>proto-google-cloud-pubsub-v1</artifactId> + <version>1.60.0</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>com.google.api.grpc</groupId> + <artifactId>proto-google-cloud-pubsub-v1</artifactId> + <version>1.60.0</version> + <scope>compile</scope> + </dependency> </dependencies> <dependencyManagement> @@ -237,18 +251,23 @@ </dependencyManagement> <build> - - <resources> - <resource> - <directory>src/main/resources</directory> - <filtering>true</filtering> - </resource> - </resources> - <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + <configuration> + <classifier>spring-boot</classifier> + <mainClass> + org.opendes.indexer.IndexerApplication + </mainClass> + </configuration> + </execution> + </executions> </plugin> </plugins> </build> diff --git a/indexer-service-root/src/main/java/org/opendes/indexer/middleware/IndexerFilter.java b/indexer-service-root/src/main/java/org/opendes/indexer/middleware/IndexerFilter.java index 949f15d61f1ce418c88c760cb0f6763b816fe4f7..1d229c4f05c7a551dfad4151c55d69cb15590693 100644 --- a/indexer-service-root/src/main/java/org/opendes/indexer/middleware/IndexerFilter.java +++ b/indexer-service-root/src/main/java/org/opendes/indexer/middleware/IndexerFilter.java @@ -36,7 +36,6 @@ import javax.servlet.Filter; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.container.ResourceInfo; import javax.ws.rs.core.Context; -import javax.ws.rs.core.UriInfo; import java.io.IOException; import java.lang.reflect.Method; diff --git a/indexer-service-root/src/main/java/org/opendes/indexer/publish/IPublisher.java b/indexer-service-root/src/main/java/org/opendes/indexer/publish/IPublisher.java index 367e8911a79fb4ede11b7c7860f22e5705317398..6c592cfba6fd838e7d262ffc6e9790bcf9508edb 100644 --- a/indexer-service-root/src/main/java/org/opendes/indexer/publish/IPublisher.java +++ b/indexer-service-root/src/main/java/org/opendes/indexer/publish/IPublisher.java @@ -1,11 +1,10 @@ package org.opendes.indexer.publish; import com.google.pubsub.v1.PubsubMessage; +import org.opendes.client.api.DpsHeaders; import org.opendes.indexer.util.JobStatus; -import java.util.Map; - public interface IPublisher { - public PubsubMessage publishStatusChangedTagsToTopic(Map<String, String> headers, JobStatus indexerBatchStatus) throws Exception; + public PubsubMessage publishStatusChangedTagsToTopic(DpsHeaders headers, JobStatus indexerBatchStatus) throws Exception; } diff --git a/indexer-service-root/src/main/java/org/opendes/indexer/service/IndexerServiceImpl.java b/indexer-service-root/src/main/java/org/opendes/indexer/service/IndexerServiceImpl.java index 1f458fb871f54e5d82421c50ae0c15f83429fdc3..dfd545315d9dd5d758442191ff9c6899501de867 100644 --- a/indexer-service-root/src/main/java/org/opendes/indexer/service/IndexerServiceImpl.java +++ b/indexer-service-root/src/main/java/org/opendes/indexer/service/IndexerServiceImpl.java @@ -38,6 +38,7 @@ import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.RestStatus; +import org.opendes.client.api.DpsHeaders; import org.opendes.indexer.logging.AuditLogger; import org.opendes.indexer.model.*; import org.opendes.indexer.publish.IPublisher; @@ -96,7 +97,7 @@ public class IndexerServiceImpl implements IndexerService { @Autowired private JobStatus jobStatus; - private Map<String, String> headers; + private DpsHeaders headers; @Override public JobStatus processRecordChangedMessages(RecordChangedMessages message, List<RecordInfo> recordInfos) throws Exception { @@ -108,7 +109,7 @@ public class IndexerServiceImpl implements IndexerService { List<String> retryRecordIds = new LinkedList<>(); // get auth header - this.headers = this.requestInfo.getHeadersMapWithDwdAuthZ(); + this.headers = this.requestInfo.getHeaders(); // initialize status for all messages. this.jobStatus.initialize(recordInfos); diff --git a/indexer-service-root/src/main/java/org/opendes/indexer/service/ReindexServiceImpl.java b/indexer-service-root/src/main/java/org/opendes/indexer/service/ReindexServiceImpl.java index de91f8b19e2a4265e07fd24c186ba31a323ae254..5d6657dfc5deb876296ba2244970396afb5572d1 100644 --- a/indexer-service-root/src/main/java/org/opendes/indexer/service/ReindexServiceImpl.java +++ b/indexer-service-root/src/main/java/org/opendes/indexer/service/ReindexServiceImpl.java @@ -49,7 +49,7 @@ public class ReindexServiceImpl implements ReindexService { public String reindexRecords(RecordReindexRequest recordReindexRequest) { try { - Map<String, String> headers = this.requestInfo.getHeadersMapWithDwdAuthZ(); + DpsHeaders headers = this.requestInfo.getHeadersWithDwdAuthZ(); RecordQueryResponse recordQueryResponse = this.storageService.getRecordsByKind(recordReindexRequest); @@ -59,9 +59,9 @@ public class ReindexServiceImpl implements ReindexService { .map(record -> RecordInfo.builder().id(record).kind(recordReindexRequest.getKind()).op(OperationType.create.name()).build()).collect(Collectors.toList()); Map<String, String> attributes = new HashMap<>(); - attributes.put(DpsHeaders.ACCOUNT_ID, headers.get(DpsHeaders.ACCOUNT_ID)); - attributes.put(DpsHeaders.DATA_PARITION_ID, headers.get(DpsHeaders.DATA_PARITION_ID)); - attributes.put(DpsHeaders.CORRELATION_ID, headers.get(DpsHeaders.CORRELATION_ID)); + attributes.put(DpsHeaders.ACCOUNT_ID, headers.getAccountId()); + attributes.put(DpsHeaders.DATA_PARITION_ID, headers.getPartitionIdWithFallbackToAccountId()); + attributes.put(DpsHeaders.CORRELATION_ID, headers.getCorrelationId()); Gson gson = new Gson(); RecordChangedMessages recordChangedMessages = RecordChangedMessages.builder().data(gson.toJson(msgs)).attributes(attributes).build(); diff --git a/indexer-service-root/src/main/java/org/opendes/indexer/util/IRequestInfo.java b/indexer-service-root/src/main/java/org/opendes/indexer/util/IRequestInfo.java index a6604a5fd2d5b8d0aa128dc29978559294854775..690b53930356cb85e00f256a12c5c22600c58180 100644 --- a/indexer-service-root/src/main/java/org/opendes/indexer/util/IRequestInfo.java +++ b/indexer-service-root/src/main/java/org/opendes/indexer/util/IRequestInfo.java @@ -5,15 +5,18 @@ import org.opendes.client.api.DpsHeaders; import java.util.Map; public interface IRequestInfo { - DpsHeaders getHeaders(); + public DpsHeaders getHeaders(); - String getPartitionId(); + public String getPartitionId(); - Map<String, String> getHeadersMap(); + public Map<String, String> getHeadersMap(); - Map<String, String> getHeadersMapWithDwdAuthZ(); + public Map<String, String> getHeadersMapWithDwdAuthZ(); - boolean isCronRequest(); + public DpsHeaders getHeadersWithDwdAuthZ(); - boolean isTaskQueueRequest(); + + public boolean isCronRequest(); + + public boolean isTaskQueueRequest(); } diff --git a/indexer-service-root/src/main/java/org/opendes/indexer/util/IndexerQueueTaskBuilder.java b/indexer-service-root/src/main/java/org/opendes/indexer/util/IndexerQueueTaskBuilder.java index 115df9a04d984aa828f5ff80ef503a989299406d..5458ec736874ef7b96ef85ed88912f1adc09c6d7 100644 --- a/indexer-service-root/src/main/java/org/opendes/indexer/util/IndexerQueueTaskBuilder.java +++ b/indexer-service-root/src/main/java/org/opendes/indexer/util/IndexerQueueTaskBuilder.java @@ -21,6 +21,7 @@ import com.slb.core.logging.JaxRsDpsLog; import com.slb.core.model.CloudTaskRequest; import com.slb.core.service.UrlFetchService; import com.slb.core.util.Config; +import org.opendes.client.api.DpsHeaders; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -38,15 +39,15 @@ public class IndexerQueueTaskBuilder { @Autowired private JaxRsDpsLog log; - public void createWorkerTask(String payload, Map<String, String> headers) { + public void createWorkerTask(String payload, DpsHeaders headers) { createTask(WORKER_RELATIVE_URL, payload, headers); } - public void createReIndexTask(String payload, Map<String, String> headers) { + public void createReIndexTask(String payload,DpsHeaders headers) { createTask(REINDEX_RELATIVE_URL, payload, headers); } - private void createTask(String url, String payload, Map<String, String> headers) { + private void createTask(String url, String payload, DpsHeaders headers) { CloudTaskRequest cloudTaskRequest = CloudTaskRequest.builder().message(payload).url(url).build(); @@ -54,7 +55,7 @@ public class IndexerQueueTaskBuilder { HttpResponse response = this.urlFetchService.sendRequest( HttpMethods.POST, Config.getIndexerQueueHost(), - headers, + headers.getHeaders(), null, new Gson().toJson(cloudTaskRequest)); this.log.info(String.format("task enqueuing response: %s", response.getResponseCode())); diff --git a/indexer-service-root/src/test/java/org/opendes/indexer/logging/JaxRsDpsLogTest.java b/indexer-service-root/src/test/java/org/opendes/indexer/logging/JaxRsDpsLogTest.java new file mode 100644 index 0000000000000000000000000000000000000000..c5fc0172c286d5785c78c68350f94a8abfcae324 --- /dev/null +++ b/indexer-service-root/src/test/java/org/opendes/indexer/logging/JaxRsDpsLogTest.java @@ -0,0 +1,110 @@ +// Copyright 2017-2019, Schlumberger +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opendes.indexer.logging; + +import com.slb.core.logging.JaxRsDpsLog; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.opendes.client.api.DpsHeaders; +import org.opendes.client.logging.DpsLog; +import org.opendes.client.logging.payload.AuditPayload; +import org.opendes.client.logging.payload.Request; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.*; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.*; + +@RunWith(SpringRunner.class) +public class JaxRsDpsLogTest { + + @Mock + private DpsLog log; + + @InjectMocks + private JaxRsDpsLog sut; + + @InjectMocks + private ServiceLogId logId; + + @Test + public void should_includeAllHeadersExceptAuth_when_writingALog() { + this.sut.info("msg"); + + ArgumentCaptor<Map> argument = ArgumentCaptor.forClass(Map.class); + verify(this.log).info(any(), any(), argument.capture()); + assertEquals("cor123", argument.getValue().get(DpsHeaders.CORRELATION_ID)); + assertFalse(argument.getValue().containsKey("authorization")); + + when(logId.getAppLog()).thenReturn("search.app"); + when(logId.getAuditLog()).thenReturn("search.audit"); + when(logId.getRequestLog()).thenReturn("search.request"); + } + + @Test + public void should_writeToAuditLogWithGivenPayload_on_auditRequests() { + AuditPayload pl = new AuditPayload(); + this.sut.audit(pl); + verify(this.log).audit(eq("search.audit"), eq(pl), any()); + } + + @Test + public void should_writeToRequestLogWithGivenHttpObj_on_requestLog() { + Request http = Request.builder().build(); + this.sut.request(http); + verify(this.log).request(eq("search.request"), eq(http), any()); + } + + @Test + public void should_writeToAppLogWithGivenMsg_on_errorLogrequest() { + this.sut.error("error"); + verify(this.log).error(eq("search.app"), eq("error"), any()); + } + + @Test + public void should_writeToAppLogWithGivenMsg_on_warningLogrequest() { + this.sut.warning("warning"); + verify(this.log).warning(eq("search.app"), eq("warning"), any()); + } + + @Test + public void should_writeToAppLogWithGivenMsgArray_on_warningLogrequest() { + List<String> warnings = Arrays.asList("Mismatch", "OutOfRange"); + String output = "0: Mismatch" + System.lineSeparator() + "1: OutOfRange" + System.lineSeparator(); + this.sut.warning(warnings); + verify(this.log).warning(eq("search.app"), eq(output), any()); + } + + @Test + public void should_notWriteToAppLogWithGivenNullMsgArray_on_warningLogrequest() { + List<String> warnings = null; + this.sut.warning(warnings); + verify(this.log, never()).warning(eq("search.app"), eq(null), any()); + } + + @Test + public void should_notWriteToAppLogWithGivenEmptyMsgArray_on_warningLogrequest() { + List<String> warnings = new ArrayList<>(); + this.sut.warning(warnings); + verify(this.log, never()).warning(eq("search.app"), eq(""), any()); + } +} \ No newline at end of file