package org.onap.policy.controlloop.actor.so;
+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.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import java.net.http.HttpResponse.BodyHandlers;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ForkJoinPool;
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;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpPollingParams;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.so.SoRequest;
import org.onap.policy.so.SoResponse;
*/
@Test
public void testSuccess() throws Exception {
- SoParams opParams = SoParams.builder().clientName(MY_CLIENT).path("serviceInstances/v7")
- .pathGet("orchestrationRequests/v5/").maxGets(2).build();
- config = new SoConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+ HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT).path("serviceInstances/v7")
+ .pollPath("orchestrationRequests/v5/").maxPolls(2).build();
+ config = new HttpPollingConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+
oper = new VfModuleDelete(params, config);
outcome = oper.start().get();
// verify that target validation is done
params = params.toBuilder().target(null).build();
- assertThatIllegalArgumentException().isThrownBy(() -> new VfModuleDelete(params, config))
+ assertThatIllegalArgumentException().isThrownBy(() -> new MyOperation(params, config))
.withMessageContaining("Target information");
}
+ @Test
+ public void testGetPropertyNames() {
+ // @formatter:off
+ assertThat(oper.getPropertyNames()).isEqualTo(
+ List.of(
+ OperationProperties.AAI_MODEL_SERVICE,
+ OperationProperties.AAI_MODEL_VNF,
+ OperationProperties.AAI_MODEL_CLOUD_REGION,
+ OperationProperties.AAI_MODEL_TENANT,
+ OperationProperties.DATA_VF_COUNT));
+ // @formatter:on
+ }
+
@Test
public void testStartPreprocessorAsync() throws Exception {
// insert CQ data so it's there for the check
assertTrue(guardStarted.get());
}
+ /**
+ * Tests startPreprocessorAsync(), when preprocessing is disabled.
+ */
+ @Test
+ public void testStartPreprocessorAsyncDisabled() {
+ params = params.toBuilder().preprocessed(true).build();
+ assertNull(new MyOperation(params, config).startPreprocessorAsync());
+ }
+
@Test
public void testStartGuardAsync() throws Exception {
// remove CQ data so it's forced to query
oper = new MyOperation(params, config) {
@Override
- public long getWaitMsGet() {
+ public long getPollWaitMs() {
return 1;
}
};
}
/**
- * Tests startOperationAsync() when "get" operations are required.
+ * Tests startOperationAsync() when polling is required.
*/
@Test
- public void testStartOperationAsyncWithGets() throws Exception {
+ public void testStartOperationAsyncWithPolling() throws Exception {
// indicate that the response was incomplete
configureResponse(coder.encode(response).replace("COMPLETE", "incomplete"));
oper = new MyOperation(params, config) {
@Override
- public long getWaitMsGet() {
+ public long getPollWaitMs() {
return 1;
}
};
Map<String, Object> headers = Map.of("key-A", "value-A");
+ String reqText = oper.prettyPrint(req);
+
final CompletableFuture<Response> delFuture =
- oper.delete("my-uri", headers, MediaType.APPLICATION_JSON, req, callback);
+ oper.delete("my-uri", headers, MediaType.APPLICATION_JSON, reqText, callback);
ArgumentCaptor<HttpRequest> reqCaptor = ArgumentCaptor.forClass(HttpRequest.class);
verify(javaClient).sendAsync(reqCaptor.capture(), any());
SoRequest req = new SoRequest();
req.setRequestId(REQ_ID);
+ String reqText = oper.prettyPrint(req);
+
CompletableFuture<Response> delFuture =
- oper.delete("/my-uri", Map.of(), MediaType.APPLICATION_JSON, req, callback);
+ oper.delete("/my-uri", Map.of(), MediaType.APPLICATION_JSON, reqText, callback);
assertTrue(delFuture.isCompletedExceptionally());
assertSame(thrown, thrownCaptor.getValue().getCause());
}
- @Test
- public void testEncodeBody() {
- // try when request is already a string
- assertEquals("hello", oper.encodeRequest("hello"));
-
- // try with a real request
- SoRequest req = new SoRequest();
- req.setRequestId(REQ_ID);
- assertEquals("{\"requestId\":\"" + REQ_ID.toString() + "\"}", oper.encodeRequest(req));
-
- // coder throws an exception
- oper = new MyOperation(params, config) {
- @Override
- protected Coder makeCoder() {
- return new StandardCoder() {
- @Override
- public String encode(Object object) throws CoderException {
- throw new CoderException(EXPECTED_EXCEPTION);
- }
- };
- }
- };
-
- assertThatIllegalArgumentException().isThrownBy(() -> oper.encodeRequest(req))
- .withMessage("cannot encode request");
- }
-
/**
* Tests addAuthHeader() when there is a username, but no password.
*/
@Test
public void testMakeHttpClient() {
// must use a real operation to invoke this method
- assertNotNull(new VfModuleDelete(params, config).makeHttpClient());
+ assertNotNull(new MyOperation(params, config).makeHttpClient());
}
private class MyOperation extends VfModuleDelete {
- public MyOperation(ControlLoopOperationParams params, HttpConfig config) {
+ public MyOperation(ControlLoopOperationParams params, HttpPollingConfig config) {
super(params, config);
}