Moving all files to root directory
[appc.git] / appc-dispatcher / appc-dispatcher-common / state-machine-lib / src / test / java / org / openecomp / appc / statemachine / TestStateMachine.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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  */
21
22 package org.openecomp.appc.statemachine;
23
24
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.*;
29
30 import java.util.ArrayList;
31 import java.util.List;
32 import java.util.Set;
33
34
35 public class TestStateMachine {
36
37     @Test
38     public void handleEvent() throws InvalidInputException {
39
40 //        MetadataReader metadataReader = new MetadataReader();
41 //        StateMachineMetadata metadata = metadataReader.readMetadata(null);
42 //
43 //        StateMachine machine = StateMachineFactory.getStateMachine(metadata);
44 //
45 //        /*
46 //        Testing Positive Scenario passing the valid events and validating the StateMachineResponse
47 //         */
48 //        for(State state:metadata.getStates()){
49 //
50 //            for(Transition transition:state.getTransitions()){
51 //                Event event = transition.getEvent();
52 //                State nextState = transition.getNextState();
53 //
54 //                StateMachineResponse response = machine.handleEvent(state,event);
55 //                Assert.assertEquals(response.getNextState(),nextState);
56 //                Assert.assertEquals(response.getResponse(),Response.VALID_TRANSITION);
57 //            }
58 //        }
59 //
60 //        /*
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
64 //         */
65 //        for(State state:metadata.getStates()){
66 //
67 //            for(Transition transition:state.getTransitions()){
68 //                List<Event> negativeEvents = getNegativeEvents(state,metadata.getEvents());
69 //
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);
74 //
75 //                    boolean flag =false;
76 //                    try{
77 //                        response = machine.handleEvent(state,new Event("PUT"));
78 //                    }
79 //                    catch(InvalidInputException e){
80 //                        flag = true;
81 //                    }
82 //                    Assert.assertTrue(flag);
83 //
84 //                }
85 //            }
86 //        }
87     }
88
89 //    private List<Event> getNegativeEvents(State state,Set<Event> events) {
90 //        List<Event> negativeEventList = new ArrayList<>();
91 //        negativeEventList.addAll(events);
92 //
93 //        for(Transition transition: state.getTransitions()){
94 //            negativeEventList.remove(transition.getEvent());
95 //        }
96 //        return negativeEventList;
97 //    }
98 }