Return-Path: X-Original-To: apmail-chemistry-commits-archive@www.apache.org Delivered-To: apmail-chemistry-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 914F192BC for ; Tue, 3 Apr 2012 05:16:00 +0000 (UTC) Received: (qmail 34918 invoked by uid 500); 3 Apr 2012 05:16:00 -0000 Delivered-To: apmail-chemistry-commits-archive@chemistry.apache.org Received: (qmail 34876 invoked by uid 500); 3 Apr 2012 05:16:00 -0000 Mailing-List: contact commits-help@chemistry.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@chemistry.apache.org Delivered-To: mailing list commits@chemistry.apache.org Received: (qmail 34854 invoked by uid 99); 3 Apr 2012 05:15:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Apr 2012 05:15:59 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Apr 2012 05:15:47 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id DDDAF2388BFF; Tue, 3 Apr 2012 05:15:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1308692 [7/42] - in /chemistry/site/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory: ./ css/ images/ images/logos/ xref-test/ xref-test/org/ xref-test/org/apache/ xref-test/org/apache/chemistry/ ... Date: Tue, 03 Apr 2012 05:14:54 -0000 To: commits@chemistry.apache.org From: gabriele@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120403051501.DDDAF2388BFF@eris.apache.org> Added: chemistry/site/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref-test/org/apache/chemistry/opencmis/inmemory/DiscoveryServiceTest.html URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref-test/org/apache/chemistry/opencmis/inmemory/DiscoveryServiceTest.html?rev=1308692&view=auto ============================================================================== --- chemistry/site/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref-test/org/apache/chemistry/opencmis/inmemory/DiscoveryServiceTest.html (added) +++ chemistry/site/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref-test/org/apache/chemistry/opencmis/inmemory/DiscoveryServiceTest.html Tue Apr 3 05:14:48 2012 @@ -0,0 +1,179 @@ + + + + +DiscoveryServiceTest xref + + + +
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one
+3    * or more contributor license agreements.  See the NOTICE file
+4    * distributed with this work for additional information
+5    * regarding copyright ownership.  The ASF licenses this file
+6    * to you under the Apache License, Version 2.0 (the
+7    * "License"); you may not use this file except in compliance
+8    * with the License.  You may obtain a copy of the License at
+9    *
+10   * http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   * Unless required by applicable law or agreed to in writing,
+13   * software distributed under the License is distributed on an
+14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   * KIND, either express or implied.  See the License for the
+16   * specific language governing permissions and limitations
+17   * under the License.
+18   */
+19  package org.apache.chemistry.opencmis.inmemory;
+20  
+21  import static org.junit.Assert.assertEquals;
+22  
+23  import java.math.BigInteger;
+24  import java.util.ArrayList;
+25  import java.util.List;
+26  
+27  import org.apache.chemistry.opencmis.commons.data.ObjectList;
+28  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
+29  import org.apache.chemistry.opencmis.inmemory.ObjectServiceTest.ObjectTestTypeSystemCreator;
+30  import org.apache.chemistry.opencmis.util.repository.ObjectGenerator;
+31  import org.apache.commons.logging.Log;
+32  import org.apache.commons.logging.LogFactory;
+33  import org.junit.Before;
+34  import org.junit.Test;
+35  
+36  public class DiscoveryServiceTest extends AbstractServiceTest {
+37  
+38      private static final Log log = LogFactory.getLog(DiscoveryServiceTest.class);
+39      private static final String TEST_FOLDER_TYPE_ID = ObjectServiceTest.TEST_FOLDER_TYPE_ID;
+40      private static final String TEST_DOCUMENT_TYPE_ID = ObjectServiceTest.TEST_DOCUMENT_TYPE_ID;
+41      private static final String TEST_FOLDER_STRING_PROP_ID = ObjectServiceTest.TEST_FOLDER_STRING_PROP_ID;
+42      private static final String TEST_DOCUMENT_STRING_PROP_ID = ObjectServiceTest.TEST_DOCUMENT_STRING_PROP_ID;
+43  
+44      @Override
+45      @Before
+46      public void setUp() {
+47          super.setTypeCreatorClass(ObjectTestTypeSystemCreator.class.getName());
+48          super.setUp();
+49      }
+50  
+51      @Test
+52      public void testQuery() {
+53          log.info("starting testQuery() ...");
+54  
+55          ObjectGenerator gen = new ObjectGenerator(fFactory, fNavSvc, fObjSvc, fRepSvc, fRepositoryId, 
+56                  ObjectGenerator.CONTENT_KIND.LoremIpsumText);
+57          gen.setNumberOfDocumentsToCreatePerFolder(3);
+58          gen.setDocumentTypeId(TEST_DOCUMENT_TYPE_ID);
+59          gen.setFolderTypeId(TEST_FOLDER_TYPE_ID);
+60  
+61          List<String> propsToSet = new ArrayList<String>();
+62          propsToSet.add(TEST_DOCUMENT_STRING_PROP_ID);
+63          gen.setDocumentPropertiesToGenerate(propsToSet);
+64  
+65          propsToSet = new ArrayList<String>();
+66          propsToSet.add(TEST_FOLDER_STRING_PROP_ID);
+67          gen.setFolderPropertiesToGenerate(propsToSet);
+68  
+69          gen.createFolderHierachy(2, 2, fRootFolderId);
+70  
+71          Boolean searchAllVersions = Boolean.FALSE;
+72          Boolean includeAllowableActions = Boolean.FALSE;
+73          IncludeRelationships includeRelationships = IncludeRelationships.NONE;
+74          String renditionFilter = null;
+75          BigInteger maxItems = null;
+76          BigInteger skipCount = null;
+77  
+78          String statement = "SELECT * FROM " + TEST_DOCUMENT_TYPE_ID + " WHERE " + TEST_DOCUMENT_STRING_PROP_ID + "='My Doc StringProperty 1'";
+79          ObjectList res = fDiscSvc.query(fRepositoryId, statement, searchAllVersions, includeAllowableActions,
+80                  includeRelationships, renditionFilter, maxItems, skipCount, null);
+81          assertEquals(1, res.getObjects().size());
+82  
+83          statement = "SELECT " + TEST_DOCUMENT_STRING_PROP_ID + " FROM " + TEST_DOCUMENT_TYPE_ID + " WHERE " + TEST_DOCUMENT_STRING_PROP_ID + "='My Doc StringProperty 1'";
+84          res = fDiscSvc.query(fRepositoryId, statement, searchAllVersions, includeAllowableActions,
+85                  includeRelationships, renditionFilter, maxItems, skipCount, null);
+86          assertEquals(1, res.getObjects().size());
+87          assertEquals(1, res.getObjects().get(0).getProperties().getProperties().size()); // only one property should be delivered
+88  
+89          statement = "SELECT * FROM cmis:folder";
+90          res = fDiscSvc.query(fRepositoryId, statement, searchAllVersions, includeAllowableActions,
+91                  includeRelationships, renditionFilter, maxItems, skipCount, null);
+92          // root + 2 at level 1 + 2*2 at level 2 = 7
+93          assertEquals(7, res.getObjects().size());
+94  
+95  
+96          /*
+97          assertEquals(BigInteger.valueOf(9), res.getNumItems());
+98  
+99          statement = "SELECT * FROM cmis:folder";
+100         res = fDiscSvc.query(fRepositoryId, statement, searchAllVersions, includeAllowableActions,
+101                 includeRelationships, renditionFilter, maxItems, skipCount, null);
+102         // root + 2 at level 1 + 2*2 at level 2 = 7
+103         assertEquals(BigInteger.valueOf(7), res.getNumItems());
+104 
+105         statement = "SELECT * FROM cmis:folder";
+106         res = fDiscSvc.query(fRepositoryId, statement, searchAllVersions, includeAllowableActions,
+107                 includeRelationships, renditionFilter, maxItems, skipCount, null);
+108         // root + 2 at level 1 + 2*2 at level 2 = 7
+109         assertEquals(BigInteger.valueOf(7), res.getNumItems());
+110 
+111         statement = "SELECT * FROM cmis:folder WHERE name='Jens'";
+112         res = fDiscSvc.query(fRepositoryId, statement, searchAllVersions, includeAllowableActions,
+113                 includeRelationships, renditionFilter, maxItems, skipCount, null);
+114         assertEquals(BigInteger.valueOf(0), res.getNumItems());
+115 */
+116         log.info("... testQuery() finished.");
+117     }
+118 
+119     @Test
+120     public void testQueryPaging() {
+121         log.info("starting testQuery() ...");
+122 
+123         String statement;
+124         ObjectList res;
+125         ObjectGenerator gen = new ObjectGenerator(fFactory, fNavSvc, fObjSvc, fRepSvc, fRepositoryId,
+126                 ObjectGenerator.CONTENT_KIND.LoremIpsumText);
+127         gen.setNumberOfDocumentsToCreatePerFolder(3);
+128         gen.setDocumentTypeId(TEST_DOCUMENT_TYPE_ID);
+129         gen.setFolderTypeId(TEST_FOLDER_TYPE_ID);
+130 
+131         List<String> propsToSet = new ArrayList<String>();
+132         propsToSet.add(TEST_DOCUMENT_STRING_PROP_ID);
+133         gen.setDocumentPropertiesToGenerate(propsToSet);
+134 
+135         propsToSet = new ArrayList<String>();
+136         propsToSet.add(TEST_FOLDER_STRING_PROP_ID);
+137         gen.setFolderPropertiesToGenerate(propsToSet);
+138 
+139         gen.createFolderHierachy(2, 2, fRootFolderId);
+140 
+141         Boolean searchAllVersions = Boolean.FALSE;
+142         Boolean includeAllowableActions = Boolean.FALSE;
+143         IncludeRelationships includeRelationships = IncludeRelationships.NONE;
+144         String renditionFilter = null;
+145         BigInteger skipCount = BigInteger.valueOf(0);
+146         BigInteger maxItems = BigInteger.valueOf(3);
+147 
+148         int count = 0;
+149         boolean hasMoreItems = true;
+150         statement = "SELECT * FROM cmis:document";
+151         while (hasMoreItems) {
+152             res = fDiscSvc.query(fRepositoryId, statement, searchAllVersions, includeAllowableActions,
+153                     includeRelationships, renditionFilter, maxItems, skipCount, null);
+154             hasMoreItems = res.hasMoreItems();
+155             assertEquals(3, res.getObjects().size());
+156             if (res.getNumItems() != null) {
+157                 assertEquals(9L, res.getNumItems().longValue());
+158             }
+159             skipCount = skipCount.add(maxItems);
+160             ++count;
+161         }
+162         assertEquals(3, count);
+163     }
+164 
+165 }
+
+
+ + Added: chemistry/site/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref-test/org/apache/chemistry/opencmis/inmemory/FolderTest.html URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref-test/org/apache/chemistry/opencmis/inmemory/FolderTest.html?rev=1308692&view=auto ============================================================================== --- chemistry/site/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref-test/org/apache/chemistry/opencmis/inmemory/FolderTest.html (added) +++ chemistry/site/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref-test/org/apache/chemistry/opencmis/inmemory/FolderTest.html Tue Apr 3 05:14:48 2012 @@ -0,0 +1,203 @@ + + + + +FolderTest xref + + + +
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one
+3    * or more contributor license agreements.  See the NOTICE file
+4    * distributed with this work for additional information
+5    * regarding copyright ownership.  The ASF licenses this file
+6    * to you under the Apache License, Version 2.0 (the
+7    * "License"); you may not use this file except in compliance
+8    * with the License.  You may obtain a copy of the License at
+9    *
+10   * http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   * Unless required by applicable law or agreed to in writing,
+13   * software distributed under the License is distributed on an
+14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   * KIND, either express or implied.  See the License for the
+16   * specific language governing permissions and limitations
+17   * under the License.
+18   */
+19  package org.apache.chemistry.opencmis.inmemory;
+20  
+21  import java.util.List;
+22  
+23  import junit.framework.TestCase;
+24  
+25  import org.apache.chemistry.opencmis.inmemory.storedobj.api.Filing;
+26  import org.apache.chemistry.opencmis.inmemory.storedobj.api.Folder;
+27  import org.apache.chemistry.opencmis.inmemory.storedobj.api.ObjectStore;
+28  import org.apache.chemistry.opencmis.inmemory.storedobj.api.StoredObject;
+29  import org.apache.chemistry.opencmis.inmemory.storedobj.impl.FolderImpl;
+30  import org.apache.chemistry.opencmis.inmemory.storedobj.impl.ObjectStoreImpl;
+31  import org.junit.Before;
+32  import org.junit.Test;
+33  
+34  /**
+35   * @author <a href="mailto:fmueller@opentext.com">Florian M&uuml;ller</a>
+36   * @author Jens
+37   */
+38  
+39  /**
+40   * Some test directly against the in-memory folder object.
+41   */
+42  public class FolderTest extends TestCase {
+43  
+44      private ObjectStore fStore;
+45      private FolderImpl fRoot;
+46      private FolderImpl f1;
+47      private FolderImpl f2;
+48      private FolderImpl f3;
+49      private FolderImpl f4;
+50      private FolderImpl f11;
+51      private static final String TEST_REPOSITORY_ID = "TestRepositoryId";
+52      private static final String USER = "user";
+53  
+54      @Before
+55      protected void setUp() throws Exception {
+56          fStore = new ObjectStoreImpl(TEST_REPOSITORY_ID);
+57          createFolders();
+58      }
+59  
+60      @Test
+61      public void testCreatAndGetFolders() {
+62          try {
+63              Folder childFolder = createFolder("Folder 1");
+64              fRoot.addChildFolder(childFolder);
+65              fail("Should throw exception if folder already exists.");
+66          } catch (Exception e) {
+67          }
+68          assertEquals(f1.getName(), "Folder 1");
+69          assertEquals(f11.getName(), "Folder 1.1");
+70          assertNull(fRoot.getParent());
+71          assertEquals(fRoot, f1.getParent());
+72          assertEquals(f1, f11.getParent());
+73          assertEquals(Filing.PATH_SEPARATOR, fRoot.getPath());
+74          assertEquals("/Folder 1", f1.getPath());
+75          assertEquals("/Folder 1/Folder 1.1", f11.getPath());
+76          StoredObject fTest = fStore.getObjectByPath("/", USER);
+77          assertEquals(fRoot, fTest);
+78          fTest = fStore.getObjectByPath("/Folder 1", USER);
+79          assertEquals(f1, fTest);
+80          fTest = fStore.getObjectByPath("/Folder 1/Folder 1.1", USER);
+81          assertEquals(f11, fTest);
+82          List<StoredObject> subFolders = fRoot.getChildren(-1, -1, "user");
+83          assertEquals(4, subFolders.size());
+84          subFolders = f2.getChildren(-1, -1, "user");
+85          assertEquals(0, subFolders.size());
+86          subFolders = f1.getChildren(-1, -1, "user");
+87          assertEquals(1, subFolders.size());
+88      }
+89  
+90      @Test
+91      public void testRenameFolder() {
+92          // rename top level folder
+93          String newName = "Folder B";
+94          String oldPath = f2.getPath();
+95          f2.rename(newName);
+96          assertEquals(f2.getName(), newName);
+97          assertEquals(f2.getPath(), Filing.PATH_SEPARATOR + newName);
+98          assertNull(fStore.getObjectByPath(oldPath, USER));
+99          assertEquals(f2, fStore.getObjectByPath(Filing.PATH_SEPARATOR + newName, USER));
+100         try {
+101             f2.rename("Folder 3");
+102             fail("Should not allow to rename a folder to an existing name");
+103         } catch (Exception e) {
+104         }
+105 
+106         // rename sub folder
+107         oldPath = f11.getPath();
+108         f11.rename(newName);
+109         assertEquals(f11.getName(), newName);
+110         assertEquals(f11.getPath(), "/Folder 1/Folder B");
+111         assertNull(fStore.getObjectByPath(oldPath, USER));
+112         assertEquals(f11, fStore.getObjectByPath("/Folder 1/Folder B", USER));
+113         try {
+114             f2.rename(newName);
+115             fail("Should not allow to rename a folder to an existing name");
+116         } catch (Exception e) {
+117         }
+118         try {
+119             f2.rename("illegal/name");
+120             fail("Should not allow to rename a folder to a name with illegal name");
+121         } catch (Exception e) {
+122         }
+123 
+124         // rename root folder
+125         try {
+126             fRoot.rename("abc");
+127             fail("Should not be possible to rename root folder");
+128         } catch (Exception e) {
+129         }
+130     }
+131 
+132     @Test
+133     public void testMoveFolder() {
+134         String oldPath = f1.getPath();
+135         Folder f1Parent = f1.getParent();
+136         f1.move(f1Parent, f3);
+137         assertNull(fStore.getObjectByPath(oldPath, USER));
+138         assertEquals(f1.getPath(), "/Folder 3/Folder 1");
+139         assertEquals(f1, fStore.getObjectByPath("/Folder 3/Folder 1", USER));
+140 
+141         f2.rename("Folder 1");
+142         try {
+143             Folder f2Parent = f2.getParent();
+144             f2.move(f2Parent, f3);
+145             fail("Should not be possible to move folder to a folder that has a child with same name");
+146         } catch (Exception e) {
+147         }
+148     }
+149 
+150     @Test
+151     public void testDeleteFolder() {
+152         String oldPath = f2.getPath();
+153         fStore.deleteObject(f2.getId(), true, "TestUser");
+154         assertNull(fStore.getObjectByPath(oldPath, USER));
+155 
+156         try {
+157             fStore.deleteObject(f1.getId(), true, "TestUser");
+158             fail("Should not be possible to move folder that has children");
+159         } catch (Exception e) {
+160         }
+161     }
+162 
+163     private void createFolders() {
+164         fRoot = (FolderImpl) fStore.getRootFolder();
+165         f1 = (FolderImpl) createFolder("Folder 1");
+166         fRoot.addChildFolder(f1);
+167         f1.persist();
+168 
+169         f2 = (FolderImpl) createFolder("Folder 2");
+170         fRoot.addChildFolder(f2);
+171         f2.persist();
+172 
+173         f3 = (FolderImpl) createFolder("Folder 3");
+174         fRoot.addChildFolder(f3);
+175         f3.persist();
+176 
+177         f4 = (FolderImpl) createFolder("Folder 4");
+178         fRoot.addChildFolder(f4);
+179         f4.persist();
+180 
+181         f11 = (FolderImpl) createFolder("Folder 1.1");
+182         f1.addChildFolder(f11);
+183         f11.persist();
+184     }
+185     
+186     private Folder createFolder(String name) {
+187     	return fStore.createFolder(name, null, "user", null, null, null);    	
+188     }
+189 }
+
+
+ + Added: chemistry/site/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref-test/org/apache/chemistry/opencmis/inmemory/MultiFilingTest.html URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref-test/org/apache/chemistry/opencmis/inmemory/MultiFilingTest.html?rev=1308692&view=auto ============================================================================== --- chemistry/site/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref-test/org/apache/chemistry/opencmis/inmemory/MultiFilingTest.html (added) +++ chemistry/site/trunk/content/java/0.7.0/maven/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/xref-test/org/apache/chemistry/opencmis/inmemory/MultiFilingTest.html Tue Apr 3 05:14:48 2012 @@ -0,0 +1,314 @@ + + + + +MultiFilingTest xref + + + +
+
+1   /*
+2    * Licensed to the Apache Software Foundation (ASF) under one
+3    * or more contributor license agreements.  See the NOTICE file
+4    * distributed with this work for additional information
+5    * regarding copyright ownership.  The ASF licenses this file
+6    * to you under the Apache License, Version 2.0 (the
+7    * "License"); you may not use this file except in compliance
+8    * with the License.  You may obtain a copy of the License at
+9    *
+10   * http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   * Unless required by applicable law or agreed to in writing,
+13   * software distributed under the License is distributed on an
+14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   * KIND, either express or implied.  See the License for the
+16   * specific language governing permissions and limitations
+17   * under the License.
+18   */
+19  package org.apache.chemistry.opencmis.inmemory;
+20  
+21  import static org.junit.Assert.assertEquals;
+22  import static org.junit.Assert.assertFalse;
+23  import static org.junit.Assert.assertNotNull;
+24  import static org.junit.Assert.assertTrue;
+25  import static org.junit.Assert.fail;
+26  
+27  import java.util.ArrayList;
+28  import java.util.List;
+29  import java.util.Map;
+30  
+31  import org.apache.chemistry.opencmis.commons.PropertyIds;
+32  import org.apache.chemistry.opencmis.commons.data.ObjectData;
+33  import org.apache.chemistry.opencmis.commons.data.ObjectParentData;
+34  import org.apache.chemistry.opencmis.commons.data.Properties;
+35  import org.apache.chemistry.opencmis.commons.data.PropertyData;
+36  import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
+37  import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
+38  import org.apache.chemistry.opencmis.commons.enums.VersioningState;
+39  import org.apache.chemistry.opencmis.commons.exceptions.CmisNameConstraintViolationException;
+40  import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
+41  import org.apache.chemistry.opencmis.commons.server.CallContext;
+42  import org.apache.chemistry.opencmis.commons.spi.Holder;
+43  import org.apache.chemistry.opencmis.inmemory.types.InMemoryFolderTypeDefinition;
+44  import org.apache.commons.logging.Log;
+45  import org.apache.commons.logging.LogFactory;
+46  import org.junit.After;
+47  import org.junit.Before;
+48  import org.junit.Test;
+49  
+50  public class MultiFilingTest extends AbstractServiceTest {
+51  
+52      private static final Log LOG = LogFactory.getLog(MultiFilingTest.class);
+53      private static final String DOCUMENT_TYPE_ID = UnitTestTypeSystemCreator.COMPLEX_TYPE;
+54      private static final String FOLDER_TYPE_ID = InMemoryFolderTypeDefinition.getRootFolderType().getId();
+55      private static final String UNFILED_DOC_NAME = "Unfiled document";
+56      private static final String RENAMED_DOC_NAME = "My Renamed Document";
+57  
+58      private String fId1;
+59      private String fId2;
+60      private String fId11;
+61  
+62      @Override
+63      @Before
+64      public void setUp() {
+65          super.setUp();
+66      }
+67  
+68      @Override
+69      @After
+70      public void tearDown() {
+71          super.tearDown();
+72      }
+73  
+74      @Test
+75      public void testCreateUnfiledDocument() {
+76          LOG.debug("Begin testCreatUnfiledDocument()");
+77          String docId = createUnfiledDocument();
+78          String docId2 = getDocument(docId);
+79          assertEquals(docId, docId2);
+80  
+81          // get object parents, must be empty
+82          List<ObjectParentData> res = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
+83                  IncludeRelationships.NONE, null, true, null);
+84  
+85          assertNotNull(res);
+86          assertEquals(res.size(), 0);
+87          
+88          // test with a different user than Admin:
+89          switchCallContext("Alice");
+90          docId = createDocument(UNFILED_DOC_NAME + "_2", null, DOCUMENT_TYPE_ID, true);
+91          docId2 = getDocument(docId);
+92          assertEquals(docId, docId2);
+93  
+94          LOG.debug("End testCreatUnfiledDocument()");
+95      }
+96  
+97      @Test
+98      public void testMakeFiledDocumentUnfiled() {
+99          LOG.debug("Begin testMakeFiledDocumentUnfiled()");
+100 
+101         String docId = createDocument("Filed document", fRootFolderId, DOCUMENT_TYPE_ID, true);
+102 
+103         fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fRootFolderId, null);
+104         List<ObjectParentData> parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
+105                 IncludeRelationships.NONE, null, true, null);
+106         assertEquals(0, parents.size());
+107 
+108         LOG.debug("End testMakeFiledDocumentUnfiled()");
+109     }
+110 
+111     @Test
+112     public void testAddDocumentToFolder() {
+113         LOG.debug("Begin testAddDocumentToFolder()");
+114         String docId = createUnfiledDocument();
+115         addDocumentToFolder(docId);
+116         LOG.debug("End testAddDocumentToFolder()");
+117     }
+118 
+119     @Test
+120     public void testRemoveDocumentFromFolder() {
+121         LOG.debug("Begin testRemoveDocumentFromFolder()");
+122 
+123         String docId = createUnfiledDocument();
+124         removeDocumentFromFolder(docId);
+125         LOG.debug("End testRemoveDocumentFromFolder()");
+126     }
+127 
+128     @Test
+129     public void testMoveMultiFiledDocument() {
+130         LOG.debug("begin testMoveMultiFiledDocument()");
+131         String docId = createUnfiledDocument();
+132         prepareMultiFiledDocument(docId);
+133         String newFolderId = createFolder("folder2.1", fId2, FOLDER_TYPE_ID);
+134 
+135         Holder<String> idHolder = new Holder<String>(docId);
+136         fObjSvc.moveObject(fRepositoryId, idHolder, newFolderId, fId11, null);
+137         List<ObjectParentData> parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
+138                 IncludeRelationships.NONE, null, true, null);
+139         assertEquals(3, parents.size());
+140         boolean foundNewParent = false;
+141         boolean foundOldParent = false;
+142         for (ObjectParentData parentData : parents) {
+143             if (parentData.getObject().getId().equals(newFolderId)) {
+144                 foundNewParent = true;
+145             }
+146             if (parentData.getObject().getId().equals(fId11)) {
+147                 foundOldParent = true;
+148             }
+149         }
+150         assertTrue("After move new target should be a parent", foundNewParent);
+151         assertFalse("After move old source should no longer be a parent", foundOldParent);
+152         LOG.debug("End testMoveMultiFiledDocument()");
+153     }
+154 
+155     @Test
+156     public void testRenameMultiFiledDocument() {
+157         LOG.debug("begin testRenameMultiFiledDocument()");
+158         String docId = createUnfiledDocument();
+159         prepareMultiFiledDocument(docId);
+160         renameDocumentAndCheckResult(docId);
+161         LOG.debug("End testRenameMultiFiledDocument()");
+162     }
+163 
+164     @Test
+165     public void testRenameMultiFiledDocumentWithNameConflict() {
+166         LOG.debug("begin testRenameMultiFiledDocument()");
+167         String docId = createUnfiledDocument();
+168         prepareMultiFiledDocument(docId);
+169         // create a document with the new name in one of the folders
+170         createDocument(RENAMED_DOC_NAME, fId11, DOCUMENT_TYPE_ID, true);
+171         // try to rename which should fail now
+172         try {
+173             renameDocumentAndCheckResult(docId);
+174             fail("A rename to an existing name in one of the filed folders should fail");
+175         } catch (Exception e) {
+176             assertTrue(e instanceof CmisNameConstraintViolationException);
+177         }
+178         LOG.debug("End testRenameMultiFiledDocument()");
+179     }
+180 
+181     @Test
+182     public void testAddVersionedDocumentToFolder() {
+183         LOG.debug("Begin testAddVersionedDocumentToFolder()");
+184         String docId = createVersionedDocument();
+185         addDocumentToFolder(docId);
+186         LOG.debug("End testAddVersionedDocumentToFolder()");
+187     }
+188 
+189     @Test
+190     public void testRemoveVersionedDocumentFromFolder() {
+191         LOG.debug("Begin testRemoveVersionedDocumentFromFolder()");
+192 
+193         String docId = createVersionedDocument();
+194         removeDocumentFromFolder(docId);
+195         LOG.debug("End testRemoveVersionedDocumentFromFolder()");
+196     }
+197 
+198     private void createFolders() {
+199         fId1 = createFolder("folder1", fRootFolderId, FOLDER_TYPE_ID);
+200         fId2 = createFolder("folder2", fRootFolderId, FOLDER_TYPE_ID);
+201         fId11 = createFolder("folder1.1", fId1, FOLDER_TYPE_ID);
+202     }
+203 
+204     private void addDocumentToFolder(String docId) {
+205 
+206         List<String> folderIds = prepareMultiFiledDocument(docId);
+207 
+208         // get object parents, must contain all folders
+209         List<ObjectParentData> res = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
+210                 IncludeRelationships.NONE, null, true, null);
+211         assertEquals(3, res.size());
+212         for (ObjectParentData opd : res) {
+213             assertTrue(folderIds.contains(opd.getObject().getId()));
+214             assertEquals(BaseTypeId.CMIS_FOLDER, opd.getObject().getBaseTypeId());
+215             assertEquals(UNFILED_DOC_NAME, opd.getRelativePathSegment());
+216         }
+217 
+218         // try version specific filing, should fail
+219         try {
+220             fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId1, false, null);
+221             fail("Adding not all versions to a folder should fail.");
+222         } catch (Exception e) {
+223             assertTrue(e instanceof CmisNotSupportedException);
+224         }
+225     }
+226 
+227     private void removeDocumentFromFolder(String docId) {
+228         prepareMultiFiledDocument(docId);
+229 
+230         fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fId1, null);
+231         List<ObjectParentData> parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false,
+232                 IncludeRelationships.NONE, null, true, null);
+233         assertEquals(2, parents.size());
+234         for (ObjectParentData opd : parents) {
+235             assertFalse(fId1.equals(opd.getObject().getId()));
+236         }
+237 
+238         fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fId2, null);
+239         parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false, IncludeRelationships.NONE, null, true,
+240                 null);
+241         assertEquals(1, parents.size());
+242         for (ObjectParentData opd : parents) {
+243             assertFalse(fId1.equals(opd.getObject().getId()));
+244         }
+245 
+246         fMultiSvc.removeObjectFromFolder(fRepositoryId, docId, fId11, null);
+247         parents = fNavSvc.getObjectParents(fRepositoryId, docId, "*", false, IncludeRelationships.NONE, null, true,
+248                 null);
+249         assertEquals(0, parents.size());
+250     }
+251 
+252     private String createUnfiledDocument() {
+253         return createDocument(UNFILED_DOC_NAME, null, DOCUMENT_TYPE_ID, true);
+254     }
+255 
+256     private List<String> prepareMultiFiledDocument(String docId) {
+257         createFolders();
+258 
+259         // add the document to three folders
+260         fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId1, true, null);
+261         fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId2, true, null);
+262         fMultiSvc.addObjectToFolder(fRepositoryId, docId, fId11, true, null);
+263 
+264         List<String> folderIds = new ArrayList<String>();
+265         folderIds.add(fId1);
+266         folderIds.add(fId2);
+267         folderIds.add(fId11);
+268 
+269         return folderIds;
+270     }
+271 
+272     private void renameDocumentAndCheckResult(String docId) {
+273         Holder<String> idHolder = new Holder<String>(docId);
+274         List<PropertyData<?>> properties = new ArrayList<PropertyData<?>>();
+275         properties.add(fFactory.createPropertyIdData(PropertyIds.NAME, RENAMED_DOC_NAME));
+276         Properties newProps = fFactory.createPropertiesData(properties);
+277         Holder<String> changeTokenHolder = new Holder<String>();
+278         fObjSvc.updateProperties(fRepositoryId, idHolder, changeTokenHolder, newProps, null);
+279         docId = idHolder.getValue();
+280         ObjectData res = fObjSvc.getObject(fRepositoryId, docId, "*", false, IncludeRelationships.NONE, null, false,
+281                 false, null);
+282         assertNotNull(res);
+283         Map<String, PropertyData<?>> propMap = res.getProperties().getProperties();
+284         PropertyData<?> pd = propMap.get(PropertyIds.NAME);
+285         assertNotNull(pd);
+286         assertEquals(RENAMED_DOC_NAME, pd.getFirstValue());
+287     }
+288 
+289     private String createVersionedDocument() {
+290 
+291         return createDocument(UNFILED_DOC_NAME, null, UnitTestTypeSystemCreator.VERSIONED_TYPE,
+292                 VersioningState.MAJOR, true);
+293 
+294     }
+295 
+296     private void switchCallContext(String user) {
+297         ((DummyCallContext) fTestCallContext).put(CallContext.USERNAME, user);
+298     }
+299 
+300 }
+
+
+ +