package org.onap.policy.controlloop.actor.appc;
-import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.function.BiConsumer;
-import java.util.function.BiFunction;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.policy.appc.Request;
import org.onap.policy.appc.Response;
import org.onap.policy.appc.ResponseCode;
import org.onap.policy.appc.ResponseStatus;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.common.utils.coder.StandardCoderInstantAsMillis;
import org.onap.policy.common.utils.coder.StandardCoderObject;
-import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.actorserviceprovider.Util;
-import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperator;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.controlloop.policy.Target;
-import org.powermock.reflect.Whitebox;
+import org.onap.policy.simulators.AppcLegacyTopicServer;
+import org.onap.policy.simulators.TopicServer;
/**
* Superclass for various operator tests.
*/
-public abstract class BasicAppcOperation extends BasicBidirectionalTopicOperation {
+public abstract class BasicAppcOperation extends BasicBidirectionalTopicOperation<Request> {
+ protected static final String[] IGNORE_FIELDS = {"RequestID", "subRequestID", "TimeStamp"};
protected static final String MY_DESCRIPTION = "my-description";
protected static final String MY_VNF = "my-vnf";
protected static final String KEY1 = "my-key-A";
protected static final String KEY2 = "my-key-B";
+ protected static final String KEY3 = "my-key-C";
protected static final String VALUE1 = "{\"input\":\"hello\"}";
protected static final String VALUE2 = "{\"output\":\"world\"}";
protected static final String RESOURCE_ID = "my-resource";
protected Response response;
+ protected GenericVnf genvnf;
/**
* Constructs the object using a default actor and operation name.
*/
public BasicAppcOperation() {
- super();
+ this.coder = new StandardCoderInstantAsMillis();
}
/**
*/
public BasicAppcOperation(String actor, String operation) {
super(actor, operation);
+ this.coder = new StandardCoderInstantAsMillis();
}
/**
* Initializes mocks and sets up.
*/
public void setUp() throws Exception {
- super.setUp();
+ super.setUpBasic();
response = new Response();
response.setStatus(status);
status.setCode(ResponseCode.SUCCESS.getValue());
status.setDescription(MY_DESCRIPTION);
+
+ genvnf = new GenericVnf();
+ genvnf.setVnfId(MY_VNF);
+ }
+
+ public void tearDown() {
+ super.tearDownBasic();
+ }
+
+ @Override
+ protected TopicServer<Request> makeServer(TopicSink sink, TopicSource source) {
+ return new AppcLegacyTopicServer(sink, source);
}
/**
assertTrue(future2.isDone());
outcome = future2.get();
- assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertEquals(OperationResult.SUCCESS, outcome.getResult());
assertEquals(MY_DESCRIPTION, outcome.getMessage());
}
- /**
- * Pretty-prints a request and verifies that the result matches the expected JSON.
- *
- * @param <T> request type
- * @param expectedJsonFile name of the file containing the expected JSON
- * @param request request to verify
- * @throws CoderException if the request cannot be pretty-printed
- */
- protected <T> void verifyRequest(String expectedJsonFile, T request) throws CoderException {
- String json = new StandardCoder().encode(request, true);
- String expected = ResourceUtils.getResourceAsString(expectedJsonFile);
-
- // strip request id, because it changes each time
- final String stripper = "svc-request-id[^,]*";
- json = json.replaceFirst(stripper, "").trim();
- expected = expected.replaceFirst(stripper, "").trim();
-
- assertEquals(expected, json);
- }
-
- /**
- * Verifies that an exception is thrown if a field is missing from the enrichment
- * data.
- *
- * @param fieldName name of the field to be removed from the enrichment data
- * @param expectedText text expected in the exception message
- */
- protected void verifyMissing(String fieldName, String expectedText,
- BiFunction<ControlLoopOperationParams, BidirectionalTopicOperator, AppcOperation> maker) {
-
- makeContext();
- enrichment.remove(fieldName);
-
- AppcOperation oper = maker.apply(params, operator);
-
- assertThatIllegalArgumentException().isThrownBy(() -> Whitebox.invokeMethod(oper, "makeRequest", 1))
- .withMessageContaining("missing").withMessageContaining(expectedText);
- }
-
@Override
protected void makeContext() {
super.makeContext();
- Target target = new Target();
- target.setResourceID(RESOURCE_ID);
+ Map<String, String> entities = Map.of(ControlLoopOperationParams.PARAMS_ENTITY_RESOURCEID, RESOURCE_ID);
- params = params.toBuilder().target(target).build();
+ params = params.toBuilder().targetEntityIds(entities).build();
}
/**
}
@Override
- protected Map<String, String> makePayload() {
+ protected Map<String, Object> makePayload() {
return Map.of(KEY1, VALUE1, KEY2, VALUE2);
}
}