mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
75551: Reverse Merge HEAD-BUG-FIX (5.0/Cloud) 74584: Reverse merged HEAD-BUG-FIX (5.0/Cloud) << Requires more work on the EOL branch >> 74416: Merged EOL to HEAD-BUG-FIX (5.0/Cloud) 74309: ACE-2010 EOL Legacy CMIS Inputs (2) in 5.0 - Start replacing references to the original CMIS code with Alfresco and chemistry Open CMIS classes 74342: ACE-2010 EOL Legacy CMIS Inputs (2) in 5.0 - Switch ServiceRegistry over to using Open CMIS classes 74406: ACE-2010 EOL Legacy CMIS Inputs (2) in 5.0 << Compiles and starts Share without error >> - Removed Original CMIS classes from the repository, remote-api and thor - Moved the CMIS.DictionaryBootstrap bean into opencmis-context.xml before removing cmis-api-context.xml - Some code was left under: root\projects\remote-api\source\java\org\alfresco\repo\cmis ...........................................................\client ...........................................................\ws ...........................................................\rest ................................test-java\org\alfresco\repo\cmis ................................................................\ws ................................................................\rest Will have to see if it should be be removed too, or if it is common with OpenCMIS 74407: ACE-2010 EOL Legally CMIS Inputs (2) in 5.0 - Removed left over code under: root\projects\remote-api\source\java\org\alfresco\repo\cmis ................................test-java\org\alfresco\repo\cmis - Removed an authentication URL test in QuickShareRestApiTest which was failing in the same way as the tests above. - Removed CXFAuthenticationSystemTest which appears to be using the original CMIS 74465: Merged EOL (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 74464: ACE-2010 EOL Legacey CMIS Inputs (2) in 5.0 - New failure in QuickShareRestApiTest - CXFAuthenticationSystemTest (deleted) was still referenced in MiscSystemTestSuite git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@77489 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -45,29 +45,17 @@ public class RemoteApi01TestSuite extends TestSuite
|
||||
}
|
||||
|
||||
static void tests1(TestSuite suite)
|
||||
{
|
||||
suite.addTestSuite(org.alfresco.cmis.changelog.CMISChangeLogServiceTest.class);
|
||||
suite.addTestSuite(org.alfresco.repo.cmis.rest.test.AspectTest.class);
|
||||
suite.addTestSuite(org.alfresco.repo.cmis.rest.test.CMISAtomTemplatesTest.class);
|
||||
}
|
||||
|
||||
static void tests2(TestSuite suite) //
|
||||
{
|
||||
suite.addTestSuite(org.alfresco.repo.cmis.rest.test.PolicyTest.class);
|
||||
}
|
||||
|
||||
static void tests3(TestSuite suite) //
|
||||
{
|
||||
suite.addTestSuite(org.alfresco.repo.management.subsystems.test.SubsystemsTest.class);
|
||||
suite.addTestSuite(org.alfresco.repo.remoteticket.RemoteAlfrescoTicketServiceTest.class);
|
||||
}
|
||||
|
||||
static void tests4(TestSuite suite) //
|
||||
static void tests2(TestSuite suite) //
|
||||
{
|
||||
suite.addTest(org.alfresco.repo.web.scripts.WebScriptTestSuite.suite());
|
||||
}
|
||||
|
||||
static void tests5(TestSuite suite) //
|
||||
static void tests3(TestSuite suite) //
|
||||
{
|
||||
suite.addTestSuite(org.alfresco.repo.webdav.GetMethodRegressionTest.class);
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.webdav.MoveMethodTest.class));
|
||||
@@ -77,25 +65,25 @@ public class RemoteApi01TestSuite extends TestSuite
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.webdav.WebDAVMethodTest.class));
|
||||
}
|
||||
|
||||
static void tests6(TestSuite suite) //
|
||||
static void tests4(TestSuite suite) //
|
||||
{
|
||||
// TestNodeComments.testNodeComments() fails 50% of the time we with previous tests
|
||||
// TestCMIS.testCMIS() fails 30% of the time with previous tests
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.rest.api.tests.ApiTest.class));
|
||||
}
|
||||
|
||||
static void tests7(TestSuite suite) //
|
||||
static void tests5(TestSuite suite) //
|
||||
{
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.rest.api.tests.TestCMISAPI.class)); // Fails with previous or following tests
|
||||
}
|
||||
|
||||
static void tests8(TestSuite suite) //
|
||||
static void tests6(TestSuite suite) //
|
||||
{
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.rest.workflow.api.tests.DeploymentWorkflowApiTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.rest.workflow.api.tests.ProcessDefinitionWorkflowApiTest.class));
|
||||
}
|
||||
|
||||
static void tests9(TestSuite suite) //
|
||||
static void tests7(TestSuite suite) //
|
||||
{
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.rest.workflow.api.tests.ProcessWorkflowApiTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.rest.workflow.api.tests.TaskWorkflowApiTest.class));
|
||||
|
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* See {@link RemoteApi01TestSuite}
|
||||
*
|
||||
* @Author Alan Davis
|
||||
*/
|
||||
public class RemoteApi08TestSuite extends TestSuite
|
||||
{
|
||||
public static Test suite()
|
||||
{
|
||||
TestSuite suite = new TestSuite();
|
||||
RemoteApi01TestSuite.tests8(suite);
|
||||
return suite;
|
||||
}
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* See {@link RemoteApi01TestSuite}
|
||||
*
|
||||
* @Author Alan Davis
|
||||
*/
|
||||
public class RemoteApi09TestSuite extends TestSuite
|
||||
{
|
||||
public static Test suite()
|
||||
{
|
||||
TestSuite suite = new TestSuite();
|
||||
RemoteApi01TestSuite.tests9(suite);
|
||||
return suite;
|
||||
}
|
||||
}
|
@@ -1,482 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.cmis.changelog;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.transaction.Status;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.cmis.CMISCapabilityChanges;
|
||||
import org.alfresco.cmis.CMISChangeEvent;
|
||||
import org.alfresco.cmis.CMISChangeLog;
|
||||
import org.alfresco.cmis.CMISChangeLogService;
|
||||
import org.alfresco.cmis.CMISChangeType;
|
||||
import org.alfresco.cmis.CMISInvalidArgumentException;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.audit.AuditComponent;
|
||||
import org.alfresco.repo.audit.AuditServiceImpl;
|
||||
import org.alfresco.repo.audit.UserAuditFilter;
|
||||
import org.alfresco.repo.audit.model.AuditModelRegistryImpl;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
|
||||
/**
|
||||
* Base tests for {@link CMISChangeLogServiceImpl}
|
||||
*
|
||||
* @author Dmitry Velichkevich
|
||||
*/
|
||||
@Category(OwnJVMTestsCategory.class)
|
||||
public class CMISChangeLogServiceTest extends TestCase
|
||||
{
|
||||
private static final String CMIS_AUTHORITY = "cmis";
|
||||
private static final String CHANGE_PREFIX = "Changed";
|
||||
private static final String INVALID_CHANGE_TOKEN = "<Invalid Change Token>";
|
||||
private static final String[] NAME_PARTS = new String[] { "TestDocument (", ").txt", "TestFolder (", ")" };
|
||||
|
||||
private static int TOTAL_AMOUNT = 31;
|
||||
private static int CREATED_AMOUNT = 18;
|
||||
private static final int THE_HALFT_OF_CREATED_AMOUNT = CREATED_AMOUNT / 2;
|
||||
private static final Map<CMISChangeType, Integer> EXPECTED_AMOUNTS = new HashMap<CMISChangeType, Integer>();
|
||||
static
|
||||
{
|
||||
EXPECTED_AMOUNTS.put(CMISChangeType.CREATED, 5);
|
||||
EXPECTED_AMOUNTS.put(CMISChangeType.DELETED, 3);
|
||||
EXPECTED_AMOUNTS.put(CMISChangeType.SECURITY, 4);
|
||||
EXPECTED_AMOUNTS.put(CMISChangeType.UPDATED, 6);
|
||||
}
|
||||
|
||||
private AuditModelRegistryImpl auditSubsystem;
|
||||
private CMISChangeLogService changeLogService;
|
||||
private NodeService nodeService;
|
||||
private FileFolderService fileFolderService;
|
||||
private PermissionService permissionService;
|
||||
private TransactionService transactionService;
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
private RetryingTransactionHelper retryingTransactionHelper;
|
||||
private UserTransaction testTX;
|
||||
|
||||
private int actualCount = 0;
|
||||
private Map<CMISChangeType, Integer> actualAmounts = new HashMap<CMISChangeType, Integer>();
|
||||
private List<NodeRef> created = null;
|
||||
private List<NodeRef> deleted = null;
|
||||
|
||||
private void disableAudit()
|
||||
{
|
||||
auditSubsystem.stop();
|
||||
auditSubsystem.setProperty("audit.enabled", "true");
|
||||
auditSubsystem.setProperty("audit.cmischangelog.enabled", "false");
|
||||
}
|
||||
|
||||
private void enableAudit()
|
||||
{
|
||||
auditSubsystem.stop();
|
||||
auditSubsystem.setProperty("audit.enabled", "true");
|
||||
auditSubsystem.setProperty("audit.cmischangelog.enabled", "true");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link CMISChangeLogServiceImpl} with disabled Auditing feature
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testServiceWithDisabledAuditing() throws Exception
|
||||
{
|
||||
disableAudit();
|
||||
String lastChangeLogToken = changeLogService.getLastChangeLogToken();
|
||||
createTestData(EXPECTED_AMOUNTS, false);
|
||||
assertEquals(CMISCapabilityChanges.NONE, changeLogService.getCapability());
|
||||
try
|
||||
{
|
||||
changeLogService.getChangeLogEvents(lastChangeLogToken, null);
|
||||
fail("Changes Logging was not enabled but no one Change Log Service method thrown exception");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
assertTrue("Invalid exception type from Change Log Service method call with desabled Changes Logging", e instanceof AlfrescoRuntimeException);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests {@link CMISChangeLogServiceImpl} with enabled Auditing feature
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testEnabledAuditing() throws Exception
|
||||
{
|
||||
enableAudit();
|
||||
String logToken = changeLogService.getLastChangeLogToken();
|
||||
createTestData(EXPECTED_AMOUNTS, false);
|
||||
assertEquals(CMISCapabilityChanges.OBJECTIDSONLY, changeLogService.getCapability());
|
||||
CMISChangeLog changeLog = changeLogService.getChangeLogEvents(logToken, null);
|
||||
assertChangeLog(logToken, changeLog);
|
||||
assertChangeEvents(logToken, changeLog, null, FoldersAppearing.NOT_EXPECTED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates Change Log descriptor that was returned for some Change Log Token
|
||||
*
|
||||
* @param logToken {@link String} value that represents last Change Log Token
|
||||
* @param changeLog {@link CMISChangeLog} instance that represents Change Log descriptor
|
||||
*/
|
||||
private void assertChangeLog(String logToken, CMISChangeLog changeLog)
|
||||
{
|
||||
assertNotNull(("'" + logToken + "' Change Log Token has no descriptor"), changeLog);
|
||||
assertNotNull(("Event Etries for '" + logToken + "' Change Log Token are undefined"), changeLog.getChangeEvents());
|
||||
assertFalse(("Descriptor for '" + logToken + "' Change Log Token has no any Event Entry"), changeLog.getChangeEvents().isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates test data which will represent Change Events of all possible types
|
||||
*
|
||||
* @param requiredAmounts {@link Map}<{@link CMISChangeType}, {@link Integer}> container instance that determines amount of Change Event for each Change Type
|
||||
* @return pair containing list of created node refs, and list of deleted node refs
|
||||
* @see CMISChangeType
|
||||
*/
|
||||
private Pair<List<NodeRef>, List<NodeRef>> createTestData(Map<CMISChangeType, Integer> requiredAmounts, boolean withFolders)
|
||||
{
|
||||
changeLogService.getLastChangeLogToken();
|
||||
created = new LinkedList<NodeRef>();
|
||||
deleted = new LinkedList<NodeRef>();
|
||||
Pair<List<NodeRef>, List<NodeRef>> result = new Pair<List<NodeRef>, List<NodeRef>>(created, deleted);
|
||||
NodeRef parentNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
|
||||
SecureRandom randomizer = new SecureRandom();
|
||||
for (CMISChangeType key : requiredAmounts.keySet())
|
||||
{
|
||||
Integer amount = requiredAmounts.get(key);
|
||||
for (int i = 0; i < amount; i++)
|
||||
{
|
||||
boolean folder = withFolders && (0 == ((Math.abs(randomizer.nextInt()) % amount) % 2));
|
||||
QName objectType = (folder) ? (ContentModel.TYPE_FOLDER) : (ContentModel.TYPE_CONTENT);
|
||||
FileInfo object = fileFolderService.create(parentNodeRef, generateName(randomizer, folder), objectType);
|
||||
created.add(object.getNodeRef());
|
||||
addOneToAmount(actualAmounts, CMISChangeType.CREATED);
|
||||
switch (key)
|
||||
{
|
||||
case DELETED:
|
||||
{
|
||||
nodeService.deleteNode(object.getNodeRef());
|
||||
deleted.add(object.getNodeRef());
|
||||
addOneToAmount(actualAmounts, CMISChangeType.DELETED);
|
||||
break;
|
||||
}
|
||||
case SECURITY:
|
||||
{
|
||||
permissionService.setPermission(object.getNodeRef(), CMIS_AUTHORITY, PermissionService.EXECUTE_CONTENT, true);
|
||||
addOneToAmount(actualAmounts, CMISChangeType.SECURITY);
|
||||
break;
|
||||
}
|
||||
case UPDATED:
|
||||
{
|
||||
StringBuilder nameBuilder = new StringBuilder(CHANGE_PREFIX);
|
||||
nameBuilder.append(nodeService.getProperty(object.getNodeRef(), ContentModel.PROP_NAME));
|
||||
nodeService.setProperty(object.getNodeRef(), ContentModel.PROP_NAME, nameBuilder.toString());
|
||||
addOneToAmount(actualAmounts, CMISChangeType.UPDATED);
|
||||
}
|
||||
}
|
||||
actualCount++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes each element of created test data if element exist and current user has appropriate rights
|
||||
*
|
||||
* @param testData {@link Map}<{@link NodeRef}, {@link Map}<{@link QName}, {@link Serializable}>> container instance that contains test data
|
||||
*/
|
||||
private void deleteTestData()
|
||||
{
|
||||
if (created != null)
|
||||
{
|
||||
for (NodeRef object : created)
|
||||
{
|
||||
if (nodeService.exists(object) && (AccessStatus.ALLOWED == permissionService.hasPermission(object, PermissionService.DELETE)))
|
||||
{
|
||||
nodeService.deleteNode(object);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param folder {@link Boolean} value that determines which name should be generated (for Folder or Document Object)
|
||||
* @return {@link String} value that represents generated uniquely name for Document Object
|
||||
*/
|
||||
private String generateName(SecureRandom randomizer, boolean folder)
|
||||
{
|
||||
StringBuilder nameBuilder = new StringBuilder();
|
||||
int i = (folder) ? (2) : (0);
|
||||
nameBuilder.append(NAME_PARTS[i++]).append(Math.abs(randomizer.nextInt())).append(NAME_PARTS[i++]);
|
||||
return nameBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method validates Change Event entries according to created earlier Objects. According to <b>assertProperties</b> parameter this method may and may not check properties
|
||||
* of Change Event entry according to appropriate expected Object against Change Type
|
||||
*
|
||||
* @param expectedObjects {@link Map}<{@link NodeRef}, {@link Map}<{@link QName}, {@link Serializable}>> container instance that contains Ids and properties of
|
||||
* expected Objects
|
||||
* @param logToken {@link String} value that represents last Change Log Token
|
||||
* @param changeLog {@link CMISChangeLog} instance that represents Change Log descriptor for last Change Log Token
|
||||
* @param maxItems {@link Integer} value that determines high bound of Change Events amount
|
||||
* @see CMISChangeType
|
||||
*/
|
||||
private void assertChangeEvents(String logToken, CMISChangeLog changeLog, Integer maxItems, FoldersAppearing foldersAppearing)
|
||||
{
|
||||
Map<CMISChangeType, Integer> logAmounts = new HashMap<CMISChangeType, Integer>();
|
||||
boolean folderWasFound = false;
|
||||
int idx = 0;
|
||||
for (CMISChangeEvent event : changeLog.getChangeEvents())
|
||||
{
|
||||
// skip first change log entry if a log token has been specified, as the CMIS spec expects
|
||||
// the change entry to be returned for the specified log token
|
||||
idx++;
|
||||
if (logToken != null && idx == 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
assertNotNull(("One of the Change Log Event Enries is undefined for '" + logToken + "' Change Log Token"), event);
|
||||
assertNotNull(("Change Event Entry Id of one of the Change Entries is undefined for '" + logToken + "' Change Log Token"), event.getChangedNode());
|
||||
assertNotNull(("Change Event Change Type of one of the Change Entries is undefined for '" + logToken + "' Change Log Token"), event.getChangeType());
|
||||
assertTrue("Unexpected Object Id='" + event.getChangedNode().toString() + "' from Change Log Token Entries list for '" + logToken + "' Change Log Token", created
|
||||
.contains(event.getChangedNode()));
|
||||
if (!deleted.contains(event.getChangedNode()))
|
||||
{
|
||||
folderWasFound = folderWasFound || fileFolderService.getFileInfo(event.getChangedNode()).isFolder();
|
||||
assertTrue(
|
||||
("Object from Change Event Entries list is marked as '" + event.getChangeType().toString() + "' but does not exist for '" + logToken + "' Change Log Token"),
|
||||
nodeService.exists(event.getChangedNode()));
|
||||
}
|
||||
else
|
||||
{
|
||||
assertTrue("Object has been deleted", deleted.contains(event.getChangedNode()));
|
||||
assertFalse(("Object from Change Event Entries list is marked as 'DELETED' but it still exist for '" + logToken + "' Change Log Token"), nodeService.exists(event
|
||||
.getChangedNode()));
|
||||
}
|
||||
addOneToAmount(logAmounts, event.getChangeType());
|
||||
}
|
||||
if (FoldersAppearing.MUST_APPEAR == foldersAppearing)
|
||||
{
|
||||
assertTrue("No one Folder Object was returned", folderWasFound);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FoldersAppearing.NOT_EXPECTED == foldersAppearing)
|
||||
{
|
||||
assertFalse("Some Folder Object was found", folderWasFound);
|
||||
}
|
||||
}
|
||||
if ((null == maxItems) || (maxItems >= TOTAL_AMOUNT))
|
||||
{
|
||||
for (CMISChangeType key : actualAmounts.keySet())
|
||||
{
|
||||
Integer actualAmount = actualAmounts.get(key);
|
||||
Integer logAmount = logAmounts.get(key);
|
||||
assertTrue(("Invalid Entries amount for '" + key.toString() + "' Change Type. Actual amount: " + actualAmount + ", but log amount: " + logAmount), actualAmount
|
||||
.equals(logAmount));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum FoldersAppearing
|
||||
{
|
||||
NOT_EXPECTED, MAY_APPEAR, MUST_APPEAR
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines which kind of Change was handled and increments appropriate amount to 1
|
||||
*
|
||||
* @param mappedAmounts {@link Map}>{@link CMISChangeType}, {@link Integer}< container instance that contains all accumulated amounts for each kind of Change
|
||||
* @param changeType {@link CMISChangeType} enum value that determines kind of Change
|
||||
*/
|
||||
private void addOneToAmount(Map<CMISChangeType, Integer> mappedAmounts, CMISChangeType changeType)
|
||||
{
|
||||
Integer amount = mappedAmounts.get(changeType);
|
||||
amount = (null == amount) ? (Integer.valueOf(1)) : (Integer.valueOf(amount.intValue() + 1));
|
||||
mappedAmounts.put(changeType, amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@link CMISChangeLogServiceImpl} with enabled Auditing feature for Max Items parameter
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testEnabledAuditingForMaxItems() throws Exception
|
||||
{
|
||||
enableAudit();
|
||||
String logToken = changeLogService.getLastChangeLogToken();
|
||||
createTestData(EXPECTED_AMOUNTS, false);
|
||||
assertEquals(CMISCapabilityChanges.OBJECTIDSONLY, changeLogService.getCapability());
|
||||
CMISChangeLog changeLog = changeLogService.getChangeLogEvents(logToken, THE_HALFT_OF_CREATED_AMOUNT);
|
||||
assertChangeLog(logToken, changeLog);
|
||||
assertChangeEvents(logToken, changeLog, THE_HALFT_OF_CREATED_AMOUNT, FoldersAppearing.NOT_EXPECTED);
|
||||
assertEquals(THE_HALFT_OF_CREATED_AMOUNT, changeLog.getChangeEvents().size());
|
||||
assertTrue("Not all Change Log Entries were requested but result set is indicating that no one more Entry is avilable", changeLog.hasMoreItems());
|
||||
changeLog = changeLogService.getChangeLogEvents(logToken, TOTAL_AMOUNT + (logToken == null ? 0 : 1));
|
||||
assertChangeEvents(logToken, changeLog, TOTAL_AMOUNT, FoldersAppearing.NOT_EXPECTED);
|
||||
assertFalse("All Change Log Entries were requested but result set is indicating that some more Entry(s) are available", changeLog.hasMoreItems());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method tests {@link CMISChangeLogServiceImpl} on receiving Change Event Entries for Invalid Change Log Token with enable and disabled Changes Logging
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testReceivingChangeEventsForInvalidChangeToken() throws Exception
|
||||
{
|
||||
enableAudit();
|
||||
try
|
||||
{
|
||||
changeLogService.getChangeLogEvents(INVALID_CHANGE_TOKEN, null);
|
||||
fail("Change Events were received normally for Invalid Change Log Token");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
assertTrue("Invalid exception type from Change Log Service method call with enabled Changes Logging", e instanceof CMISInvalidArgumentException);
|
||||
}
|
||||
disableAudit();
|
||||
try
|
||||
{
|
||||
changeLogService.getChangeLogEvents(INVALID_CHANGE_TOKEN, null);
|
||||
fail("Changes Logging was not enabled but not one Change Log Service method thrown exception");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
assertTrue("Invalid exception type from Change Log Service method call with desabled Changes Logging", e instanceof AlfrescoRuntimeException);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method tests {@link CMISChangeLogServiceImpl} on working with Change Event entries which could contain Folder Objects
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testReceivingOfChangeEventsExpectingFolders() throws Exception
|
||||
{
|
||||
enableAudit();
|
||||
String changeToken = changeLogService.getLastChangeLogToken();
|
||||
createTestData(EXPECTED_AMOUNTS, true);
|
||||
CMISChangeLog changeLogEvents = changeLogService.getChangeLogEvents(changeToken, null);
|
||||
assertChangeLog(changeToken, changeLogEvents);
|
||||
assertChangeEvents(changeToken, changeLogEvents, null, FoldersAppearing.MUST_APPEAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method tests {@link CMISChangeLogServiceImpl} on working with Change Event entries which could contain Folder Objects. Also this method tests behavior of Max Items
|
||||
* parameter for Folder Objects
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testReceivingOfChangeEventsExpectingFoldersAndBoundedByMaxItems() throws Exception
|
||||
{
|
||||
enableAudit();
|
||||
String changeToken = changeLogService.getLastChangeLogToken();
|
||||
createTestData(EXPECTED_AMOUNTS, true);
|
||||
CMISChangeLog changeLogEvents = changeLogService.getChangeLogEvents(changeToken, 15);
|
||||
assertTrue("Not all Change Event Entries were requested but result set indicates that no more Entry(s) available", changeLogEvents.hasMoreItems());
|
||||
assertChangeLog(changeToken, changeLogEvents);
|
||||
assertChangeEvents(changeToken, changeLogEvents, 15, FoldersAppearing.MAY_APPEAR);
|
||||
changeLogEvents = changeLogService.getChangeLogEvents(changeToken, TOTAL_AMOUNT + (changeToken == null ? 0 : 1));
|
||||
assertChangeLog(changeToken, changeLogEvents);
|
||||
assertChangeEvents(changeToken, changeLogEvents, TOTAL_AMOUNT, FoldersAppearing.MUST_APPEAR);
|
||||
assertFalse("All Change Event Entries were requested but results indicating that some more Entry(s) available", changeLogEvents.hasMoreItems());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
ApplicationContext applicationContext = ApplicationContextHelper.getApplicationContext();
|
||||
changeLogService = (CMISChangeLogService) applicationContext.getBean("CMISChangeLogService");
|
||||
nodeService = (NodeService) applicationContext.getBean("NodeService");
|
||||
permissionService = (PermissionService) applicationContext.getBean("PermissionService");
|
||||
fileFolderService = (FileFolderService) applicationContext.getBean("FileFolderService");
|
||||
transactionService = (TransactionService) applicationContext.getBean("transactionComponent");
|
||||
authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
|
||||
retryingTransactionHelper = (RetryingTransactionHelper) applicationContext.getBean("retryingTransactionHelper");
|
||||
//MNT-10807 : Auditing does not take into account audit.filter.alfresco-access.transaction.user
|
||||
UserAuditFilter userAuditFilter = new UserAuditFilter();
|
||||
userAuditFilter.setUserFilterPattern("System;.*");
|
||||
userAuditFilter.afterPropertiesSet();
|
||||
AuditComponent auditComponent = (AuditComponent) applicationContext.getBean("auditComponent");
|
||||
auditComponent.setUserAuditFilter(userAuditFilter);
|
||||
AuditServiceImpl auditServiceImpl = (AuditServiceImpl) applicationContext.getBean("auditService");
|
||||
auditServiceImpl.setAuditComponent(auditComponent);
|
||||
auditSubsystem = (AuditModelRegistryImpl) applicationContext.getBean("Audit");
|
||||
|
||||
// initialise audit subsystem
|
||||
RetryingTransactionCallback<Void> initAudit = new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
public Void execute() throws Exception
|
||||
{
|
||||
auditSubsystem.stop();
|
||||
auditSubsystem.setProperty("audit.enabled", "true");
|
||||
auditSubsystem.setProperty("audit.cmischangelog.enabled", "true");
|
||||
auditSubsystem.start();
|
||||
return null;
|
||||
}
|
||||
};
|
||||
retryingTransactionHelper.doInTransaction(initAudit, false, true);
|
||||
|
||||
// start test transaction
|
||||
testTX = transactionService.getUserTransaction();
|
||||
testTX.begin();
|
||||
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
deleteTestData();
|
||||
|
||||
if (testTX.getStatus() == Status.STATUS_ACTIVE)
|
||||
{
|
||||
testTX.rollback();
|
||||
}
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
|
||||
auditSubsystem.destroy();
|
||||
}
|
||||
}
|
@@ -1,142 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.rest.test;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.apache.abdera.i18n.iri.IRI;
|
||||
import org.apache.abdera.model.Element;
|
||||
import org.apache.abdera.model.Entry;
|
||||
import org.apache.abdera.model.Link;
|
||||
import org.apache.chemistry.abdera.ext.CMISConstants;
|
||||
import org.apache.chemistry.abdera.ext.CMISObject;
|
||||
import org.apache.chemistry.abdera.ext.CMISProperty;
|
||||
import org.junit.Assert;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Request;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||
|
||||
/**
|
||||
* Tests Alfresco CMIS REST API extensions for Aspects.
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public class AspectTest extends BaseCMISTest
|
||||
{
|
||||
public void testAspectSet() throws Exception
|
||||
{
|
||||
// create document for checkout
|
||||
Link children = cmisClient.getChildrenLink(testCaseFolder);
|
||||
Entry document = createObject(children.getHref(), getName(), "cmis:document");
|
||||
Request documentReq = new GetRequest(document.getSelfLink().getHref().toString());
|
||||
Response documentRes = sendRequest(documentReq, 200);
|
||||
Assert.assertNotNull(documentRes);
|
||||
String xml = documentRes.getContentAsString();
|
||||
Assert.assertNotNull(xml);
|
||||
|
||||
// checkout
|
||||
IRI checkedoutHREF = cmisClient.getCheckedOutCollection(cmisClient.getWorkspace(cmisService));
|
||||
Request checkoutReq = new PostRequest(checkedoutHREF.toString(), xml, CMISConstants.MIMETYPE_ENTRY);
|
||||
Response pwcRes = sendRequest(checkoutReq, 201);
|
||||
Assert.assertNotNull(pwcRes);
|
||||
Entry pwc = parse(new StringReader(pwcRes.getContentAsString()));
|
||||
Assert.assertNotNull(pwc);
|
||||
|
||||
// Apply some aspects to the working copy
|
||||
String updateFile = localTemplates.load("AspectTest.addAspects.cmisatomentry.xml");
|
||||
|
||||
Request updateReq = new PutRequest(pwc.getEditLink().getHref().toString(), updateFile,
|
||||
CMISConstants.MIMETYPE_ENTRY);
|
||||
Response pwcUpdatedres = sendRequest(updateReq, 200);
|
||||
Assert.assertNotNull(pwcUpdatedres);
|
||||
Entry updated = parse(new StringReader(pwcUpdatedres.getContentAsString()));
|
||||
|
||||
{
|
||||
Set<String> appliedAspects = new HashSet<String>(5);
|
||||
Map<String, String> aspectProperties = new HashMap<String, String>(11);
|
||||
extractAspectsAndProperties(updated, appliedAspects, aspectProperties);
|
||||
assertContains(appliedAspects, "P:cm:syndication", "P:cm:summarizable", "P:cm:author");
|
||||
assertEquals("Aspect Test (summary)", aspectProperties.get("cm:summary"));
|
||||
assertEquals("David Ward", aspectProperties.get("cm:author"));
|
||||
}
|
||||
|
||||
// check in with updated aspects
|
||||
String checkinFile = localTemplates.load("AspectTest.removeAndAddAspects.cmisatomentry.xml");
|
||||
String checkinUrl = pwc.getSelfLink().getHref().toString();
|
||||
Request checkinReq = new PutRequest(checkinUrl, checkinFile, CMISConstants.MIMETYPE_ENTRY).setArgs(Collections
|
||||
.singletonMap("checkin", "true"));
|
||||
Response checkinRes = sendRequest(checkinReq, 200);
|
||||
Assert.assertNotNull(checkinRes);
|
||||
Entry checkedIn = parse(new StringReader(checkinRes.getContentAsString()));
|
||||
{
|
||||
Set<String> appliedAspects = new HashSet<String>(5);
|
||||
Map<String, String> aspectProperties = new HashMap<String, String>(11);
|
||||
extractAspectsAndProperties(checkedIn, appliedAspects, aspectProperties);
|
||||
assertContains(appliedAspects, "P:cm:syndication", "P:cm:summarizable", "P:cm:countable");
|
||||
assertDoesNotContain(appliedAspects, "P:cm:author");
|
||||
assertEquals("Aspect Test (new summary)", aspectProperties.get("cm:summary"));
|
||||
assertNull(aspectProperties.get("cm:author"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param document
|
||||
* @param appliedAspects
|
||||
* @param aspectProperties
|
||||
*/
|
||||
private void extractAspectsAndProperties(Entry document, Set<String> appliedAspects,
|
||||
Map<String, String> aspectProperties)
|
||||
{
|
||||
CMISObject documentObject = document.getExtension(CMISConstants.OBJECT);
|
||||
Assert.assertNotNull(documentObject);
|
||||
Element aspectEl = documentObject.getProperties().getExtension(new QName("http://www.alfresco.org", "aspects"));
|
||||
Assert.assertNotNull(aspectEl);
|
||||
for (Element child : aspectEl)
|
||||
{
|
||||
if (child.getQName().equals(ELEMENT_APPLIED_ASPECTS))
|
||||
{
|
||||
appliedAspects.add(child.getText());
|
||||
}
|
||||
else if (child.getQName().equals(ELEMENT_PROPERTIES))
|
||||
{
|
||||
for (Element propertyEl : child)
|
||||
{
|
||||
if (propertyEl instanceof CMISProperty)
|
||||
{
|
||||
CMISProperty prop = (CMISProperty) propertyEl;
|
||||
aspectProperties.put(prop.getId(), prop.getStringValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fail("Unexpected element: " + child.getQName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,159 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.rest.test;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.alfresco.repo.cmis.rest.AlfrescoCMISExtensionFactory;
|
||||
import org.alfresco.repo.web.scripts.BaseWebScriptTest;
|
||||
import org.apache.abdera.Abdera;
|
||||
import org.apache.abdera.factory.Factory;
|
||||
import org.apache.abdera.i18n.iri.IRI;
|
||||
import org.apache.abdera.model.Document;
|
||||
import org.apache.abdera.model.Element;
|
||||
import org.apache.abdera.model.Entry;
|
||||
import org.apache.abdera.model.Service;
|
||||
import org.apache.abdera.parser.ParseException;
|
||||
import org.apache.abdera.parser.Parser;
|
||||
import org.apache.chemistry.abdera.ext.CMISConstants;
|
||||
import org.apache.chemistry.tck.atompub.client.CMISClient;
|
||||
import org.apache.chemistry.tck.atompub.utils.ResourceLoader;
|
||||
import org.junit.Assert;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Request;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||
|
||||
/**
|
||||
* Base class for Alfresco specific CMIS REST API tests.
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public abstract class BaseCMISTest extends BaseWebScriptTest
|
||||
{
|
||||
protected static final QName ELEMENT_PROPERTIES = new QName("http://www.alfresco.org", "properties");
|
||||
protected static final QName ELEMENT_APPLIED_ASPECTS = new QName("http://www.alfresco.org", "appliedAspects");
|
||||
|
||||
protected static final String URL_CMIS = "/cmis";
|
||||
|
||||
protected Abdera abdera;
|
||||
protected Parser parser;
|
||||
protected Factory factory;
|
||||
|
||||
public BaseCMISTest()
|
||||
{
|
||||
// construct Abdera Service
|
||||
abdera = new Abdera();
|
||||
factory = abdera.getFactory();
|
||||
factory.registerExtension(new AlfrescoCMISExtensionFactory());
|
||||
parser = factory.newParser();
|
||||
|
||||
// construct test templates
|
||||
localTemplates = new ResourceLoader('/' + getClass().getPackage().getName().replace('.', '/') + '/');
|
||||
|
||||
// Create a dummy client. We won't / can't use it to make requests.
|
||||
cmisClient = new CMISClient(null, null, null, null);
|
||||
cmisClient.setValidate(false);
|
||||
}
|
||||
|
||||
protected CMISClient cmisClient;
|
||||
protected ResourceLoader localTemplates;
|
||||
protected Service cmisService;
|
||||
protected Entry testCaseFolder;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
setDefaultRunAs("admin");
|
||||
|
||||
Request req = new GetRequest(URL_CMIS);
|
||||
Response res = sendRequest(req, 200);
|
||||
String xml = res.getContentAsString();
|
||||
Assert.assertNotNull(xml);
|
||||
Assert.assertTrue(xml.length() > 0);
|
||||
cmisService = parse(new StringReader(xml));
|
||||
Assert.assertNotNull(cmisService);
|
||||
IRI rootFolderHREF = cmisClient.getRootCollection(cmisClient.getWorkspace(cmisService));
|
||||
Assert.assertNotNull(rootFolderHREF);
|
||||
String folderName = getClass().getSimpleName() + System.currentTimeMillis() + " - " + getName();
|
||||
testCaseFolder = createObject(rootFolderHREF, folderName, "cmis:folder");
|
||||
}
|
||||
|
||||
protected <T extends Element> T parse(Reader doc)
|
||||
{
|
||||
Document<T> entryDoc = parser.parse(doc);
|
||||
return entryDoc.getRoot();
|
||||
}
|
||||
|
||||
protected <T extends Element> T fetch(IRI href, Map<String, String> args) throws Exception
|
||||
{
|
||||
Request get = new GetRequest(href.toString()).setArgs(args);
|
||||
Response res = sendRequest(get, 200);
|
||||
Assert.assertNotNull(res);
|
||||
String xml = res.getContentAsString();
|
||||
T result = this.<T> parse(new StringReader(xml));
|
||||
Assert.assertNotNull(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected Entry createObject(IRI parent, String name, String type) throws Exception
|
||||
{
|
||||
return createObject(parent, name, type, 201);
|
||||
}
|
||||
|
||||
protected <T extends Element> T createObject(IRI parent, String name, String type, int expectedStatus) throws Exception
|
||||
{
|
||||
String createObject = localTemplates.load("BaseCMISTest.createObject.atomentry.xml");
|
||||
createObject = createObject.replace("${NAME}", name);
|
||||
createObject = createObject.replace("${TYPE}", type);
|
||||
Request req = new PostRequest(parent.toString(), createObject, CMISConstants.MIMETYPE_ENTRY);
|
||||
Response res = sendRequest(req, expectedStatus);
|
||||
Assert.assertNotNull(res);
|
||||
try
|
||||
{
|
||||
String xml = res.getContentAsString();
|
||||
return this.<T> parse(new StringReader(xml));
|
||||
}
|
||||
catch (ParseException e)
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void assertContains(Set<String> actual, String... expected)
|
||||
{
|
||||
Assert.assertTrue(actual.containsAll(Arrays.asList(expected)));
|
||||
}
|
||||
|
||||
protected void assertDoesNotContain(Set<String> actual, String... unexpected)
|
||||
{
|
||||
Set<String> copy = new HashSet<String>(actual);
|
||||
copy.retainAll(Arrays.asList(unexpected));
|
||||
Assert.assertTrue(copy.isEmpty());
|
||||
}
|
||||
}
|
@@ -1,132 +0,0 @@
|
||||
package org.alfresco.repo.cmis.rest.test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.apache.abdera.Abdera;
|
||||
import org.apache.abdera.model.Document;
|
||||
import org.apache.abdera.model.Element;
|
||||
import org.apache.abdera.model.Entry;
|
||||
import org.apache.abdera.model.Feed;
|
||||
import org.apache.abdera.protocol.Response;
|
||||
import org.apache.abdera.protocol.client.AbderaClient;
|
||||
import org.apache.abdera.protocol.client.ClientResponse;
|
||||
import org.apache.chemistry.abdera.ext.CMISConstants;
|
||||
import org.apache.chemistry.abdera.ext.CMISExtensionFactory;
|
||||
import org.apache.chemistry.abdera.ext.CMISObject;
|
||||
import org.apache.chemistry.abdera.ext.CMISProperties;
|
||||
import org.apache.chemistry.abdera.ext.CMISProperty;
|
||||
import org.apache.commons.httpclient.UsernamePasswordCredentials;
|
||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||
|
||||
|
||||
public class BulkCreateAndQuerySystemTest
|
||||
{
|
||||
private static Abdera abdera;
|
||||
private static final String URL = "http://localhost:8080";
|
||||
private static final String rootFolder = "testfolder";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
abdera = new Abdera();
|
||||
abdera.getFactory().registerExtension(new CMISExtensionFactory());
|
||||
|
||||
AbderaClient client = new AbderaClient(abdera);
|
||||
|
||||
client.setMaxConnectionsPerHost(100);
|
||||
client.addCredentials(URL, null, "basic", new UsernamePasswordCredentials("admin", "admin"));
|
||||
|
||||
String rootId = createFolder(client, URL + "/alfresco/service/cmis/p/children", rootFolder);
|
||||
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
createFolder(client, URL + "/alfresco/service/cmis/p/" + rootFolder + "/children", "folder_" + i);
|
||||
findFolder(client, rootId, "folder_" + i);
|
||||
}
|
||||
}
|
||||
|
||||
private static void findFolder(AbderaClient client, String inFolderId, String name) {
|
||||
System.out.println("querying for " + name + " in " + inFolderId);
|
||||
String query = "<query xmlns=\"http://docs.oasis-open.org/ns/cmis/core/200908/\">\n" +
|
||||
"<statement>SELECT cmis:Name, cmis:ObjectId FROM cmis:folder WHERE cmis:Name='" + name + "' AND IN_FOLDER('" + inFolderId + "')</statement>\n" +
|
||||
"<pageSize>100</pageSize>\n" +
|
||||
"<skipCount>0</skipCount>\n" +
|
||||
"</query>";
|
||||
|
||||
StringRequestEntity requestEntity;
|
||||
try {
|
||||
requestEntity = new StringRequestEntity(query, "application/cmisquery+xml", "ISO-8859-1");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ClientResponse response = client.post(URL + "/alfresco/service/cmis/queries", requestEntity);
|
||||
try {
|
||||
if (response.getType() == Response.ResponseType.SUCCESS) {
|
||||
|
||||
Document<Feed> feed = response.getDocument();
|
||||
List<Entry> entries = feed.getRoot().getEntries();
|
||||
for (Entry entry : entries) {
|
||||
System.out.println("received query result with name " + entry.getTitle());
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException(response.getStatusText());
|
||||
}
|
||||
} finally {
|
||||
response.release();
|
||||
}
|
||||
}
|
||||
|
||||
private static String createFolder(AbderaClient client, String parent, String name) throws Exception {
|
||||
Entry entry = abdera.newEntry();
|
||||
entry.setTitle(name);
|
||||
entry.setSummary("Summary...");
|
||||
|
||||
CMISObject cmisObject = entry.addExtension(CMISConstants.OBJECT);
|
||||
CMISProperties properties = cmisObject.addExtension(CMISConstants.PROPERTIES);
|
||||
CMISProperty property = properties.addExtension(CMISConstants.ID_PROPERTY);
|
||||
property.setAttributeValue(CMISConstants.PROPERTY_ID, CMISConstants.PROP_OBJECT_TYPE_ID);
|
||||
Element value = property.addExtension(CMISConstants.PROPERTY_VALUE);
|
||||
value.setText("cmis:folder");
|
||||
|
||||
ClientResponse resp = client.post(parent, entry);
|
||||
|
||||
try {
|
||||
if (resp.getType() != Response.ResponseType.SUCCESS) {
|
||||
printError(resp);
|
||||
|
||||
throw new RuntimeException(resp.getStatusText());
|
||||
} else {
|
||||
System.out.println("Created folder " + name);
|
||||
|
||||
Document<Entry> entryDoc = resp.getDocument();
|
||||
Entry root = entryDoc.getRoot();
|
||||
|
||||
CMISObject object = root.getExtension(CMISConstants.OBJECT);
|
||||
CMISProperties p = object.getProperties();
|
||||
|
||||
return p.find(CMISConstants.PROP_OBJECT_ID).getStringValue();
|
||||
}
|
||||
} finally {
|
||||
resp.release();
|
||||
}
|
||||
}
|
||||
|
||||
private static void printError(ClientResponse resp) {
|
||||
try {
|
||||
InputStream inputStream = resp.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
String line = reader.readLine();
|
||||
while (line != null) {
|
||||
System.out.println(line);
|
||||
line = reader.readLine();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.rest.test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.apache.abdera.Abdera;
|
||||
import org.apache.abdera.model.Document;
|
||||
import org.apache.abdera.model.Element;
|
||||
import org.apache.abdera.model.Entry;
|
||||
import org.apache.abdera.protocol.Response;
|
||||
import org.apache.abdera.protocol.client.AbderaClient;
|
||||
import org.apache.abdera.protocol.client.ClientResponse;
|
||||
import org.apache.chemistry.abdera.ext.CMISConstants;
|
||||
import org.apache.chemistry.abdera.ext.CMISExtensionFactory;
|
||||
import org.apache.chemistry.abdera.ext.CMISObject;
|
||||
import org.apache.chemistry.abdera.ext.CMISProperties;
|
||||
import org.apache.chemistry.abdera.ext.CMISProperty;
|
||||
import org.apache.commons.httpclient.UsernamePasswordCredentials;
|
||||
|
||||
|
||||
/**
|
||||
* Test ALFCOM-2947 CMIS: createFolder & immediately add document can fail
|
||||
*/
|
||||
public class BulkCreateSystemTest
|
||||
{
|
||||
private static Abdera abdera;
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
abdera = new Abdera();
|
||||
abdera.getFactory().registerExtension(new CMISExtensionFactory());
|
||||
|
||||
AbderaClient client = new AbderaClient(abdera);
|
||||
client.usePreemptiveAuthentication(true);
|
||||
client.addCredentials("http://localhost:8080", null, "basic", new UsernamePasswordCredentials("admin", "admin"));
|
||||
|
||||
String root = createFolder(client,
|
||||
"http://localhost:8080/alfresco/service/api/path/workspace/SpacesStore/Company%20Home/children",
|
||||
"testfolder14");
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
String folder = createFolder(client, root, "folder_" + i);
|
||||
createDocument(client, folder, "doc");
|
||||
}
|
||||
}
|
||||
|
||||
private static String createFolder(AbderaClient client, String parent, String name) throws Exception
|
||||
{
|
||||
Entry entry = abdera.newEntry();
|
||||
entry.setTitle(name);
|
||||
entry.setSummary("Summarize summarize...");
|
||||
|
||||
CMISObject cmisObject = entry.addExtension(CMISConstants.OBJECT);
|
||||
CMISProperties properties = cmisObject.addExtension(CMISConstants.PROPERTIES);
|
||||
CMISProperty property = properties.addExtension(CMISConstants.ID_PROPERTY);
|
||||
property.setAttributeValue(CMISConstants.PROPERTY_ID, CMISConstants.PROP_OBJECT_TYPE_ID);
|
||||
Element value = property.addExtension(CMISConstants.PROPERTY_VALUE);
|
||||
value.setText("cmis:Folder");
|
||||
|
||||
ClientResponse resp = client.post(parent, entry);
|
||||
|
||||
try
|
||||
{
|
||||
if (resp.getType() != Response.ResponseType.SUCCESS)
|
||||
{
|
||||
printError(resp);
|
||||
|
||||
throw new RuntimeException(resp.getStatusText());
|
||||
} else
|
||||
{
|
||||
System.out.println("Created folder " + name);
|
||||
|
||||
Document<Entry> entryDoc = resp.getDocument();
|
||||
Entry root = entryDoc.getRoot();
|
||||
|
||||
return root.getLink("children").getHref().toString();
|
||||
}
|
||||
} finally
|
||||
{
|
||||
resp.release();
|
||||
}
|
||||
}
|
||||
|
||||
private static void createDocument(AbderaClient client, String parent, String name)
|
||||
{
|
||||
Entry entry = abdera.newEntry();
|
||||
entry.setTitle(name);
|
||||
entry.setSummary("Summarize summarize...");
|
||||
|
||||
CMISObject cmisObject = entry.addExtension(CMISConstants.OBJECT);
|
||||
CMISProperties properties = cmisObject.addExtension(CMISConstants.PROPERTIES);
|
||||
CMISProperty property = properties.addExtension(CMISConstants.ID_PROPERTY);
|
||||
property.setAttributeValue(CMISConstants.PROPERTY_ID, CMISConstants.PROP_OBJECT_TYPE_ID);
|
||||
Element value = property.addExtension(CMISConstants.PROPERTY_VALUE);
|
||||
value.setText("document");
|
||||
|
||||
ClientResponse resp = client.post(parent, entry);
|
||||
|
||||
try
|
||||
{
|
||||
if (resp.getType() != Response.ResponseType.SUCCESS)
|
||||
{
|
||||
printError(resp);
|
||||
|
||||
throw new RuntimeException(resp.getStatusText());
|
||||
}
|
||||
} finally
|
||||
{
|
||||
resp.release();
|
||||
}
|
||||
}
|
||||
|
||||
private static void printError(ClientResponse resp)
|
||||
{
|
||||
try
|
||||
{
|
||||
InputStream inputStream = resp.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
String line = reader.readLine();
|
||||
while (line != null)
|
||||
{
|
||||
System.out.println(line);
|
||||
line = reader.readLine();
|
||||
}
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,218 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2013 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.rest.test;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.io.StringReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.sax.SAXSource;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import javax.xml.validation.Schema;
|
||||
import javax.xml.validation.SchemaFactory;
|
||||
import javax.xml.validation.Validator;
|
||||
|
||||
import org.alfresco.model.ApplicationModel;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.abdera.model.Entry;
|
||||
import org.apache.abdera.model.Link;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Request;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Response;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
public class CMISAtomTemplatesTest extends BaseCMISTest
|
||||
{
|
||||
private NodeService nodeService;
|
||||
|
||||
static String docName;
|
||||
|
||||
static String xmlResponse;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
// create document
|
||||
docName = "Test 1 _" + System.currentTimeMillis();
|
||||
Link children = cmisClient.getChildrenLink(testCaseFolder);
|
||||
Entry document = createObject(children.getHref(), docName, "cmis:document");
|
||||
Request documentReq = new GetRequest(document.getSelfLink().getHref().toString());
|
||||
Response documentRes = sendRequest(documentReq, 200);
|
||||
Assert.assertNotNull(documentRes);
|
||||
xmlResponse = documentRes.getContentAsString();
|
||||
Assert.assertNotNull(xmlResponse);
|
||||
|
||||
this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChildrenGetAtomFeed() throws Exception
|
||||
{
|
||||
// retrieve the list of nodes
|
||||
String id = testCaseFolder.getId().toString().replace("urn:uuid:", "workspace:SpacesStore/i/");
|
||||
Request get = new GetRequest("/cmis/s/" + id + "/children");
|
||||
Response res = sendRequest(get, 200);
|
||||
String xml = res.getContentAsString();
|
||||
|
||||
// check document name with repeatable spaces in xml response.
|
||||
assertEquals("Probably, children.get.atomfeed.ftl template has compress dirrective", true, xml.contains(docName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testItemGetAtomentryTemplate() throws Exception
|
||||
{
|
||||
// check document name with repeatable spaces in xml response.
|
||||
assertEquals("Probably, item.get.atomentry.ftl template has compress dirrective", true, xmlResponse.contains(docName));
|
||||
}
|
||||
|
||||
/*
|
||||
* Get children, if parent has object of non-cmis type
|
||||
* cm:folderlink is non-cmis type.
|
||||
*/
|
||||
@Test
|
||||
public void testChildrenWithLink() throws Exception
|
||||
{
|
||||
String testFolderRefStr = testCaseFolder.getId().toString().replace("urn:uuid:", "workspace://SpacesStore/");
|
||||
NodeRef testFolderRef = new NodeRef(testFolderRefStr);
|
||||
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(2, 1.0f);
|
||||
String linkName = "link " + testCaseFolder.getTitle() + ".url";
|
||||
props.put(ContentModel.PROP_NAME, linkName);
|
||||
props.put(ContentModel.PROP_LINK_DESTINATION, testFolderRef);
|
||||
|
||||
AuthenticationUtil.pushAuthentication();;
|
||||
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
|
||||
|
||||
NodeRef linkRef = null;
|
||||
|
||||
try
|
||||
{
|
||||
ChildAssociationRef childRef = nodeService.createNode(
|
||||
testFolderRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
QName.createQName(testCaseFolder.getTitle()),
|
||||
ApplicationModel.TYPE_FOLDERLINK,
|
||||
props);
|
||||
linkRef = childRef.getChildRef();
|
||||
|
||||
String id = testCaseFolder.getId().toString().replace("urn:uuid:", "workspace:SpacesStore/i/");
|
||||
Request get = new GetRequest("/cmis/s/" + id + "/children");
|
||||
sendRequest(get, 200);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (linkRef != null)
|
||||
{
|
||||
nodeService.deleteNode(linkRef);
|
||||
}
|
||||
AuthenticationUtil.popAuthentication();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCheckXmlResponse() throws Exception
|
||||
{
|
||||
String testFolderRefStr = testCaseFolder.getId().toString().replace("urn:uuid:", "workspace://SpacesStore/");
|
||||
NodeRef testFolderRef = new NodeRef(testFolderRefStr);
|
||||
|
||||
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
|
||||
properties.put(ContentModel.PROP_NAME, "testcontent");
|
||||
properties.put(ContentModel.PROP_DESCRIPTION, "content - test doc for test");
|
||||
|
||||
AuthenticationUtil.pushAuthentication();
|
||||
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
|
||||
|
||||
NodeRef testDocNodeRef = null;
|
||||
try
|
||||
{
|
||||
ChildAssociationRef testDoc = nodeService.createNode(testFolderRef, ContentModel.ASSOC_CONTAINS,
|
||||
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "testcontent"), ContentModel.TYPE_CONTENT, properties);
|
||||
testDocNodeRef = testDoc.getChildRef();
|
||||
properties.clear();
|
||||
properties.put(ApplicationModel.PROP_EDITINLINE, true);
|
||||
nodeService.addAspect(testDocNodeRef, ApplicationModel.ASPECT_INLINEEDITABLE, properties);
|
||||
|
||||
String id = testDocNodeRef.toString().replace("workspace://SpacesStore/", "workspace:SpacesStore/i/");
|
||||
Request get = new GetRequest("/cmis/s/" + id);
|
||||
Response res = sendRequest(get, 200);
|
||||
String xml = res.getContentAsString();
|
||||
|
||||
try
|
||||
{
|
||||
validateXmlResponse(xml);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
fail(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (testDocNodeRef != null)
|
||||
{
|
||||
nodeService.deleteNode(testDocNodeRef);
|
||||
}
|
||||
AuthenticationUtil.popAuthentication();
|
||||
}
|
||||
}
|
||||
|
||||
private void validateXmlResponse(String xml) throws Exception
|
||||
{
|
||||
Source[] shemas = new Source[] {
|
||||
new StreamSource(new StringReader(localTemplates.load("xml.xsd"))),
|
||||
new StreamSource(new StringReader(localTemplates.load("atom.xsd"))),
|
||||
new StreamSource(new StringReader(localTemplates.load("app.xsd"))),
|
||||
new StreamSource(new StringReader(localTemplates.load("CMIS-Core.xsd"))),
|
||||
new StreamSource(new StringReader(localTemplates.load("envelope.xsd"))),
|
||||
new StreamSource(new StringReader(localTemplates.load("Alfresco-Core.xsd")))
|
||||
};
|
||||
|
||||
Schema schema = null;
|
||||
String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
|
||||
SchemaFactory factory = SchemaFactory.newInstance(language);
|
||||
schema = factory.newSchema(shemas);
|
||||
|
||||
// creating a Validator instance
|
||||
Validator validator = schema.newValidator();
|
||||
|
||||
// preparing the XML file as a SAX source
|
||||
SAXSource source = new SAXSource(new InputSource(new StringReader(xml)));
|
||||
|
||||
// validating the SAX source against the schema
|
||||
validator.validate(source);
|
||||
}
|
||||
}
|
@@ -1,120 +0,0 @@
|
||||
package org.alfresco.repo.cmis.rest.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl;
|
||||
import org.apache.chemistry.opencmis.client.api.Document;
|
||||
import org.apache.chemistry.opencmis.client.api.Folder;
|
||||
import org.apache.chemistry.opencmis.client.api.ItemIterable;
|
||||
import org.apache.chemistry.opencmis.client.api.ObjectType;
|
||||
import org.apache.chemistry.opencmis.client.api.OperationContext;
|
||||
import org.apache.chemistry.opencmis.client.api.Relationship;
|
||||
import org.apache.chemistry.opencmis.client.api.Session;
|
||||
import org.apache.chemistry.opencmis.client.api.SessionFactory;
|
||||
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
|
||||
import org.apache.chemistry.opencmis.commons.PropertyIds;
|
||||
import org.apache.chemistry.opencmis.commons.SessionParameter;
|
||||
import org.apache.chemistry.opencmis.commons.enums.BindingType;
|
||||
import org.apache.chemistry.opencmis.commons.enums.RelationshipDirection;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.safehaus.uuid.UUIDGenerator;
|
||||
|
||||
/**
|
||||
* CMIS Relationship integration tests.
|
||||
*
|
||||
* @author Alex Strachan (tidy up by Alan Davis)
|
||||
*/
|
||||
public class CmisRelationshipSystemTest
|
||||
{
|
||||
static Session session;
|
||||
|
||||
static Document doc1;
|
||||
|
||||
@BeforeClass
|
||||
public static void classSetup() throws Exception
|
||||
{
|
||||
SessionFactory factory = SessionFactoryImpl.newInstance();
|
||||
Map<String, String> sessionParameters = new HashMap<String, String>();
|
||||
sessionParameters
|
||||
.put(SessionParameter.ATOMPUB_URL, "http://localhost:8080/alfresco/s/cmis");
|
||||
sessionParameters.put(SessionParameter.USER, "admin");
|
||||
sessionParameters.put(SessionParameter.PASSWORD, "admin");
|
||||
sessionParameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
|
||||
sessionParameters.put(SessionParameter.OBJECT_FACTORY_CLASS,
|
||||
AlfrescoObjectFactoryImpl.class.getName());
|
||||
session = factory.getRepositories(sessionParameters).get(0).createSession();
|
||||
|
||||
/*
|
||||
* Association example from:
|
||||
* http://forums.alfresco.com/en/viewtopic.php?f=45&t=27219
|
||||
*/
|
||||
HashMap<String, Object> prop1 = new HashMap<String, Object>();
|
||||
prop1.put(PropertyIds.NAME, GUID());
|
||||
prop1.put(PropertyIds.OBJECT_TYPE_ID, "D:ws:article");
|
||||
|
||||
HashMap<String, Object> prop2 = new HashMap<String, Object>();
|
||||
prop2.put(PropertyIds.NAME, GUID());
|
||||
prop2.put(PropertyIds.OBJECT_TYPE_ID, "D:ws:article");
|
||||
|
||||
Folder folder = (Folder) session.getObjectByPath("/");
|
||||
|
||||
doc1 = folder.createDocument(prop1, null, null, null, null, null,
|
||||
session.getDefaultContext());
|
||||
Document doc2 = folder.createDocument(prop2, null, null, null, null, null,
|
||||
session.getDefaultContext());
|
||||
|
||||
Map<String, String> relProps = new HashMap<String, String>();
|
||||
relProps.put("cmis:sourceId", doc1.getId());
|
||||
relProps.put("cmis:targetId", doc2.getId());
|
||||
relProps.put("cmis:objectTypeId", "R:ws:relatedArticles");
|
||||
session.createRelationship(relProps, null, null, null);
|
||||
}
|
||||
|
||||
private static String GUID()
|
||||
{
|
||||
return UUIDGenerator.getInstance().generateRandomBasedUUID().toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testObjectRelationships() throws Exception
|
||||
{
|
||||
// Can't use object relationships retrieval due an isValidCmisRelationship issue.
|
||||
// TODO Change expected value to 1 rather than 0 once bug is fixed.
|
||||
assertEquals(0, doc1.getRelationships().size());
|
||||
}
|
||||
|
||||
private void testGetRelationshipsViaSession(RelationshipDirection direction) throws Exception
|
||||
{
|
||||
// Try and get relationships using the session
|
||||
ObjectType typeDefinition = session.getTypeDefinition("R:ws:relatedArticles");
|
||||
OperationContext operationContext = session.createOperationContext();
|
||||
|
||||
ItemIterable<Relationship> relationships = session.getRelationships(doc1, true, direction,
|
||||
typeDefinition, operationContext);
|
||||
int relationshipCount = 0;
|
||||
Iterator<Relationship> iterator = relationships.iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
relationshipCount++;
|
||||
iterator.next();
|
||||
}
|
||||
assertEquals(1, relationshipCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRelationshipDirectionEither() throws Exception
|
||||
{
|
||||
testGetRelationshipsViaSession(RelationshipDirection.EITHER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRelationshipDirectionSource() throws Exception
|
||||
{
|
||||
testGetRelationshipsViaSession(RelationshipDirection.SOURCE);
|
||||
}
|
||||
}
|
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.rest.test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.abdera.i18n.iri.IRI;
|
||||
import org.apache.abdera.model.Entry;
|
||||
import org.apache.abdera.model.Feed;
|
||||
import org.apache.abdera.model.Link;
|
||||
import org.apache.chemistry.abdera.ext.CMISConstants;
|
||||
import org.apache.chemistry.abdera.ext.CMISTypeDefinition;
|
||||
import org.junit.Assert;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.Request;
|
||||
|
||||
/**
|
||||
* Tests Alfresco CMIS Policy implementation.
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public class PolicyTest extends BaseCMISTest
|
||||
{
|
||||
public void testPolicies() throws Exception
|
||||
{
|
||||
// Try creating an object with the cmis:policy base type (expect a constraint exception)
|
||||
Link children = cmisClient.getChildrenLink(testCaseFolder);
|
||||
createObject(children.getHref(), getName(), "cmis:policy", 409);
|
||||
|
||||
// Try creating an object of any of the cmis:policy subtypes
|
||||
IRI typesHREF = cmisClient.getTypesChildrenCollection(cmisClient.getWorkspace(cmisService));
|
||||
Map<String, String> args = new HashMap<String, String>();
|
||||
args.put("typeId", "cmis:policy");
|
||||
args.put("includePropertyDefinitions", "true");
|
||||
Feed types = fetch(typesHREF, args);
|
||||
List<Entry> entries = types.getEntries();
|
||||
assertNotSame(0, entries.size());
|
||||
for (Entry type : entries) {
|
||||
CMISTypeDefinition entryType = type.getExtension(CMISConstants.TYPE_DEFINITION);
|
||||
Assert.assertNotNull(entryType);
|
||||
createObject(children.getHref(), getName(), entryType.getId(), 409);
|
||||
}
|
||||
|
||||
// Create a document to attempt to apply policies to
|
||||
Entry document = createObject(children.getHref(), getName(), "cmis:document");
|
||||
|
||||
// retrieve policies feed on document (this should be empty)
|
||||
Link polsLink = document.getLink(CMISConstants.REL_POLICIES);
|
||||
assertNotNull(polsLink);
|
||||
Feed polsBefore = fetch(polsLink.getHref(), null);
|
||||
assertNotNull(polsBefore);
|
||||
assertEquals(0, polsBefore.getEntries().size());
|
||||
|
||||
// Try applying a policy (expect a constraint exception)
|
||||
String policyFile = localTemplates.load("PolicyTest.applyPolicy.atomentry.xml");
|
||||
policyFile = policyFile.replace("${OBJECTID}", "doesnotexist");
|
||||
Request req = new PostRequest(polsLink.getHref().toString(), policyFile, CMISConstants.MIMETYPE_ENTRY);
|
||||
sendRequest(req, 409);
|
||||
}
|
||||
}
|
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.ws.test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.ws.Holder;
|
||||
|
||||
import org.alfresco.repo.cmis.ws.Aspects;
|
||||
import org.alfresco.repo.cmis.ws.CmisExtensionType;
|
||||
import org.alfresco.repo.cmis.ws.CmisPropertiesType;
|
||||
import org.alfresco.repo.cmis.ws.CmisProperty;
|
||||
import org.alfresco.repo.cmis.ws.CmisPropertyString;
|
||||
import org.alfresco.repo.cmis.ws.SetAspects;
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* Tests Alfresco CMIS WebService API extensions for Aspects.
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public class AspectTest extends BaseCMISTest
|
||||
{
|
||||
public void testAspectSet() throws Exception
|
||||
{
|
||||
// create document for checkout
|
||||
Holder<String> objectId = new Holder<String>();
|
||||
objectServicePort.createDocument(repositoryId, createObjectProperties(getName(), "cmis:document"),
|
||||
testFolderId, null, null, null, null, null, new Holder<CmisExtensionType>(), objectId);
|
||||
Assert.assertNotNull(objectId.value);
|
||||
|
||||
// checkout
|
||||
versioningServicePort.checkOut(repositoryId, objectId, new Holder<CmisExtensionType>(), new Holder<Boolean>());
|
||||
Assert.assertNotNull(objectId.value);
|
||||
|
||||
// Apply some aspects to the working copy
|
||||
{
|
||||
CmisPropertiesType properties = new CmisPropertiesType();
|
||||
SetAspects extension = new SetAspects();
|
||||
properties.getAny().add(extension);
|
||||
extension.getAspectsToAdd().addAll(Arrays.asList(new String[]
|
||||
{
|
||||
"P:cm:syndication", "P:cm:summarizable"
|
||||
}));
|
||||
CmisPropertiesType extensionProperties = new CmisPropertiesType();
|
||||
extension.setProperties(extensionProperties);
|
||||
setStringProperty(extensionProperties, "cm:summary", "Aspect Test (summary)");
|
||||
// Add a property without explicitly adding its aspect. Should be automatically added.
|
||||
setStringProperty(extensionProperties, "cm:author", "David Ward");
|
||||
objectServicePort.updateProperties(repositoryId, objectId, null, properties, null);
|
||||
CmisPropertiesType updated = objectServicePort.getProperties(repositoryId, objectId.value, null, null);
|
||||
Set<String> appliedAspects = new HashSet<String>(5);
|
||||
Map<String, String> aspectProperties = new HashMap<String, String>(11);
|
||||
extractAspectsAndProperties(updated, appliedAspects, aspectProperties);
|
||||
assertContains(appliedAspects, "P:cm:syndication", "P:cm:summarizable", "P:cm:author");
|
||||
assertEquals("Aspect Test (summary)", aspectProperties.get("cm:summary"));
|
||||
assertEquals("David Ward", aspectProperties.get("cm:author"));
|
||||
}
|
||||
|
||||
// check in with updated aspects
|
||||
{
|
||||
CmisPropertiesType properties = new CmisPropertiesType();
|
||||
SetAspects extension = new SetAspects();
|
||||
properties.getAny().add(extension);
|
||||
extension.getAspectsToAdd().add("P:cm:countable");
|
||||
extension.getAspectsToRemove().add("P:cm:author");
|
||||
CmisPropertiesType extensionProperties = new CmisPropertiesType();
|
||||
extension.setProperties(extensionProperties);
|
||||
setStringProperty(extensionProperties, "cm:summary", "Aspect Test (new summary)");
|
||||
versioningServicePort.checkIn(repositoryId, objectId, null, properties, null, null, null, null, null,
|
||||
new Holder<CmisExtensionType>());
|
||||
CmisPropertiesType checkedIn = objectServicePort.getProperties(repositoryId, objectId.value, null, null);
|
||||
Set<String> appliedAspects = new HashSet<String>(5);
|
||||
Map<String, String> aspectProperties = new HashMap<String, String>(11);
|
||||
extractAspectsAndProperties(checkedIn, appliedAspects, aspectProperties);
|
||||
assertContains(appliedAspects, "P:cm:syndication", "P:cm:summarizable", "P:cm:countable");
|
||||
assertDoesNotContain(appliedAspects, "P:cm:author");
|
||||
assertEquals("Aspect Test (new summary)", aspectProperties.get("cm:summary"));
|
||||
assertNull(aspectProperties.get("cm:author"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param properties
|
||||
* @param appliedAspects
|
||||
* @param aspectProperties
|
||||
*/
|
||||
private void extractAspectsAndProperties(CmisPropertiesType properties, Set<String> appliedAspects,
|
||||
Map<String, String> aspectProperties)
|
||||
{
|
||||
Aspects extension = null;
|
||||
for (Object object : properties.getAny())
|
||||
{
|
||||
if (object instanceof Aspects)
|
||||
{
|
||||
extension = (Aspects) object;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (extension == null)
|
||||
{
|
||||
fail("alf:aspects element not included");
|
||||
}
|
||||
appliedAspects.addAll(extension.getAppliedAspects());
|
||||
CmisPropertiesType extensionProperties = extension.getProperties();
|
||||
if (extensionProperties == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (CmisProperty property : extensionProperties.getProperty())
|
||||
{
|
||||
if (property instanceof CmisPropertyString)
|
||||
{
|
||||
aspectProperties.put(property.getPropertyDefinitionId(), ((CmisPropertyString) property).getValue()
|
||||
.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.ws.test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.xml.ws.Holder;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.alfresco.cmis.CMISDictionaryModel;
|
||||
import org.alfresco.repo.cmis.ws.CmisException;
|
||||
import org.alfresco.repo.cmis.ws.CmisExtensionType;
|
||||
import org.alfresco.repo.cmis.ws.CmisPropertiesType;
|
||||
import org.alfresco.repo.cmis.ws.CmisPropertyId;
|
||||
import org.alfresco.repo.cmis.ws.CmisPropertyString;
|
||||
import org.alfresco.repo.cmis.ws.ObjectServicePort;
|
||||
import org.alfresco.repo.cmis.ws.PolicyServicePort;
|
||||
import org.alfresco.repo.cmis.ws.RepositoryServicePort;
|
||||
import org.alfresco.repo.cmis.ws.VersioningServicePort;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.junit.Assert;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
/**
|
||||
* Base class for tests to Alfresco CMIS WebService API extensions.
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public abstract class BaseCMISTest extends TestCase
|
||||
{
|
||||
protected RepositoryServicePort repositoryServicePort;
|
||||
protected ObjectServicePort objectServicePort;
|
||||
protected VersioningServicePort versioningServicePort;
|
||||
protected PolicyServicePort policyServicePort;
|
||||
protected String defaultRunAs = "admin";
|
||||
protected String repositoryId;
|
||||
protected String testFolderId;
|
||||
|
||||
protected ApplicationContext ctx;
|
||||
|
||||
public BaseCMISTest()
|
||||
{
|
||||
ctx = ApplicationContextHelper.getApplicationContext(new String[]
|
||||
{
|
||||
ApplicationContextHelper.CONFIG_LOCATIONS[0], "classpath:alfresco/web-services-application-context.xml"
|
||||
});
|
||||
repositoryServicePort = (RepositoryServicePort) ctx.getBean("dmRepositoryService");
|
||||
objectServicePort = (ObjectServicePort) ctx.getBean("dmObjectService");
|
||||
versioningServicePort = (VersioningServicePort) ctx.getBean("dmVersioningService");
|
||||
policyServicePort = (PolicyServicePort) ctx.getBean("dmPolicyService");
|
||||
try
|
||||
{
|
||||
repositoryId = repositoryServicePort.getRepositories(null).get(0).getRepositoryId();
|
||||
}
|
||||
catch (CmisException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDefaultRunAs(String defaultRunAs)
|
||||
{
|
||||
this.defaultRunAs = defaultRunAs;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(defaultRunAs);
|
||||
String rootFolderId = repositoryServicePort.getRepositoryInfo(repositoryId, null).getRootFolderId();
|
||||
Holder<String> objectId = new Holder<String>();
|
||||
String folderName = getClass().getSimpleName() + System.currentTimeMillis() + " - " + getName();
|
||||
objectServicePort.createFolder(repositoryId, createObjectProperties(folderName, "cmis:folder"), rootFolderId,
|
||||
null, null, null, new Holder<CmisExtensionType>(), objectId);
|
||||
testFolderId = objectId.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
protected CmisPropertiesType createObjectProperties(String name, String type)
|
||||
{
|
||||
CmisPropertiesType properties = new CmisPropertiesType();
|
||||
CmisPropertyString stringProperty = new CmisPropertyString();
|
||||
stringProperty.setPropertyDefinitionId(CMISDictionaryModel.PROP_NAME);
|
||||
stringProperty.getValue().add(name);
|
||||
properties.getProperty().add(stringProperty);
|
||||
CmisPropertyId idProperty = new CmisPropertyId();
|
||||
idProperty.setPropertyDefinitionId(CMISDictionaryModel.PROP_OBJECT_TYPE_ID);
|
||||
idProperty.getValue().add(type);
|
||||
properties.getProperty().add(idProperty);
|
||||
return properties;
|
||||
}
|
||||
|
||||
protected void setStringProperty(CmisPropertiesType properties, String id, String value)
|
||||
{
|
||||
CmisPropertyString stringProperty = new CmisPropertyString();
|
||||
properties.getProperty().add(stringProperty);
|
||||
stringProperty.setPropertyDefinitionId(id);
|
||||
stringProperty.getValue().add(value);
|
||||
}
|
||||
|
||||
protected void assertContains(Set<String> actual, String... expected)
|
||||
{
|
||||
Assert.assertTrue(actual.containsAll(Arrays.asList(expected)));
|
||||
}
|
||||
|
||||
protected void assertDoesNotContain(Set<String> actual, String... unexpected)
|
||||
{
|
||||
Set<String> copy = new HashSet<String>(actual);
|
||||
copy.retainAll(Arrays.asList(unexpected));
|
||||
Assert.assertTrue(copy.isEmpty());
|
||||
}
|
||||
}
|
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.cmis.ws.test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.ws.Holder;
|
||||
|
||||
import org.alfresco.repo.cmis.ws.CmisException;
|
||||
import org.alfresco.repo.cmis.ws.CmisExtensionType;
|
||||
import org.alfresco.repo.cmis.ws.CmisObjectType;
|
||||
import org.alfresco.repo.cmis.ws.CmisTypeDefinitionListType;
|
||||
import org.alfresco.repo.cmis.ws.CmisTypeDefinitionType;
|
||||
import org.alfresco.repo.cmis.ws.EnumServiceException;
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* Tests Alfresco CMIS Policy Web Service implementation.
|
||||
*
|
||||
* @author dward
|
||||
*/
|
||||
public class PolicyTest extends BaseCMISTest
|
||||
{
|
||||
public void testPolicies() throws Exception
|
||||
{
|
||||
// Try creating an object with the cmis:policy base type (expect a constraint exception)
|
||||
Holder<String> objectId = new Holder<String>();
|
||||
try
|
||||
{
|
||||
objectServicePort.createPolicy(repositoryId, createObjectProperties(getName(), "cmis:policy"),
|
||||
testFolderId, null, null, null, new Holder<CmisExtensionType>(), objectId);
|
||||
fail("Expected CmisException");
|
||||
}
|
||||
catch (CmisException e)
|
||||
{
|
||||
Assert.assertEquals(EnumServiceException.CONSTRAINT, e.getFaultInfo().getType());
|
||||
}
|
||||
|
||||
// Try creating an object of any of the cmis:policy subtypes
|
||||
CmisTypeDefinitionListType typeDefs = repositoryServicePort.getTypeChildren(repositoryId, "cmis:policy", true,
|
||||
null, null, null);
|
||||
List<CmisTypeDefinitionType> entries = typeDefs.getTypes();
|
||||
assertNotSame(0, entries.size());
|
||||
for (CmisTypeDefinitionType type : entries)
|
||||
{
|
||||
try
|
||||
{
|
||||
objectServicePort.createPolicy(repositoryId, createObjectProperties(getName(), type.getId()),
|
||||
testFolderId, null, null, null, new Holder<CmisExtensionType>(), objectId);
|
||||
fail("Expected CmisException");
|
||||
}
|
||||
catch (CmisException e)
|
||||
{
|
||||
Assert.assertEquals(EnumServiceException.CONSTRAINT, e.getFaultInfo().getType());
|
||||
}
|
||||
}
|
||||
|
||||
// Create a document to attempt to apply policies to
|
||||
objectServicePort.createDocument(repositoryId, createObjectProperties(getName(), "cmis:document"),
|
||||
testFolderId, null, null, null, null, null, new Holder<CmisExtensionType>(), objectId);
|
||||
Assert.assertNotNull(objectId.value);
|
||||
|
||||
// retrieve list of policies applied to document (this should be empty)
|
||||
List<CmisObjectType> policies = policyServicePort.getAppliedPolicies(repositoryId, objectId.value, null, null);
|
||||
assertNotNull(policies);
|
||||
assertEquals(0, policies.size());
|
||||
|
||||
// Try applying a policy (expect a constraint exception)
|
||||
try
|
||||
{
|
||||
policyServicePort
|
||||
.applyPolicy(repositoryId, "doesnotexist", objectId.value, new Holder<CmisExtensionType>());
|
||||
fail("Expected CmisException");
|
||||
}
|
||||
catch (CmisException e)
|
||||
{
|
||||
Assert.assertEquals(EnumServiceException.CONSTRAINT, e.getFaultInfo().getType());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -1,182 +0,0 @@
|
||||
package org.alfresco.repo.cmis.ws.test;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
import javax.activation.DataHandler;
|
||||
import javax.xml.ws.Holder;
|
||||
|
||||
import org.alfresco.cmis.CMISDictionaryModel;
|
||||
import org.alfresco.repo.cmis.ws.CmisContentStreamType;
|
||||
import org.alfresco.repo.cmis.ws.CmisException;
|
||||
import org.alfresco.repo.cmis.ws.CmisExtensionType;
|
||||
import org.alfresco.repo.cmis.ws.CmisObjectInFolderListType;
|
||||
import org.alfresco.repo.cmis.ws.CmisObjectInFolderType;
|
||||
import org.alfresco.repo.cmis.ws.CmisObjectType;
|
||||
import org.alfresco.repo.cmis.ws.CmisPropertiesType;
|
||||
import org.alfresco.repo.cmis.ws.CmisProperty;
|
||||
import org.alfresco.repo.cmis.ws.CmisPropertyId;
|
||||
import org.alfresco.repo.cmis.ws.CmisPropertyString;
|
||||
import org.alfresco.repo.cmis.ws.DiscoveryServicePort;
|
||||
import org.alfresco.repo.cmis.ws.EnumVersioningState;
|
||||
import org.alfresco.repo.cmis.ws.NavigationServicePort;
|
||||
import org.alfresco.repo.cmis.ws.ObjectFactory;
|
||||
import org.alfresco.repo.cmis.ws.Query;
|
||||
import org.alfresco.repo.cmis.ws.QueryResponse;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
|
||||
/**
|
||||
* The test of paging support of results of DMDiscoveryServicePort.query()
|
||||
*
|
||||
* @author Arseny Kovalchuk
|
||||
*/
|
||||
public class QueryPagingTest extends BaseCMISTest
|
||||
{
|
||||
private static final int NUMBER_OF_DOCUMENTS = 50;
|
||||
private static final String QUERY_DOCUMENTS_TEMPLATE = "select * from cmis:document d where in_folder('%1$s')";
|
||||
|
||||
private static final ObjectFactory OBJECT_FACTORY = new ObjectFactory();
|
||||
|
||||
private String queryDocuments;
|
||||
|
||||
protected DiscoveryServicePort discoveryServicePort;
|
||||
protected NavigationServicePort navigationServicePort;
|
||||
|
||||
public QueryPagingTest()
|
||||
{
|
||||
super();
|
||||
discoveryServicePort = (DiscoveryServicePort) ctx.getBean("dmDiscoveryService");
|
||||
navigationServicePort = (NavigationServicePort) ctx.getBean("dmNavigationService");
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
queryDocuments = String.format(QUERY_DOCUMENTS_TEMPLATE, testFolderId);
|
||||
//System.out.println(queryDocuments);
|
||||
}
|
||||
|
||||
/**
|
||||
* The main reason for this test is ALF-9566
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testPagingSupport() throws Exception
|
||||
{
|
||||
clearDocumentsInFolder(testFolderId);
|
||||
|
||||
createDocumentsInFolder(testFolderId, NUMBER_OF_DOCUMENTS);
|
||||
|
||||
// Select 10 of NUMBER_OF_DOCUMENTS, 0 documents to skip, so NUMBER_OF_DOCUMENTS - 10 still available
|
||||
int skipCount = 0;
|
||||
int maxItems = 10;
|
||||
QueryResponse response = discoveryServicePort.query(createQuery(maxItems, skipCount));
|
||||
assertEquals(NUMBER_OF_DOCUMENTS - skipCount, response.getObjects().getNumItems().intValue());
|
||||
assertEquals(maxItems, response.getObjects().getObjects().size());
|
||||
assertTrue(response.getObjects().isHasMoreItems());
|
||||
|
||||
// Select 10 of NUMBER_OF_DOCUMENTS, 10 documents to skip, so NUMBER_OF_DOCUMENTS - 10 - 10 still available
|
||||
skipCount = 10;
|
||||
maxItems = 10;
|
||||
response = discoveryServicePort.query(createQuery(maxItems, skipCount));
|
||||
assertEquals(NUMBER_OF_DOCUMENTS - skipCount, response.getObjects().getNumItems().intValue());
|
||||
assertEquals(maxItems, response.getObjects().getObjects().size());
|
||||
assertTrue(response.getObjects().isHasMoreItems());
|
||||
|
||||
// Select 10 of NUMBER_OF_DOCUMENTS, NUMBER_OF_DOCUMENTS - 10 to skip, so there are no docs available
|
||||
skipCount = NUMBER_OF_DOCUMENTS - 10;
|
||||
maxItems = 10;
|
||||
response = discoveryServicePort.query(createQuery(maxItems, skipCount));
|
||||
assertEquals(NUMBER_OF_DOCUMENTS - skipCount, response.getObjects().getNumItems().intValue());
|
||||
assertEquals(maxItems, response.getObjects().getObjects().size());
|
||||
assertFalse(response.getObjects().isHasMoreItems());
|
||||
|
||||
// Select NUMBER_OF_DOCUMENTS to select, 0 to skip, so, there are no docs available
|
||||
skipCount = 0;
|
||||
maxItems = NUMBER_OF_DOCUMENTS;
|
||||
response = discoveryServicePort.query(createQuery(maxItems, skipCount));
|
||||
assertEquals(NUMBER_OF_DOCUMENTS - skipCount, response.getObjects().getNumItems().intValue());
|
||||
assertEquals(maxItems, response.getObjects().getObjects().size());
|
||||
assertFalse(response.getObjects().isHasMoreItems());
|
||||
|
||||
clearDocumentsInFolder(testFolderId);
|
||||
}
|
||||
|
||||
protected void createDocumentsInFolder(String folderId, int docsCount) throws Exception
|
||||
{
|
||||
for (int i = 0; i < NUMBER_OF_DOCUMENTS; i++)
|
||||
{
|
||||
String docName = "Test Document " + i + ".txt";
|
||||
//System.out.println("Creating " + docName);
|
||||
createDocument(docName, folderId);
|
||||
}
|
||||
}
|
||||
|
||||
protected void clearDocumentsInFolder(String folderId) throws CmisException
|
||||
{
|
||||
CmisObjectInFolderListType result = navigationServicePort.getChildren(repositoryId, testFolderId, "*", null, false, null, null, false, BigInteger.valueOf(-1),
|
||||
BigInteger.ZERO, null);
|
||||
if (!result.getObjects().isEmpty())
|
||||
{
|
||||
for(CmisObjectInFolderType obj : result.getObjects())
|
||||
{
|
||||
String documentId = getObjectId(obj.getObject());
|
||||
//System.out.println("Deleting document with ID:" + documentId);
|
||||
objectServicePort.deleteObject(repositoryId, documentId, true, new Holder<CmisExtensionType>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String getObjectId(CmisObjectType object)
|
||||
{
|
||||
CmisPropertiesType propertiesType = object.getProperties();
|
||||
for(CmisProperty property : propertiesType.getProperty())
|
||||
{
|
||||
if ((property instanceof CmisPropertyId) && CMISDictionaryModel.PROP_OBJECT_ID.equals(property.getPropertyDefinitionId()))
|
||||
{
|
||||
return ((CmisPropertyId) property).getValue().iterator().next();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String createDocument(String name, String parentFolderId) throws Exception
|
||||
{
|
||||
String content = "This is a test content";
|
||||
CmisPropertiesType properties = new CmisPropertiesType();
|
||||
List<CmisProperty> propertiesList = properties.getProperty();
|
||||
CmisPropertyString cmisProperty = new CmisPropertyString();
|
||||
cmisProperty.setPropertyDefinitionId(CMISDictionaryModel.PROP_NAME);
|
||||
cmisProperty.getValue().add(name);
|
||||
CmisPropertyId idProperty = new CmisPropertyId();
|
||||
idProperty.setPropertyDefinitionId(CMISDictionaryModel.PROP_OBJECT_TYPE_ID);
|
||||
idProperty.getValue().add(CMISDictionaryModel.DOCUMENT_TYPE_ID.getId());
|
||||
|
||||
propertiesList.add(cmisProperty);
|
||||
propertiesList.add(idProperty);
|
||||
|
||||
CmisContentStreamType cmisStream = new CmisContentStreamType();
|
||||
cmisStream.setFilename(name);
|
||||
cmisStream.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
|
||||
DataHandler dataHandler = new DataHandler(content, MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
||||
cmisStream.setStream(dataHandler);
|
||||
|
||||
Holder<CmisExtensionType> extensions = new Holder<CmisExtensionType>();
|
||||
Holder<String> idHolder = new Holder<String>();
|
||||
objectServicePort.createDocument(repositoryId, properties, parentFolderId, cmisStream, EnumVersioningState.MAJOR, null, null, null, extensions, idHolder);
|
||||
return idHolder.value;
|
||||
}
|
||||
|
||||
private Query createQuery(int maxItems, int skipCount)
|
||||
{
|
||||
Query parameters = new Query();
|
||||
parameters.setRepositoryId(repositoryId);
|
||||
parameters.setStatement(queryDocuments);
|
||||
parameters.setSkipCount(OBJECT_FACTORY.createQuerySkipCount(BigInteger.valueOf(skipCount)));
|
||||
parameters.setMaxItems(OBJECT_FACTORY.createQueryMaxItems(BigInteger.valueOf(maxItems)));
|
||||
parameters.setIncludeAllowableActions(OBJECT_FACTORY.createQueryIncludeAllowableActions(Boolean.FALSE));
|
||||
parameters.setSearchAllVersions(OBJECT_FACTORY.createQuerySearchAllVersions(Boolean.FALSE));
|
||||
return parameters;
|
||||
}
|
||||
|
||||
}
|
@@ -225,9 +225,10 @@ public class QuickShareRestApiTest extends BaseWebScriptTest
|
||||
assertEquals(TEST_MIMETYPE_JPEG, mimetype);
|
||||
|
||||
// get content for node (authenticated)
|
||||
rsp = sendRequest(new GetRequest(AUTH_CONTENT_URL.replace("{node_ref_3}", testNodeRef_3)), expectedStatusOK, USER_ONE);
|
||||
byte[] content = rsp.getContentAsByteArray();
|
||||
checkBytes(TEST_CONTENT, content);
|
||||
// Commented out when removing original CMIS impl
|
||||
// rsp = sendRequest(new GetRequest(AUTH_CONTENT_URL.replace("{node_ref_3}", testNodeRef_3)), expectedStatusOK, USER_ONE);
|
||||
// byte[] content = rsp.getContentAsByteArray();
|
||||
// checkBytes(TEST_CONTENT, content);
|
||||
|
||||
// get content thumbnail for node (authenticated)
|
||||
rsp = sendRequest(new GetRequest(AUTH_CONTENT_THUMBNAIL_URL.replace("{node_ref_3}", testNodeRef_3).replace("{thumbnailname}", "doclib")), expectedStatusOK, USER_ONE);
|
||||
@@ -237,7 +238,8 @@ public class QuickShareRestApiTest extends BaseWebScriptTest
|
||||
// As user two ...
|
||||
|
||||
rsp = sendRequest(new GetRequest(AUTH_METADATA_URL.replace("{node_ref_3}", testNodeRef_3)), expectedStatusServerError, USER_TWO);
|
||||
rsp = sendRequest(new GetRequest(AUTH_CONTENT_URL.replace("{node_ref_3}", testNodeRef_3)), expectedStatusForbidden, USER_TWO);
|
||||
// Commented out when removing original CMIS impl
|
||||
// rsp = sendRequest(new GetRequest(AUTH_CONTENT_URL.replace("{node_ref_3}", testNodeRef_3)), expectedStatusForbidden, USER_TWO);
|
||||
rsp = sendRequest(new GetRequest(AUTH_CONTENT_THUMBNAIL_URL.replace("{node_ref_3}", testNodeRef_3).replace("{thumbnailname}", "doclib")), expectedStatusServerError, USER_TWO);
|
||||
|
||||
// As user one ...
|
||||
@@ -261,7 +263,7 @@ public class QuickShareRestApiTest extends BaseWebScriptTest
|
||||
|
||||
// get content for share (note: can be unauthenticated)
|
||||
rsp = sendRequest(new GetRequest(SHARE_CONTENT_URL.replace("{shared_id}", sharedId)), expectedStatusOK, USER_TWO);
|
||||
content = rsp.getContentAsByteArray();
|
||||
byte[] content = rsp.getContentAsByteArray();
|
||||
checkBytes(TEST_CONTENT, content);
|
||||
|
||||
// get content thumbnail for share (note: can be unauthenticated)
|
||||
|
Reference in New Issue
Block a user