2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.client.policy;
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;
28 import java.util.HashMap;
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;
40 public class PolicyClientImplTest {
43 public static void setUp() {
44 System.setProperty("mso.config.path", "src/test/resources");
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"));
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");
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");
77 public void getDecisionMockTest() {
78 String serviceType = "S";
81 String workStep = "1";
82 String errorCode = "123";
84 PolicyDecision expected = new PolicyDecision();
85 expected.setDecision("PERMIT");
86 expected.setDetails("Retry");
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);
96 doReturn(expected).when(client).getDecision(serviceType, vnfType, bbID, workStep, errorCode);
98 PolicyDecision actual = client.getDecision(serviceType, vnfType, bbID, workStep, errorCode);
99 assertThat(actual, sameBeanAs(expected));
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);