Added:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/url/ShortViewURLConstructorTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/url/ShortViewURLConstructorTest.java?rev=682151&view=auto
==============================================================================
---
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/url/ShortViewURLConstructorTest.java
(added)
+++
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/url/ShortViewURLConstructorTest.java
Sun Aug 3 05:28:09 2008
@@ -0,0 +1,143 @@
+/*
+ * (C) Janne Jalkanen 2005
+ *
+ */
+package com.ecyrd.jspwiki.url;
+
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.WikiException;
+
+public class ShortViewURLConstructorTest extends TestCase
+{
+ TestEngine testEngine;
+
+ Properties props = new Properties();
+
+ protected void setUp() throws Exception
+ {
+ props.load( TestEngine.findTestProperties() );
+ }
+
+ private URLConstructor getConstructor( String baseURL, String prefix )
+ throws WikiException
+ {
+ props.setProperty( WikiEngine.PROP_BASEURL, baseURL );
+ if( prefix != null ) props.setProperty(
ShortViewURLConstructor.PROP_PREFIX, prefix );
+
+ testEngine = new TestEngine(props);
+ URLConstructor constr = new ShortViewURLConstructor();
+
+ constr.initialize( testEngine, props );
+
+ return constr;
+ }
+
+ public void testViewURL1()
+ throws Exception
+ {
+ URLConstructor c = getConstructor( "http://localhost/", "wiki/" );
+
+ assertEquals( "http://localhost/wiki/Main",
c.makeURL(WikiContext.VIEW,"Main",true,null) );
+ }
+
+ public void testViewURL2()
+ throws Exception
+ {
+ URLConstructor c = getConstructor( "http://localhost/mywiki/", null );
+
+ assertEquals( "http://localhost/mywiki/wiki/Main",
c.makeURL(WikiContext.VIEW,"Main",true,null) );
+ }
+
+ public void testViewURL3()
+ throws Exception
+ {
+ URLConstructor c = getConstructor( "http://localhost:8080/", null );
+
+ assertEquals( "http://localhost:8080/wiki/Main",
c.makeURL(WikiContext.VIEW,"Main",true,null) );
+ }
+
+ public void testViewURL4()
+ throws Exception
+ {
+ URLConstructor c = getConstructor( "http://localhost/mywiki/", null );
+
+ assertEquals( "/mywiki/wiki/Main",
c.makeURL(WikiContext.VIEW,"Main",false,null) );
+ }
+
+ public void testViewURL5()
+ throws Exception
+ {
+ URLConstructor c = getConstructor( "http://localhost/", "" );
+
+ assertEquals( "http://localhost/Main",
c.makeURL(WikiContext.VIEW,"Main",true,null) );
+ }
+
+ public void testViewURL6()
+ throws Exception
+ {
+ URLConstructor c = getConstructor( "http://localhost/mywiki/app1/",
null );
+
+ assertEquals( "http://localhost/mywiki/app1/wiki/Main",
c.makeURL(WikiContext.VIEW,"Main",true,null) );
+ }
+
+ public void testViewURL7()
+ throws Exception
+ {
+ URLConstructor c = getConstructor( "http://localhost/mywiki/app1/",
"view/" );
+
+ assertEquals( "http://localhost/mywiki/app1/view/Main",
c.makeURL(WikiContext.VIEW,"Main",true,null) );
+ }
+
+ public void testEditURL1()
+ throws Exception
+ {
+ URLConstructor c = getConstructor( "http://localhost/mywiki/", null );
+
+ assertEquals( "http://localhost/mywiki/Edit.jsp?page=Main",
c.makeURL(WikiContext.EDIT,"Main",true,null) );
+ }
+
+ public void testAttachURL1()
+ throws Exception
+ {
+ URLConstructor c = getConstructor( "http://localhost/mywiki/", null );
+
+ assertEquals( "http://localhost/mywiki/attach/Main/foo.txt",
c.makeURL(WikiContext.ATTACH,"Main/foo.txt",true,null) );
+ }
+
+ public void testAttachURLRelative1()
+ throws Exception
+ {
+ URLConstructor c = getConstructor( "http://localhost/mywiki/", null );
+
+ assertEquals( "/mywiki/attach/Main/foo.txt",
c.makeURL(WikiContext.ATTACH,"Main/foo.txt",false,null) );
+ }
+
+ public void testOtherURL1()
+ throws Exception
+ {
+ URLConstructor c = getConstructor( "http://localhost/mywiki/", null );
+
+ assertEquals( "http://localhost/mywiki/foo.jsp",
c.makeURL(WikiContext.NONE,"foo.jsp",true,null) );
+ }
+
+ public void testOtherURL2()
+ throws Exception
+ {
+ URLConstructor c = getConstructor( "http://localhost/mywiki/dobble/",
null );
+
+ assertEquals( "http://localhost/mywiki/dobble/foo.jsp?a=1&b=2",
c.makeURL(WikiContext.NONE,"foo.jsp",true,"a=1&b=2") );
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( ShortViewURLConstructorTest.class );
+ }
+}
Propchange:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/url/ShortViewURLConstructorTest.java
------------------------------------------------------------------------------
svn:executable = *
Modified:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/AllTests.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/AllTests.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
---
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/AllTests.java
(original)
+++
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/AllTests.java
Sun Aug 3 05:28:09 2008
@@ -17,9 +17,12 @@
suite.addTest( ClassUtilTest.suite() );
suite.addTest( CommentedPropertiesTest.suite() );
+ suite.addTest( CryptoUtilTest.suite() );
suite.addTest( MailUtilTest.suite() );
suite.addTest( PriorityListTest.suite() );
+ suite.addTest( SerializerTest.suite() );
suite.addTest( TextUtilTest.suite() );
+ suite.addTest( TimedCounterListTest.suite() );
return suite;
}
Added:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/CryptoUtilTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/CryptoUtilTest.java?rev=682151&view=auto
==============================================================================
---
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/CryptoUtilTest.java
(added)
+++
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/CryptoUtilTest.java
Sun Aug 3 05:28:09 2008
@@ -0,0 +1,157 @@
+package com.ecyrd.jspwiki.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.commons.codec.binary.Base64;
+
+public class CryptoUtilTest extends TestCase
+{
+
+ public static Test suite()
+ {
+ return new TestSuite( CryptoUtilTest.class );
+ }
+
+ public void testCommandLineHash() throws Exception
+ {
+ // Save old printstream
+ PrintStream oldOut = System.out;
+
+ // Swallow System out and get command output
+ OutputStream out = new ByteArrayOutputStream();
+ System.setOut( new PrintStream( out ) );
+ CryptoUtil.main( new String[] { "--hash", "password" } );
+ String output = new String( out.toString() );
+
+ // Restore old printstream
+ System.setOut( oldOut );
+
+ // Run our tests
+ assertTrue( output.startsWith( "{SSHA}" ) );
+ }
+
+ public void testCommandLineNoVerify() throws Exception
+ {
+ // Save old printstream
+ PrintStream oldOut = System.out;
+
+ // Swallow System out and get command output
+ OutputStream out = new ByteArrayOutputStream();
+ System.setOut( new PrintStream( out ) );
+ // Supply a bogus password
+ CryptoUtil.main( new String[] { "--verify", "password",
"{SSHA}yfT8SRT/WoOuNuA6KbJeF10OznZmb28=" } );
+ String output = new String( out.toString() );
+
+ // Restore old printstream
+ System.setOut( oldOut );
+
+ // Run our tests
+ assertTrue( output.startsWith( "false" ) );
+ }
+
+ public void testCommandLineSyntaxError1() throws Exception
+ {
+ // Try verifying password without the {SSHA} prefix
+ try {
+ CryptoUtil.main( new String[] { "--verify", "password",
"yfT8SRT/WoOuNuA6KbJeF10OznZmb28=" } );
+ }
+ catch (IllegalArgumentException e)
+ {
+ // Excellent; we expected an error
+ }
+ }
+
+ public void testCommandLineVerify() throws Exception
+ {
+ // Save old printstream
+ PrintStream oldOut = System.out;
+
+ // Swallow System out and get command output
+ OutputStream out = new ByteArrayOutputStream();
+ System.setOut( new PrintStream( out ) );
+ CryptoUtil.main( new String[] { "--verify", "testing123",
"{SSHA}yfT8SRT/WoOuNuA6KbJeF10OznZmb28=" } );
+ String output = new String( out.toString() );
+
+ // Restore old printstream
+ System.setOut( oldOut );
+
+ // Run our tests
+ assertTrue( output.startsWith( "true" ) );
+ }
+
+ public void testExtractHash()
+ {
+ byte[] digest;
+
+ digest = Base64.decodeBase64(
"yfT8SRT/WoOuNuA6KbJeF10OznZmb28=".getBytes() );
+ assertEquals( "foo", new String( CryptoUtil.extractSalt( digest ) ) );
+
+ digest = Base64.decodeBase64(
"tAVisOOQGAeVyP8UMFQY9qi83lxsb09e".getBytes() );
+ assertEquals( "loO^", new String( CryptoUtil.extractSalt( digest ) ) );
+
+ digest = Base64.decodeBase64(
"BZaDYvB8czmNW3MjR2j7/mklODV0ZXN0eQ==".getBytes() );
+ assertEquals( "testy", new String( CryptoUtil.extractSalt( digest ) )
);
+ }
+
+ public void testGetSaltedPassword() throws Exception
+ {
+ byte[] password;
+
+ // Generate a hash with a known password and salt
+ password = "testing123".getBytes();
+ assertEquals( "{SSHA}yfT8SRT/WoOuNuA6KbJeF10OznZmb28=",
CryptoUtil.getSaltedPassword( password, "foo".getBytes() ) );
+
+ // Generate two hashes with a known password and 2 different salts
+ password = "password".getBytes();
+ assertEquals( "{SSHA}tAVisOOQGAeVyP8UMFQY9qi83lxsb09e",
CryptoUtil.getSaltedPassword( password, "loO^".getBytes() ) );
+ assertEquals( "{SSHA}BZaDYvB8czmNW3MjR2j7/mklODV0ZXN0eQ==",
CryptoUtil.getSaltedPassword( password, "testy".getBytes() ) );
+ }
+
+ public void testMultipleHashes() throws Exception
+ {
+ String p1 = CryptoUtil.getSaltedPassword( "password".getBytes() );
+ String p2 = CryptoUtil.getSaltedPassword( "password".getBytes() );
+ String p3 = CryptoUtil.getSaltedPassword( "password".getBytes() );
+ assertNotSame( p1, p2 );
+ assertNotSame( p2, p3 );
+ assertNotSame( p1, p3 );
+ }
+
+ public void testSaltedPasswordLength() throws Exception
+ {
+ // Generate a hash with a known password and salt
+ byte[] password = "mySooperRandomPassword".getBytes();
+ String hash = CryptoUtil.getSaltedPassword( password,
"salt".getBytes() );
+
+ // slappasswd says that a 4-byte salt should give us 6 chars for prefix
+ // + 20 chars for the hash + 12 for salt (38 total)
+ assertEquals( 38, hash.length() );
+ }
+
+ public void verifySaltedPassword() throws Exception
+ {
+ byte[] password;
+
+ // Verify with a known digest
+ password = "testing123".getBytes("UTF-8");
+ assertTrue( CryptoUtil.verifySaltedPassword( password,
"{SSHA}yfT8SRT/WoOuNuA6KbJeF10OznZmb28=" ) );
+
+ // Verify with two more known digests
+ password = "password".getBytes();
+ assertTrue( CryptoUtil.verifySaltedPassword( password,
"{SSHA}tAVisOOQGAeVyP8UMFQY9qi83lxsb09e" ) );
+ assertTrue( CryptoUtil.verifySaltedPassword( password,
"{SSHA}BZaDYvB8czmNW3MjR2j7/mklODV0ZXN0eQ==" ) );
+
+ // Verify with three consecutive random generations (based on
+ // slappasswd)
+ password = "testPassword".getBytes();
+ assertTrue( CryptoUtil.verifySaltedPassword( password,
"{SSHA}t2tfJHm/QZYUh0OZ8tkm05l2LLbuc3ZF" ) );
+ assertTrue( CryptoUtil.verifySaltedPassword( password,
"{SSHA}0FKV9iM2cA5bAMws7mSgwg+zik/GT+wy" ) );
+ assertTrue( CryptoUtil.verifySaltedPassword( password,
"{SSHA}/0Dzvh+8+w0YO673Qr7vqEOmdeMSrbGG" ) );
+ }
+}
Modified:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/MailUtilTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/MailUtilTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
---
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/MailUtilTest.java
(original)
+++
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/MailUtilTest.java
Sun Aug 3 05:28:09 2008
@@ -1,8 +1,11 @@
package com.ecyrd.jspwiki.util;
+import java.net.ConnectException;
import java.util.Properties;
+import javax.mail.MessagingException;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -52,7 +55,7 @@
TestEngine testEngine = new TestEngine( m_props );
- m_context = testEngine.getWikiActionBeanFactory().newViewActionBean(
new WikiPage( testEngine, PAGE_NAME ) );
+ m_context = testEngine.getWikiActionBeanFactory().newViewActionBean(
null, null, new WikiPage( testEngine, PAGE_NAME ) );
}
public void tearDown()
@@ -85,8 +88,6 @@
{
m_props.setProperty( "jspwiki.usePageCache", "true" );
-
System.out.println(m_context.getEngine().getWikiProperties().getProperty(MailUtil.PROP_MAIL_ACCOUNT));
-
String user = System.getProperty( "user.name" ) + "@localhost";
try
@@ -96,6 +97,19 @@
"Mail test",
"This is a test mail generated by
MailUtilTest.");
}
+ catch( MessagingException e )
+ {
+ if( e.getCause() instanceof ConnectException )
+ {
+ // This can occur if you do not have a SMTP server set up. We
just log this
+ // and don't fail.
+ System.out.println("I could not test whether mail sending
works, since I could not connect to your SMTP server.");
+ System.out.println("Reason: "+e.getMessage());
+ return;
+ }
+ e.printStackTrace();
+ fail( "Unknown problem (check the console for error report)" );
+ }
catch (Exception e)
{
e.printStackTrace();
Added:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/SerializerTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/SerializerTest.java?rev=682151&view=auto
==============================================================================
---
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/SerializerTest.java
(added)
+++
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/SerializerTest.java
Sun Aug 3 05:28:09 2008
@@ -0,0 +1,33 @@
+package com.ecyrd.jspwiki.util;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class SerializerTest extends TestCase
+{
+
+ public static Test suite()
+ {
+ return new TestSuite( SerializerTest.class );
+ }
+
+ public void testSerializeMap() throws Exception
+ {
+ Map<String, Serializable> map = new HashMap<String, Serializable>();
+ map.put( "attribute1", "some random value" );
+ map.put( "attribute2", "another value" );
+ String serializedForm = Serializer.serializeToBase64( map );
+
+ Map<String, ? extends Serializable> newMap =
Serializer.deserializeFromBase64( serializedForm );
+ assertEquals( 2, newMap.size() );
+ assertTrue( newMap.containsKey( "attribute1" ) );
+ assertTrue( newMap.containsKey( "attribute2" ) );
+ assertEquals( "some random value", newMap.get( "attribute1" ) );
+ assertEquals( "another value", newMap.get( "attribute2" ) );
+ }
+}
Added:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/TimedCounterListTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/TimedCounterListTest.java?rev=682151&view=auto
==============================================================================
---
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/TimedCounterListTest.java
(added)
+++
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/util/TimedCounterListTest.java
Sun Aug 3 05:28:09 2008
@@ -0,0 +1,53 @@
+package com.ecyrd.jspwiki.util;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class TimedCounterListTest extends TestCase
+{
+ TimedCounterList<String> m_list = new TimedCounterList<String>();
+
+ public void setUp()
+ {
+ m_list.add( "Foo" );
+ m_list.add( "Foo" );
+ m_list.add( "Foo" );
+ m_list.add( "Bar" );
+ }
+
+ public void testCount()
+ {
+ assertEquals( "Foo", 3, m_list.count( "Foo" ) );
+ assertEquals( "Bar", 1, m_list.count( "Bar" ) );
+ assertEquals( "Baz", 0, m_list.count( "Baz" ) );
+ }
+
+ public void testCleanup()
+ {
+ try
+ {
+ Thread.sleep(110);
+
+ m_list.cleanup(100);
+
+ assertEquals( "Foo", 0, m_list.count( "Foo" ) );
+ assertEquals( "Bar", 0, m_list.count( "Foo" ) );
+ assertEquals( "Baz", 0, m_list.count( "Foo" ) );
+
+ assertEquals( "size", 0, m_list.size() );
+ }
+ catch( InterruptedException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( TimedCounterListTest.class );
+ }
+
+}
Modified:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/AllTests.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/AllTests.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
---
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/AllTests.java
(original)
+++
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/AllTests.java
Sun Aug 3 05:28:09 2008
@@ -15,11 +15,6 @@
public static Test suite()
{
TestSuite suite = new TestSuite("JSPWiki web unit tests");
- suite.addTestSuite( com.ecyrd.jspwiki.web.CustomTest.class );
- suite.addTestSuite( com.ecyrd.jspwiki.web.CustomAbsoluteTest.class
);
- suite.addTestSuite( com.ecyrd.jspwiki.web.CustomJDBCTest.class );
- suite.addTestSuite( com.ecyrd.jspwiki.web.ContainerTest.class );
- suite.addTestSuite( com.ecyrd.jspwiki.web.ContainerJDBCTest.class
);
return suite;
}
}
Added:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/TestContainer.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/TestContainer.java?rev=682151&view=auto
==============================================================================
---
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/TestContainer.java
(added)
+++
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/TestContainer.java
Sun Aug 3 05:28:09 2008
@@ -0,0 +1,376 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package com.ecyrd.jspwiki.web;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+
+import org.apache.log4j.Logger;
+import org.hsqldb.jdbc.jdbcDataSource;
+import org.mortbay.http.*;
+import org.mortbay.http.handler.SecurityHandler;
+import org.mortbay.jetty.plus.DefaultDataSourceService;
+import org.mortbay.jetty.plus.Server;
+import org.mortbay.jetty.servlet.WebApplicationContext;
+import org.mortbay.jndi.ContextFactory;
+import org.mortbay.jndi.InitialContextFactory;
+import org.mortbay.jndi.NamingContext;
+import org.mortbay.jndi.Util;
+import org.mortbay.util.Password;
+
+import com.ecyrd.jspwiki.auth.Users;
+
+/**
+ * Lightweight wrapper that starts and stops an embedded Jetty server on a
+ * hard-coded port [EMAIL PROTECTED] #HTTP_PORT}. The server can be shut down
by sending a
+ * request to the shutdown port, which is hard-coded to [EMAIL PROTECTED]
#SHUTDOWN_PORT}.
+ */
+public class TestContainer
+{
+ private final Server server;
+
+ /**
+ * High port that listens for web application requests.
+ */
+ public static final int HTTP_PORT = 10024;
+
+ /**
+ * High port that listens for shutdown requests.
+ */
+ public static final int SHUTDOWN_PORT = 19041;
+
+ public static final String INITIAL_CONTEXT_FACTORY =
"java.naming.factory.initial";
+
+ // Minimum and maximum number of jetty threads
+ public static final int MIN_JETTY_THREADS = 1;
+
+ public static final int MAX_JETTY_THREADS = 1024;
+
+ public static final int DEFAULT_JETTY_THREADS = 512;
+
+ /** Number of jetty threads for the server. */
+ private static int jettyThreads = DEFAULT_JETTY_THREADS;
+
+ private static final Logger log = Logger.getLogger( TestContainer.class );
+
+ /**
+ * Starts up a test server for a particular web application on the
specified
+ * port (or default if no port was specified).
+ *
+ * @param args the command-line arguments
+ * @throws Exception - you know, just in case.
+ */
+ public static void main( String[] args ) throws Exception
+ {
+ // Extract key-value pairs that represent test contexts and directories
+ Map<String, String> apps = extractApps( args );
+ if( apps.size() == 0 )
+ {
+ throw new IllegalArgumentException( "No apps supplied!" );
+ }
+
+ // If we get here, then everything parsed ok...
+
+ // Create a new server and load up the webapps
+ TestContainer container = new TestContainer();
+ for( Map.Entry<String, String> app : apps.entrySet() )
+ {
+ String context = app.getKey();
+ String path = app.getValue();
+ log.info( "Adding context " + context + " at path " + path );
+ container.addWebApp( context, path );
+ }
+
+ // Create the DataSource service
+ DefaultDataSourceService dss = new DefaultDataSourceService();
+ dss.setName( "DataSourceService" );
+
+ // Create the connection pool
+ jdbcDataSource cpds = new jdbcDataSource();
+ cpds.setDatabase( "jdbc:hsqldb:hsql://localhost/jspwiki" );
+ cpds.setLoginTimeout( 10 );
+ cpds.setUser( "SA" );
+ cpds.setPassword( null );
+
+ // Configure and bind DataSource to JNDI for user database
+ dss.addDataSource( "jdbc/UserDatabase", cpds );
+ container.server.addService( dss );
+ dss.getDataSource( "jdbc/UserDatabase" );
+
+ // Configure and bind DataSource to JNDI for group database
+ dss.addDataSource( "jdbc/GroupDatabase", cpds );
+ container.server.addService( dss );
+ dss.getDataSource( "jdbc/GroupDatabase" );
+
+ System.out.println( "Configured datasources." );
+
+ // Start the server
+ try
+ {
+ System.out.println( "Starting up test container." );
+ container.start();
+ }
+ catch( Throwable t )
+ {
+ t.printStackTrace();
+ System.err.println( t.getMessage() );
+ System.exit( 1 );
+ }
+ System.out.println( "Started." );
+
+ }
+
+ private static Map<String, String> extractApps( String[] args )
+ {
+ Map<String, String> apps = new HashMap<String, String>();
+ for( int i = 0; i < args.length; i++ )
+ {
+ String[] pair = args[i].split( "=" );
+
+ // Right length?
+ if( pair.length != 2 )
+ {
+ throw new IllegalArgumentException( "Malformed argument '" +
args[i] + "'; expected 'context=path' pattern." );
+ }
+
+ // Extract and sanitize first arg
+ String context = pair[0].trim();
+ if( !context.startsWith( "/" ) )
+ {
+ context = "/" + context;
+ }
+
+ // Extract and verify the path
+ String path = pair[1].trim();
+ File file = new File( path );
+ if( !file.exists() )
+ {
+ throw new IllegalArgumentException( "Path " + path + " does
not exist." );
+ }
+ if( !file.isDirectory() )
+ {
+ throw new IllegalArgumentException( "Path " + path + " cannot
be a file; it must be a directory." );
+ }
+
+ apps.put( context, path );
+ }
+
+ return apps;
+ }
+
+ /**
+ * Prepares a Jetty server with its HTTP and shutdown handlers. Callers
must
+ * start the server by calling [EMAIL PROTECTED] #start()}.
+ *
+ * @throws Exception you know, just in case
+ */
+ public TestContainer() throws Exception
+ {
+ // Initialize JNDI for the server, using the Jetty JNDI packages if
not set yet
+ // Normally this is set at JVM startup by property
-Djava.naming.factory.initial=classname
+ String contextFactoryClass = System.getProperty(
INITIAL_CONTEXT_FACTORY );
+ if ( contextFactoryClass == null )
+ {
+ System.setProperty( INITIAL_CONTEXT_FACTORY,
"org.mortbay.jndi.InitialContextFactory" );
+ ContextFactory.setNameParser( new
InitialContextFactory.DefaultParser() );
+ log.info( "No JNDI context factory found; using
org.mortbay.jndi.InitialContextFactory." );
+ }
+ log.info( "Initialized JNDI with context factory class=" +
contextFactoryClass + "." );
+
+ // Bind the "java:comp" namespace if not bound already
+ Context initCtx = new InitialContext();
+ try
+ {
+ initCtx.lookup( "java:comp" );
+ }
+ catch ( NameNotFoundException e )
+ {
+ Util.bind( initCtx, "java:comp", new NamingContext() );
+ NamingContext compCtx = (NamingContext) initCtx.lookup(
"java:comp" );
+ compCtx.setNameParser( new InitialContextFactory.DefaultParser() );
+ log.info( "No JNDI java:comp namespace found; creating it," );
+ // Context envCtx = compCtx.createSubcontext( "env" );
+ // System.out.println( envCtx );
+ }
+ log.info( "Initialized JNDI java:comp namespace.=" +
contextFactoryClass );
+
+ // Initialize new Jetty server
+ log.info( "Creating new test container." );
+ System.setProperty( "org.mortbay.xml.XmlParser.NotValidating", "true"
);
+ server = new Server();
+ server.setStopAtShutdown( true );
+
+ // Create HTTP listener
+ SocketListener listener = new SocketListener();
+ listener.setHost( "localhost" );
+ listener.setMaxIdleTimeMs( 60000 );
+ listener.setMaxThreads( jettyThreads );
+ listener.setPort( HTTP_PORT );
+ server.addListener( listener );
+ log.info( "...added HTTP listener for port " + HTTP_PORT );
+
+ // Create shutdown listener
+ listener = new SocketListener();
+ listener.setHost( "localhost" );
+ listener.setMaxThreads( jettyThreads );
+ listener.setPort( SHUTDOWN_PORT );
+ listener.setHttpHandler( new ShutdownHandler() );
+ server.addListener( listener );
+ log.info( "...added shutdown listener for port " + SHUTDOWN_PORT );
+
+ // Set the default users and roles for the realm (note that realm name
*must* match web.xml <realm-name>
+ HashUserRealm realm = new HashUserRealm( "JSPWikiRealm" );
+ realm.put( Users.ADMIN, new Password( Users.ADMIN_PASS ) );
+ realm.addUserToRole( Users.ADMIN, "Authenticated" );
+ realm.addUserToRole( Users.ADMIN, "Admin" );
+ realm.put( Users.JANNE, new Password( Users.JANNE_PASS ) );
+ realm.addUserToRole( Users.JANNE, "Authenticated" );
+ server.addRealm( realm );
+ }
+
+ /**
+ * Configures a test web application
+ *
+ * @param m_context the name of the web m_context; must start with "/"
+ * @param path the file path for the WAR file, or expanded WAR directory
+ * @return the configured web application
+ * @throws IOException
+ */
+ public WebApplicationContext addWebApp( String context, String path )
throws IOException
+ {
+ WebApplicationContext webapp = server.addWebApplication( context, path
);
+ log.info( "Adding test webapp " + context + " for path " + path );
+
+ // Add a security handler for any constraints enabled by web.xml
+ SecurityHandler sh = new SecurityHandler();
+ webapp.addHandler( sh );
+
+ return webapp;
+ }
+
+ /**
+ * Starts the Jetty server
+ */
+ public void start() throws Exception
+ {
+ System.setProperty( "org.mortbay.http.HttpRequest.maxFormContentSize",
"0" );
+ server.start();
+ }
+
+ /**
+ * Stops the Jetty server
+ */
+ public void stop()
+ {
+ try
+ {
+ server.stop();
+ }
+ catch( InterruptedException ex )
+ {
+ throw new RuntimeException( ex );
+ }
+ }
+
+ /**
+ * HTTP Handler that shuts down the Jetty server if a request is received
on
+ * the shutdown port..
+ */
+ public static final class ShutdownHandler implements HttpHandler
+ {
+ private static final long serialVersionUID = -7785141243907081919L;
+
+ private HttpContext m_context;
+
+ /**
+ * Returns the HttpContext used to initialize this handler.
+ */
+ public HttpContext getHttpContext()
+ {
+ return m_context;
+ }
+
+ /**
+ * No-op method that always returns a generic description of the
+ * shutdown handler.
+ */
+ public String getName()
+ {
+ return "Shutdown HTTP handler.";
+ }
+
+ /**
+ * Intercepts the HTTP request and shuts down the server instantly.
+ */
+ public void handle( String arg0, String arg1, HttpRequest arg2,
HttpResponse arg3 ) throws HttpException, IOException
+ {
+ System.exit(0);
+// System.err.println( "Shutdown request detected." );
+// try
+// {
+// m_server.stop( false );
+// }
+// catch( InterruptedException e )
+// {
+// e.printStackTrace();
+// throw new HttpException(
HttpResponse.__500_Internal_Server_Error, e.getMessage() );
+// }
+ }
+
+ /**
+ * No-op method that sets a reference to the HttpContext supplied to
the
+ * initialize method.
+ */
+ public void initialize( HttpContext context )
+ {
+ m_context = context;
+ }
+
+ /**
+ * No-op method that always returns <code>true</code>.
+ */
+ public boolean isStarted()
+ {
+ return true;
+ }
+
+ /**
+ * No-op method that does nothing.
+ */
+ public void start() throws Exception
+ {
+ }
+
+ /**
+ * No-op method that does nothing.
+ */
+ public void stop() throws InterruptedException
+ {
+ }
+ }
+
+}
Propchange:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/web/TestContainer.java
------------------------------------------------------------------------------
svn:executable = *
Modified:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/ApprovalWorkflowTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/ApprovalWorkflowTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
---
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/ApprovalWorkflowTest.java
(original)
+++
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/ApprovalWorkflowTest.java
Sun Aug 3 05:28:09 2008
@@ -258,6 +258,7 @@
*/
public static class TestPrepTask extends Task
{
+ private static final long serialVersionUID = 1L;
public TestPrepTask( String messageKey )
{
Modified:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/DecisionQueueTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/DecisionQueueTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
---
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/DecisionQueueTest.java
(original)
+++
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/DecisionQueueTest.java
Sun Aug 3 05:28:09 2008
@@ -1,21 +1,22 @@
/*
JSPWiki - a JSP-based WikiWiki clone.
- Copyright (C) 2001-2007 Janne Jalkanen ([EMAIL PROTECTED])
-
- This program 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.1 of the License, or
- (at your option) any later version.
-
- This program 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 program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
*/
package com.ecyrd.jspwiki.workflow;
Modified:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/OutcomeTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/OutcomeTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
---
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/OutcomeTest.java
(original)
+++
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/OutcomeTest.java
Sun Aug 3 05:28:09 2008
@@ -40,7 +40,7 @@
props.load(TestEngine.findTestProperties());
WikiEngine engine = new TestEngine(props);
InternationalizationManager i18n =
engine.getInternationalizationManager();
- String core = InternationalizationManager.CORE_BUNDLE;
+ String core = "templates.default";
Locale english = Locale.ENGLISH;
Outcome o;
Modified:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/TaskTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/TaskTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
---
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/TaskTest.java
(original)
+++
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/workflow/TaskTest.java
Sun Aug 3 05:28:09 2008
@@ -17,6 +17,8 @@
/** Sample Task that completes normally. */
public static class NormalTask extends Task
{
+ private static final long serialVersionUID = 1L;
+
public NormalTask(Workflow workflow)
{
super(workflow, "task.normal");
@@ -31,6 +33,8 @@
/** Sample Task that encounters an error during processing. */
public static class ErrorTask extends Task
{
+ private static final long serialVersionUID = 1L;
+
public ErrorTask(Workflow workflow)
{
super(workflow, "task.error");
Modified:
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/xmlrpc/RPCHandlerTest.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/xmlrpc/RPCHandlerTest.java?rev=682151&r1=682150&r2=682151&view=diff
==============================================================================
---
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/xmlrpc/RPCHandlerTest.java
(original)
+++
incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/tests/com/ecyrd/jspwiki/xmlrpc/RPCHandlerTest.java
Sun Aug 3 05:28:09 2008
@@ -30,7 +30,7 @@
m_engine = new TestEngine( m_props );
m_handler = new RPCHandler();
- WikiContext ctx =
m_engine.getWikiActionBeanFactory().newViewActionBean( new WikiPage(m_engine,
"Dummy") );
+ WikiContext ctx =
m_engine.getWikiActionBeanFactory().newViewActionBean( null, null, new
WikiPage(m_engine, "Dummy") );
m_handler.initialize( ctx );
}