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 --- .../impl/LifecycleManagerImpl.java | 102 ++++++++++++ .../impl/LifecycleManagerImpl.java | 102 ------------ .../resources/org/onap/appc/default.properties | 39 +++++ .../org/openecomp/appc/default.properties | 39 ----- .../java/org/onap/appc/LifecycleManagerTest.java | 185 +++++++++++++++++++++ .../org/onap/appc/OamLifeCycleManagerTest.java | 152 +++++++++++++++++ .../org/openecomp/appc/LifecycleManagerTest.java | 185 --------------------- .../openecomp/appc/OamLifeCycleManagerTest.java | 152 ----------------- 8 files changed, 478 insertions(+), 478 deletions(-) create mode 100644 appc-lifecycle-management/appc-lifecycle-management-core/src/main/java/org/onap/appc/lifecyclemanager/impl/LifecycleManagerImpl.java delete mode 100644 appc-lifecycle-management/appc-lifecycle-management-core/src/main/java/org/openecomp/appc/lifecyclemanager/impl/LifecycleManagerImpl.java create mode 100644 appc-lifecycle-management/appc-lifecycle-management-core/src/main/resources/org/onap/appc/default.properties delete mode 100644 appc-lifecycle-management/appc-lifecycle-management-core/src/main/resources/org/openecomp/appc/default.properties create mode 100644 appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/onap/appc/LifecycleManagerTest.java create mode 100644 appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/onap/appc/OamLifeCycleManagerTest.java delete mode 100644 appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/openecomp/appc/LifecycleManagerTest.java delete mode 100644 appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/openecomp/appc/OamLifeCycleManagerTest.java (limited to 'appc-lifecycle-management/appc-lifecycle-management-core/src') diff --git a/appc-lifecycle-management/appc-lifecycle-management-core/src/main/java/org/onap/appc/lifecyclemanager/impl/LifecycleManagerImpl.java b/appc-lifecycle-management/appc-lifecycle-management-core/src/main/java/org/onap/appc/lifecyclemanager/impl/LifecycleManagerImpl.java new file mode 100644 index 000000000..12c48b481 --- /dev/null +++ b/appc-lifecycle-management/appc-lifecycle-management-core/src/main/java/org/onap/appc/lifecyclemanager/impl/LifecycleManagerImpl.java @@ -0,0 +1,102 @@ +/*- + * ============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.lifecyclemanager.impl; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.att.eelf.i18n.EELFResourceManager; +import org.onap.appc.exceptions.InvalidInputException; +import org.onap.appc.i18n.Msg; +import org.onap.appc.lifecyclemanager.LifecycleManager; +import org.onap.appc.lifecyclemanager.objects.LifecycleException; +import org.onap.appc.lifecyclemanager.objects.NoTransitionDefinedException; +import org.onap.appc.statemachine.StateMachine; +import org.onap.appc.statemachine.StateMetaDataReader; +import org.onap.appc.statemachine.impl.StateMachineFactory; +import org.onap.appc.statemachine.impl.readers.AppcOamMetaDataReader; +import org.onap.appc.statemachine.impl.readers.VnfMetaDataReader; +import org.onap.appc.statemachine.objects.*; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class LifecycleManagerImpl implements LifecycleManager{ + + private StateMetaDataReader metadataReader; + private static Map stateMachineMap = new ConcurrentHashMap<>(); + private final EELFLogger logger = EELFManager.getInstance().getLogger(LifecycleManagerImpl.class); + private final EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger(); + + @Override + public String getNextState(String vnfType, String currentState, String event) throws NoTransitionDefinedException,LifecycleException{ + if (logger.isTraceEnabled()) { + logger.trace("Entering to getNextState with vnfType = "+ vnfType + ", currentState = " + currentState + ", event = " + event); + } + + State nextState; + StateMachine machine; + StateMachineResponse response; + try { + machine = this.getStateMachine(vnfType); + response = machine.handleEvent(new State(currentState),new Event(event)); + if(Response.NO_TRANSITION_DEFINED.equals(response.getResponse())){ + errorLogger.error(EELFResourceManager.format(Msg.VF_ILLEGAL_COMMAND, vnfType,event,currentState)); + throw new NoTransitionDefinedException("No Transition Defined for currentState = " + currentState + ", event = " + event,currentState,event); + } + nextState = response.getNextState(); + } catch (InvalidInputException e) { + logger.error(e.getMessage()); + throw new LifecycleException(e,currentState,event); + } + if (logger.isTraceEnabled()) { + logger.trace("Exiting from getNextState with (nextState = " + nextState.getStateName() + ")"); + } + return nextState.getStateName(); + } + + private StateMachine getStateMachine(String vnfType){ + if (logger.isTraceEnabled()) { + logger.trace("Entering to getNextState with vnfType = "+ vnfType); + } + if(vnfType == null){ + vnfType = "DEFAULT"; + } + StateMachine machine = stateMachineMap.get(vnfType); + if(machine == null){ + metadataReader = getMetadataReader(vnfType); + StateMachineMetadata metadata = metadataReader.readMetadata(); + machine = StateMachineFactory.getStateMachine(metadata); + stateMachineMap.put(vnfType,machine); + } + + logger.trace("Exiting getStateMachine with StateMachine = " + stateMachineMap.get(vnfType).toString()); + return stateMachineMap.get(vnfType); + } + + private StateMetaDataReader getMetadataReader(String vnfType) { + return vnfType.equals("APPC") ? new AppcOamMetaDataReader() : new VnfMetaDataReader(); + } + +} diff --git a/appc-lifecycle-management/appc-lifecycle-management-core/src/main/java/org/openecomp/appc/lifecyclemanager/impl/LifecycleManagerImpl.java b/appc-lifecycle-management/appc-lifecycle-management-core/src/main/java/org/openecomp/appc/lifecyclemanager/impl/LifecycleManagerImpl.java deleted file mode 100644 index 12c48b481..000000000 --- a/appc-lifecycle-management/appc-lifecycle-management-core/src/main/java/org/openecomp/appc/lifecyclemanager/impl/LifecycleManagerImpl.java +++ /dev/null @@ -1,102 +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.lifecyclemanager.impl; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.att.eelf.i18n.EELFResourceManager; -import org.onap.appc.exceptions.InvalidInputException; -import org.onap.appc.i18n.Msg; -import org.onap.appc.lifecyclemanager.LifecycleManager; -import org.onap.appc.lifecyclemanager.objects.LifecycleException; -import org.onap.appc.lifecyclemanager.objects.NoTransitionDefinedException; -import org.onap.appc.statemachine.StateMachine; -import org.onap.appc.statemachine.StateMetaDataReader; -import org.onap.appc.statemachine.impl.StateMachineFactory; -import org.onap.appc.statemachine.impl.readers.AppcOamMetaDataReader; -import org.onap.appc.statemachine.impl.readers.VnfMetaDataReader; -import org.onap.appc.statemachine.objects.*; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -public class LifecycleManagerImpl implements LifecycleManager{ - - private StateMetaDataReader metadataReader; - private static Map stateMachineMap = new ConcurrentHashMap<>(); - private final EELFLogger logger = EELFManager.getInstance().getLogger(LifecycleManagerImpl.class); - private final EELFLogger errorLogger = EELFManager.getInstance().getErrorLogger(); - - @Override - public String getNextState(String vnfType, String currentState, String event) throws NoTransitionDefinedException,LifecycleException{ - if (logger.isTraceEnabled()) { - logger.trace("Entering to getNextState with vnfType = "+ vnfType + ", currentState = " + currentState + ", event = " + event); - } - - State nextState; - StateMachine machine; - StateMachineResponse response; - try { - machine = this.getStateMachine(vnfType); - response = machine.handleEvent(new State(currentState),new Event(event)); - if(Response.NO_TRANSITION_DEFINED.equals(response.getResponse())){ - errorLogger.error(EELFResourceManager.format(Msg.VF_ILLEGAL_COMMAND, vnfType,event,currentState)); - throw new NoTransitionDefinedException("No Transition Defined for currentState = " + currentState + ", event = " + event,currentState,event); - } - nextState = response.getNextState(); - } catch (InvalidInputException e) { - logger.error(e.getMessage()); - throw new LifecycleException(e,currentState,event); - } - if (logger.isTraceEnabled()) { - logger.trace("Exiting from getNextState with (nextState = " + nextState.getStateName() + ")"); - } - return nextState.getStateName(); - } - - private StateMachine getStateMachine(String vnfType){ - if (logger.isTraceEnabled()) { - logger.trace("Entering to getNextState with vnfType = "+ vnfType); - } - if(vnfType == null){ - vnfType = "DEFAULT"; - } - StateMachine machine = stateMachineMap.get(vnfType); - if(machine == null){ - metadataReader = getMetadataReader(vnfType); - StateMachineMetadata metadata = metadataReader.readMetadata(); - machine = StateMachineFactory.getStateMachine(metadata); - stateMachineMap.put(vnfType,machine); - } - - logger.trace("Exiting getStateMachine with StateMachine = " + stateMachineMap.get(vnfType).toString()); - return stateMachineMap.get(vnfType); - } - - private StateMetaDataReader getMetadataReader(String vnfType) { - return vnfType.equals("APPC") ? new AppcOamMetaDataReader() : new VnfMetaDataReader(); - } - -} diff --git a/appc-lifecycle-management/appc-lifecycle-management-core/src/main/resources/org/onap/appc/default.properties b/appc-lifecycle-management/appc-lifecycle-management-core/src/main/resources/org/onap/appc/default.properties new file mode 100644 index 000000000..0c4de19aa --- /dev/null +++ b/appc-lifecycle-management/appc-lifecycle-management-core/src/main/resources/org/onap/appc/default.properties @@ -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========================================================= +### + +# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded +# to supply configuration options +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. + +#Property below provided by appc.properties +appc.LCM.provider.url=https://localhost:8443/restconf/operations/appc-provider-lcm +appc.LCM.poolMembers=:3904 +appc.LCM.service=dmaap +appc.LCM.topic.write=APPC-TEST2 +appc.LCM.client.name=APPC-TEST-CLIENT-LC-MGMT-MAIN +appc.LCM.provider.user=test +appc.LCM.provider.pass=test + + diff --git a/appc-lifecycle-management/appc-lifecycle-management-core/src/main/resources/org/openecomp/appc/default.properties b/appc-lifecycle-management/appc-lifecycle-management-core/src/main/resources/org/openecomp/appc/default.properties deleted file mode 100644 index 0c4de19aa..000000000 --- a/appc-lifecycle-management/appc-lifecycle-management-core/src/main/resources/org/openecomp/appc/default.properties +++ /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========================================================= -### - -# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded -# to supply configuration options -org.onap.appc.bootstrap.file=appc.properties -org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. - -#Property below provided by appc.properties -appc.LCM.provider.url=https://localhost:8443/restconf/operations/appc-provider-lcm -appc.LCM.poolMembers=:3904 -appc.LCM.service=dmaap -appc.LCM.topic.write=APPC-TEST2 -appc.LCM.client.name=APPC-TEST-CLIENT-LC-MGMT-MAIN -appc.LCM.provider.user=test -appc.LCM.provider.pass=test - - diff --git a/appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/onap/appc/LifecycleManagerTest.java b/appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/onap/appc/LifecycleManagerTest.java new file mode 100644 index 000000000..07aef6cb3 --- /dev/null +++ b/appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/onap/appc/LifecycleManagerTest.java @@ -0,0 +1,185 @@ +/*- + * ============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; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.appc.exceptions.InvalidInputException; +import org.onap.appc.lifecyclemanager.LifecycleManager; +import org.onap.appc.statemachine.StateMetaDataReader; +import org.onap.appc.lifecyclemanager.impl.LifecycleManagerImpl; +import org.onap.appc.lifecyclemanager.objects.LifecycleException; +import org.onap.appc.lifecyclemanager.objects.NoTransitionDefinedException; +import org.onap.appc.statemachine.impl.readers.VnfMetaDataReader; +import org.onap.appc.statemachine.impl.readers.VnfMetaDataReader.VNFOperation; +import org.onap.appc.statemachine.objects.Event; +import org.onap.appc.statemachine.objects.State; +import org.onap.appc.statemachine.objects.StateMachineMetadata; +import org.onap.appc.statemachine.objects.Transition; + +import java.util.*; + + +public class LifecycleManagerTest { + + private static final State[] VALID_LOCK_STATES = new State[] { + new State("instantiated"), + new State("configured"), + new State("tested"), + new State("running"), + new State("error"), + new State("unknown"), + new State("created"), + new State("not orchestrated"), + new State("stopped"), + }; + + @Test + public void handleEvent() throws InvalidInputException, LifecycleException, NoTransitionDefinedException { + + StateMachineMetadata metadata = getMetaDataReader().readMetadata(); + LifecycleManagerImpl lifecycleManager = new LifecycleManagerImpl(); + + /* + * Testing Positive Scenario passing the valid events and validating the StateMachineResponse + */ + for(State state:metadata.getStates()){ + + for(Transition transition:state.getTransitions()){ + Event event = transition.getEvent(); + State nextStateFromMetadata = transition.getNextState(); + + String expectedNextState = lifecycleManager.getNextState(null,state.toString(),event.toString()); + Assert.assertEquals(expectedNextState,nextStateFromMetadata.toString()); + } + } + + /* + Testing Negative Scenarios, 1. Passing the valid Events for which Transition is not defined in + Metadata and validating the StateMachineResponse 2. Passing the invalid events which are not + registered as events in the StateMachineMetadata and validating StateMachineResponse + */ + for(State state:metadata.getStates()){ + + for(Transition transition:state.getTransitions()){ + List negativeEvents = getNegativeEvents(state,metadata.getEvents()); + + for(Event negativeEvent:negativeEvents){ + boolean flag =false; + try{ + lifecycleManager.getNextState(null,state.toString(),negativeEvent.toString()); + + } + catch (NoTransitionDefinedException e){ + flag =true; + } + Assert.assertEquals(flag,true); + + flag = false; + try{ + lifecycleManager.getNextState(null,state.toString(),"PUT"); + } + catch(LifecycleException e){ + flag = true; + } + Assert.assertTrue(flag); + + } + } + } + } + + @Test + public void testNotOrchestratedState() throws LifecycleException, NoTransitionDefinedException { + LifecycleManager lifecycleManager = new LifecycleManagerImpl(); + String nextState = lifecycleManager.getNextState( + null,"NOT ORCHESTRATED",VNFOperation.Configure.toString()); + Assert.assertEquals(nextState,"Configuring"); + } + + @Test(expected = NoTransitionDefinedException.class) + public void testBakckingUpState() throws LifecycleException, NoTransitionDefinedException { + LifecycleManager lifecycleManager = new LifecycleManagerImpl(); + lifecycleManager.getNextState(null,"Software_Uploading",VNFOperation.Configure.toString()); + } + + private List getNegativeEvents(State state,Set events) { + List negativeEventList = new ArrayList<>(); + negativeEventList.addAll(events); + + for(Transition transition: state.getTransitions()){ + negativeEventList.remove(transition.getEvent()); + } + return negativeEventList; + } + + @Test + public void testLockStates() throws LifecycleException, NoTransitionDefinedException { + StateMachineMetadata metadata = getMetaDataReader().readMetadata(); + LifecycleManagerImpl lifecycleManager = new LifecycleManagerImpl(); + + for(State state: metadata.getStates()) { + if(isValidState(state, VALID_LOCK_STATES)) { + assertSameNextState(lifecycleManager, state, VNFOperation.Lock); + assertSameNextState(lifecycleManager, state, VnfMetaDataReader.VNFOperation.Unlock); + assertSameNextState(lifecycleManager, state, VNFOperation.CheckLock); + } else { + assertNoNextState(lifecycleManager, state, VNFOperation.Lock); + assertNoNextState(lifecycleManager, state, VNFOperation.Unlock); + assertNoNextState(lifecycleManager, state, VNFOperation.CheckLock); + } + } + } + + private boolean isValidState(State state, State[] validStates) { + for(State validState: validStates) { + if(validState.equals(state)) { + return true; + } + } + return false; + } + + private void assertSameNextState(LifecycleManager lifecycleManager, State state, VNFOperation operation) + throws LifecycleException, NoTransitionDefinedException { + Assert.assertEquals(state.getStateName(), + lifecycleManager.getNextState("no-matter", state.getStateName(), operation.toString())); + } + + private void assertNoNextState(LifecycleManager lifecycleManager, State state, VNFOperation operation) + throws LifecycleException { + try { + lifecycleManager.getNextState("no-matter", state.getStateName(), operation.toString()); + Assert.fail("lifecycleManager.getNextState() should fail for state [" + state + + "], operation [" + operation + "]"); + } catch(NoTransitionDefinedException e) { + // this exception is excepted + } + } + + private StateMetaDataReader getMetaDataReader() { + return new VnfMetaDataReader(); + } +} diff --git a/appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/onap/appc/OamLifeCycleManagerTest.java b/appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/onap/appc/OamLifeCycleManagerTest.java new file mode 100644 index 000000000..403a9f39e --- /dev/null +++ b/appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/onap/appc/OamLifeCycleManagerTest.java @@ -0,0 +1,152 @@ +/*- + * ============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; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.appc.lifecyclemanager.impl.LifecycleManagerImpl; +import org.onap.appc.lifecyclemanager.objects.LifecycleException; +import org.onap.appc.lifecyclemanager.objects.NoTransitionDefinedException; +import org.onap.appc.statemachine.impl.readers.AppcOamMetaDataReader; +import org.onap.appc.statemachine.impl.readers.AppcOamStates; + +import java.util.Arrays; +import java.util.List; + + +public class OamLifeCycleManagerTest { + private static final String VNF_TYPE_APPC = "APPC"; + private static final String NO_DEFINITION_FORMAT = "No Transition Defined for currentState = %s, event = %s"; + + private LifecycleManagerImpl lifecycleManager; + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Before + public void setUp() throws Exception { + lifecycleManager = new LifecycleManagerImpl(); + } + + private void validateProper(String state, String event, String expectedResult) + throws LifecycleException, NoTransitionDefinedException { + String nextState = lifecycleManager.getNextState(VNF_TYPE_APPC, state, event); + Assert.assertEquals(String.format("Should return %s", expectedResult), expectedResult, nextState); + } + + private void validateException(String state, String event) throws LifecycleException, NoTransitionDefinedException { + expectedException.expect(NoTransitionDefinedException.class); + expectedException.expectMessage(String.format(NO_DEFINITION_FORMAT, state, event)); + lifecycleManager.getNextState(VNF_TYPE_APPC, state, event); + + // Reset to no expectation + expectedException = ExpectedException.none(); + } + + @Test + public void testOamStateTransitionForMaintenanceMode() throws Exception { + String event = AppcOamMetaDataReader.AppcOperation.MaintenanceMode.name(); + String expecteResult = AppcOamStates.EnteringMaintenanceMode.toString(); + + for (AppcOamStates appcOamStates : AppcOamStates.values()) { + String state = appcOamStates.toString(); + if (appcOamStates == AppcOamStates.Started) { + validateProper(state, event, expecteResult); + } else { + validateException(state, event); + } + } + } + + @Test + public void testOamStateTransitionForStart() throws Exception { + String event = AppcOamMetaDataReader.AppcOperation.Start.name(); + String expectResult = AppcOamStates.Starting.toString(); + + List goodStates = Arrays.asList( + AppcOamStates.MaintenanceMode, + AppcOamStates.Stopped, + AppcOamStates.Stopping); + + for (AppcOamStates appcOamStates : AppcOamStates.values()) { + String state = appcOamStates.toString(); + if (goodStates.contains(appcOamStates)) { + validateProper(state, event, expectResult); + } else { + validateException(state, event); + } + } + } + + @Test + public void testOamStateTransitionForStop() throws Exception { + String event = AppcOamMetaDataReader.AppcOperation.Stop.name(); + String expectResult = AppcOamStates.Stopping.toString(); + + List goodStates = Arrays.asList( + AppcOamStates.Error, + AppcOamStates.EnteringMaintenanceMode, + AppcOamStates.MaintenanceMode, + AppcOamStates.Started, + AppcOamStates.Starting); + + for (AppcOamStates appcOamStates : AppcOamStates.values()) { + String state = appcOamStates.toString(); + if (goodStates.contains(appcOamStates)) { + validateProper(state, event, expectResult); + } else { + validateException(state, event); + } + } + } + + + @Test + public void testOamStateTransitionForRestart() throws Exception { + String event = AppcOamMetaDataReader.AppcOperation.Restart.name(); + String expectResult = AppcOamStates.Restarting.toString(); + + List goodStates = Arrays.asList( + AppcOamStates.Error, + AppcOamStates.EnteringMaintenanceMode, + AppcOamStates.MaintenanceMode, + AppcOamStates.Started, + AppcOamStates.Starting, + AppcOamStates.Stopped, + AppcOamStates.Stopping); + + for (AppcOamStates appcOamStates : AppcOamStates.values()) { + String state = appcOamStates.toString(); + if (goodStates.contains(appcOamStates)) { + validateProper(state, event, expectResult); + } else { + validateException(state, event); + } + } + } +} diff --git a/appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/openecomp/appc/LifecycleManagerTest.java b/appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/openecomp/appc/LifecycleManagerTest.java deleted file mode 100644 index 07aef6cb3..000000000 --- a/appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/openecomp/appc/LifecycleManagerTest.java +++ /dev/null @@ -1,185 +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; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.appc.exceptions.InvalidInputException; -import org.onap.appc.lifecyclemanager.LifecycleManager; -import org.onap.appc.statemachine.StateMetaDataReader; -import org.onap.appc.lifecyclemanager.impl.LifecycleManagerImpl; -import org.onap.appc.lifecyclemanager.objects.LifecycleException; -import org.onap.appc.lifecyclemanager.objects.NoTransitionDefinedException; -import org.onap.appc.statemachine.impl.readers.VnfMetaDataReader; -import org.onap.appc.statemachine.impl.readers.VnfMetaDataReader.VNFOperation; -import org.onap.appc.statemachine.objects.Event; -import org.onap.appc.statemachine.objects.State; -import org.onap.appc.statemachine.objects.StateMachineMetadata; -import org.onap.appc.statemachine.objects.Transition; - -import java.util.*; - - -public class LifecycleManagerTest { - - private static final State[] VALID_LOCK_STATES = new State[] { - new State("instantiated"), - new State("configured"), - new State("tested"), - new State("running"), - new State("error"), - new State("unknown"), - new State("created"), - new State("not orchestrated"), - new State("stopped"), - }; - - @Test - public void handleEvent() throws InvalidInputException, LifecycleException, NoTransitionDefinedException { - - StateMachineMetadata metadata = getMetaDataReader().readMetadata(); - LifecycleManagerImpl lifecycleManager = new LifecycleManagerImpl(); - - /* - * Testing Positive Scenario passing the valid events and validating the StateMachineResponse - */ - for(State state:metadata.getStates()){ - - for(Transition transition:state.getTransitions()){ - Event event = transition.getEvent(); - State nextStateFromMetadata = transition.getNextState(); - - String expectedNextState = lifecycleManager.getNextState(null,state.toString(),event.toString()); - Assert.assertEquals(expectedNextState,nextStateFromMetadata.toString()); - } - } - - /* - Testing Negative Scenarios, 1. Passing the valid Events for which Transition is not defined in - Metadata and validating the StateMachineResponse 2. Passing the invalid events which are not - registered as events in the StateMachineMetadata and validating StateMachineResponse - */ - for(State state:metadata.getStates()){ - - for(Transition transition:state.getTransitions()){ - List negativeEvents = getNegativeEvents(state,metadata.getEvents()); - - for(Event negativeEvent:negativeEvents){ - boolean flag =false; - try{ - lifecycleManager.getNextState(null,state.toString(),negativeEvent.toString()); - - } - catch (NoTransitionDefinedException e){ - flag =true; - } - Assert.assertEquals(flag,true); - - flag = false; - try{ - lifecycleManager.getNextState(null,state.toString(),"PUT"); - } - catch(LifecycleException e){ - flag = true; - } - Assert.assertTrue(flag); - - } - } - } - } - - @Test - public void testNotOrchestratedState() throws LifecycleException, NoTransitionDefinedException { - LifecycleManager lifecycleManager = new LifecycleManagerImpl(); - String nextState = lifecycleManager.getNextState( - null,"NOT ORCHESTRATED",VNFOperation.Configure.toString()); - Assert.assertEquals(nextState,"Configuring"); - } - - @Test(expected = NoTransitionDefinedException.class) - public void testBakckingUpState() throws LifecycleException, NoTransitionDefinedException { - LifecycleManager lifecycleManager = new LifecycleManagerImpl(); - lifecycleManager.getNextState(null,"Software_Uploading",VNFOperation.Configure.toString()); - } - - private List getNegativeEvents(State state,Set events) { - List negativeEventList = new ArrayList<>(); - negativeEventList.addAll(events); - - for(Transition transition: state.getTransitions()){ - negativeEventList.remove(transition.getEvent()); - } - return negativeEventList; - } - - @Test - public void testLockStates() throws LifecycleException, NoTransitionDefinedException { - StateMachineMetadata metadata = getMetaDataReader().readMetadata(); - LifecycleManagerImpl lifecycleManager = new LifecycleManagerImpl(); - - for(State state: metadata.getStates()) { - if(isValidState(state, VALID_LOCK_STATES)) { - assertSameNextState(lifecycleManager, state, VNFOperation.Lock); - assertSameNextState(lifecycleManager, state, VnfMetaDataReader.VNFOperation.Unlock); - assertSameNextState(lifecycleManager, state, VNFOperation.CheckLock); - } else { - assertNoNextState(lifecycleManager, state, VNFOperation.Lock); - assertNoNextState(lifecycleManager, state, VNFOperation.Unlock); - assertNoNextState(lifecycleManager, state, VNFOperation.CheckLock); - } - } - } - - private boolean isValidState(State state, State[] validStates) { - for(State validState: validStates) { - if(validState.equals(state)) { - return true; - } - } - return false; - } - - private void assertSameNextState(LifecycleManager lifecycleManager, State state, VNFOperation operation) - throws LifecycleException, NoTransitionDefinedException { - Assert.assertEquals(state.getStateName(), - lifecycleManager.getNextState("no-matter", state.getStateName(), operation.toString())); - } - - private void assertNoNextState(LifecycleManager lifecycleManager, State state, VNFOperation operation) - throws LifecycleException { - try { - lifecycleManager.getNextState("no-matter", state.getStateName(), operation.toString()); - Assert.fail("lifecycleManager.getNextState() should fail for state [" + state - + "], operation [" + operation + "]"); - } catch(NoTransitionDefinedException e) { - // this exception is excepted - } - } - - private StateMetaDataReader getMetaDataReader() { - return new VnfMetaDataReader(); - } -} diff --git a/appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/openecomp/appc/OamLifeCycleManagerTest.java b/appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/openecomp/appc/OamLifeCycleManagerTest.java deleted file mode 100644 index 403a9f39e..000000000 --- a/appc-lifecycle-management/appc-lifecycle-management-core/src/test/java/org/openecomp/appc/OamLifeCycleManagerTest.java +++ /dev/null @@ -1,152 +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; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.onap.appc.lifecyclemanager.impl.LifecycleManagerImpl; -import org.onap.appc.lifecyclemanager.objects.LifecycleException; -import org.onap.appc.lifecyclemanager.objects.NoTransitionDefinedException; -import org.onap.appc.statemachine.impl.readers.AppcOamMetaDataReader; -import org.onap.appc.statemachine.impl.readers.AppcOamStates; - -import java.util.Arrays; -import java.util.List; - - -public class OamLifeCycleManagerTest { - private static final String VNF_TYPE_APPC = "APPC"; - private static final String NO_DEFINITION_FORMAT = "No Transition Defined for currentState = %s, event = %s"; - - private LifecycleManagerImpl lifecycleManager; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Before - public void setUp() throws Exception { - lifecycleManager = new LifecycleManagerImpl(); - } - - private void validateProper(String state, String event, String expectedResult) - throws LifecycleException, NoTransitionDefinedException { - String nextState = lifecycleManager.getNextState(VNF_TYPE_APPC, state, event); - Assert.assertEquals(String.format("Should return %s", expectedResult), expectedResult, nextState); - } - - private void validateException(String state, String event) throws LifecycleException, NoTransitionDefinedException { - expectedException.expect(NoTransitionDefinedException.class); - expectedException.expectMessage(String.format(NO_DEFINITION_FORMAT, state, event)); - lifecycleManager.getNextState(VNF_TYPE_APPC, state, event); - - // Reset to no expectation - expectedException = ExpectedException.none(); - } - - @Test - public void testOamStateTransitionForMaintenanceMode() throws Exception { - String event = AppcOamMetaDataReader.AppcOperation.MaintenanceMode.name(); - String expecteResult = AppcOamStates.EnteringMaintenanceMode.toString(); - - for (AppcOamStates appcOamStates : AppcOamStates.values()) { - String state = appcOamStates.toString(); - if (appcOamStates == AppcOamStates.Started) { - validateProper(state, event, expecteResult); - } else { - validateException(state, event); - } - } - } - - @Test - public void testOamStateTransitionForStart() throws Exception { - String event = AppcOamMetaDataReader.AppcOperation.Start.name(); - String expectResult = AppcOamStates.Starting.toString(); - - List goodStates = Arrays.asList( - AppcOamStates.MaintenanceMode, - AppcOamStates.Stopped, - AppcOamStates.Stopping); - - for (AppcOamStates appcOamStates : AppcOamStates.values()) { - String state = appcOamStates.toString(); - if (goodStates.contains(appcOamStates)) { - validateProper(state, event, expectResult); - } else { - validateException(state, event); - } - } - } - - @Test - public void testOamStateTransitionForStop() throws Exception { - String event = AppcOamMetaDataReader.AppcOperation.Stop.name(); - String expectResult = AppcOamStates.Stopping.toString(); - - List goodStates = Arrays.asList( - AppcOamStates.Error, - AppcOamStates.EnteringMaintenanceMode, - AppcOamStates.MaintenanceMode, - AppcOamStates.Started, - AppcOamStates.Starting); - - for (AppcOamStates appcOamStates : AppcOamStates.values()) { - String state = appcOamStates.toString(); - if (goodStates.contains(appcOamStates)) { - validateProper(state, event, expectResult); - } else { - validateException(state, event); - } - } - } - - - @Test - public void testOamStateTransitionForRestart() throws Exception { - String event = AppcOamMetaDataReader.AppcOperation.Restart.name(); - String expectResult = AppcOamStates.Restarting.toString(); - - List goodStates = Arrays.asList( - AppcOamStates.Error, - AppcOamStates.EnteringMaintenanceMode, - AppcOamStates.MaintenanceMode, - AppcOamStates.Started, - AppcOamStates.Starting, - AppcOamStates.Stopped, - AppcOamStates.Stopping); - - for (AppcOamStates appcOamStates : AppcOamStates.values()) { - String state = appcOamStates.toString(); - if (goodStates.contains(appcOamStates)) { - validateProper(state, event, expectResult); - } else { - validateException(state, event); - } - } - } -} -- cgit 1.2.3-korg