Author: mladen.turk(a)jboss.com
Date: 2008-05-28 11:42:16 -0400 (Wed, 28 May 2008)
New Revision: 1628
Added:
sandbox/aloha/test/
sandbox/aloha/test/org/
sandbox/aloha/test/org/jboss/
sandbox/aloha/test/org/jboss/aloha/
sandbox/aloha/test/org/jboss/aloha/TestAll.java
sandbox/aloha/test/org/jboss/aloha/TestParameter.java
sandbox/aloha/test/org/jboss/aloha/TestResponseBodyParser.java
Log:
Add basic test code
Added: sandbox/aloha/test/org/jboss/aloha/TestAll.java
===================================================================
--- sandbox/aloha/test/org/jboss/aloha/TestAll.java (rev 0)
+++ sandbox/aloha/test/org/jboss/aloha/TestAll.java 2008-05-28 15:42:16 UTC (rev 1628)
@@ -0,0 +1,54 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import junit.framework.*;
+
+/**
+ */
+public class TestAll extends TestCase
+{
+
+ public TestAll(String testName)
+ {
+ super(testName);
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite();
+ // Fundamentals
+ suite.addTest(TestParameter.suite());
+ suite.addTest(TestResponseBodyParser.suite());
+ return suite;
+ }
+
+ public static void main(String args[])
+ {
+ String[] testCaseName = { TestAll.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+}
Property changes on: sandbox/aloha/test/org/jboss/aloha/TestAll.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/test/org/jboss/aloha/TestParameter.java
===================================================================
--- sandbox/aloha/test/org/jboss/aloha/TestParameter.java (rev 0)
+++ sandbox/aloha/test/org/jboss/aloha/TestParameter.java 2008-05-28 15:42:16 UTC (rev
1628)
@@ -0,0 +1,140 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.util.Date;
+import junit.framework.*;
+
+/**
+ * Parameter Test.
+ *
+ */
+public class TestParameter extends TestCase
+{
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(TestParameter.class);
+ return suite;
+ }
+
+ public void testInit()
+ throws Exception
+ {
+ Parameter p;
+ p = new Parameter("Foo", null);
+ assertEquals("Value ", "", p.getValue());
+ }
+
+ public void testString()
+ throws Exception
+ {
+ Parameter p;
+ p = new Parameter("Foo", false, ParameterType.String);
+ assertEquals("Value ", "", p.getValue());
+ assertEquals("String ", "Foo=", p.toString());
+ p.setValue("1 2");
+ assertEquals("Value ", "1 2", p.getValue());
+ assertEquals("String ", "Foo=\"1 2\"",
p.toString());
+ }
+
+ public void testStringArray()
+ throws Exception
+ {
+ Parameter p;
+ p = new Parameter("Foo", false, ParameterType.StringArray);
+ assertEquals("Value ", "", p.getStringArray()[0]);
+ assertEquals("String ", "Foo=", p.toString());
+ p.setValue("1 2:3");
+ assertEquals("Value ", "1 2:3", p.getValue());
+ assertEquals("String ", "Foo=\"1 2:3\"",
p.toString());
+ assertEquals("Value[1] ", "2:3", p.getStringArray()[1]);
+ }
+
+ public void testInteger()
+ throws Exception
+ {
+ Parameter p;
+ p = new Parameter("Foo", false, ParameterType.Integer);
+ assertEquals("Value ", 0, p.getInteger());
+ assertEquals("String ", "Foo=0", p.toString());
+ p.setValue("1 2");
+ assertEquals("Value ", "0", p.getValue());
+ p.setValue(-1);
+ assertEquals("String ", "Foo=-1", p.toString());
+ }
+
+ public void testBoolean()
+ throws Exception
+ {
+ Parameter p;
+ p = new Parameter("Foo", false, ParameterType.Boolean);
+ assertFalse(p.getBoolean());
+ assertEquals("String ", "Foo=False", p.toString());
+ p.putValue("oN");
+ assertEquals("Type ", BooleanType.On, p.getBooleanType());
+ assertTrue(p.getBoolean());
+ p.putValue("y");
+ assertEquals("String ", "Foo=Y", p.toString());
+ assertTrue(p.getBoolean());
+ p.setValue(BooleanType.No);
+ assertEquals("Type ", BooleanType.No, p.getBooleanType());
+ assertFalse(p.getBoolean());
+ }
+
+ public void testReadOnly()
+ throws Exception
+ {
+ Parameter p;
+ p = new Parameter("Foo", true, ParameterType.Boolean);
+ p.putValue("off");
+ assertEquals("Type", BooleanType.Off, p.getBooleanType());
+ assertFalse(p.getBoolean());
+ try {
+ p.setValue(BooleanType.Yes);
+ assertTrue(p.getBoolean());
+ p.setValue(BooleanType.No);
+ assertEquals("Reached ", "should not", "did");
+ } catch (IllegalAccessException e) {
+ assertTrue(p.getBoolean());
+ }
+ }
+
+ public void testDate()
+ throws Exception
+ {
+ Parameter p;
+ p = new Parameter("Foo", false, ParameterType.Date);
+ p.setValue(1000L);
+ assertEquals("Date", new Date(1000L), p.getDate());
+ p = new Parameter("Foo", false, ParameterType.Rfc822Date);
+ p.setValue(1000L);
+ assertEquals("Date", new Date(1000L), p.getDate());
+ p.putValue("Thu, 1 Jan 1970 00:00:02 GMT");
+ assertEquals("Date", new Date(2000L), p.getDate());
+ assertEquals("Date", 2000L, p.getLong());
+ }
+
+
+}
Property changes on: sandbox/aloha/test/org/jboss/aloha/TestParameter.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/test/org/jboss/aloha/TestResponseBodyParser.java
===================================================================
--- sandbox/aloha/test/org/jboss/aloha/TestResponseBodyParser.java
(rev 0)
+++ sandbox/aloha/test/org/jboss/aloha/TestResponseBodyParser.java 2008-05-28 15:42:16 UTC
(rev 1628)
@@ -0,0 +1,160 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import junit.framework.*;
+
+/**
+ * ResponseBodyParser Test.
+ *
+ */
+public class TestResponseBodyParser extends TestCase
+{
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(TestResponseBodyParser.class);
+ return suite;
+ }
+
+ public void testEmptyLine()
+ throws Exception
+ {
+ ResponseBodyParser p;
+ p = new ResponseBodyParser("");
+ assertEquals("ResponseType", ResponseType.Empty, p.getResponseType());
+ p = new ResponseBodyParser("\r\n");
+ assertEquals("ResponseType", ResponseType.Empty, p.getResponseType());
+ assertTrue(p.isOk());
+ }
+
+ public void testErrorLine()
+ throws Exception
+ {
+ ResponseBodyParser p;
+ p = new ResponseBodyParser("?");
+ assertTrue(p.isError());
+ p = new ResponseBodyParser("?Error");
+ assertTrue(p.isError());
+ p = new ResponseBodyParser("?Error:");
+ assertTrue(p.isError());
+ p = new ResponseBodyParser("?Error: 1");
+ assertEquals("Error code", 22, p.getErrorCode());
+ p = new ResponseBodyParser("?Error: 1;");
+ assertEquals("Error code", 22, p.getErrorCode());
+ p = new ResponseBodyParser("?Error: ; Description");
+ assertEquals("Error code", 22, p.getErrorCode());
+ p = new ResponseBodyParser("?Error: 1; Description");
+ assertEquals("Error code", 1, p.getErrorCode());
+ }
+
+ public void testProtocolError()
+ throws Exception
+ {
+ ResponseBodyParser p;
+ p = new ResponseBodyParser("?MCMP/1.0");
+ assertTrue(p.getResponseType() == ResponseType.ProtocolError);
+ assertEquals("Error description", "1.0",
p.getErrorDescription());
+ }
+
+ public void testUnknownTypeError()
+ throws Exception
+ {
+ ResponseBodyParser p;
+ p = new ResponseBodyParser("?Unknown-Type:");
+ assertTrue(p.getResponseType() == ResponseType.UnknownType);
+ p = new ResponseBodyParser("?Unknown-Type: Foo");
+ assertEquals("Unknown-Type", "Foo",
p.getErrorDescription());
+ }
+
+ public void testUnknownResourceError()
+ throws Exception
+ {
+ ResponseBodyParser p;
+ p = new ResponseBodyParser("?Unknown-Resource:");
+ assertTrue(p.getResponseType() == ResponseType.UnknownResource);
+ p = new ResponseBodyParser("?Unknown-Resource: Foo");
+ assertEquals("Unknown-Resource", "Foo",
p.getErrorDescription());
+ }
+
+ public void testOk()
+ throws Exception
+ {
+ ResponseBodyParser p;
+ p = new ResponseBodyParser("OK");
+ assertTrue(p.isOk());
+ }
+
+ public void testLines()
+ throws Exception
+ {
+ ResponseBodyParser p;
+ p = new ResponseBodyParser("\r\nOK");
+ assertTrue(p.isOk());
+ }
+
+ public void testParam()
+ throws Exception
+ {
+ ResponseBodyParser p;
+ p = new ResponseBodyParser("A");
+ assertTrue(p.isOk());
+ Parameter v;
+ v = p.getResources().get(0).getParameters().get(0);
+ assertEquals("Parameter name", "?", v.getName());
+ assertEquals("Parameter value", "A", v.getValue());
+ p = new ResponseBodyParser("A=B");
+ assertTrue(p.isOk());
+ v = p.getResources().get(0).getParameters().get(0);
+ assertEquals("Parameter name", "A", v.getName());
+ assertEquals("Parameter value", "B", v.getValue());
+ p = new ResponseBodyParser("A=B; ; ; C=\"D:B\"");
+ assertTrue(p.isOk());
+ v = p.getResources().get(0).getParameters().get(1);
+ assertEquals("Parameter name", "C", v.getName());
+ assertEquals("Parameter value", "D:B", v.getValue());
+ }
+
+ public void testResource()
+ throws Exception
+ {
+ ResponseBodyParser p;
+ p = new ResponseBodyParser("OK\r\n?Error\r\n@Member: Foo=Bar");
+ assertTrue(p.isOk());
+ GenericResource r;
+ Parameter v;
+ r = p.getResources().get(0);
+ assertEquals("Resource Type", ResourceType.Member,
r.getResourceType());
+ v = r.getParameters().get(0);
+ assertEquals("Parameter name", "Foo", v.getName());
+ assertEquals("Parameter value", "Bar", v.getValue());
+ p = new ResponseBodyParser("@Host/_default_");
+ assertTrue(p.isOk());
+ r = p.getResources().get(0);
+ assertEquals("Resource Type", ResourceType.Host,
r.getResourceType());
+ assertEquals("Resource Name", "_default_",
r.getResourceName());
+
+ }
+
+}
Property changes on: sandbox/aloha/test/org/jboss/aloha/TestResponseBodyParser.java
___________________________________________________________________
Name: svn:eol-style
+ native