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.FxLogoutFailedException;
040: import com.flexive.shared.security.ACL;
041: import com.flexive.shared.structure.*;
042: import com.flexive.shared.value.FxString;
043: import static com.flexive.tests.embedded.FxTestUtils.login;
044: import static com.flexive.tests.embedded.FxTestUtils.logout;
045: import com.flexive.tests.embedded.TestUsers;
046: import org.apache.commons.lang.RandomStringUtils;
047: import org.testng.Assert;
048: import org.testng.annotations.AfterClass;
049: import org.testng.annotations.BeforeClass;
050: import org.testng.annotations.Test;
051:
052: /**
053: * Tests to updates of structural information
054: *
055: * @author Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
056: */
057: @Test(groups={"ejb","structure"})
058: public class UpdateTest extends StructureTestBase {
059: private static final String TEST_TYPE = "UPDATETYPETEST_"
060: + RandomStringUtils.random(16, true, true);
061: private long typeId = -1;
062:
063: private void createProperty(long typeId, ACL acl, String name,
064: String XPath) throws FxApplicationException {
065: ass.createProperty(typeId, FxPropertyEdit.createNew(name,
066: new FxString("UpdateTest UnitTest property " + name),
067: new FxString("hint..."), new FxMultiplicity(0, 5), acl,
068: FxDataType.String1024).setMultiLang(true), XPath);
069: }
070:
071: private void createGroup(long typeId, String name, String XPath)
072: throws FxApplicationException {
073: ass.createGroup(typeId,
074: FxGroupEdit.createNew(name, new FxString(
075: "UpdateTest UnitTest group " + name),
076: new FxString("hint..."), true,
077: FxMultiplicity.MULT_0_N), XPath);
078: }
079:
080: private void createStructure() throws FxApplicationException {
081: ACL structACL = CacheAdmin.getEnvironment().getACL(
082: ACL.Category.STRUCTURE.getDefaultId());
083: typeId = type.save(FxTypeEdit.createNew(TEST_TYPE,
084: new FxString("Test type"), structACL, null));
085: createProperty(typeId, structACL, "P0", "/");
086: createGroup(typeId, "G1", "/");
087: createGroup(typeId, "G2", "/G1");
088: createProperty(typeId, structACL, "P1", "/G1/G2");
089: createProperty(typeId, structACL, "P2", "/G1/G2");
090: }
091:
092: /**
093: * Change the alias of a group assignment that has instances
094: *
095: * @throws FxApplicationException on errors
096: */
097: @Test
098: public void groupAssignmentRename() throws FxApplicationException {
099: FxContent c = co.initialize(typeId);
100: c.setValue("/G1/G2/P1", new FxString(true, "Test1"));
101: c.setValue("/G1/G2/P2", new FxString(true, "Test2"));
102: FxPK cpk = co.save(c);
103: FxGroupAssignmentEdit ga = ((FxGroupAssignment) CacheAdmin
104: .getEnvironment().getType(typeId).getAssignment("/G1"))
105: .asEditable();
106: ga.setAlias("X1");
107: ass.save(ga, false);
108: FxContent x = co.load(cpk);
109: Assert.assertEquals(c.getValue("/G1/G2/P1"), x
110: .getValue("/X1/G2/P1"));
111: //set it back
112: ga = ((FxGroupAssignment) CacheAdmin.getEnvironment().getType(
113: typeId).getAssignment("/X1")).asEditable();
114: ga.setAlias("G1");
115: ass.save(ga, false);
116: FxContent y = co.load(cpk);
117: Assert.assertEquals(y.getValue("/G1/G2/P1"), x
118: .getValue("/X1/G2/P1"));
119: }
120:
121: /**
122: * Test position changes
123: *
124: * @throws FxApplicationException on errors
125: */
126: @Test
127: public void assignmentReposition() throws FxApplicationException {
128: FxPropertyAssignmentEdit pa1 = ((FxPropertyAssignment) CacheAdmin
129: .getEnvironment().getType(typeId).getAssignment(
130: "/G1/G2/P1")).asEditable();
131: FxPropertyAssignmentEdit pa2 = ((FxPropertyAssignment) CacheAdmin
132: .getEnvironment().getType(typeId).getAssignment(
133: "/G1/G2/P2")).asEditable();
134: Assert.assertEquals(pa1.getPosition(), 0);
135: Assert.assertEquals(pa2.getPosition(), 1);
136: pa1.setPosition(123);
137: ass.save(pa1, false);
138: pa1 = ((FxPropertyAssignment) CacheAdmin.getEnvironment()
139: .getType(typeId).getAssignment("/G1/G2/P1"))
140: .asEditable();
141: pa2 = ((FxPropertyAssignment) CacheAdmin.getEnvironment()
142: .getType(typeId).getAssignment("/G1/G2/P2"))
143: .asEditable();
144: Assert.assertEquals(pa1.getPosition(), 1);
145: Assert.assertEquals(pa2.getPosition(), 0);
146: }
147:
148: /**
149: * setup...
150: *
151: * @throws Exception on errors
152: */
153: @BeforeClass
154: public void beforeClass() throws Exception {
155: super .init();
156: login(TestUsers.SUPERVISOR);
157: createStructure();
158: }
159:
160: @AfterClass(dependsOnMethods={"tearDownStructures"})
161: public void afterClass() throws FxLogoutFailedException,
162: FxApplicationException {
163: logout();
164: }
165:
166: @AfterClass
167: public void tearDownStructures() throws Exception {
168: if (typeId == -1)
169: return;
170: co.removeForType(typeId);
171: type.remove(typeId);
172: }
173: }
|