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