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.structure;
034:
035: import com.flexive.shared.CacheAdmin;
036: import com.flexive.shared.content.FxContent;
037: import com.flexive.shared.content.FxPK;
038: import com.flexive.shared.exceptions.FxApplicationException;
039: import com.flexive.shared.exceptions.FxCreateException;
040: import com.flexive.shared.exceptions.FxLogoutFailedException;
041: import com.flexive.shared.security.ACL;
042: import com.flexive.shared.structure.*;
043: import com.flexive.shared.value.FxString;
044: import com.flexive.tests.embedded.FxTestUtils;
045: import static com.flexive.tests.embedded.FxTestUtils.login;
046: import static com.flexive.tests.embedded.FxTestUtils.logout;
047: import com.flexive.tests.embedded.TestUsers;
048: import org.apache.commons.lang.RandomStringUtils;
049: import org.testng.annotations.AfterClass;
050: import org.testng.annotations.BeforeClass;
051: import org.testng.annotations.Test;
052:
053: /**
054: * Test for the group mode (one-of and any-of) of group assignments
055: *
056: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
057: */
058: @Test(groups={"ejb","structure"})
059: public class GroupModeTest extends StructureTestBase {
060:
061: private final static String TYPE_NAME = "GROUPMODETEST_"
062: + RandomStringUtils.random(16, true, true);
063:
064: private ACL aclStructure, aclWorkflow, aclContent;
065: private long typeId;
066:
067: /**
068: * setup...
069: *
070: * @throws Exception on errors
071: */
072: @BeforeClass
073: public void beforeClass() throws Exception {
074: super .init();
075: login(TestUsers.SUPERVISOR);
076: //create the base type
077: ACL[] tmp = FxTestUtils.createACLs(
078: new String[] {
079: "STRUCTURE_"
080: + RandomStringUtils.random(16, true,
081: true),
082: "WORKFLOW_"
083: + RandomStringUtils.random(16, true,
084: true),
085: "CONTENT_"
086: + RandomStringUtils.random(16, true,
087: true)
088:
089: }, new ACL.Category[] { ACL.Category.STRUCTURE,
090: ACL.Category.WORKFLOW, ACL.Category.INSTANCE },
091: TestUsers.getTestMandator());
092: aclStructure = tmp[0];
093: aclWorkflow = tmp[1];
094: aclContent = tmp[2];
095: typeId = type.save(FxTypeEdit.createNew(TYPE_NAME,
096: new FxString("Test data"), aclStructure, null));
097:
098: createGroup("A", "/", GroupMode.AnyOf);
099: createProperty("A_P1", "/A");
100: createProperty("A_P2", "/A");
101:
102: createGroup("B", "/", GroupMode.OneOf);
103: createProperty("B_P1", "/B");
104: createProperty("B_P2", "/B");
105:
106: createGroup("C", "/", GroupMode.OneOf);
107: createGroup("C_G1", "/C", GroupMode.OneOf);
108: createProperty("C_G1_P1", "/C/C_G1");
109: createProperty("C_G1_P2", "/C/C_G1");
110: createProperty("C_P1", "/C");
111: }
112:
113: @AfterClass(dependsOnMethods={"tearDownStructures"})
114: public void afterClass() throws FxLogoutFailedException,
115: FxApplicationException {
116: logout();
117: }
118:
119: @AfterClass
120: public void tearDownStructures() throws Exception {
121: long typeId = CacheAdmin.getEnvironment().getType(TYPE_NAME)
122: .getId();
123: co.removeForType(typeId);
124: type.remove(typeId);
125: FxTestUtils.removeACL(aclStructure, aclWorkflow, aclContent);
126: }
127:
128: private void createProperty(String name, String XPath)
129: throws FxApplicationException {
130: ass.createProperty(typeId, FxPropertyEdit.createNew(name,
131: new FxString("GroupMode UnitTest property " + name),
132: new FxString("hint..."), FxMultiplicity.MULT_0_1,
133: aclStructure, FxDataType.String1024), XPath);
134: }
135:
136: private void createGroup(String name, String XPath, GroupMode mode)
137: throws FxApplicationException {
138: ass.createGroup(typeId, FxGroupEdit.createNew(name,
139: new FxString("GroupMode UnitTest group " + name),
140: new FxString("hint..."), true, FxMultiplicity.MULT_0_1)
141: .setAssignmentGroupMode(mode), XPath);
142: }
143:
144: @Test
145: public void groupModeTest() throws Exception {
146: FxContent test = co.initialize(typeId);
147: assert test.getGroupData("/B").getCreateableChildren(false)
148: .size() == 2 : "2 creatable children expected!";
149: FxString testValue = new FxString(false, "Test...");
150: test.setValue("/A/A_P1", testValue);
151: test.setValue("/A/A_P2", testValue);
152: test.setValue("/B/B_P1", testValue);
153: test.setValue("/C/C_P1", testValue);
154: try {
155: test.setValue("/B/B_P2", testValue);
156: assert false : "One-Of groups used twice!";
157: } catch (FxCreateException e) {
158: //ok
159: }
160: assert test.getGroupData("/B").getCreateableChildren(false)
161: .size() == 0 : "No creatable children should be returned!";
162: FxPK pk = co.save(test);
163: FxContent loaded = co.load(pk);
164: assert loaded.getValue("/A/A_P1").equals(testValue);
165: assert loaded.getValue("/A/A_P2").equals(testValue);
166: assert loaded.getValue("/B/B_P1").equals(testValue);
167: try {
168: loaded.setValue("/B/B_P2", testValue);
169: assert false : "One-Of groups used twice!";
170: } catch (FxCreateException e) {
171: //ok
172: }
173: loaded.remove("/B/B_P1");
174: loaded.setValue("/B/B_P2", testValue);
175: try {
176: loaded.setValue("/C/C_G1/C_G1_P1", testValue);
177: assert false : "One-Of groups used twice!";
178: } catch (FxCreateException e) {
179: //ok
180: }
181: loaded.remove("/C/C_P1");
182: loaded.setValue("/C/C_G1/C_G1_P1", testValue);
183: try {
184: loaded.setValue("/C/C_G1/C_G1_P2", testValue);
185: assert false : "One-Of groups used twice!";
186: } catch (FxCreateException e) {
187: //ok
188: }
189: co.save(loaded);
190: loaded = co.load(pk);
191: assert loaded.getValue("/B/B_P2").equals(testValue);
192: FxContent random = co.initialize(typeId).randomize();
193: pk = co.save(random);
194: co.load(pk);
195: }
196:
197: }
|