OW2 Consortium
Search OW2 Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | fractal-commits List | January 2007 Index

<--  Date Index  --> <--  Thread Index  -->

CVS update of julia/test/conform/org/objectweb/fractal/juliak/conform (4 files)


    Date: Sunday, January 28, 2007 @ 16:05:55
  Author: seintur
    Path: .../fractal/julia/test/conform/org/objectweb/fractal/juliak/conform

   Added: TestComponent.java TestInterceptorController.java
          TestMembraneController.java package.html

JUnit test for features specific to component-based control membranes.


--------------------------------+
 TestComponent.java             |  113 +++++++++++++++
 TestInterceptorController.java |  281 +++++++++++++++++++++++++++++++++++++++
 TestMembraneController.java    |  113 +++++++++++++++
 package.html                   |   33 ++++
 4 files changed, 540 insertions(+)


Index: 
julia/test/conform/org/objectweb/fractal/juliak/conform/TestComponent.java
diff -u /dev/null 
julia/test/conform/org/objectweb/fractal/juliak/conform/TestComponent.java:1.1
--- /dev/null   Sun Jan 28 16:05:55 2007
+++ 
julia/test/conform/org/objectweb/fractal/juliak/conform/TestComponent.java  
Sun Jan 28 16:05:55 2007
@@ -0,0 +1,113 @@
+/***
+ * Julia
+ * Copyright (C) 2005-2007 INRIA, France Telecom, USTL
+ *
+ * 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: Lionel.Seinturier@xxxxxxx
+ *
+ * Author: Lionel Seinturier
+ */
+
+package org.objectweb.fractal.juliak.conform;
+
+import org.objectweb.fractal.api.Component;
+import org.objectweb.fractal.api.NoSuchInterfaceException;
+import org.objectweb.fractal.api.control.IllegalLifeCycleException;
+import org.objectweb.fractal.api.factory.GenericFactory;
+import org.objectweb.fractal.api.factory.InstantiationException;
+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.julia.conform.Test;
+import org.objectweb.fractal.julia.conform.components.C;
+import org.objectweb.fractal.julia.conform.components.CAttributes;
+import org.objectweb.fractal.julia.conform.components.I;
+import org.objectweb.fractal.juliak.membrane.CustomFactory;
+import org.objectweb.fractal.juliak.membrane.Primitive;
+import org.objectweb.fractal.util.Fractal;
+
+/**
+ * JUnit test for the component factory features which are specific to 
Juliak.
+ *  
+ * @author Lionel Seinturier <Lionel.Seinturier@xxxxxxx>
+ * @since 2.5
+ */
+public class TestComponent extends Test {
+
+  protected Component boot;
+  protected TypeFactory tf;
+  protected GenericFactory gf;
+
+  protected ComponentType t;
+
+  protected final static String AC = 
"attribute-controller/"+PKG+".CAttributes/false,false,false";
+  protected final static String sI = "server/"+PKG+".I/false,false,false";
+  protected final static String cI = "client/"+PKG+".I/true,false,false";
+
+  // 
-------------------------------------------------------------------------
+  // Constructor and setup
+  // 
-------------------------------------------------------------------------
+
+  public TestComponent (final String name) {
+    super(name);
+  }
+
+  protected void setUp () throws InstantiationException, 
NoSuchInterfaceException {
+    boot = Fractal.getBootstrapComponent();
+    tf = Fractal.getTypeFactory(boot);
+    gf = Fractal.getGenericFactory(boot);
+    t = tf.createFcType(new InterfaceType[] {
+      tf.createFcItfType("attribute-controller", 
CAttributes.class.getName(), false, false, false),
+      tf.createFcItfType("server", I.class.getName(), false, false, false),
+      tf.createFcItfType("client", I.class.getName(), true, true, false)
+    });
+  }
+
+  // 
-------------------------------------------------------------------------
+  // Test gluing a control membrane to a content
+  // 
-------------------------------------------------------------------------
+
+  public void testPrimitive() throws InstantiationException, 
IllegalLifeCycleException, NoSuchInterfaceException {
+      CustomFactory cf = new Primitive();
+      cf.setFcTypeFactory(tf);
+      cf.setFcGenericFactory(gf);
+      Component membrane = cf.newFcInstance();
+      assertNotNull(membrane);
+      
+      Component c = gf.newFcInstance(t, membrane, C.class.getName());
+      Fractal.getLifeCycleController(c).startFc();
+      I i = (I)c.getFcInterface("server");
+      checkInterface(i);
+  }
+
+  // 
-------------------------------------------------------------------------
+  // Test joint use of Julia and Juliak components
+  // 
-------------------------------------------------------------------------
+
+  public void testJuliaPrimitive() throws InstantiationException, 
IllegalLifeCycleException, NoSuchInterfaceException {
+      Component c = gf.newFcInstance(t, "/julia/primitive", 
C.class.getName());
+      Fractal.getLifeCycleController(c).startFc();
+      I i = (I)c.getFcInterface("server");
+      checkInterface(i);
+      
+      try {
+          c.getFcInterface("/membrane-controller");
+          fail("The Julia factory should have been used for creating this 
component");
+      }
+      catch( NoSuchInterfaceException nsie ) {}
+  }
+
+}
Index: 
julia/test/conform/org/objectweb/fractal/juliak/conform/TestInterceptorController.java
diff -u /dev/null 
julia/test/conform/org/objectweb/fractal/juliak/conform/TestInterceptorController.java:1.1
--- /dev/null   Sun Jan 28 16:05:55 2007
+++ 
julia/test/conform/org/objectweb/fractal/juliak/conform/TestInterceptorController.java
      Sun Jan 28 16:05:55 2007
@@ -0,0 +1,281 @@
+/***
+ * Julia
+ * Copyright (C) 2005-2007 INRIA, France Telecom, USTL
+ *
+ * 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: Lionel.Seinturier@xxxxxxx
+ *
+ * Author: Lionel Seinturier
+ */
+
+package org.objectweb.fractal.juliak.conform;
+
+import org.objectweb.fractal.api.Component;
+import org.objectweb.fractal.api.NoSuchInterfaceException;
+import org.objectweb.fractal.api.control.IllegalLifeCycleException;
+import org.objectweb.fractal.api.control.LifeCycleController;
+import org.objectweb.fractal.api.factory.GenericFactory;
+import org.objectweb.fractal.api.factory.InstantiationException;
+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.julia.ComponentInterface;
+import org.objectweb.fractal.julia.InitializationContext;
+import org.objectweb.fractal.julia.Interceptor;
+import org.objectweb.fractal.julia.conform.Test;
+import org.objectweb.fractal.julia.conform.components.C;
+import org.objectweb.fractal.julia.conform.components.I;
+import org.objectweb.fractal.julia.conform.controllers.BasicStatController;
+import 
org.objectweb.fractal.juliak.control.interceptor.InterceptorController;
+import org.objectweb.fractal.util.Fractal;
+
+/**
+ * JUnit test for the interceptor controller of Juliak.
+ * 
+ * @author Lionel Seinturier <Lionel.Seinturier@xxxxxxx>
+ * @since 2.5
+ */
+public class TestInterceptorController extends Test {
+
+    protected Component boot;
+    protected TypeFactory tf;
+    protected GenericFactory gf;
+
+    protected ComponentType t;
+    protected Component c;
+
+    // 
-------------------------------------------------------------------------
+    // Constructor and setup
+    // 
-------------------------------------------------------------------------
+
+    public TestInterceptorController(final String name) {
+      super(name);
+    }
+
+    protected void setUp () throws InstantiationException, 
NoSuchInterfaceException {
+      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, true, 
false),
+              tf.createFcItfType("clients", I.class.getName(), true, true, 
true)
+            });
+      setUpComponents();
+    }
+
+    protected void setUpComponents () throws InstantiationException {
+        c = gf.newFcInstance(t, "primitive", C.class.getName());
+    }
+    
+    // 
-------------------------------------------------------------------------
+    // Test InterceptorController
+    // 
-------------------------------------------------------------------------
+
+    public void testInterceptorController() throws NoSuchInterfaceException {
+        InterceptorController ic = (InterceptorController)
+            c.getFcInterface(InterceptorController.NAME);
+        assertNotNull(ic);
+    }
+
+    // 
-------------------------------------------------------------------------
+    // Test getFcInterceptors
+    // 
-------------------------------------------------------------------------
+
+    public void testGetInterceptors() throws NoSuchInterfaceException {
+        checkInterceptor("server");
+        checkNoInterceptor("client");
+    }
+
+    public void testCollectionGetInterceptors() throws 
NoSuchInterfaceException {
+        checkInterceptor("servers");
+        checkInterceptor("servers0");
+        checkNoInterceptor("clients");
+        checkNoInterceptor("clients0");
+    }
+    
+    protected void checkInterceptor(String itfName) throws 
NoSuchInterfaceException {
+        InterceptorController ic = (InterceptorController)
+            c.getFcInterface(InterceptorController.NAME);
+    
+        Object itf = c.getFcInterface(itfName);
+        if( ! (itf instanceof ComponentInterface) ) {
+            fail("Interceptor should implement ComponentInterface");
+        }
+        ComponentInterface citf = (ComponentInterface) itf;
+        
+        Interceptor[] interceptors = ic.getFcInterceptors(citf);
+        assertEquals(1,interceptors.length);
+        
+        Interceptor i0 = interceptors[0];
+        if( !(i0 instanceof I) ) {
+            fail("Interceptor should implement I");
+        }
+    }
+
+    protected void checkNoInterceptor(String itfName) throws 
NoSuchInterfaceException {
+        InterceptorController ic = (InterceptorController)
+            c.getFcInterface(InterceptorController.NAME);
+    
+        Object itf = c.getFcInterface(itfName);
+        if( ! (itf instanceof ComponentInterface) ) {
+            fail("Interceptor should implement ComponentInterface");
+        }
+        ComponentInterface citf = (ComponentInterface) itf;
+        
+        Interceptor[] interceptors = ic.getFcInterceptors(citf);
+        assertEquals(0,interceptors.length);
+    }
+
+    // 
-------------------------------------------------------------------------
+    // Test addFcInterceptors and removeFcInterceptors
+    // 
-------------------------------------------------------------------------
+
+    public void testAddRemoveInterceptor() throws NoSuchInterfaceException, 
IllegalLifeCycleException {
+        checkAddRemoveInterceptor("server");
+    }
+    
+    public void testCollectionAddRemoveInterceptor() throws 
NoSuchInterfaceException, IllegalLifeCycleException {
+        checkAddRemoveInterceptor("servers");
+        checkAddRemoveInterceptor("servers0");
+    }
+    
+    protected void checkAddRemoveInterceptor(String itfName) throws 
NoSuchInterfaceException, IllegalLifeCycleException {
+        
+        LifeCycleController lc = Fractal.getLifeCycleController(c);
+        lc.startFc();
+        
+        InterceptorController ic = (InterceptorController)
+            c.getFcInterface(InterceptorController.NAME);
+
+        Object itf = c.getFcInterface(itfName);
+        ComponentInterface citf = (ComponentInterface) itf;
+        I iserver = (I) itf;
+        
+        // Add the interceptor
+        IInterceptor ii = new IInterceptor();
+        ic.addFcInterceptor(citf, ii);
+        Interceptor[] interceptors = ic.getFcInterceptors(citf);
+        assertEquals(2,interceptors.length);
+        assertEquals(0, ii.fcCounter);
+        
+        // Call m(), check that the interceptor has been executed
+        iserver.m(true);
+        assertEquals(1, ii.fcCounter);
+        
+        // Remove the interceptor
+        ic.removeFcInterceptor(citf, ii);
+        interceptors = ic.getFcInterceptors(citf);
+        assertEquals(1,interceptors.length);
+        
+        // Call m(), check that the interceptor has not been executed
+        iserver.m(true);
+        assertEquals(1, ii.fcCounter);
+    }
+    
+    private static class IInterceptor extends BasicStatController implements 
Interceptor, I {
+
+        public Object getFcItfDelegate() {
+            return delegate;
+        }
+
+        public void setFcItfDelegate(Object delegate) {
+            this.delegate = delegate;
+        }
+        
+        private Object delegate;
+
+        public Object clone () {
+            return null;
+        }
+        
+        public void initFcController(InitializationContext ic) throws 
InstantiationException {
+        }
+
+        public void m(boolean v) {
+            fcCounter++;
+        }
+
+        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 false;
+        }
+
+        public byte n(byte v, String w) {
+            return 0;
+        }
+
+        public char n(char v, double w) {
+            return 0;
+        }
+
+        public short n(short v, float w) {
+            return 0;
+        }
+
+        public int n(int v, long w) {
+            return 0;
+        }
+
+        public long n(long v, int w) {
+            return 0;
+        }
+
+        public float n(float v, short w) {
+            return 0;
+        }
+
+        public double n(double v, char w) {
+            return 0;
+        }
+
+        public String n(String v, byte w) {
+            return null;
+        }
+
+        public String[] n(String[] v, boolean w) {
+            return null;
+        }
+        
+    }
+}
Index: 
julia/test/conform/org/objectweb/fractal/juliak/conform/TestMembraneController.java
diff -u /dev/null 
julia/test/conform/org/objectweb/fractal/juliak/conform/TestMembraneController.java:1.1
--- /dev/null   Sun Jan 28 16:05:55 2007
+++ 
julia/test/conform/org/objectweb/fractal/juliak/conform/TestMembraneController.java
 Sun Jan 28 16:05:55 2007
@@ -0,0 +1,113 @@
+/***
+ * Julia
+ * Copyright (C) 2005-2007 INRIA, France Telecom, USTL
+ *
+ * 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: Lionel.Seinturier@xxxxxxx
+ *
+ * Author: Lionel Seinturier
+ */
+
+package org.objectweb.fractal.juliak.conform;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.objectweb.fractal.api.Component;
+import org.objectweb.fractal.api.NoSuchInterfaceException;
+import org.objectweb.fractal.api.factory.GenericFactory;
+import org.objectweb.fractal.api.factory.InstantiationException;
+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.julia.conform.Test;
+import org.objectweb.fractal.julia.conform.components.C;
+import org.objectweb.fractal.julia.conform.components.CAttributes;
+import org.objectweb.fractal.julia.conform.components.I;
+import 
org.objectweb.fractal.juliak.control.interceptor.InterceptorController;
+import org.objectweb.fractal.juliak.control.membrane.MembraneController;
+import org.objectweb.fractal.util.Fractal;
+
+/**
+ * JUnit test for the membrane controller of Juliak.
+ * 
+ * @author Lionel Seinturier <Lionel.Seinturier@xxxxxxx>
+ * @since 2.5
+ */
+public class TestMembraneController extends Test {
+
+    protected Component boot;
+    protected TypeFactory tf;
+    protected GenericFactory gf;
+
+    protected ComponentType t;
+    protected Component c;
+
+    protected final static String MCOMP = "//"+COMP;
+    protected final static String MBC = "//"+BC;
+    protected final static String MLC = "//"+LC;
+    protected final static String MSC = "//"+SC;
+    protected final static String MNC = "//"+NC;
+    protected final static String MMC = 
"//"+MembraneController.NAME+"/"+MembraneController.TYPE.getFcItfSignature()+"/false,false,false";
+    protected final static String MIC = 
"//"+InterceptorController.NAME+"/"+InterceptorController.TYPE.getFcItfSignature()+"/false,false,false";
+    
+    // 
-------------------------------------------------------------------------
+    // Constructor and setup
+    // 
-------------------------------------------------------------------------
+
+    public TestMembraneController(final String name) {
+      super(name);
+    }
+
+    protected void setUp () throws InstantiationException, 
NoSuchInterfaceException {
+      boot = Fractal.getBootstrapComponent();
+      tf = Fractal.getTypeFactory(boot);
+      gf = Fractal.getGenericFactory(boot);
+      t = tf.createFcType(new InterfaceType[] {
+        tf.createFcItfType("attribute-controller", 
CAttributes.class.getName(), false, false, false),
+        tf.createFcItfType("server", I.class.getName(), false, false, false),
+        tf.createFcItfType("client", I.class.getName(), true, true, false)
+      });
+      setUpComponents();
+    }
+
+    protected void setUpComponents () throws InstantiationException {
+        c = gf.newFcInstance(t, "primitive", C.class.getName());
+    }
+    
+    // 
-------------------------------------------------------------------------
+    // Test MembraneController
+    // 
-------------------------------------------------------------------------
+
+    public void testMembraneController() throws NoSuchInterfaceException {
+        MembraneController mc = (MembraneController)
+            c.getFcInterface(MembraneController.NAME);
+        assertNotNull(mc);
+        
+        Component membrane = mc.getFcMembrane();
+        assertNotNull(membrane);
+        
+        checkComponent(membrane, new HashSet(Arrays.asList(new Object[]{
+            COMP, BC, CC, SC, NC, MCOMP, MBC, MLC, MSC, MNC, MMC, MIC
+        })));
+    }
+
+    protected void checkComponent (Component c, Set itfs) {
+        Set extItfs = getExternalItfs(c);
+        assertEquals("Wrong external interface list", itfs, extItfs);
+    }
+}
Index: julia/test/conform/org/objectweb/fractal/juliak/conform/package.html
diff -u /dev/null 
julia/test/conform/org/objectweb/fractal/juliak/conform/package.html:1.1
--- /dev/null   Sun Jan 28 16:05:55 2007
+++ julia/test/conform/org/objectweb/fractal/juliak/conform/package.html      
  Sun Jan 28 16:05:55 2007
@@ -0,0 +1,33 @@
+<!--
+ * Julia
+ * Copyright (C) 2005-2006 INRIA, France Telecom, USTL
+ *
+ * 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: Lionel.Seinturier@xxxxxxx
+ *
+ * Author: Lionel Seinturier
+ -->
+
+<html>
+<body>
+
+<p>
+JUnit conformance test for the Juliak-specific features.
+@since 2.5
+</p>
+
+</body>
+</html>



<--  Date Index  --> <--  Thread Index  -->

Reply via email to:

Powered by MHonArc.

Copyright © 2006-2007, OW2 Consortium | contact | webmaster.