summaryrefslogtreecommitdiffstats
path: root/feature-lifecycle/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'feature-lifecycle/src/test/java')
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java23
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java42
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java27
3 files changed, 46 insertions, 46 deletions
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java
index bb8e4940..2a258305 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-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.
@@ -34,7 +34,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
-import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
@@ -44,7 +43,6 @@ import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
-import org.onap.policy.models.pdp.enums.PdpMessageType;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -127,28 +125,19 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
assertTrue(fsm.statusTask.isDone());
}
- private Callable<Boolean> isStatus(PdpState state) {
- return () -> {
- if (fsm.client.getSink().getRecentEvents().length == 0) {
- return false;
- }
-
- List<String> events = Arrays.asList(fsm.client.getSink().getRecentEvents());
- PdpStatus status =
- new StandardCoder().decode(events.get(events.size() - 1), PdpStatus.class);
-
- return status.getMessageName() == PdpMessageType.PDP_STATUS && state == status.getState();
- };
- }
-
@Test
public void status() {
waitUntil(fsm.getStatusTimerSeconds() + 1, TimeUnit.SECONDS, isStatus(PdpState.ACTIVE));
int preCount = fsm.client.getSink().getRecentEvents().length;
assertTrue(fsm.status());
+ assertEquals(preCount, fsm.client.getSink().getRecentEvents().length);
+
+ fsm.start(controllerSupport.getController());
+ assertTrue(fsm.status());
assertEquals(preCount + 1, fsm.client.getSink().getRecentEvents().length);
+ fsm.stop(controllerSupport.getController());
fsm.shutdown();
}
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java
index 341d9857..f242e4c6 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-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.
@@ -33,7 +33,6 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
-import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
@@ -94,23 +93,6 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
fsm.shutdown();
}
- private Callable<Boolean> isStatus(PdpState state, int count) {
- return () -> {
- if (!fsm.client.getSink().isAlive()) {
- return false;
- }
-
- if (fsm.client.getSink().getRecentEvents().length != count) {
- return false;
- }
-
- String[] events = fsm.client.getSink().getRecentEvents();
- PdpStatus status = new StandardCoder().decode(events[events.length - 1], PdpStatus.class);
-
- return status.getMessageName() == PdpMessageType.PDP_STATUS && state == status.getState();
- };
- }
-
@Test
public void stop() {
simpleStop();
@@ -137,19 +119,23 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
@Test
public void status() {
- status(PdpState.PASSIVE);
- fsm.shutdown();
- }
-
- private void status(PdpState state) {
- waitUntil(5, TimeUnit.SECONDS, isStatus(state, 1));
+ assertTrue(fsm.client.getSink().isAlive());
+ assertTrue(fsm.status());
+ assertSame(0, fsm.client.getSink().getRecentEvents().length);
- waitUntil(fsm.statusTimerSeconds + 2, TimeUnit.SECONDS, isStatus(state, 2));
- waitUntil(fsm.statusTimerSeconds + 2, TimeUnit.SECONDS, isStatus(state, 3));
+ fsm.start(controllerSupport.getController());
+ status(PdpState.PASSIVE, 1);
+ fsm.stop(controllerSupport.getController());
+ fsm.shutdown();
+ }
+ private void status(PdpState state, int initial) {
+ waitUntil(5, TimeUnit.SECONDS, isStatus(state, initial));
+ waitUntil(fsm.statusTimerSeconds + 2, TimeUnit.SECONDS, isStatus(state, initial + 1));
+ waitUntil(fsm.statusTimerSeconds + 2, TimeUnit.SECONDS, isStatus(state, initial + 2));
assertTrue(fsm.status());
- waitUntil(200, TimeUnit.MILLISECONDS, isStatus(state, 4));
+ waitUntil(200, TimeUnit.MILLISECONDS, isStatus(state, initial + 3));
}
@Test
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java
index b5b59767..fe3566db 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-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.
@@ -28,10 +28,14 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.time.PseudoScheduledExecutorService;
import org.onap.policy.common.utils.time.TestTimeMulti;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
import org.onap.policy.drools.utils.logging.LoggerUtil;
+import org.onap.policy.models.pdp.concepts.PdpStatus;
+import org.onap.policy.models.pdp.enums.PdpMessageType;
+import org.onap.policy.models.pdp.enums.PdpState;
public abstract class LifecycleStateRunningTest {
@@ -84,4 +88,25 @@ public abstract class LifecycleStateRunningTest {
public void waitUntil(long twait, TimeUnit units, Callable<Boolean> condition) {
time.waitUntil(twait, units, condition);
}
+
+ protected Callable<Boolean> isStatus(PdpState state, int count) {
+ return () -> {
+ if (fsm.client.getSink().getRecentEvents().length != count) {
+ return false;
+ }
+
+ String[] events = fsm.client.getSink().getRecentEvents();
+ PdpStatus status = new StandardCoder().decode(events[events.length - 1], PdpStatus.class);
+
+ if (status.getSupportedPolicyTypes() != null) {
+ return false;
+ }
+
+ return status.getMessageName() == PdpMessageType.PDP_STATUS && state == status.getState();
+ };
+ }
+
+ protected Callable<Boolean> isStatus(PdpState state) {
+ return isStatus(state, fsm.client.getSink().getRecentEvents().length);
+ }
}