Made the test pass under Windows.

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2954 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Simone Bordet 2011-04-01 15:26:21 +00:00
parent 35558971d9
commit c7cd3c3233
1 changed files with 16 additions and 32 deletions

View File

@ -14,11 +14,9 @@
package org.eclipse.jetty.server.session; package org.eclipse.jetty.server.session;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.util.Random; import java.util.Random;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.ContentExchange; import org.eclipse.jetty.client.ContentExchange;
@ -27,6 +25,7 @@ import org.eclipse.jetty.http.HttpMethods;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -43,18 +42,6 @@ public abstract class AbstractWebAppObjectInSessionTest
{ {
public abstract AbstractTestServer createServer(int port); public abstract AbstractTestServer createServer(int port);
private void copy(File source, File target) throws Exception
{
FileInputStream input = new FileInputStream(source);
FileOutputStream output = new FileOutputStream(target);
int read = -1;
byte[] bytes = new byte[64];
while ((read = input.read(bytes)) >= 0) output.write(bytes, 0, read);
input.close();
output.close();
}
@Test @Test
public void testWebappObjectInSession() throws Exception public void testWebappObjectInSession() throws Exception
{ {
@ -85,24 +72,21 @@ public abstract class AbstractWebAppObjectInSessionTest
String packageName = WebAppObjectInSessionServlet.class.getPackage().getName(); String packageName = WebAppObjectInSessionServlet.class.getPackage().getName();
File packageDirs = new File(classesDir, packageName.replace('.', File.separatorChar)); File packageDirs = new File(classesDir, packageName.replace('.', File.separatorChar));
packageDirs.mkdirs(); packageDirs.mkdirs();
String resourceName = WebAppObjectInSessionServlet.class.getName().replace('.', File.separatorChar) + ".class";
String resourceName = WebAppObjectInSessionServlet.class.getSimpleName() + ".class";
Resource res = Resource.newResource(getClass().getClassLoader().getResource(resourceName)); Resource resource = Resource.newResource(getClass().getResource(resourceName));
//File sourceFile = new File(getClass().getClassLoader().getResource(resourceName).toURI()); //File sourceFile = new File(getClass().getClassLoader().getResource(resourceName).toURI());
File targetFile = new File(packageDirs, resourceName.substring(packageName.length())); File targetFile = new File(packageDirs, resourceName);
//copy(sourceFile, targetFile); //copy(sourceFile, targetFile);
resourceName = WebAppObjectInSessionServlet.TestSharedNonStatic.class.getName().replace('.', File.separatorChar) + ".class"; IO.copy(resource.getInputStream(), new FileOutputStream(targetFile));
IO.copy(res.getInputStream(), new FileOutputStream(targetFile));
resourceName = WebAppObjectInSessionServlet.class.getSimpleName() + "$" + WebAppObjectInSessionServlet.TestSharedStatic.class.getSimpleName() + ".class";
resourceName = WebAppObjectInSessionServlet.TestSharedStatic.class.getName().replace('.', File.separatorChar) + ".class"; resource = Resource.newResource(getClass().getResource(resourceName));
res = Resource.newResource(getClass().getClassLoader().getResource(resourceName));
//sourceFile = new File(getClass().getClassLoader().getResource(resourceName).toURI()); //sourceFile = new File(getClass().getClassLoader().getResource(resourceName).toURI());
targetFile = new File(packageDirs, resourceName.substring(packageName.length())); targetFile = new File(packageDirs, resourceName);
//copy(sourceFile, targetFile); //copy(sourceFile, targetFile);
IO.copy(res.getInputStream(), new FileOutputStream(targetFile)); IO.copy(resource.getInputStream(), new FileOutputStream(targetFile));
Random random = new Random(System.nanoTime()); Random random = new Random(System.nanoTime());
int port1 = random.nextInt(50000) + 10000; int port1 = random.nextInt(50000) + 10000;