aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.so/src/test
diff options
context:
space:
mode:
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.java19
-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.java18
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperatorTest.java50
-rw-r--r--models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java8
5 files changed, 107 insertions, 70 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 089470420..3a2aaf849 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
@@ -54,7 +54,7 @@ public abstract class BasicSoOperation extends BasicHttpOperation<SoRequest> {
public static final int WAIT_SEC_GETS = 20;
@Mock
- protected SoOperator soOperator;
+ protected SoConfig config;
protected Target target;
protected SoResponse response;
@@ -80,7 +80,7 @@ public abstract class BasicSoOperation extends BasicHttpOperation<SoRequest> {
* Initializes mocks and sets up.
*/
public void setUp() throws Exception {
- super.setUp();
+ super.setUpBasic();
response = new SoResponse();
@@ -98,17 +98,16 @@ public abstract class BasicSoOperation extends BasicHttpOperation<SoRequest> {
when(rawResponse.getStatus()).thenReturn(200);
when(rawResponse.readEntity(String.class)).thenReturn(coder.encode(response));
- operator = soOperator;
-
- initOperator();
+ initConfig();
}
@Override
- protected void initOperator() {
- super.initOperator();
- when(soOperator.getMaxGets()).thenReturn(MAX_GETS);
- when(soOperator.getPathGet()).thenReturn(PATH_GET);
- when(soOperator.getWaitSecGet()).thenReturn(WAIT_SEC_GETS);
+ protected void initConfig() {
+ super.initConfig();
+ when(config.getClient()).thenReturn(client);
+ when(config.getMaxGets()).thenReturn(MAX_GETS);
+ when(config.getPathGet()).thenReturn(PATH_GET);
+ when(config.getWaitSecGet()).thenReturn(WAIT_SEC_GETS);
}
@Override
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
new file mode 100644
index 000000000..17fd9c9de
--- /dev/null
+++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoConfigTest.java
@@ -0,0 +1,82 @@
+/*-
+ * ============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 e70413876..871d37032 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
@@ -68,16 +68,16 @@ public class SoOperationTest extends BasicSoOperation {
public void setUp() throws Exception {
super.setUp();
- initOperator();
+ initConfig();
- oper = new SoOperation(params, soOperator) {};
+ oper = new SoOperation(params, config) {};
}
@Test
public void testConstructor_testGetWaitMsGet() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
assertEquals(DEFAULT_OPERATION, oper.getName());
- assertSame(soOperator, oper.getOperator());
+ assertSame(config, oper.getConfig());
assertEquals(1000 * WAIT_SEC_GETS, oper.getWaitMsGet());
}
@@ -85,7 +85,7 @@ public class SoOperationTest extends BasicSoOperation {
public void testStartPreprocessorAsync() {
AtomicBoolean guardStarted = new AtomicBoolean();
- oper = new SoOperation(params, soOperator) {
+ oper = new SoOperation(params, config) {
@Override
protected CompletableFuture<OperationOutcome> startGuardAsync() {
guardStarted.set(true);
@@ -150,7 +150,7 @@ public class SoOperationTest extends BasicSoOperation {
// use a real executor
params = params.toBuilder().executor(ForkJoinPool.commonPool()).build();
- oper = new SoOperation(params, soOperator) {
+ oper = new SoOperation(params, config) {
@Override
public long getWaitMsGet() {
return 1;
@@ -159,7 +159,7 @@ public class SoOperationTest extends BasicSoOperation {
CompletableFuture<OperationOutcome> future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
- assertSame(outcome, future2.get(5, TimeUnit.SECONDS));
+ assertSame(outcome, future2.get(500, TimeUnit.SECONDS));
assertEquals(PolicyResult.SUCCESS, outcome.getResult());
assertEquals(2, oper.getGetCount());
@@ -236,7 +236,7 @@ public class SoOperationTest extends BasicSoOperation {
// try with null target
params = params.toBuilder().target(null).build();
- oper = new SoOperation(params, soOperator) {};
+ oper = new SoOperation(params, config) {};
assertThatIllegalArgumentException().isThrownBy(() -> oper.prepareSoModelInfo()).withMessage("missing Target");
}
@@ -274,7 +274,7 @@ public class SoOperationTest extends BasicSoOperation {
// null payload
params = params.toBuilder().payload(null).build();
- oper = new SoOperation(params, soOperator) {};
+ oper = new SoOperation(params, config) {};
assertNull(oper.buildRequestParameters());
}
@@ -295,7 +295,7 @@ public class SoOperationTest extends BasicSoOperation {
// null payload
params = params.toBuilder().payload(null).build();
- oper = new SoOperation(params, soOperator) {};
+ oper = new SoOperation(params, config) {};
assertNull(oper.buildConfigurationParameters());
}
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
index 16bbdea2a..20403237b 100644
--- 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
@@ -22,9 +22,7 @@ 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.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import java.util.Map;
@@ -34,11 +32,7 @@ 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.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.Util;
-import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
public class SoOperatorTest {
@@ -86,35 +80,8 @@ public class SoOperatorTest {
}
@Test
- public void testMakeSoOperator() {
- oper = SoOperator.makeSoOperator(ACTOR, OPERATION, MyOperation::new);
-
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- ControlLoopEventContext context = new ControlLoopEventContext(event);
- ControlLoopOperationParams params =
- ControlLoopOperationParams.builder().actor(ACTOR).operation(OPERATION).context(context).build();
-
- Operation operation1 = oper.buildOperation(params);
- assertNotNull(operation1);
-
- Operation operation2 = oper.buildOperation(params);
- assertNotNull(operation2);
- assertNotSame(operation1, operation2);
- }
-
- @Test
public void testDoConfigure_testGetters() {
- // should use given values
- assertSame(client, oper.getClient());
- assertEquals(PATH_GET, oper.getPathGet());
- assertEquals(MAX_GETS, oper.getMaxGets());
- assertEquals(WAIT_SEC_GETS, oper.getWaitSecGet());
-
- SoParams params = SoParams.builder().pathGet("unslashed").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);
- assertEquals("unslashed/", oper.getPathGet());
+ assertTrue(oper.getCurrentConfig() instanceof SoConfig);
// test invalid parameters
Map<String, Object> paramMap2 = Util.translateToMap(OPERATION, SoParams.builder().build());
@@ -124,12 +91,7 @@ public class SoOperatorTest {
private class MyOperator extends SoOperator {
public MyOperator() {
- super(ACTOR, OPERATION);
- }
-
- @Override
- public Operation buildOperation(ControlLoopOperationParams params) {
- return null;
+ super(ACTOR, OPERATION, null);
}
@Override
@@ -137,10 +99,4 @@ public class SoOperatorTest {
return factory;
}
}
-
- private class MyOperation extends SoOperation {
- public MyOperation(ControlLoopOperationParams params, SoOperator operator) {
- super(params, operator);
- }
- }
}
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 40efdc880..6c3cfbf66 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
@@ -64,7 +64,7 @@ public class VfModuleCreateTest extends BasicSoOperation {
@Before
public void setUp() throws Exception {
super.setUp();
- oper = new VfModuleCreate(params, soOperator);
+ oper = new VfModuleCreate(params, config);
}
@Test
@@ -82,7 +82,7 @@ public class VfModuleCreateTest extends BasicSoOperation {
AtomicBoolean guardStarted = new AtomicBoolean();
- oper = new VfModuleCreate(params, soOperator) {
+ oper = new VfModuleCreate(params, config) {
@Override
protected CompletableFuture<OperationOutcome> startGuardAsync() {
guardStarted.set(true);
@@ -102,7 +102,7 @@ public class VfModuleCreateTest extends BasicSoOperation {
// use a real executor
params = params.toBuilder().executor(ForkJoinPool.commonPool()).build();
- oper = new VfModuleCreate(params, soOperator) {
+ oper = new VfModuleCreate(params, config) {
@Override
public long getWaitMsGet() {
return 1;
@@ -128,7 +128,7 @@ public class VfModuleCreateTest extends BasicSoOperation {
// use a real executor
params = params.toBuilder().executor(ForkJoinPool.commonPool()).build();
- oper = new VfModuleCreate(params, soOperator) {
+ oper = new VfModuleCreate(params, config) {
@Override
public long getWaitMsGet() {
return 1;