5d2134ec1daf421b3b03a4714506cd261309eec9
[policy/drools-applications.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * TestSOActorServiceProvider
4  * ================================================================================
5  * Copyright (C) 2018 Ericsson. 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.policy.controlloop.actor.so;
22
23 import static org.junit.Assert.*;
24
25 import java.util.UUID;
26
27 import org.junit.AfterClass;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.onap.policy.controlloop.ControlLoopOperation;
31 import org.onap.policy.controlloop.VirtualControlLoopEvent;
32 import org.onap.policy.controlloop.policy.Policy;
33 import org.onap.policy.drools.http.server.HttpServletServer;
34 import org.onap.policy.drools.system.PolicyEngine;
35 import org.onap.policy.simulators.Util;
36 import org.onap.policy.so.SORequest;
37
38 public class TestSOActorServiceProvider {
39         @BeforeClass
40         public static void setUpSimulator() {
41                 try {
42                         Util.buildAaiSim();
43                 } catch (Exception e) {
44                         fail(e.getMessage());
45                 }
46         }
47
48         @AfterClass
49         public static void tearDownSimulator() {
50                 HttpServletServer.factory.destroy();
51         }
52
53         @Test
54         public void testConstructRequest() {
55                 VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
56                 ControlLoopOperation operation = new ControlLoopOperation();
57
58                 UUID requestID = UUID.randomUUID();
59                 onset.setRequestID(requestID);
60
61                 PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
62                 PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
63                 PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
64
65                 Policy policy = new Policy();
66                 policy.setActor("Dorothy");
67                 policy.setRecipe("GoToOz");
68                 assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
69
70                 policy.setActor("SO");
71                 assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
72
73                 policy.setRecipe("VF Module Create");
74                 assertNotNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
75
76                 PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:999999");
77                 assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
78
79                 PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
80                 assertNotNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
81
82                 SORequest request = new SOActorServiceProvider().constructRequest(onset, operation, policy);
83
84                 assertEquals(requestID, request.getRequestId());
85                 assertEquals("policy", request.getRequestDetails().getRequestInfo().getRequestorId());
86                 assertEquals("RegionOne", request.getRequestDetails().getCloudConfiguration().getLcpCloudRegionId());
87         }
88
89         @Test
90         public void testSendRequest() {
91                 try {
92                         SOActorServiceProvider.sendRequest(UUID.randomUUID().toString(), null, null);
93                 }
94                 catch (Exception e) {
95                         fail("Test should not throw an exception");
96                 }
97         }
98
99         @Test
100         public void testMethods() {
101                 SOActorServiceProvider sp = new SOActorServiceProvider();
102
103                 assertEquals("SO", sp.actor());
104                 assertEquals(1, sp.recipes().size());
105                 assertEquals("VF Module Create", sp.recipes().get(0));
106                 assertEquals(0, sp.recipePayloads("VF Module Create").size());
107         }
108 }