2 * ============LICENSE_START==============================================
3 * Copyright (c) 2019 AT&T Intellectual Property.
4 * =======================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License. You may obtain a
7 * copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 * ============LICENSE_END=================================================
20 package org.onap.optf.cmso.optimizer.availability.timewindows;
22 import java.time.Instant;
23 import java.util.ArrayList;
24 import java.util.Date;
25 import java.util.List;
26 import java.util.TimeZone;
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.Mockito;
34 import org.mockito.MockitoAnnotations;
35 import org.mockito.runners.MockitoJUnitRunner;
36 import org.onap.optf.cmso.optimizer.availability.policies.PolicyManager;
37 import org.onap.optf.cmso.optimizer.availability.policies.model.TimeLimitAndVerticalTopology;
38 import org.onap.optf.cmso.optimizer.service.rs.models.ChangeWindow;
39 import org.springframework.core.env.Environment;
41 @RunWith(MockitoJUnitRunner.class)
42 public class RecurringWindowsTest {
46 private PolicyManager policyManager;
49 public Environment env;
53 MockitoAnnotations.initMocks(this);
54 Mockito.when(env.getProperty("cmso.local.policy.folder", "data/policies")).thenReturn("data/policies");
58 public void getAvailabilityWindowsForPolicies() {
59 getAvailabilityWindowsForPolicy("AllDayEveryDay", "2019-03-08T00:00:00.00Z", "2019-03-12T00:00:00.00Z", 5);
60 getAvailabilityWindowsForPolicy("Weekday_00_06", "2019-03-08T00:00:00.00Z", "2019-03-12T00:00:00.00Z", 3);
61 getAvailabilityWindowsForPolicy("EveryDay_00_06", "2019-03-08T00:00:00.00Z", "2019-03-12T00:00:00.00Z", 5);
62 getAvailabilityWindowsForPolicy("Weekend_00_06", "2019-03-08T00:00:00.00Z", "2019-03-12T00:00:00.00Z", 3);
65 private void getAvailabilityWindowsForPolicy(String policyName, String startStr, String endStr, int size) {
66 TimeLimitAndVerticalTopology top = policyManager.getTimeLimitAndVerticalTopologyByName(policyName);
67 Assert.assertTrue(top != null);
68 List<TimeLimitAndVerticalTopology> topList = new ArrayList<>();
70 ChangeWindow changeWindow = new ChangeWindow();
71 Instant start = Instant.parse(startStr);
72 Instant end = Instant.parse(endStr);
73 changeWindow.setStartTime(Date.from(start));
74 changeWindow.setEndTime(Date.from(end));
75 List<ChangeWindow> windows = RecurringWindows.getAvailabilityWindowsForPolicies(topList, changeWindow);
76 Assert.assertTrue(windows != null);
77 Assert.assertTrue(windows.size() == size);