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 * ===================================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
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.policy.asdc.Resource;
35 import org.onap.policy.asdc.ResourceType;
36 import org.onap.policy.controlloop.policy.PolicyResult;
38 public class OperationalPolicyReqTest {
41 public void convertToResourceTest() throws NoSuchMethodException, SecurityException, IllegalAccessException,
42 IllegalArgumentException, InvocationTargetException {
43 Method method = OperationalPolicyReq.class.getDeclaredMethod("convertToResource", List.class,
45 method.setAccessible(true);
46 // return method.invoke(targetObject, argObjects);
47 List<String> stringList = new ArrayList<>();
48 stringList.add("test1");
49 stringList.add("test2");
50 stringList.add("test3");
51 stringList.add("test4");
52 Resource resources[] = (Resource[]) method.invoke(null, stringList, ResourceType.VF);
54 assertTrue(resources.length == 4);
55 assertTrue("test1".equals(resources[0].getResourceName()));
56 assertTrue("test2".equals(resources[1].getResourceName()));
57 assertTrue("test3".equals(resources[2].getResourceName()));
58 assertTrue("test4".equals(resources[3].getResourceName()));
62 public void convertToPolicyResultTest() throws NoSuchMethodException, SecurityException, IllegalAccessException,
63 IllegalArgumentException, InvocationTargetException {
64 Method method = OperationalPolicyReq.class.getDeclaredMethod("convertToPolicyResult", List.class);
65 method.setAccessible(true);
66 // return method.invoke(targetObject, argObjects);
67 List<String> stringList = new ArrayList<>();
68 stringList.add("FAILURE");
69 stringList.add("SUCCESS");
70 stringList.add("FAILURE_GUARD");
71 stringList.add("FAILURE_TIMEOUT");
72 PolicyResult policyResult[] = (PolicyResult[]) method.invoke(null, stringList);
74 assertTrue(policyResult.length == 4);
75 assertTrue(policyResult[0].equals(PolicyResult.FAILURE));
76 assertTrue(policyResult[1].equals(PolicyResult.SUCCESS));
77 assertTrue(policyResult[2].equals(PolicyResult.FAILURE_GUARD));
78 assertTrue(policyResult[3].equals(PolicyResult.FAILURE_TIMEOUT));