2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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=========================================================
22 package org.openecomp.appc.statemachine;
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.openecomp.appc.statemachine.impl.StateMachineFactory;
28 import org.openecomp.appc.statemachine.objects.*;
30 import java.util.ArrayList;
31 import java.util.List;
35 public class TestStateMachine {
38 public void handleEvent() throws InvalidInputException {
40 // MetadataReader metadataReader = new MetadataReader();
41 // StateMachineMetadata metadata = metadataReader.readMetadata(null);
43 // StateMachine machine = StateMachineFactory.getStateMachine(metadata);
46 // Testing Positive Scenario passing the valid events and validating the StateMachineResponse
48 // for(State state:metadata.getStates()){
50 // for(Transition transition:state.getTransitions()){
51 // Event event = transition.getEvent();
52 // State nextState = transition.getNextState();
54 // StateMachineResponse response = machine.handleEvent(state,event);
55 // Assert.assertEquals(response.getNextState(),nextState);
56 // Assert.assertEquals(response.getResponse(),Response.VALID_TRANSITION);
61 // Testing Negative Scenarios, 1. Passing the valid Events for which Transition is not defined in
62 // Metadata and validating the StateMachineResponse 2. Passing the invalid events which are not
63 // registered as events in the StateMachineMetadata and validating StateMachineResponse
65 // for(State state:metadata.getStates()){
67 // for(Transition transition:state.getTransitions()){
68 // List<Event> negativeEvents = getNegativeEvents(state,metadata.getEvents());
70 // for(Event negativeEvent:negativeEvents){
71 // StateMachineResponse response = machine.handleEvent(state,negativeEvent);
72 // Assert.assertEquals(response.getNextState(),null);
73 // Assert.assertEquals(response.getResponse(),Response.NO_TRANSITION_DEFINED);
75 // boolean flag =false;
77 // response = machine.handleEvent(state,new Event("PUT"));
79 // catch(InvalidInputException e){
82 // Assert.assertTrue(flag);
89 // private List<Event> getNegativeEvents(State state,Set<Event> events) {
90 // List<Event> negativeEventList = new ArrayList<>();
91 // negativeEventList.addAll(events);
93 // for(Transition transition: state.getTransitions()){
94 // negativeEventList.remove(transition.getEvent());
96 // return negativeEventList;