From 80b3f339cadb72558feb0cadb249ce7046ce60ae Mon Sep 17 00:00:00 2001 From: Jerry Flood Date: Sun, 31 Mar 2019 08:32:37 -0400 Subject: 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 --- .../availability/policies/PolicyManagerTest.java | 13 ++-- .../timewindows/RecurringWindowsTest.java | 79 ++++++++++++++++++++++ .../cmso/service/rs/MockHttpServletRequest.java | 1 - 3 files changed, 85 insertions(+), 8 deletions(-) create mode 100644 cmso-optimizer/src/test/java/org/onap/optf/cmso/optimizer/availability/timewindows/RecurringWindowsTest.java (limited to 'cmso-optimizer') 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 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 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 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 { -- cgit 1.2.3-korg