diff options
Diffstat (limited to 'appc-lifecycle-management/state-machine-lib/src/test/java')
10 files changed, 709 insertions, 0 deletions
diff --git a/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/StateMachineFactoryTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/StateMachineFactoryTest.java new file mode 100644 index 000000000..f75e04d6a --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/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.openecomp.appc.statemachine.impl; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.appc.statemachine.StateMachine; +import org.openecomp.appc.statemachine.objects.Event; +import org.openecomp.appc.statemachine.objects.State; +import org.openecomp.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/openecomp/appc/statemachine/impl/StateMachineImplTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/StateMachineImplTest.java new file mode 100644 index 000000000..16a489aca --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/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.openecomp.appc.statemachine.impl; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.internal.util.reflection.Whitebox; +import org.openecomp.appc.exceptions.InvalidInputException; +import org.openecomp.appc.statemachine.objects.Event; +import org.openecomp.appc.statemachine.objects.Response; +import org.openecomp.appc.statemachine.objects.State; +import org.openecomp.appc.statemachine.objects.StateMachineMetadata; +import org.openecomp.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/openecomp/appc/statemachine/impl/readers/AppcOamMetaDataReaderTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/readers/AppcOamMetaDataReaderTest.java new file mode 100644 index 000000000..6073caa52 --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/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.openecomp.appc.statemachine.impl.readers; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.appc.statemachine.objects.Event; +import org.openecomp.appc.statemachine.objects.State; +import org.openecomp.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/openecomp/appc/statemachine/impl/readers/VnfMetaDataReaderTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/readers/VnfMetaDataReaderTest.java new file mode 100644 index 000000000..b8b623f12 --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/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.openecomp.appc.statemachine.impl.readers; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openecomp.appc.lifecyclemanager.objects.VNFOperationOutcome; +import org.openecomp.appc.statemachine.objects.Event; +import org.openecomp.appc.statemachine.objects.State; +import org.openecomp.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/openecomp/appc/statemachine/objects/EventTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/EventTest.java new file mode 100644 index 000000000..e646bd260 --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/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.openecomp.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/openecomp/appc/statemachine/objects/ResponseTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/ResponseTest.java new file mode 100644 index 000000000..b9f955f0d --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/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.openecomp.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/openecomp/appc/statemachine/objects/StateMachineMetadataTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/StateMachineMetadataTest.java new file mode 100644 index 000000000..96c411061 --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/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.openecomp.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/openecomp/appc/statemachine/objects/StateMachineResponseTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/StateMachineResponseTest.java new file mode 100644 index 000000000..c974ea067 --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/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.openecomp.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/openecomp/appc/statemachine/objects/StateTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/StateTest.java new file mode 100644 index 000000000..4e95d0a90 --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/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.openecomp.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/openecomp/appc/statemachine/objects/TransitionTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/TransitionTest.java new file mode 100644 index 000000000..d948c15e4 --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/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.openecomp.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()); + } + +} |