2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 package org.onap.clamp.clds.client.req;
26 import static org.junit.Assert.assertTrue;
28 import java.lang.reflect.InvocationTargetException;
29 import java.lang.reflect.Method;
30 import java.util.ArrayList;
31 import java.util.List;
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;
39 public class OperationalPolicyReqTest {
42 public void convertToResourceTest() throws NoSuchMethodException, SecurityException, IllegalAccessException,
43 IllegalArgumentException, InvocationTargetException {
44 Method method = OperationalPolicyReq.class.getDeclaredMethod("convertToResource", List.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);
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()));
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);
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));