From a8bc4c671a318f9f130d1a2d92f72dd75cd60f92 Mon Sep 17 00:00:00 2001
From: aalekhj <aaljain@microsoft.com>
Date: Thu, 24 Sep 2020 11:38:48 +0530
Subject: [PATCH] Added init method for unit testing for
 `LegalTagPublisherImpl`

---
 .../azure/jobs/LegalTagPublisherImplTest.java | 69 +++++++++++++++++++
 .../org.mockito.plugins.MockMaker             |  1 +
 2 files changed, 70 insertions(+)
 create mode 100644 provider/legal-azure/src/test/java/org/opengroup/osdu/legal/azure/jobs/LegalTagPublisherImplTest.java
 create mode 100644 provider/legal-azure/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker

diff --git a/provider/legal-azure/src/test/java/org/opengroup/osdu/legal/azure/jobs/LegalTagPublisherImplTest.java b/provider/legal-azure/src/test/java/org/opengroup/osdu/legal/azure/jobs/LegalTagPublisherImplTest.java
new file mode 100644
index 000000000..ccbe72aec
--- /dev/null
+++ b/provider/legal-azure/src/test/java/org/opengroup/osdu/legal/azure/jobs/LegalTagPublisherImplTest.java
@@ -0,0 +1,69 @@
+//  Copyright © Microsoft Corporation
+//
+//  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.opengroup.osdu.legal.azure.jobs;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.microsoft.azure.servicebus.Message;
+import com.microsoft.azure.servicebus.MessageBody;
+import com.microsoft.azure.servicebus.TopicClient;
+import com.microsoft.azure.servicebus.primitives.ServiceBusException;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
+import org.opengroup.osdu.core.common.model.http.DpsHeaders;
+import org.opengroup.osdu.core.common.model.legal.StatusChangedTags;
+
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.*;
+
+@RunWith(MockitoJUnitRunner.class)
+public class LegalTagPublisherImplTest {
+
+
+    private static final String DATA_PARTITION_WITH_FALLBACK_ACCOUNT_ID = "data-partition-account-id";
+    private static final String CORRELATION_ID = "correlation-id";
+    private static final String USER_EMAIL = "user@email.com";
+
+    private JaxRsDpsLog logger;
+
+    private TopicClient topicClient;
+
+    @Mock
+    private DpsHeaders headers;
+
+    @InjectMocks
+    private LegalTagPublisherImpl sut;
+
+    @Before
+    public void init() throws ServiceBusException, InterruptedException {
+        topicClient = mock(TopicClient.class);
+        logger = mock(JaxRsDpsLog.class);
+        doNothing().when(topicClient).send(any());
+        doNothing().when(logger).error(anyString(), (Exception) any());
+        doNothing().when(logger).info(anyString());
+        doReturn(DATA_PARTITION_WITH_FALLBACK_ACCOUNT_ID).when(headers).getPartitionIdWithFallbackToAccountId();
+        doReturn(CORRELATION_ID).when(headers).getCorrelationId();
+        doReturn(USER_EMAIL).when(headers).getUserEmail();
+        sut = new LegalTagPublisherImpl(topicClient, logger);
+    }
+}
diff --git a/provider/legal-azure/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/provider/legal-azure/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644
index 000000000..1f0955d45
--- /dev/null
+++ b/provider/legal-azure/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
@@ -0,0 +1 @@
+mock-maker-inline
-- 
GitLab