aboutsummaryrefslogtreecommitdiffstats
path: root/cmso-optimizer
diff options
context:
space:
mode:
authorJerry Flood <jflood@att.com>2019-03-31 08:32:37 -0400
committerJerry Flood <jflood@att.com>2019-03-31 08:41:13 -0400
commit80b3f339cadb72558feb0cadb249ce7046ce60ae (patch)
tree4a8b569c19959659ac628061e6ba386b3d6c1565 /cmso-optimizer
parent9acaa2f04c92b6ffb0ae11a0f7b41aa260f2371d (diff)
Commit 4 for Define OPtimizer API mS
Multiple commits required due to commit size limitation. Change-Id: I351c5c47d628c253e84059d6e699f5a24748883f Issue-ID: OPTFRA-437 Signed-off-by: Jerry Flood <jflood@att.com>
Diffstat (limited to 'cmso-optimizer')
-rw-r--r--cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/policies/PolicyManagerTest.java13
-rw-r--r--cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/timewindows/RecurringWindowsTest.java79
-rw-r--r--cmso-optimizer/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java1
3 files changed, 85 insertions, 8 deletions
diff --git a/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/policies/PolicyManagerTest.java b/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/policies/PolicyManagerTest.java
index 7874501..c71c829 100644
--- a/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/policies/PolicyManagerTest.java
+++ b/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/policies/PolicyManagerTest.java
@@ -18,6 +18,7 @@
*/
package org.onap.optf.cmso.optimizer.availability.policies;
+
import java.util.List;
import org.junit.Assert;
import org.junit.Before;
@@ -33,8 +34,7 @@ import org.onap.optf.cmso.optimizer.availability.policies.model.TimeLimitAndVert
import org.springframework.core.env.Environment;
@RunWith(MockitoJUnitRunner.class)
-public class PolicyManagerTest
-{
+public class PolicyManagerTest {
@InjectMocks
private PolicyManager policyManager;
@@ -52,12 +52,11 @@ public class PolicyManagerTest
public void getPolicyByName() {
String policyName = "Weekday_00_06";
- String result = "CMSO.Weekday_00_06,";
+ String result = "CMSO.Weekday_00_06,CMSO.Weekday_00_06,CMSO.Weekday_00_06,";
List<Policy> policies = policyManager.getSupportedPolicies();
StringBuilder sb = new StringBuilder();
- for (Policy pol : policies)
- {
- sb.append(pol.getPolicyName()).append("," );
+ for (Policy pol : policies) {
+ sb.append(pol.getPolicyName()).append(",");
}
System.out.println(" String result = \"" + sb.toString() + "\";");
Assert.assertTrue(result.equals(sb.toString()));
@@ -67,4 +66,4 @@ public class PolicyManagerTest
Assert.assertTrue(top != null);
}
-} \ No newline at end of file
+}
diff --git a/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/timewindows/RecurringWindowsTest.java b/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/timewindows/RecurringWindowsTest.java
new file mode 100644
index 0000000..ce1f1a4
--- /dev/null
+++ b/cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/timewindows/RecurringWindowsTest.java
@@ -0,0 +1,79 @@
+/*
+ * ============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.optimizer.availability.timewindows;
+
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+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.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.optf.cmso.optimizer.availability.policies.PolicyManager;
+import org.onap.optf.cmso.optimizer.availability.policies.model.TimeLimitAndVerticalTopology;
+import org.onap.optf.cmso.optimizer.service.rs.models.ChangeWindow;
+import org.springframework.core.env.Environment;
+
+@RunWith(MockitoJUnitRunner.class)
+public class RecurringWindowsTest {
+
+
+ @InjectMocks
+ private PolicyManager policyManager;
+
+ @Mock
+ public Environment env;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ Mockito.when(env.getProperty("cmso.local.policy.folder", "data/policies")).thenReturn("data/policies");
+ }
+
+ @Test
+ public void getAvailabilityWindowsForPolicies() {
+ getAvailabilityWindowsForPolicy("Weekday_00_06", "2019-03-08T00:00:00.00Z", "2019-03-12T00:00:00.00Z", 2);
+ getAvailabilityWindowsForPolicy("EveryDay_00_06", "2019-03-08T00:00:00.00Z", "2019-03-12T00:00:00.00Z", 4);
+ getAvailabilityWindowsForPolicy("Weekend_00_06", "2019-03-08T00:00:00.00Z", "2019-03-12T00:00:00.00Z", 3);
+
+ }
+
+ private void getAvailabilityWindowsForPolicy(String policyName, String startStr, String endStr, int size) {
+ TimeLimitAndVerticalTopology top = policyManager.getTimeLimitAndVerticalTopologyByName(policyName);
+ Assert.assertTrue(top != null);
+ List<TimeLimitAndVerticalTopology> topList = new ArrayList<>();
+ topList.add(top);
+ ChangeWindow changeWindow = new ChangeWindow();
+ Instant start = Instant.parse(startStr);
+ Instant end = Instant.parse(endStr);
+ changeWindow.setStartTime(Date.from(start));
+ changeWindow.setEndTime(Date.from(end));
+ List<ChangeWindow> windows = RecurringWindows.getAvailabilityWindowsForPolicies(topList, changeWindow);
+ Assert.assertTrue(windows != null);
+ Assert.assertTrue(windows.size() == size);
+
+ }
+}
diff --git a/cmso-optimizer/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java b/cmso-optimizer/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java
index 84e66c1..f7d0939 100644
--- a/cmso-optimizer/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java
+++ b/cmso-optimizer/src/test/java/org/onap/optf/cmso/service/rs/MockHttpServletRequest.java
@@ -21,7 +21,6 @@ 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 {