use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.
the class SerializableProxyTest method shouldNotGenerateWriteReplaceItThereIsAlreadyOne.
@Test
public void shouldNotGenerateWriteReplaceItThereIsAlreadyOne() throws Exception {
AuthorWithWriteReplaceMethod beanWithWriteReplace = new AuthorWithWriteReplaceMethod(999, "someone", "!@#@!#!@#", "someone@somewhere.com", "blah", Section.NEWS);
try {
beanWithWriteReplace.getClass().getDeclaredMethod("writeReplace");
} catch (NoSuchMethodException e) {
fail("Bean should declare a writeReplace method");
}
Object proxy = proxyFactory.createProxy(beanWithWriteReplace, new ResultLoaderMap(), new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
Class<?>[] interfaces = proxy.getClass().getInterfaces();
boolean ownInterfaceFound = false;
for (Class<?> i : interfaces) {
if (i.equals(WriteReplaceInterface.class)) {
ownInterfaceFound = true;
break;
}
}
assertFalse(ownInterfaceFound);
}
use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.
the class SerializableProxyTest method shouldSerializeAProxyForABeanWithDefaultConstructor.
@Test
public void shouldSerializeAProxyForABeanWithDefaultConstructor() throws Exception {
Object proxy = proxyFactory.createProxy(author, new ResultLoaderMap(), new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
Object proxy2 = deserialize(serialize((Serializable) proxy));
assertEquals(author, proxy2);
}
use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.
the class SerializableProxyTest method shouldNotLetReadUnloadedPropertyAfterTwoSerializations.
@Test(expected = ExecutorException.class)
public void shouldNotLetReadUnloadedPropertyAfterTwoSerializations() throws Exception {
ResultLoaderMap loader = new ResultLoaderMap();
loader.addLoader("id", null, null);
Object proxy = proxyFactory.createProxy(author, loader, new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
Author author2 = (Author) deserialize(serialize(deserialize(serialize((Serializable) proxy))));
author2.getId();
}
use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.
the class SerializableProxyTest method shouldKeepGenericTypes.
@Test
public void shouldKeepGenericTypes() throws Exception {
for (int i = 0; i < 10000; i++) {
Author pc = new Author();
Author proxy = (Author) proxyFactory.createProxy(pc, new ResultLoaderMap(), new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
proxy.getBio();
}
}
use of org.apache.ibatis.session.Configuration in project mybatis-3 by mybatis.
the class SerializableProxyTest method shouldGenerateWriteReplace.
@Test
public void shouldGenerateWriteReplace() throws Exception {
try {
author.getClass().getDeclaredMethod("writeReplace");
fail("Author should not have a writeReplace method");
} catch (NoSuchMethodException e) {
// ok
}
Object proxy = proxyFactory.createProxy(author, new ResultLoaderMap(), new Configuration(), new DefaultObjectFactory(), new ArrayList<Class<?>>(), new ArrayList<Object>());
Method m = proxy.getClass().getDeclaredMethod("writeReplace");
}
Aggregations