1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *   http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 package org.apache.guacamole.io;
21 
22 import java.io.StringReader;
23 import org.apache.guacamole.GuacamoleException;
24 import org.apache.guacamole.protocol.GuacamoleInstruction;
25 import org.junit.Test;
26 import static org.junit.Assert.*;
27 
28 /**
29  * Tests the ReaderGuacamoleReader implementation of GuacamoleReader, validating
30  * that instructions are parsed correctly.
31  */
32 public class ReaderGuacamoleReaderTest {
33 
34     /**
35      * Test of ReaderGuacamoleReader parsing.
36      *
37      * @throws GuacamoleException If a parse error occurs while parsing the
38      *                            known-good test string.
39      */
40     @Test
testReader()41     public void testReader() throws GuacamoleException {
42 
43         // Test string
44         final String test = "1.a,2.bc,3.def,10.helloworld;4.test,5.test2;0.;3.foo;";
45 
46         GuacamoleReader reader = new ReaderGuacamoleReader(new StringReader(test));
47 
48         GuacamoleInstruction instruction;
49 
50         // Validate first test instruction
51         instruction = reader.readInstruction();
52         assertNotNull(instruction);
53         assertEquals(3, instruction.getArgs().size());
54         assertEquals("a", instruction.getOpcode());
55         assertEquals("bc", instruction.getArgs().get(0));
56         assertEquals("def", instruction.getArgs().get(1));
57         assertEquals("helloworld", instruction.getArgs().get(2));
58 
59         // Validate second test instruction
60         instruction = reader.readInstruction();
61         assertNotNull(instruction);
62         assertEquals(1, instruction.getArgs().size());
63         assertEquals("test", instruction.getOpcode());
64         assertEquals("test2", instruction.getArgs().get(0));
65 
66         // Validate third test instruction
67         instruction = reader.readInstruction();
68         assertNotNull(instruction);
69         assertEquals(0, instruction.getArgs().size());
70         assertEquals("", instruction.getOpcode());
71 
72         // Validate fourth test instruction
73         instruction = reader.readInstruction();
74         assertNotNull(instruction);
75         assertEquals(0, instruction.getArgs().size());
76         assertEquals("foo", instruction.getOpcode());
77 
78         // There should be no more instructions
79         instruction = reader.readInstruction();
80         assertNull(instruction);
81 
82     }
83 
84 
85 
86 }
87