import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.UUID;
-
+import org.apache.commons.io.IOUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.onap.policy.aai.AaiGetVnfResponse;
-import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.aai.AaiCqResponse;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.policy.Policy;
public class VfcActorServiceProviderTest {
+ private static final String DOROTHY_GALE_1939 = "dorothy.gale.1939";
+ private static final String CQ_RESPONSE_JSON = "aai/AaiCqResponse.json";
+ private static final String RESTART = "Restart";
+
/**
- * Set up for test class.
+ * Set up before test class.
+ * @throws Exception if the A&AI simulator cannot be started
*/
@BeforeClass
- public static void setUpSimulator() {
- try {
- Util.buildAaiSim();
- } catch (Exception e) {
- fail(e.getMessage());
- }
+ public static void setUpSimulator() throws Exception {
+ Util.buildAaiSim();
}
@AfterClass
public static void tearDownSimulator() {
- HttpServletServer.factory.destroy();
+ HttpServletServerFactoryInstance.getServerFactory().destroy();
+ }
+
+ @Test
+ public void testMethods() {
+ VfcActorServiceProvider sp = new VfcActorServiceProvider();
+
+ assertEquals("VFC", sp.actor());
+ assertEquals(1, sp.recipes().size());
+ assertEquals(RESTART, sp.recipes().get(0));
+ assertEquals("VM", sp.recipeTargets(RESTART).get(0));
+ assertEquals(0, sp.recipePayloads(RESTART).size());
}
@Test
- public void testConstructRequest() {
+ public void testConstructRequestCq() throws IOException {
VirtualControlLoopEvent onset = new VirtualControlLoopEvent();
ControlLoopOperation operation = new ControlLoopOperation();
Policy policy = new Policy();
policy.setRecipe("GoToOz");
- assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null, null, null, null));
+ assertNull(VfcActorServiceProvider.constructRequestCq(onset, operation, policy, null));
- onset.getAai().put("generic-vnf.vnf-id", "dorothy.gale.1939");
- assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null, null, null, null));
+ onset.getAai().put("generic-vnf.vnf-id", DOROTHY_GALE_1939);
+ assertNull(VfcActorServiceProvider.constructRequestCq(onset, operation, policy, null));
- assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null, "http://localhost:6666", "AAI", "AAI"));
UUID requestId = UUID.randomUUID();
onset.setRequestId(requestId);
- assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null, "http://localhost:6666", "AAI", "AAI"));
+ assertNull(VfcActorServiceProvider.constructRequestCq(onset, operation, policy, null));
onset.getAai().put("generic-vnf.vnf-name", "Dorothy");
- assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null, "http://localhost:6666", "AAI", null));
+ assertNull(VfcActorServiceProvider.constructRequestCq(onset, operation, policy, null));
- assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null, "http://localhost:6666", "AAI", "AAI"));
onset.getAai().put("service-instance.service-instance-id", "");
- assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, null, "http://localhost:6666", "AAI", "AAI"));
+ assertNull(VfcActorServiceProvider.constructRequestCq(onset, operation, policy, null));
- assertNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse(), "http://localhost:6666", "AAI", "AAI"));
+ assertNull(VfcActorServiceProvider.constructRequestCq(onset, operation, policy,
+ loadAaiResponse(CQ_RESPONSE_JSON)));
- policy.setRecipe("Restart");
- assertNotNull(VfcActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse(), "http://localhost:6666", "AAI", "AAI"));
+ policy.setRecipe(RESTART);
+ assertNotNull(VfcActorServiceProvider.constructRequestCq(onset, operation, policy,
+ loadAaiResponse(CQ_RESPONSE_JSON)));
- VfcRequest request =
- VfcActorServiceProvider.constructRequest(onset, operation, policy, new AaiGetVnfResponse(), "http://localhost:6666", "AAI", "AAI");
+ VfcRequest request = VfcActorServiceProvider.constructRequestCq(onset, operation, policy,
+ loadAaiResponse(CQ_RESPONSE_JSON));
assertEquals(requestId, Objects.requireNonNull(request).getRequestId());
- assertEquals("dorothy.gale.1939", request.getHealRequest().getVnfInstanceId());
+ assertEquals(DOROTHY_GALE_1939, request.getHealRequest().getVnfInstanceId());
assertEquals("restartvm", request.getHealRequest().getAdditionalParams().getAction());
}
- @Test
- public void testMethods() {
- VfcActorServiceProvider sp = new VfcActorServiceProvider();
-
- assertEquals("VFC", sp.actor());
- assertEquals(1, sp.recipes().size());
- assertEquals("Restart", sp.recipes().get(0));
- assertEquals("VM", sp.recipeTargets("Restart").get(0));
- assertEquals(0, sp.recipePayloads("Restart").size());
+ /**
+ * Reads an AAI vserver named-query response from a file.
+ *
+ * @param fileName name of the file containing the JSON response
+ * @return output from the AAI vserver named-query
+ * @throws IOException if the file cannot be read
+ */
+ private AaiCqResponse loadAaiResponse(String fileName) throws IOException {
+ String resp = IOUtils.toString(getClass().getResource(fileName), StandardCharsets.UTF_8);
+ return new AaiCqResponse(resp);
}
+
}