Commit 24ad75c0 authored by Lionel Seinturier's avatar Lionel Seinturier

Tests for the management of collection interfaces in the COMP mode.

parent b68b8fbb
......@@ -83,6 +83,9 @@
<adl>org.ow2.frascati.tinfi.mix.Mix</adl>
<adl>org.ow2.frascati.tinfi.oabdoun.optionalreference.OptionalReference</adl>
<adl>org.ow2.frascati.tinfi.oabdoun.constructor.ConstructorPropertyInjection</adl>
<adl>org.objectweb.fractal.julia.conform.components.BindingController</adl>
<adl>org.objectweb.fractal.julia.conform.components.C7scaPrimitive</adl>
<adl>org.objectweb.fractal.julia.conform.components.C8scaPrimitive</adl>
</adls>
<modules>
<module>FRACTAL_ADL</module>
......
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2007-2013 Inria, Univ. Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Lionel Seinturier
*/
package org.objectweb.fractal.julia.conform.components;
import org.objectweb.fractal.api.control.BindingController;
import java.util.Map;
import java.util.HashMap;
public class C implements CAttributes, BindingController, I, J {
private boolean x1;
private byte x2;
private char x3;
private short x4;
private int x5;
private long x6;
private float x7;
private double x8;
private String x9;
private boolean x11;
private I i;
private Map<String,Object> j = new HashMap<String,Object>();
// ATTRIBUTE CONTROLLER
public boolean getX1 () {
return x1;
}
public void setX1 (boolean x1) {
this.x1 = x1;
}
public byte getX2 () {
return x2;
}
public void setX2 (byte x2) {
this.x2 = x2;
}
public char getX3 () {
return x3;
}
public void setX3 (char x3) {
this.x3 = x3;
}
public short getX4 () {
return x4;
}
public void setX4 (short x4) {
this.x4 = x4;
}
public int getX5 () {
return x5;
}
public void setX5 (int x5) {
this.x5 = x5;
}
public long getX6 () {
return x6;
}
public void setX6 (long x6) {
this.x6 = x6;
}
public float getX7 () {
return x7;
}
public void setX7 (float x7) {
this.x7 = x7;
}
public double getX8 () {
return x8;
}
public void setX8 (double x8) {
this.x8 = x8;
}
public String getX9 () {
return x9;
}
public void setX9 (String x9) {
this.x9 = x9;
}
public boolean getReadOnlyX10 () {
return true;
}
public void setWriteOnlyX11 (boolean x11) {
this.x11 = x11;
}
// BINDING CONTROLLER
public String[] listFc () {
String[] result = new String[j.size() + 1];
j.keySet().toArray(result);
result[j.size()] = "client";
return result;
}
public Object lookupFc (String s) {
if (s.equals("client")) {
return i;
} else if (s.startsWith("clients")) {
return j.get(s);
}
return null;
}
public void bindFc (String s, Object o) {
if (s.equals("client")) {
i = (I)o;
} else if (s.startsWith("clients")) {
j.put(s, o);
}
}
public void unbindFc (String s) {
if (s.equals("client")) {
i = null;
} else if (s.startsWith("clients")) {
j.remove(s);
}
}
// FUNCTIONAL INTERFACE
public void m (boolean v) {
}
public void m (byte v) {
}
public void m (char v) {
}
public void m (short v) {
}
public void m (int v) {
}
public void m (long v) {
}
public void m (float v) {
}
public void m (double v) {
}
public void m (String v) {
}
public void m (String[] v) {
}
public boolean n (boolean v, String[] w) {
return v | x11; // for write only attribute tests
}
public byte n (byte v, String w) {
return v;
}
public char n (char v, double w) {
return v;
}
public short n (short v, float w) {
return v;
}
public int n (int v, long w) {
if (i != null) {
// for interceptors tests
return w == 0 ? v : i.n(v + 1, w - 1);
} else if (j.size() > 0) {
// for interceptors tests
return w == 0 ? v : ((I)j.values().iterator().next()).n(v + 1, w - 1);
} else {
return v;
}
}
public long n (long v, int w) {
return v;
}
public float n (float v, short w) {
return v;
}
public double n (double v, char w) {
return v;
}
public String n (String v, byte w) {
return v;
}
public String[] n (String[] v, boolean w) {
return v;
}
}
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2007-2013 Inria, Univ. Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Lionel Seinturier
*/
package org.objectweb.fractal.julia.conform.components;
import org.objectweb.fractal.api.control.AttributeController;
public interface CAttributes extends AttributeController {
boolean getX1 ();
void setX1 (boolean v);
byte getX2 ();
void setX2 (byte v);
char getX3 ();
void setX3 (char v);
short getX4 ();
void setX4 (short v);
int getX5 ();
void setX5 (int v);
long getX6 ();
void setX6 (long v);
float getX7 ();
void setX7 (float v);
double getX8 ();
void setX8 (double v);
String getX9 ();
void setX9 (String v);
boolean getReadOnlyX10 ();
void setWriteOnlyX11 (boolean v);
}
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2007-2013 Inria, Univ. Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Lionel Seinturier
*/
package org.objectweb.fractal.julia.conform.components;
public interface I {
void m (boolean v);
void m (byte v);
void m (char v);
void m (short v);
void m (int v);
void m (long v);
void m (float v);
void m (double v);
void m (String v);
void m (String[] v);
boolean n (boolean v, String[] w);
byte n (byte v, String w);
char n (char v, double w);
short n (short v, float w);
int n (int v, long w);
long n (long v, int w);
float n (float v, short w);
double n (double v, char w);
String n (String v, byte w);
String[] n (String[] v, boolean w);
}
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2007-2013 Inria, Univ. Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Lionel Seinturier
*/
package org.objectweb.fractal.julia.conform.components;
public interface J {
}
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE definition PUBLIC "-//objectweb.org//DTD Fractal ADL 2.0//EN" "classpath://org/objectweb/fractal/adl/xml/basic.dtd">
<definition name="org.objectweb.fractal.julia.conform.components.BindingController">
<controller desc="scaComposite" />
</definition>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE definition PUBLIC "-//objectweb.org//DTD Fractal ADL 2.0//EN" "classpath://org/objectweb/fractal/adl/xml/basic.dtd">
<definition name="org.objectweb.fractal.julia.conform.components.C7scaPrimitive">
<interface name="server" role="server" cardinality="singleton" signature="org.objectweb.fractal.julia.conform.components.I" />
<interface name="servers" role="server" cardinality="collection" signature="org.objectweb.fractal.julia.conform.components.I" />
<interface name="client" role="client" cardinality="singleton" signature="org.objectweb.fractal.julia.conform.components.I" />
<interface name="clients" role="client" cardinality="collection" signature="org.objectweb.fractal.julia.conform.components.I" />
<content class="org.objectweb.fractal.julia.conform.components.C" />
<controller desc="scaPrimitive" />
</definition>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE definition PUBLIC "-//objectweb.org//DTD Fractal ADL 2.0//EN" "classpath://org/objectweb/fractal/adl/xml/basic.dtd">
<definition name="org.objectweb.fractal.julia.conform.components.C8scaPrimitive">
<interface name="serverI" role="server" contingency="optional" signature="org.objectweb.fractal.julia.conform.components.I" />
<interface name="serverJ" role="server" signature="org.objectweb.fractal.julia.conform.components.J" />
<content class="org.objectweb.fractal.julia.conform.components.C" />
<controller desc="scaPrimitive" />
</definition>
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2007-2013 Inria, Univ. Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Lionel Seinturier
*/
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;
import org.objectweb.fractal.api.control.ContentController;
import org.objectweb.fractal.api.control.IllegalBindingException;
import org.objectweb.fractal.api.factory.GenericFactory;
import org.objectweb.fractal.api.type.ComponentType;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.api.type.TypeFactory;
import org.objectweb.fractal.util.Fractal;
import org.ow2.frascati.tinfi.TinfiDomain;
/**
* This test originates from Julia but is reused here since the implemenation of
* the binding controller for Tinfi scaPrimitive components differs from the one
* of Julia primitive components.
*
* @author Lionel Seinturier <Lionel.Seinturier@univ-lille1.fr>
* @since 1.4.6
*/
public class BindingControllerTestCase
extends org.objectweb.fractal.julia.conform.components.Test {
protected Component boot;
protected TypeFactory tf;
protected GenericFactory gf;
protected ComponentType t, u;
protected Component c, d, e;
protected boolean isTemplate;
// -------------------------------------------------------------------------
// Constructor and setup
// -------------------------------------------------------------------------
@Before
public void setUp () throws Exception {
boot = Fractal.getBootstrapComponent();
tf = Fractal.getTypeFactory(boot);
gf = Fractal.getGenericFactory(boot);
t = tf.createFcType(new InterfaceType[] {
tf.createFcItfType("server", I.class.getName(), false, false, false),
tf.createFcItfType("servers", I.class.getName(), false, false, true),
tf.createFcItfType("client", I.class.getName(), true, false, false),
tf.createFcItfType("clients", I.class.getName(), true, false, true)
});
u = tf.createFcType(new InterfaceType[] {
tf.createFcItfType("serverI", I.class.getName(), false, true, false),
tf.createFcItfType("serverJ", J.class.getName(), false, false, false),
});
setUpComponents();
}
protected void setUpComponents () throws Exception {
c = gf.newFcInstance(t, "scaPrimitive", C.class.getName());
d = gf.newFcInstance(t, "scaPrimitive", C.class.getName());
e = gf.newFcInstance(u, "scaPrimitive", C.class.getName());
String adl = getClass().getPackage().getName()+".BindingController";
Component composite = TinfiDomain.getComponent(adl);
ContentController cc = Fractal.getContentController(composite);
cc.addFcSubComponent(c);
cc.addFcSubComponent(d);
cc.addFcSubComponent(e);
}
// -------------------------------------------------------------------------
// 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" });
Assert.assertEquals(d.getFcInterface("server"), bc.lookupFc("client"));
bc.unbindFc("client");
Assert.assertEquals(null, bc.lookupFc("client"));
}
@Test
public void testCollectionBindLookupUnbind () throws Exception {
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");
Assert.assertEquals(null, bc.lookupFc("clients0"));
checkList(bc, new String[] { "client" });
}
protected void checkList (BindingController bc, String[] expected) {
String[] names = bc.listFc();
Set<String> nameSet = new HashSet<String>();
for (int i = 0; i < names.length; ++i) {
String name = names[i];
if (!nameSet.add(name)) {
Assert.fail("Duplicated interface name: " + name);
}
}
Assert.assertEquals(new HashSet<String>(Arrays.asList(expected)), nameSet);
}
// -------------------------------------------------------------------------
// Test errors in lookup, bind, unbind
// -------------------------------------------------------------------------
@Test
public void testNoSuchInterfaceLookup () {
try {
Fractal.getBindingController(c).lookupFc("c");
Assert.fail();
} catch (NoSuchInterfaceException e) {
}
}
@Test
public void testNoSuchInterfaceBind () throws Exception {
try {
Fractal.getBindingController(c).bindFc("c", d.getFcInterface("server"));
Assert.fail();
} catch (NoSuchInterfaceException e) {
}
}
@Test
public void testNotAServerInterface () throws Exception {
try {
Fractal.getBindingController(c).bindFc("client", c.getFcInterface("client"));
Assert.fail();
} catch (IllegalBindingException e) {
}
}
@Test
public void testWrongType () throws Exception {
try {
Fractal.getBindingController(c).bindFc("client", e.getFcInterface("serverJ"));
Assert.fail();
} catch (IllegalBindingException e) {
}
}
@Test
public void testMandatoryToOptional () throws Exception {
try {
Fractal.getBindingController(c).bindFc("client", e.getFcInterface("serverI"));
Assert.fail();
} catch (IllegalBindingException e) {
}
}
public void testAlreadyBound () throws Exception {
BindingController bc = Fractal.getBindingController(c);
bc.bindFc("client", d.getFcInterface("server"));
try {
bc.bindFc("client", d.getFcInterface("server"));
Assert.fail();
} catch (IllegalBindingException e) {
}
bc.bindFc("clients0", d.getFcInterface("server"));
try {
bc.bindFc("clients0", d.getFcInterface("server"));
Assert.fail();
} catch (IllegalBindingException e) {
}
}
@Test
public void testNoSuchInterfaceUnind () throws Exception {
try {
Fractal.getBindingController(c).unbindFc("c");
Assert.fail();
} catch (NoSuchInterfaceException e) {
}
}
@Test
public void testNotBound () throws Exception {
try {
Fractal.getBindingController(c).unbindFc("client");
Assert.fail();
} catch (IllegalBindingException e) {
}
}
}
/***
* OW2 FraSCAti Tinfi
* Copyright (C) 2007-2013 Inria, Univ. Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either