001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
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;
034:
035: import com.flexive.shared.CacheAdmin;
036: import com.flexive.shared.security.ACL;
037: import com.flexive.shared.security.ACL.Category;
038: import com.flexive.shared.security.Mandator;
039: import com.flexive.shared.structure.*;
040: import com.flexive.shared.workflow.Step;
041: import com.flexive.shared.workflow.StepDefinition;
042: import com.flexive.shared.workflow.Workflow;
043: import org.testng.annotations.Test;
044:
045: import java.util.List;
046:
047: /**
048: * Environment beans tests. Includes tests that verify the un-modifiability of
049: * environment lists by the client.
050: *
051: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
052: */
053: public class EnvironmentTest {
054:
055: protected FxEnvironment getEnvironment() {
056: return CacheAdmin.getEnvironment();
057: }
058:
059: @Test(groups={"ejb","environment"})
060: public void testGetDataTypes() {
061: List<FxDataType> dataTypes = getEnvironment().getDataTypes();
062: testUnmodifiableList("environment.getDataTypes()", dataTypes,
063: FxDataType.String1024);
064: assert dataTypes.equals(getEnvironment().getDataTypes()) : "Environment list modified.";
065: }
066:
067: @Test(groups={"ejb","environment"})
068: public void testGetACLs() {
069: List<ACL> acls = getEnvironment().getACLs();
070: testUnmodifiableList("environment.getACLs()", acls, new ACL(1,
071: "test", null, -1, null, null, null,
072: ACL.Category.INSTANCE, null));
073: assert acls.equals(getEnvironment().getACLs());
074: }
075:
076: @Test(groups={"ejb","environment"})
077: public void testGetACLsByCategory() {
078: for (Category category : Category.values()) {
079: List<ACL> acls = getEnvironment().getACLs(category);
080: testUnmodifiableList("environment.getACLs()", acls,
081: new ACL(1, "test", null, -1, null, null, null,
082: ACL.Category.INSTANCE, null));
083: assert acls.equals(getEnvironment().getACLs(category));
084: }
085: }
086:
087: @Test(groups={"ejb","environment"})
088: public void testGetWorkflows() {
089: List<Workflow> workflows = getEnvironment().getWorkflows();
090: testUnmodifiableList("environment.getWorkflows()", workflows,
091: new Workflow(-1, "test", null, null, null));
092: assert workflows.equals(getEnvironment().getWorkflows());
093: }
094:
095: @Test(groups={"ejb","environment"})
096: public void testGetSteps() {
097: List<Step> steps = getEnvironment().getSteps();
098: testUnmodifiableList("environment.getSteps()", steps, new Step(
099: -1, -1, -1, -1));
100: assert steps.equals(getEnvironment().getSteps());
101: }
102:
103: @Test(groups={"ejb","environment"})
104: public void testGetStepDefinitions() {
105: List<StepDefinition> stepDefinitions = getEnvironment()
106: .getStepDefinitions();
107: testUnmodifiableList("environment.getStepDefinitions()",
108: stepDefinitions, new StepDefinition(-1, null, null, -1));
109: assert stepDefinitions.equals(getEnvironment()
110: .getStepDefinitions());
111: }
112:
113: public void testGetStepsByDefinition() {
114: // TODO
115: }
116:
117: public void testGetStepsByWorkflow() {
118: // TODO
119: }
120:
121: @Test(groups={"ejb","environment"})
122: public void testGetMandators() {
123: List<Mandator> mandators = getEnvironment().getMandators(true,
124: true);
125: testUnmodifiableList("environment.getMandators()", mandators,
126: new Mandator(-1, "test", -1, true, null));
127: assert mandators.equals(getEnvironment().getMandators(true,
128: true));
129: }
130:
131: @Test(groups={"ejb","environment"})
132: public void testGetGroups() {
133: for (int i = 0; i < 16; i++) {
134: List<FxGroup> groups = getEnvironment().getGroups(
135: (i & 1) > 0, (i & 2) > 0, (i & 4) > 0, (i & 8) > 0);
136: testUnmodifiableList(
137: "environment.getGroups()",
138: groups,
139: new FxGroup(1, "test", null, null, true, null, null));
140: assert groups
141: .equals(getEnvironment().getGroups((i & 1) > 0,
142: (i & 2) > 0, (i & 4) > 0, (i & 8) > 0));
143: }
144: }
145:
146: @Test(groups={"ejb","environment"})
147: public void testGetProperties() {
148: List<FxProperty> properties = getEnvironment().getProperties(
149: true, true);
150: testUnmodifiableList("environment.getProperties()", properties,
151: new FxProperty(-1, "test", null, null, null));
152: assert properties.equals(getEnvironment().getProperties(true,
153: true));
154: }
155:
156: @Test(groups={"ejb","environment"})
157: public void testGetPropertyAssignments() {
158: List<FxPropertyAssignment> assignments = getEnvironment()
159: .getPropertyAssignments();
160: testUnmodifiableList("environment.getPropertyAssignments()",
161: assignments, null);
162: assert assignments.equals(getEnvironment()
163: .getPropertyAssignments());
164: }
165:
166: @Test(groups={"ejb","environment"})
167: public void testGetPropertyAssignments2() {
168: List<FxPropertyAssignment> assignments = getEnvironment()
169: .getPropertyAssignments(true);
170: testUnmodifiableList(
171: "environment.getPropertyAssignments(true)",
172: assignments, null);
173: assert assignments.equals(getEnvironment()
174: .getPropertyAssignments(true));
175: }
176:
177: @Test(groups={"ejb","environment"})
178: public void testGetGroupAssignments() {
179: List<FxGroupAssignment> assignments = getEnvironment()
180: .getGroupAssignments();
181: testUnmodifiableList("environment.getGroupAssignments()",
182: assignments, new FxGroupAssignment(-1, false, null,
183: "test", null, -1, new FxMultiplicity(0, 1), 0,
184: null, -1, null, null, null, GroupMode.AnyOf,
185: null));
186: assert assignments.equals(getEnvironment()
187: .getGroupAssignments());
188: }
189:
190: @Test(groups={"ejb","environment"})
191: public void testGetTypes() {
192: for (int i = 0; i < 16; i++) {
193: List<FxType> types = getEnvironment().getTypes((i & 1) > 0,
194: (i & 2) > 0, (i & 4) > 0, (i & 8) > 0);
195: testUnmodifiableList("environment.getTypes(...)", types,
196: null);
197: assert types.equals(getEnvironment().getTypes((i & 1) > 0,
198: (i & 2) > 0, (i & 4) > 0, (i & 8) > 0));
199: }
200: }
201:
202: private <T> void testUnmodifiableList(String source, List<T> list,
203: T dummyInstance) {
204: try {
205: list.clear();
206: assert false : "List can be cleared: " + source;
207: } catch (UnsupportedOperationException e) {
208: // continue
209: }
210: try {
211: list.add(dummyInstance);
212: assert false : "List can be extended: " + source;
213: } catch (UnsupportedOperationException e) {
214: // continue
215: }
216: try {
217: if (list.size() > 0) {
218: list.remove(0);
219: assert false : "List elements can be removed: "
220: + source;
221: }
222: } catch (UnsupportedOperationException e) {
223: // continue
224: }
225: }
226: }
|