Commit 7e4ec062 authored by Lionel Seinturier's avatar Lionel Seinturier

JUnit 4 style.

Documenting TODO.
parent bac87b9b
......@@ -43,7 +43,7 @@ public class C implements CAttributes, BindingController, I, J {
private I i;
private Map j = new HashMap();
private Map<String,Object> j = new HashMap<String,Object>();
// ATTRIBUTE CONTROLLER
......
......@@ -25,7 +25,11 @@ package org.objectweb.fractal.julia.conform.components;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.control.BindingController;
......@@ -38,7 +42,8 @@ import org.objectweb.fractal.api.type.TypeFactory;
import org.objectweb.fractal.util.Fractal;
import org.ow2.frascati.tinfi.TinfiDomain;
public class BindingControllerTestCase extends Test {
public class BindingControllerTestCase
extends org.objectweb.fractal.julia.conform.components.Test {
protected Component boot;
protected TypeFactory tf;
......@@ -57,11 +62,8 @@ public class BindingControllerTestCase extends Test {
// Constructor and setup
// -------------------------------------------------------------------------
public BindingControllerTestCase (final String name) {
super(name);
}
protected void setUp () throws Exception {
@Before
public void setUp () throws Exception {
boot = Fractal.getBootstrapComponent();
tf = Fractal.getTypeFactory(boot);
gf = Fractal.getGenericFactory(boot);
......@@ -94,93 +96,119 @@ public class BindingControllerTestCase extends Test {
// -------------------------------------------------------------------------
// Test list, lookup, bind, unbind
// -------------------------------------------------------------------------
@Test
public void testList () throws Exception {
BindingController bc = Fractal.getBindingController(c);
checkList(bc, new String[] { "client" });
}
@Test
public void testBindLookupUnbind () throws Exception {
BindingController bc = Fractal.getBindingController(c);
bc.bindFc("client", d.getFcInterface("server"));
checkList(bc, new String[] { "client" });
assertEquals(d.getFcInterface("server"), bc.lookupFc("client"));
Assert.assertEquals(d.getFcInterface("server"), bc.lookupFc("client"));
bc.unbindFc("client");
assertEquals(null, bc.lookupFc("client"));
Assert.assertEquals(null, bc.lookupFc("client"));
}
// public void testCollectionBindLookupUnbind () throws Exception {
// BindingController bc = Fractal.getBindingController(c);
// bc.bindFc("clients0", d.getFcInterface("server"));
// checkList(bc, new String[] { "client", "clients0" });
// assertEquals(d.getFcInterface("server"), bc.lookupFc("clients0"));
// bc.unbindFc("clients0");
//
// /*
// * From below, this differs from the original Julia test. The purpose is to
// * illustrate the fact that although clients0 is unbound and is no longer
// * returned with listFc, it is still present in the array returned by
// * getFcInterfaces.
// */
// assertEquals(null, bc.lookupFc("clients0"));
// checkList(bc, new String[] { "client" });
// checkComponent(c, new HashSet(Arrays.asList(new Object[] {
// COMP, BC, LC, SC, NC, serverI, clientI, clients0I
// })));
// }
// @Test
public void testCollectionBindLookupUnbind () throws Exception {
/*
* TODO
*
* in tinfi-runtime-oo
* add a o.o.f.t.control.component.ComponentExt interface with a removeFc(Object) method
*
* in tinfi-mixins
* add a o.o.f.t.control.component.CollectionInterfaceComponentMixin layer
* implementing this method "in the vein of"
* org.objectweb.fractal.julia.TypeComponentMixin#getFcInterface(java.lang.String)
* but of course for removing collection interface instances
*
* in tinfi-opt-oo
* declare this extra layer in SCAPrimitive and in SCAComposite
*
* propage this change in tinfi-opt-comp-core and the tests in tinfi-tests-comp
*/
BindingController bc = Fractal.getBindingController(c);
bc.bindFc("clients0", d.getFcInterface("server"));
checkList(bc, new String[] { "client", "clients0" });
Assert.assertEquals(d.getFcInterface("server"), bc.lookupFc("clients0"));
bc.unbindFc("clients0");
/*
* From below, this differs from the original Julia test. The purpose is to
* illustrate the fact that although clients0 is unbound and is no longer
* returned with listFc, it is still present in the array returned by
* getFcInterfaces.
*/
Assert.assertEquals(null, bc.lookupFc("clients0"));
checkList(bc, new String[] { "client" });
checkComponent(c, new HashSet<String>(Arrays.asList(new String[] {
COMP, BC, LC, SC, NC, serverI, clientI, clients0I
})));
}
protected void checkList (BindingController bc, String[] expected) {
String[] names = bc.listFc();
HashSet nameSet = new HashSet();
Set<String> nameSet = new HashSet<String>();
for (int i = 0; i < names.length; ++i) {
String name = names[i];
if (!nameSet.add(name)) {
fail("Duplicated interface name: " + name);
Assert.fail("Duplicated interface name: " + name);
}
}
assertEquals(new HashSet(Arrays.asList(expected)), nameSet);
Assert.assertEquals(new HashSet<String>(Arrays.asList(expected)), nameSet);
}
// -------------------------------------------------------------------------
// Test errors in lookup, bind, unbind
// -------------------------------------------------------------------------
public void testNoSuchInterfaceLookup () throws Exception {
@Test
public void testNoSuchInterfaceLookup () {
try {
Fractal.getBindingController(c).lookupFc("c");
fail();
Assert.fail();
} catch (NoSuchInterfaceException e) {
}
}
@Test
public void testNoSuchInterfaceBind () throws Exception {
try {
Fractal.getBindingController(c).bindFc("c", d.getFcInterface("server"));
fail();
Assert.fail();
} catch (NoSuchInterfaceException e) {
}
}
@Test
public void testNotAServerInterface () throws Exception {
try {
Fractal.getBindingController(c).bindFc("client", c.getFcInterface("client"));
fail();
Assert.fail();
} catch (IllegalBindingException e) {
}
}
@Test
public void testWrongType () throws Exception {
try {
Fractal.getBindingController(c).bindFc("client", e.getFcInterface("serverJ"));
fail();
Assert.fail();
} catch (IllegalBindingException e) {
}
}
@Test
public void testMandatoryToOptional () throws Exception {
try {
Fractal.getBindingController(c).bindFc("client", e.getFcInterface("serverI"));
fail();
Assert.fail();
} catch (IllegalBindingException e) {
}
}
......@@ -190,29 +218,31 @@ public class BindingControllerTestCase extends Test {
bc.bindFc("client", d.getFcInterface("server"));
try {
bc.bindFc("client", d.getFcInterface("server"));
fail();
Assert.fail();
} catch (IllegalBindingException e) {
}
bc.bindFc("clients0", d.getFcInterface("server"));
try {
bc.bindFc("clients0", d.getFcInterface("server"));
fail();
Assert.fail();
} catch (IllegalBindingException e) {
}
}
@Test
public void testNoSuchInterfaceUnind () throws Exception {
try {
Fractal.getBindingController(c).unbindFc("c");
fail();
Assert.fail();
} catch (NoSuchInterfaceException e) {
}
}
@Test
public void testNotBound () throws Exception {
try {
Fractal.getBindingController(c).unbindFc("client");
fail();
Assert.fail();
} catch (IllegalBindingException e) {
}
}
......
......@@ -23,23 +23,19 @@
package org.objectweb.fractal.julia.conform.components;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.junit.Assert;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.api.Interface;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.api.control.ContentController;
import org.objectweb.fractal.julia.conform.components.I;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.util.Fractal;
import junit.framework.TestCase;
import java.util.Set;
import java.util.Iterator;
import java.util.HashSet;
public abstract class Test extends TestCase {
public abstract class Test {
protected final static String COMP = "component/org.objectweb.fractal.api.Component/false,false,false";
protected final static String BC = "binding-controller/org.objectweb.fractal.api.control.BindingController/false,false,false";
......@@ -51,10 +47,6 @@ public abstract class Test extends TestCase {
protected final static String PKG = "org.objectweb.fractal.julia.conform.components";
public Test (final String name) {
super(name);
}
protected void checkInterface (I i) {
i.m(true);
i.m((byte)1);
......@@ -67,30 +59,30 @@ public abstract class Test extends TestCase {
i.m("1");
i.m(new String[] { "1" });
assertEquals(true, i.n(true, null));
assertEquals((byte)1, i.n((byte)1, null));
assertEquals((char)1, i.n((char)1, (double)0));
assertEquals((short)1, i.n((short)1, (float)0));
assertEquals((int)1, i.n((int)1, (long)0));
assertEquals((long)1, i.n((long)1, (int)0));
assertEquals((float)1, i.n((float)1, (short)0), 0);
assertEquals((double)1, i.n((double)1, (char)0), 0);
assertEquals("1", i.n("1", (byte)0));
Assert.assertEquals(true, i.n(true, null));
Assert.assertEquals((byte)1, i.n((byte)1, null));
Assert.assertEquals((char)1, i.n((char)1, (double)0));
Assert.assertEquals((short)1, i.n((short)1, (float)0));
Assert.assertEquals((int)1, i.n((int)1, (long)0));
Assert.assertEquals((long)1, i.n((long)1, (int)0));
Assert.assertEquals((float)1, i.n((float)1, (short)0), 0);
Assert.assertEquals((double)1, i.n((double)1, (char)0), 0);
Assert.assertEquals("1", i.n("1", (byte)0));
}
protected void checkComponent (Component c, Set itfs) throws Exception {
Set extItfs = getExternalItfs(c);
assertEquals("Wrong external interface list", itfs, extItfs);
Iterator i = itfs.iterator();
protected void checkComponent (Component c, Set<String> itfs) {
Set<String> extItfs = getExternalItfs(c);
Assert.assertEquals("Wrong external interface list", itfs, extItfs);
Iterator<String> i = itfs.iterator();
while (i.hasNext()) {
String itf = (String)i.next();
String itf = i.next();
String compItf = null;
try {
compItf = getItf((Interface)c.getFcInterface(getItfName(itf)), false);
} catch (NoSuchInterfaceException e) {
fail("Missing external interface: " + itf);
Assert.fail("Missing external interface: " + itf);
}
assertEquals("Wrong external interface", itf, compItf);
Assert.assertEquals("Wrong external interface", itf, compItf);
}
ContentController cc;
......@@ -100,7 +92,7 @@ public abstract class Test extends TestCase {
return;
}
itfs = new HashSet(itfs);
itfs = new HashSet<String>(itfs);
i = itfs.iterator();
while (i.hasNext()) {
String itf = (String)i.next();
......@@ -109,40 +101,40 @@ public abstract class Test extends TestCase {
}
}
Set intItfs = getInternalItfs(cc);
assertEquals("Wrong internal interface list", itfs, intItfs);
Set<String> intItfs = getInternalItfs(cc);
Assert.assertEquals("Wrong internal interface list", itfs, intItfs);
i = itfs.iterator();
while (i.hasNext()) {
String itf = (String)i.next();
String itf = i.next();
String compItf = null;
try {
compItf = getItf((Interface)cc.getFcInternalInterface(getItfName(itf)), true);
} catch (NoSuchInterfaceException e) {
fail("Missing internal interface: " + itf);
Assert.fail("Missing internal interface: " + itf);
}
assertEquals("Wrong internal interface", itf, compItf);
Assert.assertEquals("Wrong internal interface", itf, compItf);
}
}
protected Set getExternalItfs (Component c) {
HashSet result = new HashSet();
protected Set<String> getExternalItfs (Component c) {
Set<String> result = new HashSet<String>();
Object[] extItfs = c.getFcInterfaces();
for (int i = 0; i < extItfs.length; ++i) {
String itf = getItf((Interface)extItfs[i], false);
if (!result.add(itf)) {
fail("Duplicated interface: " + itf);
Assert.fail("Duplicated interface: " + itf);
}
}
return result;
}
private Set getInternalItfs (ContentController cc) {
HashSet result = new HashSet();
private Set<String> getInternalItfs (ContentController cc) {
Set<String> result = new HashSet<String>();
Object[] extItfs = cc.getFcInternalInterfaces();
for (int i = 0; i < extItfs.length; ++i) {
String itf = getItf((Interface)extItfs[i], true);
if (!result.add(itf)) {
fail("Duplicated interface: " + itf);
Assert.fail("Duplicated interface: " + itf);
}
}
return result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment