104d40f76e167ea1757262663e14f966ce7bf0e8
[so.git] / common / src / test / java / org / onap / so / client / policy / PolicyClientImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.client.policy;
22
23 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertThat;
26 import static org.mockito.Mockito.doReturn;
27
28 import java.util.HashMap;
29 import java.util.Map;
30
31 import org.junit.BeforeClass;
32 import org.junit.Ignore;
33 import org.junit.Test;
34 import org.mockito.Mockito;
35 import org.onap.so.client.defaultproperties.PolicyRestPropertiesImpl;
36 import org.onap.so.client.policy.entities.DictionaryData;
37 import org.onap.so.client.policy.entities.PolicyDecision;
38 import org.onap.so.client.policy.entities.PolicyServiceType;
39
40 public class PolicyClientImplTest {
41         
42         @BeforeClass
43         public static void setUp() {
44                 System.setProperty("mso.config.path", "src/test/resources");
45         }
46         @Test
47         public void successReadProperties() {
48                 PolicyRestClient client = new PolicyRestClient(new PolicyRestPropertiesImpl(), PolicyServiceType.GET_DECISION);
49                 Map<String, String> map = new HashMap<>();
50                 client.initializeHeaderMap(map);
51                 assertEquals("Found expected Client Auth", "Basic bTAzNzQzOnBvbGljeVIwY2sk", map.get("ClientAuth"));
52                 assertEquals("Found expected Authorization", "Basic dGVzdHBkcDphbHBoYTEyMw==", map.get("Authorization"));
53                 assertEquals("Found expected Environment", "TEST", map.get("Environment"));
54         }
55         
56         @Test
57         @Ignore
58         public void getDecisionTest() {
59                 PolicyClient client = new PolicyClientImpl();
60                 PolicyDecision decision = client.getDecision("S", "V", "BB1", "1", "123");
61                 assertEquals("Decision is correct", decision.getDecision(), "PERMIT");
62                 assertEquals("Decision details is correct", decision.getDetails(), "Retry");
63         }
64         
65         @Test
66         @Ignore
67         public void getAllowedTreatmentsTest(){
68                 PolicyClient client = new PolicyClientImpl();
69                 DictionaryData dictClient = client.getAllowedTreatments("BB1", "1");
70                 final String dictBbidString = dictClient.getBbid().getString();
71                 final String dictWorkStepString = dictClient.getWorkstep().getString();
72                 assertEquals("DictionaryData matches a response Bbid", dictBbidString, "BB1");
73                 assertEquals("DicitonaryData matches a response WorkStep", dictWorkStepString, "1");
74         }
75         
76         @Test
77         public void getDecisionMockTest() {
78                 String serviceType = "S";
79                 String vnfType = "V";
80                 String bbID = "BB1";
81                 String workStep = "1";
82                 String errorCode = "123";
83                 
84                 PolicyDecision expected = new PolicyDecision();
85                 expected.setDecision("PERMIT");
86                 expected.setDetails("Retry");
87                 
88                 DecisionAttributes decisionAttributes = new DecisionAttributes();
89                 decisionAttributes.setServiceType(serviceType);
90                 decisionAttributes.setVNFType(vnfType);
91                 decisionAttributes.setBBID(bbID);
92                 decisionAttributes.setWorkStep(workStep);
93                 decisionAttributes.setErrorCode(errorCode);
94                 PolicyClient client = Mockito.spy(PolicyClientImpl.class);
95                 
96                 doReturn(expected).when(client).getDecision(serviceType, vnfType, bbID, workStep, errorCode);
97
98                 PolicyDecision actual = client.getDecision(serviceType, vnfType, bbID, workStep, errorCode);
99                 assertThat(actual, sameBeanAs(expected));
100         }
101         
102         /*
103         @Test
104         public void getAllowedTreatmentsTest() {
105                 PolicyClient client = new PolicyClientImpl();
106                 AllowedTreatments allowedTreatments = client.getAllowedTreatments("BB1", "1");
107                 int expectedSizeOfList = 4;
108                 int sizeOfList = allowedTreatments.getAllowedTreatments().size();
109                 assertEquals("Decision is correct", sizeOfList, expectedSizeOfList);
110         }*/
111 }