Commit 18 for Create Optimized Sched API 43/83243/3
authorJerry Flood <jflood@att.com>
Mon, 25 Mar 2019 16:29:03 +0000 (12:29 -0400)
committerJerry Flood <jflood@att.com>
Tue, 26 Mar 2019 14:18:37 +0000 (10:18 -0400)
Multiple commits required due to commit size limitation.

Change-Id: I54431d92b7685911a761800137a301ce9b2fc2f3
Issue-ID: OPTFRA-458
Signed-off-by: Jerry Flood <jflood@att.com>
cmso-service/src/main/java/org/onap/optf/cmso/ticketmgt/TmStatusClient.java
cmso-service/src/main/java/org/onap/optf/cmso/ticketmgt/bean/BuildCreateRequest.java
cmso-service/src/main/resources/logmessages.properties
cmso-service/src/test/java/org/onap/optf/cmso/JpaInit.java [new file with mode: 0644]
cmso-service/src/test/java/org/onap/optf/cmso/JtestHelper.java [new file with mode: 0644]
cmso-service/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java [new file with mode: 0644]

index e327acc..3d13b6f 100644 (file)
@@ -1,36 +1,34 @@
 /*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- * Modifications Copyright © 2018 IBM.\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
+ * Copyright © 2017-2018 AT&T Intellectual Property. Modifications Copyright © 2018 IBM.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ *\r
+ *\r
+ * Unless otherwise specified, all documentation contained herein is licensed under the Creative\r
+ * Commons License, Attribution 4.0 Intl. (the "License"); you may not use this documentation except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ *\r
+ * https://creativecommons.org/licenses/by/4.0/\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, documentation distributed under the\r
+ * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\r
+ * express or implied. See the License for the specific language governing permissions and\r
  * limitations under the License.\r
- * \r
- * \r
- * Unless otherwise specified, all documentation contained herein is licensed\r
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");\r
- * you may not use this documentation except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *         https://creativecommons.org/licenses/by/4.0/\r
- * \r
- * Unless required by applicable law or agreed to in writing, documentation\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
-*/\r
+ */\r
 \r
 package org.onap.optf.cmso.ticketmgt;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+import com.att.eelf.i18n.EELFResourceManager;\r
 import java.util.ArrayList;\r
 import java.util.HashMap;\r
 import java.util.HashSet;\r
@@ -38,7 +36,6 @@ import java.util.List;
 import java.util.Map;\r
 import java.util.Set;\r
 import java.util.UUID;\r
-\r
 import javax.transaction.Transactional;\r
 import org.onap.optf.cmso.common.CMSStatusEnum;\r
 import org.onap.optf.cmso.common.LogMessages;\r
@@ -53,13 +50,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.env.Environment;\r
 import org.springframework.stereotype.Component;\r
 import org.springframework.transaction.interceptor.TransactionAspectSupport;\r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
-import com.att.eelf.i18n.EELFResourceManager;\r
 \r
 @Component\r
 public class TmStatusClient {\r
-    private static EELFLogger log = EELFManager.getInstance().getLogger(TmStatusClient.class);\r
     private static EELFLogger errors = EELFManager.getInstance().getErrorLogger();\r
     private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();\r
 \r
@@ -87,43 +80,48 @@ public class TmStatusClient {
     Environment env;\r
 \r
     @Autowired\r
-    ScheduleDAO scheduleDAO;\r
+    ScheduleDAO scheduleDao;\r
 \r
     @Autowired\r
-    ChangeManagementScheduleDAO cmScheduleDAO;\r
+    ChangeManagementScheduleDAO cmScheduleDao;\r
 \r
     @Autowired\r
-    ChangeManagementGroupDAO cmGroupDAO;\r
+    ChangeManagementGroupDAO cmGroupDao;\r
 \r
     @Autowired\r
     TmClient tmClient;\r
 \r
+    /**\r
+     * Check status.\r
+     *\r
+     * @param id the id\r
+     */\r
     @Transactional\r
     public void checkStatus(String id) {\r
         debug.debug("Entered checkStatus id=" + id);\r
         try {\r
             // Multiple cmso instance support - re-get the record with a Schedule lock\r
-               UUID uuid = UUID.fromString(id);\r
-            Schedule s = scheduleDAO.lockOne(uuid);\r
-            if (!s.getStatus().equals(CMSStatusEnum.NotificationsInitiated.toString())) {\r
-                debug.debug(s.getScheduleId() + " is no longer in " + CMSStatusEnum.NotificationsInitiated.toString()\r
-                        + " : it is " + s.getStatus());\r
+            UUID uuid = UUID.fromString(id);\r
+            Schedule sch = scheduleDao.lockOne(uuid);\r
+            if (!sch.getStatus().equals(CMSStatusEnum.NotificationsInitiated.toString())) {\r
+                debug.debug(sch.getScheduleId() + " is no longer in " + CMSStatusEnum.NotificationsInitiated.toString()\r
+                                + " : it is " + sch.getStatus());\r
                 // Attempt at avoiding race condition in a load balance env. ?\r
                 return;\r
             }\r
             Map<GroupAuditStatus, List<ChangeManagementGroup>> groupStatus =\r
-                    new HashMap<GroupAuditStatus, List<ChangeManagementGroup>>();\r
-            List<ChangeManagementGroup> groups = cmGroupDAO.findBySchedulesID(uuid);\r
+                            new HashMap<GroupAuditStatus, List<ChangeManagementGroup>>();\r
+            List<ChangeManagementGroup> groups = cmGroupDao.findBySchedulesID(uuid);\r
 \r
             // Close tickets for completed VNFs\r
             for (ChangeManagementGroup group : groups) {\r
-                processGroup(s, group);\r
+                processGroup(sch, group);\r
             }\r
 \r
             // Check overall status of schedule.\r
             //\r
             for (ChangeManagementGroup group : groups) {\r
-                GroupAuditStatus status = auditGroupStatus(s, group);\r
+                GroupAuditStatus status = auditGroupStatus(sch, group);\r
                 List<ChangeManagementGroup> list = groupStatus.get(status);\r
                 if (list == null) {\r
                     list = new ArrayList<ChangeManagementGroup>();\r
@@ -132,16 +130,17 @@ public class TmStatusClient {
                 list.add(group);\r
             }\r
             // In progress\r
-            if (groupStatus.containsKey(GroupAuditStatus.InProgress))\r
+            if (groupStatus.containsKey(GroupAuditStatus.InProgress)) {\r
                 return;\r
+            }\r
             //\r
             if (groupStatus.containsKey(GroupAuditStatus.CompletedWithErrors)) {\r
-                s.setStatus(CMSStatusEnum.CompletedWithError.toString());\r
+                sch.setStatus(CMSStatusEnum.CompletedWithError.toString());\r
             }\r
             if (groupStatus.containsKey(GroupAuditStatus.Completed)) {\r
-                s.setStatus(CMSStatusEnum.Completed.toString());\r
+                sch.setStatus(CMSStatusEnum.Completed.toString());\r
             }\r
-            scheduleDAO.save(s);\r
+            scheduleDao.save(sch);\r
         } catch (Exception e) {\r
             errors.error(LogMessages.UNEXPECTED_EXCEPTION, e, e.getMessage());\r
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();\r
@@ -150,18 +149,17 @@ public class TmStatusClient {
         }\r
     }\r
 \r
-    private void processGroup(Schedule s, ChangeManagementGroup group) throws CMSException {\r
-        debug.debug("{Processing status of " + s.getScheduleId() + " group=" + group.getGroupId());\r
+    private void processGroup(Schedule sch, ChangeManagementGroup group) throws CMSException {\r
+        debug.debug("{Processing status of " + sch.getScheduleId() + " group=" + group.getGroupId());\r
         // Get status of all VNFs within a ticket within the group (Tickets will not\r
         // span groups)\r
         Map<String, List<ChangeManagementSchedule>> failed = new HashMap<String, List<ChangeManagementSchedule>>();\r
         Map<String, List<ChangeManagementSchedule>> inProgress = new HashMap<String, List<ChangeManagementSchedule>>();\r
         Map<String, List<ChangeManagementSchedule>> completed = new HashMap<String, List<ChangeManagementSchedule>>();\r
         Map<String, List<ChangeManagementSchedule>> tmClosed = new HashMap<String, List<ChangeManagementSchedule>>();\r
-        List<ChangeManagementSchedule> cmSchedules = cmScheduleDAO.findByChangeManagementGroupId(group.getUuid());\r
+        List<ChangeManagementSchedule> cmSchedules = cmScheduleDao.findByChangeManagementGroupId(group.getUuid());\r
         for (ChangeManagementSchedule cmSchedule : cmSchedules) {\r
             String status = cmSchedule.getStatus();\r
-            String changeId = cmSchedule.getTmChangeId();\r
             String tmStatus = cmSchedule.getTmStatus();\r
             CMSStatusEnum cmsStatus = CMSStatusEnum.Completed.fromString(status);\r
             switch (cmsStatus) {\r
@@ -186,43 +184,47 @@ public class TmStatusClient {
                 case ScheduledImmediate:\r
                 default:\r
                     errors.applicationEvent(\r
-                            "Unexpected Change Management schedule event status {0} encountered after notification : scheduleId={1} vnfName={2}",\r
-                            status, s.getScheduleId(), cmSchedule.getVnfName());\r
+                                    "Unexpected Change Management schedule event status {0} encountered "\r
+                                    + "after notification : scheduleId={1} vnfName={2}",\r
+                                    status, sch.getScheduleId(), cmSchedule.getVnfName());\r
                     break;\r
             }\r
-            if (tmStatus != null && tmStatus.equals("Closed"))\r
+            if (tmStatus != null && tmStatus.equals("Closed")) {\r
                 addTo(tmClosed, cmSchedule);\r
+            }\r
         }\r
-        debug.debug("{Status of " + s.getScheduleId() + " Group " + group.getGroupId() + "\ncompleted="\r
-                + completed.keySet().toString() + "\ninProgress=" + inProgress.keySet().toString() + "\nfailed="\r
-                + failed.keySet().toString() + "\ntmCLosed=" + tmClosed.keySet().toString());\r
+        debug.debug("{Status of " + sch.getScheduleId() + " Group " + group.getGroupId() + "\ncompleted="\r
+                        + completed.keySet().toString() + "\ninProgress=" + inProgress.keySet().toString() + "\nfailed="\r
+                        + failed.keySet().toString() + "\ntmCLosed=" + tmClosed.keySet().toString());\r
 \r
         // Remove all tickets from completed where there are still 'Triggered' VNFs\r
-        for (String changeId : inProgress.keySet())\r
+        for (String changeId : inProgress.keySet()) {\r
             completed.remove(changeId);\r
+        }\r
         // Remove all tickets from completed where the ticket is already closed.\r
-        for (String changeId : tmClosed.keySet())\r
+        for (String changeId : tmClosed.keySet()) {\r
             completed.remove(changeId);\r
+        }\r
 \r
         // Do not know what to do with failed\r
         for (String changeId : failed.keySet()) {\r
             completed.remove(changeId);\r
-            closeTheTicket(s, group, changeId, failed.get(changeId), ClosureCode.Unsuccessful,\r
-                    "Change management request failed for one or more VNFs");\r
+            closeTheTicket(sch, group, changeId, failed.get(changeId), ClosureCode.Unsuccessful,\r
+                            "Change management request failed for one or more VNFs");\r
         }\r
 \r
         // Remaining completed tickets should be closed\r
-        debug.debug("{Final status of " + s.getScheduleId() + " Group " + group.getGroupId() + "\ncompleted="\r
-                + completed.keySet().toString() + "\ninProgress=" + inProgress.keySet().toString() + "\nfailed="\r
-                + failed.keySet().toString() + "\ntmCLosed=" + tmClosed.keySet().toString());\r
+        debug.debug("{Final status of " + sch.getScheduleId() + " Group " + group.getGroupId() + "\ncompleted="\r
+                        + completed.keySet().toString() + "\ninProgress=" + inProgress.keySet().toString() + "\nfailed="\r
+                        + failed.keySet().toString() + "\ntmCLosed=" + tmClosed.keySet().toString());\r
         for (String changeId : completed.keySet()) {\r
-            closeTheTicket(s, group, changeId, completed.get(changeId), ClosureCode.Successful,\r
-                    ClosureCode.Successful.toString());\r
+            closeTheTicket(sch, group, changeId, completed.get(changeId), ClosureCode.Successful,\r
+                            ClosureCode.Successful.toString());\r
         }\r
 \r
     }\r
 \r
-    private GroupAuditStatus auditGroupStatus(Schedule s, ChangeManagementGroup group) {\r
+    private GroupAuditStatus auditGroupStatus(Schedule sch, ChangeManagementGroup group) {\r
         // Determine group status and synchronize VNF status with Ticket status.\r
         Map<String, List<ChangeManagementSchedule>> failed = new HashMap<String, List<ChangeManagementSchedule>>();\r
         Map<String, List<ChangeManagementSchedule>> inProgress = new HashMap<String, List<ChangeManagementSchedule>>();\r
@@ -232,8 +234,7 @@ public class TmStatusClient {
         Set<String> allNames = new HashSet<String>();\r
         Set<String> failedNames = new HashSet<String>();\r
         Set<String> completedNames = new HashSet<String>();\r
-        Long startDate = group.getStartTimeMillis();\r
-        List<ChangeManagementSchedule> cmSchedules = cmScheduleDAO.findByChangeManagementGroupId(group.getUuid());\r
+        List<ChangeManagementSchedule> cmSchedules = cmScheduleDao.findByChangeManagementGroupId(group.getUuid());\r
         for (ChangeManagementSchedule cmSchedule : cmSchedules) {\r
             String vnfName = cmSchedule.getVnfName();\r
             vnfNames.add(vnfName);\r
@@ -265,17 +266,20 @@ public class TmStatusClient {
                 case ScheduledImmediate:\r
                 default:\r
                     errors.applicationEvent(\r
-                            "Unexpected Change Management schedule event status {0} encountered after notification : scheduleId={1} vnfName={2}",\r
-                            status, s.getScheduleId(), cmSchedule.getVnfName());\r
+                                    "Unexpected Change Management schedule event status {0} encountered"\r
+                                    + " after notification : scheduleId={1} vnfName={2}",\r
+                                    status, sch.getScheduleId(), cmSchedule.getVnfName());\r
                     break;\r
             }\r
-            if (tmStatus != null && tmStatus.equals("Closed"))\r
+            if (tmStatus != null && tmStatus.equals("Closed")) {\r
                 addTo(tmClosed, cmSchedule);\r
+            }\r
         }\r
 \r
         // We have at least 1 ticket with VNFs in progress. Leave schedule status as is.\r
-        if (inProgress.size() > 0)\r
+        if (inProgress.size() > 0) {\r
             return GroupAuditStatus.InProgress;\r
+        }\r
 \r
         // All VNFs are either failed or completed (or there is a bug.)\r
 \r
@@ -291,7 +295,6 @@ public class TmStatusClient {
     }\r
 \r
     private void addTo(Map<String, List<ChangeManagementSchedule>> map, ChangeManagementSchedule cmSchedule) {\r
-        String status = cmSchedule.getStatus();\r
         String changeId = cmSchedule.getTmChangeId();\r
         List<ChangeManagementSchedule> list = map.get(changeId);\r
         if (list == null) {\r
@@ -302,14 +305,15 @@ public class TmStatusClient {
 \r
     }\r
 \r
-    private void closeTheTicket(Schedule s, ChangeManagementGroup group, String changeId,\r
-            List<ChangeManagementSchedule> list, ClosureCode closureCode, String closingComments) throws CMSException {\r
+    private void closeTheTicket(Schedule sch, ChangeManagementGroup group, String changeId,\r
+                    List<ChangeManagementSchedule> list, ClosureCode closureCode, String closingComments)\r
+                    throws CMSException {\r
         debug.debug("Closing ticket " + changeId + ":" + closureCode);\r
         try {\r
-            tmClient.closeTicket(s, group, list, changeId, closureCode, closingComments);\r
+            tmClient.closeTicket(sch, group, list, changeId, closureCode, closingComments);\r
             for (ChangeManagementSchedule cms : list) {\r
                 cms.setTmStatus("Closed");\r
-                cmScheduleDAO.save(cms);\r
+                cmScheduleDao.save(cms);\r
             }\r
         } catch (CMSException e) {\r
             throw e;\r
index 0b7c319..8c8cd6f 100644 (file)
@@ -1,27 +1,27 @@
 /*\r
- * Copyright © 2017-2018 AT&T Intellectual Property.\r
- * Modifications Copyright © 2018 IBM.\r
- * \r
+ * Copyright Â© 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright Â© 2018 IBM.\r
+ *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
- * \r
+ *\r
  *         http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
+ *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
  * See the License for the specific language governing permissions and\r
  * limitations under the License.\r
- * \r
- * \r
+ *\r
+ *\r
  * Unless otherwise specified, all documentation contained herein is licensed\r
  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");\r
  * you may not use this documentation except in compliance with the License.\r
  * You may obtain a copy of the License at\r
- * \r
+ *\r
  *         https://creativecommons.org/licenses/by/4.0/\r
- * \r
+ *\r
  * Unless required by applicable law or agreed to in writing, documentation\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
 \r
 package org.onap.optf.cmso.ticketmgt.bean;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+import com.fasterxml.jackson.databind.JsonNode;\r
+import com.fasterxml.jackson.databind.ObjectMapper;\r
+import com.fasterxml.jackson.databind.node.ObjectNode;\r
+import com.fasterxml.jackson.databind.node.TextNode;\r
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;\r
 import java.io.File;\r
 import java.util.Iterator;\r
 import java.util.List;\r
@@ -40,14 +47,10 @@ import org.onap.optf.cmso.common.LogMessages;
 import org.springframework.beans.factory.annotation.Autowired;\r
 import org.springframework.core.env.Environment;\r
 import org.springframework.stereotype.Component;\r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
-import com.fasterxml.jackson.databind.JsonNode;\r
-import com.fasterxml.jackson.databind.ObjectMapper;\r
-import com.fasterxml.jackson.databind.node.ObjectNode;\r
-import com.fasterxml.jackson.databind.node.TextNode;\r
-import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;\r
 \r
+/**\r
+ * The Class BuildCreateRequest.\r
+ */\r
 @Component\r
 public class BuildCreateRequest {\r
 \r
@@ -58,6 +61,9 @@ public class BuildCreateRequest {
     // This is for example purposes only ans every provider\r
     // will have unique requirements.\r
     // This assumes multiple VNFs can appear on a single ticket\r
+    /**\r
+     * The Enum Variables.\r
+     */\r
     //\r
     public enum Variables {\r
         vnfList(168), requesterId(50), plannedStartDate(15), plannedEndDate(15), validationStartTime(\r
@@ -71,19 +77,30 @@ public class BuildCreateRequest {
             this.maxLength = max;\r
         }\r
 \r
+        /**\r
+         * Gets the max length.\r
+         *\r
+         * @return the max length\r
+         */\r
         public int getMaxLength() {\r
             return maxLength;\r
         }\r
     }\r
 \r
-    private static EELFLogger log = EELFManager.getInstance().getLogger(BuildCreateRequest.class);\r
-    private static EELFLogger metrics = EELFManager.getInstance().getMetricsLogger();\r
     private static EELFLogger errors = EELFManager.getInstance().getErrorLogger();\r
     private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();\r
 \r
     @Autowired\r
     Environment env;\r
 \r
+    /**\r
+     * Creates the change record request.\r
+     *\r
+     * @param variables the variables\r
+     * @param assetList the asset list\r
+     * @param workflowName the workflow name\r
+     * @return the json node\r
+     */\r
     public JsonNode createChangeRecordRequest(Map<String, Object> variables, List<TmAsset> assetList,\r
             String workflowName) {\r
         JsonNode rawjson = getYaml("CreateChangeTicket");\r
@@ -91,24 +108,48 @@ public class BuildCreateRequest {
         return json;\r
     }\r
 \r
+    /**\r
+     * Creates the close cancel change record.\r
+     *\r
+     * @param variables the variables\r
+     * @return the json node\r
+     */\r
     public JsonNode createCloseCancelChangeRecord(Map<String, Object> variables) {\r
         JsonNode rawjson = getYaml("CloseCancelChangeRecord");\r
         JsonNode json = substituteJson(rawjson, variables);\r
         return json;\r
     }\r
 \r
+    /**\r
+     * Creates the cancel change record.\r
+     *\r
+     * @param variables the variables\r
+     * @return the json node\r
+     */\r
     public JsonNode createCancelChangeRecord(Map<String, Object> variables) {\r
         JsonNode rawjson = getYaml("CancelChangeRecord");\r
         JsonNode json = substituteJson(rawjson, variables);\r
         return json;\r
     }\r
 \r
+    /**\r
+     * Creates the update change record.\r
+     *\r
+     * @param variables the variables\r
+     * @return the json node\r
+     */\r
     public JsonNode createUpdateChangeRecord(Map<String, Object> variables) {\r
         JsonNode rawjson = getYaml("UpdateChangeRecord");\r
         JsonNode json = substituteJson(rawjson, variables);\r
         return json;\r
     }\r
 \r
+    /**\r
+     * Creates the get change record.\r
+     *\r
+     * @param variables the variables\r
+     * @return the json node\r
+     */\r
     public JsonNode createGetChangeRecord(Map<String, Object> variables) {\r
         JsonNode rawjson = getYaml("GetChangeRecord");\r
         JsonNode json = substituteJson(rawjson, variables);\r
@@ -171,17 +212,27 @@ public class BuildCreateRequest {
     }\r
 \r
     private boolean isInteger(String name) {\r
-        if (name.equals(Variables.plannedEndDate.toString()))\r
+        if (name.equals(Variables.plannedEndDate.toString())) {\r
             return true;\r
-        if (name.equals(Variables.plannedStartDate.toString()))\r
+        }\r
+        if (name.equals(Variables.plannedStartDate.toString())) {\r
             return true;\r
-        if (name.equals(Variables.actualStartDate.toString()))\r
+        }\r
+        if (name.equals(Variables.actualStartDate.toString())) {\r
             return true;\r
-        if (name.equals(Variables.actualEndDate.toString()))\r
+        }\r
+        if (name.equals(Variables.actualEndDate.toString())) {\r
             return true;\r
+        }\r
         return false;\r
     }\r
 \r
+    /**\r
+     * Gets the yaml.\r
+     *\r
+     * @param workflowName the workflow name\r
+     * @return the yaml\r
+     */\r
     public JsonNode getYaml(String workflowName) {\r
         JsonNode json = null;\r
         // Get the YAML file for this workflow\r
index e339117..cd85191 100644 (file)
@@ -57,3 +57,4 @@ UNAUTHORIZED UNAUTHORIZED|Authorization failed.|No resolution needed|No action i
 UNAUTHENTICATED UNAUTHENTICATED|Authentication failed.|No resolution needed|No action is required
 UNRECOGNIZED_MSO_STATUS UNRECOGNIZED_MSO_STATUS|Unrecognized status returned by MSO {0}|No resolution needed|No action is required
 UNABLE_TO_PARSE_MSO_RESPONSE UNABLE_TO_PARSE_MSO_RESPONSE|Unable to parse status message from MSO {0} : {1}|No resolution needed|No action is required
+MISSING_VALID_GROUP_FOR_ELEMENT MISSING_VALID_GROUP_FOR_ELEMENT|Element {0} returned by optimizer has invalid group id|No resolution needed|No action is required
diff --git a/cmso-service/src/test/java/org/onap/optf/cmso/JpaInit.java b/cmso-service/src/test/java/org/onap/optf/cmso/JpaInit.java
new file mode 100644 (file)
index 0000000..08d110e
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * ============LICENSE_START=======================================================================================
+ * Copyright (c) 2019 AT&T Intellectual Property.
+ * ===================================================================
+ * 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.optf.cmso;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.onap.optf.cmso.model.ApprovalType;
+import org.onap.optf.cmso.model.Domain;
+import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
+
+/**
+ * The Class JpaInit.
+ */
+public class JpaInit {
+
+    private static AtomicBoolean initialized = new AtomicBoolean(false);
+
+    /**
+     * Inits the.
+     *
+     * @param entityManager the entity manager
+     */
+    public static void init(TestEntityManager entityManager) {
+        if (initialized.compareAndSet(true, true)) {
+            return;
+        }
+        Domain dom = new Domain();
+        dom.setDomain("ChangeManagement");
+        entityManager.persist(dom);
+        ApprovalType at = new ApprovalType();
+        at.setApprovalCount(1);
+        at.setDomain("ChangeManagement");
+        at.setApprovalType("Tier 2");
+        entityManager.persist(at);
+        entityManager.flush();
+
+    }
+}
diff --git a/cmso-service/src/test/java/org/onap/optf/cmso/JtestHelper.java b/cmso-service/src/test/java/org/onap/optf/cmso/JtestHelper.java
new file mode 100644 (file)
index 0000000..f83cd88
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * ============LICENSE_START=======================================================================================
+ * Copyright (c) 2019 AT&T Intellectual Property.
+ * ===================================================================
+ * 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.optf.cmso;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.Map;
+import java.util.Scanner;
+import org.apache.commons.text.StrSubstitutor;
+
+public class JtestHelper {
+    private static String templatefolder = "src/test/templates" + File.separator;
+
+    /**
+     * Template.
+     *
+     * @param filename the filename
+     * @param values the values
+     * @return the string
+     */
+    public static String template(String filename, Map<String, String> values) {
+        String data = "";
+        Scanner sc = null;
+        try {
+            File tfld = new File(templatefolder + filename);
+            sc = new Scanner(tfld);
+            sc.useDelimiter("\\Z");
+            data = sc.next();
+            StrSubstitutor ss = new StrSubstitutor(values);
+            data = ss.replace(data);
+        } catch (FileNotFoundException e) {
+            data = "";
+        } finally {
+            if (sc != null) {
+                sc.close();
+            }
+        }
+        return data;
+    }
+}
diff --git a/cmso-service/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java b/cmso-service/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java
new file mode 100644 (file)
index 0000000..8070e41
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * ============LICENSE_START=======================================================================================
+ * Copyright (c) 2019 AT&T Intellectual Property.
+ * ===================================================================
+ * 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.optf.cmso.service.rs;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class MockHttpServletRequest {
+    public StringBuffer url = new StringBuffer("http://localhost:8089/cmso/v1/ChangeManagement/schedules/");
+    public HttpServletRequest request = mock(HttpServletRequest.class);
+
+    MockHttpServletRequest() {
+
+        when(request.getRequestURL()).thenReturn(url);
+        when(request.getHeader("Authorization")).thenReturn("BasicbTEzODc3OnNjaGVkdWxlci1SMTgwMiE=");
+
+    }
+
+}