From 14ee9cc1ceb81bd6fe963e4d3580595830885714 Mon Sep 17 00:00:00 2001 From: Dilip kumar Pampana Date: Wed, 10 Jan 2018 10:26:15 -0500 Subject: Life Cycle Managment Updates Issue-ID: APPC-349 Change-Id: Ifdb7bf973c08374bea43c298005d88f2a9d15dd0 Signed-off-by: Dilip kumar Pampana --- .../org/onap/appc/statemachine/impl/StateMachineImpl.java | 14 +++++++++----- .../java/org/onap/appc/statemachine/objects/State.java | 3 ++- .../appc/statemachine/impl/StateMachineFactoryTest.java | 2 +- .../onap/appc/statemachine/impl/StateMachineImplTest.java | 3 ++- 4 files changed, 14 insertions(+), 8 deletions(-) (limited to 'appc-lifecycle-management/state-machine-lib') diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineImpl.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineImpl.java index b56250708..75864a9ba 100644 --- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineImpl.java +++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineImpl.java @@ -25,6 +25,7 @@ package org.onap.appc.statemachine.impl; import java.util.HashSet; +import java.util.List; import java.util.Set; import org.onap.appc.exceptions.InvalidInputException; @@ -40,8 +41,8 @@ import org.onap.appc.statemachine.objects.Transition; * Implementation of StateMachine */ public class StateMachineImpl implements StateMachine { - private static final String invalidInputFormat = "VNF State or incoming event is invalid. State = %s event = %s"; - static final String toStringFormat = "StateMachineImpl{states=%s, events=%s}"; + private static final String INVALID_INPUT_FORMAT = "VNF State or incoming event is invalid. State = %s event = %s"; + static final String TO_STRING_FORMAT = "StateMachineImpl{states=%s, events=%s}"; private final Set states; private final Set events; @@ -57,25 +58,28 @@ public class StateMachineImpl implements StateMachine { public StateMachineResponse handleEvent(State inputState, Event event) throws InvalidInputException{ if(!validateInputs(inputState,event)){ - throw new InvalidInputException(String.format(invalidInputFormat, inputState, event)); + throw new InvalidInputException(String.format(INVALID_INPUT_FORMAT, inputState, event)); } StateMachineResponse response = new StateMachineResponse(); State currentState = null; State nextState = null; - for(State stateInSet:states){ + for(State stateInSet : states){ if(stateInSet.equals(inputState)){ currentState = stateInSet; break; } } if (currentState != null) { + List transitions = currentState.getTransitions(); + if (transitions != null) { for (Transition transition : currentState.getTransitions()) { if (event.equals(transition.getEvent())) { nextState = transition.getNextState(); } } } + } if(nextState == null){ response.setResponse(Response.NO_TRANSITION_DEFINED); } @@ -98,6 +102,6 @@ public class StateMachineImpl implements StateMachine { @Override public String toString() { - return String.format(toStringFormat, states, events); + return String.format(TO_STRING_FORMAT, states, events); } } diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/State.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/State.java index 117cd76c0..8f099b616 100644 --- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/State.java +++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/State.java @@ -67,9 +67,10 @@ public class State { } void addTransition(Transition transition) { + if (transition != null) { this.transitions.add(transition); } - + } public List getTransitions() { return transitions; } 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 index e35482e45..f0867ae5f 100644 --- 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 @@ -48,7 +48,7 @@ public class StateMachineFactoryTest { new State("TestingState1"), new Event("TestingEvent1"), new State("TestingState2")); metadata = builder.build(); - } + } @Test public void testGetStateMachine() throws Exception { 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 index a4a8b9fcc..6de952e2b 100644 --- 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 @@ -36,6 +36,7 @@ import org.onap.appc.statemachine.objects.StateMachineMetadata; import org.onap.appc.statemachine.objects.StateMachineResponse; public class StateMachineImplTest { + private StateMachineMetadata.StateMachineMetadataBuilder builder; private StateMachineMetadata metadata; private StateMachineImpl stateMachine; @@ -100,7 +101,7 @@ public class StateMachineImplTest { @Test public void testToString() throws Exception { Assert.assertEquals( - String.format(stateMachine.toStringFormat, metadata.getStates(), metadata.getEvents()), + String.format(stateMachine.TO_STRING_FORMAT, metadata.getStates(), metadata.getEvents()), stateMachine.toString()); } -- cgit 1.2.3-korg