summaryrefslogtreecommitdiffstats
path: root/cmso-optimizer
diff options
context:
space:
mode:
authorVikas Varma <vv8305@att.com>2019-04-01 02:11:08 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-01 02:11:08 +0000
commitd0e81cbd407753ae4435ef126d376ec839f1aac5 (patch)
treea561efe4c3a79cfccb9c979850c1cae3e602ea05 /cmso-optimizer
parent2f6d2ea5a384d3e32ad7052ef2d8b9babca91cef (diff)
parent80b3f339cadb72558feb0cadb249ce7046ce60ae (diff)
Merge "Commit 4 for Define OPtimizer API mS"
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 {