Applying license changes to 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  * 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.Assert;
29 import org.junit.Test;
30 import org.openecomp.appc.statemachine.impl.StateMachineFactory;
31 import org.openecomp.appc.statemachine.objects.*;
32
33 import java.util.ArrayList;
34 import java.util.List;
35 import java.util.Set;
36
37
38 public class TestStateMachine {
39
40     @Test
41     public void handleEvent() throws InvalidInputException {
42
43 //        MetadataReader metadataReader = new MetadataReader();
44 //        StateMachineMetadata metadata = metadataReader.readMetadata(null);
45 //
46 //        StateMachine machine = StateMachineFactory.getStateMachine(metadata);
47 //
48 //        /*
49 //        Testing Positive Scenario passing the valid events and validating the StateMachineResponse
50 //         */
51 //        for(State state:metadata.getStates()){
52 //
53 //            for(Transition transition:state.getTransitions()){
54 //                Event event = transition.getEvent();
55 //                State nextState = transition.getNextState();
56 //
57 //                StateMachineResponse response = machine.handleEvent(state,event);
58 //                Assert.assertEquals(response.getNextState(),nextState);
59 //                Assert.assertEquals(response.getResponse(),Response.VALID_TRANSITION);
60 //            }
61 //        }
62 //
63 //        /*
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
67 //         */
68 //        for(State state:metadata.getStates()){
69 //
70 //            for(Transition transition:state.getTransitions()){
71 //                List<Event> negativeEvents = getNegativeEvents(state,metadata.getEvents());
72 //
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);
77 //
78 //                    boolean flag =false;
79 //                    try{
80 //                        response = machine.handleEvent(state,new Event("PUT"));
81 //                    }
82 //                    catch(InvalidInputException e){
83 //                        flag = true;
84 //                    }
85 //                    Assert.assertTrue(flag);
86 //
87 //                }
88 //            }
89 //        }
90     }
91
92 //    private List<Event> getNegativeEvents(State state,Set<Event> events) {
93 //        List<Event> negativeEventList = new ArrayList<>();
94 //        negativeEventList.addAll(events);
95 //
96 //        for(Transition transition: state.getTransitions()){
97 //            negativeEventList.remove(transition.getEvent());
98 //        }
99 //        return negativeEventList;
100 //    }
101 }