use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method createDocument.
/**
* Creates a document.
*/
protected Document createDocument(Session session, Folder parent, String name, String objectTypeId, String[] secondaryTypeIds, String content) {
if (parent == null) {
throw new IllegalArgumentException("Parent is not set!");
}
if (name == null) {
throw new IllegalArgumentException("Name is not set!");
}
if (objectTypeId == null) {
throw new IllegalArgumentException("Object Type ID is not set!");
}
if (content == null) {
content = "";
}
// check type
ObjectType type;
try {
type = session.getTypeDefinition(objectTypeId);
} catch (CmisObjectNotFoundException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Document type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
return null;
}
if (Boolean.FALSE.equals(type.isCreatable())) {
addResult(createResult(SKIPPED, "Document type '" + objectTypeId + "' is not creatable!", true));
return null;
}
// create
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
if (secondaryTypeIds != null) {
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, Arrays.asList(secondaryTypeIds));
}
type = session.getTypeDefinition(objectTypeId);
if (!(type instanceof DocumentTypeDefinition)) {
addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
return null;
}
DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
byte[] contentBytes = null;
Document result = null;
try {
contentBytes = IOUtils.toUTF8Bytes(content);
ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes));
// create the document
result = parent.createDocument(properties, contentStream, versioningState, null, null, null, SELECT_ALL_NO_CACHE_OC);
contentStream.getStream().close();
} catch (Exception e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Document could not be created! Exception: " + e.getMessage(), e, true));
return null;
}
try {
CmisTestResult f;
// check document name
f = createResult(FAILURE, "Document name does not match!", false);
addResult(assertEquals(name, result.getName(), null, f));
// check content length
f = createResult(WARNING, "Content length does not match!", false);
addResult(assertEquals((long) contentBytes.length, result.getContentStreamLength(), null, f));
// check the new document
addResult(checkObject(session, result, getAllProperties(result), "New document object spec compliance"));
// check content
try {
ContentStream contentStream = result.getContentStream();
f = createResult(WARNING, "Document filename and the filename of the content stream do not match!", false);
addResult(assertEquals(name, contentStream.getFileName(), null, f));
f = createResult(WARNING, "cmis:contentStreamFileName and the filename of the content stream do not match!", false);
addResult(assertEquals(result.getContentStreamFileName(), contentStream.getFileName(), null, f));
String fetchedContent = getStringFromContentStream(result.getContentStream());
if (!content.equals(fetchedContent)) {
addResult(createResult(FAILURE, "Content of newly created document doesn't match the orign content!"));
}
} catch (IOException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Content of newly created document couldn't be read! Exception: " + e.getMessage(), e, true));
}
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created document is invalid! Exception: " + e.getMessage(), e, true));
}
// check parents
List<Folder> parents = result.getParents(SELECT_ALL_NO_CACHE_OC);
boolean found = false;
for (Folder folder : parents) {
if (parent.getId().equals(folder.getId())) {
found = true;
break;
}
}
if (!found) {
addResult(createResult(FAILURE, "The folder the document has been created in is not in the list of the document parents!"));
}
return result;
}
use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method checkTypeDefinition.
protected CmisTestResult checkTypeDefinition(Session session, TypeDefinition type, String message) {
List<CmisTestResult> results = new ArrayList<CmisTestResult>();
CmisTestResult f;
f = createResult(FAILURE, "Type is null!");
addResult(results, assertNotNull(type, null, f));
if (type != null) {
f = createResult(FAILURE, "Type ID is not set!");
addResult(results, assertStringNotEmpty(type.getId(), null, f));
f = createResult(FAILURE, "Base type ID is not set!");
addResult(results, assertNotNull(type.getBaseTypeId(), null, f));
f = createResult(FAILURE, "Local name is not set!");
addResult(results, assertStringNotEmpty(type.getLocalName(), null, f));
// f = createResult(FAILURE, "Local namespace is not set!");
// addResult(results, assertStringNotEmpty(type.(), null, f));
boolean isQueryNameRequired = Boolean.TRUE.equals(type.isQueryable());
addResult(results, checkQueryName(type.getQueryName(), isQueryNameRequired, "Type Query Name: " + type.getQueryName()));
if ((type.getId() != null) && (type.getBaseTypeId() != null)) {
if (type.getBaseTypeId().value().equals(type.getId())) {
f = createResult(FAILURE, "Base type has parent type!");
addResult(results, assertStringNullOrEmpty(type.getParentTypeId(), null, f));
f = createResult(FAILURE, "Query name of base type is wrong!");
addResult(results, assertEquals(type.getId(), type.getQueryName(), null, f));
} else {
f = createResult(FAILURE, "Parent type is not set!");
addResult(results, assertStringNotEmpty(type.getParentTypeId(), null, f));
}
}
f = createResult(FAILURE, "Creatable flag is not set!");
addResult(results, assertNotNull(type.isCreatable(), null, f));
f = createResult(FAILURE, "Fileable flag is not set!");
addResult(results, assertNotNull(type.isFileable(), null, f));
f = createResult(FAILURE, "Controllable ACL flag is not set!");
addResult(results, assertNotNull(type.isControllableAcl(), null, f));
f = createResult(FAILURE, "Controllable Policy flag is not set!");
addResult(results, assertNotNull(type.isControllablePolicy(), null, f));
f = createResult(FAILURE, "Fulltext indexed flag is not set!");
addResult(results, assertNotNull(type.isFulltextIndexed(), null, f));
f = createResult(FAILURE, "Included in super type flag is not set!");
addResult(results, assertNotNull(type.isIncludedInSupertypeQuery(), null, f));
f = createResult(FAILURE, "Queryable flag is not set!");
addResult(results, assertNotNull(type.isQueryable(), null, f));
f = createResult(WARNING, "Type display name is not set!");
addResult(results, assertStringNotEmpty(type.getDisplayName(), null, f));
f = createResult(WARNING, "Type description is not set!");
addResult(results, assertStringNotEmpty(type.getDescription(), null, f));
if (BaseTypeId.CMIS_DOCUMENT.equals(type.getBaseTypeId())) {
DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
f = createResult(FAILURE, "Versionable flag is not set!");
addResult(results, assertNotNull(docType.isVersionable(), null, f));
f = createResult(FAILURE, "Content stream allowed flag is not set!");
addResult(results, assertNotNull(docType.getContentStreamAllowed(), null, f));
} else if (BaseTypeId.CMIS_FOLDER.equals(type.getBaseTypeId())) {
if (type.isFileable() != null) {
f = createResult(FAILURE, "Folder types must be fileable!");
addResult(results, assertIsTrue(type.isFileable(), null, f));
}
} else if (BaseTypeId.CMIS_RELATIONSHIP.equals(type.getBaseTypeId())) {
RelationshipTypeDefinition relType = (RelationshipTypeDefinition) type;
f = createResult(FAILURE, "Allowed Source Type IDs are not set!");
addResult(results, assertNotNull(relType.getAllowedSourceTypeIds(), null, f));
if (relType.getAllowedSourceTypeIds() != null) {
for (String typeId : relType.getAllowedSourceTypeIds()) {
try {
session.getTypeDefinition(typeId);
} catch (CmisInvalidArgumentException e) {
addResult(results, createResult(WARNING, "Allowed Source Type IDs contain a type ID that doesn't exist: " + typeId));
} catch (CmisObjectNotFoundException e) {
addResult(results, createResult(WARNING, "Allowed Source Type IDs contain a type ID that doesn't exist: " + typeId));
}
}
}
f = createResult(FAILURE, "Allowed Target Type IDs are not set!");
addResult(results, assertNotNull(relType.getAllowedTargetTypeIds(), null, f));
if (relType.getAllowedTargetTypeIds() != null) {
for (String typeId : relType.getAllowedTargetTypeIds()) {
try {
session.getTypeDefinition(typeId);
} catch (CmisInvalidArgumentException e) {
addResult(results, createResult(WARNING, "Allowed Target Type IDs contain a type ID that doesn't exist: " + typeId));
} catch (CmisObjectNotFoundException e) {
addResult(results, createResult(WARNING, "Allowed Target Type IDs contain a type ID that doesn't exist: " + typeId));
}
}
}
if (type.isFileable() != null) {
f = createResult(FAILURE, "Relationship types must not be fileable!");
addResult(results, assertIsFalse(type.isFileable(), null, f));
}
} else if (BaseTypeId.CMIS_POLICY.equals(type.getBaseTypeId())) {
// nothing to do
} else if (BaseTypeId.CMIS_SECONDARY.equals(type.getBaseTypeId())) {
if (type.isCreatable() != null) {
f = createResult(FAILURE, "Secondary types must not be creatable!");
addResult(results, assertIsFalse(type.isCreatable(), null, f));
}
if (type.isFileable() != null) {
f = createResult(FAILURE, "Secondary types must not be fileable!");
addResult(results, assertIsFalse(type.isFileable(), null, f));
}
if (type.isControllableAcl() != null) {
f = createResult(FAILURE, "The controllable ACL flag must be false for secondary types!");
addResult(results, assertIsFalse(type.isControllableAcl(), null, f));
}
if (type.isControllablePolicy() != null) {
f = createResult(FAILURE, "The controllable policy flag must be false for secondary types!");
addResult(results, assertIsFalse(type.isControllablePolicy(), null, f));
}
}
// check properties
if (!BaseTypeId.CMIS_SECONDARY.equals(type.getBaseTypeId())) {
f = createResult(FAILURE, "Type has no property definitions!");
addResult(results, assertNotNull(type.getPropertyDefinitions(), null, f));
if (type.getPropertyDefinitions() != null) {
for (PropertyDefinition<?> propDef : type.getPropertyDefinitions().values()) {
if (propDef == null) {
addResult(results, createResult(FAILURE, "A property definition is null!"));
} else if (propDef.getId() == null) {
addResult(results, createResult(FAILURE, "A property definition ID is null!"));
} else {
addResult(results, checkPropertyDefinition(propDef, "Property definition: " + propDef.getId()));
}
}
}
CmisPropertyDefintion cpd;
// cmis:name
cpd = new CmisPropertyDefintion(PropertyIds.NAME, null, PropertyType.STRING, Cardinality.SINGLE, null, null, null);
addResult(results, cpd.check(type));
// cmis:objectId
cpd = new CmisPropertyDefintion(PropertyIds.OBJECT_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.ONCREATE, null, null);
addResult(results, cpd.check(type));
// cmis:baseTypeId
cpd = new CmisPropertyDefintion(PropertyIds.BASE_TYPE_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:objectTypeId
cpd = new CmisPropertyDefintion(PropertyIds.OBJECT_TYPE_ID, true, PropertyType.ID, Cardinality.SINGLE, Updatability.ONCREATE, null, null);
addResult(results, cpd.check(type));
// cmis:createdBy
cpd = new CmisPropertyDefintion(PropertyIds.CREATED_BY, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, true, true);
addResult(results, cpd.check(type));
// cmis:creationDate
cpd = new CmisPropertyDefintion(PropertyIds.CREATION_DATE, false, PropertyType.DATETIME, Cardinality.SINGLE, Updatability.READONLY, true, true);
addResult(results, cpd.check(type));
// cmis:lastModifiedBy
cpd = new CmisPropertyDefintion(PropertyIds.LAST_MODIFIED_BY, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, true, true);
addResult(results, cpd.check(type));
// cmis:lastModificationDate
cpd = new CmisPropertyDefintion(PropertyIds.LAST_MODIFICATION_DATE, false, PropertyType.DATETIME, Cardinality.SINGLE, Updatability.READONLY, true, true);
addResult(results, cpd.check(type));
// cmis:changeToken
cpd = new CmisPropertyDefintion(PropertyIds.CHANGE_TOKEN, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// CMIS 1.1 properties
if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_1) {
// cmis:description
cpd = new CmisPropertyDefintion(PropertyIds.DESCRIPTION, null, PropertyType.STRING, Cardinality.SINGLE, null, null, null);
addResult(results, cpd.check(type));
// cmis:secondaryObjectTypeIds
cpd = new CmisPropertyDefintion(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, false, PropertyType.ID, Cardinality.MULTI, null, null, false);
addResult(results, cpd.check(type));
if (BaseTypeId.CMIS_DOCUMENT.equals(type.getBaseTypeId())) {
// cmis:isPrivateWorkingCopy
cpd = new CmisPropertyDefintion(PropertyIds.IS_PRIVATE_WORKING_COPY, null, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
}
}
if (BaseTypeId.CMIS_DOCUMENT.equals(type.getBaseTypeId())) {
// cmis:isImmutable
cpd = new CmisPropertyDefintion(PropertyIds.IS_IMMUTABLE, false, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:isLatestVersion
cpd = new CmisPropertyDefintion(PropertyIds.IS_LATEST_VERSION, false, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:isMajorVersion
cpd = new CmisPropertyDefintion(PropertyIds.IS_MAJOR_VERSION, false, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:isLatestMajorVersion
cpd = new CmisPropertyDefintion(PropertyIds.IS_LATEST_MAJOR_VERSION, false, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:versionLabel
cpd = new CmisPropertyDefintion(PropertyIds.VERSION_LABEL, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:versionSeriesId
cpd = new CmisPropertyDefintion(PropertyIds.VERSION_SERIES_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:isVersionSeriesCheckedOut
cpd = new CmisPropertyDefintion(PropertyIds.IS_VERSION_SERIES_CHECKED_OUT, false, PropertyType.BOOLEAN, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:versionSeriesCheckedOutBy
cpd = new CmisPropertyDefintion(PropertyIds.VERSION_SERIES_CHECKED_OUT_BY, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:versionSeriesCheckedOutId
cpd = new CmisPropertyDefintion(PropertyIds.VERSION_SERIES_CHECKED_OUT_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:checkinComment
cpd = new CmisPropertyDefintion(PropertyIds.CHECKIN_COMMENT, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:contentStreamLength
cpd = new CmisPropertyDefintion(PropertyIds.CONTENT_STREAM_LENGTH, false, PropertyType.INTEGER, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:contentStreamMimeType
cpd = new CmisPropertyDefintion(PropertyIds.CONTENT_STREAM_MIME_TYPE, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:contentStreamFileName
cpd = new CmisPropertyDefintion(PropertyIds.CONTENT_STREAM_FILE_NAME, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:contentStreamId
cpd = new CmisPropertyDefintion(PropertyIds.CONTENT_STREAM_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
} else if (BaseTypeId.CMIS_FOLDER.equals(type.getBaseTypeId())) {
// cmis:parentId
cpd = new CmisPropertyDefintion(PropertyIds.PARENT_ID, false, PropertyType.ID, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:path
cpd = new CmisPropertyDefintion(PropertyIds.PATH, false, PropertyType.STRING, Cardinality.SINGLE, Updatability.READONLY, null, null);
addResult(results, cpd.check(type));
// cmis:allowedChildObjectTypeIds
cpd = new CmisPropertyDefintion(PropertyIds.ALLOWED_CHILD_OBJECT_TYPE_IDS, false, PropertyType.ID, Cardinality.MULTI, Updatability.READONLY, null, false);
addResult(results, cpd.check(type));
} else if (BaseTypeId.CMIS_RELATIONSHIP.equals(type.getBaseTypeId())) {
// cmis:sourceId
cpd = new CmisPropertyDefintion(PropertyIds.SOURCE_ID, true, PropertyType.ID, Cardinality.SINGLE, null, null, null);
addResult(results, cpd.check(type));
// cmis:targetId
cpd = new CmisPropertyDefintion(PropertyIds.TARGET_ID, true, PropertyType.ID, Cardinality.SINGLE, null, null, null);
addResult(results, cpd.check(type));
} else if (BaseTypeId.CMIS_POLICY.equals(type.getBaseTypeId())) {
// cmis:policyText
cpd = new CmisPropertyDefintion(PropertyIds.POLICY_TEXT, null, PropertyType.STRING, Cardinality.SINGLE, null, null, null);
addResult(results, cpd.check(type));
}
}
}
CmisTestResultImpl result = createResult(getWorst(results), message);
result.getChildren().addAll(results);
return result.getStatus().getLevel() <= OK.getLevel() ? null : result;
}
use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class ContentRangesTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
// create a test folder
Folder testFolder = createTestFolder(session);
Document doc = null;
try {
// create the document
doc = createDocument(session, testFolder, "testcontent.txt", CONTENT);
String excerpt;
ContentStream content;
long contentLength = doc.getContentStreamLength();
// no offset, no length -> full content
try {
content = doc.getContentStream(null, null);
excerpt = getStringFromContentStream(content);
if (contentLength > -1 && content.getLength() > -1) {
f = createResult(WARNING, "Content length does not match {offset=null, length=null}!", false);
addResult(assertEquals(contentLength, content.getLength(), null, f));
}
if (CONTENT.equals(excerpt)) {
addResult(assertIsFalse(content instanceof PartialContentStream, null, createResult(FAILURE, "Retrieved stream is marked as partial stream " + "although the full stream {offset=null, length=null} was expected!")));
} else {
addResult(createResult(FAILURE, "Retrieved stream doesn't match the document content!"));
}
} catch (Exception e) {
addResult(createResult(FAILURE, "Unexpected exception while retrieving full stream {offset=null, length=null}: " + e, e, false));
}
// offset = 0, no length -> full content
try {
content = doc.getContentStream(BigInteger.ZERO, null);
excerpt = getStringFromContentStream(content);
if (contentLength > -1 && content.getLength() > -1) {
f = createResult(WARNING, "Content length does not match {offset=0, length=null}!", false);
addResult(assertEquals(contentLength, content.getLength(), null, f));
}
if (CONTENT.equals(excerpt)) {
addResult(assertIsFalse(content instanceof PartialContentStream, null, createResult(WARNING, "Retrieved stream is marked as partial stream " + "although the full stream {offset=0, length=null} was expected!")));
} else {
addResult(createResult(FAILURE, "Retrieved stream doesn't match the document content!"));
}
} catch (Exception e) {
addResult(createResult(FAILURE, "Unexpected exception while retrieving full stream {offset=0, length=null}: " + e, e, false));
}
// offset, no length
try {
content = doc.getContentStream(BigInteger.valueOf(3), null);
excerpt = getStringFromContentStream(content);
if (contentLength > -1 && content.getLength() > -1) {
f = createResult(WARNING, "Content length does not match {offset=3, length=null}!", false);
addResult(assertEquals(contentLength - 3, content.getLength(), null, f));
}
if (CONTENT.equals(excerpt)) {
addResult(createResult(WARNING, "Retrieved full stream instead of an excerpt {offset=3, length=null}! Content ranges supported?"));
addResult(assertIsFalse(content instanceof PartialContentStream, null, createResult(WARNING, "Retrieved stream is marked as partial stream, " + "although the full stream is returned!")));
} else {
f = createResult(FAILURE, "Retrieved stream excerpt {offset=3, length=null} doesn't match!");
addResult(assertEquals(CONTENT.substring(3), excerpt, null, f));
addResult(assertIsTrue(content instanceof PartialContentStream, null, createResult(WARNING, "Retrieved stream is not marked as partial stream. " + "(AtomPub and Browser Binding should return the HTTP status code 206.)")));
}
} catch (Exception e) {
addResult(createResult(FAILURE, "Unexpected exception while retrieving stream {offset=3, length=null}: " + e, e, false));
}
// no offset, length
try {
content = doc.getContentStream(null, BigInteger.valueOf(12));
excerpt = getStringFromContentStream(content);
if (content.getLength() > -1) {
f = createResult(WARNING, "Content length does not match {offset=null, length=12}!", false);
addResult(assertEquals(12L, content.getLength(), null, f));
}
if (CONTENT.equals(excerpt)) {
addResult(createResult(WARNING, "Retrieved full stream instead of an excerpt {offset=null, length=12}! Content ranges supported?"));
addResult(assertIsFalse(content instanceof PartialContentStream, null, createResult(WARNING, "Retrieved stream is marked as partial stream, " + "although the full stream is returned!")));
} else {
f = createResult(FAILURE, "Retrieved stream excerpt {offset=null, length=12} doesn't match!");
addResult(assertEquals(CONTENT.substring(0, 12), excerpt, null, f));
addResult(assertIsTrue(content instanceof PartialContentStream, null, createResult(WARNING, "Retrieved stream is not marked as partial stream. " + "(AtomPub and Browser Binding should return the HTTP status code 206.)")));
}
} catch (Exception e) {
addResult(createResult(FAILURE, "Unexpected exception while retrieving stream {offset=null, length=12}: " + e, e, false));
}
// offset and length
try {
content = doc.getContentStream(BigInteger.valueOf(5), BigInteger.valueOf(17));
excerpt = getStringFromContentStream(content);
if (content.getLength() > -1) {
f = createResult(WARNING, "Content length does not match {offset=5, length=17}!", false);
addResult(assertEquals(17L, content.getLength(), null, f));
}
if (CONTENT.equals(excerpt)) {
addResult(createResult(WARNING, "Retrieved full stream instead of an excerpt {offset=5, length=17}! Content ranges supported?"));
addResult(assertIsFalse(content instanceof PartialContentStream, null, createResult(WARNING, "Retrieved stream is marked as partial stream, " + "although the full stream is returned!")));
} else {
f = createResult(FAILURE, "Retrieved stream excerpt {offset=5, length=17} doesn't match!");
addResult(assertEquals(CONTENT.substring(5, 5 + 17), excerpt, null, f));
addResult(assertIsTrue(content instanceof PartialContentStream, null, createResult(WARNING, "Retrieved stream is not marked as partial stream. " + "(AtomPub and Browser Binding should return the HTTP status code 206.)")));
}
} catch (Exception e) {
addResult(createResult(FAILURE, "Unexpected exception while retrieving stream {offset=5, length=17}: " + e, e, false));
}
// offset and length > content size
try {
content = doc.getContentStream(BigInteger.valueOf(9), BigInteger.valueOf(123));
excerpt = getStringFromContentStream(content);
if (content.getLength() > -1) {
f = createResult(WARNING, "Content length does not match {offset=9, length=123}!", false);
addResult(assertEquals((long) (CONTENT.length() - 9), content.getLength(), null, f));
}
if (CONTENT.equals(excerpt)) {
addResult(createResult(WARNING, "Retrieved full stream instead of an excerpt {offset=9, length=123}! Content ranges supported?"));
addResult(assertIsFalse(content instanceof PartialContentStream, null, createResult(WARNING, "Retrieved stream is marked as partial stream, " + "although the full stream is returned!")));
} else {
f = createResult(FAILURE, "Retrieved stream excerpt {offset=9, length=123} doesn't match!");
addResult(assertEquals(CONTENT.substring(9), excerpt, null, f));
addResult(assertIsTrue(content instanceof PartialContentStream, null, createResult(WARNING, "Retrieved stream is not marked as partial stream. " + "(AtomPub and Browser Binding should return the HTTP status code 206.)")));
}
} catch (Exception e) {
addResult(createResult(FAILURE, "Unexpected exception while retrieving stream {offset=9, length=123}: " + e, e, false));
}
} finally {
// clean up
deleteObject(doc);
deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class CopyTest method run.
@Override
public void run(Session session) {
// if (getBinding() == BindingType.ATOMPUB) {
// addResult(createResult(SKIPPED,
// "AtomPub binding does not support createDocumentFromSource(). Test Skipped!"));
// return;
// }
CmisTestResult f;
try {
// create folders
Folder testFolder = createTestFolder(session);
Folder folder1 = createFolder(session, testFolder, "copyfolder1");
Folder folder2 = createFolder(session, testFolder, "copyfolder2");
// create document
Document doc1 = createDocument(session, folder1, "copytestdoc.txt", "copy test");
VersioningState versioningState = VersioningState.MAJOR;
if (!((DocumentTypeDefinition) doc1.getType()).isVersionable()) {
versioningState = VersioningState.NONE;
}
// copy
Document doc2 = doc1.copy(folder2, null, versioningState, null, null, null, SELECT_ALL_NO_CACHE_OC);
if (doc2 == null) {
addResult(createResult(FAILURE, "Copied document is null!"));
} else {
addResult(checkObject(session, doc2, getAllProperties(doc2), "Copied document check. Id: + " + doc2.getName()));
f = createResult(FAILURE, "Content streams don't match!");
addResult(assertEquals(doc1.getContentStream(), doc2.getContentStream(), null, f));
}
int count1 = countFolderChildren(folder1);
f = createResult(FAILURE, "Source folder should have exactly one child but has " + count1 + " children!");
addResult(assertEquals(1, count1, null, f));
int count2 = countFolderChildren(folder2);
f = createResult(FAILURE, "Target folder should have exactly one child but has " + count2 + " children!");
addResult(assertEquals(1, count2, null, f));
deleteObject(doc2);
deleteObject(doc1);
} finally {
// clean up
// deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class CreateAndDeleteFolderTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
int numOfFolders = 20;
// create a test folder
Folder testFolder = createTestFolder(session);
try {
Map<String, Folder> folders = new HashMap<String, Folder>();
// create folders
for (int i = 0; i < numOfFolders; i++) {
Folder newFolder = createFolder(session, testFolder, "folder" + i);
folders.put(newFolder.getId(), newFolder);
}
// simple children test
addResult(checkChildren(session, testFolder, "Test folder children check"));
// check if all folders are there
ItemIterable<CmisObject> children = testFolder.getChildren(SELECT_ALL_NO_CACHE_OC);
List<String> childrenIds = new ArrayList<String>();
for (CmisObject child : children) {
if (child != null) {
childrenIds.add(child.getId());
Folder folder = folders.get(child.getId());
f = createResult(FAILURE, "Folder and test folder child don't match! Id: " + child.getId());
addResult(assertShallowEquals(folder, child, null, f));
}
}
f = createResult(FAILURE, "Number of created folders does not match the number of existing folders!");
addResult(assertEquals(numOfFolders, childrenIds.size(), null, f));
for (Folder folder : folders.values()) {
if (!childrenIds.contains(folder.getId())) {
addResult(createResult(FAILURE, "Created folder not found in test folder children! Id: " + folder.getId()));
}
}
// delete all folders
for (Folder folder : folders.values()) {
// empty folders should be deleteable like this
folder.delete(true);
f = createResult(FAILURE, "Folder should not exist anymore but it is still there! Id: " + folder.getId());
addResult(assertIsFalse(exists(folder), null, f));
}
} finally {
// delete the test folder
deleteTestFolder();
}
addResult(createInfoResult("Tested the creation and deletion of " + numOfFolders + " folders."));
}
Aggregations