use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class CreateBigDocument method run.
@Override
public void run(Session session) {
CmisTestResult f;
// create a test folder
Folder testFolder = createTestFolder(session);
try {
String name = "bigdoc";
String objectTypeId = getDocumentTestTypeId();
String mimetype = "application/octet-stream";
// 10 MiB
final long size = 10 * 1024 * 1024;
InputStream in = new InputStream() {
private int counter = -1;
@Override
public int read() throws IOException {
counter++;
if (counter >= size) {
return -1;
}
return '0' + (counter / 10);
}
};
// create stream and properties
ContentStream contentStream = session.getObjectFactory().createContentStream(name, size, mimetype, in);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
// check type
TypeDefinition type = session.getTypeDefinition(objectTypeId);
if (!(type instanceof DocumentTypeDefinition)) {
addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
return;
}
DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
// create and fetch the document
ObjectId id = session.createDocument(properties, testFolder, contentStream, versioningState);
Document doc = (Document) session.getObject(id, SELECT_ALL_NO_CACHE_OC);
// check the new document
addResult(checkObject(session, doc, getAllProperties(doc), "New document object spec compliance"));
// check the size
f = createResult(FAILURE, "Content stream length doesn't match the uploaded content!", true);
assertEquals(size, doc.getContentStreamLength(), null, f);
// delete it
// doc.delete(true);
} finally {
// delete the test folder
// deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class RepositoryInfoTest method run.
@Override
public void run(Session session) {
CmisTestResult success;
CmisTestResult failure;
RepositoryInfo ri = getRepositoryInfo(session);
// ID
success = createResult(OK, "Repository ID: " + ri.getId());
failure = createResult(FAILURE, "Repository id is not set!", true);
addResult(assertStringNotEmpty(ri.getId(), success, failure));
// name
failure = createResult(FAILURE, "Repository name is not set!");
addResult(assertNotNull(ri.getName(), null, failure));
success = createResult(OK, "Repository name: " + ri.getName());
failure = createResult(WARNING, "Repository name is empty!");
addResult(assertStringNotEmpty(ri.getName(), success, failure));
// description
failure = createResult(FAILURE, "Repository description is not set!");
addResult(assertNotNull(ri.getDescription(), null, failure));
success = createResult(OK, "Repository description: " + ri.getDescription());
failure = createResult(WARNING, "Repository description is empty!");
addResult(assertStringNotEmpty(ri.getDescription(), success, failure));
// vendor
failure = createResult(FAILURE, "Vendor name is not set!");
addResult(assertStringNotEmpty(ri.getVendorName(), null, failure));
success = createResult(OK, "Vendor name: " + ri.getVendorName());
failure = createResult(WARNING, "Vendor name is empty!");
addResult(assertStringNotEmpty(ri.getVendorName(), success, failure));
// product name
failure = createResult(FAILURE, "Product name is not set!");
addResult(assertStringNotEmpty(ri.getProductName(), null, failure));
success = createResult(OK, "Product name: " + ri.getProductName());
failure = createResult(WARNING, "Product name is empty!");
addResult(assertStringNotEmpty(ri.getProductName(), success, failure));
// product version
failure = createResult(FAILURE, "Product version is not set!");
addResult(assertStringNotEmpty(ri.getProductVersion(), null, failure));
success = createResult(OK, "Product version: " + ri.getProductVersion());
failure = createResult(WARNING, "Product version is empty!");
addResult(assertStringNotEmpty(ri.getProductVersion(), success, failure));
// CMIS version supported
success = createResult(OK, "CMIS Version Supported: " + ri.getCmisVersionSupported());
failure = createResult(FAILURE, "CMIS Version Supported is not set!");
addResult(assertStringNotEmpty(ri.getCmisVersionSupported(), success, failure));
if (!"1.0".equals(ri.getCmisVersionSupported()) && !"1.1".equals(ri.getCmisVersionSupported())) {
addResult(createResult(FAILURE, "CMIS Version Supported is neither '1.0' nor '1.1'!"));
}
// root folder
success = createResult(OK, "Root folder ID: " + ri.getRootFolderId());
failure = createResult(FAILURE, "Root folder ID is not set!");
addResult(assertStringNotEmpty(ri.getRootFolderId(), success, failure));
// thin client URI
success = createResult(OK, "Thin client URI: " + ri.getThinClientUri());
failure = createResult(WARNING, "Thin client URI is not set!");
addResult(assertStringNotEmpty(ri.getThinClientUri(), success, failure));
if (ri.getThinClientUri() != null && ri.getThinClientUri().length() > 0) {
try {
HttpURLConnection conn = (HttpURLConnection) (new URL(ri.getThinClientUri())).openConnection();
conn.connect();
int responseCode = conn.getResponseCode();
failure = createResult(WARNING, "Unable to connect to thin client '" + ri.getThinClientUri() + "'. HTTP status code: " + responseCode);
addResult(assertIsTrue(responseCode >= 200 && responseCode < 400, null, failure));
conn.disconnect();
} catch (Exception e) {
addResult(createResult(WARNING, "Unable to connect to thin client '" + ri.getThinClientUri() + "': " + e.getMessage(), e, false));
}
}
// principal ID anonymous
success = createResult(OK, "Principal ID anonymous: " + ri.getPrincipalIdAnonymous());
failure = createResult(WARNING, "Principal ID anonymous is not set!");
addResult(assertStringNotEmpty(ri.getPrincipalIdAnonymous(), success, failure));
// principal ID anyone
success = createResult(OK, "Principal ID anyone: " + ri.getPrincipalIdAnyone());
failure = createResult(WARNING, "Principal Id anyone is not set!");
addResult(assertStringNotEmpty(ri.getPrincipalIdAnyone(), success, failure));
// latest change log token
success = createResult(OK, "Latest change log token: " + ri.getLatestChangeLogToken());
failure = createResult(WARNING, "Latest change log token is not set!");
addResult(assertStringNotEmpty(ri.getLatestChangeLogToken(), success, failure));
// changes incomplete
success = createResult(OK, "Changes Incomplete: " + ri.getChangesIncomplete());
failure = createResult(WARNING, "Changes Incomplete is not set!");
addResult(assertNotNull(ri.getChangesIncomplete(), success, failure));
// changes on type
success = createResult(OK, "Changes on type: " + ri.getChangesOnType());
failure = createResult(WARNING, "Changes on type is not set!");
addResult(assertNotNull(ri.getChangesOnType(), success, failure));
if (ri.getChangesOnType() != null) {
failure = createResult(WARNING, "Changes on type has more than 4 entries!");
addResult(assertIsTrue(ri.getChangesOnType().size() < 5, null, failure));
}
// features
if (ri.getCmisVersion() != CmisVersion.CMIS_1_0) {
success = createResult(OK, "Repository features exposed.");
failure = createResult(OK, "No repository features exposed.");
addResult(assertNotNull(ri.getExtensionFeatures(), success, failure));
if (ri.getExtensionFeatures() != null) {
for (ExtensionFeature feature : ri.getExtensionFeatures()) {
failure = createResult(FAILURE, "At least one repository features has no ID!");
addResult(assertStringNotEmpty(feature.getId(), null, failure));
}
}
}
// capabilities
if (ri.getCapabilities() == null) {
addResult(createResult(FAILURE, "Capabilities are not set!"));
} else {
RepositoryCapabilities cap = ri.getCapabilities();
// ACL capability
success = createResult(OK, "ACL capability: " + cap.getAclCapability());
failure = createResult(FAILURE, "ACL capability is not set!");
addResult(assertNotNull(cap.getAclCapability(), success, failure));
// changes capability
success = createResult(OK, "Changes capability: " + cap.getChangesCapability());
failure = createResult(WARNING, "Changes capability is not set!");
addResult(assertNotNull(cap.getChangesCapability(), success, failure));
// content stream updates capability
success = createResult(OK, "Content stream updates capability: " + cap.getContentStreamUpdatesCapability());
failure = createResult(FAILURE, "Content stream updates is not set!");
addResult(assertNotNull(cap.getContentStreamUpdatesCapability(), success, failure));
// get descendants capability
success = createResult(OK, "Get descendants capability: " + cap.isGetDescendantsSupported());
failure = createResult(FAILURE, "Get descendants capability is not set!");
addResult(assertNotNull(cap.isGetDescendantsSupported(), success, failure));
// get folder tree capability
success = createResult(OK, "Get folder tree capability: " + cap.isGetFolderTreeSupported());
failure = createResult(FAILURE, "Get folder tree capability is not set!");
addResult(assertNotNull(cap.isGetFolderTreeSupported(), success, failure));
// multifiling capability
success = createResult(OK, "Multifiling capability: " + cap.isMultifilingSupported());
failure = createResult(FAILURE, "Multifiling capability is not set!");
addResult(assertNotNull(cap.isMultifilingSupported(), success, failure));
// unfiling capability
success = createResult(OK, "Unfiling capability: " + cap.isUnfilingSupported());
failure = createResult(FAILURE, "Unfiling capability is not set!");
addResult(assertNotNull(cap.isUnfilingSupported(), success, failure));
// version specific filing capability
success = createResult(OK, "Version specific filing capability: " + cap.isVersionSpecificFilingSupported());
failure = createResult(FAILURE, "Version specific filing capability is not set!");
addResult(assertNotNull(cap.isVersionSpecificFilingSupported(), success, failure));
// query capability
success = createResult(OK, "Query capability: " + cap.getQueryCapability());
failure = createResult(FAILURE, "Query capability is not set!");
addResult(assertNotNull(cap.getQueryCapability(), success, failure));
// JOIN capability
success = createResult(OK, "JOIN capability: " + cap.getJoinCapability());
failure = createResult(FAILURE, "JOIN capability is not set!");
addResult(assertNotNull(cap.getJoinCapability(), success, failure));
// all versions searchable capability
success = createResult(OK, "All versions searchable capability: " + cap.isAllVersionsSearchableSupported());
failure = createResult(FAILURE, "All versions searchable capability is not set!");
addResult(assertNotNull(cap.isAllVersionsSearchableSupported(), success, failure));
// PWC searchable capability
success = createResult(OK, "PWC searchable capability: " + cap.isPwcSearchableSupported());
failure = createResult(FAILURE, "PWC searchable capability is not set!");
addResult(assertNotNull(cap.isPwcSearchableSupported(), success, failure));
// PWC updatable capability
success = createResult(OK, "PWC updatable capability: " + cap.isPwcUpdatableSupported());
failure = createResult(FAILURE, "PWC updatable capability is not set!");
addResult(assertNotNull(cap.isPwcUpdatableSupported(), success, failure));
// renditions capability
success = createResult(OK, "Renditions capability: " + cap.getRenditionsCapability());
failure = createResult(FAILURE, "Renditions capability is not set!");
addResult(assertNotNull(cap.getRenditionsCapability(), success, failure));
if (ri.getCmisVersion() != CmisVersion.CMIS_1_0) {
// new type settable attributes
success = createResult(OK, "'New type settable attributes' flags are set.");
failure = createResult(WARNING, "'New type settable attributes' flags are not set!");
addResult(assertNotNull(cap.getNewTypeSettableAttributes(), success, failure));
// creatable property types
success = createResult(OK, "'Creatable property types' flags are set.");
failure = createResult(WARNING, "'Creatable property types' flags are not set!");
addResult(assertNotNull(cap.getCreatablePropertyTypes(), success, failure));
}
}
// ACL capabilities
if (ri.getAclCapabilities() == null) {
addResult(createResult(WARNING, "ACL capabilities are not set!"));
} else {
AclCapabilities aclCap = ri.getAclCapabilities();
// supported permissions
success = createResult(OK, "Supported permissions: " + aclCap.getSupportedPermissions());
failure = createResult(WARNING, "Supported permissions are not set!");
addResult(assertNotNull(aclCap.getSupportedPermissions(), success, failure));
// ACL propagation
success = createResult(OK, "ACL propagation: " + aclCap.getAclPropagation());
failure = createResult(WARNING, "ACL propagation is not set!");
addResult(assertNotNull(aclCap.getAclPropagation(), success, failure));
// permissions
success = createResult(OK, "Permissions: " + (aclCap.getPermissions() == null ? "?" : aclCap.getPermissions().size()));
failure = createResult(FAILURE, "Permissions are not set!");
addResult(assertNotNull(aclCap.getPermissions(), success, failure));
if (aclCap.getPermissions() != null) {
int i = 0;
for (PermissionDefinition permDef : aclCap.getPermissions()) {
failure = createResult(FAILURE, "Permission #" + i + " is not set!");
addResult(assertNotNull(permDef, null, failure));
if (permDef != null) {
failure = createResult(FAILURE, "ID of permission #" + i + " is not set!");
addResult(assertStringNotEmpty(permDef.getId(), null, failure));
}
i++;
}
}
// permission mapping
success = createResult(OK, "Permission mapping: " + (aclCap.getPermissionMapping() == null ? "?" : aclCap.getPermissionMapping().size()));
failure = createResult(WARNING, "Permission mapping is not set!");
addResult(assertNotNull(aclCap.getPermissionMapping(), success, failure));
}
if (ri.getExtensionFeatures() != null) {
for (ExtensionFeature ef : ri.getExtensionFeatures()) {
success = createResult(OK, "Extension Feature: " + ef.getId());
failure = createResult(FAILURE, "Extension Feature without ID!");
addResult(assertStringNotEmpty(ef.getId(), success, failure));
failure = createResult(WARNING, "Extension Feature without common name: " + ef.getId());
addResult(assertStringNotEmpty(ef.getCommonName(), null, failure));
failure = createResult(WARNING, "Extension Feature without version label: " + ef.getId());
addResult(assertStringNotEmpty(ef.getVersionLabel(), null, failure));
failure = createResult(WARNING, "Extension Feature without URL: " + ef.getId());
addResult(assertStringNotEmpty(ef.getUrl(), null, failure));
}
}
}
use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class ACLSmokeTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
if (supportsACLs(session)) {
try {
// create folder and document
Folder testFolder = createTestFolder(session);
Document doc = createDocument(session, testFolder, "acltest.txt", "ACL test");
// check if there is an ACL
Acl acl = doc.getAcl();
f = createResult(FAILURE, "ACLs are supported but newly created document has no ACL!");
addResult(assertNotNull(acl, null, f));
// check basic permissions
Acl basicAcl = session.getAcl(doc, true);
f = createResult(FAILURE, "ACLs are supported but repository does not return a basic ACL for the newly created document!");
addResult(assertNotNull(basicAcl, null, f));
if (basicAcl != null) {
addResult(checkACL(session, basicAcl, false, "Basic ACL"));
if (basicAcl.getAces() != null) {
for (Ace ace : basicAcl.getAces()) {
if (ace.getPermissions() != null) {
for (String permission : ace.getPermissions()) {
if (!"cmis:read".equals(permission) && !"cmis:write".equals(permission) && !"cmis:all".equals(permission)) {
addResult(createResult(FAILURE, "ACE contains a non-basic permission: " + permission));
}
}
}
}
}
}
if (getAclCapability(session) == CapabilityAcl.MANAGE && !Boolean.FALSE.equals(doc.getType().isControllableAcl())) {
String principal = getParameters().get(TestParameters.DEFAULT_ACL_PRINCIPAL);
if (principal == null) {
principal = TestParameters.DEFAULT_ACL_PRINCIPAL_VALUE;
}
// apply permission "cmis:write"
List<Ace> aces = new ArrayList<Ace>();
aces.add(session.getObjectFactory().createAce(principal, Collections.singletonList("cmis:write")));
session.applyAcl(doc, aces, null, null);
if (session.getRepositoryInfo().getAclCapabilities().getAclPropagation() != AclPropagation.REPOSITORYDETERMINED) {
// set permission "cmis:all"
aces = new ArrayList<Ace>();
aces.add(session.getObjectFactory().createAce(principal, Collections.singletonList("cmis:all")));
session.setAcl(doc, aces);
}
} else {
addResult(createResult(INFO, "The repository or the type '" + doc.getType().getId() + "' don't support managing ACLs."));
}
deleteObject(doc);
} finally {
deleteTestFolder();
}
} else {
addResult(createResult(SKIPPED, "ACLs are not supported. Test Skipped!"));
}
}
use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class AsyncCreateAndDeleteDocumentTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
int numOfDocuments = 100;
String mimeType = "text/plain";
byte[] contentBytes = new byte[64 * 1024];
for (int i = 0; i < contentBytes.length; i++) {
contentBytes[i] = (byte) ('0' + i % 10);
}
// create an async session
AsyncSession asyncSession = AsyncSessionFactoryImpl.newInstance().createAsyncSession(session, 10);
// create a test folder
Folder testFolder = createTestFolder(session);
try {
// create documents
List<Future<ObjectId>> docFutures = new ArrayList<Future<ObjectId>>();
for (int i = 0; i < numOfDocuments; i++) {
String name = "asyncdoc" + i + ".txt";
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, getDocumentTestTypeId());
ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(contentBytes.length), mimeType, new ByteArrayInputStream(contentBytes));
Future<ObjectId> newDocument = asyncSession.createDocument(properties, testFolder, contentStream, null);
docFutures.add(newDocument);
}
// wait for all document being created
List<ObjectId> docIds = new ArrayList<ObjectId>();
try {
for (Future<ObjectId> docFuture : docFutures) {
ObjectId id = docFuture.get();
docIds.add(id);
}
} catch (Exception e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Documents could not been created! Exception: " + e.getMessage(), e, true));
}
// check children of the test folder
int count = countChildren(testFolder);
f = createResult(FAILURE, "Test folder should have " + numOfDocuments + " children but has " + count + "!");
addResult(assertEquals(count, numOfDocuments, null, f));
// simple children test
addResult(checkChildren(session, testFolder, "Test folder children check"));
// get documents
Map<String, Future<CmisObject>> getObjectFutures = new HashMap<String, Future<CmisObject>>();
Map<String, Future<ContentStream>> contentStreamFutures = new HashMap<String, Future<ContentStream>>();
Map<String, ByteArrayOutputStream> content = new HashMap<String, ByteArrayOutputStream>();
for (ObjectId docId : docIds) {
Future<CmisObject> getObjectFuture = asyncSession.getObject(docId, SELECT_ALL_NO_CACHE_OC);
getObjectFutures.put(docId.getId(), getObjectFuture);
ByteArrayOutputStream out = new ByteArrayOutputStream(contentBytes.length);
content.put(docId.getId(), out);
Future<ContentStream> contentStreamFuture = asyncSession.storeContentStream(docId, out);
contentStreamFutures.put(docId.getId(), contentStreamFuture);
}
// wait for all document being fetched
try {
for (Map.Entry<String, Future<CmisObject>> getObjectFuture : getObjectFutures.entrySet()) {
CmisObject object = getObjectFuture.getValue().get();
f = createResult(FAILURE, "Fetching document failed!");
addResult(assertIsTrue(object instanceof Document, null, f));
if (object != null) {
f = createResult(FAILURE, "Fetched wrong document!");
addResult(assertEquals(getObjectFuture.getKey(), object.getId(), null, f));
}
}
} catch (Exception e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Documents could not been fetched! Exception: " + e.getMessage(), e, true));
}
// wait for all document content being fetched
try {
for (Map.Entry<String, Future<ContentStream>> contentStreamFuture : contentStreamFutures.entrySet()) {
ContentStream contentStream = contentStreamFuture.getValue().get();
f = createResult(FAILURE, "Fetching document content failed!");
addResult(assertNotNull(contentStream, null, f));
if (contentStream != null) {
if (contentStream.getMimeType() == null) {
addResult(createResult(FAILURE, "Content MIME type is null!"));
} else {
f = createResult(WARNING, "Content MIME types don't match!");
addResult(assertIsTrue(contentStream.getMimeType().trim().toLowerCase(Locale.ENGLISH).startsWith(mimeType.toLowerCase(Locale.ENGLISH)), null, f));
}
}
ByteArrayOutputStream out = content.get(contentStreamFuture.getKey());
byte[] readBytes = out.toByteArray();
f = createResult(FAILURE, "Read content length doesn't match document content length!");
addResult(assertEquals(contentBytes.length, readBytes.length, null, f));
f = createResult(FAILURE, "Read content doesn't match document content!");
addResult(assertEqualArray(contentBytes, readBytes, null, f));
}
} catch (Exception e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Document content could not been fetched! Exception: " + e.getMessage(), e, true));
}
// delete documents
List<Future<?>> delFutures = new ArrayList<Future<?>>();
for (ObjectId docId : docIds) {
Future<?> delFuture = asyncSession.delete(docId);
delFutures.add(delFuture);
}
// wait for all document being deleted
try {
for (Future<?> delFuture : delFutures) {
delFuture.get();
}
} catch (Exception e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Documents could not been deleted! Exception: " + e.getMessage(), e, true));
}
// check children of the test folder
count = countChildren(testFolder);
f = createResult(FAILURE, "Test folder should be empty but has " + count + " children!");
addResult(assertEquals(count, 0, null, f));
} finally {
// delete the test folder
deleteTestFolder();
if (asyncSession instanceof AbstractExecutorServiceAsyncSession<?>) {
((AbstractExecutorServiceAsyncSession<?>) asyncSession).shutdown();
}
}
addResult(createInfoResult("Tested the parallel creation and deletion of " + numOfDocuments + " documents."));
}
use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class CoreHtmlReport method printTestResults.
private void printTestResults(CmisTest test, Writer writer) throws IOException {
if (!test.isEnabled()) {
return;
}
writer.write("\n<h4>" + escape(test.getName()) + " (" + test.getTime() + " ms)</h4>\n");
if (test.getDescription() != null) {
writer.write("\n<p><i>" + escape(test.getDescription()) + "</i></p>\n");
}
if (test.getResults() != null) {
for (CmisTestResult result : test.getResults()) {
writer.write("<div style=\"padding: 5px;\">\n");
printResult(result, writer);
writer.write("</div>\n");
}
}
}
Aggregations