001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2007
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.tests.embedded.jsf.bean;
034:
035: import com.flexive.shared.CacheAdmin;
036: import com.flexive.shared.EJBLookup;
037: import com.flexive.shared.exceptions.FxAccountInUseException;
038: import com.flexive.shared.exceptions.FxApplicationException;
039: import com.flexive.shared.exceptions.FxLoginFailedException;
040: import com.flexive.shared.exceptions.FxLogoutFailedException;
041: import com.flexive.shared.interfaces.ACLEngine;
042: import com.flexive.shared.interfaces.WorkflowEngine;
043: import com.flexive.shared.security.ACL;
044: import com.flexive.shared.security.Mandator;
045: import com.flexive.shared.security.UserGroup;
046: import com.flexive.shared.value.FxString;
047: import com.flexive.shared.workflow.*;
048: import static com.flexive.tests.embedded.FxTestUtils.login;
049: import static com.flexive.tests.embedded.FxTestUtils.logout;
050: import com.flexive.tests.embedded.TestUsers;
051: import com.flexive.war.beans.admin.main.WorkflowBean;
052: import org.testng.annotations.AfterClass;
053: import org.testng.annotations.BeforeClass;
054: import org.testng.annotations.Test;
055:
056: import java.util.ArrayList;
057: import java.util.List;
058:
059: /**
060: * Tests for the WorkflowBean.
061: *
062: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
063: */
064: @Test(groups={"jsf"})
065: public class WorkflowBeanTest {
066: private static final String WORKFLOW_NAME = "JSF/TestNG test workflow";
067: private static final String WORKFLOW_DESCRIPTION = "JSF/TestNG test description";
068:
069: private WorkflowBean workflowBean = null;
070: private WorkflowEngine workflowEngine = null;
071: private ACLEngine aclEngine = null;
072: private ACL workflowAcl = null;
073:
074: @BeforeClass
075: public void beforeClass() throws FxLoginFailedException,
076: FxAccountInUseException, FxApplicationException {
077: workflowBean = new WorkflowBean();
078: workflowEngine = EJBLookup.getWorkflowEngine();
079: aclEngine = EJBLookup.getACLEngine();
080: login(TestUsers.SUPERVISOR);
081: workflowAcl = aclEngine.load(aclEngine.create(
082: "WorkflowBeanTestACL", new FxString("Test ACL"),
083: Mandator.MANDATOR_FLEXIVE, "#000000", null,
084: ACL.Category.WORKFLOW));
085: }
086:
087: @AfterClass
088: public void afterClass() throws FxLogoutFailedException,
089: FxApplicationException {
090: aclEngine.remove(workflowAcl.getId());
091: logout();
092: }
093:
094: @Test
095: public void testGetWorkflows() {
096: List<Workflow> workflows = workflowBean.getList();
097: List<Workflow> environmentWorkflows = CacheAdmin
098: .getEnvironment().getWorkflows();
099: assert workflows.size() == environmentWorkflows.size();
100: for (int i = 0; i < workflows.size(); i++) {
101: assert (workflows.get(i)
102: .equals(environmentWorkflows.get(i)));
103: }
104: }
105:
106: @Test
107: public void testCreateWorkflow() throws FxApplicationException {
108: long workflowId = -1;
109: try {
110: workflowBean
111: .setWorkflow(new WorkflowEdit(getTestWorkflow()));
112: String result = workflowBean.create();
113: workflowId = workflowBean.getWorkflow().getId();
114: assert "workflowEdit".equals(result) : "Unexpected result for workflowBean.create: "
115: + result;
116: assert workflowId != -1 : "Workflow not created successfully";
117: try {
118: CacheAdmin.getEnvironment().getWorkflow(workflowId);
119: } catch (Exception e) {
120: assert false : "Created workflow not found in CacheAdmin.getEnvironment().";
121: }
122: } finally {
123: if (workflowId != -1) {
124: workflowEngine.remove(workflowId);
125: }
126: }
127: }
128:
129: @Test
130: public void testUpdateWorkflow() throws FxApplicationException {
131: long workflowId = -1;
132: try {
133: workflowBean
134: .setWorkflow(new WorkflowEdit(getTestWorkflow()));
135: String result = workflowBean.create();
136: workflowId = workflowBean.getWorkflow().getId();
137: assert "workflowEdit".equals(result) : "Unexpected result for workflowBean.create: "
138: + result;
139: // add live and edit steps
140: workflowBean
141: .setStepDefinitionId(StepDefinition.EDIT_STEP_ID);
142: workflowBean.setStepACL(workflowAcl.getId());
143: workflowBean.addStep();
144: workflowBean
145: .setStepDefinitionId(StepDefinition.LIVE_STEP_ID);
146: workflowBean.addStep();
147: // add route between inserted steps
148: workflowBean.setFromStepId(workflowBean.getSteps().get(0)
149: .getId());
150: workflowBean.setToStepId(workflowBean.getSteps().get(1)
151: .getId());
152: workflowBean.setUserGroup(new UserGroup(
153: UserGroup.GROUP_EVERYONE, "everyone",
154: Mandator.MANDATOR_FLEXIVE, "#FFFFFF"));
155: workflowBean.addRoute();
156: // persist to database
157: workflowBean.save();
158: Workflow workflow = CacheAdmin.getEnvironment()
159: .getWorkflow(workflowBean.getWorkflow().getId());
160: assert workflow.getSteps().size() == 2 : "Unexpected number of steps: "
161: + workflow.getSteps().size();
162: assert workflow.getRoutes().size() == 1 : "Unexpected number of routes: "
163: + workflow.getRoutes().size();
164: } finally {
165: if (workflowId != -1) {
166: workflowEngine.remove(workflowId);
167: }
168: }
169: }
170:
171: @Test
172: public void testDeleteWorkflow() throws FxApplicationException {
173: long workflowId = -1;
174: try {
175: workflowBean
176: .setWorkflow(new WorkflowEdit(getTestWorkflow()));
177: workflowBean.create();
178: workflowId = workflowBean.getWorkflow().getId();
179: assert workflowId != -1 : "Workflow not created successfully";
180: workflowBean.setWorkflowId(workflowId);
181: String result = workflowBean.delete();
182: assert "workflowOverview".equals(result) : "Unexpected result for workflowBean.delete: "
183: + result;
184: try {
185: CacheAdmin.getEnvironment().getWorkflow(workflowId);
186: assert false : "Workflow " + workflowId
187: + " should be deleted.";
188: } catch (Exception e) {
189: // pass
190: workflowId = -1;
191: }
192: } finally {
193: if (workflowId != -1) {
194: workflowEngine.remove(workflowId);
195: }
196: }
197: }
198:
199: @Test
200: public void testGetStepsForAdding() throws FxApplicationException {
201: long workflowId = -1;
202: try {
203: workflowBean
204: .setWorkflow(new WorkflowEdit(getTestWorkflow()));
205: workflowBean.create();
206: workflowId = workflowBean.getWorkflow().getId();
207: assert workflowId != -1;
208: assert workflowBean.getStepsForAdding().size() == CacheAdmin
209: .getEnvironment().getStepDefinitions().size() : "Expected to get all step definitions for an empty workflow.";
210: } finally {
211: if (workflowId != -1) {
212: workflowEngine.remove(workflowId);
213: }
214: }
215: }
216:
217: private Workflow getTestWorkflow() {
218: return new Workflow(-1, WORKFLOW_NAME, WORKFLOW_DESCRIPTION,
219: new ArrayList<Step>(), new ArrayList<Route>());
220: }
221: }
|