0001: /*
0002: * Copyright 2001-2006 C:1 Financial Services GmbH
0003: *
0004: * This software is free software; you can redistribute it and/or
0005: * modify it under the terms of the GNU Lesser General Public
0006: * License Version 2.1, as published by the Free Software Foundation.
0007: *
0008: * This software is distributed in the hope that it will be useful,
0009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0011: * Lesser General Public License for more details.
0012: *
0013: * You should have received a copy of the GNU Lesser General Public
0014: * License along with this library; if not, write to the Free Software
0015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
0016: */
0017:
0018: package de.finix.contelligent.core;
0019:
0020: import java.util.Collections;
0021: import java.util.HashMap;
0022: import java.util.HashSet;
0023: import java.util.Map;
0024: import java.util.Set;
0025:
0026: import de.finix.contelligent.CallData;
0027: import de.finix.contelligent.Component;
0028: import de.finix.contelligent.ComponentContext;
0029: import de.finix.contelligent.ComponentLink;
0030: import de.finix.contelligent.ComponentManager;
0031: import de.finix.contelligent.ComponentNotFoundException;
0032: import de.finix.contelligent.ComponentPath;
0033: import de.finix.contelligent.Container;
0034: import de.finix.contelligent.Contelligent;
0035: import de.finix.contelligent.Session;
0036: import de.finix.contelligent.category.Category;
0037: import de.finix.contelligent.category.CategoryManager;
0038: import de.finix.contelligent.content.BooleanContent;
0039: import de.finix.contelligent.content.ContelligentBooleanContent;
0040: import de.finix.contelligent.content.ContentProvider;
0041: import de.finix.contelligent.core.security.AccessControlList;
0042: import de.finix.contelligent.core.security.ContelligentPrincipal;
0043: import de.finix.contelligent.core.security.ContelligentSecurityManager;
0044: import de.finix.contelligent.core.security.User;
0045: import de.finix.contelligent.exception.ComponentAlreadyExistsException;
0046: import de.finix.contelligent.resource.NumberResource;
0047: import de.finix.contelligent.resource.TextResource;
0048: import de.finix.contelligent.test.ContelligentTestCase;
0049: import de.finix.contelligent.test.components.TypeWithAllPropertyTypes;
0050: import de.finix.contelligent.xml.elements.TypeElement;
0051: import de.finix.contelligent.xml.elements.TypeMetainfoElement;
0052:
0053: public class ComponentManagerTest extends ContelligentTestCase {
0054:
0055: private static final String RESOURCE_KEY1 = ":de";
0056:
0057: private static final String RESOURCE_KEY2 = ":en";
0058:
0059: private CallData callData;
0060:
0061: private ComponentManager manager;
0062:
0063: private ComponentPath dir1, dir2, dir1Text1, dir2Text2;
0064:
0065: private Session session;
0066:
0067: /**
0068: * Creates a new <code>ComponentManagerTest</code> instance.
0069: *
0070: * @param name
0071: * a <code>String</code> value
0072: */
0073: public ComponentManagerTest(String name) {
0074: super (name);
0075: }
0076:
0077: /**
0078: * Here we fetch the <code>CallData</code> and the
0079: * <code>ComponentManager</code> from the request and set them as instance
0080: * variables.
0081: *
0082: * @exception java.lang.Exception
0083: * if an error occurs
0084: */
0085: public void setUp() throws Exception {
0086: session = beginSession("admin", "system-users", "admin");
0087: callData = createCallData(session);
0088: manager = callData.getActualManager();
0089: assertNotNull("No ComponentManager set in CallData", manager);
0090:
0091: beginTx(callData);
0092: try {
0093: dir1 = TEST_WORK_DIR.append("dir1");
0094: dir2 = TEST_WORK_DIR.append("dir2");
0095: dir1Text1 = dir1.append("text1");
0096: dir2Text2 = dir2.append("text2");
0097:
0098: Container workdir = (Container) manager.getComponent(
0099: TEST_WORK_DIR, callData);
0100: if (manager.componentExists(dir1)) {
0101: manager.deleteComponentTree(callData, dir1);
0102: }
0103: if (manager.componentExists(dir2)) {
0104: manager.deleteComponentTree(callData, dir2);
0105: }
0106: Container dir1Container = (Container) manager
0107: .createComponent(workdir, dir1.getName(),
0108: FOLDER_TYPE_NAME, null, null, callData);
0109: assertNotNull("Could not create container " + dir1,
0110: dir1Container);
0111: assertTrue("Container '" + dir1
0112: + "' does not exist after successful creation",
0113: manager.componentExists(dir1));
0114:
0115: Container dir2Container = (Container) manager
0116: .createComponent(workdir, dir2.getName(),
0117: FOLDER_TYPE_NAME, null, null, callData);
0118: assertNotNull("Could not create container " + dir2,
0119: dir2Container);
0120: assertTrue("Container '" + dir2
0121: + "' does not exist after successful creation",
0122: manager.componentExists(dir1));
0123:
0124: Component text1 = manager.createComponent(dir1Container,
0125: dir1Text1.getName(), ALLPROPS_TYPE_NAME, null,
0126: null, callData);
0127: assertNotNull("Could not create text component "
0128: + dir1Text1, text1);
0129: assertTrue("Text component '" + dir1Text1
0130: + "' does not exist after successful creation",
0131: manager.componentExists(dir1Text1));
0132:
0133: Component text2 = manager.createComponent(dir2Container,
0134: dir2Text2.getName(), ALLPROPS_TYPE_NAME, null,
0135: null, callData);
0136: assertNotNull("Could not create text component "
0137: + dir2Text2, text2);
0138: assertTrue("Text component '" + dir2Text2
0139: + "' does not exist after successful creation",
0140: manager.componentExists(dir2Text2));
0141:
0142: commitTx();
0143: } catch (Exception e) {
0144: rollbackTx();
0145: endSession(session); // the TestRunner doesn't call tearDown() if
0146: // setUp() fails!
0147: throw e;
0148: } catch (Error e) { // assert throws Error
0149: rollbackTx();
0150: endSession(session);
0151: throw e;
0152: }
0153: }
0154:
0155: public void tearDown() throws Exception {
0156: beginTx(callData);
0157: try {
0158: manager.deleteComponentTree(callData, dir1);
0159: assertTrue("Test-container '" + dir1
0160: + "' does exist after deletion", !manager
0161: .componentExists(dir1));
0162: manager.deleteComponentTree(callData, dir2);
0163: assertTrue("Test-container '" + dir2
0164: + "' does exist after deletion", !manager
0165: .componentExists(dir2));
0166: commitTx();
0167: } catch (Exception e) {
0168: rollbackTx();
0169: throw e;
0170: } catch (Error e) { // assert throws Error
0171: rollbackTx();
0172: throw e;
0173: } finally {
0174: endSession(session);
0175: }
0176: }
0177:
0178: public void testCopy() throws Throwable {
0179: final ComponentPath dir1Copy = dir2.append("CopyOfDir1");
0180: final ComponentPath dir1Text1Copy = dir1Copy.append(dir1Text1
0181: .getName());
0182:
0183: beginTx(callData);
0184: try {
0185: manager.copyComponentTree(callData, dir1, dir2, dir1Copy
0186: .getName());
0187: assertTrue("Component '" + dir1Copy
0188: + "' does not exists after copy", manager
0189: .componentExists(dir1Copy));
0190: // subcomponent text1 must also exist:
0191: assertTrue("Subcomponent '" + dir1Text1.getName()
0192: + "' does not exists after copy", manager
0193: .componentExists(dir1Text1Copy));
0194: Component component = manager.getComponent(dir1Copy,
0195: callData);
0196: assertTrue(((ComponentContextImpl) component
0197: .getComponentContext()).getACL().isEmpty());
0198: component = manager.getComponent(dir1Text1Copy, callData);
0199: assertTrue(((ComponentContextImpl) component
0200: .getComponentContext()).getACL().isEmpty());
0201: commitTx();
0202: } catch (Throwable t) {
0203: rollbackTx();
0204: throw t;
0205: }
0206:
0207: beginTx(callData);
0208: try {
0209: manager.copyComponentTree(callData, dir1Text1, dir2,
0210: dir1Copy.getName());
0211: fail("Attempt to overwrite existing component should raise a ComponentAlreadyExistsException");
0212: } catch (ComponentAlreadyExistsException e) {
0213: commitTx();// OK
0214: } catch (Throwable t) {
0215: rollbackTx();
0216: throw t;
0217: }
0218:
0219: beginTx(callData);
0220: try {
0221: manager.deleteComponentTree(callData, dir1Copy);
0222: manager.copyComponentTree(callData, dir1Text1, dir2,
0223: dir1Copy.getName());
0224:
0225: // path CopyOfDir1 should now be text dir1Text1
0226: Component copy = manager.getComponent(dir1Copy, callData);
0227: assertTrue(
0228: "Copy of '"
0229: + dir1Copy
0230: + "' is no instance of TypeWithAllPropertyTypes but '"
0231: + copy.getClass() + "'!",
0232: (copy instanceof TypeWithAllPropertyTypes));
0233: if (copy instanceof Container) {
0234: // no subcomponents must exist now:
0235: assertTrue(
0236: "No subcomponents must exists after copy of text component",
0237: (manager.getSubcomponentCount((Container) copy) == 0));
0238: }
0239: commitTx();
0240: } catch (Throwable t) {
0241: rollbackTx();
0242: throw t;
0243: }
0244: }
0245:
0246: public void testCopyOfClone() throws Throwable {
0247: beginTx(callData);
0248: final ComponentPath dir1Copy = dir2.append("CopyOfDir1");
0249: final ComponentPath dir1Text1Copy = dir1Copy.append(dir1Text1
0250: .getName());
0251: long orgValue = 0, cloneValue;
0252:
0253: try {
0254: TypeWithAllPropertyTypes clone = (TypeWithAllPropertyTypes) manager
0255: .cloneComponent(dir1Text1, callData);
0256:
0257: orgValue = clone.getLongTest();
0258: cloneValue = (orgValue + 111);
0259: clone.setLongTest(cloneValue);
0260: manager.updateComponent(clone, callData);
0261: clone = (TypeWithAllPropertyTypes) manager.getComponent(
0262: dir1Text1, callData);
0263:
0264: assertTrue("Clone of '" + dir1Text1
0265: + "' does not have new property value!", (clone
0266: .getLongTest() == cloneValue));
0267:
0268: manager.copyComponentTree(callData, dir1, dir2, dir1Copy
0269: .getName());
0270: assertTrue("Component '" + dir1Copy
0271: + "' does not exists after copy", manager
0272: .componentExists(dir1Copy));
0273: // subcomponent text1 must also exist:
0274: assertTrue("Subcomponent '" + dir1Text1Copy.getName()
0275: + "' does not exists after copy", manager
0276: .componentExists(dir1Text1Copy));
0277:
0278: commitTx();
0279: } catch (Throwable t) {
0280: rollbackTx();
0281: throw t;
0282: }
0283:
0284: beginTx(callData);
0285: TypeWithAllPropertyTypes clone = (TypeWithAllPropertyTypes) manager
0286: .getComponent(dir1Text1Copy, callData);
0287: assertTrue("Copied clone of '" + dir1Text1
0288: + "' does not have new property value!", (clone
0289: .getLongTest() == cloneValue));
0290: commitTx();
0291:
0292: // now with resources:
0293: final String RESOURCE_KEY = "test:xx:yy";
0294: final String orgContent = "original contents";
0295: final String cloneContent = "contents of clone";
0296: final ComponentPath dir2Copy = dir1.append("CopyOfDir2");
0297: final ComponentPath dir2Text2Copy = dir2Copy.append(dir2Text2
0298: .getName());
0299:
0300: beginTx(callData);
0301: try {
0302: Component component = manager.cloneComponent(dir2Text2,
0303: callData);
0304: ComponentContextImpl context = (ComponentContextImpl) component
0305: .getComponentContext();
0306: TextResource resource = new TextResource(orgContent,
0307: TimeService.getInstance().currentTimeMillis());
0308: context.setContentResource(RESOURCE_KEY, resource);
0309: context.setTemplateResource(RESOURCE_KEY, resource);
0310: manager.updateComponent(component, callData);
0311: component = null;
0312: context = null;
0313: resource = null;
0314: commitTx();
0315: beginTx(callData);
0316:
0317: component = manager.getComponent(dir2Text2, callData);
0318: context = (ComponentContextImpl) component
0319: .getComponentContext();
0320: assertTrue("content-resource not created", context
0321: .getContentResource(RESOURCE_KEY) != null);
0322: assertTrue("content-resourceIdentifier missing", context
0323: .getContentResourceIdentifiers().contains(
0324: RESOURCE_KEY));
0325: assertTrue("template-resource not created", context
0326: .getTemplateResource(RESOURCE_KEY) != null);
0327: assertTrue("template-rResourceIdentifier missing", context
0328: .getTemplateResourceIdentifiers().contains(
0329: RESOURCE_KEY));
0330:
0331: resource = (TextResource) context
0332: .getContentResource(RESOURCE_KEY);
0333: String contents = resource.getString();
0334: assertTrue("content-resource does not contain '"
0335: + orgContent + "' but '" + contents + "'!",
0336: orgContent.equals(contents));
0337: resource = (TextResource) context
0338: .getTemplateResource(RESOURCE_KEY);
0339: contents = resource.getString();
0340: assertTrue("template-resource does not contain '"
0341: + orgContent + "' but '" + contents + "'!",
0342: orgContent.equals(contents));
0343:
0344: component = manager.cloneComponent(component);
0345: context = (ComponentContextImpl) component
0346: .getComponentContext();
0347: context.setContentResource(RESOURCE_KEY, new TextResource(
0348: cloneContent, TimeService.getInstance()
0349: .currentTimeMillis()));
0350: context.setTemplateResource(RESOURCE_KEY, new TextResource(
0351: cloneContent, TimeService.getInstance()
0352: .currentTimeMillis()));
0353: manager.updateComponent(component, callData);
0354:
0355: manager.copyComponentTree(callData, dir2, dir1, dir2Copy
0356: .getName());
0357:
0358: commitTx();
0359: beginTx(callData);
0360:
0361: assertTrue("Component '" + dir2Copy
0362: + "' does not exists after copy", manager
0363: .componentExists(dir2Copy));
0364: // subcomponent text1 must also exist:
0365: assertTrue("Subcomponent '" + dir2Text2Copy.getName()
0366: + "' does not exists after copy", manager
0367: .componentExists(dir2Text2Copy));
0368:
0369: component = manager.getComponent(dir2Text2Copy, callData);
0370: context = (ComponentContextImpl) component
0371: .getComponentContext();
0372: resource = (TextResource) context
0373: .getContentResource(RESOURCE_KEY);
0374: contents = resource.getString();
0375: assertTrue("content-resource does not contain '"
0376: + cloneContent + "' but '" + contents + "'!",
0377: cloneContent.equals(contents));
0378: resource = (TextResource) context
0379: .getTemplateResource(RESOURCE_KEY);
0380: contents = resource.getString();
0381: assertTrue("template-resource does not contain '"
0382: + cloneContent + "' but '" + contents + "'!",
0383: cloneContent.equals(contents));
0384: commitTx();
0385: } catch (Throwable t) {
0386: rollbackTx();
0387: throw t;
0388: }
0389: }
0390:
0391: /** creates a component with additional properties and owners */
0392: public void testCreateComponent() throws Throwable {
0393: beginTx(callData);
0394: Contelligent contelligent = getContelligent();
0395: String groupId = contelligent
0396: .getProperty("contelligent.pkgs.test.user-groupid");
0397: String userId = contelligent
0398: .getProperty("contelligent.pkgs.test.user-id");
0399: String password = contelligent
0400: .getProperty("contelligent.pkgs.test.user-password");
0401: User testUser = ContelligentSecurityManager.getInstance()
0402: .authenticate(userId, groupId, password);
0403: assertNotNull("Could not find test-user '" + userId
0404: + "' with group-id '" + groupId + "'!", testUser);
0405:
0406: ContelligentPrincipal actualPrincipal = callData
0407: .getContelligentSession().getUser();
0408: Set ownerSet = new HashSet(2);
0409: ownerSet.add(testUser);
0410: ownerSet.add(actualPrincipal);
0411: ComponentPath path = dir1.append("AText");
0412: AccessControlList acl = new AccessControlList(path.toString(),
0413: ownerSet);
0414: Map propertyMap = new HashMap();
0415: propertyMap.put("longTest", "99");
0416: Container dir1Container = (Container) manager.getComponent(
0417: dir1, callData);
0418: try {
0419: manager.createComponent(dir1Container, path.getName(),
0420: ALLPROPS_TYPE_NAME, propertyMap, acl, callData);
0421: assertTrue("Component '" + path
0422: + "' does not exist after successful creation",
0423: manager.componentExists(path));
0424:
0425: TypeWithAllPropertyTypes comp = (TypeWithAllPropertyTypes) manager
0426: .getComponent(path, callData);
0427: assertTrue(
0428: "The test property was not set correctly using createComponent",
0429: comp.getLongTest() == 99L);
0430:
0431: acl = ((ComponentContextImpl) comp.getComponentContext())
0432: .getACL();
0433: Set owners = acl.getOwners();
0434: assertTrue("test-user is no owner", owners
0435: .contains(testUser));
0436: assertTrue("actual user (" + actualPrincipal
0437: + ") is no owner", owners.contains(actualPrincipal));
0438:
0439: commitTx();
0440: } catch (Throwable t) {
0441: rollbackTx();
0442: throw t;
0443: }
0444: }
0445:
0446: public void testCreateComponentInReadOnlyPkg() throws Throwable {
0447: beginTx(callData);
0448: Contelligent contelligent = getContelligent();
0449: String groupId = contelligent
0450: .getProperty("contelligent.pkgs.test.user-groupid");
0451: String userId = contelligent
0452: .getProperty("contelligent.pkgs.test.user-id");
0453: String password = contelligent
0454: .getProperty("contelligent.pkgs.test.user-password");
0455: User testUser = ContelligentSecurityManager.getInstance()
0456: .authenticate(userId, groupId, password);
0457: assertNotNull("Could not find test-user '" + userId
0458: + "' with group-id '" + groupId + "'!", testUser);
0459:
0460: ContelligentPrincipal actualPrincipal = callData
0461: .getContelligentSession().getUser();
0462: Set ownerSet = new HashSet(2);
0463: ownerSet.add(testUser);
0464: ownerSet.add(actualPrincipal);
0465: ComponentPath path = dir1.append("AText");
0466: AccessControlList acl = new AccessControlList(path.toString(),
0467: ownerSet);
0468: Map propertyMap = new HashMap();
0469: propertyMap.put("longTest", "99");
0470: Container dir1Container = (Container) manager.getComponent(
0471: new ComponentPath("/contelligent/core"), callData);
0472: try {
0473: manager.createComponent(dir1Container, path.getName(),
0474: ALLPROPS_TYPE_NAME, propertyMap, acl, callData);
0475: assertTrue("Exception expected", false);
0476: } catch (Throwable t) {
0477: rollbackTx();
0478: }
0479: }
0480:
0481: /**
0482: * Creates a link and tries to resolve it using both followLinks true and
0483: * false within the same tx.
0484: */
0485: public void testCreateLink() throws Throwable {
0486: beginTx(callData);
0487: try {
0488: // (create link to dir2Text2 beneath dir1)
0489: Component linkTarget = manager.getComponent(dir2Text2,
0490: callData);
0491: Container parent = (Container) manager.getComponent(dir1,
0492: callData);
0493: ComponentPath linkPath = dir1.append("LinkToText2");
0494: manager.createLink(linkTarget, parent, linkPath.getName(),
0495: null, callData);
0496:
0497: assertTrue("Link '" + linkPath
0498: + "' does not exists after creation!", manager
0499: .componentExists(linkPath));
0500:
0501: Component link = manager.getComponent(linkPath, callData,
0502: false);
0503: assertTrue("Link '" + linkPath
0504: + "' is no instance of ComponentLink but '"
0505: + link.getClass() + "'!",
0506: (link instanceof ComponentLink));
0507:
0508: Component tmp = manager.getComponent(linkPath, callData,
0509: true);
0510: assertEquals("Following link '" + linkPath
0511: + "' results in wrong component!", dir2Text2, tmp
0512: .getComponentContext().getPath());
0513:
0514: assertTrue("Following link '" + linkPath
0515: + "' results in wrong type (class='"
0516: + tmp.getClass() + "')!",
0517: (tmp instanceof TypeWithAllPropertyTypes));
0518:
0519: commitTx();
0520:
0521: // now check the same in another tx:
0522:
0523: beginTx(callData);
0524:
0525: link = manager.getComponent(linkPath, callData, false);
0526: assertTrue("Link '" + linkPath
0527: + "' is no instance of ComponentLink but '"
0528: + link.getClass() + "'!",
0529: (link instanceof ComponentLink));
0530:
0531: tmp = manager.getComponent(linkPath, callData, true);
0532: assertEquals("Following link '" + linkPath
0533: + "' results in wrong component!", dir2Text2, tmp
0534: .getComponentContext().getPath());
0535:
0536: assertTrue("Following link '" + linkPath
0537: + "' results in wrong type (class='"
0538: + tmp.getClass() + "')!",
0539: (tmp instanceof TypeWithAllPropertyTypes));
0540:
0541: commitTx();
0542: } catch (Throwable t) {
0543: rollbackTx();
0544: throw t;
0545: }
0546: }
0547:
0548: public void testDelete() throws Throwable {
0549: ComponentPath path = dir1.append("MyComponent");
0550: NumberResource resource1 = new NumberResource(
0551: new Double(29.883), TimeService.getInstance()
0552: .currentTimeMillis());
0553: NumberResource resource2 = new NumberResource(
0554: new Double(99.775), TimeService.getInstance()
0555: .currentTimeMillis());
0556:
0557: beginTx(callData);
0558: try {
0559: Container dir1Container = (Container) manager.getComponent(
0560: dir1, callData);
0561: Component c = manager.createComponent(dir1Container, path
0562: .getName(), ALLPROPS_TYPE_NAME, null, null,
0563: callData);
0564: ComponentContextImpl context = (ComponentContextImpl) c
0565: .getComponentContext();
0566: context
0567: .setSensitiveContentCategories(getCategories(new String[] { "locale" }));
0568: context.setContentResource(RESOURCE_KEY1, resource1);
0569: context.setContentResource(RESOURCE_KEY2, resource2);
0570: manager.updateComponent(c, callData);
0571: commitTx();
0572: } catch (Throwable t) {
0573: rollbackTx();
0574: throw t;
0575: }
0576:
0577: beginTx(callData);
0578: assertTrue("Component '" + path
0579: + "' does not exist after successful creation", manager
0580: .componentExists(path));
0581: Component c = manager.getComponent(path, callData);
0582: ComponentContext ctx = c.getComponentContext();
0583: assertTrue("Resource1 not found", ctx
0584: .getContentResource(RESOURCE_KEY1) != null);
0585: assertTrue("Resource2 not found", ctx
0586: .getContentResource(RESOURCE_KEY2) != null);
0587: assertTrue("Sensitive categories not found", !ctx
0588: .getSensitiveContentCategories().isEmpty());
0589: commitTx();
0590:
0591: beginTx(callData);
0592: try {
0593: manager.deleteComponentTree(callData, path);
0594: assertTrue("Component '" + path
0595: + "' still exists after successful deletion",
0596: !manager.componentExists(path));
0597: commitTx();
0598: } catch (Throwable t) {
0599: rollbackTx();
0600: throw t;
0601: }
0602:
0603: beginTx(callData);
0604: try {
0605: manager.getComponent(path, callData);
0606: fail("Component still exists");
0607: } catch (ComponentNotFoundException e) {
0608: }
0609: commitTx();
0610: }
0611:
0612: // helper method for testDelete
0613: private Set getCategories(String[] names) {
0614: Set answer = new HashSet();
0615: for (int i = 0; i < names.length; i++) {
0616: answer.add(ContelligentImpl.getInstance()
0617: .getCategoryManager().getCategory(names[i]));
0618: }
0619: return answer;
0620: }
0621:
0622: public void testSimpleMove() throws Throwable {
0623: beginTx(callData);
0624:
0625: try {
0626: // move dir1:
0627: ComponentPath moveTarget = dir2.append("Dir1Moved");
0628: ComponentPath movedSubTarget = moveTarget.append(dir1Text1
0629: .getName());
0630: manager.moveComponentTree(dir1, moveTarget, callData);
0631: assertTrue(!manager.componentExists(dir1));
0632: assertTrue(manager.componentExists(moveTarget));
0633: // sub text1
0634: assertTrue(manager.componentExists(movedSubTarget));
0635:
0636: commitTx();
0637: beginTx(callData);
0638:
0639: // now move it back:
0640: manager.moveComponentTree(moveTarget, dir1, callData);
0641:
0642: commitTx();
0643: beginTx(callData);
0644:
0645: assertTrue(manager.componentExists(dir1));
0646: assertTrue(!manager.componentExists(moveTarget));
0647:
0648: commitTx();
0649: } catch (Throwable t) {
0650: rollbackTx();
0651: throw t;
0652: }
0653: }
0654:
0655: public void testSimpleCategoryResolving() throws Throwable {
0656: beginTx(callData);
0657:
0658: CategoryManager categoryManager = getContelligent()
0659: .getCategoryManager();
0660: String categoryName = getContelligent().getProperty(
0661: "contelligent.pkgs.test.category");
0662: Category category = categoryManager.getCategory(categoryName);
0663: assertNotNull("Test-Category '" + categoryName + "' not found",
0664: category);
0665:
0666: try {
0667: Container container = (Container) manager.getComponent(
0668: dir1, callData);
0669: container = (Container) manager.createComponent(container,
0670: categoryName, FOLDER_TYPE_NAME, null, null,
0671: callData);
0672: container = (Container) manager.createComponent(container,
0673: category.getDefaultValue(), FOLDER_TYPE_NAME, null,
0674: null, callData);
0675: manager.createComponent(container, "test",
0676: ALLPROPS_TYPE_NAME, null, null, callData);
0677:
0678: container = null;
0679: commitTx();
0680: } catch (Throwable t) {
0681: rollbackTx();
0682: throw t;
0683: }
0684:
0685: beginTx(callData);
0686:
0687: ComponentPath normalPath = dir1.append(categoryName).append(
0688: category.getDefaultValue()).append("test");
0689: assertTrue("Component '" + normalPath
0690: + "' does not exist after successful creation", manager
0691: .componentExists(normalPath));
0692:
0693: Map categoryMap = new HashMap(callData.getCategoryMap());
0694: categoryMap.put(categoryName, category.getDefaultValue());
0695: // XXX: this is a hack until we have createCallData() with param
0696: // 'categoryMap' or something. (2002/10/30, rs)
0697: ((AbstractCallDataImpl) callData).setCategoryMap(categoryMap);
0698:
0699: ComponentPath categoryPath = dir1.append(categoryName).append(
0700: CategoryManager.CATEGORY_TOKEN).append("test");
0701: Component test = manager.getComponent(categoryPath, callData);
0702: assertNotNull("Could not find component using path '"
0703: + categoryPath + "'", test);
0704:
0705: commitTx();
0706: }
0707:
0708: public void testMultipleCategoryResolving() throws Throwable {
0709: beginTx(callData);
0710:
0711: long testDefault = 8884L;
0712: long testBBB = 9887777L;
0713:
0714: CategoryManager categoryManager = getContelligent()
0715: .getCategoryManager();
0716: String categoryName = getContelligent().getProperty(
0717: "contelligent.pkgs.test.category");
0718: Category category = categoryManager.getCategory(categoryName);
0719: assertNotNull("Test-Category '" + categoryName + "' not found",
0720: category);
0721:
0722: try {
0723: Container container = (Container) manager.getComponent(
0724: dir1, callData);
0725: container = (Container) manager.createComponent(container,
0726: categoryName, FOLDER_TYPE_NAME, null, null,
0727: callData);
0728: container = (Container) manager.createComponent(container,
0729: category.getDefaultValue(), FOLDER_TYPE_NAME, null,
0730: null, callData);
0731: container = (Container) manager.createComponent(container,
0732: "folder", FOLDER_TYPE_NAME, null, null, callData);
0733: container = (Container) manager.createComponent(container,
0734: categoryName, FOLDER_TYPE_NAME, null, null,
0735: callData);
0736: Container container2 = (Container) manager.createComponent(
0737: container, category.getDefaultValue(),
0738: FOLDER_TYPE_NAME, null, null, callData);
0739: Container container3 = (Container) manager.createComponent(
0740: container, "bbb", FOLDER_TYPE_NAME, null, null,
0741: callData);
0742:
0743: Map propertyMap = new HashMap();
0744: propertyMap.put("longTest", String.valueOf(testDefault));
0745: manager.createComponent(container2, "test",
0746: ALLPROPS_TYPE_NAME, propertyMap, null, callData);
0747: propertyMap.put("longTest", String.valueOf(testBBB));
0748: manager.createComponent(container3, "test",
0749: ALLPROPS_TYPE_NAME, propertyMap, null, callData);
0750:
0751: container = null;
0752: container2 = null;
0753: container3 = null;
0754: commitTx();
0755: } catch (Throwable t) {
0756: rollbackTx();
0757: throw t;
0758: }
0759:
0760: beginTx(callData);
0761:
0762: ComponentPath categoryPath = dir1.append(categoryName).append(
0763: CategoryManager.CATEGORY_TOKEN).append("folder")
0764: .append(categoryName).append(
0765: CategoryManager.CATEGORY_TOKEN).append("test");
0766:
0767: Map categoryMap = new HashMap(callData.getCategoryMap());
0768: categoryMap.put(categoryName, category.getDefaultValue());
0769: // XXX: this is a hack until we have createCallData() with param
0770: // 'categoryMap' or something. (2002/10/30, rs)
0771: ((AbstractCallDataImpl) callData).setCategoryMap(categoryMap);
0772:
0773: TypeWithAllPropertyTypes comp = (TypeWithAllPropertyTypes) manager
0774: .getComponent(categoryPath, callData);
0775: assertNotNull("Could not find component using path '"
0776: + categoryPath + "'", comp);
0777: assertTrue("Wrong component resolved using path '"
0778: + categoryPath + "'!",
0779: comp.getLongTest() == testDefault);
0780:
0781: categoryMap.put(categoryName, "bbb");
0782:
0783: comp = (TypeWithAllPropertyTypes) manager.getComponent(
0784: categoryPath, callData);
0785: assertNotNull("Could not find component using path '"
0786: + categoryPath + "'", comp);
0787: assertTrue("Wrong component resolved using path '"
0788: + categoryPath + "'!", comp.getLongTest() == testBBB);
0789:
0790: categoryMap.put(categoryName, "ccc");
0791: comp = (TypeWithAllPropertyTypes) manager.getComponent(
0792: categoryPath, callData);
0793: assertNotNull("Could not find component using path '"
0794: + categoryPath + "'", comp);
0795: assertTrue("Wrong component resolved using path '"
0796: + categoryPath + "'!", comp.getLongTest() == testBBB);
0797:
0798: commitTx();
0799: }
0800:
0801: public void testSetContent() throws Throwable {
0802: beginTx(callData);
0803:
0804: Container container = (Container) manager.getComponent(dir1,
0805: callData);
0806: ContentProvider component = (ContentProvider) manager
0807: .createComponent(container, "test",
0808: "contelligent.content.Boolean",
0809: Collections.EMPTY_MAP, null, callData);
0810: ((ContelligentBooleanContent) component.getContent())
0811: .setBooleanValue(false, callData);
0812: manager.updateComponent((Component) component, callData);
0813: commitTx();
0814:
0815: beginTx(callData);
0816: component = (ContentProvider) manager.getComponent(dir1
0817: .append("test"), callData);
0818: assertFalse(((BooleanContent) component.getContent())
0819: .getBooleanValue(callData));
0820: ContentProvider clone = (ContentProvider) manager
0821: .cloneComponent(dir1.append("test"), callData);
0822: ((ContelligentBooleanContent) clone.getContent())
0823: .setBooleanValue(true, callData);
0824: manager.updateComponent((Component) clone, callData);
0825: commitTx();
0826:
0827: beginTx(callData);
0828: component = (ContentProvider) manager.getComponent(dir1
0829: .append("test"), callData);
0830: assertTrue(((BooleanContent) component.getContent())
0831: .getBooleanValue(callData));
0832: commitTx();
0833: }
0834:
0835: public void testBlueprintAddToAll() throws Throwable {
0836: beginTx(callData);
0837: Contelligent contelligent = getContelligent();
0838: String groupId = contelligent
0839: .getProperty("contelligent.pkgs.test.user-groupid");
0840: String userId = contelligent
0841: .getProperty("contelligent.pkgs.test.user-id");
0842: String password = contelligent
0843: .getProperty("contelligent.pkgs.test.user-password");
0844: User testUser = ContelligentSecurityManager.getInstance()
0845: .authenticate(userId, groupId, password);
0846: assertNotNull("Could not find test-user '" + userId
0847: + "' with group-id '" + groupId + "'!", testUser);
0848:
0849: ContelligentPrincipal actualPrincipal = callData
0850: .getContelligentSession().getUser();
0851: Set ownerSet = new HashSet(2);
0852: ownerSet.add(testUser);
0853: ownerSet.add(actualPrincipal);
0854: ComponentPath blueprintPath = dir1.append("Blueprint");
0855: ComponentPath instancePath = dir1.append("Instance");
0856: AccessControlList acl = new AccessControlList(blueprintPath
0857: .toString(), ownerSet);
0858: Map propertyMap = new HashMap();
0859: propertyMap.put("longTest", "99");
0860: Container dir1Container = (Container) manager.getComponent(
0861: dir1, callData);
0862: try {
0863: manager.createComponent(dir1Container, blueprintPath
0864: .getName(), ALLPROPS_TYPE_NAME, propertyMap, acl,
0865: callData);
0866: assertTrue("Component '" + blueprintPath
0867: + "' does not exist after successful creation",
0868: manager.componentExists(blueprintPath));
0869:
0870: TypeWithAllPropertyTypes comp = (TypeWithAllPropertyTypes) manager
0871: .getComponent(blueprintPath, callData);
0872: assertTrue(
0873: "The test property was not set correctly using createComponent",
0874: comp.getLongTest() == 99L);
0875:
0876: acl = ((ComponentContextImpl) comp.getComponentContext())
0877: .getACL();
0878: Set owners = acl.getOwners();
0879: assertTrue("test-user is no owner", owners
0880: .contains(testUser));
0881: assertTrue("actual user (" + actualPrincipal
0882: + ") is no owner", owners.contains(actualPrincipal));
0883:
0884: commitTx();
0885: } catch (Throwable t) {
0886: rollbackTx();
0887: throw t;
0888: }
0889:
0890: // define blueprint
0891: beginTx(callData);
0892: try {
0893: TypeElement typeElement = new TypeElement();
0894: typeElement.setBlueprintPath(blueprintPath.toPath());
0895: typeElement.setName("contelligent.test.ENH544");
0896: typeElement.setRestrictType(ALLPROPS_TYPE_NAME);
0897: typeElement.setGroup("content");
0898: typeElement.setMetainfoElement(new TypeMetainfoElement());
0899: typeElement
0900: .getMetainfoElement()
0901: .setGui(
0902: "de.finix.contelligent.client.gui.composed.FormGUI");
0903: manager.createType(typeElement);
0904: commitTx();
0905: } catch (Throwable t) {
0906: rollbackTx();
0907: throw t;
0908: }
0909:
0910: try {
0911: // create instance
0912: beginTx(callData);
0913: try {
0914: manager.createComponent(dir1Container, instancePath
0915: .getName(), "contelligent.test.ENH544", null,
0916: acl, callData);
0917: assertTrue("Component '" + instancePath
0918: + "' does not exist after successful creation",
0919: manager.componentExists(instancePath));
0920: commitTx();
0921: } catch (Throwable t) {
0922: rollbackTx();
0923: throw t;
0924: }
0925:
0926: // extend blueprint
0927: beginTx(callData);
0928: try {
0929: Container container = (Container) manager.getComponent(
0930: blueprintPath, callData);
0931: manager.createComponent(container, "newPart",
0932: ALLPROPS_TYPE_NAME, null, null, callData);
0933: commitTx();
0934: } catch (Throwable t) {
0935: rollbackTx();
0936: throw t;
0937: }
0938:
0939: // propagate to instances
0940: beginTx(callData);
0941: try {
0942: manager.addToAllBlueprintInstances(blueprintPath
0943: .append("newPart"), callData);
0944: assertTrue("not propagated",
0945: manager.componentExists(instancePath
0946: .append("newPart")));
0947: commitTx();
0948: } catch (Throwable t) {
0949: rollbackTx();
0950: throw t;
0951: }
0952: } finally {
0953: beginTx(callData);
0954: manager.deleteType(callData, "contelligent.test.ENH544",
0955: true, true);
0956: commitTx();
0957: }
0958: }
0959:
0960: public void testBlueprintCleanUp() throws Throwable {
0961: beginTx(callData);
0962: Contelligent contelligent = getContelligent();
0963: String groupId = contelligent
0964: .getProperty("contelligent.pkgs.test.user-groupid");
0965: String userId = contelligent
0966: .getProperty("contelligent.pkgs.test.user-id");
0967: String password = contelligent
0968: .getProperty("contelligent.pkgs.test.user-password");
0969: User testUser = ContelligentSecurityManager.getInstance()
0970: .authenticate(userId, groupId, password);
0971: assertNotNull("Could not find test-user '" + userId
0972: + "' with group-id '" + groupId + "'!", testUser);
0973:
0974: ContelligentPrincipal actualPrincipal = callData
0975: .getContelligentSession().getUser();
0976: Set ownerSet = new HashSet(2);
0977: ownerSet.add(testUser);
0978: ownerSet.add(actualPrincipal);
0979: ComponentPath path = dir1.append("Blueprint");
0980: ComponentPath instancePath = dir1.append("Instance");
0981: AccessControlList acl = new AccessControlList(path.toString(),
0982: ownerSet);
0983: Map propertyMap = new HashMap();
0984: propertyMap.put("longTest", "99");
0985: Container dir1Container = (Container) manager.getComponent(
0986: dir1, callData);
0987: try {
0988: manager.createComponent(dir1Container, path.getName(),
0989: ALLPROPS_TYPE_NAME, propertyMap, acl, callData);
0990: assertTrue("Component '" + path
0991: + "' does not exist after successful creation",
0992: manager.componentExists(path));
0993:
0994: TypeWithAllPropertyTypes comp = (TypeWithAllPropertyTypes) manager
0995: .getComponent(path, callData);
0996: assertTrue(
0997: "The test property was not set correctly using createComponent",
0998: comp.getLongTest() == 99L);
0999:
1000: acl = ((ComponentContextImpl) comp.getComponentContext())
1001: .getACL();
1002: Set owners = acl.getOwners();
1003: assertTrue("test-user is no owner", owners
1004: .contains(testUser));
1005: assertTrue("actual user (" + actualPrincipal
1006: + ") is no owner", owners.contains(actualPrincipal));
1007:
1008: commitTx();
1009: } catch (Throwable t) {
1010: rollbackTx();
1011: throw t;
1012: }
1013:
1014: try {
1015: // define blueprint
1016: beginTx(callData);
1017: try {
1018: TypeElement typeElement = new TypeElement();
1019: typeElement.setBlueprintPath(path.toPath());
1020: typeElement.setName("contelligent.test.ENH544");
1021: typeElement.setRestrictType(ALLPROPS_TYPE_NAME);
1022: typeElement.setGroup("content");
1023: typeElement
1024: .setMetainfoElement(new TypeMetainfoElement());
1025: typeElement
1026: .getMetainfoElement()
1027: .setGui(
1028: "de.finix.contelligent.client.gui.composed.FormGUI");
1029: manager.createType(typeElement);
1030: commitTx();
1031: } catch (Throwable t) {
1032: rollbackTx();
1033: throw t;
1034: }
1035:
1036: // create instance
1037: beginTx(callData);
1038: try {
1039: manager.createComponent(dir1Container, instancePath
1040: .getName(), "contelligent.test.ENH544", null,
1041: null, callData);
1042: assertTrue("Component '" + instancePath
1043: + "' does not exist after successful creation",
1044: manager.componentExists(instancePath));
1045: commitTx();
1046: } catch (Throwable t) {
1047: rollbackTx();
1048: throw t;
1049: }
1050:
1051: // extend instance
1052: beginTx(callData);
1053: try {
1054: Container container = (Container) manager.getComponent(
1055: instancePath, callData);
1056: manager.createComponent(container, "newPart",
1057: ALLPROPS_TYPE_NAME, null, null, callData);
1058: commitTx();
1059: } catch (Throwable t) {
1060: rollbackTx();
1061: throw t;
1062: }
1063:
1064: // clean up instances
1065: beginTx(callData);
1066: try {
1067: manager.cleanUpBlueprintInstances(path, callData);
1068: assertTrue("not clean",
1069: !manager.componentExists(instancePath
1070: .append("newPart")));
1071: commitTx();
1072: } catch (Throwable t) {
1073: rollbackTx();
1074: throw t;
1075: }
1076: } finally {
1077: beginTx(callData);
1078: manager.deleteType(callData, "contelligent.test.ENH544",
1079: true, true);
1080: commitTx();
1081: }
1082: }
1083:
1084: public void testIntraTxDeletionConsistency1() throws Throwable {
1085: // Tests for visibility of a delete within the same transaction
1086: // Should be handled by the CM through the generated delete event
1087:
1088: boolean result = true;
1089:
1090: // Prepare test environment
1091: beginTx(callData);
1092: Container container = (Container) manager.getComponent(
1093: TEST_WORK_DIR, callData);
1094: manager
1095: .copyComponentTree(callData, new ComponentPath(
1096: "/contelligent/test/pages/test"),
1097: TEST_WORK_DIR, "test");
1098: commitTx();
1099:
1100: beginTx(callData);
1101: // Make sure components get cached
1102: manager.getComponent(TEST_WORK_DIR.append(new ComponentPath(
1103: "test")), callData);
1104: manager.getComponent(TEST_WORK_DIR.append(new ComponentPath(
1105: "test/aaa")), callData);
1106: manager.getComponent(TEST_WORK_DIR.append(new ComponentPath(
1107: "test/bbb")), callData);
1108: // Check if deletion is visible
1109: manager.deleteComponentTree(callData, TEST_WORK_DIR
1110: .append("test"));
1111: if (manager.componentExists(TEST_WORK_DIR
1112: .append(new ComponentPath("test/aaa")))) {
1113: // Hmm, it still seems to be there...
1114: result = false;
1115: }
1116: try {
1117: manager.getComponent(TEST_WORK_DIR
1118: .append(new ComponentPath("test/aaa")), callData);
1119: result = false;
1120: } catch (ComponentNotFoundException cne) {
1121: // All OK, this is what we wanted!
1122: }
1123: commitTx();
1124:
1125: assertTrue("Component was still visible after deletion!",
1126: result);
1127:
1128: }
1129:
1130: public void testIntraTxDeletionConsistency2() throws Throwable {
1131: // Like Test 1 but without committing after component creation
1132: // Should be handled by the CM through the deleted flag on the clone
1133:
1134: boolean result = true;
1135:
1136: beginTx(callData);
1137: Container container = (Container) manager.getComponent(
1138: TEST_WORK_DIR, callData);
1139: manager
1140: .copyComponentTree(callData, new ComponentPath(
1141: "/contelligent/test/pages/test"),
1142: TEST_WORK_DIR, "test");
1143:
1144: // Check if deletion is visible
1145: manager.deleteComponentTree(callData, TEST_WORK_DIR
1146: .append("test"));
1147: if (manager.componentExists(TEST_WORK_DIR
1148: .append(new ComponentPath("test/aaa")))) {
1149: // Hmm, it still seems to be there...
1150: result = false;
1151: }
1152: try {
1153: manager.getComponent(TEST_WORK_DIR
1154: .append(new ComponentPath("test/aaa")), callData);
1155: result = false;
1156: } catch (ComponentNotFoundException cne) {
1157: // All OK, this is what we wanted!
1158: }
1159: commitTx();
1160:
1161: assertTrue("Component was still visible after deletion!",
1162: result);
1163:
1164: }
1165:
1166: }
|