GUACAMOLE-1: Refactor org.glyptodon package/groupId to org.apache.

This commit is contained in:
Michael Jumper
2016-03-22 14:05:53 -07:00
parent 2358d88683
commit 6990344697
402 changed files with 1536 additions and 1536 deletions

View File

@@ -0,0 +1,91 @@
/*
* Copyright (C) 2014 Glyptodon LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.apache.guacamole.io;
import java.io.StringReader;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.protocol.GuacamoleInstruction;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Tests the ReaderGuacamoleReader implementation of GuacamoleReader, validating
* that instructions are parsed correctly.
*
* @author Michael Jumper
*/
public class ReaderGuacamoleReaderTest {
/**
* Test of ReaderGuacamoleReader parsing.
*
* @throws GuacamoleException If a parse error occurs while parsing the
* known-good test string.
*/
@Test
public void testReader() throws GuacamoleException {
// Test string
final String test = "1.a,2.bc,3.def,10.helloworld;4.test,5.test2;0.;3.foo;";
GuacamoleReader reader = new ReaderGuacamoleReader(new StringReader(test));
GuacamoleInstruction instruction;
// Validate first test instruction
instruction = reader.readInstruction();
assertNotNull(instruction);
assertEquals(3, instruction.getArgs().size());
assertEquals("a", instruction.getOpcode());
assertEquals("bc", instruction.getArgs().get(0));
assertEquals("def", instruction.getArgs().get(1));
assertEquals("helloworld", instruction.getArgs().get(2));
// Validate second test instruction
instruction = reader.readInstruction();
assertNotNull(instruction);
assertEquals(1, instruction.getArgs().size());
assertEquals("test", instruction.getOpcode());
assertEquals("test2", instruction.getArgs().get(0));
// Validate third test instruction
instruction = reader.readInstruction();
assertNotNull(instruction);
assertEquals(0, instruction.getArgs().size());
assertEquals("", instruction.getOpcode());
// Validate fourth test instruction
instruction = reader.readInstruction();
assertNotNull(instruction);
assertEquals(0, instruction.getArgs().size());
assertEquals("foo", instruction.getOpcode());
// There should be no more instructions
instruction = reader.readInstruction();
assertNull(instruction);
}
}

View File

@@ -0,0 +1,95 @@
/*
* Copyright (C) 2014 Glyptodon LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.apache.guacamole.protocol;
import java.io.StringReader;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.io.GuacamoleReader;
import org.apache.guacamole.io.ReaderGuacamoleReader;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* Test which validates filtering of Guacamole instructions with
* FilteredGuacamoleReader.
*
* @author Michael Jumper
*/
public class FilteredGuacamoleReaderTest {
/**
* Filter which allows through "yes" instructions but drops all others.
*/
private static class TestFilter implements GuacamoleFilter {
@Override
public GuacamoleInstruction filter(GuacamoleInstruction instruction) throws GuacamoleException {
if (instruction.getOpcode().equals("yes"))
return instruction;
return null;
}
}
@Test
public void testFilter() throws Exception {
// Test string
final String test = "3.yes,1.A;2.no,1.B;3.yes,1.C;3.yes,1.D;4.nope,1.E;";
GuacamoleReader reader = new FilteredGuacamoleReader(new ReaderGuacamoleReader(new StringReader(test)),
new TestFilter());
GuacamoleInstruction instruction;
// Validate first instruction
instruction = reader.readInstruction();
assertNotNull(instruction);
assertEquals("yes", instruction.getOpcode());
assertEquals(1, instruction.getArgs().size());
assertEquals("A", instruction.getArgs().get(0));
// Validate second instruction
instruction = reader.readInstruction();
assertNotNull(instruction);
assertEquals("yes", instruction.getOpcode());
assertEquals(1, instruction.getArgs().size());
assertEquals("C", instruction.getArgs().get(0));
// Validate third instruction
instruction = reader.readInstruction();
assertNotNull(instruction);
assertEquals("yes", instruction.getOpcode());
assertEquals(1, instruction.getArgs().size());
assertEquals("D", instruction.getArgs().get(0));
// Should be done now
instruction = reader.readInstruction();
assertNull(instruction);
}
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright (C) 2014 Glyptodon LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.apache.guacamole.protocol;
import java.io.StringWriter;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.io.GuacamoleWriter;
import org.apache.guacamole.io.WriterGuacamoleWriter;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* Test which validates filtering of Guacamole instructions with
* FilteredGuacamoleWriter.
*
* @author Michael Jumper
*/
public class FilteredGuacamoleWriterTest {
/**
* Filter which allows through "yes" instructions but drops all others.
*/
private static class TestFilter implements GuacamoleFilter {
@Override
public GuacamoleInstruction filter(GuacamoleInstruction instruction) throws GuacamoleException {
if (instruction.getOpcode().equals("yes"))
return instruction;
return null;
}
}
@Test
public void testFilter() throws Exception {
StringWriter stringWriter = new StringWriter();
GuacamoleWriter writer = new FilteredGuacamoleWriter(new WriterGuacamoleWriter(stringWriter),
new TestFilter());
// Write a few chunks of complete instructions
writer.write("3.yes,1.A;2.no,1.B;3.yes,1.C;3.yes,1.D;4.nope,1.E;".toCharArray());
writer.write("1.n,3.abc;3.yes,5.hello;2.no,4.test;3.yes,5.world;".toCharArray());
// Validate filtered results
assertEquals("3.yes,1.A;3.yes,1.C;3.yes,1.D;3.yes,5.hello;3.yes,5.world;", stringWriter.toString());
}
}

View File

@@ -0,0 +1,126 @@
/*
* Copyright (C) 2014 Glyptodon LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.apache.guacamole.protocol;
import org.apache.guacamole.GuacamoleException;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* Unit test for GuacamoleParser. Verifies that parsing of the Guacamole
* protocol works as required.
*
* @author Michael Jumper
*/
public class GuacamoleParserTest {
/**
* The GuacamoleParser instance being tested.
*/
private final GuacamoleParser parser = new GuacamoleParser();
/**
* Test of append method, of class GuacamoleParser.
*
* @throws GuacamoleException If a parse error occurs while parsing the
* known-good test string.
*/
@Test
public void testParser() throws GuacamoleException {
// Test string
char buffer[] = "1.a,2.bc,3.def,10.helloworld;4.test,5.test2;0.;3.foo;".toCharArray();
int offset = 0;
int length = buffer.length;
GuacamoleInstruction instruction;
int parsed;
// Parse more data
while (length > 0 && (parsed = parser.append(buffer, offset, length)) != 0) {
offset += parsed;
length -= parsed;
}
// Validate first test instruction
assertTrue(parser.hasNext());
instruction = parser.next();
assertNotNull(instruction);
assertEquals(3, instruction.getArgs().size());
assertEquals("a", instruction.getOpcode());
assertEquals("bc", instruction.getArgs().get(0));
assertEquals("def", instruction.getArgs().get(1));
assertEquals("helloworld", instruction.getArgs().get(2));
// Parse more data
while (length > 0 && (parsed = parser.append(buffer, offset, length)) != 0) {
offset += parsed;
length -= parsed;
}
// Validate second test instruction
assertTrue(parser.hasNext());
instruction = parser.next();
assertNotNull(instruction);
assertEquals(1, instruction.getArgs().size());
assertEquals("test", instruction.getOpcode());
assertEquals("test2", instruction.getArgs().get(0));
// Parse more data
while (length > 0 && (parsed = parser.append(buffer, offset, length)) != 0) {
offset += parsed;
length -= parsed;
}
// Validate third test instruction
assertTrue(parser.hasNext());
instruction = parser.next();
assertNotNull(instruction);
assertEquals(0, instruction.getArgs().size());
assertEquals("", instruction.getOpcode());
// Parse more data
while (length > 0 && (parsed = parser.append(buffer, offset, length)) != 0) {
offset += parsed;
length -= parsed;
}
// Validate fourth test instruction
assertTrue(parser.hasNext());
instruction = parser.next();
assertNotNull(instruction);
assertEquals(0, instruction.getArgs().size());
assertEquals("foo", instruction.getOpcode());
// Parse more data
while (length > 0 && (parsed = parser.append(buffer, offset, length)) != 0) {
offset += parsed;
length -= parsed;
}
// There should be no more instructions
assertFalse(parser.hasNext());
}
}