summaryrefslogtreecommitdiffstats
path: root/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap
diff options
context:
space:
mode:
authorPatrick Brady <pb071s@att.com>2017-12-13 11:19:06 -0800
committerPatrick Brady <pb071s@att.com>2017-12-13 11:19:17 -0800
commit781b1a6df324419c846c84ea983c18fc8362bfd3 (patch)
tree580008010dd50ca32db2ef6dc2e36628cf8c2b5b /appc-lifecycle-management/state-machine-lib/src/test/java/org/onap
parent161df8a94bb3b0c34ed16fd4fdba078bd1eeef9a (diff)
Third part of onap rename
This part of the commit changes the folder structure on all other folders of appc. Change-Id: I8acfa11cdfcdcd36be0e137245d1dd7324f1abd3 Signed-off-by: Patrick Brady <pb071s@att.com> Issue-ID: APPC-13
Diffstat (limited to 'appc-lifecycle-management/state-machine-lib/src/test/java/org/onap')
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/StateMachineFactoryTest.java59
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/StateMachineImplTest.java107
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/readers/AppcOamMetaDataReaderTest.java74
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/readers/AppcOamStatesTest.java71
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/readers/VnfMetaDataReaderTest.java79
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/EventTest.java70
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/ResponseTest.java40
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/StateMachineMetadataTest.java61
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/StateMachineResponseTest.java71
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/StateTest.java91
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/TransitionTest.java57
11 files changed, 780 insertions, 0 deletions
diff --git a/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/StateMachineFactoryTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/StateMachineFactoryTest.java
new file mode 100644
index 000000000..e35482e45
--- /dev/null
+++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/StateMachineFactoryTest.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.statemachine.impl;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.appc.statemachine.StateMachine;
+import org.onap.appc.statemachine.objects.Event;
+import org.onap.appc.statemachine.objects.State;
+import org.onap.appc.statemachine.objects.StateMachineMetadata;
+
+public class StateMachineFactoryTest {
+ private StateMachineMetadata metadata;
+
+ @Before
+ public void setUp() throws Exception {
+ StateMachineMetadata.StateMachineMetadataBuilder builder =
+ new StateMachineMetadata.StateMachineMetadataBuilder();
+ builder.addEvent(new Event("TestingEvent1"));
+ builder.addEvent(new Event("TestingEvent2"));
+ builder.addState(new State("TestingState1"));
+ builder.addState(new State("TestingState2"));
+ builder.addState(new State("TestingState3"));
+ builder.addTransition(
+ new State("TestingState1"), new Event("TestingEvent1"), new State("TestingState2"));
+
+ metadata = builder.build();
+ }
+
+ @Test
+ public void testGetStateMachine() throws Exception {
+ StateMachine stateMachine = StateMachineFactory.getStateMachine(metadata);
+ Assert.assertTrue("Should return StateMachineImpl", stateMachine instanceof StateMachineImpl);
+ }
+
+}
diff --git a/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/StateMachineImplTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/StateMachineImplTest.java
new file mode 100644
index 000000000..a4a8b9fcc
--- /dev/null
+++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/StateMachineImplTest.java
@@ -0,0 +1,107 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.statemachine.impl;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.internal.util.reflection.Whitebox;
+import org.onap.appc.exceptions.InvalidInputException;
+import org.onap.appc.statemachine.objects.Event;
+import org.onap.appc.statemachine.objects.Response;
+import org.onap.appc.statemachine.objects.State;
+import org.onap.appc.statemachine.objects.StateMachineMetadata;
+import org.onap.appc.statemachine.objects.StateMachineResponse;
+
+public class StateMachineImplTest {
+ private StateMachineMetadata metadata;
+ private StateMachineImpl stateMachine;
+
+ private State state1 = new State("TestingState1");
+ private State state2 = new State("TestingState2");
+ private Event event1 = new Event("TestingEvent1");
+ private Event event2 = new Event("TestingEvent2");
+
+ @Before
+ public void setUp() throws Exception {
+ StateMachineMetadata.StateMachineMetadataBuilder builder =
+ new StateMachineMetadata.StateMachineMetadataBuilder();
+ builder.addEvent(event1);
+ builder.addEvent(event2);
+ builder.addState(state1);
+ builder.addState(state2);
+ builder.addState(new State("TestingState3"));
+ builder.addTransition(state1, event1, state2);
+
+ metadata = builder.build();
+
+ stateMachine = new StateMachineImpl(metadata);
+ }
+
+ @Test
+ public void testConstructor() throws Exception {
+ StateMachineImpl stateMachine = new StateMachineImpl(metadata);
+ Assert.assertEquals("Should have set internal states",
+ metadata.getStates(), Whitebox.getInternalState(stateMachine, "states"));
+ Assert.assertEquals("Should have set internal events",
+ metadata.getEvents(), Whitebox.getInternalState(stateMachine, "events"));
+ }
+
+ @Test(expected = InvalidInputException.class)
+ public void testHandleEventThrowsInvalidInputException() throws Exception {
+ stateMachine.handleEvent(null, null);
+ }
+
+ @Test
+ public void testHandleEvent() throws Exception {
+ StateMachineResponse response = stateMachine.handleEvent(state1, event1);
+ Assert.assertEquals(Response.VALID_TRANSITION, response.getResponse());
+ Assert.assertEquals(state2, response.getNextState());
+
+ response = stateMachine.handleEvent(state2, event1);
+ Assert.assertEquals(Response.NO_TRANSITION_DEFINED, response.getResponse());
+ Assert.assertTrue(response.getNextState() == null);
+ }
+
+ @Test
+ public void testValidateInputs() {
+ Assert.assertFalse(stateMachine.validateInputs(null, null));
+ Assert.assertFalse(stateMachine.validateInputs(new State("state1"), null));
+ Assert.assertFalse(stateMachine.validateInputs(null, new Event("event1")));
+ Assert.assertFalse(stateMachine.validateInputs(new State("state1"), new Event("event1")));
+ Assert.assertFalse(stateMachine.validateInputs(state1, new Event("event1")));
+ Assert.assertFalse(stateMachine.validateInputs(new State("state1"), event1));
+ Assert.assertTrue(stateMachine.validateInputs(state1, event1));
+
+ }
+
+ @Test
+ public void testToString() throws Exception {
+ Assert.assertEquals(
+ String.format(stateMachine.toStringFormat, metadata.getStates(), metadata.getEvents()),
+ stateMachine.toString());
+ }
+
+}
diff --git a/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/readers/AppcOamMetaDataReaderTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/readers/AppcOamMetaDataReaderTest.java
new file mode 100644
index 000000000..e8f2a2083
--- /dev/null
+++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/readers/AppcOamMetaDataReaderTest.java
@@ -0,0 +1,74 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.statemachine.impl.readers;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.appc.statemachine.objects.Event;
+import org.onap.appc.statemachine.objects.State;
+import org.onap.appc.statemachine.objects.StateMachineMetadata;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+public class AppcOamMetaDataReaderTest {
+ private List<String> expectedStateNames = new ArrayList<>();
+ private List<String> expectedEventNames = new ArrayList<>();
+
+ private StateMachineMetadata stateMachineMetadata = new AppcOamMetaDataReader().readMetadata();
+
+ @Before
+ public void setUp() throws Exception {
+ for (AppcOamStates appcOamStates : AppcOamStates.values()) {
+ expectedStateNames.add(appcOamStates.toString());
+ }
+ for (AppcOamMetaDataReader.AppcOperation appcOperation : AppcOamMetaDataReader.AppcOperation.values()) {
+ expectedEventNames.add(appcOperation.toString());
+ }
+ }
+
+ @Test
+ public void testReadMetadataForState() throws Exception {
+ Set<State> stateSet = stateMachineMetadata.getStates();
+ for (State state : stateSet) {
+ String eventName = state.getStateName();
+ Assert.assertTrue(String.format("Event(%s) should exist in expectedEventNames", eventName),
+ expectedStateNames.contains(eventName));
+ }
+ }
+
+ @Test
+ public void testReadMetadataForEvent() throws Exception {
+ Set<Event> eventSet = stateMachineMetadata.getEvents();
+ for (Event event : eventSet) {
+ String eventName = event.getEventName();
+ Assert.assertTrue(String.format("Event(%s) should exist in expectedEventNames", eventName),
+ expectedEventNames.contains(eventName));
+ }
+ }
+
+}
diff --git a/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/readers/AppcOamStatesTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/readers/AppcOamStatesTest.java
new file mode 100644
index 000000000..014618846
--- /dev/null
+++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/readers/AppcOamStatesTest.java
@@ -0,0 +1,71 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.statemachine.impl.readers;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class AppcOamStatesTest {
+
+ @Test
+ public void testBasicFunctions() {
+ AppcOamStates aState = AppcOamStates.EnteringMaintenanceMode;
+ Assert.assertEquals("name() does not match", "EnteringMaintenanceMode", aState.name());
+ Assert.assertEquals("toString() does not match", "EnteringMaintenanceMode", aState.toString());
+ Assert.assertEquals("osgiBundleState does not match", 0, aState.osgiBundleState);
+ }
+
+ @Test
+ public void testGetOamStateFromBundleState() {
+ Map<Integer, AppcOamStates> resultMap = new HashMap<Integer, AppcOamStates>() {
+ {
+ put(Bundle.UNINSTALLED, AppcOamStates.NotInstantiated);
+ put(Bundle.INSTALLED, AppcOamStates.Instantiated);
+ put(Bundle.RESOLVED, AppcOamStates.Stopped);
+ put(Bundle.STARTING, AppcOamStates.Starting);
+ put(Bundle.STOPPING, AppcOamStates.Stopping);
+ put(Bundle.ACTIVE, AppcOamStates.Started);
+ }
+ };
+ for (Map.Entry<Integer, AppcOamStates> aEntry : resultMap.entrySet()) {
+ Integer bundleState = aEntry.getKey();
+ AppcOamStates oamState = aEntry.getValue();
+ Assert.assertEquals(String.format("OSGI bundle state(%d) shoule associate with oamState(%s)",
+ bundleState, oamState), oamState, AppcOamStates.getOamStateFromBundleState(bundleState));
+ }
+
+ int bundleState = Bundle.START_TRANSIENT;
+ Assert.assertEquals(String.format("OSGI bundle state(%d) shoule associate with NotInstantiated state.",
+ bundleState), AppcOamStates.NotInstantiated, AppcOamStates.getOamStateFromBundleState(bundleState));
+
+ bundleState = Bundle.STOP_TRANSIENT;
+ Assert.assertEquals(String.format("OSGI bundle state(%d) shoule associate with NotInstantiated state.",
+ bundleState), AppcOamStates.NotInstantiated, AppcOamStates.getOamStateFromBundleState(bundleState));
+ }
+}
diff --git a/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/readers/VnfMetaDataReaderTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/readers/VnfMetaDataReaderTest.java
new file mode 100644
index 000000000..9b409491e
--- /dev/null
+++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/readers/VnfMetaDataReaderTest.java
@@ -0,0 +1,79 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.statemachine.impl.readers;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.appc.lifecyclemanager.objects.VNFOperationOutcome;
+import org.onap.appc.statemachine.objects.Event;
+import org.onap.appc.statemachine.objects.State;
+import org.onap.appc.statemachine.objects.StateMachineMetadata;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+
+public class VnfMetaDataReaderTest {
+ private List<String> expectedStateNames = new ArrayList<>();
+ private List<String> expectedEventNames = new ArrayList<>();
+
+ private StateMachineMetadata stateMachineMetadata = new VnfMetaDataReader().readMetadata();
+
+ @Before
+ public void setUp() throws Exception {
+ for (VnfMetaDataReader.VNFStates vnfStates : VnfMetaDataReader.VNFStates.values()) {
+ expectedStateNames.add(vnfStates.toString());
+ }
+ for (VnfMetaDataReader.VNFOperation vnfOperation : VnfMetaDataReader.VNFOperation.values()) {
+ expectedEventNames.add(vnfOperation.toString());
+ }
+ for (VNFOperationOutcome vnfOperationOutcome : VNFOperationOutcome.values()) {
+ expectedEventNames.add(vnfOperationOutcome.toString());
+ }
+ }
+
+ @Test
+ public void testReadMetadataForState() throws Exception {
+ Set<State> stateSet = stateMachineMetadata.getStates();
+ for (State state : stateSet) {
+ String eventName = state.getStateName();
+ Assert.assertTrue(String.format("Event(%s) should exist in expectedEventNames", eventName),
+ expectedStateNames.contains(eventName));
+ }
+ }
+
+ @Test
+ public void testReadMetadataForEvent() throws Exception {
+ Set<Event> eventSet = stateMachineMetadata.getEvents();
+ for (Event event : eventSet) {
+ String eventName = event.getEventName();
+ Assert.assertTrue(String.format("Event(%s) should exist in expectedEventNames", eventName),
+ expectedEventNames.contains(eventName));
+ }
+ }
+
+}
diff --git a/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/EventTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/EventTest.java
new file mode 100644
index 000000000..961e33ffd
--- /dev/null
+++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/EventTest.java
@@ -0,0 +1,70 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.statemachine.objects;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.internal.util.reflection.Whitebox;
+
+public class EventTest {
+ private final String EVENT_NAME = "Testing Event";
+ private Event event = new Event(EVENT_NAME);
+
+ @Test
+ public void testConstructor() {
+ Event event = new Event(EVENT_NAME);
+ Assert.assertEquals("Should set eventName",
+ EVENT_NAME, Whitebox.getInternalState(event, "eventName"));
+ Assert.assertEquals("Should set hash code",
+ EVENT_NAME.toLowerCase().hashCode(), (int)Whitebox.getInternalState(event, "hashCode"));
+ }
+
+ @Test
+ public void testHashCode() throws Exception {
+ Assert.assertEquals("Should return proper hash code",
+ EVENT_NAME.toLowerCase().hashCode(), event.hashCode());
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ Assert.assertFalse("should return false for null", event.equals(null));
+ Assert.assertFalse("should return false for object", event.equals(new State(EVENT_NAME)));
+ Assert.assertFalse("should return false for different event",
+ event.equals(new Event("Another")));
+ Assert.assertTrue("should return true", event.equals(new Event(EVENT_NAME)));
+ Assert.assertTrue("should return true (lower case)", event.equals(new Event(EVENT_NAME.toLowerCase())));
+ }
+
+ @Test
+ public void testGetEventName() throws Exception {
+ Assert.assertEquals("Should return EVENT_NAME", EVENT_NAME, event.getEventName());
+ }
+
+ @Test
+ public void testToString() throws Exception {
+ Assert.assertEquals("Should return EVENT_NAME", EVENT_NAME, event.toString());
+ }
+
+}
diff --git a/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/ResponseTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/ResponseTest.java
new file mode 100644
index 000000000..e85bce65f
--- /dev/null
+++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/ResponseTest.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.statemachine.objects;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ResponseTest {
+
+ @Test
+ public void testToString() throws Exception {
+ for (Response response : Response.values()) {
+ Assert.assertEquals("Should return the same as name",
+ response.name(), response.toString());
+ }
+ }
+
+}
diff --git a/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/StateMachineMetadataTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/StateMachineMetadataTest.java
new file mode 100644
index 000000000..684225736
--- /dev/null
+++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/StateMachineMetadataTest.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.statemachine.objects;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.internal.util.reflection.Whitebox;
+
+public class StateMachineMetadataTest {
+ private StateMachineMetadata.StateMachineMetadataBuilder builder;
+ private StateMachineMetadata metadata;
+ @Before
+ public void setUp() throws Exception {
+ builder = new StateMachineMetadata.StateMachineMetadataBuilder();
+ builder.addEvent(new Event("TestingEvent1"));
+ builder.addEvent(new Event("TestingEvent2"));
+ builder.addState(new State("TestingState1"));
+ builder.addState(new State("TestingState2"));
+ builder.addState(new State("TestingState3"));
+ builder.addTransition(
+ new State("TestingState1"), new Event("TestingEvent1"), new State("TestingState2"));
+
+ metadata = builder.build();
+ }
+
+ @Test
+ public void getStates() throws Exception {
+ Assert.assertEquals("Should return proper States",
+ Whitebox.getInternalState(builder, "states"), metadata.getStates());
+ }
+
+ @Test
+ public void getEvents() throws Exception {
+ Assert.assertEquals("Should return proper Events",
+ Whitebox.getInternalState(builder, "events"), metadata.getEvents());
+ }
+
+}
diff --git a/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/StateMachineResponseTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/StateMachineResponseTest.java
new file mode 100644
index 000000000..183b7f5af
--- /dev/null
+++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/StateMachineResponseTest.java
@@ -0,0 +1,71 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.statemachine.objects;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.internal.util.reflection.Whitebox;
+
+public class StateMachineResponseTest {
+ private StateMachineResponse stateMachineResponse = new StateMachineResponse();
+
+ @Test
+ public void testConstructor() {
+ StateMachineResponse stateMachineResponse = new StateMachineResponse();
+ Assert.assertTrue("Do not: no change to nextState",
+ Whitebox.getInternalState(stateMachineResponse, "nextState") == null);
+ Assert.assertTrue("Do not: no change to response",
+ Whitebox.getInternalState(stateMachineResponse, "response") == null);
+ }
+
+ @Test
+ public void testGetAndSetNextState() throws Exception {
+ stateMachineResponse.setNextState(null);
+ Assert.assertTrue("internal nextState should be null",
+ Whitebox.getInternalState(stateMachineResponse, "nextState") == null);
+ Assert.assertTrue("should return null", stateMachineResponse.getNextState() == null);
+
+ State state = new State("TestingState");
+ stateMachineResponse.setNextState(state);
+ Assert.assertEquals("internal nextState should be the state",
+ state, Whitebox.getInternalState(stateMachineResponse, "nextState"));
+ Assert.assertEquals("should return the state", state, stateMachineResponse.getNextState());
+ }
+
+ @Test
+ public void testGetAndSetResponse() throws Exception {
+ stateMachineResponse.setResponse(null);
+ Assert.assertTrue("internal response should be null",
+ Whitebox.getInternalState(stateMachineResponse, "response") == null);
+ Assert.assertTrue("should return null", stateMachineResponse.getResponse() == null);
+
+ Response response = Response.NO_STATE_CHANGE;
+ stateMachineResponse.setResponse(response);
+ Assert.assertEquals("internal response should be the response",
+ response, Whitebox.getInternalState(stateMachineResponse, "response"));
+ Assert.assertEquals("should return the response", response, stateMachineResponse.getResponse());
+ }
+
+}
diff --git a/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/StateTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/StateTest.java
new file mode 100644
index 000000000..601754edf
--- /dev/null
+++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/StateTest.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.statemachine.objects;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.internal.util.reflection.Whitebox;
+
+import java.util.List;
+
+public class StateTest {
+ private final String STATE_NAME = "Starting";
+ private State state = new State(STATE_NAME);
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testConstructor() {
+ State state = new State(STATE_NAME);
+ Assert.assertEquals("Should set stateName",
+ STATE_NAME, Whitebox.getInternalState(state, "stateName"));
+ Assert.assertEquals("Should set hash code",
+ STATE_NAME.toLowerCase().hashCode(), (int)Whitebox.getInternalState(state, "hashCode"));
+ List<Transition> transitions = (List<Transition>) Whitebox.getInternalState(state, "transitions");
+ Assert.assertTrue("Should initialized transtiions",
+ transitions != null && transitions.isEmpty());
+ }
+
+ @Test
+ public void testHashCode() throws Exception {
+ Assert.assertEquals("Should return proper hash code",
+ STATE_NAME.toLowerCase().hashCode(), state.hashCode());
+ }
+
+ @Test
+ public void testEquals() throws Exception {
+ Assert.assertFalse("should return false for null", state.equals(null));
+ Assert.assertFalse("should return false for object", state.equals(new Event(STATE_NAME)));
+ Assert.assertFalse("should return false for different event",
+ state.equals(new Event("Another")));
+ Assert.assertTrue("should return true", state.equals(new State(STATE_NAME)));
+ Assert.assertTrue("should return true (lower case)", state.equals(new State(STATE_NAME.toLowerCase())));
+ }
+
+ @Test
+ public void testGetStateName() throws Exception {
+ Assert.assertEquals("Should return STATE_NAME", STATE_NAME, state.getStateName());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testAddAndGetTransition() throws Exception {
+ Transition transition1 = new Transition(new Event("event1"), new State("state2"));
+ List<Transition> transitions = (List<Transition>) Whitebox.getInternalState(state, "transitions");
+ Assert.assertFalse("should not have transition1", transitions.contains(transition1));
+ state.addTransition(transition1);
+ transitions = (List<Transition>) Whitebox.getInternalState(state, "transitions");
+ Assert.assertTrue("should have added transition1", transitions.contains(transition1));
+ Assert.assertEquals("Should return transitions", transitions, state.getTransitions());
+
+ state.addTransition(null);
+ Assert.assertEquals("Should not change transitions", transitions,
+ Whitebox.getInternalState(state, "transitions"));
+ }
+
+ @Test
+ public void testToString() throws Exception {
+ Assert.assertEquals("Should return STATE_NAME", STATE_NAME, state.toString());
+ }
+}
diff --git a/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/TransitionTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/TransitionTest.java
new file mode 100644
index 000000000..da69d723c
--- /dev/null
+++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/TransitionTest.java
@@ -0,0 +1,57 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.statemachine.objects;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.internal.util.reflection.Whitebox;
+
+public class TransitionTest {
+ private final State state = new State("TestingState");
+ private final Event event = new Event("TestingEvent");
+ private Transition transition = new Transition(event, state);
+
+ @Test
+ public void testConstructor() {
+ transition = new Transition(event, state);
+ Assert.assertEquals("Should set event",
+ event, Whitebox.getInternalState(transition, "event"));
+ Assert.assertEquals("Should set nextState",
+ state, Whitebox.getInternalState(transition, "nextState"));
+ }
+
+ @Test
+ public void testGetEvent() throws Exception {
+ Assert.assertEquals("Should return internal event",
+ Whitebox.getInternalState(transition, "event"), transition.getEvent());
+ }
+
+ @Test
+ public void testGetNextState() throws Exception {
+ Assert.assertEquals("Should return internal nextState",
+ Whitebox.getInternalState(transition, "nextState"), transition.getNextState());
+ }
+
+}