aboutsummaryrefslogtreecommitdiffstats
path: root/appc-lifecycle-management/state-machine-lib
diff options
context:
space:
mode:
authorDilip kumar Pampana <dp583p@att.com>2018-01-10 10:26:15 -0500
committerSkip Wonnell <skip@att.com>2018-01-10 16:47:56 +0000
commit14ee9cc1ceb81bd6fe963e4d3580595830885714 (patch)
treed3d12b05bffd535bb0c98a1bf1d1309478d49529 /appc-lifecycle-management/state-machine-lib
parent40bae6d46b1fc0d91da8b16d07b145c86ecf7c0c (diff)
Life Cycle Managment Updates
Issue-ID: APPC-349 Change-Id: Ifdb7bf973c08374bea43c298005d88f2a9d15dd0 Signed-off-by: Dilip kumar Pampana <dp583p@att.com>
Diffstat (limited to 'appc-lifecycle-management/state-machine-lib')
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineImpl.java14
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/State.java3
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/StateMachineFactoryTest.java2
-rw-r--r--appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/StateMachineImplTest.java3
4 files changed, 14 insertions, 8 deletions
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<State> states;
private final Set<Event> 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<Transition> 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<Transition> 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());
}