package org.onap.policy.controlloop.actor.appclcm;
+import static org.assertj.core.api.Assertions.assertThat;
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.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
+import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.appclcm.AppcLcmBody;
import org.onap.policy.appclcm.AppcLcmCommonHeader;
import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
import org.onap.policy.appclcm.AppcLcmOutput;
import org.onap.policy.appclcm.AppcLcmResponseStatus;
+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.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation.Status;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.controlloop.policy.Target;
+import org.onap.policy.simulators.AppcLcmTopicServer;
+import org.onap.policy.simulators.TopicServer;
-public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation {
+public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation<AppcLcmDmaapWrapper> {
private static final String EXPECTED_EXCEPTION = "expected exception";
private static final String PAYLOAD_KEY1 = "key-A";
private AppcLcmDmaapWrapper response;
private AppcLcmOperation oper;
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ initBeforeClass(MY_SINK, MY_SOURCE);
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ destroyAfterClass();
+ }
+
/**
* Sets up.
*/
oper = new AppcLcmOperation(params, config);
}
+ @After
+ public void tearDown() {
+ super.tearDownBasic();
+ }
+
+ protected TopicServer<AppcLcmDmaapWrapper> makeServer(TopicSink sink, TopicSource source) {
+ return new AppcLcmTopicServer(sink, source);
+ }
+
+ /**
+ * Tests "success" case with simulator.
+ */
+ @Test
+ public void testSuccess() throws Exception {
+ BidirectionalTopicParams opParams =
+ BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SOURCE).build();
+ config = new BidirectionalTopicConfig(blockingExecutor, opParams, topicMgr, AppcLcmOperation.SELECTOR_KEYS);
+
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+
+ oper = new AppcLcmOperation(params, config) {
+ @Override
+ protected CompletableFuture<OperationOutcome> startGuardAsync() {
+ return null;
+ }
+ };
+
+ outcome = oper.start().get();
+ assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertTrue(outcome.getResponse() instanceof AppcLcmDmaapWrapper);
+ }
+
@Test
public void testConstructor() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
assertEquals(DEFAULT_OPERATION, oper.getName());
+ }
- // missing target entity
- params = params.toBuilder().targetEntity("").build();
- assertThatIllegalArgumentException().isThrownBy(() -> new AppcLcmOperation(params, config))
- .withMessage("missing targetEntity");
+ @Test
+ public void testGetPropertyNames() {
+ assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.AAI_TARGET_ENTITY));
}
@Test
assertTrue(executor.runAll(100));
assertTrue(future2.isDone());
- assertEquals(PolicyResult.SUCCESS, future2.get().getResult());
+ outcome = future2.get();
+ assertEquals(PolicyResult.SUCCESS, outcome.getResult());
}
@Test
public void testMakeRequest() {
+ oper.generateSubRequestId(2);
+ String subreq = oper.getSubRequestId();
+ assertNotNull(subreq);
+
AppcLcmDmaapWrapper request = oper.makeRequest(2);
assertEquals("DefaultOperation", request.getBody().getInput().getAction());
assertNotNull(header);
assertEquals(params.getRequestId(), header.getRequestId());
- String subreq = header.getSubRequestId();
- assertNotNull(subreq);
+ assertEquals(subreq, header.getSubRequestId());
assertEquals("{vnf-id=my-target}", request.getBody().getInput().getActionIdentifiers().toString());
- // a subsequent request should have a different sub-request id
- assertNotEquals(subreq, oper.makeRequest(2).getBody().getInput().getCommonHeader().getSubRequestId());
+ request = oper.makeRequest(2);
+ assertEquals(subreq, request.getBody().getInput().getCommonHeader().getSubRequestId());
}
@Test
params = params.toBuilder().operation(AppcLcmConstants.OPERATION_CONFIG_MODIFY).build();
oper = new AppcLcmOperation(params, config);
+ oper.generateSubRequestId(2);
AppcLcmDmaapWrapper req = oper.makeRequest(2);
assertEquals("{\"key-A\":\"value-A\"}", req.getBody().getInput().getPayload());
// coder exception
oper = new AppcLcmOperation(params, config) {
@Override
- protected Coder makeCoder() {
+ protected Coder getCoder() {
return new StandardCoder() {
@Override
public String encode(Object object) throws CoderException {
}
};
+ oper.generateSubRequestId(2);
+
assertThatIllegalArgumentException().isThrownBy(() -> oper.makeRequest(2))
.withMessage("Cannot convert payload");
}
@Test
public void testGetExpectedKeyValues() {
+ oper.generateSubRequestId(2);
AppcLcmDmaapWrapper request = oper.makeRequest(2);
assertEquals(Arrays.asList(request.getBody().getInput().getCommonHeader().getSubRequestId()),
oper.getExpectedKeyValues(50, request));
oper.setOutcome(outcome, PolicyResult.SUCCESS, response);
assertEquals(PolicyResult.SUCCESS, outcome.getResult());
assertEquals(MY_MESSAGE, outcome.getMessage());
+ assertSame(response, outcome.getResponse());
// failure
oper.setOutcome(outcome, PolicyResult.FAILURE, response);
assertEquals(PolicyResult.FAILURE, outcome.getResult());
assertEquals(MY_MESSAGE, outcome.getMessage());
+ assertSame(response, outcome.getResponse());
// null message
response.getBody().getOutput().getStatus().setMessage(null);
oper.setOutcome(outcome, PolicyResult.SUCCESS, response);
assertEquals(ControlLoopOperation.SUCCESS_MSG, outcome.getMessage());
+ assertSame(response, outcome.getResponse());
// null status
response.getBody().getOutput().setStatus(null);
oper.setOutcome(outcome, PolicyResult.SUCCESS, response);
assertEquals(ControlLoopOperation.SUCCESS_MSG, outcome.getMessage());
+ assertSame(response, outcome.getResponse());
}
@Test