787450197273ddb938254e62f5d22851942523e2
[optf/cmso.git] /
1 /*
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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=================================================
17  *
18  */
19
20 package org.onap.optf.cmso.optimizer.availability.policies;
21 import java.util.List;
22 import org.junit.Assert;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.InjectMocks;
27 import org.mockito.Mock;
28 import org.mockito.Mockito;
29 import org.mockito.MockitoAnnotations;
30 import org.mockito.runners.MockitoJUnitRunner;
31 import org.onap.optf.cmso.optimizer.availability.policies.model.Policy;
32 import org.onap.optf.cmso.optimizer.availability.policies.model.TimeLimitAndVerticalTopology;
33 import org.springframework.core.env.Environment;
34
35 @RunWith(MockitoJUnitRunner.class)
36 public class PolicyManagerTest
37 {
38
39     @InjectMocks
40     private PolicyManager policyManager;
41
42     @Mock
43     public Environment env;
44
45     @Before
46     public void setUp() {
47         MockitoAnnotations.initMocks(this);
48         Mockito.when(env.getProperty("cmso.local.policy.folder", "data/policies")).thenReturn("data/policies");
49     }
50
51     @Test
52     public void getPolicyByName() {
53         String policyName = "Weekday_00_06";
54
55         String result = "CMSO.Weekday_00_06,";
56         List<Policy> policies = policyManager.getSupportedPolicies();
57         StringBuilder sb = new StringBuilder();
58         for (Policy pol : policies)
59         {
60             sb.append(pol.getPolicyName()).append("," );
61         }
62         System.out.println("        String result = \"" + sb.toString() + "\";");
63         Assert.assertTrue(result.equals(sb.toString()));
64         Policy policy = policyManager.getPolicyForName(policyName);
65         Assert.assertTrue(policy != null);
66         TimeLimitAndVerticalTopology top = policyManager.getTimeLimitAndVerticalTopologyByName(policyName);
67         Assert.assertTrue(top != null);
68
69     }
70 }