Created external task utils in a common location 91/95191/1
authorBoslet, Cory <cory.boslet@att.com>
Sun, 8 Sep 2019 15:31:56 +0000 (11:31 -0400)
committerBenjamin, Max (mb388a) <mb388a@att.com>
Sun, 8 Sep 2019 15:31:56 +0000 (11:31 -0400)
Created external task utils in a common location then refactored
external task to use these common utils
Updated junit errors and failures in openstack
Removed env param and updated unit test with class
Remove env file from parm in unit test class
Match argu to match class abstract to con.
removed implementation within anonymous class

Issue-ID: SO-2291
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: I47c2850d750cbfe7ef67e2396fcb46db43e3cb97

12 files changed:
adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AbstractAuditService.java
adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java
adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java
adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryService.java
adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java
adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java
adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceTest.java [deleted file]
common/pom.xml
common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java [new file with mode: 0644]
common/src/main/java/org/onap/so/utils/ExternalTaskUtils.java [new file with mode: 0644]
common/src/test/java/org/onap/so/utils/ExternalTaskServiceUtilsTest.java [new file with mode: 0644]
common/src/test/java/org/onap/so/utils/ExternalTaskUtilsTest.java [new file with mode: 0644]

index 8edce12..493ac4a 100644 (file)
 package org.onap.so.adapters.audit;
 
 import java.util.Optional;
-import org.camunda.bpm.client.task.ExternalTask;
-import org.onap.logging.ref.slf4j.ONAPLogConstants;
 import org.onap.so.objects.audit.AAIObjectAudit;
 import org.onap.so.objects.audit.AAIObjectAuditList;
+import org.onap.so.utils.ExternalTaskUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Component;
 
 @Component
-public abstract class AbstractAuditService {
+public abstract class AbstractAuditService extends ExternalTaskUtils {
 
     private static final Logger logger = LoggerFactory.getLogger(AbstractAuditService.class);
 
@@ -82,22 +80,4 @@ public abstract class AbstractAuditService {
         }
     }
 
-    protected String[] getRetrySequence() {
-        return env.getProperty("mso.workflow.topics.retrySequence", String[].class);
-    }
-
-    protected void setupMDC(ExternalTask externalTask) {
-        logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
-        String msoRequestId = externalTask.getVariable("mso-request-id");
-        if (msoRequestId != null && !msoRequestId.isEmpty()) {
-            MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId);
-        }
-        MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, externalTask.getTopicName());
-    }
-
-    protected long calculateRetryDelay(int currentRetries) {
-        int retrySequence = getRetrySequence().length - currentRetries;
-        long retryMultiplier = Long.parseLong(env.getProperty("mso.workflow.topics.retryMultiplier", "6000"));
-        return Integer.parseInt(getRetrySequence()[retrySequence]) * retryMultiplier;
-    }
 }
index 1e5b6de..d03c86a 100644 (file)
@@ -34,7 +34,6 @@ import org.onap.so.objects.audit.AAIObjectAuditList;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Component;
 
 @Component
@@ -45,9 +44,6 @@ public class AuditCreateStackService extends AbstractAuditService {
     @Autowired
     public HeatStackAudit heatStackAudit;
 
-    @Autowired
-    public Environment environment;
-
     protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
         setupMDC(externalTask);
         AuditInventory auditInventory = externalTask.getVariable("auditInventory");
index 6a42456..fb7e925 100644 (file)
 
 package org.onap.so.adapters.audit;
 
-import java.security.GeneralSecurityException;
 import javax.annotation.PostConstruct;
 import org.camunda.bpm.client.ExternalTaskClient;
-import org.camunda.bpm.client.backoff.ExponentialBackoffStrategy;
-import org.camunda.bpm.client.interceptor.ClientRequestInterceptor;
-import org.camunda.bpm.client.interceptor.auth.BasicAuthProvider;
-import org.onap.so.utils.CryptoUtils;
+import org.onap.so.utils.ExternalTaskServiceUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -56,10 +52,13 @@ public class AuditStackService {
     @Autowired
     private AuditQueryStackService auditQueryStack;
 
+    @Autowired
+    private ExternalTaskServiceUtils externalTaskServiceUtils;
+
     @PostConstruct
-    public void auditAddAAIInventory() {
-        for (int i = 0; i < getMaxClients(); i++) {
-            ExternalTaskClient client = createExternalTaskClient();
+    public void auditAddAAIInventory() throws Exception {
+        for (int i = 0; i < externalTaskServiceUtils.getMaxClients(); i++) {
+            ExternalTaskClient client = externalTaskServiceUtils.createExternalTaskClient();
             client.subscribe("InventoryAddAudit")
                     .lockDuration(Long.parseLong(env.getProperty("mso.audit.lock-time", DEFAULT_AUDIT_LOCK_TIME)))
                     .handler(auditCreateStack::executeExternalTask).open();
@@ -67,9 +66,9 @@ public class AuditStackService {
     }
 
     @PostConstruct
-    public void auditDeleteAAIInventory() {
-        for (int i = 0; i < getMaxClients(); i++) {
-            ExternalTaskClient client = createExternalTaskClient();
+    public void auditDeleteAAIInventory() throws Exception {
+        for (int i = 0; i < externalTaskServiceUtils.getMaxClients(); i++) {
+            ExternalTaskClient client = externalTaskServiceUtils.createExternalTaskClient();
             client.subscribe("InventoryDeleteAudit")
                     .lockDuration(Long.parseLong(env.getProperty("mso.audit.lock-time", DEFAULT_AUDIT_LOCK_TIME)))
                     .handler(auditDeleteStack::executeExternalTask).open();
@@ -77,35 +76,13 @@ public class AuditStackService {
     }
 
     @PostConstruct
-    public void auditQueryInventory() {
-        for (int i = 0; i < getMaxClients(); i++) {
-            ExternalTaskClient client = createExternalTaskClient();
+    public void auditQueryInventory() throws Exception {
+        for (int i = 0; i < externalTaskServiceUtils.getMaxClients(); i++) {
+            ExternalTaskClient client = externalTaskServiceUtils.createExternalTaskClient();
             client.subscribe("InventoryQueryAudit")
                     .lockDuration(Long.parseLong(env.getProperty("mso.audit.lock-time", DEFAULT_AUDIT_LOCK_TIME)))
                     .handler(auditQueryStack::executeExternalTask).open();
         }
     }
 
-    protected ExternalTaskClient createExternalTaskClient() {
-        ClientRequestInterceptor interceptor = createClientRequestInterceptor();
-        return ExternalTaskClient.create().baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1)
-                .addInterceptor(interceptor).asyncResponseTimeout(120000)
-                .backoffStrategy(new ExponentialBackoffStrategy(0, 0, 0)).build();
-    }
-
-    protected ClientRequestInterceptor createClientRequestInterceptor() {
-        String auth = "";
-        try {
-            auth = CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey"));
-        } catch (IllegalStateException | GeneralSecurityException e) {
-            logger.error("Error Decrypting Password", e);
-        }
-        return new BasicAuthProvider(env.getRequiredProperty("mso.config.cadi.aafId"), auth);
-    }
-
-    protected int getMaxClients() {
-        return Integer.parseInt(env.getProperty("workflow.topics.maxClients", DEFAULT_MAX_CLIENTS_FOR_TOPIC));
-    }
-
-
 }
index 49a9e7e..c1cc742 100644 (file)
 
 package org.onap.so.adapters.inventory.create;
 
-import java.security.GeneralSecurityException;
 import javax.annotation.PostConstruct;
 import org.camunda.bpm.client.ExternalTaskClient;
-import org.camunda.bpm.client.backoff.ExponentialBackoffStrategy;
-import org.camunda.bpm.client.interceptor.ClientRequestInterceptor;
-import org.camunda.bpm.client.interceptor.auth.BasicAuthProvider;
-import org.onap.so.utils.CryptoUtils;
+import org.onap.so.utils.ExternalTaskServiceUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,19 +42,13 @@ public class CreateInventoryService {
     @Autowired
     private CreateInventoryTask createInventory;
 
+    @Autowired
+    private ExternalTaskServiceUtils externalTaskServiceUtils;
+
     @PostConstruct
-    public void auditAAIInventory() {
-        String auth = "";
-        try {
-            auth = CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey"));
-        } catch (IllegalStateException | GeneralSecurityException e) {
-            logger.error("Error Decrypting Password", e);
-        }
-        ClientRequestInterceptor interceptor =
-                new BasicAuthProvider(env.getRequiredProperty("mso.config.cadi.aafId"), auth);
-        ExternalTaskClient client = ExternalTaskClient.create()
-                .baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1).addInterceptor(interceptor)
-                .asyncResponseTimeout(120000).backoffStrategy(new ExponentialBackoffStrategy(0, 0, 0)).build();
+    public void auditAAIInventory() throws Exception {
+
+        ExternalTaskClient client = externalTaskServiceUtils.createExternalTaskClient();
         client.subscribe("InventoryCreate")
                 .lockDuration(Long.parseLong(env.getProperty("mso.audit.lock-time", "60000")))
                 .handler(createInventory::executeExternalTask).open();
index a6c6170..29d0ef6 100644 (file)
@@ -27,15 +27,14 @@ import org.camunda.bpm.client.task.ExternalTaskService;
 import org.onap.logging.ref.slf4j.ONAPLogConstants;
 import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
 import org.onap.so.objects.audit.AAIObjectAuditList;
+import org.onap.so.utils.ExternalTaskUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Component;
 
 @Component
-public class CreateInventoryTask {
+public class CreateInventoryTask extends ExternalTaskUtils {
 
     private static final String UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI = "Unable to write all inventory to A&AI";
 
@@ -46,9 +45,6 @@ public class CreateInventoryTask {
     @Autowired
     CreateAAIInventory createInventory;
 
-    @Autowired
-    public Environment env;
-
     protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
         setupMDC(externalTask);
         boolean success = true;
@@ -107,25 +103,5 @@ public class CreateInventoryTask {
         }
     }
 
-    private void setupMDC(ExternalTask externalTask) {
-        try {
-            logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
-            MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, externalTask.getTopicName());
-            String msoRequestId = externalTask.getVariable("mso-request-id");
-            if (msoRequestId != null && !msoRequestId.isEmpty())
-                MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId);
-        } catch (Exception e) {
-            logger.error("Error in setting up MDC", e);
-        }
-    }
-
-    protected long calculateRetryDelay(int currentRetries) {
-        int retrySequence = getRetrySequence().length - currentRetries;
-        long retryMultiplier = Long.parseLong(env.getProperty("mso.workflow.topics.retryMultiplier", "6000"));
-        return Integer.parseInt(getRetrySequence()[retrySequence]) * retryMultiplier;
-    }
 
-    public String[] getRetrySequence() {
-        return env.getProperty("mso.workflow.topics.retrySequence", String[].class);
-    }
 }
index 3432e4a..2109fb2 100644 (file)
@@ -169,47 +169,6 @@ public class AuditStackServiceDataTest extends AuditCreateStackService {
         assertNotNull(actualMap.get("auditInventoryResult"));
     }
 
-    @Test
-    public void retry_sequence_calculation_Test() {
-        long firstRetry = auditStackService.calculateRetryDelay(8);
-        assertEquals(6000L, firstRetry);
-        long secondRetry = auditStackService.calculateRetryDelay(7);
-        assertEquals(6000L, secondRetry);
-        long thirdRetry = auditStackService.calculateRetryDelay(6);
-        assertEquals(12000L, thirdRetry);
-        long fourthRetry = auditStackService.calculateRetryDelay(5);
-        assertEquals(18000L, fourthRetry);
-        long fifthRetry = auditStackService.calculateRetryDelay(4);
-        assertEquals(30000L, fifthRetry);
-        long sixRetry = auditStackService.calculateRetryDelay(3);
-        assertEquals(48000L, sixRetry);
-        long seventhRetry = auditStackService.calculateRetryDelay(2);
-        assertEquals(78000L, seventhRetry);
-        long eigthRetry = auditStackService.calculateRetryDelay(1);
-        assertEquals(120000L, eigthRetry);
-    }
-
-    @Test
-    public void retry_sequence_Test() {
-        long firstRetry = auditStackService.calculateRetryDelay(8);
-        assertEquals(6000L, firstRetry);
-        long secondRetry = auditStackService.calculateRetryDelay(7);
-        assertEquals(6000L, secondRetry);
-        long thirdRetry = auditStackService.calculateRetryDelay(6);
-        assertEquals(12000L, thirdRetry);
-        long fourthRetry = auditStackService.calculateRetryDelay(5);
-        assertEquals(18000L, fourthRetry);
-        long fifthRetry = auditStackService.calculateRetryDelay(4);
-        assertEquals(30000L, fifthRetry);
-        long sixRetry = auditStackService.calculateRetryDelay(3);
-        assertEquals(48000L, sixRetry);
-        long seventhRetry = auditStackService.calculateRetryDelay(2);
-        assertEquals(78000L, seventhRetry);
-        long eigthRetry = auditStackService.calculateRetryDelay(1);
-        assertEquals(120000L, eigthRetry);
-    }
-
-
     @Test
     public void determineAuditResult_Test() throws Exception {
         boolean actual = auditStackService.didCreateAuditFail(auditListOptSuccess);
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceTest.java
deleted file mode 100644 (file)
index c9aef95..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.so.adapters.audit;
-
-import static com.shazam.shazamcrest.MatcherAssert.assertThat;
-import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import org.camunda.bpm.client.ExternalTaskClient;
-import org.camunda.bpm.client.interceptor.ClientRequestInterceptor;
-import org.camunda.bpm.client.interceptor.auth.BasicAuthProvider;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.Spy;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.onap.so.utils.CryptoUtils;
-import org.springframework.core.env.Environment;
-
-@RunWith(MockitoJUnitRunner.class)
-public class AuditStackServiceTest {
-
-    @Spy
-    @InjectMocks
-    AuditStackService auditStackService;
-
-    @Mock
-    Environment mockEnvironment;
-
-
-    @Before
-    public void before() {
-        Mockito.doReturn("5").when(mockEnvironment).getProperty("workflow.topics.maxClients", "10");
-        Mockito.doReturn("6B466C603A260F3655DBF91E53CE54667041C01406D10E8CAF9CC24D8FA5388D06F90BFE4C852052B436")
-                .when(mockEnvironment).getRequiredProperty("mso.auth");
-        Mockito.doReturn("07a7159d3bf51a0e53be7a8f89699be7").when(mockEnvironment).getRequiredProperty("mso.msoKey");
-        Mockito.doReturn("something").when(mockEnvironment).getRequiredProperty("mso.config.cadi.aafId");
-        Mockito.doReturn("host.com").when(mockEnvironment).getRequiredProperty("mso.workflow.endpoint");
-    }
-
-    @Test
-    public void testGetMaxClients() throws Exception {
-        int actual = auditStackService.getMaxClients();
-        assertEquals(5, actual);
-    }
-
-    @Test
-    public void testCreateClientRequestInterceptor() throws Exception {
-        String auth = CryptoUtils.decrypt(
-                "6B466C603A260F3655DBF91E53CE54667041C01406D10E8CAF9CC24D8FA5388D06F90BFE4C852052B436",
-                "07a7159d3bf51a0e53be7a8f89699be7");
-        ClientRequestInterceptor expected = new BasicAuthProvider("something", auth);
-        ClientRequestInterceptor actual = auditStackService.createClientRequestInterceptor();
-        assertThat(actual, sameBeanAs(expected));
-
-    }
-
-    @Test
-    public void testCreateExternalTaskClient() throws Exception {
-        String auth = CryptoUtils.decrypt(
-                "6B466C603A260F3655DBF91E53CE54667041C01406D10E8CAF9CC24D8FA5388D06F90BFE4C852052B436",
-                "07a7159d3bf51a0e53be7a8f89699be7");
-        ClientRequestInterceptor inter = new BasicAuthProvider("something", auth);
-        Mockito.doReturn(inter).when(auditStackService).createClientRequestInterceptor();
-        ExternalTaskClient actual = auditStackService.createExternalTaskClient();
-        assertNotNull(actual);
-        Mockito.verify(auditStackService, Mockito.times(1)).createClientRequestInterceptor();
-
-    }
-}
index 2553038..1a4ffe1 100644 (file)
       <artifactId>javatuples</artifactId>
       <version>1.2</version>
     </dependency>
-
+        <dependency>
+      <groupId>org.camunda.bpm</groupId>
+      <artifactId>camunda-external-task-client</artifactId>
+      <version>1.1.1</version>
+    </dependency>
   </dependencies>
   <dependencyManagement>
     <dependencies>
diff --git a/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java b/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java
new file mode 100644 (file)
index 0000000..e43b431
--- /dev/null
@@ -0,0 +1,46 @@
+package org.onap.so.utils;
+
+import java.security.GeneralSecurityException;
+import org.camunda.bpm.client.ExternalTaskClient;
+import org.camunda.bpm.client.interceptor.ClientRequestInterceptor;
+import org.camunda.bpm.client.interceptor.auth.BasicAuthProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ExternalTaskServiceUtils {
+
+    @Autowired
+    public Environment env;
+
+    private static final Logger logger = LoggerFactory.getLogger(ExternalTaskServiceUtils.class);
+
+    public ExternalTaskClient createExternalTaskClient() throws Exception {
+        String auth = getAuth();
+        ClientRequestInterceptor interceptor = createClientInterceptor(auth);
+        return ExternalTaskClient.create().baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1)
+                .addInterceptor(interceptor).asyncResponseTimeout(120000).build();
+    }
+
+    protected ClientRequestInterceptor createClientInterceptor(String auth) {
+        return new BasicAuthProvider(env.getRequiredProperty("mso.config.cadi.aafId"), auth);
+    }
+
+    protected String getAuth() throws Exception {
+        try {
+            return CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey"));
+        } catch (IllegalStateException | GeneralSecurityException e) {
+            logger.error("Error Decrypting Password", e);
+            throw new Exception("Cannot load password");
+        }
+    }
+
+    public int getMaxClients() {
+        return Integer.parseInt(env.getProperty("workflow.topics.maxClients", "3"));
+    }
+
+
+}
diff --git a/common/src/main/java/org/onap/so/utils/ExternalTaskUtils.java b/common/src/main/java/org/onap/so/utils/ExternalTaskUtils.java
new file mode 100644 (file)
index 0000000..349767f
--- /dev/null
@@ -0,0 +1,46 @@
+package org.onap.so.utils;
+
+import org.camunda.bpm.client.task.ExternalTask;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+
+@Component
+public abstract class ExternalTaskUtils {
+
+    @Autowired
+    Environment env;
+
+    private static final Logger logger = LoggerFactory.getLogger(ExternalTaskUtils.class);
+
+    public long calculateRetryDelay(int currentRetries) {
+        int retrySequence = getRetrySequence().length - currentRetries;
+        return Integer.parseInt(getRetrySequence()[retrySequence]) * getRetryMutiplier();
+    }
+
+    protected Long getRetryMutiplier() {
+        return Long.parseLong(env.getProperty("mso.workflow.topics.retryMultiplier", "6000"));
+    }
+
+    protected String[] getRetrySequence() {
+        String[] seq = {"1", "1", "2", "3", "5", "8", "13", "20"};
+        if (env.getProperty("mso.workflow.topics.retrySequence") != null) {
+            seq = env.getProperty("mso.workflow.topics.retrySequence", String[].class);
+        }
+        return seq;
+    }
+
+    protected void setupMDC(ExternalTask externalTask) {
+        logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
+        String msoRequestId = externalTask.getVariable("mso-request-id");
+        if (msoRequestId != null && !msoRequestId.isEmpty()) {
+            MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId);
+        }
+        MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, externalTask.getTopicName());
+    }
+
+}
diff --git a/common/src/test/java/org/onap/so/utils/ExternalTaskServiceUtilsTest.java b/common/src/test/java/org/onap/so/utils/ExternalTaskServiceUtilsTest.java
new file mode 100644 (file)
index 0000000..b2db986
--- /dev/null
@@ -0,0 +1,61 @@
+package org.onap.so.utils;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
+import org.camunda.bpm.client.ExternalTaskClient;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.springframework.core.env.Environment;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ExternalTaskServiceUtilsTest {
+
+    @Spy
+    @InjectMocks
+    private ExternalTaskServiceUtils utils = new ExternalTaskServiceUtils();
+
+    @Mock
+    private Environment mockEnv;
+
+    @Mock
+    private ExternalTaskClient mockClient;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+        doReturn("3").when(mockEnv).getProperty("workflow.topics.maxClients", "3");
+        doReturn("07a7159d3bf51a0e53be7a8f89699be7").when(mockEnv).getRequiredProperty("mso.msoKey");
+        doReturn("6B466C603A260F3655DBF91E53CE54667041C01406D10E8CAF9CC24D8FA5388D06F90BFE4C852052B436").when(mockEnv)
+                .getRequiredProperty("mso.auth");
+        doReturn("someid").when(mockEnv).getRequiredProperty("mso.config.cadi.aafId");
+        doReturn("http://camunda.com").when(mockEnv).getRequiredProperty("mso.workflow.endpoint");
+    }
+
+    @Test
+    public void testCreateExternalTaskClient() throws Exception {
+        ExternalTaskClient actualClient = utils.createExternalTaskClient();
+        Assert.assertNotNull(actualClient);
+    }
+
+    @Test
+    public void testGetAuth() throws Exception {
+        String actual = utils.getAuth();
+        String expected = "Att32054Life!@";
+        assertEquals(expected, actual);
+    }
+
+    @Test
+    public void testGetMaxClients() throws Exception {
+        int actual = utils.getMaxClients();
+        int expected = 3;
+        assertEquals(expected, actual);
+    }
+
+}
diff --git a/common/src/test/java/org/onap/so/utils/ExternalTaskUtilsTest.java b/common/src/test/java/org/onap/so/utils/ExternalTaskUtilsTest.java
new file mode 100644 (file)
index 0000000..f918781
--- /dev/null
@@ -0,0 +1,65 @@
+package org.onap.so.utils;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.springframework.core.env.Environment;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ExternalTaskUtilsTest {
+
+    @Mock
+    private Environment mockenv;
+
+    @InjectMocks
+    private ExternalTaskUtils externalTaskUtilsAnony = new ExternalTaskUtils() {
+
+    };
+
+    @Test
+    public void retry_sequence_calculation_Test() {
+        Mockito.when(mockenv.getProperty("mso.workflow.topics.retryMultiplier", "6000")).thenReturn("6000");
+        long firstRetry = externalTaskUtilsAnony.calculateRetryDelay(8);
+        assertEquals(6000L, firstRetry);
+        long secondRetry = externalTaskUtilsAnony.calculateRetryDelay(7);
+        assertEquals(6000L, secondRetry);
+        long thirdRetry = externalTaskUtilsAnony.calculateRetryDelay(6);
+        assertEquals(12000L, thirdRetry);
+        long fourthRetry = externalTaskUtilsAnony.calculateRetryDelay(5);
+        assertEquals(18000L, fourthRetry);
+        long fifthRetry = externalTaskUtilsAnony.calculateRetryDelay(4);
+        assertEquals(30000L, fifthRetry);
+        long sixRetry = externalTaskUtilsAnony.calculateRetryDelay(3);
+        assertEquals(48000L, sixRetry);
+        long seventhRetry = externalTaskUtilsAnony.calculateRetryDelay(2);
+        assertEquals(78000L, seventhRetry);
+        long eigthRetry = externalTaskUtilsAnony.calculateRetryDelay(1);
+        assertEquals(120000L, eigthRetry);
+    }
+
+    @Test
+    public void retry_sequence_Test() {
+        Mockito.when(mockenv.getProperty("mso.workflow.topics.retryMultiplier", "6000")).thenReturn("6000");
+        long firstRetry = externalTaskUtilsAnony.calculateRetryDelay(8);
+        assertEquals(6000L, firstRetry);
+        long secondRetry = externalTaskUtilsAnony.calculateRetryDelay(7);
+        assertEquals(6000L, secondRetry);
+        long thirdRetry = externalTaskUtilsAnony.calculateRetryDelay(6);
+        assertEquals(12000L, thirdRetry);
+        long fourthRetry = externalTaskUtilsAnony.calculateRetryDelay(5);
+        assertEquals(18000L, fourthRetry);
+        long fifthRetry = externalTaskUtilsAnony.calculateRetryDelay(4);
+        assertEquals(30000L, fifthRetry);
+        long sixRetry = externalTaskUtilsAnony.calculateRetryDelay(3);
+        assertEquals(48000L, sixRetry);
+        long seventhRetry = externalTaskUtilsAnony.calculateRetryDelay(2);
+        assertEquals(78000L, seventhRetry);
+        long eigthRetry = externalTaskUtilsAnony.calculateRetryDelay(1);
+        assertEquals(120000L, eigthRetry);
+    }
+
+}