From 781b1a6df324419c846c84ea983c18fc8362bfd3 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:19:06 -0800 Subject: 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 Issue-ID: APPC-13 --- .../org/onap/appc/statemachine/StateMachine.java | 45 ++ .../appc/statemachine/StateMetaDataReader.java | 31 ++ .../statemachine/impl/StateMachineFactory.java | 42 ++ .../appc/statemachine/impl/StateMachineImpl.java | 103 +++++ .../impl/readers/AppcOamMetaDataReader.java | 113 +++++ .../statemachine/impl/readers/AppcOamStates.java | 56 +++ .../impl/readers/VnfMetaDataReader.java | 493 +++++++++++++++++++++ .../org/onap/appc/statemachine/objects/Event.java | 67 +++ .../onap/appc/statemachine/objects/Response.java | 39 ++ .../org/onap/appc/statemachine/objects/State.java | 81 ++++ .../statemachine/objects/StateMachineMetadata.java | 78 ++++ .../statemachine/objects/StateMachineResponse.java | 51 +++ .../onap/appc/statemachine/objects/Transition.java | 51 +++ .../openecomp/appc/statemachine/StateMachine.java | 45 -- .../appc/statemachine/StateMetaDataReader.java | 31 -- .../statemachine/impl/StateMachineFactory.java | 42 -- .../appc/statemachine/impl/StateMachineImpl.java | 103 ----- .../impl/readers/AppcOamMetaDataReader.java | 113 ----- .../statemachine/impl/readers/AppcOamStates.java | 56 --- .../impl/readers/VnfMetaDataReader.java | 493 --------------------- .../openecomp/appc/statemachine/objects/Event.java | 67 --- .../appc/statemachine/objects/Response.java | 39 -- .../openecomp/appc/statemachine/objects/State.java | 81 ---- .../statemachine/objects/StateMachineMetadata.java | 78 ---- .../statemachine/objects/StateMachineResponse.java | 51 --- .../appc/statemachine/objects/Transition.java | 51 --- .../statemachine/impl/StateMachineFactoryTest.java | 59 +++ .../statemachine/impl/StateMachineImplTest.java | 107 +++++ .../impl/readers/AppcOamMetaDataReaderTest.java | 74 ++++ .../impl/readers/AppcOamStatesTest.java | 71 +++ .../impl/readers/VnfMetaDataReaderTest.java | 79 ++++ .../onap/appc/statemachine/objects/EventTest.java | 70 +++ .../appc/statemachine/objects/ResponseTest.java | 40 ++ .../objects/StateMachineMetadataTest.java | 61 +++ .../objects/StateMachineResponseTest.java | 71 +++ .../onap/appc/statemachine/objects/StateTest.java | 91 ++++ .../appc/statemachine/objects/TransitionTest.java | 57 +++ .../statemachine/impl/StateMachineFactoryTest.java | 59 --- .../statemachine/impl/StateMachineImplTest.java | 107 ----- .../impl/readers/AppcOamMetaDataReaderTest.java | 74 ---- .../impl/readers/AppcOamStatesTest.java | 71 --- .../impl/readers/VnfMetaDataReaderTest.java | 79 ---- .../appc/statemachine/objects/EventTest.java | 70 --- .../appc/statemachine/objects/ResponseTest.java | 40 -- .../objects/StateMachineMetadataTest.java | 61 --- .../objects/StateMachineResponseTest.java | 71 --- .../appc/statemachine/objects/StateTest.java | 91 ---- .../appc/statemachine/objects/TransitionTest.java | 57 --- 48 files changed, 2030 insertions(+), 2030 deletions(-) create mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/StateMachine.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/StateMetaDataReader.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineFactory.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineImpl.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/readers/AppcOamMetaDataReader.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/readers/AppcOamStates.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/readers/VnfMetaDataReader.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/Event.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/Response.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/State.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/StateMachineMetadata.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/StateMachineResponse.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/Transition.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/StateMachine.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/StateMetaDataReader.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/StateMachineFactory.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/StateMachineImpl.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/readers/AppcOamMetaDataReader.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/readers/AppcOamStates.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/readers/VnfMetaDataReader.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/Event.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/Response.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/State.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/StateMachineMetadata.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/StateMachineResponse.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/Transition.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/StateMachineFactoryTest.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/StateMachineImplTest.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/readers/AppcOamMetaDataReaderTest.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/readers/AppcOamStatesTest.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/impl/readers/VnfMetaDataReaderTest.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/EventTest.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/ResponseTest.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/StateMachineMetadataTest.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/StateMachineResponseTest.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/StateTest.java create mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/onap/appc/statemachine/objects/TransitionTest.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/StateMachineFactoryTest.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/StateMachineImplTest.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/readers/AppcOamMetaDataReaderTest.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/readers/AppcOamStatesTest.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/readers/VnfMetaDataReaderTest.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/EventTest.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/ResponseTest.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/StateMachineMetadataTest.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/StateMachineResponseTest.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/StateTest.java delete mode 100644 appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/TransitionTest.java (limited to 'appc-lifecycle-management/state-machine-lib/src') diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/StateMachine.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/StateMachine.java new file mode 100644 index 000000000..52350852e --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/StateMachine.java @@ -0,0 +1,45 @@ +/*- + * ============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; + +import org.onap.appc.exceptions.InvalidInputException; +import org.onap.appc.statemachine.objects.Event; +import org.onap.appc.statemachine.objects.State; +import org.onap.appc.statemachine.objects.StateMachineResponse; + +/** + * Interface of the StateMachine + */ +public interface StateMachine { + /** + * Handle event + * @param currentState the current State which the event should be handled from + * @param event the Event that needs to be handled + * @return StateMachineResponse + * @throws InvalidInputException + * when the passed in currentState and event are not predefined or no relevant transition + */ + StateMachineResponse handleEvent(State currentState, Event event) throws InvalidInputException; +} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/StateMetaDataReader.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/StateMetaDataReader.java new file mode 100644 index 000000000..fe2b193e1 --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/StateMetaDataReader.java @@ -0,0 +1,31 @@ +/*- + * ============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; + +import org.onap.appc.statemachine.objects.StateMachineMetadata; + +public interface StateMetaDataReader { + StateMachineMetadata readMetadata(); +} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineFactory.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineFactory.java new file mode 100644 index 000000000..bfcafeb7d --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineFactory.java @@ -0,0 +1,42 @@ +/*- + * ============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.onap.appc.statemachine.StateMachine; +import org.onap.appc.statemachine.objects.StateMachineMetadata; + +/** + * Factory of StateMachine + */ +public class StateMachineFactory { + + private StateMachineFactory(){ + throw new IllegalAccessError("StateMachineFactory"); + } + + public static StateMachine getStateMachine(StateMachineMetadata metadata){ + return new StateMachineImpl(metadata); + } +} 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 new file mode 100644 index 000000000..b56250708 --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/StateMachineImpl.java @@ -0,0 +1,103 @@ +/*- + * ============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 java.util.HashSet; +import java.util.Set; + +import org.onap.appc.exceptions.InvalidInputException; +import org.onap.appc.statemachine.StateMachine; +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; +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 final Set states; + private final Set events; + + StateMachineImpl(StateMachineMetadata metadata){ + this.states = new HashSet<>(); + this.states.addAll(metadata.getStates()); + this.events = new HashSet<>(); + this.events.addAll(metadata.getEvents()); + } + + @Override + public StateMachineResponse handleEvent(State inputState, Event event) throws InvalidInputException{ + + if(!validateInputs(inputState,event)){ + throw new InvalidInputException(String.format(invalidInputFormat, inputState, event)); + } + + StateMachineResponse response = new StateMachineResponse(); + State currentState = null; + State nextState = null; + for(State stateInSet:states){ + if(stateInSet.equals(inputState)){ + currentState = stateInSet; + break; + } + } + if (currentState != null) { + for (Transition transition : currentState.getTransitions()) { + if (event.equals(transition.getEvent())) { + nextState = transition.getNextState(); + } + } + } + if(nextState == null){ + response.setResponse(Response.NO_TRANSITION_DEFINED); + } + else if(inputState.equals(nextState)){ + response.setResponse(Response.NO_STATE_CHANGE); + } + else{ + response.setResponse(Response.VALID_TRANSITION); + } + response.setNextState(nextState); + return response; + } + + boolean validateInputs(State state,Event event) { + return state != null + && event != null + && this.states.contains(state) + && this.events.contains(event); + } + + @Override + public String toString() { + return String.format(toStringFormat, states, events); + } +} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/readers/AppcOamMetaDataReader.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/readers/AppcOamMetaDataReader.java new file mode 100644 index 000000000..7451cf3af --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/readers/AppcOamMetaDataReader.java @@ -0,0 +1,113 @@ +/*- + * ============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.onap.appc.statemachine.StateMetaDataReader; +import org.onap.appc.statemachine.objects.Event; +import org.onap.appc.statemachine.objects.State; +import org.onap.appc.statemachine.objects.StateMachineMetadata; + +/** + * Reader for APPC OAM MetaData + */ +public class AppcOamMetaDataReader implements StateMetaDataReader { + + /** + * APPC Operation Enum + */ + public enum AppcOperation { + MaintenanceMode, + Restart, + Start, + Stop + } + + @Override + public StateMachineMetadata readMetadata() { + State notInstantiated = new State(AppcOamStates.NotInstantiated.toString()); + State instantiated = new State(AppcOamStates.Instantiated.toString()); + State restarting = new State(AppcOamStates.Restarting.toString()); + State starting = new State(AppcOamStates.Starting.toString()); + State started = new State(AppcOamStates.Started.toString()); + State enteringMaintenanceMode = new State(AppcOamStates.EnteringMaintenanceMode.toString()); + State maintenanceMode = new State(AppcOamStates.MaintenanceMode.toString()); + State error = new State(AppcOamStates.Error.toString()); + State unknown = new State(AppcOamStates.Unknown.toString()); + State stopping = new State(AppcOamStates.Stopping.toString()); + State stopped = new State(AppcOamStates.Stopped.toString()); + + Event start = new Event(AppcOperation.Start.toString()); + Event stop = new Event(AppcOperation.Stop.toString()); + Event maintenanceModeEvent = new Event(AppcOperation.MaintenanceMode.toString()); + Event restart = new Event(AppcOperation.Restart.toString()); + + StateMachineMetadata.StateMachineMetadataBuilder builder = new StateMachineMetadata + .StateMachineMetadataBuilder(); + + builder = builder.addState(notInstantiated); + builder = builder.addState(instantiated); + builder = builder.addState(starting); + builder = builder.addState(started); + builder = builder.addState(error); + builder = builder.addState(unknown); + builder = builder.addState(stopping); + builder = builder.addState(stopped); + builder = builder.addState(enteringMaintenanceMode); + builder = builder.addState(maintenanceMode); + builder = builder.addState(restarting); + + builder = builder.addEvent(start); + builder = builder.addEvent(stop); + builder = builder.addEvent(restart); + builder = builder.addEvent(maintenanceModeEvent); + + /* + * for addTransition: + * param 1: current state; param 2: received command/request; param 3: new transition state + */ + // start + builder = builder.addTransition(stopped, start, starting); + builder = builder.addTransition(maintenanceMode, start, starting); + builder = builder.addTransition(error, start, starting); + // stop + builder = builder.addTransition(started, stop, stopping); + builder = builder.addTransition(starting, stop, stopping); + builder = builder.addTransition(enteringMaintenanceMode, stop, stopping); + builder = builder.addTransition(maintenanceMode, stop, stopping); + builder = builder.addTransition(error, stop, stopping); + // maintenance mode + builder = builder.addTransition( + started, maintenanceModeEvent, enteringMaintenanceMode); + // restart + builder = builder.addTransition(stopped, restart, restarting); + builder = builder.addTransition(starting, restart, restarting); + builder = builder.addTransition(started, restart, restarting); + builder = builder.addTransition(enteringMaintenanceMode, restart, restarting); + builder = builder.addTransition(maintenanceMode, restart, restarting); + builder = builder.addTransition(error, restart, restarting); + + return builder.build(); + } +} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/readers/AppcOamStates.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/readers/AppcOamStates.java new file mode 100644 index 000000000..70a044bfa --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/readers/AppcOamStates.java @@ -0,0 +1,56 @@ +/*- + * ============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.osgi.framework.Bundle; + +public enum AppcOamStates { + EnteringMaintenanceMode(0), + Error(0), + Instantiated(Bundle.INSTALLED), + MaintenanceMode(0), + NotInstantiated(Bundle.UNINSTALLED), + Restarting(0), + Started(Bundle.ACTIVE), + Starting(Bundle.STARTING), + Stopped(Bundle.RESOLVED), + Stopping(Bundle.STOPPING), + Unknown(0); + + int osgiBundleState; + + AppcOamStates(Integer bundleState) { + osgiBundleState = bundleState; + } + + public static AppcOamStates getOamStateFromBundleState(int bundleState) { + for (AppcOamStates aState : values()) { + if (aState.osgiBundleState == bundleState) { + return aState; + } + } + return Unknown; + } +} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/readers/VnfMetaDataReader.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/readers/VnfMetaDataReader.java new file mode 100644 index 000000000..2ba949f38 --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/impl/readers/VnfMetaDataReader.java @@ -0,0 +1,493 @@ +/*- + * ============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.onap.appc.statemachine.StateMetaDataReader; +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; + +/** + * Reader for VNF MetaData + */ +public class VnfMetaDataReader implements StateMetaDataReader { + + /** + * VNF Operations + */ + public enum VNFOperation { + + Configure, Test, HealthCheck, Start, Terminate, Restart, Rebuild, Stop, ConfigModify, + ConfigScaleOut,ConfigRestore,Backup, Snapshot, + SoftwareUpload, LiveUpgrade, Rollback, Sync, Audit, Test_lic, Migrate, Evacuate, + ConfigBackup, ConfigBackupDelete, ConfigExport, + Lock(true), Unlock(true), CheckLock(true), StartApplication,StopApplication; + + private boolean builtIn; + + VNFOperation(boolean builtIn) { + this.builtIn = builtIn; + } + + VNFOperation() { + this(false); + } + } + + /** + * VNF States + */ + enum VNFStates { + Not_Instantiated, Instantiated, Configuring, Configured, Testing, Tested, + Rebuilding, Restarting, Starting, + Error, Running, Unknown, Terminating, Stopping, Stopped, + Backing_Up, Snapshotting, Software_Uploading, Upgrading, + Rollbacking, Licensing, Migrating, Evacuating, + NOT_ORCHESTRATED("NOT ORCHESTRATED"), Created; + + String stateName; + + VNFStates(String name) { + this.stateName = name; + } + + VNFStates() { + this.stateName = name(); + } + + @Override + public String toString() { + return this.stateName; + } + } + + @Override + public StateMachineMetadata readMetadata() { + State notInstantiated = new State(VNFStates.Not_Instantiated.toString()); + State instantiated = new State(VNFStates.Instantiated.toString()); + State configuring = new State(VNFStates.Configuring.toString()); + State configured = new State(VNFStates.Configured.toString()); + State testing = new State(VNFStates.Testing.toString()); + State tested = new State(VNFStates.Tested.toString()); + State rebuilding = new State(VNFStates.Rebuilding.toString()); + State restarting = new State(VNFStates.Restarting.toString()); + State starting = new State(VNFStates.Starting.toString()); + State error = new State(VNFStates.Error.toString()); + State running = new State(VNFStates.Running.toString()); + State unknown = new State(VNFStates.Unknown.toString()); + State terminating = new State(VNFStates.Terminating.toString()); + State stopping = new State(VNFStates.Stopping.toString()); + State stopped = new State(VNFStates.Stopped.toString()); + State notOrchestrated = new State(VNFStates.NOT_ORCHESTRATED.toString()); + + State backingUp = new State(VNFStates.Backing_Up.toString()); + State snapshotting = new State(VNFStates.Snapshotting.toString()); + State softwareUploading = new State(VNFStates.Software_Uploading.toString()); + State upgrading = new State(VNFStates.Upgrading.toString()); + State rollbacking = new State(VNFStates.Rollbacking.toString()); + + State migrating = new State(VNFStates.Migrating.toString()); + State evacuating = new State(VNFStates.Evacuating.toString()); + State created= new State(VNFStates.Created.toString()); + + Event startApplication = new Event(VNFOperation.StartApplication.toString()); + Event configure = new Event(VNFOperation.Configure.toString()); + Event healthcheck = new Event(VNFOperation.HealthCheck.toString()); + Event test = new Event(VNFOperation.Test.toString()); + Event start = new Event(VNFOperation.Start.toString()); + Event terminate = new Event(VNFOperation.Terminate.toString()); + Event restart = new Event(VNFOperation.Restart.toString()); + Event rebuild = new Event(VNFOperation.Rebuild.toString()); + Event stop = new Event(VNFOperation.Stop.toString()); + Event configModify = new Event(VNFOperation.ConfigModify.toString()); + Event configScaleout = new Event(VNFOperation.ConfigScaleOut.toString()); + Event configRestore = new Event(VNFOperation.ConfigRestore.toString()); + Event backup = new Event(VNFOperation.Backup.toString()); + Event snapshot = new Event(VNFOperation.Snapshot.toString()); + Event softwareUpload = new Event(VNFOperation.SoftwareUpload.toString()); + Event liveUpgrade = new Event(VNFOperation.LiveUpgrade.toString()); + Event rollback = new Event(VNFOperation.Rollback.toString()); + Event sync = new Event(VNFOperation.Sync.toString()); + Event audit = new Event(VNFOperation.Audit.toString()); + Event migrate = new Event(VNFOperation.Migrate.toString()); + Event evacuate = new Event(VNFOperation.Evacuate.toString()); + Event configBackup = new Event(VNFOperation.ConfigBackup.toString()); + Event configBackupDelete = new Event(VNFOperation.ConfigBackupDelete.toString()); + Event configExport = new Event(VNFOperation.ConfigExport.toString()); + Event stopApplication= new Event(VNFOperation.StopApplication.toString()); + + Event lock = new Event(VNFOperation.Lock.toString()); + Event unlock = new Event(VNFOperation.Unlock.toString()); + Event checklock = new Event(VNFOperation.CheckLock.toString()); + + Event success = new Event(VNFOperationOutcome.SUCCESS.toString()); + Event failure = new Event(VNFOperationOutcome.FAILURE.toString()); + + + StateMachineMetadata.StateMachineMetadataBuilder builder = + new StateMachineMetadata.StateMachineMetadataBuilder(); + + builder = builder.addState(notInstantiated); + builder = builder.addState(instantiated); + builder = builder.addState(configuring); + builder = builder.addState(configured); + builder = builder.addState(testing); + builder = builder.addState(tested); + builder = builder.addState(rebuilding); + builder = builder.addState(restarting); + builder = builder.addState(starting); + builder = builder.addState(error); + builder = builder.addState(running); + builder = builder.addState(unknown); + builder = builder.addState(terminating); + builder = builder.addState(stopping); + builder = builder.addState(stopped); + + builder = builder.addState(backingUp); + builder = builder.addState(snapshotting); + builder = builder.addState(softwareUploading); + builder = builder.addState(upgrading); + builder = builder.addState(rollbacking); + builder = builder.addState(migrating); + builder = builder.addState(evacuating); + builder = builder.addState(notOrchestrated); + builder = builder.addState(created); + builder = builder.addEvent(startApplication); + builder = builder.addEvent(configure); + builder = builder.addEvent(test); + builder = builder.addEvent(start); + builder = builder.addEvent(terminate); + builder = builder.addEvent(restart); + builder = builder.addEvent(rebuild); + builder = builder.addEvent(success); + builder = builder.addEvent(failure); + builder = builder.addEvent(stop); + builder = builder.addEvent(configModify); + builder = builder.addEvent(configScaleout); + builder = builder.addEvent(configRestore); + builder = builder.addEvent(healthcheck); + builder = builder.addEvent(backup); + builder = builder.addEvent(snapshot); + builder = builder.addEvent(softwareUpload); + builder = builder.addEvent(liveUpgrade); + builder = builder.addEvent(rollback); + builder = builder.addEvent(sync); + builder = builder.addEvent(audit); + builder = builder.addEvent(migrate); + builder = builder.addEvent(evacuate); + builder = builder.addEvent(lock); + builder = builder.addEvent(unlock); + builder = builder.addEvent(checklock); + builder = builder.addEvent(configBackup); + builder = builder.addEvent(configBackupDelete); + builder = builder.addEvent(configExport); + builder = builder.addEvent(stopApplication); + + builder = builder.addTransition(notOrchestrated,configure,configuring); + builder = builder.addTransition(notOrchestrated,test,testing); + builder = builder.addTransition(notOrchestrated,start,starting); + builder = builder.addTransition(notOrchestrated,terminate,terminating); + builder = builder.addTransition(notOrchestrated,restart,restarting); + builder = builder.addTransition(notOrchestrated,rebuild,rebuilding); + builder = builder.addTransition(notOrchestrated,stop,stopping); + builder = builder.addTransition(notOrchestrated,configModify,configuring); + builder = builder.addTransition(notOrchestrated,configScaleout,configuring); + builder = builder.addTransition(notOrchestrated,configRestore,configuring); + builder = builder.addTransition(notOrchestrated,healthcheck,testing); + builder = builder.addTransition(notOrchestrated,backup,backingUp); + builder = builder.addTransition(notOrchestrated,snapshot,snapshotting); + builder = builder.addTransition(notOrchestrated,softwareUpload,softwareUploading); + builder = builder.addTransition(notOrchestrated,liveUpgrade,upgrading); + builder = builder.addTransition(notOrchestrated,rollback,rollbacking); + builder = builder.addTransition(notOrchestrated,migrate,migrating); + builder = builder.addTransition(notOrchestrated,evacuate,evacuating); + builder = builder.addTransition(notOrchestrated,lock,notOrchestrated); + builder = builder.addTransition(notOrchestrated,unlock,notOrchestrated); + builder = builder.addTransition(notOrchestrated,checklock,notOrchestrated); + builder = builder.addTransition(notOrchestrated,startApplication,starting); + builder = builder.addTransition(notOrchestrated,stopApplication,stopping); + builder = builder.addTransition(notOrchestrated,configBackup,notOrchestrated); + + builder = builder.addTransition(created,configure,configuring); + builder = builder.addTransition(created,test,testing); + builder = builder.addTransition(created,start,starting); + builder = builder.addTransition(created,terminate,terminating); + builder = builder.addTransition(created,restart,restarting); + builder = builder.addTransition(created,rebuild,rebuilding); + builder = builder.addTransition(created,stop,stopping); + builder = builder.addTransition(created,configModify,configuring); + builder = builder.addTransition(created,configScaleout,configuring); + builder = builder.addTransition(created,configRestore,configuring); + builder = builder.addTransition(created,healthcheck,testing); + builder = builder.addTransition(created,backup,backingUp); + builder = builder.addTransition(created,snapshot,snapshotting); + builder = builder.addTransition(created,softwareUpload,softwareUploading); + builder = builder.addTransition(created,liveUpgrade,upgrading); + builder = builder.addTransition(created,rollback,rollbacking); + builder = builder.addTransition(created,migrate,migrating); + builder = builder.addTransition(created,evacuate,evacuating); + builder = builder.addTransition(created,lock,created); + builder = builder.addTransition(created,unlock,created); + builder = builder.addTransition(created,checklock,created); + builder = builder.addTransition(created,startApplication,starting); + builder = builder.addTransition(created,stopApplication,stopping); + builder = builder.addTransition(created,configBackup,created); + + builder = builder.addTransition(instantiated,configure,configuring); + builder = builder.addTransition(instantiated,test,testing); + builder = builder.addTransition(instantiated,start,starting); + builder = builder.addTransition(instantiated,terminate,terminating); + builder = builder.addTransition(instantiated,restart,restarting); + builder = builder.addTransition(instantiated,rebuild,rebuilding); + builder = builder.addTransition(instantiated,stop,stopping); + builder = builder.addTransition(instantiated,configModify,configuring); + builder = builder.addTransition(instantiated,configScaleout,configuring); + builder = builder.addTransition(instantiated,configRestore,configuring); + builder = builder.addTransition(instantiated,healthcheck,testing); + builder = builder.addTransition(instantiated,backup,backingUp); + builder = builder.addTransition(instantiated,snapshot,snapshotting); + builder = builder.addTransition(instantiated,softwareUpload,softwareUploading); + builder = builder.addTransition(instantiated,liveUpgrade,upgrading); + builder = builder.addTransition(instantiated,rollback,rollbacking); + builder = builder.addTransition(instantiated,migrate,migrating); + builder = builder.addTransition(instantiated,evacuate,evacuating); + builder = builder.addTransition(instantiated,lock,instantiated); + builder = builder.addTransition(instantiated,unlock,instantiated); + builder = builder.addTransition(instantiated,checklock,instantiated); + + builder = builder.addTransition(configured,configure,configuring); + builder = builder.addTransition(configured,test,testing); + builder = builder.addTransition(configured,start,starting); + builder = builder.addTransition(configured,terminate,terminating); + builder = builder.addTransition(configured,restart,restarting); + builder = builder.addTransition(configured,rebuild,rebuilding); + builder = builder.addTransition(configured,stop,stopping); + builder = builder.addTransition(configured,configModify,configuring); + builder = builder.addTransition(configured,configScaleout,configuring); + builder = builder.addTransition(configured,configRestore,configuring); + builder = builder.addTransition(configured,healthcheck,testing); + builder = builder.addTransition(configured,backup,backingUp); + builder = builder.addTransition(configured,snapshot,snapshotting); + builder = builder.addTransition(configured,softwareUpload,softwareUploading); + builder = builder.addTransition(configured,liveUpgrade,upgrading); + builder = builder.addTransition(configured,rollback,rollbacking); + builder = builder.addTransition(configured,sync,configured); + builder = builder.addTransition(configured,audit,configured); + builder = builder.addTransition(configured,migrate,migrating); + builder = builder.addTransition(configured,evacuate,evacuating); + builder = builder.addTransition(configured,lock,configured); + builder = builder.addTransition(configured,unlock,configured); + builder = builder.addTransition(configured,checklock,configured); + builder = builder.addTransition(configured,configBackup,configured); + builder = builder.addTransition(configured,configBackupDelete,configured); + builder = builder.addTransition(configured,configExport,configured); + builder = builder.addTransition(configured,stopApplication,stopping); + + builder = builder.addTransition(tested,configure,configuring); + builder = builder.addTransition(tested,test,testing); + builder = builder.addTransition(tested,start,starting); + builder = builder.addTransition(tested,terminate,terminating); + builder = builder.addTransition(tested,restart,restarting); + builder = builder.addTransition(tested,rebuild,rebuilding); + builder = builder.addTransition(tested,stop,stopping); + builder = builder.addTransition(tested,configModify,configuring); + builder = builder.addTransition(tested,configScaleout,configuring); + builder = builder.addTransition(tested,configRestore,configuring); + builder = builder.addTransition(tested,healthcheck,testing); + builder = builder.addTransition(tested,backup,backingUp); + builder = builder.addTransition(tested,snapshot,snapshotting); + builder = builder.addTransition(tested,softwareUpload,softwareUploading); + builder = builder.addTransition(tested,liveUpgrade,upgrading); + builder = builder.addTransition(tested,rollback,rollbacking); + builder = builder.addTransition(tested,sync,tested); + builder = builder.addTransition(tested,audit,tested); + builder = builder.addTransition(tested,migrate,migrating); + builder = builder.addTransition(tested,evacuate,evacuating); + builder = builder.addTransition(tested,lock,tested); + builder = builder.addTransition(tested,unlock,tested); + builder = builder.addTransition(tested,checklock,tested); + builder = builder.addTransition(tested,configBackup,tested); + builder = builder.addTransition(tested,configBackupDelete,tested); + builder = builder.addTransition(tested,configExport,tested); + builder = builder.addTransition(tested,stopApplication,stopping); + + builder = builder.addTransition(running,configure,configuring); + builder = builder.addTransition(running,test,testing); + builder = builder.addTransition(running,start,starting); + builder = builder.addTransition(running,terminate,terminating); + builder = builder.addTransition(running,restart,restarting); + builder = builder.addTransition(running,rebuild,rebuilding); + builder = builder.addTransition(running,stop,stopping); + builder = builder.addTransition(running,configModify,configuring); + builder = builder.addTransition(running,configScaleout,configuring); + builder = builder.addTransition(running,configRestore,configuring); + builder = builder.addTransition(running,healthcheck,testing); + builder = builder.addTransition(running,backup,backingUp); + builder = builder.addTransition(running,snapshot,snapshotting); + builder = builder.addTransition(running,softwareUpload,softwareUploading); + builder = builder.addTransition(running,liveUpgrade,upgrading); + builder = builder.addTransition(running,rollback,rollbacking); + builder = builder.addTransition(running,sync,running); + builder = builder.addTransition(running,audit,running); + builder = builder.addTransition(running,migrate,migrating); + builder = builder.addTransition(running,evacuate,evacuating); + builder = builder.addTransition(running,lock,running); + builder = builder.addTransition(running,unlock,running); + builder = builder.addTransition(running,checklock,running); + builder = builder.addTransition(running,configBackup,running); + builder = builder.addTransition(running,configBackupDelete,running); + builder = builder.addTransition(running,configExport,running); + builder = builder.addTransition(running,stopApplication,stopping); + + builder = builder.addTransition(error,configure,configuring); + builder = builder.addTransition(error,test,testing); + builder = builder.addTransition(error,start,starting); + builder = builder.addTransition(error,terminate,terminating); + builder = builder.addTransition(error,restart,restarting); + builder = builder.addTransition(error,rebuild,rebuilding); + builder = builder.addTransition(error,stop,stopping); + builder = builder.addTransition(error,configModify,configuring); + builder = builder.addTransition(error,configScaleout,configuring); + builder = builder.addTransition(error,configRestore,configuring); + builder = builder.addTransition(error,healthcheck,testing); + builder = builder.addTransition(error,backup,backingUp); + builder = builder.addTransition(error,snapshot,snapshotting); + builder = builder.addTransition(error,softwareUpload,softwareUploading); + builder = builder.addTransition(error,liveUpgrade,upgrading); + builder = builder.addTransition(error,rollback,rollbacking); + builder = builder.addTransition(error,sync,error); + builder = builder.addTransition(error,audit,error); + builder = builder.addTransition(error,migrate,migrating); + builder = builder.addTransition(error,evacuate,evacuating); + builder = builder.addTransition(error,lock,error); + builder = builder.addTransition(error,unlock,error); + builder = builder.addTransition(error,checklock,error); + builder = builder.addTransition(error,configBackup,error); + builder = builder.addTransition(error,configBackupDelete,error); + builder = builder.addTransition(error,configExport,error); + builder = builder.addTransition(error,stopApplication,stopping); + + builder = builder.addTransition(unknown,configure,configuring); + builder = builder.addTransition(unknown,test,testing); + builder = builder.addTransition(unknown,start,starting); + builder = builder.addTransition(unknown,terminate,terminating); + builder = builder.addTransition(unknown,restart,restarting); + builder = builder.addTransition(unknown,rebuild,rebuilding); + builder = builder.addTransition(unknown,stop,stopping); + builder = builder.addTransition(unknown,configModify,configuring); + builder = builder.addTransition(unknown,configScaleout,configuring); + builder = builder.addTransition(unknown,configRestore,configuring); + builder = builder.addTransition(unknown,healthcheck,testing); + builder = builder.addTransition(unknown,backup,backingUp); + builder = builder.addTransition(unknown,snapshot,snapshotting); + builder = builder.addTransition(unknown,softwareUpload,softwareUploading); + builder = builder.addTransition(unknown,liveUpgrade,upgrading); + builder = builder.addTransition(unknown,rollback,rollbacking); + builder = builder.addTransition(unknown,sync,unknown); + builder = builder.addTransition(unknown,audit,unknown); + builder = builder.addTransition(unknown,migrate,migrating); + builder = builder.addTransition(unknown,evacuate,evacuating); + builder = builder.addTransition(unknown,lock,unknown); + builder = builder.addTransition(unknown,unlock,unknown); + builder = builder.addTransition(unknown,checklock,unknown); + builder = builder.addTransition(unknown,configBackup,unknown); + builder = builder.addTransition(unknown,configBackupDelete,unknown); + builder = builder.addTransition(unknown,configExport,unknown); + builder = builder.addTransition(unknown,stopApplication,stopping); + + builder = builder.addTransition(stopped,configure,configuring); + builder = builder.addTransition(stopped,test,testing); + builder = builder.addTransition(stopped,start,starting); + builder = builder.addTransition(stopped,terminate,terminating); + builder = builder.addTransition(stopped,restart,restarting); + builder = builder.addTransition(stopped,rebuild,rebuilding); + builder = builder.addTransition(stopped,configModify,configuring); + builder = builder.addTransition(stopped,configScaleout,configuring); + builder = builder.addTransition(stopped,configRestore,configuring); + builder = builder.addTransition(stopped,healthcheck,testing); + builder = builder.addTransition(stopped,backup,backingUp); + builder = builder.addTransition(stopped,snapshot,snapshotting); + builder = builder.addTransition(stopped,softwareUpload,softwareUploading); + builder = builder.addTransition(stopped,liveUpgrade,upgrading); + builder = builder.addTransition(stopped,rollback,rollbacking); + builder = builder.addTransition(stopped,migrate,migrating); + builder = builder.addTransition(stopped,evacuate,evacuating); + builder = builder.addTransition(stopped,lock,stopped); + builder = builder.addTransition(stopped,unlock,stopped); + builder = builder.addTransition(stopped,checklock,stopped); + + builder = builder.addTransition(configuring,success,configured); + builder = builder.addTransition(configuring,failure,error); + + builder = builder.addTransition(testing,success,tested); + builder = builder.addTransition(testing,failure,error); + + builder = builder.addTransition(restarting,success,running); + builder = builder.addTransition(restarting,failure,error); + + builder = builder.addTransition(starting,success,running); + builder = builder.addTransition(starting,failure,error); + + builder = builder.addTransition(terminating,success,notInstantiated); + builder = builder.addTransition(terminating,failure,error); + + builder = builder.addTransition(rebuilding,success,running); + builder = builder.addTransition(rebuilding,failure,error); + + builder = builder.addTransition(stopping,success,stopped); + builder = builder.addTransition(stopping,failure,error); + + builder = builder.addTransition(backingUp,success,running); + builder = builder.addTransition(backingUp,failure,error); + + builder = builder.addTransition(snapshotting,success,running); + builder = builder.addTransition(snapshotting,failure,error); + + builder = builder.addTransition(softwareUploading,success,running); + builder = builder.addTransition(softwareUploading,failure,error); + + builder = builder.addTransition(upgrading,success,running); + builder = builder.addTransition(upgrading,failure,error); + + builder = builder.addTransition(rollbacking,success,running); + builder = builder.addTransition(rollbacking,failure,error); + + builder = builder.addTransition(migrating,success,running); + builder = builder.addTransition(migrating,failure,error); + + builder = builder.addTransition(evacuating,success,running); + builder = builder.addTransition(evacuating,failure,error); + + + builder = builder.addTransition(configured,startApplication,starting); + builder = builder.addTransition(tested,startApplication,starting); + builder = builder.addTransition(error,startApplication,starting); + builder = builder.addTransition(unknown,startApplication,starting); + builder = builder.addTransition(running,startApplication,starting); + + return builder.build(); + } +} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/Event.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/Event.java new file mode 100644 index 000000000..5e9b7c813 --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/Event.java @@ -0,0 +1,67 @@ +/*- + * ============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; + +/** + * Event Object + */ +public class Event{ + private final String eventName; + private final int hashCode; + + /** + * Constructor + * @param eventName String of the event name + */ + public Event(String eventName) { + this.eventName = eventName; + this.hashCode = this.eventName.toLowerCase().hashCode(); + } + + @Override + public int hashCode() { + return hashCode; + } + @Override + public boolean equals(Object obj) { + if(obj == null){ + return false; + } + if(!(obj instanceof Event)){ + return false; + } + Event event = (Event)obj; + return this.eventName.equalsIgnoreCase(event.getEventName()); + } + + public String getEventName() { + return eventName; + } + + @Override + public String toString(){ + return this.eventName; + } +} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/Response.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/Response.java new file mode 100644 index 000000000..49b6c909b --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/Response.java @@ -0,0 +1,39 @@ +/*- + * ============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; + +/** + * Response object + */ +public enum Response { + NO_TRANSITION_DEFINED, + NO_STATE_CHANGE, + VALID_TRANSITION; + + @Override + public String toString(){ + return this.name(); + } +} 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 new file mode 100644 index 000000000..117cd76c0 --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/State.java @@ -0,0 +1,81 @@ +/*- + * ============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 java.util.ArrayList; +import java.util.List; + +/** + * State Object + */ +public class State { + private final String stateName; + private final int hashCode; + private final List transitions; + + /** + * Constructor + * @param stateName String of the state name + */ + public State(String stateName) { + this.stateName = stateName; + this.hashCode = stateName.toLowerCase().hashCode(); + this.transitions = new ArrayList<>(); + } + + @Override + public int hashCode() { + return hashCode; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (!(obj instanceof State)) { + return false; + } + State state = (State)obj; + return this.stateName.equalsIgnoreCase(state.getStateName()); + } + + public String getStateName() { + return stateName; + } + + void addTransition(Transition transition) { + this.transitions.add(transition); + } + + public List getTransitions() { + return transitions; + } + + @Override + public String toString() { + return this.stateName; + } +} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/StateMachineMetadata.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/StateMachineMetadata.java new file mode 100644 index 000000000..02088b26e --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/StateMachineMetadata.java @@ -0,0 +1,78 @@ +/*- + * ============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 java.util.HashSet; +import java.util.Set; + +public class StateMachineMetadata { + + private Set states; + private Set events; + + private StateMachineMetadata(StateMachineMetadataBuilder builder){ + states = builder.states; + events = builder.events; + } + + public Set getStates() { + return states; + } + + public Set getEvents() { + return events; + } + + public static class StateMachineMetadataBuilder{ + + private Set states; + private Set events; + + public StateMachineMetadataBuilder(){ + states = new HashSet<>(); + events = new HashSet<>(); + } + + public StateMachineMetadataBuilder addState(State state){ + this.states.add(state); + return this; + } + + public StateMachineMetadataBuilder addEvent(Event event){ + this.events.add(event); + return this; + } + + public StateMachineMetadataBuilder addTransition(State currentState,Event event,State nextState){ + Transition transition = new Transition(event,nextState); + currentState.addTransition(transition); + return this; + } + + public StateMachineMetadata build(){ + return new StateMachineMetadata(this); + } + } +} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/StateMachineResponse.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/StateMachineResponse.java new file mode 100644 index 000000000..9fc401527 --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/StateMachineResponse.java @@ -0,0 +1,51 @@ +/*- + * ============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; + + +public class StateMachineResponse { + private State nextState; + private Response response; + + public StateMachineResponse(){ + // do nothing + } + + public State getNextState() { + return nextState; + } + + public Response getResponse() { + return response; + } + + public void setNextState(State nextState) { + this.nextState = nextState; + } + + public void setResponse(Response response) { + this.response = response; + } +} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/Transition.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/Transition.java new file mode 100644 index 000000000..2c6ee6366 --- /dev/null +++ b/appc-lifecycle-management/state-machine-lib/src/main/java/org/onap/appc/statemachine/objects/Transition.java @@ -0,0 +1,51 @@ +/*- + * ============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; + +/** + * Transition Object + */ +public class Transition { + private Event event; + private State nextState; + + /** + * Constructor + * @param event which triggers the transition + * @param nextState of State which indicates the transition targeted state + */ + Transition(Event event, State nextState) { + this.event = event; + this.nextState = nextState; + } + + public Event getEvent() { + return event; + } + + public State getNextState() { + return nextState; + } +} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/StateMachine.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/StateMachine.java deleted file mode 100644 index 52350852e..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/StateMachine.java +++ /dev/null @@ -1,45 +0,0 @@ -/*- - * ============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; - -import org.onap.appc.exceptions.InvalidInputException; -import org.onap.appc.statemachine.objects.Event; -import org.onap.appc.statemachine.objects.State; -import org.onap.appc.statemachine.objects.StateMachineResponse; - -/** - * Interface of the StateMachine - */ -public interface StateMachine { - /** - * Handle event - * @param currentState the current State which the event should be handled from - * @param event the Event that needs to be handled - * @return StateMachineResponse - * @throws InvalidInputException - * when the passed in currentState and event are not predefined or no relevant transition - */ - StateMachineResponse handleEvent(State currentState, Event event) throws InvalidInputException; -} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/StateMetaDataReader.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/StateMetaDataReader.java deleted file mode 100644 index fe2b193e1..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/StateMetaDataReader.java +++ /dev/null @@ -1,31 +0,0 @@ -/*- - * ============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; - -import org.onap.appc.statemachine.objects.StateMachineMetadata; - -public interface StateMetaDataReader { - StateMachineMetadata readMetadata(); -} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/StateMachineFactory.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/StateMachineFactory.java deleted file mode 100644 index bfcafeb7d..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/StateMachineFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============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.onap.appc.statemachine.StateMachine; -import org.onap.appc.statemachine.objects.StateMachineMetadata; - -/** - * Factory of StateMachine - */ -public class StateMachineFactory { - - private StateMachineFactory(){ - throw new IllegalAccessError("StateMachineFactory"); - } - - public static StateMachine getStateMachine(StateMachineMetadata metadata){ - return new StateMachineImpl(metadata); - } -} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/StateMachineImpl.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/StateMachineImpl.java deleted file mode 100644 index b56250708..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/StateMachineImpl.java +++ /dev/null @@ -1,103 +0,0 @@ -/*- - * ============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 java.util.HashSet; -import java.util.Set; - -import org.onap.appc.exceptions.InvalidInputException; -import org.onap.appc.statemachine.StateMachine; -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; -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 final Set states; - private final Set events; - - StateMachineImpl(StateMachineMetadata metadata){ - this.states = new HashSet<>(); - this.states.addAll(metadata.getStates()); - this.events = new HashSet<>(); - this.events.addAll(metadata.getEvents()); - } - - @Override - public StateMachineResponse handleEvent(State inputState, Event event) throws InvalidInputException{ - - if(!validateInputs(inputState,event)){ - throw new InvalidInputException(String.format(invalidInputFormat, inputState, event)); - } - - StateMachineResponse response = new StateMachineResponse(); - State currentState = null; - State nextState = null; - for(State stateInSet:states){ - if(stateInSet.equals(inputState)){ - currentState = stateInSet; - break; - } - } - if (currentState != null) { - for (Transition transition : currentState.getTransitions()) { - if (event.equals(transition.getEvent())) { - nextState = transition.getNextState(); - } - } - } - if(nextState == null){ - response.setResponse(Response.NO_TRANSITION_DEFINED); - } - else if(inputState.equals(nextState)){ - response.setResponse(Response.NO_STATE_CHANGE); - } - else{ - response.setResponse(Response.VALID_TRANSITION); - } - response.setNextState(nextState); - return response; - } - - boolean validateInputs(State state,Event event) { - return state != null - && event != null - && this.states.contains(state) - && this.events.contains(event); - } - - @Override - public String toString() { - return String.format(toStringFormat, states, events); - } -} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/readers/AppcOamMetaDataReader.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/readers/AppcOamMetaDataReader.java deleted file mode 100644 index 7451cf3af..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/readers/AppcOamMetaDataReader.java +++ /dev/null @@ -1,113 +0,0 @@ -/*- - * ============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.onap.appc.statemachine.StateMetaDataReader; -import org.onap.appc.statemachine.objects.Event; -import org.onap.appc.statemachine.objects.State; -import org.onap.appc.statemachine.objects.StateMachineMetadata; - -/** - * Reader for APPC OAM MetaData - */ -public class AppcOamMetaDataReader implements StateMetaDataReader { - - /** - * APPC Operation Enum - */ - public enum AppcOperation { - MaintenanceMode, - Restart, - Start, - Stop - } - - @Override - public StateMachineMetadata readMetadata() { - State notInstantiated = new State(AppcOamStates.NotInstantiated.toString()); - State instantiated = new State(AppcOamStates.Instantiated.toString()); - State restarting = new State(AppcOamStates.Restarting.toString()); - State starting = new State(AppcOamStates.Starting.toString()); - State started = new State(AppcOamStates.Started.toString()); - State enteringMaintenanceMode = new State(AppcOamStates.EnteringMaintenanceMode.toString()); - State maintenanceMode = new State(AppcOamStates.MaintenanceMode.toString()); - State error = new State(AppcOamStates.Error.toString()); - State unknown = new State(AppcOamStates.Unknown.toString()); - State stopping = new State(AppcOamStates.Stopping.toString()); - State stopped = new State(AppcOamStates.Stopped.toString()); - - Event start = new Event(AppcOperation.Start.toString()); - Event stop = new Event(AppcOperation.Stop.toString()); - Event maintenanceModeEvent = new Event(AppcOperation.MaintenanceMode.toString()); - Event restart = new Event(AppcOperation.Restart.toString()); - - StateMachineMetadata.StateMachineMetadataBuilder builder = new StateMachineMetadata - .StateMachineMetadataBuilder(); - - builder = builder.addState(notInstantiated); - builder = builder.addState(instantiated); - builder = builder.addState(starting); - builder = builder.addState(started); - builder = builder.addState(error); - builder = builder.addState(unknown); - builder = builder.addState(stopping); - builder = builder.addState(stopped); - builder = builder.addState(enteringMaintenanceMode); - builder = builder.addState(maintenanceMode); - builder = builder.addState(restarting); - - builder = builder.addEvent(start); - builder = builder.addEvent(stop); - builder = builder.addEvent(restart); - builder = builder.addEvent(maintenanceModeEvent); - - /* - * for addTransition: - * param 1: current state; param 2: received command/request; param 3: new transition state - */ - // start - builder = builder.addTransition(stopped, start, starting); - builder = builder.addTransition(maintenanceMode, start, starting); - builder = builder.addTransition(error, start, starting); - // stop - builder = builder.addTransition(started, stop, stopping); - builder = builder.addTransition(starting, stop, stopping); - builder = builder.addTransition(enteringMaintenanceMode, stop, stopping); - builder = builder.addTransition(maintenanceMode, stop, stopping); - builder = builder.addTransition(error, stop, stopping); - // maintenance mode - builder = builder.addTransition( - started, maintenanceModeEvent, enteringMaintenanceMode); - // restart - builder = builder.addTransition(stopped, restart, restarting); - builder = builder.addTransition(starting, restart, restarting); - builder = builder.addTransition(started, restart, restarting); - builder = builder.addTransition(enteringMaintenanceMode, restart, restarting); - builder = builder.addTransition(maintenanceMode, restart, restarting); - builder = builder.addTransition(error, restart, restarting); - - return builder.build(); - } -} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/readers/AppcOamStates.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/readers/AppcOamStates.java deleted file mode 100644 index 70a044bfa..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/readers/AppcOamStates.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============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.osgi.framework.Bundle; - -public enum AppcOamStates { - EnteringMaintenanceMode(0), - Error(0), - Instantiated(Bundle.INSTALLED), - MaintenanceMode(0), - NotInstantiated(Bundle.UNINSTALLED), - Restarting(0), - Started(Bundle.ACTIVE), - Starting(Bundle.STARTING), - Stopped(Bundle.RESOLVED), - Stopping(Bundle.STOPPING), - Unknown(0); - - int osgiBundleState; - - AppcOamStates(Integer bundleState) { - osgiBundleState = bundleState; - } - - public static AppcOamStates getOamStateFromBundleState(int bundleState) { - for (AppcOamStates aState : values()) { - if (aState.osgiBundleState == bundleState) { - return aState; - } - } - return Unknown; - } -} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/readers/VnfMetaDataReader.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/readers/VnfMetaDataReader.java deleted file mode 100644 index 2ba949f38..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/impl/readers/VnfMetaDataReader.java +++ /dev/null @@ -1,493 +0,0 @@ -/*- - * ============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.onap.appc.statemachine.StateMetaDataReader; -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; - -/** - * Reader for VNF MetaData - */ -public class VnfMetaDataReader implements StateMetaDataReader { - - /** - * VNF Operations - */ - public enum VNFOperation { - - Configure, Test, HealthCheck, Start, Terminate, Restart, Rebuild, Stop, ConfigModify, - ConfigScaleOut,ConfigRestore,Backup, Snapshot, - SoftwareUpload, LiveUpgrade, Rollback, Sync, Audit, Test_lic, Migrate, Evacuate, - ConfigBackup, ConfigBackupDelete, ConfigExport, - Lock(true), Unlock(true), CheckLock(true), StartApplication,StopApplication; - - private boolean builtIn; - - VNFOperation(boolean builtIn) { - this.builtIn = builtIn; - } - - VNFOperation() { - this(false); - } - } - - /** - * VNF States - */ - enum VNFStates { - Not_Instantiated, Instantiated, Configuring, Configured, Testing, Tested, - Rebuilding, Restarting, Starting, - Error, Running, Unknown, Terminating, Stopping, Stopped, - Backing_Up, Snapshotting, Software_Uploading, Upgrading, - Rollbacking, Licensing, Migrating, Evacuating, - NOT_ORCHESTRATED("NOT ORCHESTRATED"), Created; - - String stateName; - - VNFStates(String name) { - this.stateName = name; - } - - VNFStates() { - this.stateName = name(); - } - - @Override - public String toString() { - return this.stateName; - } - } - - @Override - public StateMachineMetadata readMetadata() { - State notInstantiated = new State(VNFStates.Not_Instantiated.toString()); - State instantiated = new State(VNFStates.Instantiated.toString()); - State configuring = new State(VNFStates.Configuring.toString()); - State configured = new State(VNFStates.Configured.toString()); - State testing = new State(VNFStates.Testing.toString()); - State tested = new State(VNFStates.Tested.toString()); - State rebuilding = new State(VNFStates.Rebuilding.toString()); - State restarting = new State(VNFStates.Restarting.toString()); - State starting = new State(VNFStates.Starting.toString()); - State error = new State(VNFStates.Error.toString()); - State running = new State(VNFStates.Running.toString()); - State unknown = new State(VNFStates.Unknown.toString()); - State terminating = new State(VNFStates.Terminating.toString()); - State stopping = new State(VNFStates.Stopping.toString()); - State stopped = new State(VNFStates.Stopped.toString()); - State notOrchestrated = new State(VNFStates.NOT_ORCHESTRATED.toString()); - - State backingUp = new State(VNFStates.Backing_Up.toString()); - State snapshotting = new State(VNFStates.Snapshotting.toString()); - State softwareUploading = new State(VNFStates.Software_Uploading.toString()); - State upgrading = new State(VNFStates.Upgrading.toString()); - State rollbacking = new State(VNFStates.Rollbacking.toString()); - - State migrating = new State(VNFStates.Migrating.toString()); - State evacuating = new State(VNFStates.Evacuating.toString()); - State created= new State(VNFStates.Created.toString()); - - Event startApplication = new Event(VNFOperation.StartApplication.toString()); - Event configure = new Event(VNFOperation.Configure.toString()); - Event healthcheck = new Event(VNFOperation.HealthCheck.toString()); - Event test = new Event(VNFOperation.Test.toString()); - Event start = new Event(VNFOperation.Start.toString()); - Event terminate = new Event(VNFOperation.Terminate.toString()); - Event restart = new Event(VNFOperation.Restart.toString()); - Event rebuild = new Event(VNFOperation.Rebuild.toString()); - Event stop = new Event(VNFOperation.Stop.toString()); - Event configModify = new Event(VNFOperation.ConfigModify.toString()); - Event configScaleout = new Event(VNFOperation.ConfigScaleOut.toString()); - Event configRestore = new Event(VNFOperation.ConfigRestore.toString()); - Event backup = new Event(VNFOperation.Backup.toString()); - Event snapshot = new Event(VNFOperation.Snapshot.toString()); - Event softwareUpload = new Event(VNFOperation.SoftwareUpload.toString()); - Event liveUpgrade = new Event(VNFOperation.LiveUpgrade.toString()); - Event rollback = new Event(VNFOperation.Rollback.toString()); - Event sync = new Event(VNFOperation.Sync.toString()); - Event audit = new Event(VNFOperation.Audit.toString()); - Event migrate = new Event(VNFOperation.Migrate.toString()); - Event evacuate = new Event(VNFOperation.Evacuate.toString()); - Event configBackup = new Event(VNFOperation.ConfigBackup.toString()); - Event configBackupDelete = new Event(VNFOperation.ConfigBackupDelete.toString()); - Event configExport = new Event(VNFOperation.ConfigExport.toString()); - Event stopApplication= new Event(VNFOperation.StopApplication.toString()); - - Event lock = new Event(VNFOperation.Lock.toString()); - Event unlock = new Event(VNFOperation.Unlock.toString()); - Event checklock = new Event(VNFOperation.CheckLock.toString()); - - Event success = new Event(VNFOperationOutcome.SUCCESS.toString()); - Event failure = new Event(VNFOperationOutcome.FAILURE.toString()); - - - StateMachineMetadata.StateMachineMetadataBuilder builder = - new StateMachineMetadata.StateMachineMetadataBuilder(); - - builder = builder.addState(notInstantiated); - builder = builder.addState(instantiated); - builder = builder.addState(configuring); - builder = builder.addState(configured); - builder = builder.addState(testing); - builder = builder.addState(tested); - builder = builder.addState(rebuilding); - builder = builder.addState(restarting); - builder = builder.addState(starting); - builder = builder.addState(error); - builder = builder.addState(running); - builder = builder.addState(unknown); - builder = builder.addState(terminating); - builder = builder.addState(stopping); - builder = builder.addState(stopped); - - builder = builder.addState(backingUp); - builder = builder.addState(snapshotting); - builder = builder.addState(softwareUploading); - builder = builder.addState(upgrading); - builder = builder.addState(rollbacking); - builder = builder.addState(migrating); - builder = builder.addState(evacuating); - builder = builder.addState(notOrchestrated); - builder = builder.addState(created); - builder = builder.addEvent(startApplication); - builder = builder.addEvent(configure); - builder = builder.addEvent(test); - builder = builder.addEvent(start); - builder = builder.addEvent(terminate); - builder = builder.addEvent(restart); - builder = builder.addEvent(rebuild); - builder = builder.addEvent(success); - builder = builder.addEvent(failure); - builder = builder.addEvent(stop); - builder = builder.addEvent(configModify); - builder = builder.addEvent(configScaleout); - builder = builder.addEvent(configRestore); - builder = builder.addEvent(healthcheck); - builder = builder.addEvent(backup); - builder = builder.addEvent(snapshot); - builder = builder.addEvent(softwareUpload); - builder = builder.addEvent(liveUpgrade); - builder = builder.addEvent(rollback); - builder = builder.addEvent(sync); - builder = builder.addEvent(audit); - builder = builder.addEvent(migrate); - builder = builder.addEvent(evacuate); - builder = builder.addEvent(lock); - builder = builder.addEvent(unlock); - builder = builder.addEvent(checklock); - builder = builder.addEvent(configBackup); - builder = builder.addEvent(configBackupDelete); - builder = builder.addEvent(configExport); - builder = builder.addEvent(stopApplication); - - builder = builder.addTransition(notOrchestrated,configure,configuring); - builder = builder.addTransition(notOrchestrated,test,testing); - builder = builder.addTransition(notOrchestrated,start,starting); - builder = builder.addTransition(notOrchestrated,terminate,terminating); - builder = builder.addTransition(notOrchestrated,restart,restarting); - builder = builder.addTransition(notOrchestrated,rebuild,rebuilding); - builder = builder.addTransition(notOrchestrated,stop,stopping); - builder = builder.addTransition(notOrchestrated,configModify,configuring); - builder = builder.addTransition(notOrchestrated,configScaleout,configuring); - builder = builder.addTransition(notOrchestrated,configRestore,configuring); - builder = builder.addTransition(notOrchestrated,healthcheck,testing); - builder = builder.addTransition(notOrchestrated,backup,backingUp); - builder = builder.addTransition(notOrchestrated,snapshot,snapshotting); - builder = builder.addTransition(notOrchestrated,softwareUpload,softwareUploading); - builder = builder.addTransition(notOrchestrated,liveUpgrade,upgrading); - builder = builder.addTransition(notOrchestrated,rollback,rollbacking); - builder = builder.addTransition(notOrchestrated,migrate,migrating); - builder = builder.addTransition(notOrchestrated,evacuate,evacuating); - builder = builder.addTransition(notOrchestrated,lock,notOrchestrated); - builder = builder.addTransition(notOrchestrated,unlock,notOrchestrated); - builder = builder.addTransition(notOrchestrated,checklock,notOrchestrated); - builder = builder.addTransition(notOrchestrated,startApplication,starting); - builder = builder.addTransition(notOrchestrated,stopApplication,stopping); - builder = builder.addTransition(notOrchestrated,configBackup,notOrchestrated); - - builder = builder.addTransition(created,configure,configuring); - builder = builder.addTransition(created,test,testing); - builder = builder.addTransition(created,start,starting); - builder = builder.addTransition(created,terminate,terminating); - builder = builder.addTransition(created,restart,restarting); - builder = builder.addTransition(created,rebuild,rebuilding); - builder = builder.addTransition(created,stop,stopping); - builder = builder.addTransition(created,configModify,configuring); - builder = builder.addTransition(created,configScaleout,configuring); - builder = builder.addTransition(created,configRestore,configuring); - builder = builder.addTransition(created,healthcheck,testing); - builder = builder.addTransition(created,backup,backingUp); - builder = builder.addTransition(created,snapshot,snapshotting); - builder = builder.addTransition(created,softwareUpload,softwareUploading); - builder = builder.addTransition(created,liveUpgrade,upgrading); - builder = builder.addTransition(created,rollback,rollbacking); - builder = builder.addTransition(created,migrate,migrating); - builder = builder.addTransition(created,evacuate,evacuating); - builder = builder.addTransition(created,lock,created); - builder = builder.addTransition(created,unlock,created); - builder = builder.addTransition(created,checklock,created); - builder = builder.addTransition(created,startApplication,starting); - builder = builder.addTransition(created,stopApplication,stopping); - builder = builder.addTransition(created,configBackup,created); - - builder = builder.addTransition(instantiated,configure,configuring); - builder = builder.addTransition(instantiated,test,testing); - builder = builder.addTransition(instantiated,start,starting); - builder = builder.addTransition(instantiated,terminate,terminating); - builder = builder.addTransition(instantiated,restart,restarting); - builder = builder.addTransition(instantiated,rebuild,rebuilding); - builder = builder.addTransition(instantiated,stop,stopping); - builder = builder.addTransition(instantiated,configModify,configuring); - builder = builder.addTransition(instantiated,configScaleout,configuring); - builder = builder.addTransition(instantiated,configRestore,configuring); - builder = builder.addTransition(instantiated,healthcheck,testing); - builder = builder.addTransition(instantiated,backup,backingUp); - builder = builder.addTransition(instantiated,snapshot,snapshotting); - builder = builder.addTransition(instantiated,softwareUpload,softwareUploading); - builder = builder.addTransition(instantiated,liveUpgrade,upgrading); - builder = builder.addTransition(instantiated,rollback,rollbacking); - builder = builder.addTransition(instantiated,migrate,migrating); - builder = builder.addTransition(instantiated,evacuate,evacuating); - builder = builder.addTransition(instantiated,lock,instantiated); - builder = builder.addTransition(instantiated,unlock,instantiated); - builder = builder.addTransition(instantiated,checklock,instantiated); - - builder = builder.addTransition(configured,configure,configuring); - builder = builder.addTransition(configured,test,testing); - builder = builder.addTransition(configured,start,starting); - builder = builder.addTransition(configured,terminate,terminating); - builder = builder.addTransition(configured,restart,restarting); - builder = builder.addTransition(configured,rebuild,rebuilding); - builder = builder.addTransition(configured,stop,stopping); - builder = builder.addTransition(configured,configModify,configuring); - builder = builder.addTransition(configured,configScaleout,configuring); - builder = builder.addTransition(configured,configRestore,configuring); - builder = builder.addTransition(configured,healthcheck,testing); - builder = builder.addTransition(configured,backup,backingUp); - builder = builder.addTransition(configured,snapshot,snapshotting); - builder = builder.addTransition(configured,softwareUpload,softwareUploading); - builder = builder.addTransition(configured,liveUpgrade,upgrading); - builder = builder.addTransition(configured,rollback,rollbacking); - builder = builder.addTransition(configured,sync,configured); - builder = builder.addTransition(configured,audit,configured); - builder = builder.addTransition(configured,migrate,migrating); - builder = builder.addTransition(configured,evacuate,evacuating); - builder = builder.addTransition(configured,lock,configured); - builder = builder.addTransition(configured,unlock,configured); - builder = builder.addTransition(configured,checklock,configured); - builder = builder.addTransition(configured,configBackup,configured); - builder = builder.addTransition(configured,configBackupDelete,configured); - builder = builder.addTransition(configured,configExport,configured); - builder = builder.addTransition(configured,stopApplication,stopping); - - builder = builder.addTransition(tested,configure,configuring); - builder = builder.addTransition(tested,test,testing); - builder = builder.addTransition(tested,start,starting); - builder = builder.addTransition(tested,terminate,terminating); - builder = builder.addTransition(tested,restart,restarting); - builder = builder.addTransition(tested,rebuild,rebuilding); - builder = builder.addTransition(tested,stop,stopping); - builder = builder.addTransition(tested,configModify,configuring); - builder = builder.addTransition(tested,configScaleout,configuring); - builder = builder.addTransition(tested,configRestore,configuring); - builder = builder.addTransition(tested,healthcheck,testing); - builder = builder.addTransition(tested,backup,backingUp); - builder = builder.addTransition(tested,snapshot,snapshotting); - builder = builder.addTransition(tested,softwareUpload,softwareUploading); - builder = builder.addTransition(tested,liveUpgrade,upgrading); - builder = builder.addTransition(tested,rollback,rollbacking); - builder = builder.addTransition(tested,sync,tested); - builder = builder.addTransition(tested,audit,tested); - builder = builder.addTransition(tested,migrate,migrating); - builder = builder.addTransition(tested,evacuate,evacuating); - builder = builder.addTransition(tested,lock,tested); - builder = builder.addTransition(tested,unlock,tested); - builder = builder.addTransition(tested,checklock,tested); - builder = builder.addTransition(tested,configBackup,tested); - builder = builder.addTransition(tested,configBackupDelete,tested); - builder = builder.addTransition(tested,configExport,tested); - builder = builder.addTransition(tested,stopApplication,stopping); - - builder = builder.addTransition(running,configure,configuring); - builder = builder.addTransition(running,test,testing); - builder = builder.addTransition(running,start,starting); - builder = builder.addTransition(running,terminate,terminating); - builder = builder.addTransition(running,restart,restarting); - builder = builder.addTransition(running,rebuild,rebuilding); - builder = builder.addTransition(running,stop,stopping); - builder = builder.addTransition(running,configModify,configuring); - builder = builder.addTransition(running,configScaleout,configuring); - builder = builder.addTransition(running,configRestore,configuring); - builder = builder.addTransition(running,healthcheck,testing); - builder = builder.addTransition(running,backup,backingUp); - builder = builder.addTransition(running,snapshot,snapshotting); - builder = builder.addTransition(running,softwareUpload,softwareUploading); - builder = builder.addTransition(running,liveUpgrade,upgrading); - builder = builder.addTransition(running,rollback,rollbacking); - builder = builder.addTransition(running,sync,running); - builder = builder.addTransition(running,audit,running); - builder = builder.addTransition(running,migrate,migrating); - builder = builder.addTransition(running,evacuate,evacuating); - builder = builder.addTransition(running,lock,running); - builder = builder.addTransition(running,unlock,running); - builder = builder.addTransition(running,checklock,running); - builder = builder.addTransition(running,configBackup,running); - builder = builder.addTransition(running,configBackupDelete,running); - builder = builder.addTransition(running,configExport,running); - builder = builder.addTransition(running,stopApplication,stopping); - - builder = builder.addTransition(error,configure,configuring); - builder = builder.addTransition(error,test,testing); - builder = builder.addTransition(error,start,starting); - builder = builder.addTransition(error,terminate,terminating); - builder = builder.addTransition(error,restart,restarting); - builder = builder.addTransition(error,rebuild,rebuilding); - builder = builder.addTransition(error,stop,stopping); - builder = builder.addTransition(error,configModify,configuring); - builder = builder.addTransition(error,configScaleout,configuring); - builder = builder.addTransition(error,configRestore,configuring); - builder = builder.addTransition(error,healthcheck,testing); - builder = builder.addTransition(error,backup,backingUp); - builder = builder.addTransition(error,snapshot,snapshotting); - builder = builder.addTransition(error,softwareUpload,softwareUploading); - builder = builder.addTransition(error,liveUpgrade,upgrading); - builder = builder.addTransition(error,rollback,rollbacking); - builder = builder.addTransition(error,sync,error); - builder = builder.addTransition(error,audit,error); - builder = builder.addTransition(error,migrate,migrating); - builder = builder.addTransition(error,evacuate,evacuating); - builder = builder.addTransition(error,lock,error); - builder = builder.addTransition(error,unlock,error); - builder = builder.addTransition(error,checklock,error); - builder = builder.addTransition(error,configBackup,error); - builder = builder.addTransition(error,configBackupDelete,error); - builder = builder.addTransition(error,configExport,error); - builder = builder.addTransition(error,stopApplication,stopping); - - builder = builder.addTransition(unknown,configure,configuring); - builder = builder.addTransition(unknown,test,testing); - builder = builder.addTransition(unknown,start,starting); - builder = builder.addTransition(unknown,terminate,terminating); - builder = builder.addTransition(unknown,restart,restarting); - builder = builder.addTransition(unknown,rebuild,rebuilding); - builder = builder.addTransition(unknown,stop,stopping); - builder = builder.addTransition(unknown,configModify,configuring); - builder = builder.addTransition(unknown,configScaleout,configuring); - builder = builder.addTransition(unknown,configRestore,configuring); - builder = builder.addTransition(unknown,healthcheck,testing); - builder = builder.addTransition(unknown,backup,backingUp); - builder = builder.addTransition(unknown,snapshot,snapshotting); - builder = builder.addTransition(unknown,softwareUpload,softwareUploading); - builder = builder.addTransition(unknown,liveUpgrade,upgrading); - builder = builder.addTransition(unknown,rollback,rollbacking); - builder = builder.addTransition(unknown,sync,unknown); - builder = builder.addTransition(unknown,audit,unknown); - builder = builder.addTransition(unknown,migrate,migrating); - builder = builder.addTransition(unknown,evacuate,evacuating); - builder = builder.addTransition(unknown,lock,unknown); - builder = builder.addTransition(unknown,unlock,unknown); - builder = builder.addTransition(unknown,checklock,unknown); - builder = builder.addTransition(unknown,configBackup,unknown); - builder = builder.addTransition(unknown,configBackupDelete,unknown); - builder = builder.addTransition(unknown,configExport,unknown); - builder = builder.addTransition(unknown,stopApplication,stopping); - - builder = builder.addTransition(stopped,configure,configuring); - builder = builder.addTransition(stopped,test,testing); - builder = builder.addTransition(stopped,start,starting); - builder = builder.addTransition(stopped,terminate,terminating); - builder = builder.addTransition(stopped,restart,restarting); - builder = builder.addTransition(stopped,rebuild,rebuilding); - builder = builder.addTransition(stopped,configModify,configuring); - builder = builder.addTransition(stopped,configScaleout,configuring); - builder = builder.addTransition(stopped,configRestore,configuring); - builder = builder.addTransition(stopped,healthcheck,testing); - builder = builder.addTransition(stopped,backup,backingUp); - builder = builder.addTransition(stopped,snapshot,snapshotting); - builder = builder.addTransition(stopped,softwareUpload,softwareUploading); - builder = builder.addTransition(stopped,liveUpgrade,upgrading); - builder = builder.addTransition(stopped,rollback,rollbacking); - builder = builder.addTransition(stopped,migrate,migrating); - builder = builder.addTransition(stopped,evacuate,evacuating); - builder = builder.addTransition(stopped,lock,stopped); - builder = builder.addTransition(stopped,unlock,stopped); - builder = builder.addTransition(stopped,checklock,stopped); - - builder = builder.addTransition(configuring,success,configured); - builder = builder.addTransition(configuring,failure,error); - - builder = builder.addTransition(testing,success,tested); - builder = builder.addTransition(testing,failure,error); - - builder = builder.addTransition(restarting,success,running); - builder = builder.addTransition(restarting,failure,error); - - builder = builder.addTransition(starting,success,running); - builder = builder.addTransition(starting,failure,error); - - builder = builder.addTransition(terminating,success,notInstantiated); - builder = builder.addTransition(terminating,failure,error); - - builder = builder.addTransition(rebuilding,success,running); - builder = builder.addTransition(rebuilding,failure,error); - - builder = builder.addTransition(stopping,success,stopped); - builder = builder.addTransition(stopping,failure,error); - - builder = builder.addTransition(backingUp,success,running); - builder = builder.addTransition(backingUp,failure,error); - - builder = builder.addTransition(snapshotting,success,running); - builder = builder.addTransition(snapshotting,failure,error); - - builder = builder.addTransition(softwareUploading,success,running); - builder = builder.addTransition(softwareUploading,failure,error); - - builder = builder.addTransition(upgrading,success,running); - builder = builder.addTransition(upgrading,failure,error); - - builder = builder.addTransition(rollbacking,success,running); - builder = builder.addTransition(rollbacking,failure,error); - - builder = builder.addTransition(migrating,success,running); - builder = builder.addTransition(migrating,failure,error); - - builder = builder.addTransition(evacuating,success,running); - builder = builder.addTransition(evacuating,failure,error); - - - builder = builder.addTransition(configured,startApplication,starting); - builder = builder.addTransition(tested,startApplication,starting); - builder = builder.addTransition(error,startApplication,starting); - builder = builder.addTransition(unknown,startApplication,starting); - builder = builder.addTransition(running,startApplication,starting); - - return builder.build(); - } -} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/Event.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/Event.java deleted file mode 100644 index 5e9b7c813..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/Event.java +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * ============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; - -/** - * Event Object - */ -public class Event{ - private final String eventName; - private final int hashCode; - - /** - * Constructor - * @param eventName String of the event name - */ - public Event(String eventName) { - this.eventName = eventName; - this.hashCode = this.eventName.toLowerCase().hashCode(); - } - - @Override - public int hashCode() { - return hashCode; - } - @Override - public boolean equals(Object obj) { - if(obj == null){ - return false; - } - if(!(obj instanceof Event)){ - return false; - } - Event event = (Event)obj; - return this.eventName.equalsIgnoreCase(event.getEventName()); - } - - public String getEventName() { - return eventName; - } - - @Override - public String toString(){ - return this.eventName; - } -} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/Response.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/Response.java deleted file mode 100644 index 49b6c909b..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/Response.java +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * ============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; - -/** - * Response object - */ -public enum Response { - NO_TRANSITION_DEFINED, - NO_STATE_CHANGE, - VALID_TRANSITION; - - @Override - public String toString(){ - return this.name(); - } -} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/State.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/State.java deleted file mode 100644 index 117cd76c0..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/State.java +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * ============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 java.util.ArrayList; -import java.util.List; - -/** - * State Object - */ -public class State { - private final String stateName; - private final int hashCode; - private final List transitions; - - /** - * Constructor - * @param stateName String of the state name - */ - public State(String stateName) { - this.stateName = stateName; - this.hashCode = stateName.toLowerCase().hashCode(); - this.transitions = new ArrayList<>(); - } - - @Override - public int hashCode() { - return hashCode; - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (!(obj instanceof State)) { - return false; - } - State state = (State)obj; - return this.stateName.equalsIgnoreCase(state.getStateName()); - } - - public String getStateName() { - return stateName; - } - - void addTransition(Transition transition) { - this.transitions.add(transition); - } - - public List getTransitions() { - return transitions; - } - - @Override - public String toString() { - return this.stateName; - } -} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/StateMachineMetadata.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/StateMachineMetadata.java deleted file mode 100644 index 02088b26e..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/StateMachineMetadata.java +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * ============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 java.util.HashSet; -import java.util.Set; - -public class StateMachineMetadata { - - private Set states; - private Set events; - - private StateMachineMetadata(StateMachineMetadataBuilder builder){ - states = builder.states; - events = builder.events; - } - - public Set getStates() { - return states; - } - - public Set getEvents() { - return events; - } - - public static class StateMachineMetadataBuilder{ - - private Set states; - private Set events; - - public StateMachineMetadataBuilder(){ - states = new HashSet<>(); - events = new HashSet<>(); - } - - public StateMachineMetadataBuilder addState(State state){ - this.states.add(state); - return this; - } - - public StateMachineMetadataBuilder addEvent(Event event){ - this.events.add(event); - return this; - } - - public StateMachineMetadataBuilder addTransition(State currentState,Event event,State nextState){ - Transition transition = new Transition(event,nextState); - currentState.addTransition(transition); - return this; - } - - public StateMachineMetadata build(){ - return new StateMachineMetadata(this); - } - } -} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/StateMachineResponse.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/StateMachineResponse.java deleted file mode 100644 index 9fc401527..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/StateMachineResponse.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============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; - - -public class StateMachineResponse { - private State nextState; - private Response response; - - public StateMachineResponse(){ - // do nothing - } - - public State getNextState() { - return nextState; - } - - public Response getResponse() { - return response; - } - - public void setNextState(State nextState) { - this.nextState = nextState; - } - - public void setResponse(Response response) { - this.response = response; - } -} diff --git a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/Transition.java b/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/Transition.java deleted file mode 100644 index 2c6ee6366..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/main/java/org/openecomp/appc/statemachine/objects/Transition.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============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; - -/** - * Transition Object - */ -public class Transition { - private Event event; - private State nextState; - - /** - * Constructor - * @param event which triggers the transition - * @param nextState of State which indicates the transition targeted state - */ - Transition(Event event, State nextState) { - this.event = event; - this.nextState = nextState; - } - - public Event getEvent() { - return event; - } - - public State getNextState() { - return nextState; - } -} 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 expectedStateNames = new ArrayList<>(); + private List 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 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 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 resultMap = new HashMap() { + { + 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 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 expectedStateNames = new ArrayList<>(); + private List 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 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 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 transitions = (List) 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 transitions = (List) Whitebox.getInternalState(state, "transitions"); + Assert.assertFalse("should not have transition1", transitions.contains(transition1)); + state.addTransition(transition1); + transitions = (List) 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()); + } + +} 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 deleted file mode 100644 index e35482e45..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/StateMachineFactoryTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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/openecomp/appc/statemachine/impl/StateMachineImplTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/StateMachineImplTest.java deleted file mode 100644 index a4a8b9fcc..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/StateMachineImplTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============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/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 deleted file mode 100644 index e8f2a2083..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/readers/AppcOamMetaDataReaderTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============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 expectedStateNames = new ArrayList<>(); - private List 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 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 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/AppcOamStatesTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/readers/AppcOamStatesTest.java deleted file mode 100644 index 014618846..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/readers/AppcOamStatesTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============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 resultMap = new HashMap() { - { - 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 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/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 deleted file mode 100644 index 9b409491e..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/impl/readers/VnfMetaDataReaderTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/*- - * ============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 expectedStateNames = new ArrayList<>(); - private List 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 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 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 deleted file mode 100644 index 961e33ffd..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/EventTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * ============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/openecomp/appc/statemachine/objects/ResponseTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/ResponseTest.java deleted file mode 100644 index e85bce65f..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/ResponseTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * ============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/openecomp/appc/statemachine/objects/StateMachineMetadataTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/StateMachineMetadataTest.java deleted file mode 100644 index 684225736..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/StateMachineMetadataTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * ============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/openecomp/appc/statemachine/objects/StateMachineResponseTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/StateMachineResponseTest.java deleted file mode 100644 index 183b7f5af..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/StateMachineResponseTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============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/openecomp/appc/statemachine/objects/StateTest.java b/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/StateTest.java deleted file mode 100644 index 601754edf..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/StateTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * ============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 transitions = (List) 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 transitions = (List) Whitebox.getInternalState(state, "transitions"); - Assert.assertFalse("should not have transition1", transitions.contains(transition1)); - state.addTransition(transition1); - transitions = (List) 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 deleted file mode 100644 index da69d723c..000000000 --- a/appc-lifecycle-management/state-machine-lib/src/test/java/org/openecomp/appc/statemachine/objects/TransitionTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * ============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()); - } - -} -- cgit 1.2.3-korg