Thomas Vachuska | f9c8436 | 2015-04-15 11:20:45 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onlab.stc; |
| 17 | |
| 18 | import org.junit.BeforeClass; |
| 19 | import org.junit.Test; |
| 20 | |
| 21 | import java.io.FileNotFoundException; |
| 22 | import java.io.IOException; |
| 23 | |
| 24 | import static org.onlab.stc.CompilerTest.getStream; |
| 25 | import static org.onlab.stc.Coordinator.print; |
| 26 | import static org.onlab.stc.Scenario.loadScenario; |
| 27 | |
| 28 | /** |
| 29 | * Test of the test coordinator. |
| 30 | */ |
| 31 | public class CoordinatorTest { |
| 32 | |
| 33 | private Coordinator coordinator; |
| 34 | private StepProcessListener listener = new Listener(); |
| 35 | |
| 36 | @BeforeClass |
| 37 | public static void setUpClass() throws IOException { |
| 38 | CompilerTest.setUpClass(); |
| 39 | StepProcessor.launcher = "true "; |
| 40 | } |
| 41 | |
| 42 | @Test |
| 43 | public void simple() throws FileNotFoundException, InterruptedException { |
| 44 | executeTest("simple-scenario.xml"); |
| 45 | } |
| 46 | |
| 47 | @Test |
| 48 | public void complex() throws FileNotFoundException, InterruptedException { |
| 49 | executeTest("scenario.xml"); |
| 50 | } |
| 51 | |
| 52 | private void executeTest(String name) throws FileNotFoundException, InterruptedException { |
| 53 | Scenario scenario = loadScenario(getStream(name)); |
| 54 | Compiler compiler = new Compiler(scenario); |
| 55 | compiler.compile(); |
| 56 | coordinator = new Coordinator(scenario, compiler.processFlow(), compiler.logDir()); |
| 57 | coordinator.addListener(listener); |
| 58 | coordinator.start(); |
| 59 | coordinator.waitFor(); |
| 60 | coordinator.removeListener(listener); |
| 61 | } |
| 62 | |
| 63 | private class Listener implements StepProcessListener { |
| 64 | @Override |
| 65 | public void onStart(Step step) { |
| 66 | print("> %s: started", step.name()); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public void onCompletion(Step step, int exitCode) { |
| 71 | print("< %s: %s", step.name(), exitCode == 0 ? "completed" : "failed"); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public void onOutput(Step step, String line) { |
| 76 | print(" %s: %s", step.name(), line); |
| 77 | } |
| 78 | } |
| 79 | } |