Skip to content

Commit

Permalink
Minor. Test restructure + helper methods.
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@222 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
nickarls committed Nov 3, 2008
1 parent 0581093 commit 6ebe93c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 46 deletions.
Expand Up @@ -31,4 +31,8 @@ else if (Reflections.isArrayType(rawType))
}
}

public static boolean isProxy(Object instance) {
return instance.getClass().getName().indexOf("_$$_javassist_") > 0;
}

}
Expand Up @@ -14,6 +14,7 @@
import org.jboss.webbeans.test.beans.Tuna;
import org.jboss.webbeans.test.beans.TunedTuna;
import org.jboss.webbeans.test.util.Util;
import org.jboss.webbeans.util.ClientProxy;
import org.testng.annotations.Test;

@SpecVersion("PDR")
Expand All @@ -26,7 +27,7 @@ public void testClientProxyUsedForNormalScope()
{
Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
Tuna tuna = manager.getInstance(tunaBean);
assert tuna.getClass().getName().indexOf("$$_javassist_") > 0;
assert ClientProxy.isProxy(tuna);
}

@Test(groups = "clientProxy")
Expand All @@ -35,57 +36,32 @@ public void testClientProxyNotUsedForPseudoScope()
{
Bean<Fox> foxBean = Util.createSimpleWebBean(Fox.class, manager);
Fox fox = manager.getInstance(foxBean);
assert fox.getClass() == Fox.class;
assert !ClientProxy.isProxy(fox);
}

private byte[] serializeBean(Object instance) throws IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bytes);
out.writeObject(instance);
return bytes.toByteArray();
}

private Object deserializeBean(byte[] bytes) throws IOException, ClassNotFoundException {
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
return in.readObject();
}

@Test(groups = "clientProxy")
@SpecAssertion(section = "4.4")
public void testSimpleWebBeanClientProxyIsSerializable()
public void testSimpleWebBeanClientProxyIsSerializable() throws IOException, ClassNotFoundException
{
Bean<TunedTuna> tunaBean = Util.createSimpleWebBean(TunedTuna.class, manager);
manager.addBean(tunaBean);
TunedTuna tuna = manager.getInstance(tunaBean);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
ObjectOutputStream out = null;
ObjectInputStream in = null;
try
{
out = new ObjectOutputStream(bytes);
out.writeObject(tuna);
out.flush();
byte[] data = bytes.toByteArray();
in = new ObjectInputStream(new ByteArrayInputStream(data));
tuna = (TunedTuna) in.readObject();
assert tuna.getState().equals("tuned");
}
catch (Exception e)
{
e.printStackTrace();
assert false;
}
finally
{
try
{
if (bytes != null)
{
bytes.close();
}
if (out != null)
{
out.close();
}
if (in != null)
{
in.close();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
assert true;
assert ClientProxy.isProxy(tuna);
byte[] bytes = serializeBean(tuna);
tuna = (TunedTuna) deserializeBean(bytes);
assert ClientProxy.isProxy(tuna);
assert tuna.getState().equals("tuned");
}

@Test(groups = "clientProxy", expectedExceptions = UnproxyableDependencyException.class)
Expand All @@ -105,7 +81,7 @@ public void testClientProxyInvocation()
Bean<TunedTuna> tunaBean = Util.createSimpleWebBean(TunedTuna.class, manager);
manager.addBean(tunaBean);
TunedTuna tuna = manager.getInstance(tunaBean);
assert tuna.getClass().getName().indexOf("$$_javassist_") > 0;
assert ClientProxy.isProxy(tuna);
assert tuna.getState().equals("tuned");
}

Expand Down

0 comments on commit 6ebe93c

Please sign in to comment.