2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
\r
8 * =============================================================================
\r
9 * Licensed under the Apache License, Version 2.0 (the "License");
\r
10 * you may not use this file except in compliance with the License.
\r
11 * You may obtain a copy of the License at
\r
13 * http://www.apache.org/licenses/LICENSE-2.0
\r
15 * Unless required by applicable law or agreed to in writing, software
\r
16 * distributed under the License is distributed on an "AS IS" BASIS,
\r
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
18 * See the License for the specific language governing permissions and
\r
19 * limitations under the License.
\r
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
\r
25 package org.openecomp.appc;
\r
27 import org.junit.Assert;
\r
28 import org.junit.Before;
\r
29 import org.junit.Rule;
\r
30 import org.junit.Test;
\r
31 import org.junit.rules.ExpectedException;
\r
32 import org.openecomp.appc.lifecyclemanager.impl.LifecycleManagerImpl;
\r
33 import org.openecomp.appc.lifecyclemanager.objects.LifecycleException;
\r
34 import org.openecomp.appc.lifecyclemanager.objects.NoTransitionDefinedException;
\r
35 import org.openecomp.appc.statemachine.impl.readers.AppcOamMetaDataReader;
\r
36 import org.openecomp.appc.statemachine.impl.readers.AppcOamStates;
\r
38 import java.util.Arrays;
\r
39 import java.util.List;
\r
42 public class OamLifeCycleManagerTest {
\r
43 private static final String VNF_TYPE_APPC = "APPC";
\r
44 private static final String NO_DEFINITION_FORMAT = "No Transition Defined for currentState = %s, event = %s";
\r
46 private LifecycleManagerImpl lifecycleManager;
\r
49 public ExpectedException expectedException = ExpectedException.none();
\r
52 public void setUp() throws Exception {
\r
53 lifecycleManager = new LifecycleManagerImpl();
\r
56 private void validateProper(String state, String event, String expectedResult)
\r
57 throws LifecycleException, NoTransitionDefinedException {
\r
58 String nextState = lifecycleManager.getNextState(VNF_TYPE_APPC, state, event);
\r
59 Assert.assertEquals(String.format("Should return %s", expectedResult), expectedResult, nextState);
\r
62 private void validateException(String state, String event) throws LifecycleException, NoTransitionDefinedException {
\r
63 expectedException.expect(NoTransitionDefinedException.class);
\r
64 expectedException.expectMessage(String.format(NO_DEFINITION_FORMAT, state, event));
\r
65 lifecycleManager.getNextState(VNF_TYPE_APPC, state, event);
\r
67 // Reset to no expectation
\r
68 expectedException = ExpectedException.none();
\r
72 public void testOamStateTransitionForMaintenanceMode() throws Exception {
\r
73 String event = AppcOamMetaDataReader.AppcOperation.MaintenanceMode.name();
\r
74 String expecteResult = AppcOamStates.EnteringMaintenanceMode.toString();
\r
76 for (AppcOamStates appcOamStates : AppcOamStates.values()) {
\r
77 String state = appcOamStates.toString();
\r
78 if (appcOamStates == AppcOamStates.Started) {
\r
79 validateProper(state, event, expecteResult);
\r
81 validateException(state, event);
\r
87 public void testOamStateTransitionForStart() throws Exception {
\r
88 String event = AppcOamMetaDataReader.AppcOperation.Start.name();
\r
89 String expectResult = AppcOamStates.Starting.toString();
\r
91 List<AppcOamStates> goodStates = Arrays.asList(
\r
92 AppcOamStates.MaintenanceMode,
\r
93 AppcOamStates.Stopped,
\r
94 AppcOamStates.Stopping);
\r
96 for (AppcOamStates appcOamStates : AppcOamStates.values()) {
\r
97 String state = appcOamStates.toString();
\r
98 if (goodStates.contains(appcOamStates)) {
\r
99 validateProper(state, event, expectResult);
\r
101 validateException(state, event);
\r
107 public void testOamStateTransitionForStop() throws Exception {
\r
108 String event = AppcOamMetaDataReader.AppcOperation.Stop.name();
\r
109 String expectResult = AppcOamStates.Stopping.toString();
\r
111 List<AppcOamStates> goodStates = Arrays.asList(
\r
112 AppcOamStates.Error,
\r
113 AppcOamStates.EnteringMaintenanceMode,
\r
114 AppcOamStates.MaintenanceMode,
\r
115 AppcOamStates.Started,
\r
116 AppcOamStates.Starting);
\r
118 for (AppcOamStates appcOamStates : AppcOamStates.values()) {
\r
119 String state = appcOamStates.toString();
\r
120 if (goodStates.contains(appcOamStates)) {
\r
121 validateProper(state, event, expectResult);
\r
123 validateException(state, event);
\r
130 public void testOamStateTransitionForRestart() throws Exception {
\r
131 String event = AppcOamMetaDataReader.AppcOperation.Restart.name();
\r
132 String expectResult = AppcOamStates.Restarting.toString();
\r
134 List<AppcOamStates> goodStates = Arrays.asList(
\r
135 AppcOamStates.Error,
\r
136 AppcOamStates.EnteringMaintenanceMode,
\r
137 AppcOamStates.MaintenanceMode,
\r
138 AppcOamStates.Started,
\r
139 AppcOamStates.Starting,
\r
140 AppcOamStates.Stopped,
\r
141 AppcOamStates.Stopping);
\r
143 for (AppcOamStates appcOamStates : AppcOamStates.values()) {
\r
144 String state = appcOamStates.toString();
\r
145 if (goodStates.contains(appcOamStates)) {
\r
146 validateProper(state, event, expectResult);
\r
148 validateException(state, event);
\r