Merging in bug fixes
[appc.git] / appc-dispatcher / appc-dispatcher-common / state-machine-lib / src / test / java / org / openecomp / appc / statemachine / TestStateMachine.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.openecomp.appc.statemachine;
26
27
28 import org.junit.Test;
29 import org.openecomp.appc.statemachine.objects.InvalidInputException;
30
31
32 public class TestStateMachine {
33
34     @Test
35     public void handleEvent() throws InvalidInputException {
36
37 //        MetadataReader metadataReader = new MetadataReader();
38 //        StateMachineMetadata metadata = metadataReader.readMetadata(null);
39 //
40 //        StateMachine machine = StateMachineFactory.getStateMachine(metadata);
41 //
42 //        /*
43 //        Testing Positive Scenario passing the valid events and validating the StateMachineResponse
44 //         */
45 //        for(State state:metadata.getStates()){
46 //
47 //            for(Transition transition:state.getTransitions()){
48 //                Event event = transition.getEvent();
49 //                State nextState = transition.getNextState();
50 //
51 //                StateMachineResponse response = machine.handleEvent(state,event);
52 //                Assert.assertEquals(response.getNextState(),nextState);
53 //                Assert.assertEquals(response.getResponse(),Response.VALID_TRANSITION);
54 //            }
55 //        }
56 //
57 //        /*
58 //        Testing Negative Scenarios, 1. Passing the valid Events for which Transition is not defined in
59 //        Metadata and validating the StateMachineResponse 2. Passing the invalid events which are not
60 //        registered as events in the StateMachineMetadata and validating StateMachineResponse
61 //         */
62 //        for(State state:metadata.getStates()){
63 //
64 //            for(Transition transition:state.getTransitions()){
65 //                List<Event> negativeEvents = getNegativeEvents(state,metadata.getEvents());
66 //
67 //                for(Event negativeEvent:negativeEvents){
68 //                    StateMachineResponse response = machine.handleEvent(state,negativeEvent);
69 //                    Assert.assertEquals(response.getNextState(),null);
70 //                    Assert.assertEquals(response.getResponse(),Response.NO_TRANSITION_DEFINED);
71 //
72 //                    boolean flag =false;
73 //                    try{
74 //                        response = machine.handleEvent(state,new Event("PUT"));
75 //                    }
76 //                    catch(InvalidInputException e){
77 //                        flag = true;
78 //                    }
79 //                    Assert.assertTrue(flag);
80 //
81 //                }
82 //            }
83 //        }
84     }
85
86 //    private List<Event> getNegativeEvents(State state,Set<Event> events) {
87 //        List<Event> negativeEventList = new ArrayList<>();
88 //        negativeEventList.addAll(events);
89 //
90 //        for(Transition transition: state.getTransitions()){
91 //            negativeEventList.remove(transition.getEvent());
92 //        }
93 //        return negativeEventList;
94 //    }
95 }