aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.so/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-06-11 19:00:41 -0400
committerJim Hahn <jrh3@att.com>2020-06-12 18:40:29 -0400
commite9af3a2b3a430626c740b18ccf8592706db1dfb1 (patch)
treeff0d351b54f4862de8512666d3a7c1371ef73118 /models-interactions/model-actors/actor.so/src/test
parentc34fdc19686d70af12e8873b0b01b96dd54c1aa3 (diff)
Moving common polling code into HttpOperation
SO and VFC have duplicate code for polling. Moved it into the common superclass. Issue-ID: POLICY-2632 Change-Id: I27128bfb2d54ef522b6b44ff569819a8463f3454 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.so/src/test')
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java15
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorParamsTest.java118
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoConfigTest.java82
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java100
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperatorTest.java102
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoParamsTest.java92
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java18
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java24
-rw-r--r--models-interactions/model-actors/actor.so/src/test/resources/service.yaml5
9 files changed, 38 insertions, 518 deletions
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java
index 11418ff75..c8afab450 100644
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java
@@ -35,6 +35,7 @@ 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.actorserviceprovider.parameters.HttpPollingConfig;
import org.onap.policy.controlloop.policy.Target;
import org.onap.policy.simulators.SoSimulatorJaxRs;
import org.onap.policy.so.SoRequest;
@@ -56,13 +57,13 @@ public abstract class BasicSoOperation extends BasicHttpOperation<SoRequest> {
public static final String MODEL_VERS_ID = "my-model-version-id";
public static final String SUBSCRIPTION_SVC_TYPE = "my-subscription-service-type";
public static final String MY_PATH = "my-path";
- public static final String PATH_GET = "my-path-get/";
- public static final int MAX_GETS = 3;
- public static final int WAIT_SEC_GETS = 20;
+ public static final String POLL_PATH = "my-poll-path/";
+ public static final int MAX_POLLS = 3;
+ public static final int POLL_WAIT_SEC = 20;
public static final Integer VF_COUNT = 10;
@Mock
- protected SoConfig config;
+ protected HttpPollingConfig config;
protected Target target;
protected SoResponse response;
@@ -134,9 +135,9 @@ public abstract class BasicSoOperation extends BasicHttpOperation<SoRequest> {
super.initConfig();
when(config.getClient()).thenReturn(client);
when(config.getPath()).thenReturn(MY_PATH);
- when(config.getMaxGets()).thenReturn(MAX_GETS);
- when(config.getPathGet()).thenReturn(PATH_GET);
- when(config.getWaitSecGet()).thenReturn(WAIT_SEC_GETS);
+ when(config.getMaxPolls()).thenReturn(MAX_POLLS);
+ when(config.getPollPath()).thenReturn(POLL_PATH);
+ when(config.getPollWaitSec()).thenReturn(POLL_WAIT_SEC);
}
@Override
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorParamsTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorParamsTest.java
deleted file mode 100644
index 93f305550..000000000
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoActorParamsTest.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.actor.so;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.function.Consumer;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.policy.common.parameters.ValidationResult;
-import org.onap.policy.controlloop.actorserviceprovider.Util;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.ActorParams;
-
-
-public class SoActorParamsTest {
- private static final String CONTAINER = "my-container";
- private static final String CLIENT = "my-client";
- private static final String PATH_GET = "my-path-get";
- private static final int MAX_GETS = 3;
- private static final int WAIT_SEC_GETS = 20;
- private static final int TIMEOUT = 10;
-
- private static final String PATH1 = "path #1";
- private static final String PATH2 = "path #2";
- private static final String URI1 = "uri #1";
- private static final String URI2 = "uri #2";
-
- private Map<String, Map<String, Object>> operations;
- private SoActorParams params;
-
- /**
- * Initializes {@link #operations} with two items and {@link params} with a fully
- * populated object.
- */
- @Before
- public void setUp() {
- operations = new TreeMap<>();
- operations.put(PATH1, Map.of("path", URI1));
- operations.put(PATH2, Map.of("path", URI2));
-
- params = makeSoActorParams();
- }
-
- @Test
- public void testValidate() {
- assertTrue(params.validate(CONTAINER).isValid());
-
- // only a few fields are required
- SoActorParams sparse = Util.translate(CONTAINER, Map.of(ActorParams.OPERATIONS_FIELD, operations),
- SoActorParams.class);
- assertTrue(sparse.validate(CONTAINER).isValid());
-
- testValidateField("maxGets", "minimum", params2 -> params2.setMaxGets(-1));
- testValidateField("waitSecGet", "minimum", params2 -> params2.setWaitSecGet(0));
-
- // check fields from superclass
- testValidateField(ActorParams.OPERATIONS_FIELD, "null", params2 -> params2.setOperations(null));
- testValidateField("timeoutSec", "minimum", params2 -> params2.setTimeoutSec(-1));
-
- // check edge cases
- params.setMaxGets(0);
- assertTrue(params.validate(CONTAINER).isValid());
- params.setMaxGets(MAX_GETS);
-
- params.setWaitSecGet(1);
- assertTrue(params.validate(CONTAINER).isValid());
- params.setWaitSecGet(WAIT_SEC_GETS);
- }
-
- private void testValidateField(String fieldName, String expected, Consumer<SoActorParams> makeInvalid) {
-
- // original params should be valid
- ValidationResult result = params.validate(CONTAINER);
- assertTrue(fieldName, result.isValid());
-
- // make invalid params
- SoActorParams params2 = makeSoActorParams();
- makeInvalid.accept(params2);
- result = params2.validate(CONTAINER);
- assertFalse(fieldName, result.isValid());
- assertThat(result.getResult()).contains(CONTAINER).contains(fieldName).contains(expected);
- }
-
- private SoActorParams makeSoActorParams() {
- SoActorParams params2 = new SoActorParams();
- params2.setClientName(CLIENT);
- params2.setTimeoutSec(TIMEOUT);
- params2.setOperations(operations);
-
- params2.setWaitSecGet(WAIT_SEC_GETS);
- params2.setMaxGets(MAX_GETS);
- params2.setPathGet(PATH_GET);
-
- return params2;
- }
-}
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoConfigTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoConfigTest.java
deleted file mode 100644
index 17fd9c9de..000000000
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoConfigTest.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.actor.so;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertSame;
-import static org.mockito.Mockito.when;
-
-import java.util.concurrent.Executor;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.onap.policy.common.endpoints.http.client.HttpClient;
-import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
-
-public class SoConfigTest {
- private static final String MY_CLIENT = "my-client";
- private static final String MY_PATH = "my-path";
- private static final String GET_PATH = "get-path";
- private static final int TIMEOUT_SEC = 10;
- private static final int MAX_GETS = 20;
- private static final int WAIT_SEC = 30;
-
- @Mock
- private HttpClient client;
- @Mock
- private HttpClientFactory factory;
- @Mock
- private Executor executor;
-
- private SoParams params;
- private SoConfig config;
-
- /**
- * Sets up.
- */
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- when(factory.get(MY_CLIENT)).thenReturn(client);
-
- params = SoParams.builder().maxGets(MAX_GETS).pathGet(GET_PATH).waitSecGet(WAIT_SEC).clientName(MY_CLIENT)
- .path(MY_PATH).timeoutSec(TIMEOUT_SEC).build();
- config = new SoConfig(executor, params, factory);
- }
-
- @Test
- public void test() {
- assertEquals(GET_PATH + "/", config.getPathGet());
- assertEquals(MAX_GETS, config.getMaxGets());
- assertEquals(WAIT_SEC, config.getWaitSecGet());
-
- // check value from superclass
- assertSame(executor, config.getBlockingExecutor());
- assertSame(client, config.getClient());
-
- // path with trailing "/"
- params = params.toBuilder().pathGet(GET_PATH + "/").build();
- config = new SoConfig(executor, params, factory);
- assertEquals(GET_PATH + "/", config.getPathGet());
- }
-}
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java
index b794eab4e..46d96fded 100644
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java
@@ -28,7 +28,6 @@ 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 static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -37,8 +36,6 @@ import java.time.Month;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ForkJoinPool;
-import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.junit.Before;
@@ -56,7 +53,6 @@ import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.so.SoModelInfo;
import org.onap.policy.so.SoRequest;
import org.onap.policy.so.SoRequestInfo;
-import org.onap.policy.so.SoRequestReferences;
import org.onap.policy.so.SoRequestStatus;
import org.onap.policy.so.SoResponse;
@@ -79,11 +75,11 @@ public class SoOperationTest extends BasicSoOperation {
}
@Test
- public void testConstructor_testGetWaitMsGet() {
+ public void testConstructor() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
assertEquals(DEFAULT_OPERATION, oper.getName());
assertSame(config, oper.getConfig());
- assertEquals(1000 * WAIT_SEC_GETS, oper.getWaitMsGet());
+ assertTrue(oper.isUsePolling());
// check when Target is null
params = params.toBuilder().target(null).build();
@@ -167,98 +163,6 @@ public class SoOperationTest extends BasicSoOperation {
}
@Test
- public void testPostProcess() throws Exception {
- // completed
- oper.generateSubRequestId(2);
- assertNull(oper.getSubRequestId());
- CompletableFuture<OperationOutcome> future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
- assertTrue(future2.isDone());
- assertSame(outcome, future2.get());
- assertEquals(PolicyResult.SUCCESS, outcome.getResult());
- assertNotNull(oper.getSubRequestId());
- assertSame(response, outcome.getResponse());
-
- // failed
- oper.generateSubRequestId(2);
- assertNull(oper.getSubRequestId());
- response.getRequest().getRequestStatus().setRequestState(SoOperation.FAILED);
- future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
- assertTrue(future2.isDone());
- assertSame(outcome, future2.get());
- assertEquals(PolicyResult.FAILURE, outcome.getResult());
- assertNotNull(oper.getSubRequestId());
- assertSame(response, outcome.getResponse());
-
- // no request id in the response
- oper.generateSubRequestId(2);
- assertNull(oper.getSubRequestId());
- response.getRequestReferences().setRequestId(null);
- response.getRequest().getRequestStatus().setRequestState("unknown");
- assertThatIllegalArgumentException()
- .isThrownBy(() -> oper.postProcessResponse(outcome, PATH, rawResponse, response))
- .withMessage("missing request ID in response");
- response.getRequestReferences().setRequestId(REQ_ID.toString());
-
- // status = 500
- when(rawResponse.getStatus()).thenReturn(500);
-
- // null request reference
- SoRequestReferences ref = response.getRequestReferences();
- response.setRequestReferences(null);
- assertThatIllegalArgumentException()
- .isThrownBy(() -> oper.postProcessResponse(outcome, PATH, rawResponse, response))
- .withMessage("missing request ID in response");
- response.setRequestReferences(ref);
- }
-
- /**
- * Tests postProcess() when the "get" is repeated a couple of times.
- */
- @Test
- public void testPostProcessRepeated_testResetGetCount() throws Exception {
- /*
- * Two failures and then a success - should result in two "get" calls.
- *
- * Note: getStatus() is invoked twice during each call, so have to double up the
- * return values.
- */
- when(rawResponse.getStatus()).thenReturn(500, 500, 500, 500, 200, 200);
-
- when(client.get(any(), any(), any())).thenAnswer(provideResponse(rawResponse));
-
- // use a real executor
- params = params.toBuilder().executor(ForkJoinPool.commonPool()).build();
-
- oper = new SoOperation(params, config) {
- @Override
- public long getWaitMsGet() {
- return 1;
- }
- };
-
- CompletableFuture<OperationOutcome> future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
-
- assertSame(outcome, future2.get(5, TimeUnit.SECONDS));
- assertEquals(PolicyResult.SUCCESS, outcome.getResult());
- assertEquals(2, oper.getGetCount());
-
- /*
- * repeat - this time, the "get" operations will be exhausted, so it should fail
- */
- when(rawResponse.getStatus()).thenReturn(500);
-
- future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
-
- assertSame(outcome, future2.get(5, TimeUnit.SECONDS));
- assertEquals(PolicyResult.FAILURE_TIMEOUT, outcome.getResult());
- assertEquals(MAX_GETS + 1, oper.getGetCount());
-
- oper.resetGetCount();
- assertEquals(0, oper.getGetCount());
- assertNull(oper.getSubRequestId());
- }
-
- @Test
public void testGetRequestState() {
SoResponse resp = new SoResponse();
assertNull(oper.getRequestState(resp));
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperatorTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperatorTest.java
deleted file mode 100644
index 20403237b..000000000
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperatorTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.actor.so;
-
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
-
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.onap.policy.common.endpoints.http.client.HttpClient;
-import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
-import org.onap.policy.controlloop.actorserviceprovider.Util;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
-
-public class SoOperatorTest {
- private static final String ACTOR = "my-actor";
- private static final String OPERATION = "my-name";
- private static final String CLIENT = "my-client";
- private static final String PATH = "/my-path";
- private static final String PATH_GET = "my-path-get/";
- private static final int MAX_GETS = 3;
- private static final int WAIT_SEC_GETS = 20;
- private static final int TIMEOUT = 100;
-
- @Mock
- private HttpClient client;
-
- @Mock
- private HttpClientFactory factory;
-
-
- private SoOperator oper;
-
- /**
- * Initializes fields, including {@link #oper}, and resets the static fields used by
- * the REST server.
- */
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
-
- when(factory.get(CLIENT)).thenReturn(client);
-
- oper = new MyOperator();
-
- SoParams params = SoParams.builder().pathGet(PATH_GET).maxGets(MAX_GETS).waitSecGet(WAIT_SEC_GETS)
- .clientName(CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
- Map<String, Object> paramMap = Util.translateToMap(OPERATION, params);
- oper.configure(paramMap);
- }
-
- @Test
- public void testConstructor() {
- assertEquals(ACTOR, oper.getActorName());
- assertEquals(OPERATION, oper.getName());
- assertEquals(ACTOR + "." + OPERATION, oper.getFullName());
- }
-
- @Test
- public void testDoConfigure_testGetters() {
- assertTrue(oper.getCurrentConfig() instanceof SoConfig);
-
- // test invalid parameters
- Map<String, Object> paramMap2 = Util.translateToMap(OPERATION, SoParams.builder().build());
- assertThatThrownBy(() -> oper.configure(paramMap2)).isInstanceOf(ParameterValidationRuntimeException.class);
- }
-
-
- private class MyOperator extends SoOperator {
- public MyOperator() {
- super(ACTOR, OPERATION, null);
- }
-
- @Override
- protected HttpClientFactory getClientFactory() {
- return factory;
- }
- }
-}
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoParamsTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoParamsTest.java
deleted file mode 100644
index 2b02ad8ff..000000000
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoParamsTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.actor.so;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.util.function.Function;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.policy.common.parameters.ValidationResult;
-import org.onap.policy.controlloop.actor.so.SoParams.SoParamsBuilder;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams.HttpParamsBuilder;
-
-public class SoParamsTest {
- private static final String CONTAINER = "my-container";
- private static final String CLIENT = "my-client";
- private static final String PATH = "my-path";
- private static final String PATH_GET = "my-path-get";
- private static final int MAX_GETS = 3;
- private static final int WAIT_SEC_GETS = 20;
- private static final int TIMEOUT = 10;
-
- private SoParams params;
-
- @Before
- public void setUp() {
- params = SoParams.builder().pathGet(PATH_GET).maxGets(MAX_GETS).waitSecGet(WAIT_SEC_GETS).clientName(CLIENT)
- .path(PATH).timeoutSec(TIMEOUT).build();
- }
-
- @Test
- public void testValidate() {
- assertTrue(params.validate(CONTAINER).isValid());
-
- testValidateField("pathGet", "null", bldr -> bldr.pathGet(null));
- testValidateField("maxGets", "minimum", bldr -> bldr.maxGets(-1));
- testValidateField("waitSecGet", "minimum", bldr -> bldr.waitSecGet(-1));
-
- // validate one of the superclass fields
- testValidateField("clientName", "null", bldr -> bldr.clientName(null));
-
- // check edge cases
- assertTrue(params.toBuilder().maxGets(0).build().validate(CONTAINER).isValid());
- assertFalse(params.toBuilder().waitSecGet(0).build().validate(CONTAINER).isValid());
- assertTrue(params.toBuilder().waitSecGet(1).build().validate(CONTAINER).isValid());
- }
-
- @Test
- public void testBuilder_testToBuilder() {
- assertEquals(CLIENT, params.getClientName());
-
- assertEquals(PATH_GET, params.getPathGet());
- assertEquals(MAX_GETS, params.getMaxGets());
- assertEquals(WAIT_SEC_GETS, params.getWaitSecGet());
-
- assertEquals(params, params.toBuilder().build());
- }
-
- private void testValidateField(String fieldName, String expected,
- @SuppressWarnings("rawtypes") Function<SoParamsBuilder, HttpParamsBuilder> makeInvalid) {
-
- // original params should be valid
- ValidationResult result = params.validate(CONTAINER);
- assertTrue(fieldName, result.isValid());
-
- // make invalid params
- result = makeInvalid.apply(params.toBuilder()).build().validate(CONTAINER);
- assertFalse(fieldName, result.isValid());
- assertThat(result.getResult()).contains(fieldName).contains(expected);
- }
-}
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java
index 2b3e1163b..94268646d 100644
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java
@@ -51,6 +51,8 @@ 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;
+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;
@@ -88,11 +90,13 @@ public class VfModuleCreateTest extends BasicSoOperation {
*/
@Test
public void testSuccess() throws Exception {
- SoParams opParams = SoParams.builder().clientName(MY_CLIENT).path("serviceInstantiation/v7/serviceInstances")
- .pathGet("orchestrationRequests/v5/").maxGets(2).build();
- config = new SoConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+ HttpPollingParams opParams = HttpPollingParams.builder().clientName(MY_CLIENT)
+ .path("serviceInstantiation/v7/serviceInstances").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 VfModuleCreate(params, config);
outcome = oper.start().get();
@@ -179,7 +183,7 @@ public class VfModuleCreateTest extends BasicSoOperation {
oper = new VfModuleCreate(params, config) {
@Override
- public long getWaitMsGet() {
+ protected long getPollWaitMs() {
return 1;
}
};
@@ -197,10 +201,10 @@ public class VfModuleCreateTest extends BasicSoOperation {
}
/**
- * Tests startOperationAsync() when "get" operations are required.
+ * Tests startOperationAsync() when polling is required.
*/
@Test
- public void testStartOperationAsyncWithGets() throws Exception {
+ public void testStartOperationAsyncWithPolling() throws Exception {
when(rawResponse.getStatus()).thenReturn(500, 500, 500, 500, 200, 200);
when(client.post(any(), any(), any(), any())).thenAnswer(provideResponse(rawResponse));
@@ -211,7 +215,7 @@ public class VfModuleCreateTest extends BasicSoOperation {
oper = new VfModuleCreate(params, config) {
@Override
- public long getWaitMsGet() {
+ public long getPollWaitMs() {
return 1;
}
};
diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java
index f5d05a0e8..d7b53411b 100644
--- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java
@@ -64,7 +64,8 @@ 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;
-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;
@@ -119,11 +120,12 @@ public class VfModuleDeleteTest extends BasicSoOperation {
*/
@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();
@@ -138,7 +140,7 @@ public class VfModuleDeleteTest extends BasicSoOperation {
// 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");
}
@@ -208,7 +210,7 @@ public class VfModuleDeleteTest extends BasicSoOperation {
oper = new MyOperation(params, config) {
@Override
- public long getWaitMsGet() {
+ public long getPollWaitMs() {
return 1;
}
};
@@ -226,10 +228,10 @@ public class VfModuleDeleteTest extends BasicSoOperation {
}
/**
- * 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"));
@@ -242,7 +244,7 @@ public class VfModuleDeleteTest extends BasicSoOperation {
oper = new MyOperation(params, config) {
@Override
- public long getWaitMsGet() {
+ public long getPollWaitMs() {
return 1;
}
};
@@ -383,7 +385,7 @@ public class VfModuleDeleteTest extends BasicSoOperation {
@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());
}
@@ -428,7 +430,7 @@ public class VfModuleDeleteTest extends BasicSoOperation {
private class MyOperation extends VfModuleDelete {
- public MyOperation(ControlLoopOperationParams params, HttpConfig config) {
+ public MyOperation(ControlLoopOperationParams params, HttpPollingConfig config) {
super(params, config);
}
diff --git a/models-interactions/model-actors/actor.so/src/test/resources/service.yaml b/models-interactions/model-actors/actor.so/src/test/resources/service.yaml
index e1cb0d9f3..e16e7d74a 100644
--- a/models-interactions/model-actors/actor.so/src/test/resources/service.yaml
+++ b/models-interactions/model-actors/actor.so/src/test/resources/service.yaml
@@ -26,8 +26,11 @@ httpClients:
actors:
SO:
clientName: my-client
+ pollPath: orchestrationRequests/v5
+ pollWaitSec: 20
+ maxPolls: 20
operations:
VF Module Create:
path: serviceInstantiation/v7/serviceInstances
VF Module Delete:
- path: serviceInstances/v7 \ No newline at end of file
+ path: serviceInstances/v7