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.openecomp.appc.statemachine;
28 import org.junit.Assert;
29 import org.junit.Test;
30 import org.openecomp.appc.statemachine.impl.StateMachineFactory;
31 import org.openecomp.appc.statemachine.objects.*;
33 import java.util.ArrayList;
34 import java.util.List;
38 public class TestStateMachine {
41 public void handleEvent() throws InvalidInputException {
43 // MetadataReader metadataReader = new MetadataReader();
44 // StateMachineMetadata metadata = metadataReader.readMetadata(null);
46 // StateMachine machine = StateMachineFactory.getStateMachine(metadata);
49 // Testing Positive Scenario passing the valid events and validating the StateMachineResponse
51 // for(State state:metadata.getStates()){
53 // for(Transition transition:state.getTransitions()){
54 // Event event = transition.getEvent();
55 // State nextState = transition.getNextState();
57 // StateMachineResponse response = machine.handleEvent(state,event);
58 // Assert.assertEquals(response.getNextState(),nextState);
59 // Assert.assertEquals(response.getResponse(),Response.VALID_TRANSITION);
64 // Testing Negative Scenarios, 1. Passing the valid Events for which Transition is not defined in
65 // Metadata and validating the StateMachineResponse 2. Passing the invalid events which are not
66 // registered as events in the StateMachineMetadata and validating StateMachineResponse
68 // for(State state:metadata.getStates()){
70 // for(Transition transition:state.getTransitions()){
71 // List<Event> negativeEvents = getNegativeEvents(state,metadata.getEvents());
73 // for(Event negativeEvent:negativeEvents){
74 // StateMachineResponse response = machine.handleEvent(state,negativeEvent);
75 // Assert.assertEquals(response.getNextState(),null);
76 // Assert.assertEquals(response.getResponse(),Response.NO_TRANSITION_DEFINED);
78 // boolean flag =false;
80 // response = machine.handleEvent(state,new Event("PUT"));
82 // catch(InvalidInputException e){
85 // Assert.assertTrue(flag);
92 // private List<Event> getNegativeEvents(State state,Set<Event> events) {
93 // List<Event> negativeEventList = new ArrayList<>();
94 // negativeEventList.addAll(events);
96 // for(Transition transition: state.getTransitions()){
97 // negativeEventList.remove(transition.getEvent());
99 // return negativeEventList;