import java.util.concurrent.TimeoutException;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.InvocationCallback;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.onap.policy.aai.AaiConstants;
import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.Util;
import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperator;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.policy.PolicyResult;
private static final StandardCoder coder = new StandardCoder();
private static final String MY_LINK = "my-link";
- private static final String MY_VSERVER = "my-verserver-name";
+ private static final String MY_VSERVER = "my-vserver-name";
+ private static final String SIM_VSERVER = "OzVServer";
@Captor
private ArgumentCaptor<Entity<Map<String, String>>> entityCaptor;
super(AaiConstants.ACTOR_NAME, AaiCustomQueryOperation.NAME);
}
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ initBeforeClass();
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ destroyAfterClass();
+ }
+
/**
* Sets up.
*/
oper = new AaiCustomQueryOperation(params, config);
}
+ /**
+ * Tests "success" case with simulator.
+ */
+ @Test
+ public void testSuccess() throws Exception {
+ HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/query").build();
+ config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+ preloadTenantData();
+
+ params = params.toBuilder().targetEntity(SIM_VSERVER).retry(0).timeoutSec(5).executor(blockingExecutor).build();
+ oper = new AaiCustomQueryOperation(params, config);
+
+ outcome = oper.start().get();
+ assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ }
+
@Test
- public void testAaiCustomQueryOperation() {
+ public void testConstructor() {
assertEquals(AaiConstants.ACTOR_NAME, oper.getActorName());
assertEquals(AaiCustomQueryOperation.NAME, oper.getName());
assertEquals(MY_VSERVER, oper.getVserver());
private void preloadTenantData(StandardCoderObject data) {
context.setProperty(AaiGetOperation.getTenantKey(MY_VSERVER), data);
+ context.setProperty(AaiGetOperation.getTenantKey(SIM_VSERVER), data);
}
private PolicyResult getResult(CompletableFuture<OperationOutcome> future2)
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import javax.ws.rs.client.InvocationCallback;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.aai.AaiConstants;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
import org.onap.policy.controlloop.policy.PolicyResult;
public class AaiGetOperationTest extends BasicAaiOperation<Void> {
-
private static final String INPUT_FIELD = "input";
private static final String TEXT = "my-text";
super(AaiConstants.ACTOR_NAME, AaiGetOperation.TENANT);
}
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ initBeforeClass();
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ destroyAfterClass();
+ }
+
/**
* Sets up.
*/
oper = new AaiGetOperation(params, config);
}
+ /**
+ * Tests "success" case with simulator.
+ */
+ @Test
+ public void testSuccess() throws Exception {
+ HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/search/nodes-query").build();
+ config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+ params = params.toBuilder().targetEntity("OzVServer").retry(0).timeoutSec(5).executor(blockingExecutor).build();
+ oper = new AaiGetOperation(params, config);
+
+ outcome = oper.start().get();
+ assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ }
+
+ /**
+ * Tests "failure" case with simulator.
+ */
+ @Test
+ public void testFailure() throws Exception {
+ HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/search/nodes-query").build();
+ config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+ params = params.toBuilder().targetEntity("failedVserver").retry(0).timeoutSec(5).executor(blockingExecutor)
+ .build();
+ oper = new AaiGetOperation(params, config);
+
+ outcome = oper.start().get();
+ assertEquals(PolicyResult.FAILURE, outcome.getResult());
+ }
+
@Test
public void testGetRetry() {
// use default if null retry
import static org.junit.Assert.assertEquals;
import java.util.Map;
+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;
/**
* Superclass for various operator tests.
super(actor, operation);
}
+ /**
+ * Starts the simulator.
+ */
+ protected static void initBeforeClass() throws Exception {
+ Util.buildAaiSim();
+
+ BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("aai/")
+ .hostname("localhost").managed(true).port(Util.AAISIM_SERVER_PORT).build();
+ HttpClientFactoryInstance.getClientFactory().build(clientParams);
+ }
+
+ protected static void destroyAfterClass() {
+ HttpClientFactoryInstance.getClientFactory().destroy();
+ HttpServletServerFactoryInstance.getServerFactory().destroy();
+ }
+
protected void verifyHeaders(Map<String, Object> headers) {
assertEquals("POLICY", headers.get("X-FromAppId").toString());
assertEquals(params.getRequestId().toString(), headers.get("X-TransactionId"));
import java.util.Map;
import java.util.TreeMap;
import org.apache.commons.lang3.tuple.Pair;
+import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.appc.CommonHeader;
import org.onap.policy.appc.Request;
public class AppcOperationTest extends BasicAppcOperation {
private AppcOperation oper;
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ // use same topic name for both sides
+ initBeforeClass(MY_SINK, MY_SINK);
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ destroyAfterClass();
+ }
+
/**
* Sets up.
*/
@Before
+ @Override
public void setUp() throws Exception {
super.setUp();
};
}
+ @After
+ @Override
+ public void tearDown() {
+ super.tearDown();
+ }
+
@Test
- public void testAppcOperation() {
+ public void testConstructor() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
assertEquals(DEFAULT_OPERATION, oper.getName());
}
import org.onap.policy.appc.Response;
import org.onap.policy.appc.ResponseCode;
import org.onap.policy.appc.ResponseStatus;
+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.controlloop.actor.test.BasicBidirectionalTopicOperation;
import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.controlloop.policy.Target;
+import org.onap.policy.simulators.AppcLegacyTopicServer;
+import org.onap.policy.simulators.TopicServer;
import org.powermock.reflect.Whitebox;
/**
status.setDescription(MY_DESCRIPTION);
}
+ public void tearDown() {
+ super.tearDownBasic();
+ }
+
+ @SuppressWarnings("rawtypes")
+ protected TopicServer makeServer(TopicSink sink, TopicSource source) {
+ return new AppcLegacyTopicServer(sink, source);
+ }
+
/**
* Runs the operation and verifies that the response is successful.
*
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.lang3.tuple.Pair;
+import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.aai.domain.yang.GenericVnf;
import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams;
import org.onap.policy.controlloop.policy.PolicyResult;
public class ModifyConfigOperationTest extends BasicAppcOperation {
super(DEFAULT_ACTOR, ModifyConfigOperation.NAME);
}
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ // use same topic name for both sides
+ initBeforeClass(MY_SINK, MY_SINK);
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ destroyAfterClass();
+ }
+
@Before
+ @Override
public void setUp() throws Exception {
super.setUp();
oper = new ModifyConfigOperation(params, config);
}
+ @After
+ @Override
+ public void tearDown() {
+ super.tearDown();
+ }
+
+ /**
+ * Tests "success" case with simulator.
+ */
+ @Test
+ public void testSuccess() throws Exception {
+ BidirectionalTopicParams opParams =
+ BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SINK).build();
+ config = new BidirectionalTopicConfig(blockingExecutor, opParams, topicMgr, AppcOperation.SELECTOR_KEYS);
+
+ AaiCqResponse cq = mock(AaiCqResponse.class);
+ GenericVnf genvnf = mock(GenericVnf.class);
+ when(genvnf.getVnfId()).thenReturn(MY_VNF);
+ when(cq.getGenericVnfByModelInvariantId(any())).thenReturn(genvnf);
+
+ params.getContext().setProperty(AaiCqResponse.CONTEXT_KEY, cq);
+
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+
+ oper = new ModifyConfigOperation(params, config) {
+ @Override
+ protected CompletableFuture<OperationOutcome> startGuardAsync() {
+ return null;
+ }
+ };
+
+ outcome = oper.start().get();
+ assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ }
+
@Test
- public void testModifyConfigOperation() {
+ public void testConstructor() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
assertEquals(ModifyConfigOperation.NAME, oper.getName());
}
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.Pair;
+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.actorserviceprovider.OperationOutcome;
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 {
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();
+ }
+
+ @SuppressWarnings("rawtypes")
+ protected TopicServer 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());
+ }
+
@Test
public void testConstructor() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.onap.policy.models.policy-models-interactions</groupId>
+ <artifactId>simulators</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
import java.util.TreeMap;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
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.common.utils.coder.CoderException;
import org.onap.policy.controlloop.actor.test.BasicHttpOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.models.decisions.concepts.DecisionRequest;
import org.onap.policy.models.decisions.concepts.DecisionResponse;
+import org.onap.policy.simulators.GuardSimulatorJaxRs;
public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> {
private GuardConfig guardConfig;
private GuardOperation oper;
+ /**
+ * Starts the simulator.
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ org.onap.policy.simulators.Util.buildGuardSim();
+
+ BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("policy/pdpx/v1/")
+ .hostname("localhost").managed(true).port(org.onap.policy.simulators.Util.GUARDSIM_SERVER_PORT)
+ .build();
+ HttpClientFactoryInstance.getClientFactory().build(clientParams);
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ HttpClientFactoryInstance.getClientFactory().destroy();
+ HttpServletServerFactoryInstance.getServerFactory().destroy();
+ }
+
/**
* Sets up.
*/
oper = new GuardOperation(params, config);
}
+ /**
+ * Tests "success" case with simulator.
+ */
+ @Test
+ public void testSuccess() throws Exception {
+ GuardParams opParams = GuardParams.builder().clientName(MY_CLIENT).path("decision").build();
+ config = new GuardConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+ oper = new GuardOperation(params, config);
+
+ outcome = oper.start().get();
+ assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ }
+
+ /**
+ * Tests "failure" case with simulator.
+ */
+ @Test
+ public void testFailure() throws Exception {
+ GuardParams opParams = GuardParams.builder().clientName(MY_CLIENT).path("decision").build();
+ config = new GuardConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor)
+ .payload(Map.of("clname", GuardSimulatorJaxRs.DENY_CLNAME)).build();
+ oper = new GuardOperation(params, config);
+
+ outcome = oper.start().get();
+ assertEquals(PolicyResult.FAILURE, outcome.getResult());
+ }
+
@Test
public void testConstructor() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
public class BandwidthOnDemandOperation extends SdncOperation {
public static final String NAME = "BandwidthOnDemand";
- public static final String URI = "/GENERIC-RESOURCE-API:vf-module-topology-operation";
-
// fields in the enrichment data
public static final String SERVICE_ID_KEY = "service-instance.service-instance-id";
public static final String VNF_ID = "vnfId";
SdncRequest request = new SdncRequest();
request.setNsInstanceId(serviceInstance);
request.setRequestId(context.getRequestId());
- request.setUrl(URI);
+ request.setUrl("/" + getPath());
SdncHealVnfInfo vnfInfo = new SdncHealVnfInfo();
vnfInfo.setVnfId(context.getEnrichment().get(VNF_ID));
public class RerouteOperation extends SdncOperation {
public static final String NAME = "Reroute";
- public static final String URI = "/GENERIC-RESOURCE-API:network-topology-operation";
-
// fields in the enrichment data
public static final String SERVICE_ID_KEY = "service-instance.service-instance-id";
public static final String NETWORK_ID_KEY = "network-information.network-id";
SdncRequest request = new SdncRequest();
request.setNsInstanceId(serviceInstance);
request.setRequestId(context.getRequestId());
- request.setUrl(URI);
+ request.setUrl("/" + getPath());
SdncHealRequest healRequest = new SdncHealRequest();
healRequest.setRequestHeaderInfo(headerInfo);
Map<String, Object> headers = makeHeaders();
headers.put("Accept", MediaType.APPLICATION_JSON);
- String path = getPath() + request.getUrl();
+ String path = getPath();
String url = getClient().getBaseUrl() + path;
logMessage(EventType.OUT, CommInfrastructure.REST, url, request);
import static org.junit.Assert.assertNotNull;
import java.util.Map;
+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.parameters.HttpConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
+import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.sdnc.SdncRequest;
public class BandwidthOnDemandOperationTest extends BasicSdncOperation {
super(DEFAULT_ACTOR, BandwidthOnDemandOperation.NAME);
}
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ initBeforeClass();
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ destroyAfterClass();
+ }
+
/**
* Set up.
*/
}
@Test
- public void testBandwidthOnDemandOperator() {
+ public void testConstructor() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
assertEquals(BandwidthOnDemandOperation.NAME, oper.getName());
}
+ /**
+ * Tests "success" case with simulator.
+ */
+ @Test
+ public void testSuccess() throws Exception {
+ HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT)
+ .path("GENERIC-RESOURCE-API:vf-module-topology-operation").build();
+ config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+ oper = new BandwidthOnDemandOperation(params, config);
+
+ outcome = oper.start().get();
+ assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ }
+
@Test
public void testMakeRequest() throws Exception {
SdncRequest request = oper.makeRequest(1);
assertEquals("my-service", request.getNsInstanceId());
assertEquals(REQ_ID, request.getRequestId());
- assertEquals(BandwidthOnDemandOperation.URI, request.getUrl());
+ assertEquals("/my-path/", request.getUrl());
assertNotNull(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId());
verifyRequest("bod.json", request, IGNORE_FIELDS);
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
+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.common.utils.coder.StandardCoder;
import org.onap.policy.controlloop.actor.test.BasicHttpOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.sdnc.SdncRequest;
import org.onap.policy.sdnc.SdncResponse;
import org.onap.policy.sdnc.SdncResponseOutput;
+import org.onap.policy.simulators.Util;
import org.powermock.reflect.Whitebox;
/**
super(actor, operation);
}
+ /**
+ * Starts the simulator.
+ */
+ protected static void initBeforeClass() throws Exception {
+ Util.buildSdncSim();
+
+ BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("restconf/operations/")
+ .hostname("localhost").managed(true).port(Util.SDNCSIM_SERVER_PORT).build();
+ HttpClientFactoryInstance.getClientFactory().build(clientParams);
+ }
+
+ protected static void destroyAfterClass() {
+ HttpClientFactoryInstance.getClientFactory().destroy();
+ HttpServletServerFactoryInstance.getServerFactory().destroy();
+ }
+
/**
* Initializes mocks and sets up.
*/
import static org.junit.Assert.assertNotNull;
import java.util.Map;
+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.parameters.HttpConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
+import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.sdnc.SdncRequest;
public class RerouteOperationTest extends BasicSdncOperation {
super(DEFAULT_ACTOR, RerouteOperation.NAME);
}
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ initBeforeClass();
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ destroyAfterClass();
+ }
+
/**
* Set up.
*/
oper = new RerouteOperation(params, config);
}
+ /**
+ * Tests "success" case with simulator.
+ */
+ @Test
+ public void testSuccess() throws Exception {
+ HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT)
+ .path("GENERIC-RESOURCE-API:network-topology-operation").build();
+ config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+ oper = new RerouteOperation(params, config);
+
+ outcome = oper.start().get();
+ assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ }
+
@Test
- public void testRerouteOperator() {
+ public void testConstructor() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
assertEquals(RerouteOperation.NAME, oper.getName());
}
SdncRequest request = oper.makeRequest(1);
assertEquals("my-service", request.getNsInstanceId());
assertEquals(REQ_ID, request.getRequestId());
- assertEquals(RerouteOperation.URI, request.getUrl());
+ assertEquals("/my-path/", request.getUrl());
assertNotNull(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId());
verifyRequest("reroute.json", request, IGNORE_FIELDS);
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.function.BiConsumer;
+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.StandardCoderObject;
import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.sdnr.PciResponse;
import org.onap.policy.sdnr.Status;
import org.onap.policy.sdnr.util.StatusCodeEnum;
+import org.onap.policy.simulators.SdnrTopicServer;
+import org.onap.policy.simulators.TopicServer;
import org.powermock.reflect.Whitebox;
public abstract class BasicSdnrOperation extends BasicBidirectionalTopicOperation {
status.setValue(StatusCodeEnum.SUCCESS.toString());
}
+ public void tearDown() {
+ super.tearDownBasic();
+ }
+
+ @SuppressWarnings("rawtypes")
+ protected TopicServer makeServer(TopicSink sink, TopicSource source) {
+ return new SdnrTopicServer(sink, source);
+ }
+
/**
* Runs the operation and verifies that the response is successful.
*
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.lang3.tuple.Pair;
+import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
+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.sdnr.PciMessage;
super(DEFAULT_ACTOR, ModifyConfigOperation.NAME);
}
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ BasicBidirectionalTopicOperation.initBeforeClass(MY_SINK, MY_SOURCE);
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ destroyAfterClass();
+ }
+
@Before
public void setUp() throws Exception {
super.setUp();
oper = new ModifyConfigOperation(params, config);
}
+ @After
+ @Override
+ public void tearDown() {
+ super.tearDown();
+ }
+
+
+ /**
+ * 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, SdnrOperation.SELECTOR_KEYS);
+
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+
+ oper = new ModifyConfigOperation(params, config) {
+ @Override
+ protected CompletableFuture<OperationOutcome> startGuardAsync() {
+ return null;
+ }
+ };
+
+ outcome = oper.start().get();
+ assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ }
@Test
- public void testModifyConfigOperation() {
+ public void testConstructor() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
assertEquals(ModifyConfigOperation.NAME, oper.getName());
}
import java.util.Arrays;
import org.apache.commons.lang3.tuple.Pair;
+import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation.Status;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.sdnr.PciCommonHeader;
private SdnrOperation operation;
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ BasicBidirectionalTopicOperation.initBeforeClass(MY_SINK, MY_SOURCE);
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ destroyAfterClass();
+ }
+
/**
* Setup.
*/
@Before
+ @Override
public void setUp() throws Exception {
super.setUp();
operation = new SdnrOperation(params, config) {};
}
+ @After
+ @Override
+ public void tearDown() {
+ super.tearDown();
+ }
+
@Test
public void testSdnrOperation() {
assertEquals(DEFAULT_ACTOR, operation.getActorName());
import java.util.Map;
import org.mockito.Mock;
import org.onap.policy.aai.AaiCqResponse;
+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.controlloop.actorserviceprovider.Util;
import org.onap.policy.controlloop.policy.Target;
super(actor, operation);
}
+ /**
+ * Starts the simulator.
+ */
+ protected static void initBeforeClass() throws Exception {
+ org.onap.policy.simulators.Util.buildSoSim();
+
+ BusTopicParams clientParams =
+ BusTopicParams.builder().clientName(MY_CLIENT).basePath("").hostname("localhost")
+ .managed(true).port(org.onap.policy.simulators.Util.SOSIM_SERVER_PORT).build();
+ HttpClientFactoryInstance.getClientFactory().build(clientParams);
+ }
+
+ protected static void destroyAfterClass() {
+ HttpClientFactoryInstance.getClientFactory().destroy();
+ HttpServletServerFactoryInstance.getServerFactory().destroy();
+ }
+
/**
* Initializes mocks and sets up.
*/
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
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.mockito.ArgumentCaptor;
import org.onap.aai.domain.yang.CloudRegion;
import org.onap.aai.domain.yang.ServiceInstance;
import org.onap.aai.domain.yang.Tenant;
import org.onap.policy.aai.AaiCqResponse;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
super(DEFAULT_ACTOR, VfModuleCreate.NAME);
}
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ initBeforeClass();
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ destroyAfterClass();
+ }
@Before
public void setUp() throws Exception {
oper = new VfModuleCreate(params, config);
}
+ /**
+ * Tests "success" case with simulator.
+ */
+ @Test
+ public void testSuccess() throws Exception {
+ SoParams opParams = SoParams.builder().clientName(MY_CLIENT).path("serviceInstantiation/v7/serviceInstances")
+ .pathGet("orchestrationRequests/v5/").build();
+ config = new SoConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+ oper = new VfModuleCreate(params, config);
+
+ outcome = oper.start().get();
+ assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ }
+
@Test
public void testConstructor() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
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.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.onap.aai.domain.yang.ServiceInstance;
import org.onap.aai.domain.yang.Tenant;
import org.onap.policy.aai.AaiCqResponse;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
super(DEFAULT_ACTOR, VfModuleDelete.NAME);
}
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ initBeforeClass();
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ destroyAfterClass();
+ }
/**
* Sets up.
oper = new MyOperation(params, config);
}
+ /**
+ * Tests "success" case with simulator.
+ */
+ @Test
+ public void testSuccess() throws Exception {
+ SoParams opParams = SoParams.builder().clientName(MY_CLIENT).path("serviceInstances/v7")
+ .pathGet("orchestrationRequests/v5/").build();
+ config = new SoConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+ params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+ oper = new VfModuleDelete(params, config);
+
+ outcome = oper.start().get();
+ assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ }
+
@Test
public void testConstructor() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
<artifactId>junit</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.onap.policy.models.policy-models-interactions</groupId>
+ <artifactId>simulators</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.onap.policy.common</groupId>
<artifactId>utils-test</artifactId>
package org.onap.policy.controlloop.actor.test;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
+import java.util.List;
import java.util.function.BiConsumer;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
+import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
+import org.onap.policy.common.endpoints.parameters.TopicParameters;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler;
+import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicManager;
import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder;
+import org.onap.policy.simulators.TopicServer;
+import org.onap.policy.simulators.Util;
/**
* Superclass for various BidirectionalTopicOperation tests.
*/
-public class BasicBidirectionalTopicOperation extends BasicOperation {
+public abstract class BasicBidirectionalTopicOperation extends BasicOperation {
protected static final String MY_SINK = "my-sink";
protected static final String MY_SOURCE = "my-source";
protected static final int TIMEOUT_SEC = 10;
protected static final long TIMEOUT_MS = 1000L * TIMEOUT_SEC;
+ // sink and source used by the TopicServer
+ private static TopicSink serverSink;
+ private static TopicSource serverSource;
+ private static BidirectionalTopicHandler realTopicHandler;
+
+ protected static BidirectionalTopicManager topicMgr = (sink, source) -> {
+ // note: the sink and source names are swapped for the simulator
+ assertEquals(serverSource.getTopic(), sink);
+ assertEquals(serverSink.getTopic(), source);
+ return realTopicHandler;
+ };
+
@Captor
protected ArgumentCaptor<BiConsumer<String, StandardCoderObject>> listenerCaptor;
@Mock
protected BidirectionalTopicConfig config;
+ @SuppressWarnings("rawtypes")
+ private TopicServer topicServer;
+
/**
* Constructs the object using a default actor and operation name.
*/
super(actor, operation);
}
+ /**
+ * Starts the topic.
+ */
+ protected static void initBeforeClass(String sinkTopic, String sourceTopic) throws Exception {
+
+ Util.buildDmaapSim();
+
+ // note: the sink and source names are swapped for the simulator
+ TopicParameters ptopic = new TopicParameters();
+ ptopic.setTopic(sourceTopic);
+ ptopic.setManaged(true);
+ ptopic.setServers(List.of("localhost"));
+ ptopic.setTopicCommInfrastructure("dmaap");
+ ptopic.setFetchTimeout(500);
+ serverSink = TopicEndpointManager.getManager().addTopicSinks(List.of(ptopic)).get(0);
+
+ ptopic.setTopic(sinkTopic);
+ serverSource = TopicEndpointManager.getManager().addTopicSources(List.of(ptopic)).get(0);
+
+ serverSink.start();
+ serverSource.start();
+
+ if (!sinkTopic.equals(sourceTopic)) {
+ // sink and source are different - create other ends for the actor
+ initActorTopics(sinkTopic, sourceTopic, ptopic);
+ }
+
+ realTopicHandler = new BidirectionalTopicHandler(sinkTopic, sourceTopic);
+ realTopicHandler.start();
+ }
+
+ private static void initActorTopics(String sinkTopic, String sourceTopic, TopicParameters ptopic) {
+ // create sink and source for the actor, too
+ ptopic.setTopic(sinkTopic);
+ TopicEndpointManager.getManager().addTopicSinks(List.of(ptopic)).get(0).start();
+
+ ptopic.setTopic(sourceTopic);
+ TopicEndpointManager.getManager().addTopicSources(List.of(ptopic)).get(0).start();
+ }
+
+ protected static void destroyAfterClass() {
+ TopicEndpointManager.getManager().shutdown();
+ HttpServletServerFactoryInstance.getServerFactory().destroy();
+ HttpClientFactoryInstance.getClientFactory().destroy();
+ }
+
/**
* Initializes mocks and sets up.
*/
@Override
public void setUpBasic() {
super.setUpBasic();
+ topicServer = makeServer(serverSink, serverSource);
initConfig();
}
+ public void tearDownBasic() {
+ topicServer.shutdown();
+ }
+
+ /**
+ * Makes a simulator for the given sink and source.
+ *
+ * @param sink topic to which the simulator should publish responses
+ * @param source topic from which the simulator should receive messages
+ * @return a new topic server/simulator
+ */
+ @SuppressWarnings("rawtypes")
+ protected abstract TopicServer makeServer(TopicSink sink, TopicSource source);
+
/**
* Initializes a configuration.
*/
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executor;
import javax.ws.rs.core.Response;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
protected static final String DEFAULT_OPERATION = "default-operation";
protected static final String TARGET_ENTITY = "my-target";
+ protected static final Executor blockingExecutor = command -> {
+ Thread thread = new Thread(command);
+ thread.setDaemon(true);
+ thread.start();
+ };
+
protected final String actorName;
protected final String operationName;
protected Coder coder = new StandardCoder();
import static org.mockito.Mockito.verify;
import java.util.function.BiConsumer;
+import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+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.StandardCoderObject;
+import org.onap.policy.simulators.TopicServer;
public class BasicBidirectionalTopicOperationTest {
private static final String ACTOR = "my-actor";
private BasicBidirectionalTopicOperation oper;
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ BasicBidirectionalTopicOperation.initBeforeClass(BasicBidirectionalTopicOperation.MY_SINK,
+ BasicBidirectionalTopicOperation.MY_SOURCE);
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ BasicBidirectionalTopicOperation.destroyAfterClass();
+ }
/**
* Sets up.
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- oper = new BasicBidirectionalTopicOperation(ACTOR, OPERATION);
+ oper = new MyOperation(ACTOR, OPERATION);
oper.setUpBasic();
}
+ @After
+ public void tearDown() {
+ oper.tearDownBasic();
+ }
+
+ @Test
+ public void testTopicMgr() {
+ assertNotNull(BasicBidirectionalTopicOperation.topicMgr.getTopicHandler(
+ BasicBidirectionalTopicOperation.MY_SINK, BasicBidirectionalTopicOperation.MY_SOURCE));
+ }
+
@Test
public void testBasicBidirectionalTopicOperation() {
- oper = new BasicBidirectionalTopicOperation();
+ oper.tearDownBasic();
+
+ oper = new MyOperation();
+ oper.setUpBasic();
+
assertEquals(BasicOperation.DEFAULT_ACTOR, oper.actorName);
assertEquals(BasicOperation.DEFAULT_OPERATION, oper.operationName);
}
assertThatIllegalArgumentException().isThrownBy(() -> oper.provideResponse(listener, "{invalid json"))
.withMessage("response is not a Map");
}
+
+ private static class MyOperation extends BasicBidirectionalTopicOperation {
+ public MyOperation() {
+ super();
+ }
+
+ /**
+ * Constructs the object.
+ *
+ * @param actor actor name
+ * @param operation operation name
+ */
+ public MyOperation(String actor, String operation) {
+ super(actor, operation);
+ }
+
+ @Override
+ @SuppressWarnings("rawtypes")
+ protected TopicServer makeServer(TopicSink sink, TopicSource source) {
+ return new TopicServer<String>(sink, source, null, String.class) {
+ @Override
+ protected String process(String request) {
+ return null;
+ }
+ };
+ }
+ }
}
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;
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));
}
/**
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);
}
}
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;
super(actor, operation);
}
+ /**
+ * 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.
*/
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.
*/
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());
/**
* setUp.
*/
- @Override
@Before
+ @Override
public void setUp() throws Exception {
super.setUp();
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");
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
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));
}
* Parameters used by Operators that connect to a server via HTTP.
*/
@NotNull
-@NotBlank
@Data
@SuperBuilder(toBuilder = true)
public class HttpParams {
/**
* Name of the HttpClient, as found in the HttpClientFactory.
*/
+ @NotBlank
private String clientName;
/**
testValidateField("timeoutSec", "minimum", bldr -> bldr.timeoutSec(-1));
// check edge cases
+ assertFalse(params.toBuilder().clientName("").build().validate(CONTAINER).isValid());
+
+ assertTrue(params.toBuilder().path("").build().validate(CONTAINER).isValid());
+
assertFalse(params.toBuilder().timeoutSec(0).build().validate(CONTAINER).isValid());
assertTrue(params.toBuilder().timeoutSec(1).build().validate(CONTAINER).isValid());
}
* APPC-LCM topic server.
*/
public class AppcLcmTopicServer extends TopicServer<AppcLcmDmaapWrapper> {
+
public AppcLcmTopicServer(TopicSink sink, TopicSource source) {
super(sink, source, new StandardCoder(), AppcLcmDmaapWrapper.class);
}
* Legacy APPC topic server.
*/
public class AppcLegacyTopicServer extends TopicServer<Request> {
+
public AppcLegacyTopicServer(TopicSink sink, TopicSource source) {
super(sink, source, new StandardCoderInstantAsMillis(), Request.class);
}
* SDNR topic server.
*/
public class SdnrTopicServer extends TopicServer<PciMessage> {
+
public SdnrTopicServer(TopicSink sink, TopicSource source) {
super(sink, source, new StandardCoder(), PciMessage.class);
}