2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.statemachine;
26 import org.junit.Assert;
27 import org.junit.Test;
28 import org.openecomp.appc.statemachine.impl.StateMachineFactory;
29 import org.openecomp.appc.statemachine.objects.*;
31 import java.util.ArrayList;
32 import java.util.List;
36 public class TestStateMachine {
39 public void handleEvent() throws InvalidInputException {
41 // MetadataReader metadataReader = new MetadataReader();
42 // StateMachineMetadata metadata = metadataReader.readMetadata(null);
44 // StateMachine machine = StateMachineFactory.getStateMachine(metadata);
47 // Testing Positive Scenario passing the valid events and validating the StateMachineResponse
49 // for(State state:metadata.getStates()){
51 // for(Transition transition:state.getTransitions()){
52 // Event event = transition.getEvent();
53 // State nextState = transition.getNextState();
55 // StateMachineResponse response = machine.handleEvent(state,event);
56 // Assert.assertEquals(response.getNextState(),nextState);
57 // Assert.assertEquals(response.getResponse(),Response.VALID_TRANSITION);
62 // Testing Negative Scenarios, 1. Passing the valid Events for which Transition is not defined in
63 // Metadata and validating the StateMachineResponse 2. Passing the invalid events which are not
64 // registered as events in the StateMachineMetadata and validating StateMachineResponse
66 // for(State state:metadata.getStates()){
68 // for(Transition transition:state.getTransitions()){
69 // List<Event> negativeEvents = getNegativeEvents(state,metadata.getEvents());
71 // for(Event negativeEvent:negativeEvents){
72 // StateMachineResponse response = machine.handleEvent(state,negativeEvent);
73 // Assert.assertEquals(response.getNextState(),null);
74 // Assert.assertEquals(response.getResponse(),Response.NO_TRANSITION_DEFINED);
76 // boolean flag =false;
78 // response = machine.handleEvent(state,new Event("PUT"));
80 // catch(InvalidInputException e){
83 // Assert.assertTrue(flag);
90 // private List<Event> getNegativeEvents(State state,Set<Event> events) {
91 // List<Event> negativeEventList = new ArrayList<>();
92 // negativeEventList.addAll(events);
94 // for(Transition transition: state.getTransitions()){
95 // negativeEventList.remove(transition.getEvent());
97 // return negativeEventList;