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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.controlloop.actor.so;
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;
28 import java.util.UUID;
30 import org.junit.AfterClass;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
34 import org.onap.policy.controlloop.ControlLoopOperation;
35 import org.onap.policy.controlloop.VirtualControlLoopEvent;
36 import org.onap.policy.controlloop.policy.Policy;
37 import org.onap.policy.drools.system.PolicyEngine;
38 import org.onap.policy.simulators.Util;
39 import org.onap.policy.so.SORequest;
41 public class TestSOActorServiceProvider {
44 * Set up for test class.
47 public static void setUpSimulator() {
50 } catch (Exception e) {
56 * Tear down after test class.
59 public static void tearDownSimulator() {
60 HttpServletServer.factory.destroy();
64 public void testConstructRequest() {
65 VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
66 final ControlLoopOperation operation = new ControlLoopOperation();
68 final UUID requestId = UUID.randomUUID();
69 onset.setRequestId(requestId);
71 PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
72 PolicyEngine.manager.setEnvironmentProperty("aai.username", "AAI");
73 PolicyEngine.manager.setEnvironmentProperty("aai.password", "AAI");
75 Policy policy = new Policy();
76 policy.setActor("Dorothy");
77 policy.setRecipe("GoToOz");
78 assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
80 policy.setActor("SO");
81 assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
83 policy.setRecipe("VF Module Create");
84 assertNotNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
86 PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:999999");
87 assertNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
89 PolicyEngine.manager.setEnvironmentProperty("aai.url", "http://localhost:6666");
90 assertNotNull(new SOActorServiceProvider().constructRequest(onset, operation, policy));
92 SORequest request = new SOActorServiceProvider().constructRequest(onset, operation, policy);
94 assertEquals("policy", request.getRequestDetails().getRequestInfo().getRequestorId());
95 assertEquals("RegionOne", request.getRequestDetails().getCloudConfiguration().getLcpCloudRegionId());
99 public void testSendRequest() {
101 SOActorServiceProvider.sendRequest(UUID.randomUUID().toString(), null, null);
102 } catch (Exception e) {
103 fail("Test should not throw an exception");
108 public void testMethods() {
109 SOActorServiceProvider sp = new SOActorServiceProvider();
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());