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