Testing updates.

* Fixing MavenTestingUtils.toTargetURL() mistake.
* Moving phase from generate-resources to generate-test-resources
* Fixing testing flow in JettyPolicyRuntimeTest

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@695 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Joakim Erdfelt 2009-08-11 17:38:45 +00:00
parent 735454017b
commit 8b50f2e543
4 changed files with 48 additions and 67 deletions

View File

@ -38,7 +38,7 @@
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<phase>generate-test-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
@ -58,7 +58,7 @@
</execution>
<execution>
<id>copy</id>
<phase>generate-resources</phase>
<phase>generate-test-resources</phase>
<goals>
<goal>copy</goal>
</goals>

View File

@ -61,6 +61,7 @@ public class KeystoreEntry extends AbstractEntry
return keystore;
}
@Override
public void expand( PolicyContext context ) throws PolicyException
{
url = context.evaluate( url );

View File

@ -88,12 +88,11 @@ public class JettyPolicyRuntimeTest extends TestCase
File test3 = new File( "/tmp/foo/bar/do" );
test3.mkdirs();
test3.delete();
assertTrue( "Under AllPermission we are allowed", true );
}
catch ( AccessControlException ace )
{
//ace.printStackTrace();
assertFalse( "Exception was thrown which it shouldn't have been", true );
ace.printStackTrace(System.err);
fail("Should NOT have thrown an AccessControlException");
}
JettyPolicy ap2 = new JettyPolicy(getSinglePolicy("global-file-read-only-tmp-permission.policy"),evaluator);
@ -102,17 +101,17 @@ public class JettyPolicyRuntimeTest extends TestCase
Policy.setPolicy( ap2 );
// Test that the new policy does replace the old one and we are now now allowed
// Test that the new policy does replace the old one and we are now not allowed
try
{
File test3 = new File( "/tmp/foo/bar/do" );
test3.mkdirs();
assertFalse( "We should be restricted and not get here.", true );
fail("Should have thrown an AccessControlException");
}
catch ( AccessControlException ace )
{
//ace.printStackTrace();
assertTrue( "Exception was thrown as it should be.", true );
// Expected Path
}
}
@ -143,14 +142,14 @@ public class JettyPolicyRuntimeTest extends TestCase
try
{
File test3 = new File( "/tmp/foo/bar/do" );
File test3 = new File("/tmp/foo/bar/do");
test3.mkdirs();
assertTrue( "we should not get here", false );
fail("Should have thrown an AccessControlException");
}
catch ( AccessControlException ace )
catch (AccessControlException ace)
{
//ace.printStackTrace();
assertTrue( "Exception was thrown", true );
// Expected Path
}
}
@ -164,8 +163,6 @@ public class JettyPolicyRuntimeTest extends TestCase
return;
}
System.out.println("test");
JettyPolicy ap = new JettyPolicy(getSinglePolicy("jetty-certificate.policy"),evaluator);
// ap.dump( System.out );
@ -192,37 +189,23 @@ public class JettyPolicyRuntimeTest extends TestCase
ap.refresh();
try
{
Class<?> clazz = loader.loadClass("org.eclipse.jetty.toolchain.test.policy.Tester");
Method m = clazz.getMethod( "testEcho", new Class[] {String.class} );
String foo = (String)m.invoke( clazz.newInstance(), new Object[] {"foo"} );
assertEquals("foo", foo );
Method m2 = clazz.getMethod( "testReadSystemProperty", new Class[] {String.class} );
m2.invoke( clazz.newInstance(), new Object[] {"foo"} );
assertTrue( "system property access was granted", true );
}
catch ( ClassNotFoundException e )
{
e.printStackTrace();
assertFalse( "should not have got here", true );
}
catch ( SecurityException e )
{
e.printStackTrace();
assertFalse( "should not have got here", true );
}
catch ( IllegalAccessException e )
{
e.printStackTrace();
assertFalse( "should not have got here", true );
}
Class<?> clazz = loader.loadClass("org.eclipse.jetty.toolchain.test.policy.Tester");
Method m = clazz.getMethod("testEcho",new Class[]
{ String.class });
String foo = (String)m.invoke(clazz.newInstance(),new Object[]
{ "foo" });
assertEquals("foo",foo);
Method m2 = clazz.getMethod("testReadSystemProperty",new Class[]
{ String.class });
m2.invoke(clazz.newInstance(),new Object[]
{ "foo" });
assertTrue("system property access was granted",true);
}
@ -260,8 +243,6 @@ public class JettyPolicyRuntimeTest extends TestCase
ap.refresh();
boolean excepted = false;
try
{
Class<?> clazz = loader.loadClass("org.eclipse.jetty.toolchain.test.policy.Tester");
@ -274,27 +255,15 @@ public class JettyPolicyRuntimeTest extends TestCase
Method m2 = clazz.getMethod( "testReadSystemProperty", new Class[] {String.class} );
m2.invoke( clazz.newInstance(), new Object[] {"foobar"} );
}
catch ( ClassNotFoundException e )
{
e.printStackTrace();
assertFalse( "should not have got here", true );
m2.invoke(clazz.newInstance(),new Object[]
{ "foobar" });
fail("Should have thrown an InvocationTargetException");
}
catch ( InvocationTargetException e )
{
assertTrue(e.getCause().getMessage().contains( "access denied" ));
excepted = true; // we hope to get here
}
catch ( IllegalAccessException e )
{
e.printStackTrace();
assertFalse( "should not have got here", true );
}
assertTrue( "checking that we through a security exception", excepted );
}
private Set<String> getSinglePolicy(String name)

View File

@ -41,10 +41,21 @@ public class MavenTestingUtils
if (cwd == null)
{
// System property not set.
// Use CWD.
cwd = System.getProperty("user.dir");
basedir = new File(cwd);
// Set the System property.
System.setProperty("basedir",basedir.getAbsolutePath());
}
else
{
// Has system property, use it.
basedir = new File(cwd);
}
basedir = new File(cwd);
baseURI = basedir.toURI();
}
@ -193,6 +204,6 @@ public class MavenTestingUtils
public static URL toTargetURL(String path) throws MalformedURLException
{
return getBaseURI().resolve(path).toURL();
return getBaseURI().resolve("target/" + path).toURL();
}
}