1689N/A/*
1689N/A * CDDL HEADER START
1689N/A *
1689N/A * The contents of this file are subject to the terms of the
1689N/A * Common Development and Distribution License, Version 1.0 only
1689N/A * (the "License"). You may not use this file except in compliance
1689N/A * with the License.
1689N/A *
1689N/A * You can obtain a copy of the license at
1689N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
1689N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
1689N/A * See the License for the specific language governing permissions
1689N/A * and limitations under the License.
1689N/A *
1689N/A * When distributing Covered Code, include this CDDL HEADER in each
1689N/A * file and include the License file at
1689N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
1689N/A * add the following below this CDDL HEADER, with the fields enclosed
1689N/A * by brackets "[]" replaced with your own identifying information:
1689N/A * Portions Copyright [yyyy] [name of copyright owner]
1689N/A *
1689N/A * CDDL HEADER END
1689N/A *
1689N/A *
3232N/A * Copyright 2006-2008 Sun Microsystems, Inc.
1689N/A */
1689N/Apackage org.opends.server.core;
1689N/A
1689N/A
2086N/Aimport static org.opends.messages.CoreMessages.*;
2086N/Aimport org.opends.messages.MessageBuilder;
1689N/Aimport static org.testng.Assert.assertEquals;
1689N/Aimport static org.testng.Assert.assertNull;
1689N/Aimport java.util.ArrayList;
1689N/A
1689N/Aimport org.opends.server.TestCaseUtils;
1689N/Aimport org.opends.server.types.DN;
1689N/Aimport org.opends.server.types.DirectoryException;
1689N/Aimport org.opends.server.types.ResultCode;
1689N/Aimport org.opends.server.util.UtilTestCase;
1689N/Aimport org.opends.server.workflowelement.WorkflowElement;
1689N/Aimport org.testng.annotations.BeforeClass;
1689N/Aimport org.testng.annotations.DataProvider;
1689N/Aimport org.testng.annotations.Test;
1689N/A
1689N/A
1689N/A/**
1689N/A * This set of tests checks that workflow topology is properly created.
1689N/A * Topology is based on DN hierarchical relationship. Once the topolofy
1689N/A * is created, we check that the route operation returns the best workflow
1689N/A * candidate for a given request base DN.
1689N/A */
1689N/Apublic class WorkflowTopologyTest extends UtilTestCase
1689N/A{
1689N/A //===========================================================================
1689N/A //
1689N/A // B E F O R E C L A S S
1689N/A //
1689N/A //===========================================================================
1689N/A
1689N/A /**
1689N/A * Set up the environment for performing the tests in this suite.
1689N/A *
1689N/A * @throws Exception if the environment could not be set up.
1689N/A */
1689N/A @BeforeClass
1689N/A public void setUp()
1689N/A throws Exception
1689N/A {
1689N/A // This test suite depends on having the schema available,
1689N/A // so we'll start the server.
1689N/A TestCaseUtils.startServer();
1689N/A }
1689N/A
1689N/A
1689N/A //===========================================================================
1689N/A //
1689N/A // D A T A P R O V I D E R
1689N/A //
1689N/A //===========================================================================
1689N/A
1689N/A /**
1689N/A * Provide a set of DNs to create a single workflow. Each set of DNs contains
1689N/A * one baseDN for the new workflow to be created, one subordinateDN and one
1689N/A * unrelatedDN which has no hierarchical relationship with the baseDN.
1689N/A *
1689N/A * baseDN + subordinateDN + unrelatedDN
1689N/A *
1689N/A * Sample scenario for a test using this set of DNs:
1689N/A * 1) creating a workflow with the baseDN
1689N/A * 2) trying to fetch the workflow using the subordinateDN
1689N/A * 3) checking that the workflow cannot be candidate to route a request
1689N/A * with the unrelatedDN
1689N/A *
1689N/A * @return set of DNs
1689N/A * @throws Exception when DN.decode fails
1689N/A */
1689N/A @DataProvider(name = "DNSet_1")
1689N/A public Object[][] initDNSet_1()
1689N/A throws Exception
1689N/A {
1689N/A DN dnNull = null;
1689N/A DN baseDN1 = null;
1689N/A DN subordinateDN1 = null;
1689N/A DN unrelatedDN = null;
1689N/A
1689N/A try
1689N/A {
1689N/A dnNull = DN.decode ("");
1689N/A baseDN1 = DN.decode ("o=test");
1689N/A subordinateDN1 = DN.decode ("ou=subtest,o=test");
1689N/A unrelatedDN = DN.decode ("o=dummy");
1689N/A }
1689N/A catch (DirectoryException de)
1689N/A {
1689N/A throw de;
1689N/A }
1689N/A
1689N/A // Sets of DNs
1689N/A Object[][] myData =
1689N/A {
1689N/A // SET 1
1689N/A // baseDN is null suffix. There is no unrelatedDN because any DN
1689N/A // is descendant of the null suffix.
1689N/A {
1689N/A dnNull,
1689N/A subordinateDN1,
1689N/A null
1689N/A },
1689N/A
1689N/A // SET 2
1689N/A // One baseDN, one subordinateDN and one unrelatedDN
1689N/A {
1689N/A baseDN1,
1689N/A subordinateDN1,
1689N/A unrelatedDN
1689N/A },
1689N/A };
1689N/A
1689N/A return myData;
1689N/A }
1689N/A
1689N/A
1689N/A /**
1689N/A * Provide a set of DNs to create a topology of 3 workflows, and the 3
1689N/A * workflows are in the same hierarchy of DNs: baseDN1 is the superior
1689N/A * of baseDN2 which is the superior of baseDN3:
1689N/A *
1689N/A * baseDN1 + subordinateDN1
1689N/A * |
1689N/A * baseDN2 + subordinateDN2 + unrelatedDN
1689N/A * |
1689N/A * baseDN3 + subordinateDN3
1689N/A *
1689N/A * Each baseDN has a subordinateDN: the workflow with the baseDN should be
1689N/A * the candidate for a request when request base DN is the subordinateDN.
1689N/A *
1689N/A * There is an unrelatedDN which has no hierarchical relationship with any
1689N/A * of the baseDNs. The unrelatedDN is used to check that none of the
1689N/A * workflow can be candidate for the route when a request is using the
1689N/A * unrelatedDN.
1689N/A *
1689N/A * @return set of DNs
1689N/A * @throws Exception when DN.decode fails
1689N/A */
1689N/A @DataProvider(name = "DNSet_2")
1689N/A public Object[][] initDNSet_2()
1689N/A throws Exception
1689N/A {
1689N/A DN unrelatedDN = null;
1689N/A int nbElem = 3;
1689N/A DN[] baseDNs = new DN[nbElem];
1689N/A DN[] subordinateDNs = new DN[nbElem];
1689N/A DN rootDSE = null;
1689N/A
1689N/A // Create the topology of DNs:
1689N/A //
1689N/A // o=dummy ou=test1 (==> W1)
1689N/A // |
1689N/A // |
1689N/A // +--------------+
1689N/A // | |
1689N/A // | |
1689N/A // ou=subordinate1 ou=test2 (==> W2)
1689N/A // |
1689N/A // |
1689N/A // +--------------------+
1689N/A // | |
1689N/A // | |
1689N/A // ou=test3 (==> W3) ou=subordinate2
1689N/A // |
1689N/A // |
1689N/A // +--------------+
1689N/A // | |
1689N/A // | |
1689N/A // ou=subordinate3
1689N/A try
1689N/A {
1689N/A String suffix = "ou=test1";
1689N/A String baseDN1 = suffix;
1689N/A String baseDN2 = "ou=test2," + baseDN1;
1689N/A String baseDN3 = "ou=test3," + baseDN2;
1689N/A String subordinateDN1 = "ou=subordinate1," + baseDN1;
1689N/A String subordinateDN2 = "ou=subordinate2," + baseDN2;
1689N/A String subordinateDN3 = "ou=subordinate3," + baseDN3;
1689N/A
1689N/A int i = 0;
1689N/A baseDNs[i] = DN.decode (baseDN1);
1689N/A subordinateDNs[i] = DN.decode (subordinateDN1);
1689N/A i++;
1689N/A baseDNs[i] = DN.decode (baseDN2);
1689N/A subordinateDNs[i] = DN.decode (subordinateDN2);
1689N/A i++;
1689N/A baseDNs[i] = DN.decode (baseDN3);
1689N/A subordinateDNs[i] = DN.decode (subordinateDN3);
1689N/A
1689N/A unrelatedDN = DN.decode ("o=dummy");
1689N/A rootDSE = DN.decode ("");
1689N/A }
1689N/A catch (DirectoryException de)
1689N/A {
1689N/A throw de;
1689N/A }
1689N/A
1689N/A // Sets of DNs
1689N/A Object[][] myData =
1689N/A {
1689N/A // SET 1
1689N/A {
1689N/A baseDNs[0], baseDNs[1], baseDNs[2],
1689N/A subordinateDNs[0], subordinateDNs[1], subordinateDNs[2],
1689N/A unrelatedDN
1689N/A },
1689N/A
1689N/A // SET 2
1689N/A // Same than SET 1, but the first baseDN is the null suffix DN.
1689N/A // Hence there is no unrelatedDN as any DN is a subordinate of
1689N/A // the null suffix.
1689N/A {
1689N/A rootDSE, baseDNs[1], baseDNs[2],
1689N/A subordinateDNs[0], subordinateDNs[1], subordinateDNs[2],
1689N/A null
1689N/A }
1689N/A };
1689N/A
1689N/A return myData;
1689N/A }
1689N/A
1689N/A
1689N/A /**
1689N/A * Provide a set of DNs to create the following topology:
1689N/A *
1689N/A * [W1]
1689N/A * baseDN1
1689N/A * |
1689N/A * +---------+--------+
1689N/A * | |
1689N/A * | |
1689N/A * subordinateDN1 +------+------+
1689N/A * | |
1689N/A * [W2] [W3]
1689N/A * baseDN2 baseDN3
1689N/A * | |
1689N/A * | |
1689N/A * subordinateDN2 subordinateDN3
1689N/A *
1689N/A *
1689N/A * @return set of DNs
1689N/A * @throws Exception when DN.decode fails
1689N/A */
1689N/A @DataProvider(name = "DNSet_3")
1689N/A public Object[][] initDNSet_3()
1689N/A throws Exception
1689N/A {
1689N/A DN unrelatedDN = null;
1689N/A int nbElem = 3;
1689N/A DN[] baseDNs = new DN[nbElem];
1689N/A DN[] subordinateDNs = new DN[nbElem];
1689N/A DN rootDSE = null;
1689N/A
1689N/A // Create the topology of DNs:
1689N/A //
1689N/A // o=dummy dc=example,dc=com
1689N/A // |
1689N/A // |
1689N/A // +--------------+-----------------+
1689N/A // | | |
1689N/A // ou=subordinate1 ou=group ou=people
1689N/A // | |
1689N/A // | |
1689N/A // ou=subordinate2 ou=subordinate3
1689N/A try
1689N/A {
1689N/A String suffix = "dc=example,dc=com";
1689N/A String baseDN1 = suffix;
1689N/A String baseDN2 = "ou=group," + baseDN1;
1689N/A String baseDN3 = "ou=people," + baseDN1;
1689N/A String subordinateDN1 = "ou=subordinate1," + baseDN1;
1689N/A String subordinateDN2 = "ou=subordinate2," + baseDN2;
1689N/A String subordinateDN3 = "ou=subordinate3," + baseDN3;
1689N/A
1689N/A int i = 0;
1689N/A baseDNs[i] = DN.decode (baseDN1);
1689N/A subordinateDNs[i] = DN.decode (subordinateDN1);
1689N/A i++;
1689N/A baseDNs[i] = DN.decode (baseDN2);
1689N/A subordinateDNs[i] = DN.decode (subordinateDN2);
1689N/A i++;
1689N/A baseDNs[i] = DN.decode (baseDN3);
1689N/A subordinateDNs[i] = DN.decode (subordinateDN3);
1689N/A
1689N/A unrelatedDN = DN.decode ("o=dummy");
1689N/A rootDSE = DN.decode ("");
1689N/A }
1689N/A catch (DirectoryException de)
1689N/A {
1689N/A throw de;
1689N/A }
1689N/A
1689N/A // Sets of DNs
1689N/A Object[][] myData =
1689N/A {
1689N/A // SET 1
1689N/A //
1689N/A // o=dummy dc=example,dc=com
1689N/A // |
1689N/A // |
1689N/A // +--------------+-----------------+
1689N/A // | | |
1689N/A // ou=subordinate1 ou=group ou=people
1689N/A // | |
1689N/A // | |
1689N/A // ou=subordinate2 ou=subordinate3
1689N/A {
1689N/A baseDNs[0],
1689N/A baseDNs[1],
1689N/A baseDNs[2],
1689N/A subordinateDNs[0],
1689N/A subordinateDNs[1],
1689N/A subordinateDNs[2],
1689N/A unrelatedDN
1689N/A },
1689N/A
1689N/A // SET 2
1689N/A //
1689N/A // The top baseDN is the null suffix. Hence there is no unrelatedDN
1689N/A // as any DN is a subordinate of the null suffix.
1689N/A //
1689N/A // "" (rootDSE)
1689N/A // |
1689N/A // |
1689N/A // +--------------+-----------------+
1689N/A // | | |
1689N/A // ou=subordinate1 ou=group ou=people
1689N/A // | |
1689N/A // | |
1689N/A // ou=subordinate2 ou=subordinate3
1689N/A {
1689N/A rootDSE,
1689N/A baseDNs[1],
1689N/A baseDNs[2],
1689N/A subordinateDNs[0],
1689N/A subordinateDNs[1],
1689N/A subordinateDNs[2],
1689N/A null
1689N/A }
1689N/A };
1689N/A
1689N/A return myData;
1689N/A }
1689N/A
1689N/A
1689N/A /**
1689N/A * Provide a set of result codes to test the elaboration of the global
1689N/A * result code.
1689N/A *
1689N/A * @return set of result codes to test
1689N/A * @throws Exception
1689N/A */
1689N/A @DataProvider(name = "ResultCodes_1")
1689N/A public Object[][] initResultCodes_1()
1689N/A {
1689N/A // Short names...
1689N/A ResultCode rcSuccess = ResultCode.SUCCESS;
1689N/A ResultCode rcNoSuchObject = ResultCode.NO_SUCH_OBJECT;
1689N/A ResultCode rcReferral = ResultCode.REFERRAL;
1689N/A ResultCode rcOther = ResultCode.ALIAS_PROBLEM;
1689N/A ResultCode rcOther2 = ResultCode.AUTHORIZATION_DENIED;
1689N/A
1689N/A // Sets of DNs
1689N/A Object[][] myData =
1689N/A {
1689N/A // received current expected
1689N/A // result code result code result code
1689N/A { rcSuccess, rcNoSuchObject, rcSuccess },
1689N/A { rcReferral, rcSuccess, rcSuccess },
1689N/A { rcSuccess, rcOther, rcOther },
1689N/A { rcNoSuchObject, rcSuccess, rcSuccess },
1689N/A { rcNoSuchObject, rcReferral, rcReferral },
1689N/A { rcNoSuchObject, rcOther, rcOther },
1689N/A { rcReferral, rcSuccess, rcSuccess },
1689N/A { rcReferral, rcReferral, rcSuccess },
1689N/A { rcReferral, rcNoSuchObject, rcReferral },
1689N/A { rcReferral, rcOther, rcOther },
1689N/A { rcOther, rcSuccess, rcOther },
1689N/A { rcOther, rcReferral, rcOther },
1689N/A { rcOther, rcNoSuchObject, rcOther },
1689N/A { rcOther, rcOther2, rcOther2 }
1689N/A };
1689N/A
1689N/A return myData;
1689N/A }
1689N/A
1689N/A
1689N/A //===========================================================================
1689N/A //
1689N/A // T E S T C A S E S
1689N/A //
1689N/A //===========================================================================
1689N/A
1689N/A /**
1689N/A * Create a single workflow using a baseDN. There is no workflow element
1689N/A * in the workflow nor in the DIT attached to the workflow. Once the
1689N/A * workflow has been created, we are trying to fetch it using the baseDN
1689N/A * and/or the subordinateDN and/or the unrelatedDN.
1689N/A *
1689N/A * @param baseDN baseDN of the workflow to create
1689N/A * @param subordinateDN a subordinate DN of baseDN
1689N/A * @param dummyDN a DN not registered in any workflow
1689N/A */
1689N/A @Test (dataProvider = "DNSet_1", groups = "virtual")
2037N/A public void createWorkflow_basic(
1689N/A DN baseDN,
1689N/A DN subordinateDN,
1689N/A DN dummyDN
1689N/A )
1689N/A {
1689N/A // create a DIT set with the baseDN (no workflow element in the DIT).
1689N/A WorkflowElement nullWE = null;
2037N/A WorkflowImpl workflow =
3869N/A new WorkflowImpl (baseDN.toString(), baseDN, null, nullWE);
1689N/A
1689N/A // Create a worflow with the dit, no pre/post-workflow element.
2037N/A WorkflowTopologyNode workflowNode =
2037N/A new WorkflowTopologyNode (workflow, null, null);
1689N/A
1689N/A // The base DN in the workflow should match baseDN parameter
2037N/A DN workflowBaseDN = workflowNode.getBaseDN();
1689N/A assertEquals (workflowBaseDN, baseDN);
1689N/A
1689N/A // There should be no parent workflow.
2037N/A WorkflowTopologyNode parent = workflowNode.getParent();
1689N/A assertEquals (parent, null);
1689N/A
1689N/A // The workflow should handle the baseDN and subordinateDN.
1689N/A DN readBaseDN = null;
2037N/A readBaseDN = workflowNode.getParentBaseDN (baseDN);
1689N/A assertEquals (readBaseDN, baseDN);
2037N/A readBaseDN = workflowNode.getParentBaseDN (subordinateDN);
1689N/A assertEquals (readBaseDN, baseDN);
1689N/A
1689N/A // The workflow should not handle the dummyDN.
1689N/A if (dummyDN != null)
1689N/A {
2037N/A readBaseDN = workflowNode.getParentBaseDN (dummyDN);
1689N/A assertNull (readBaseDN);
1689N/A }
1689N/A
1689N/A } // createWorkflow_basic
1689N/A
1689N/A
1689N/A /**
1689N/A * Create a topology with 2 workflows. The test case contains creation
1689N/A * of clean topologies as well as bad topologies (same baseDN for the parent
1689N/A * and subordinate, subordinate above parent...).
1689N/A *
1689N/A * W1 (baseDN)
1689N/A * |
1689N/A * |
1689N/A * W2 (subordinateDN)
1689N/A *
1689N/A * There is no worklfow element attached to the DITs.
1689N/A *
1689N/A * @param baseDn base DN for the parent workflow (W1)
1689N/A * @param subordinateDN base DN for the subordinate workflow (W2)
1689N/A * @param unrelatedDN base DN with no hierarchical relationship with any
1689N/A * of the two baseDNs; parameter may be null
1689N/A */
1689N/A @Test (dataProvider = "DNSet_1", groups = "virtual")
1689N/A public void createWorkflow_simpleTopology1(
1689N/A DN baseDN,
1689N/A DN subordinateDN,
1689N/A DN unrelatedDN
1689N/A )
1689N/A {
1689N/A // Create one DIT set for baseDN and one DIT set for subordinateDN
1689N/A // (no workflow element in any DIT). Create a dummy DIT as well using
1689N/A // the unrelatedDN.
1689N/A WorkflowImpl workflow = null;
1689N/A WorkflowImpl subWorkflow = null;
1689N/A WorkflowImpl unrelatedWorkflow = null;
1689N/A {
1689N/A WorkflowElement nullWE = null;
3869N/A workflow = new WorkflowImpl (baseDN.toString(), baseDN, null, nullWE);
3869N/A subWorkflow = new WorkflowImpl (
3869N/A subordinateDN.toString(), subordinateDN, null, nullWE);
1689N/A if (unrelatedDN != null)
1689N/A {
3869N/A unrelatedWorkflow = new WorkflowImpl (
3869N/A unrelatedDN.toString(), unrelatedDN, null, nullWE);
1689N/A }
1689N/A }
1689N/A
1689N/A // Create a worflow for each dit, no pre/post-workflow element
3869N/A WorkflowTopologyNode w1 = new WorkflowTopologyNode(workflow, null, null);
3869N/A WorkflowTopologyNode w1bis = new WorkflowTopologyNode(workflow, null, null);
3869N/A WorkflowTopologyNode w2 = new WorkflowTopologyNode(subWorkflow, null, null);
1689N/A
1689N/A WorkflowTopologyNode w3 = null;
1689N/A if (unrelatedWorkflow != null)
1689N/A {
1689N/A w3 = new WorkflowTopologyNode (unrelatedWorkflow, null, null);
1689N/A }
1689N/A
1689N/A // insert status
1689N/A boolean insert;
1689N/A
1689N/A // Try to create a topology with unrelated workflows:
1689N/A //
1689N/A // w1 (baseDN)
1689N/A // |
1689N/A // w3 (dnDummy)
1689N/A //
1689N/A // Insert should be rejected
1689N/A if (w3 != null)
1689N/A {
1689N/A insert = w1.insertSubordinate (w3);
1689N/A assertEquals (insert, false);
1689N/A }
1689N/A
1689N/A // Try to create a topology with the very same workflow:
1689N/A //
1689N/A // w1 (baseDN)
1689N/A // |
1689N/A // w1 (baseDN)
1689N/A //
1689N/A // Insert should be rejected
1689N/A insert = w1.insertSubordinate (w1);
1689N/A assertEquals (insert, false);
1689N/A
1689N/A // Try to create a topology with a workflow whose baseDN is the same than
1689N/A // parent baseDN:
1689N/A //
1689N/A // w1 (baseDN)
1689N/A // |
1689N/A // w1bis (baseDN)
1689N/A //
1689N/A // Insert should be rejected
1689N/A insert = w1.insertSubordinate (w1bis);
1689N/A assertEquals (insert, false);
1689N/A
1689N/A // Try to create a topology where subordinate is above the parent:
1689N/A //
1689N/A // w2 (subordinateDN)
1689N/A // |
1689N/A // w1 (baseDN)
1689N/A //
1689N/A // Insert should be rejected
1689N/A insert = w2.insertSubordinate (w1);
1689N/A assertEquals (insert, false);
1689N/A
1689N/A // Try to create a clean topology:
1689N/A //
1689N/A // w1 (baseDN)
1689N/A // |
1689N/A // w2 (subordinateDN)
1689N/A //
1689N/A // Expected results:
1689N/A //
1689N/A // - insert should be working
1689N/A insert = w1.insertSubordinate (w2);
1689N/A assertEquals (insert, true);
1689N/A
1689N/A // - w1 should be the parent of w2
1689N/A WorkflowTopologyNode parent1 = w2.getParent();
1689N/A assertEquals (parent1, w1);
1689N/A
1689N/A // - w2 should be in the w1 subordinate list
1689N/A ArrayList<WorkflowTopologyNode> subordinates1 = w1.getSubordinates();
1689N/A assertEquals (subordinates1.size(), 1);
1689N/A assertEquals (subordinates1.get(0), w2);
1689N/A
1689N/A // - w2 should have no subordinate
1689N/A ArrayList<WorkflowTopologyNode> subordinates2 = w2.getSubordinates();
1689N/A assertEquals (subordinates2.size(), 0);
1689N/A
1689N/A } // createWorkflow_simpleTopology1
1689N/A
1689N/A
1689N/A /**
1689N/A * Create a topology with 3 workflows and check that we are getting the
1689N/A * right workflow for a given DN. Then remove a workflow in the chain and
1689N/A * check that topology is properly updated in term of parent/subordinate
1689N/A * links.
1689N/A *
1689N/A * W1 (baseDN1)
1689N/A * |
1689N/A * +----> subordinateDN1
1689N/A * |
1689N/A * W2 (baseDN2)
1689N/A * |
1689N/A * +----> subordinateDN2
1689N/A * |
1689N/A * W3 (baseDN3)
1689N/A * |
1689N/A * +----> subordinateDN3
1689N/A * |
1689N/A *
1689N/A * There is no worklfow element attached to the DITs.
1689N/A *
1689N/A * @param baseDn1 base DN for the top workflow (W1)
1689N/A * @param baseDN2 base DN for the first subordinate workflow (W2)
1689N/A * @param baseDN3 base DN for the second subordinate workflow (W3)
1689N/A * @param subordinateDN1 subordinate DN of baseDN1
1689N/A * @param subordinateDN2 subordinate DN of baseDN2
1689N/A * @param subordinateDN3 subordinate DN of baseDN3
1689N/A * @param unrelatedDN a DN not registered in any workflow
1689N/A */
1689N/A @Test (dataProvider = "DNSet_2", groups = "virtual")
1689N/A public void createWorkflow_simpleTopology2(
1689N/A DN baseDN1,
1689N/A DN baseDN2,
1689N/A DN baseDN3,
1689N/A DN subordinateDN1,
1689N/A DN subordinateDN2,
1689N/A DN subordinateDN3,
1689N/A DN unrelatedDN
1689N/A )
1689N/A {
1689N/A // Create a worflow for each baseDN, no pre/post-workflow element
1689N/A WorkflowTopologyNode w1;
1689N/A WorkflowTopologyNode w2;
1689N/A WorkflowTopologyNode w3;
1689N/A {
1689N/A // create DITs with the given baseDNs with no workflow element.
1689N/A WorkflowImpl workflow1;
1689N/A WorkflowImpl workflow2;
1689N/A WorkflowImpl workflow3;
1689N/A {
1689N/A WorkflowElement nullWE = null;
3869N/A workflow1 = new WorkflowImpl(baseDN1.toString(), baseDN1, null, nullWE);
3869N/A workflow2 = new WorkflowImpl(baseDN2.toString(), baseDN2, null, nullWE);
3869N/A workflow3 = new WorkflowImpl(baseDN3.toString(), baseDN3, null, nullWE);
1689N/A }
1689N/A
1689N/A w1 = new WorkflowTopologyNode (workflow1, null, null);
1689N/A w2 = new WorkflowTopologyNode (workflow2, null, null);
1689N/A w3 = new WorkflowTopologyNode (workflow3, null, null);
1689N/A }
1689N/A
1689N/A // insert status
1689N/A boolean insert;
1689N/A
1689N/A // Create a first topology with:
1689N/A //
1689N/A // w1 (baseDN1)
1689N/A // |
1689N/A // w3 (baseDN3)
1689N/A //
1689N/A insert = w1.insertSubordinate (w3);
1689N/A assertEquals (insert, true);
1689N/A
1689N/A // Now insert w2 between w1 and w3
1689N/A //
1689N/A // w1 (baseDN1)
1689N/A // |
1689N/A // w2 (baseDN2)
1689N/A // |
1689N/A // w3 (baseDN3)
1689N/A //
1689N/A insert = w1.insertSubordinate (w2);
1689N/A assertEquals (insert, true);
1689N/A
1689N/A // Check the topology:
1689N/A // - w1 has no parent and has only w2 as subordinate
1689N/A WorkflowTopologyNode parent = w1.getParent();
1689N/A assertNull (parent);
1689N/A ArrayList<WorkflowTopologyNode> subordinates = w1.getSubordinates();
1689N/A assertEquals (subordinates.size(), 1);
1689N/A assertEquals (subordinates.get(0), w2);
1689N/A
1689N/A // - w2 has w1 as parent and w3 as subordinate
1689N/A parent = w2.getParent();
1689N/A assertEquals (parent, w1);
1689N/A subordinates = w2.getSubordinates();
1689N/A assertEquals (subordinates.size(), 1);
1689N/A assertEquals (subordinates.get(0), w3);
1689N/A
1689N/A // -w3 has w2 as parent and no subordinate
1689N/A parent = w3.getParent();
1689N/A assertEquals (parent, w2);
1689N/A subordinates = w3.getSubordinates();
1689N/A assertEquals (subordinates.size(), 0);
1689N/A
1689N/A // ======================================================
1689N/A // Topology is clean, now let's check the route algorithm.
1689N/A // ======================================================
1689N/A
1689N/A DN readDN1 = null;
1689N/A DN readDN2 = null;
1689N/A DN readDN3 = null;
1689N/A
1689N/A // subordinate1 should be handled by w1 only
1689N/A readDN1 = w1.getParentBaseDN (subordinateDN1);
1689N/A readDN2 = w1.getParentBaseDN (subordinateDN2);
1689N/A readDN3 = w1.getParentBaseDN (subordinateDN3);
1689N/A assertEquals (readDN1, baseDN1);
1689N/A assertEquals (readDN2, baseDN2);
1689N/A assertEquals (readDN3, baseDN3);
1689N/A
1689N/A // subordinate2 should be handled by w2 only
1689N/A readDN1 = w2.getParentBaseDN (subordinateDN1);
1689N/A readDN2 = w2.getParentBaseDN (subordinateDN2);
1689N/A readDN3 = w2.getParentBaseDN (subordinateDN3);
1689N/A assertEquals (readDN1, null);
1689N/A assertEquals (readDN2, baseDN2);
1689N/A assertEquals (readDN3, baseDN3);
1689N/A
1689N/A // subordinate3 should be handled by w3 only
1689N/A readDN1 = w3.getParentBaseDN (subordinateDN1);
1689N/A readDN2 = w3.getParentBaseDN (subordinateDN2);
1689N/A readDN3 = w3.getParentBaseDN (subordinateDN3);
1689N/A assertEquals (readDN1, null);
1689N/A assertEquals (readDN2, null);
1689N/A assertEquals (readDN3, baseDN3);
1689N/A
1689N/A // unrelatedDN should be handled by none of the workflows
1689N/A readDN1 = w1.getParentBaseDN (unrelatedDN);
1689N/A readDN2 = w2.getParentBaseDN (unrelatedDN);
1689N/A readDN3 = w3.getParentBaseDN (unrelatedDN);
1689N/A assertEquals (readDN1, null);
1689N/A assertEquals (readDN2, null);
1689N/A assertEquals (readDN3, null);
2446N/A
1689N/A // ======================================================
1689N/A // Remove a workflow in the chain and check that
1689N/A // the route algorithm is still working
1689N/A // ======================================================
1689N/A
1689N/A // Remove w2...
1689N/A //
1689N/A // w1 (baseDN1) w1
1689N/A // | |
1689N/A // w2 (baseDN2) ==> |
1689N/A // | |
1689N/A // w3 (baseDN3) w3
1689N/A //
1689N/A w2.remove();
1689N/A
1689N/A // subordinate1 and subordinate2 should now be handled by w1 only
1689N/A readDN1 = w1.getParentBaseDN (subordinateDN1);
1689N/A readDN2 = w1.getParentBaseDN (subordinateDN2);
1689N/A readDN3 = w1.getParentBaseDN (subordinateDN3);
1689N/A assertEquals (readDN1, baseDN1);
1689N/A assertEquals (readDN2, baseDN1); // was baseDN2 before the removal...
1689N/A assertEquals (readDN3, baseDN3);
2446N/A
1689N/A // sanity check1
1689N/A // subordinate3 should be handled by w3 only
1689N/A readDN1 = w3.getParentBaseDN (subordinateDN1);
1689N/A readDN2 = w3.getParentBaseDN (subordinateDN2);
1689N/A readDN3 = w3.getParentBaseDN (subordinateDN3);
1689N/A assertEquals (readDN1, null);
1689N/A assertEquals (readDN2, null);
1689N/A assertEquals (readDN3, baseDN3);
2446N/A
1689N/A // sanity check2
1689N/A // unrelatedDN should be handled by none of the workflows
1689N/A readDN1 = w1.getParentBaseDN (unrelatedDN);
1689N/A readDN2 = w2.getParentBaseDN (unrelatedDN);
1689N/A readDN3 = w3.getParentBaseDN (unrelatedDN);
1689N/A assertEquals (readDN1, null);
1689N/A assertEquals (readDN2, null);
1689N/A assertEquals (readDN3, null);
2446N/A
1689N/A } // createWorkflow_simpleTopology2
1689N/A
1689N/A
1689N/A /**
1689N/A * Create a topology of workflows.
1689N/A *
1689N/A * W1
1689N/A * baseDN1
1689N/A * /\
1689N/A * / \
1689N/A * / \
1689N/A * W2 W3
1689N/A * baseDN2 baseDN3
1689N/A *
1689N/A * There is no worklfow element attached to the DITs.
1689N/A *
1689N/A * @param baseDn1 base DN for the top workflow (W1)
1689N/A * @param baseDN2 base DN for the first subordinate workflow (W2)
1689N/A * @param baseDN3 base DN for the second subordinate workflow (W3)
1689N/A * @param subordinateDN1 subordinate DN of baseDN1
1689N/A * @param subordinateDN2 subordinate DN of baseDN2
1689N/A * @param subordinateDN3 subordinate DN of baseDN3
1689N/A * @param unrelatedDN a DN not registered in any workflow
1689N/A */
1689N/A @Test (dataProvider = "DNSet_3", groups = "virtual")
2037N/A public void createWorkflow_complexTopology1(
1689N/A DN baseDN1,
1689N/A DN baseDN2,
1689N/A DN baseDN3,
1689N/A DN subordinateDN1,
1689N/A DN subordinateDN2,
1689N/A DN subordinateDN3,
1689N/A DN unrelatedDN
1689N/A )
1689N/A {
1689N/A // Create a worflow for each baseDN, no pre/post-workflow element
1689N/A WorkflowTopologyNode w1;
1689N/A WorkflowTopologyNode w2;
1689N/A WorkflowTopologyNode w3;
1689N/A {
1689N/A // create DITs with the given baseDNs with no workflow element.
1689N/A WorkflowImpl workflow1;
1689N/A WorkflowImpl workflow2;
1689N/A WorkflowImpl workflow3;
1689N/A {
1689N/A WorkflowElement nullWE = null;
1689N/A
3869N/A workflow1 = new WorkflowImpl(baseDN1.toString(), baseDN1, null, nullWE);
3869N/A workflow2 = new WorkflowImpl(baseDN2.toString(), baseDN2, null, nullWE);
3869N/A workflow3 = new WorkflowImpl(baseDN3.toString(), baseDN3, null, nullWE);
1689N/A }
1689N/A
1689N/A w1 = new WorkflowTopologyNode (workflow1, null, null);
1689N/A w2 = new WorkflowTopologyNode (workflow2, null, null);
1689N/A w3 = new WorkflowTopologyNode (workflow3, null, null);
1689N/A }
1689N/A
1689N/A // Put all the workflows in a pool
1689N/A WorkflowTopologyNode[] workflowPool = {w1, w2, w3};
1689N/A
1689N/A // Create the workflow topology: to do so, try to insert each workflow
1689N/A // in the other workflows. This is basically how workflow topology is
1689N/A // built by the network group.
1689N/A for (WorkflowTopologyNode parent: workflowPool)
1689N/A {
1689N/A for (WorkflowTopologyNode subordinate: workflowPool)
1689N/A {
1689N/A if (parent == subordinate)
1689N/A {
1689N/A // makes no sense to try to insert a workflow in itself!
1689N/A // let's do it anyway... but it should fail ;-)
1689N/A boolean insertDone = parent.insertSubordinate (parent);
1689N/A assertEquals (insertDone, false);
1689N/A }
1689N/A else
1689N/A {
1689N/A if (parent.insertSubordinate (subordinate))
1689N/A {
1689N/A // insert done
1689N/A }
1689N/A }
1689N/A }
1689N/A }
1689N/A
1689N/A // Check the topology
1689N/A // ------------------
1689N/A
1689N/A // W1 should have 2 subordinates: W2 and W3
1689N/A ArrayList<WorkflowTopologyNode> subordinates1 = w1.getSubordinates();
1689N/A assertEquals (subordinates1.size(), 2);
1689N/A
1689N/A // W2 and W3 should have no subordinate
1689N/A ArrayList<WorkflowTopologyNode> subordinates2 = w2.getSubordinates();
1689N/A assertEquals (subordinates2.size(), 0);
1689N/A ArrayList<WorkflowTopologyNode> subordinates3 = w3.getSubordinates();
1689N/A assertEquals (subordinates3.size(), 0);
1689N/A
1689N/A // W1 should be the parent of W2 and W3
1689N/A WorkflowTopologyNode parent2 = w2.getParent();
1689N/A assertEquals (parent2, w1);
1689N/A WorkflowTopologyNode parent3 = w3.getParent();
1689N/A assertEquals (parent3, w1);
1689N/A
1689N/A // Check the route algorithm
1689N/A // -------------------------
1689N/A
1689N/A // candidate for baseDN1 and subordinateBaseDN1 should be W1
1689N/A WorkflowTopologyNode candidate1 = w1.getWorkflowCandidate (baseDN1);
1689N/A assertEquals (candidate1, w1);
1689N/A candidate1 = w1.getWorkflowCandidate (subordinateDN1);
1689N/A assertEquals (candidate1, w1);
1689N/A
1689N/A // candidate for baseDN2/3 and subordinateBaseDN2/3 should be W2/3
1689N/A WorkflowTopologyNode candidate2 = w1.getWorkflowCandidate (baseDN2);
1689N/A assertEquals (candidate2, w2);
1689N/A candidate2 = w1.getWorkflowCandidate (subordinateDN2);
1689N/A assertEquals (candidate2, w2);
1689N/A
1689N/A WorkflowTopologyNode candidate3 = w1.getWorkflowCandidate (baseDN3);
1689N/A assertEquals (candidate3, w3);
1689N/A candidate3 = w1.getWorkflowCandidate (subordinateDN3);
1689N/A assertEquals (candidate3, w3);
1689N/A
1689N/A // there should be no candidate for dummyDN
1689N/A if (unrelatedDN != null)
1689N/A {
1689N/A WorkflowTopologyNode candidateDummy = w1.getWorkflowCandidate (unrelatedDN);
1689N/A assertEquals (candidateDummy, null);
1689N/A }
1689N/A
1689N/A // dump the topology
2446N/A StringBuilder sb = w1.toString ("");
1689N/A System.out.println (sb);
1689N/A
1689N/A } // createWorkflow_complexTopology1
1689N/A
1689N/A
1689N/A /**
1689N/A * Test the elaboration of the global result code by the workflow.
1689N/A */
1689N/A @Test (dataProvider = "ResultCodes_1", groups = "virtual")
1689N/A public void testGlobalResultCode(
1689N/A ResultCode receivedResultCode,
1689N/A ResultCode initialResultCode,
1689N/A ResultCode expectedGlobalResultCode
1689N/A )
1689N/A throws Exception
1689N/A {
1689N/A // Check the function that elaborates the global result code
1689N/A WorkflowResultCode globalResultCode = new WorkflowResultCode (
2086N/A initialResultCode, new MessageBuilder("")
1689N/A );
1689N/A globalResultCode.elaborateGlobalResultCode (
2086N/A receivedResultCode, new MessageBuilder("")
1689N/A );
1689N/A assertEquals (globalResultCode.resultCode(), expectedGlobalResultCode);
1689N/A }
2037N/A
2037N/A
2037N/A /**
2037N/A * Tests the workflow registration.
2037N/A */
2037N/A @Test (dataProvider = "DNSet_1", groups = "virtual")
2037N/A public void testWorkflowRegistration(
2037N/A DN baseDN,
2037N/A DN subordinateDN,
2037N/A DN dummyDN
2037N/A )
2037N/A throws DirectoryException
2037N/A {
2037N/A WorkflowElement nullWE = null;
2037N/A
2037N/A // Create a workflow to handle the baseDN with no workflow element
2037N/A WorkflowImpl workflow = new WorkflowImpl(
3869N/A baseDN.toString(), baseDN, null, nullWE);
2446N/A
2037N/A // Register the workflow with the server. Don't catch the
2037N/A // DirectoryException that could be thrown by the register() method.
2037N/A workflow.register();
2446N/A
2037N/A // Register the same workflow twice and catch the expected
2037N/A // DirectoryException.
2037N/A boolean exceptionRaised = false;
2037N/A try
2037N/A {
2037N/A workflow.register();
2037N/A }
2037N/A catch (DirectoryException e)
2037N/A {
2037N/A exceptionRaised = true;
2086N/A assertEquals(e.getMessageObject().getDescriptor(), ERR_REGISTER_WORKFLOW_ALREADY_EXISTS);
2037N/A }
2037N/A assertEquals(exceptionRaised, true);
2037N/A }
1689N/A}