moving .jndi, .mail and .mock.web unit tests from .testsuite to .context, .context.support, and .test bundles respectively
This commit is contained in:
parent
b326565ce5
commit
10be5f08a5
|
@ -16,22 +16,24 @@
|
|||
|
||||
package org.springframework.mail;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.test.AssertThrows;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Dmitriy Kopylenko
|
||||
* @author Juergen Hoeller
|
||||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
* @since 10.09.2003
|
||||
*/
|
||||
public final class SimpleMailMessageTests extends TestCase {
|
||||
public final class SimpleMailMessageTests {
|
||||
|
||||
@Test
|
||||
public void testSimpleMessageCopyCtor() {
|
||||
SimpleMailMessage message = new SimpleMailMessage();
|
||||
message.setFrom("me@mail.org");
|
||||
|
@ -52,10 +54,10 @@ public final class SimpleMailMessageTests extends TestCase {
|
|||
assertEquals("me@mail.org", message.getFrom());
|
||||
assertEquals("reply@mail.org", message.getReplyTo());
|
||||
assertEquals("you@mail.org", message.getTo()[0]);
|
||||
List ccs = Arrays.asList(message.getCc());
|
||||
List<String> ccs = Arrays.asList(message.getCc());
|
||||
assertTrue(ccs.contains("he@mail.org"));
|
||||
assertTrue(ccs.contains("she@mail.org"));
|
||||
List bccs = Arrays.asList(message.getBcc());
|
||||
List<String> bccs = Arrays.asList(message.getBcc());
|
||||
assertTrue(bccs.contains("us@mail.org"));
|
||||
assertTrue(bccs.contains("them@mail.org"));
|
||||
assertEquals(sentDate, message.getSentDate());
|
||||
|
@ -77,6 +79,7 @@ public final class SimpleMailMessageTests extends TestCase {
|
|||
assertEquals("my text", messageCopy.getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeepCopyOfStringArrayTypedFieldsOnCopyCtor() throws Exception {
|
||||
|
||||
SimpleMailMessage original = new SimpleMailMessage();
|
||||
|
@ -98,6 +101,7 @@ public final class SimpleMailMessageTests extends TestCase {
|
|||
/**
|
||||
* Tests that two equal SimpleMailMessages have equal hash codes.
|
||||
*/
|
||||
@Test
|
||||
public final void testHashCode() {
|
||||
SimpleMailMessage message1 = new SimpleMailMessage();
|
||||
message1.setFrom("from@somewhere");
|
||||
|
@ -151,20 +155,14 @@ public final class SimpleMailMessageTests extends TestCase {
|
|||
assertTrue(message1.equals(message2));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCopyCtorChokesOnNullOriginalMessage() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
new SimpleMailMessage(null);
|
||||
}
|
||||
}.runTest();
|
||||
new SimpleMailMessage(null);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCopyToChokesOnNullTargetMessage() throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
new SimpleMailMessage().copyTo(null);
|
||||
}
|
||||
}.runTest();
|
||||
new SimpleMailMessage().copyTo(null);
|
||||
}
|
||||
|
||||
}
|
|
@ -16,12 +16,13 @@
|
|||
|
||||
package org.springframework.jndi;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.DerivedTestBean;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
|
@ -30,9 +31,11 @@ import org.springframework.mock.jndi.ExpectedLookupTemplate;
|
|||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class JndiObjectFactoryBeanTests extends TestCase {
|
||||
public class JndiObjectFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testNoJndiName() throws NamingException {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
try {
|
||||
|
@ -43,6 +46,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithFullNameAndResourceRefTrue() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
Object o = new Object();
|
||||
|
@ -53,6 +57,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
assertTrue(jof.getObject() == o);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithFullNameAndResourceRefFalse() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
Object o = new Object();
|
||||
|
@ -63,6 +68,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
assertTrue(jof.getObject() == o);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithSchemeNameAndResourceRefTrue() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
Object o = new Object();
|
||||
|
@ -73,6 +79,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
assertTrue(jof.getObject() == o);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithSchemeNameAndResourceRefFalse() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
Object o = new Object();
|
||||
|
@ -83,6 +90,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
assertTrue(jof.getObject() == o);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithShortNameAndResourceRefTrue() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
Object o = new Object();
|
||||
|
@ -93,6 +101,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
assertTrue(jof.getObject() == o);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithShortNameAndResourceRefFalse() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
Object o = new Object();
|
||||
|
@ -108,6 +117,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithArbitraryNameAndResourceRefFalse() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
Object o = new Object();
|
||||
|
@ -118,6 +128,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
assertTrue(jof.getObject() == o);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithExpectedTypeAndMatch() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
String s = "";
|
||||
|
@ -128,6 +139,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
assertTrue(jof.getObject() == s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithExpectedTypeAndNoMatch() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
Object o = new Object();
|
||||
|
@ -143,6 +155,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithDefaultObject() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
String s = "";
|
||||
|
@ -154,6 +167,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
assertEquals("myString", jof.getObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithDefaultObjectAndExpectedType() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
String s = "";
|
||||
|
@ -165,6 +179,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
assertEquals("myString", jof.getObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithDefaultObjectAndExpectedTypeNoMatch() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
String s = "";
|
||||
|
@ -181,6 +196,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithProxyInterface() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
TestBean tb = new TestBean();
|
||||
|
@ -195,6 +211,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
assertEquals(99, tb.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithProxyInterfaceAndDefaultObject() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
TestBean tb = new TestBean();
|
||||
|
@ -211,6 +228,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithProxyInterfaceAndLazyLookup() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
final TestBean tb = new TestBean();
|
||||
|
@ -236,6 +254,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
assertEquals(99, tb.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithProxyInterfaceWithNotCache() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
final TestBean tb = new TestBean();
|
||||
|
@ -263,6 +282,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
assertEquals(4, tb.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithProxyInterfaceWithLazyLookupAndNotCache() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
final TestBean tb = new TestBean();
|
||||
|
@ -294,6 +314,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
assertEquals(4, tb.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyLookupWithoutProxyInterface() throws NamingException {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
jof.setJndiName("foo");
|
||||
|
@ -307,6 +328,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotCacheWithoutProxyInterface() throws NamingException {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
jof.setJndiName("foo");
|
||||
|
@ -321,6 +343,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithProxyInterfaceAndExpectedTypeAndMatch() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
TestBean tb = new TestBean();
|
||||
|
@ -336,7 +359,8 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
assertEquals(99, tb.getAge());
|
||||
}
|
||||
|
||||
public void testLookupWithProxyInterfaceAndExpectedTypeAndNoMatch() throws Exception {
|
||||
@Test
|
||||
public void testLookupWithProxyInterfaceAndExpectedTypeAndNoMatch() {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
TestBean tb = new TestBean();
|
||||
jof.setJndiTemplate(new ExpectedLookupTemplate("foo", tb));
|
||||
|
@ -352,16 +376,15 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupWithExposeAccessContext() throws Exception {
|
||||
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
|
||||
TestBean tb = new TestBean();
|
||||
MockControl ctxControl = MockControl.createControl(Context.class);
|
||||
final Context mockCtx = (Context) ctxControl.getMock();
|
||||
mockCtx.lookup("foo");
|
||||
ctxControl.setReturnValue(tb);
|
||||
final Context mockCtx = createMock(Context.class);
|
||||
expect(mockCtx.lookup("foo")).andReturn(tb);
|
||||
mockCtx.close();
|
||||
ctxControl.setVoidCallable(2);
|
||||
ctxControl.replay();
|
||||
expectLastCall().times(2);
|
||||
replay(mockCtx);
|
||||
jof.setJndiTemplate(new JndiTemplate() {
|
||||
protected Context createInitialContext() {
|
||||
return mockCtx;
|
||||
|
@ -379,7 +402,7 @@ public class JndiObjectFactoryBeanTests extends TestCase {
|
|||
proxy.equals(proxy);
|
||||
proxy.hashCode();
|
||||
proxy.toString();
|
||||
ctxControl.verify();
|
||||
verify(mockCtx);
|
||||
}
|
||||
|
||||
}
|
|
@ -17,13 +17,17 @@
|
|||
|
||||
package org.springframework.jndi;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class JndiTemplateEditorTests extends TestCase {
|
||||
public class JndiTemplateEditorTests {
|
||||
|
||||
@Test
|
||||
public void testNullIsIllegalArgument() {
|
||||
try {
|
||||
new JndiTemplateEditor().setAsText(null);
|
||||
|
@ -34,6 +38,7 @@ public class JndiTemplateEditorTests extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyStringMeansNullEnvironment() {
|
||||
JndiTemplateEditor je = new JndiTemplateEditor();
|
||||
je.setAsText("");
|
||||
|
@ -41,6 +46,7 @@ public class JndiTemplateEditorTests extends TestCase {
|
|||
assertTrue(jt.getEnvironment() == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomEnvironment() {
|
||||
JndiTemplateEditor je = new JndiTemplateEditor();
|
||||
// These properties are meaningless for JNDI, but we don't worry about that:
|
||||
|
|
|
@ -16,55 +16,54 @@
|
|||
|
||||
package org.springframework.jndi;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.NameNotFoundException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 08.07.2003
|
||||
*/
|
||||
public class JndiTemplateTests extends TestCase {
|
||||
public class JndiTemplateTests {
|
||||
|
||||
@Test
|
||||
public void testLookupSucceeds() throws Exception {
|
||||
Object o = new Object();
|
||||
String name = "foo";
|
||||
MockControl mc = MockControl.createControl(Context.class);
|
||||
final Context mock = (Context) mc.getMock();
|
||||
mock.lookup(name);
|
||||
mc.setReturnValue(o);
|
||||
mock.close();
|
||||
mc.setVoidCallable(1);
|
||||
mc.replay();
|
||||
final Context context = createMock(Context.class);
|
||||
expect(context.lookup(name)).andReturn(o);
|
||||
context.close();
|
||||
replay(context);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
protected Context createInitialContext() {
|
||||
return mock;
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
||||
Object o2 = jt.lookup(name);
|
||||
assertEquals(o, o2);
|
||||
mc.verify();
|
||||
verify(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupFails() throws Exception {
|
||||
NameNotFoundException ne = new NameNotFoundException();
|
||||
String name = "foo";
|
||||
MockControl mc = MockControl.createControl(Context.class);
|
||||
final Context mock = (Context) mc.getMock();
|
||||
mock.lookup(name);
|
||||
mc.setThrowable(ne);
|
||||
mock.close();
|
||||
mc.setVoidCallable(1);
|
||||
mc.replay();
|
||||
final Context context = createMock(Context.class);
|
||||
expect(context.lookup(name)).andThrow(ne);
|
||||
context.close();
|
||||
replay(context);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
protected Context createInitialContext() {
|
||||
return mock;
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -75,22 +74,20 @@ public class JndiTemplateTests extends TestCase {
|
|||
catch (NameNotFoundException ex) {
|
||||
// Ok
|
||||
}
|
||||
mc.verify();
|
||||
verify(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupReturnsNull() throws Exception {
|
||||
String name = "foo";
|
||||
MockControl mc = MockControl.createControl(Context.class);
|
||||
final Context mock = (Context) mc.getMock();
|
||||
mock.lookup(name);
|
||||
mc.setReturnValue(null);
|
||||
mock.close();
|
||||
mc.setVoidCallable(1);
|
||||
mc.replay();
|
||||
final Context context = createMock(Context.class);
|
||||
expect(context.lookup(name)).andReturn(null);
|
||||
context.close();
|
||||
replay(context);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
protected Context createInitialContext() {
|
||||
return mock;
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -101,23 +98,21 @@ public class JndiTemplateTests extends TestCase {
|
|||
catch (NameNotFoundException ex) {
|
||||
// Ok
|
||||
}
|
||||
mc.verify();
|
||||
verify(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLookupFailsWithTypeMismatch() throws Exception {
|
||||
Object o = new Object();
|
||||
String name = "foo";
|
||||
MockControl mc = MockControl.createControl(Context.class);
|
||||
final Context mock = (Context) mc.getMock();
|
||||
mock.lookup(name);
|
||||
mc.setReturnValue(o);
|
||||
mock.close();
|
||||
mc.setVoidCallable(1);
|
||||
mc.replay();
|
||||
final Context context = createMock(Context.class);
|
||||
expect(context.lookup(name)).andReturn(o);
|
||||
context.close();
|
||||
replay(context);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
protected Context createInitialContext() {
|
||||
return mock;
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -128,69 +123,63 @@ public class JndiTemplateTests extends TestCase {
|
|||
catch (TypeMismatchNamingException ex) {
|
||||
// Ok
|
||||
}
|
||||
mc.verify();
|
||||
verify(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBind() throws Exception {
|
||||
Object o = new Object();
|
||||
String name = "foo";
|
||||
MockControl mc = MockControl.createControl(Context.class);
|
||||
final Context mock = (Context) mc.getMock();
|
||||
mock.bind(name, o);
|
||||
mc.setVoidCallable(1);
|
||||
mock.close();
|
||||
mc.setVoidCallable(1);
|
||||
mc.replay();
|
||||
final Context context = createMock(Context.class);
|
||||
context.bind(name, o);
|
||||
context.close();
|
||||
replay(context);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
protected Context createInitialContext() {
|
||||
return mock;
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
||||
jt.bind(name, o);
|
||||
mc.verify();
|
||||
verify(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRebind() throws Exception {
|
||||
Object o = new Object();
|
||||
String name = "foo";
|
||||
MockControl mc = MockControl.createControl(Context.class);
|
||||
final Context mock = (Context) mc.getMock();
|
||||
mock.rebind(name, o);
|
||||
mc.setVoidCallable(1);
|
||||
mock.close();
|
||||
mc.setVoidCallable(1);
|
||||
mc.replay();
|
||||
final Context context = createMock(Context.class);
|
||||
context.rebind(name, o);
|
||||
context.close();
|
||||
replay(context);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
protected Context createInitialContext() {
|
||||
return mock;
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
||||
jt.rebind(name, o);
|
||||
mc.verify();
|
||||
verify(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnbind() throws Exception {
|
||||
String name = "something";
|
||||
MockControl mc = MockControl.createControl(Context.class);
|
||||
final Context mock = (Context) mc.getMock();
|
||||
mock.unbind(name);
|
||||
mc.setVoidCallable(1);
|
||||
mock.close();
|
||||
mc.setVoidCallable(1);
|
||||
mc.replay();
|
||||
final Context context = createMock(Context.class);
|
||||
context.unbind(name);
|
||||
context.close();
|
||||
replay(context);
|
||||
|
||||
JndiTemplate jt = new JndiTemplate() {
|
||||
protected Context createInitialContext() {
|
||||
return mock;
|
||||
return context;
|
||||
}
|
||||
};
|
||||
|
||||
jt.unbind(name);
|
||||
mc.verify();
|
||||
verify(context);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,11 @@
|
|||
|
||||
package org.springframework.jndi;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
@ -30,22 +35,23 @@ import javax.naming.NamingException;
|
|||
import javax.naming.spi.InitialContextFactory;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.junit.Test;
|
||||
import org.springframework.mock.jndi.SimpleNamingContext;
|
||||
import org.springframework.mock.jndi.SimpleNamingContextBuilder;
|
||||
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class SimpleNamingContextTests extends TestCase {
|
||||
public class SimpleNamingContextTests {
|
||||
|
||||
@Test
|
||||
public void testNamingContextBuilder() throws NamingException {
|
||||
SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
|
||||
InitialContextFactory factory = builder.createInitialContextFactory(null);
|
||||
|
||||
DataSource ds = new DriverManagerDataSource();
|
||||
DataSource ds = new StubDataSource();
|
||||
builder.bind("java:comp/env/jdbc/myds", ds);
|
||||
Object obj = new Object();
|
||||
builder.bind("myobject", obj);
|
||||
|
@ -54,7 +60,7 @@ public class SimpleNamingContextTests extends TestCase {
|
|||
assertTrue("Correct DataSource registered", context1.lookup("java:comp/env/jdbc/myds") == ds);
|
||||
assertTrue("Correct Object registered", context1.lookup("myobject") == obj);
|
||||
|
||||
Hashtable env2 = new Hashtable();
|
||||
Hashtable<String, String> env2 = new Hashtable<String, String>();
|
||||
env2.put("key1", "value1");
|
||||
Context context2 = factory.getInitialContext(env2);
|
||||
assertTrue("Correct DataSource registered", context2.lookup("java:comp/env/jdbc/myds") == ds);
|
||||
|
@ -110,37 +116,37 @@ public class SimpleNamingContextTests extends TestCase {
|
|||
assertTrue("Correct Integer registered", context3.lookup("myinteger") == i);
|
||||
assertTrue("Correct String registered", context3.lookup("mystring") == s);
|
||||
|
||||
Map bindingMap = new HashMap();
|
||||
NamingEnumeration bindingEnum = context3.listBindings("");
|
||||
Map<String, Binding> bindingMap = new HashMap<String, Binding>();
|
||||
NamingEnumeration<?> bindingEnum = context3.listBindings("");
|
||||
while (bindingEnum.hasMoreElements()) {
|
||||
Binding binding = (Binding) bindingEnum.nextElement();
|
||||
bindingMap.put(binding.getName(), binding);
|
||||
}
|
||||
assertTrue("Correct jdbc subcontext", ((Binding) bindingMap.get("jdbc")).getObject() instanceof Context);
|
||||
assertTrue("Correct jdbc subcontext", SimpleNamingContext.class.getName().equals(((Binding) bindingMap.get("jdbc")).getClassName()));
|
||||
assertTrue("Correct jdbc subcontext", bindingMap.get("jdbc").getObject() instanceof Context);
|
||||
assertTrue("Correct jdbc subcontext", SimpleNamingContext.class.getName().equals(bindingMap.get("jdbc").getClassName()));
|
||||
|
||||
Context jdbcContext = (Context) context3.lookup("jdbc");
|
||||
jdbcContext.bind("mydsX", ds);
|
||||
Map subBindingMap = new HashMap();
|
||||
NamingEnumeration subBindingEnum = jdbcContext.listBindings("");
|
||||
Map<String, Binding> subBindingMap = new HashMap<String, Binding>();
|
||||
NamingEnumeration<?> subBindingEnum = jdbcContext.listBindings("");
|
||||
while (subBindingEnum.hasMoreElements()) {
|
||||
Binding binding = (Binding) subBindingEnum.nextElement();
|
||||
subBindingMap.put(binding.getName(), binding);
|
||||
}
|
||||
|
||||
assertTrue("Correct DataSource registered", ds.equals(((Binding) subBindingMap.get("myds")).getObject()));
|
||||
assertTrue("Correct DataSource registered", DriverManagerDataSource.class.getName().equals(((Binding) subBindingMap.get("myds")).getClassName()));
|
||||
assertTrue("Correct DataSource registered", ds.equals(((Binding) subBindingMap.get("mydsX")).getObject()));
|
||||
assertTrue("Correct DataSource registered", DriverManagerDataSource.class.getName().equals(((Binding) subBindingMap.get("mydsX")).getClassName()));
|
||||
assertTrue("Correct Integer registered", i.equals(((Binding) bindingMap.get("myinteger")).getObject()));
|
||||
assertTrue("Correct Integer registered", Integer.class.getName().equals(((Binding) bindingMap.get("myinteger")).getClassName()));
|
||||
assertTrue("Correct String registered", s.equals(((Binding) bindingMap.get("mystring")).getObject()));
|
||||
assertTrue("Correct String registered", String.class.getName().equals(((Binding) bindingMap.get("mystring")).getClassName()));
|
||||
assertTrue("Correct DataSource registered", ds.equals(subBindingMap.get("myds").getObject()));
|
||||
assertTrue("Correct DataSource registered", StubDataSource.class.getName().equals(subBindingMap.get("myds").getClassName()));
|
||||
assertTrue("Correct DataSource registered", ds.equals(subBindingMap.get("mydsX").getObject()));
|
||||
assertTrue("Correct DataSource registered", StubDataSource.class.getName().equals(subBindingMap.get("mydsX").getClassName()));
|
||||
assertTrue("Correct Integer registered", i.equals(bindingMap.get("myinteger").getObject()));
|
||||
assertTrue("Correct Integer registered", Integer.class.getName().equals(bindingMap.get("myinteger").getClassName()));
|
||||
assertTrue("Correct String registered", s.equals(bindingMap.get("mystring").getObject()));
|
||||
assertTrue("Correct String registered", String.class.getName().equals(bindingMap.get("mystring").getClassName()));
|
||||
|
||||
context1.createSubcontext("jdbc").bind("sub/subds", ds);
|
||||
|
||||
Map pairMap = new HashMap();
|
||||
NamingEnumeration pairEnum = context2.list("jdbc");
|
||||
Map<String, String> pairMap = new HashMap<String, String>();
|
||||
NamingEnumeration<?> pairEnum = context2.list("jdbc");
|
||||
while (pairEnum.hasMore()) {
|
||||
NameClassPair pair = (NameClassPair) pairEnum.next();
|
||||
pairMap.put(pair.getName(), pair.getClassName());
|
||||
|
@ -148,16 +154,16 @@ public class SimpleNamingContextTests extends TestCase {
|
|||
assertTrue("Correct sub subcontext", SimpleNamingContext.class.getName().equals(pairMap.get("sub")));
|
||||
|
||||
Context subContext = (Context) context2.lookup("jdbc/sub");
|
||||
Map subPairMap = new HashMap();
|
||||
NamingEnumeration subPairEnum = subContext.list("");
|
||||
Map<String, String> subPairMap = new HashMap<String, String>();
|
||||
NamingEnumeration<?> subPairEnum = subContext.list("");
|
||||
while (subPairEnum.hasMoreElements()) {
|
||||
NameClassPair pair = (NameClassPair) subPairEnum.next();
|
||||
subPairMap.put(pair.getName(), pair.getClassName());
|
||||
}
|
||||
|
||||
assertTrue("Correct DataSource registered", DriverManagerDataSource.class.getName().equals(subPairMap.get("subds")));
|
||||
assertTrue("Correct DataSource registered", DriverManagerDataSource.class.getName().equals(pairMap.get("myds")));
|
||||
assertTrue("Correct DataSource registered", DriverManagerDataSource.class.getName().equals(pairMap.get("mydsX")));
|
||||
assertTrue("Correct DataSource registered", StubDataSource.class.getName().equals(subPairMap.get("subds")));
|
||||
assertTrue("Correct DataSource registered", StubDataSource.class.getName().equals(pairMap.get("myds")));
|
||||
assertTrue("Correct DataSource registered", StubDataSource.class.getName().equals(pairMap.get("mydsX")));
|
||||
|
||||
pairMap.clear();
|
||||
pairEnum = context1.list("jdbc/");
|
||||
|
@ -165,14 +171,15 @@ public class SimpleNamingContextTests extends TestCase {
|
|||
NameClassPair pair = (NameClassPair) pairEnum.next();
|
||||
pairMap.put(pair.getName(), pair.getClassName());
|
||||
}
|
||||
assertTrue("Correct DataSource registered", DriverManagerDataSource.class.getName().equals(pairMap.get("myds")));
|
||||
assertTrue("Correct DataSource registered", DriverManagerDataSource.class.getName().equals(pairMap.get("mydsX")));
|
||||
assertTrue("Correct DataSource registered", StubDataSource.class.getName().equals(pairMap.get("myds")));
|
||||
assertTrue("Correct DataSource registered", StubDataSource.class.getName().equals(pairMap.get("mydsX")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Demonstrates how emptyActivatedContextBuilder() method can be
|
||||
* used repeatedly, and how it affects creating a new InitialContext()
|
||||
*/
|
||||
@Test
|
||||
public void testCreateInitialContext() throws Exception {
|
||||
SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
|
||||
String name = "foo";
|
||||
|
@ -208,3 +215,39 @@ public class SimpleNamingContextTests extends TestCase {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
class StubDataSource implements DataSource {
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Connection getConnection(String username, String password) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public PrintWriter getLogWriter() throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getLoginTimeout() throws SQLException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setLogWriter(PrintWriter arg0) throws SQLException {
|
||||
|
||||
}
|
||||
|
||||
public void setLoginTimeout(int arg0) throws SQLException {
|
||||
|
||||
}
|
||||
|
||||
public boolean isWrapperFor(Class<?> arg0) throws SQLException {
|
||||
return false;
|
||||
}
|
||||
|
||||
public <T> T unwrap(Class<T> arg0) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -16,42 +16,50 @@
|
|||
|
||||
package org.springframework.mock.web;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 19.02.2006
|
||||
*/
|
||||
public class MockServletContextTests extends TestCase {
|
||||
public class MockServletContextTests {
|
||||
|
||||
@Test
|
||||
public void testListFiles() {
|
||||
MockServletContext sc = new MockServletContext("org/springframework/mock");
|
||||
Set paths = sc.getResourcePaths("/web");
|
||||
Set<?> paths = sc.getResourcePaths("/web");
|
||||
assertNotNull(paths);
|
||||
assertTrue(paths.contains("/web/MockServletContextTests.class"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListSubdirectories() {
|
||||
MockServletContext sc = new MockServletContext("org/springframework/mock");
|
||||
Set paths = sc.getResourcePaths("/");
|
||||
Set<?> paths = sc.getResourcePaths("/");
|
||||
assertNotNull(paths);
|
||||
assertTrue(paths.contains("/web/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListNonDirectory() {
|
||||
MockServletContext sc = new MockServletContext("org/springframework/mock");
|
||||
Set paths = sc.getResourcePaths("/web/MockServletContextTests.class");
|
||||
Set<?> paths = sc.getResourcePaths("/web/MockServletContextTests.class");
|
||||
assertNull(paths);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListInvalidPath() {
|
||||
MockServletContext sc = new MockServletContext("org/springframework/mock");
|
||||
Set paths = sc.getResourcePaths("/web/invalid");
|
||||
Set<?> paths = sc.getResourcePaths("/web/invalid");
|
||||
assertNull(paths);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetContext() {
|
||||
MockServletContext sc = new MockServletContext();
|
||||
MockServletContext sc2 = new MockServletContext();
|
||||
|
@ -61,6 +69,7 @@ public class MockServletContextTests extends TestCase {
|
|||
assertSame(sc2, sc.getContext("/second"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMimeType() {
|
||||
MockServletContext sc = new MockServletContext();
|
||||
assertEquals("text/html", sc.getMimeType("test.html"));
|
Loading…
Reference in New Issue