jetty-9 clean jetty-util tests

This commit is contained in:
Greg Wilkins 2012-07-20 16:59:10 +10:00
parent b1750c0aae
commit b2a38ac3fc
17 changed files with 138 additions and 50 deletions

View File

@ -46,7 +46,7 @@ import org.eclipse.jetty.util.log.Logger;
*/
public class UrlEncoded extends MultiMap implements Cloneable
{
private static final Logger LOG = Log.getLogger(UrlEncoded.class);
static final Logger LOG = Log.getLogger(UrlEncoded.class);
public static final String ENCODING = System.getProperty("org.eclipse.jetty.util.UrlEncoding.charset",StringUtil.__UTF8);

View File

@ -387,16 +387,19 @@ public class AggregateLifeCycle extends AbstractLifeCycle implements Destroyable
{
i++;
out.append(indent).append(" +- ");
if (b._managed)
{
out.append(indent).append(" +- ");
if (b._bean instanceof Dumpable)
((Dumpable)b._bean).dump(out,indent+(i==size?" ":" | "));
else
dumpObject(out,b._bean);
}
else
{
out.append(indent).append(" +~ ");
dumpObject(out,b._bean);
}
}
if (i!=size)

View File

@ -411,7 +411,7 @@ public class StdErrLog extends AbstractLogger
format(buffer,level,msg);
if (isHideStacks())
{
format(buffer,String.valueOf(thrown));
format(buffer,": "+String.valueOf(thrown));
}
else
{

View File

@ -88,7 +88,7 @@ public class SslContextFactory extends AbstractLifeCycle
}
}};
private static final Logger LOG = Log.getLogger(SslContextFactory.class);
static final Logger LOG = Log.getLogger(SslContextFactory.class);
public static final String DEFAULT_KEYMANAGERFACTORY_ALGORITHM =
(Security.getProperty("ssl.KeyManagerFactory.algorithm") == null ?

View File

@ -180,7 +180,6 @@ public class URLEncodedTest
ByteArrayInputStream in = new ByteArrayInputStream("name\n=value+%30&name1=&name2&n\u00e3me3=value+3".getBytes(charsets[i][0]));
MultiMap m = new MultiMap();
UrlEncoded.decodeTo(in, m, charsets[i][1], -1,-1);
System.err.println(m);
assertEquals(i+" stream length",4,m.size());
assertEquals(i+" stream name\\n","value 0",m.getString("name\n"));
assertEquals(i+" stream name1","",m.getString("name1"));
@ -244,7 +243,7 @@ public class URLEncodedTest
String query="name=X%c0%afZ";
MultiMap<String> map = new MultiMap<String>();
UrlEncoded.LOG.info("EXPECT 4 Not Valid UTF8 warnings...");
UrlEncoded.decodeUtf8To(query.getBytes(StringUtil.__ISO_8859_1),0,query.length(),map);
assertEquals("X"+Utf8Appendable.REPLACEMENT+Utf8Appendable.REPLACEMENT+"Z",map.getValue("name",0));

View File

@ -100,7 +100,6 @@ public class JSONPojoConvertorFactoryTest
bar.setColor(Color.Green);
String s = jsonOut.toJSON(bar);
System.err.println(s);
assertTrue(s.indexOf("class")<0);

View File

@ -12,7 +12,10 @@ package org.eclipse.jetty.util.component;
//You may elect to redistribute this code under either of these licenses.
//========================================================================
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.concurrent.atomic.AtomicInteger;
import junit.framework.Assert;
@ -224,33 +227,45 @@ public class AggregateLifeCycleTest
}
@Test
public void testDumpable()
public void testDumpable() throws Exception
{
AggregateLifeCycle a0 = new AggregateLifeCycle();
a0.dumpStdErr();
String dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.AggregateLifeCycl");
System.err.println("--");
AggregateLifeCycle aa0 = new AggregateLifeCycle();
a0.addBean(aa0);
a0.dumpStdErr();
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.AggregateLifeCycl");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
System.err.println("--");
AggregateLifeCycle aa1 = new AggregateLifeCycle();
a0.addBean(aa1);
a0.dumpStdErr();
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.AggregateLifeCycl");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump,"");
System.err.println("--");
AggregateLifeCycle aaa0 = new AggregateLifeCycle();
aa0.addBean(aaa0);
a0.dumpStdErr();
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.AggregateLifeCycl");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump," | +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump,"");
System.err.println("--");
AggregateLifeCycle aa10 = new AggregateLifeCycle();
aa1.addBean(aa10);
a0.dumpStdErr();
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.AggregateLifeCycl");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump," | +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump," +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump,"");
System.err.println("--");
final AggregateLifeCycle a1 = new AggregateLifeCycle();
final AggregateLifeCycle a2 = new AggregateLifeCycle();
final AggregateLifeCycle a3 = new AggregateLifeCycle();
@ -267,16 +282,95 @@ public class AggregateLifeCycleTest
}
};
a0.addBean(aa);
a0.dumpStdErr();
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.AggregateLifeCycl");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump," | +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump," | +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump," +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," |");
dump=check(dump," +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump,"");
System.err.println("--");
a2.addBean(aa0);
a0.dumpStdErr();
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.AggregateLifeCycl");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump," | +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump," | +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump," +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," | +- org.eclipse.jetty.util.component.Aggre");
dump=check(dump," | +- org.eclipse.jetty.util.component.A");
dump=check(dump," |");
dump=check(dump," +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump,"");
System.err.println("--");
a0.unmanage(aa);
a2.unmanage(aa0);
a0.dumpStdErr();
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.AggregateLifeCycl");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump," | +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump," | +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump," +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," | +~ org.eclipse.jetty.util.component.Aggre");
dump=check(dump," |");
dump=check(dump," +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump,"");
a0.unmanage(aa);
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.AggregateLifeCycl");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump," | +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +- org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump," | +- org.eclipse.jetty.util.component.Aggregate");
dump=check(dump," +~ org.eclipse.jetty.util.component.AggregateLife");
dump=check(dump,"");
}
String trim(String s) throws IOException
{
StringBuilder b=new StringBuilder();
BufferedReader reader=new BufferedReader(new StringReader(s));
for (String line=reader.readLine();line!=null;line=reader.readLine())
{
if (line.length()>50)
line=line.substring(0,50);
b.append(line).append('\n');
}
return b.toString();
}
String check(String s,String x)
{
String r=s;
int nl = s.indexOf('\n');
if (nl>0)
{
r=s.substring(nl+1);
s=s.substring(0,nl);
}
Assert.assertEquals(x,s);
return r;
}
}

View File

@ -190,7 +190,7 @@ public class JavaUtilLogTest
log.info(null,"Testing","info(null,arg0,arg1)");
log.info(null,null,null);
jul.dump();
//jul.dump();
jul.assertContainsLine("INFO|test.nu.ll|Testing info(msg,null,null) - null/null");
jul.assertContainsLine("INFO|test.nu.ll|Testing info(msg,null,null) > null null");

View File

@ -13,7 +13,6 @@
package org.eclipse.jetty.util.log;
import static org.hamcrest.Matchers.is;
import java.util.HashMap;
import java.util.Map;
@ -86,6 +85,6 @@ public class LogTest
private void assertNamedLogging(Class<?> clazz)
{
Logger lc = Log.getLogger(clazz);
Assert.assertThat("Named logging (impl=" + Log.getLog().getClass().getName() + ")",lc.getName(),is(clazz.getName()));
Assert.assertEquals("Named logging (impl=" + Log.getLog().getClass().getName() + ")",lc.getName(),clazz.getName());
}
}

View File

@ -184,7 +184,7 @@ public class StdErrLogTest
{
Properties props = new Properties();
props.setProperty("log.LEVEL", "WARN");
props.setProperty("org.eclipse.jetty.bad.LEVEL","FRUIT");
props.setProperty("org.eclipse.jetty.bad.LEVEL","EXPECTED_BAD_LEVEL");
// Default Level (because of bad level value)
Assert.assertEquals("Bad Logging Level",StdErrLog.LEVEL_WARN,StdErrLog.getLoggingLevel(props,"org.eclipse.jetty.bad"));

View File

@ -120,14 +120,10 @@ public class ResourceTest
URI uri = file.toURI();
__userURL=uri.toURL();
__userURL = new URL(__userURL.toString() + "src/test/java/org/eclipse/jetty/util/resource/");
__userURL = new URL(__userURL.toString() + "src/test/resources/org/eclipse/jetty/util/resource/");
FilePermission perm = (FilePermission) __userURL.openConnection().getPermission();
__userDir = new File(perm.getName()).getCanonicalPath() + File.separatorChar;
__relDir = "src/test/java/org/eclipse/jetty/util/resource/".replace('/', File.separatorChar);
System.err.println("User Dir="+__userDir);
System.err.println("Rel Dir="+__relDir);
System.err.println("User URL="+__userURL);
__relDir = "src/test/resources/org/eclipse/jetty/util/resource/".replace('/', File.separatorChar);
tmpFile=File.createTempFile("test",null).getCanonicalFile();
tmpFile.deleteOnExit();
@ -141,15 +137,15 @@ public class ResourceTest
data[i++]=new Data(__userURL,EXISTS,DIR);
data[i++]=new Data(__userDir,EXISTS,DIR);
data[i++]=new Data(__relDir,EXISTS,DIR);
data[i++]=new Data(__userURL+"ResourceTest.java",EXISTS,!DIR);
data[i++]=new Data(__userDir+"ResourceTest.java",EXISTS,!DIR);
data[i++]=new Data(__relDir+"ResourceTest.java",EXISTS,!DIR);
data[i++]=new Data(__userURL+"resource.txt",EXISTS,!DIR);
data[i++]=new Data(__userDir+"resource.txt",EXISTS,!DIR);
data[i++]=new Data(__relDir+"resource.txt",EXISTS,!DIR);
data[i++]=new Data(__userURL+"NoName.txt",!EXISTS,!DIR);
data[i++]=new Data(__userDir+"NoName.txt",!EXISTS,!DIR);
data[i++]=new Data(__relDir+"NoName.txt",!EXISTS,!DIR);
data[i++]=new Data(data[rt],"ResourceTest.java",EXISTS,!DIR);
data[i++]=new Data(data[rt],"/ResourceTest.java",EXISTS,!DIR);
data[i++]=new Data(data[rt],"resource.txt",EXISTS,!DIR);
data[i++]=new Data(data[rt],"/resource.txt",EXISTS,!DIR);
data[i++]=new Data(data[rt],"NoName.txt",!EXISTS,!DIR);
data[i++]=new Data(data[rt],"/NoName.txt",!EXISTS,!DIR);
@ -323,7 +319,7 @@ public class ResourceTest
String s = "jar:"+__userURL+"TestData/test.zip!/subdir/numbers";
// TODO move this into src/test/resources!!!
ZipFile zf = new ZipFile(MavenTestingUtils.getProjectFile("src/test/java/org/eclipse/jetty/util/resource/TestData/test.zip"));
ZipFile zf = new ZipFile(MavenTestingUtils.getProjectFile("src/test/resources/org/eclipse/jetty/util/resource/TestData/test.zip"));
long last = zf.getEntry("subdir/numbers").getTime();

View File

@ -127,6 +127,7 @@ public class SslContextFactoryTest
@Test
public void testResourceTsResourceKsWrongPW() throws Exception
{
SslContextFactory.LOG.info("EXPECT SslContextFactory@????????(null,null): java.security.UnrecoverableKeyException: Cannot recover key...");
Resource keystoreResource = Resource.newSystemResource("keystore");
Resource truststoreResource = Resource.newSystemResource("keystore");
@ -151,6 +152,7 @@ public class SslContextFactoryTest
@Test
public void testResourceTsWrongPWResourceKs() throws Exception
{
SslContextFactory.LOG.info("EXPECT SslContextFactory@????????(null,null): java.io.IOException: Keystore was tampered with ...");
Resource keystoreResource = Resource.newSystemResource("keystore");
Resource truststoreResource = Resource.newSystemResource("keystore");
@ -178,6 +180,7 @@ public class SslContextFactoryTest
SslContextFactory cf = new SslContextFactory();
try
{
SslContextFactory.LOG.info("EXPECT SslContextFactory@????????(null,/foo): java.lang.IllegalStateException: SSL doesn't have a valid keystore...");
((StdErrLog)Log.getLogger(AbstractLifeCycle.class)).setHideStacks(true);
cf.setTrustStore("/foo");
cf.start();

View File

@ -15,6 +15,8 @@ package org.eclipse.jetty.util.statistic;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
@ -58,15 +60,8 @@ public class SampleStatisticTest
private void assertNearEnough(String test,double expected, double actual)
{
double diff = Math.abs(expected-actual);
if (diff<0.1)
{
System.out.println("Near enough "+test+" diff="+diff);
return;
}
String failed = "Not near enough "+test+" expected="+expected+" actual="+actual+" diff="+diff;
System.err.println(failed);
assertTrue(failed,false);
Assert.assertThat(actual,Matchers.greaterThan(expected-0.1D));
Assert.assertThat(actual,Matchers.lessThan(expected+0.1D));
}
}