9b8f4aad39e1d465d7b1c590ad524e9b7f22a99a
[clamp.git] / src / test / java / org / onap / clamp / clds / client / req / OperationalPolicyReqTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23
24 package org.onap.clamp.clds.client.req;
25
26 import static org.junit.Assert.assertTrue;
27
28 import java.lang.reflect.InvocationTargetException;
29 import java.lang.reflect.Method;
30 import java.util.ArrayList;
31 import java.util.List;
32
33 import org.junit.Test;
34 import org.onap.clamp.clds.client.req.policy.OperationalPolicyReq;
35 import org.onap.policy.controlloop.policy.PolicyResult;
36 import org.onap.policy.sdc.Resource;
37 import org.onap.policy.sdc.ResourceType;
38
39 public class OperationalPolicyReqTest {
40
41     @Test
42     public void convertToResourceTest() throws NoSuchMethodException, SecurityException, IllegalAccessException,
43             IllegalArgumentException, InvocationTargetException {
44         Method method = OperationalPolicyReq.class.getDeclaredMethod("convertToResource", List.class,
45                 ResourceType.class);
46         method.setAccessible(true);
47         // return method.invoke(targetObject, argObjects);
48         List<String> stringList = new ArrayList<>();
49         stringList.add("test1");
50         stringList.add("test2");
51         stringList.add("test3");
52         stringList.add("test4");
53         Resource[] resources = (Resource[]) method.invoke(null, stringList, ResourceType.VF);
54
55         assertTrue(resources.length == 4);
56         assertTrue("test1".equals(resources[0].getResourceName()));
57         assertTrue("test2".equals(resources[1].getResourceName()));
58         assertTrue("test3".equals(resources[2].getResourceName()));
59         assertTrue("test4".equals(resources[3].getResourceName()));
60     }
61
62     @Test
63     public void convertToPolicyResultTest() throws NoSuchMethodException, SecurityException, IllegalAccessException,
64             IllegalArgumentException, InvocationTargetException {
65         Method method = OperationalPolicyReq.class.getDeclaredMethod("convertToPolicyResult", List.class);
66         method.setAccessible(true);
67         // return method.invoke(targetObject, argObjects);
68         List<String> stringList = new ArrayList<>();
69         stringList.add("FAILURE");
70         stringList.add("SUCCESS");
71         stringList.add("FAILURE_GUARD");
72         stringList.add("FAILURE_TIMEOUT");
73         PolicyResult[] policyResult = (PolicyResult[]) method.invoke(null, stringList);
74
75         assertTrue(policyResult.length == 4);
76         assertTrue(policyResult[0].equals(PolicyResult.FAILURE));
77         assertTrue(policyResult[1].equals(PolicyResult.SUCCESS));
78         assertTrue(policyResult[2].equals(PolicyResult.FAILURE_GUARD));
79         assertTrue(policyResult[3].equals(PolicyResult.FAILURE_TIMEOUT));
80     }
81 }