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