/*
 * Created on Sep 12, 2003
 */
package nonregressiontest.group.asynchronouscall;

import nonregressiontest.descriptor.defaultnodes.TestNodes;

import nonregressiontest.group.A;

import org.objectweb.proactive.core.group.Group;
import org.objectweb.proactive.core.group.ProActiveGroup;
import org.objectweb.proactive.core.node.Node;

import testsuite.test.FunctionalTest;


/**
 * @author Laurent Baduel
 */
public class Test extends FunctionalTest {
    private A typedGroup = null;
    private A resultTypedGroup = null;

    /**
     *
     */
    public Test() {
        super("asynchronous (and synchronous) call on group",
            "do an (a)synchronous call on a previously created group");
    }

    public void action() throws Exception {
        this.resultTypedGroup = this.typedGroup.asynchronousCall();
    }

    public void endTest() throws Exception {
        // nothing to do
    }

    public void initTest() throws Exception {
        Object[][] params = {
            { "Agent0" },
            { "Agent1" },
            { "Agent2" }
        };
        Node[] nodes = {
            TestNodes.getSameVMNode(), TestNodes.getLocalVMNode(),
            TestNodes.getRemoteVMNode()
        };
        this.typedGroup = (A) ProActiveGroup.newGroup(A.class.getName(),
                params, nodes);
    }

    public boolean postConditions() throws Exception {
        // was the result group created ?
        if (this.resultTypedGroup == null) {
            return false;
        }

        Group group = ProActiveGroup.getGroup(this.typedGroup);
        Group groupOfResult = ProActiveGroup.getGroup(this.resultTypedGroup);

        // has the result group the same size as the caller group ?
        if (groupOfResult.size() != group.size()) {
            return false;
        }

        boolean rightRankingOfResults = true;
        for (int i = 0; i < group.size(); i++) {
            rightRankingOfResults &= ((A) groupOfResult.get(i)).getName()
                                      .equals((((A) group.get(i)).asynchronousCall()).getName());
        }

        // is the result of the n-th group member at the n-th position in the result group ?
        return rightRankingOfResults;
    }
}

@@ -751,214 +751,10 @@
 n %7B%0A
-        this.resultTypedGroup = this.typedGroup.asynchronousCall();%0A    %7D%0A%0A    public void endTest() throws Exception %7B%0A        // nothing to do%0A    %7D%0A%0A    public void initTest() throws Exception %7B%0A        
+%09%09
 Obje
@@ -771,28 +771,19 @@
 ams = %7B%0A
-            
+%09%09%09
 %7B %22Agent
@@ -784,36 +784,27 @@
 %22Agent0%22 %7D,%0A
-            
+%09%09%09
 %7B %22Agent1%22 %7D
@@ -805,28 +805,19 @@
 nt1%22 %7D,%0A
-            
+%09%09%09
 %7B %22Agent
@@ -821,35 +821,23 @@
 ent2%22 %7D%0A
-        %7D;%0A        
+%09%09%7D;%0A%09%09
 Node%5B%5D n
@@ -845,28 +845,19 @@
 des = %7B%0A
-            
+%09%09%09
 TestNode
@@ -903,28 +903,19 @@
 Node(),%0A
-            
+%09%09%09
 TestNode
@@ -938,27 +938,15 @@
 e()%0A
-        %7D;%0A        
+%09%09%7D;%0A%09%09
 this
@@ -1010,39 +1010,173 @@
 (),%0A
-                params, nodes);
+%09%09%09%09params, nodes);%0A%0A        this.resultTypedGroup = this.typedGroup.asynchronousCall();%0A    %7D%0A%0A    public void endTest() throws Exception %7B%0A        // nothing to do
 %0A   
@@ -2072,11 +2072,58 @@
 s;%0A    %7D
+%0A%0A%09public void initTest() throws Exception %7B%0A%09%7D
 %0A%7D%0A

remove ProActive methods from initTest()