summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.vfc/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-03-27 12:35:23 -0400
committerJim Hahn <jrh3@att.com>2020-03-30 09:01:15 -0400
commit61a84fecc1eae8640fec2860f4b50102ed0baa64 (patch)
tree32ba4cf68bd9f6c4f97e92f665ab2de7ad788dc6 /models-interactions/model-actors/actor.vfc/src
parent3a374cbc9f4bef8856c3e78be1a6b4c5274cd744 (diff)
Test new actors against simulators
Also modified HttpParams to allow "path" to be blank to support any cases that really have no "path" to append to the context URI base path. Issue-ID: POLICY-2405 Change-Id: I49eebde6759659d2804b5a11c1504c37674bd0c4 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.vfc/src')
-rw-r--r--models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/Restart.java8
-rw-r--r--models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/BasicVfcOperation.java20
-rw-r--r--models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/RestartTest.java31
-rw-r--r--models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java19
4 files changed, 67 insertions, 11 deletions
diff --git a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/Restart.java b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/Restart.java
index 2c5cf8eda..e3df16d9b 100644
--- a/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/Restart.java
+++ b/models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/Restart.java
@@ -20,6 +20,7 @@
package org.onap.policy.controlloop.actor.vfc;
+import java.util.Map;
import java.util.concurrent.CompletableFuture;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
@@ -47,7 +48,10 @@ public class Restart extends VfcOperation {
String path = getPath() + pair.getLeft();
String url = getClient().getBaseUrl() + path;
- return handleResponse(outcome, url, callback -> getClient().post(callback, path, entity, null));
+ Map<String, Object> headers = makeHeaders();
+ headers.put("Accept", MediaType.APPLICATION_JSON);
+
+ return handleResponse(outcome, url, callback -> getClient().post(callback, path, entity, headers));
}
/**
@@ -58,7 +62,7 @@ public class Restart extends VfcOperation {
protected Pair<String, VfcRequest> makeRequest() {
VfcRequest request = super.constructVfcRequest();
- String requestUrl = "/ns/" + request.getNsInstanceId() + "/heal";
+ String requestUrl = "/" + request.getNsInstanceId() + "/heal";
return Pair.of(requestUrl, request);
}
}
diff --git a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/BasicVfcOperation.java b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/BasicVfcOperation.java
index be62bbb3f..47371d2b3 100644
--- a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/BasicVfcOperation.java
+++ b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/BasicVfcOperation.java
@@ -23,7 +23,11 @@ package org.onap.policy.controlloop.actor.vfc;
import static org.mockito.Mockito.when;
import org.mockito.Mock;
+import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
import org.onap.policy.controlloop.actor.test.BasicHttpOperation;
+import org.onap.policy.simulators.Util;
import org.onap.policy.vfc.VfcRequest;
import org.onap.policy.vfc.VfcResponse;
@@ -55,6 +59,22 @@ public abstract class BasicVfcOperation extends BasicHttpOperation<VfcRequest> {
}
/**
+ * Starts the simulator.
+ */
+ protected static void initBeforeClass() throws Exception {
+ Util.buildVfcSim();
+
+ BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("api/nslcm/v1/")
+ .hostname("localhost").managed(true).port(Util.VFCSIM_SERVER_PORT).build();
+ HttpClientFactoryInstance.getClientFactory().build(clientParams);
+ }
+
+ protected static void destroyAfterClass() {
+ HttpClientFactoryInstance.getClientFactory().destroy();
+ HttpServletServerFactoryInstance.getServerFactory().destroy();
+ }
+
+ /**
* Initializes mocks and sets up.
*/
public void setUp() throws Exception {
diff --git a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/RestartTest.java b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/RestartTest.java
index dd6c4cf69..5fe4973ce 100644
--- a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/RestartTest.java
+++ b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/RestartTest.java
@@ -25,14 +25,28 @@ import static org.junit.Assert.assertNotNull;
import java.util.concurrent.CompletableFuture;
import org.apache.commons.lang3.tuple.Pair;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.vfc.VfcRequest;
public class RestartTest extends BasicVfcOperation {
private Restart restartOper;
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ initBeforeClass();
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ destroyAfterClass();
+ }
+
/**
* setup restart operation.
*/
@@ -45,8 +59,23 @@ public class RestartTest extends BasicVfcOperation {
restartOper = new Restart(params, config);
}
+ /**
+ * Tests "success" case with simulator.
+ */
+ @Test
+ public void testSuccess() throws Exception {
+ VfcParams opParams = VfcParams.builder().clientName(MY_CLIENT).path("ns").pathGet("jobs").maxGets(1).build();
+ config = new VfcConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+ restartOper = new Restart(params, config);
+
+ outcome = restartOper.start().get();
+ assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ }
+
@Test
- public void testStartOperationAsync() {
+ public void testConstructor() {
CompletableFuture<OperationOutcome> futureRes = restartOper.startOperationAsync(1, outcome);
assertNotNull(futureRes);
assertEquals(0, restartOper.getGetCount());
diff --git a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java
index 4fe0cd4a6..4d98b97c9 100644
--- a/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java
+++ b/models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java
@@ -44,8 +44,8 @@ public class VfcOperationTest extends BasicVfcOperation {
/**
* setUp.
*/
- @Override
@Before
+ @Override
public void setUp() throws Exception {
super.setUp();
@@ -84,7 +84,7 @@ public class VfcOperationTest extends BasicVfcOperation {
response.setJobId("sampleJobId");
CompletableFuture<OperationOutcome> future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
assertFalse(future2.isDone());
- //assertSame(outcome, future2.get()); TODO Hanging
+ // assertSame(outcome, future2.get()); TODO Hanging
assertEquals(PolicyResult.SUCCESS, outcome.getResult());
response.getResponseDescriptor().setStatus("FinisHeD");
@@ -100,11 +100,12 @@ public class VfcOperationTest extends BasicVfcOperation {
assertEquals(PolicyResult.FAILURE, outcome.getResult());
// failed
- /*response.getResponseDescriptor().setStatus("anything but finished");
- future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
- assertTrue(future2.isDone());
- assertSame(outcome, future2.get());
- assertEquals(PolicyResult.FAILURE, outcome.getResult());*/
+ /*
+ * response.getResponseDescriptor().setStatus("anything but finished"); future2 =
+ * oper.postProcessResponse(outcome, PATH, rawResponse, response);
+ * assertTrue(future2.isDone()); assertSame(outcome, future2.get());
+ * assertEquals(PolicyResult.FAILURE, outcome.getResult());
+ */
}
@Test
@@ -115,7 +116,9 @@ public class VfcOperationTest extends BasicVfcOperation {
VfcResponseDescriptor mockDescriptor = Mockito.mock(VfcResponseDescriptor.class);
Mockito.when(mockResponse.getResponseDescriptor()).thenReturn(mockDescriptor);
- Mockito.when(mockDescriptor.getStatus()).thenReturn("COMPLETE"); // TODO use actual request state value
+
+ // TODO use actual request state value
+ Mockito.when(mockDescriptor.getStatus()).thenReturn("COMPLETE");
assertNotNull(oper.getRequestState(mockResponse));
}