You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2013/03/21 16:27:37 UTC
svn commit: r1459357 - in
/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck:
impl/AbstractSessionTest.java tests/types/SecondaryTypesTest.java
Author: fmui
Date: Thu Mar 21 15:27:36 2013
New Revision: 1459357
URL: http://svn.apache.org/r1459357
Log:
TCK: extended secondary types test
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/SecondaryTypesTest.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java?rev=1459357&r1=1459356&r2=1459357&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java Thu Mar 21 15:27:36 2013
@@ -32,6 +32,7 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.math.BigInteger;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.HashMap;
@@ -356,13 +357,14 @@ public abstract class AbstractSessionTes
* Creates a document.
*/
protected Document createDocument(Session session, Folder parent, String name, String content) {
- return createDocument(session, parent, name, getDocumentTestTypeId(), content);
+ return createDocument(session, parent, name, getDocumentTestTypeId(), null, content);
}
/**
* Creates a document.
*/
- protected Document createDocument(Session session, Folder parent, String name, String objectTypeId, String content) {
+ protected Document createDocument(Session session, Folder parent, String name, String objectTypeId,
+ String[] secondaryTypeIds, String content) {
if (content == null) {
content = "";
}
@@ -371,6 +373,10 @@ public abstract class AbstractSessionTes
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));
+ }
+
TypeDefinition type = session.getTypeDefinition(objectTypeId);
if (!(type instanceof DocumentTypeDefinition)) {
addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/SecondaryTypesTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/SecondaryTypesTest.java?rev=1459357&r1=1459356&r2=1459357&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/SecondaryTypesTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/types/SecondaryTypesTest.java Thu Mar 21 15:27:36 2013
@@ -23,12 +23,16 @@ import static org.apache.chemistry.openc
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.Folder;
+import org.apache.chemistry.opencmis.client.api.ObjectId;
import org.apache.chemistry.opencmis.client.api.ObjectType;
+import org.apache.chemistry.opencmis.client.api.Property;
import org.apache.chemistry.opencmis.client.api.SecondaryType;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.commons.PropertyIds;
@@ -76,22 +80,21 @@ public class SecondaryTypesTest extends
Folder testFolder = createTestFolder(session);
try {
- createDocumentAndAttachSecondaryType(session, testFolder);
- createDocumentWithSecondaryType(session, testFolder);
+ String secondaryTestTypeId = getSecondaryTestTypeId();
+ ObjectType secondaryTestType = session.getTypeDefinition(secondaryTestTypeId);
+
+ createDocumentAndAttachSecondaryType(session, testFolder, secondaryTestType);
+ createDocumentWithSecondaryType(session, testFolder, secondaryTestType);
} finally {
// delete the test folder
deleteTestFolder();
}
}
- private void createDocumentAndAttachSecondaryType(Session session, Folder testFolder) {
- CmisTestResult f;
-
+ private void createDocumentAndAttachSecondaryType(Session session, Folder testFolder, ObjectType secondaryTestType) {
Document doc = createDocument(session, testFolder, "createandattach.txt", "Secondary Type Test");
try {
- String secondaryTestTypeId = getSecondaryTestTypeId();
-
// -- attach secondary type
List<String> secondaryTypes = new ArrayList<String>();
@@ -102,67 +105,141 @@ public class SecondaryTypesTest extends
}
}
- secondaryTypes.add(secondaryTestTypeId);
+ // add the new secondary type
+ secondaryTypes.add(secondaryTestType.getId());
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
// attach secondary type
- Document newDoc = (Document) doc.updateProperties(properties);
+ ObjectId newId = doc.updateProperties(properties);
+ Document newDoc = (Document) session.getObject(newId, SELECT_ALL_NO_CACHE_OC);
// check if the secondary type is there
- boolean found = false;
- if (newDoc.getSecondaryTypes() == null) {
- addResult(createResult(FAILURE, "Document does not have the attached secondary type!"));
- } else {
- for (SecondaryType secType : newDoc.getSecondaryTypes()) {
- if (secondaryTestTypeId.equals(secType.getId())) {
- found = true;
- break;
- }
- }
+ boolean found = checkSecondaryType(newDoc, secondaryTestType);
- f = createResult(FAILURE, "Document does not have the attached secondary type!");
- addResult(assertIsTrue(found, null, f));
+ // -- detach secondary type
+ if (found) {
+ detachSecondaryType(session, newDoc, secondaryTestType);
}
- // -- detach secondary type
+ } finally {
+ deleteObject(doc);
+ }
+ }
+
+ private void createDocumentWithSecondaryType(Session session, Folder testFolder, ObjectType secondaryTestType) {
+ Document doc = createDocument(session, testFolder, "createwithsecondarytype.txt", getDocumentTestTypeId(),
+ new String[] { secondaryTestType.getId() }, "Secondary Type Test");
+
+ try {
+ // check if the secondary type is there
+ boolean found = checkSecondaryType(doc, secondaryTestType);
+
+ // detach secondary type
if (found) {
- secondaryTypes = new ArrayList<String>();
+ detachSecondaryType(session, doc, secondaryTestType);
+ }
+ } finally {
+ deleteObject(doc);
+ }
+ }
- for (SecondaryType secType : newDoc.getSecondaryTypes()) {
- if (!secondaryTestTypeId.equals(secType.getId())) {
- secondaryTypes.add(secType.getId());
- }
- }
+ private boolean checkSecondaryType(Document doc, ObjectType secondaryTestType) {
+ CmisTestResult f;
- properties = new HashMap<String, Object>();
- properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes);
+ // check if the secondary type is there
+ boolean found = false;
+ if (doc.getSecondaryTypes() == null) {
+ addResult(createResult(FAILURE, "Document does not have the attached secondary type!"));
+ } else {
+ for (SecondaryType secType : doc.getSecondaryTypes()) {
+ if (secondaryTestType.getId().equals(secType.getId())) {
+ found = true;
+ break;
+ }
+ }
- // attach secondary type
- Document newDoc2 = (Document) doc.updateProperties(properties);
+ f = createResult(FAILURE, "Document does not have the attached secondary type!");
+ addResult(assertIsTrue(found, null, f));
+ }
- found = false;
- if (newDoc2.getSecondaryTypes() != null) {
- for (SecondaryType secType : newDoc2.getSecondaryTypes()) {
- if (secondaryTestTypeId.equals(secType.getId())) {
- found = true;
- break;
- }
- }
+ // check properties of secondary type
+ if (found) {
+ Set<String> secondaryTypeProperties = new HashSet<String>();
+
+ if (secondaryTestType.getPropertyDefinitions() != null) {
+ for (PropertyDefinition<?> propDef : secondaryTestType.getPropertyDefinitions().values()) {
+ secondaryTypeProperties.add(propDef.getId());
}
+ }
- f = createResult(FAILURE, "Document still has the detached secondary type!");
- addResult(assertIsFalse(found, null, f));
+ for (Property<?> prop : doc.getProperties()) {
+ secondaryTypeProperties.remove(prop.getId());
}
- } finally {
- deleteObject(doc);
+ f = createResult(FAILURE, "Documents lacks the following secondary type properties: "
+ + secondaryTypeProperties);
+ addResult(assertIsTrue(secondaryTypeProperties.isEmpty(), null, f));
}
- }
- private void createDocumentWithSecondaryType(Session session, Folder testFolder) {
- // TODO
+ return found;
}
+ private void detachSecondaryType(Session session, Document doc, ObjectType secondaryTestType) {
+ CmisTestResult f;
+
+ List<String> secondaryTypesId = new ArrayList<String>();
+
+ for (SecondaryType secType : doc.getSecondaryTypes()) {
+ if (!secondaryTestType.getId().equals(secType.getId())) {
+ secondaryTypesId.add(secType.getId());
+ }
+ }
+
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypesId);
+
+ // detach secondary type
+ ObjectId newId = doc.updateProperties(properties);
+ Document newDoc = (Document) session.getObject(newId, SELECT_ALL_NO_CACHE_OC);
+
+ boolean found = false;
+ if (newDoc.getSecondaryTypes() != null) {
+ for (SecondaryType secType : newDoc.getSecondaryTypes()) {
+ if (secondaryTestType.getId().equals(secType.getId())) {
+ found = true;
+ break;
+ }
+ }
+ }
+
+ f = createResult(FAILURE, "Document still has the detached secondary type!");
+ addResult(assertIsFalse(found, null, f));
+
+ // check properties
+ ObjectType primaryType = newDoc.getType();
+ List<SecondaryType> secondaryTypes = newDoc.getSecondaryTypes();
+
+ for (Property<?> prop : doc.getProperties()) {
+ if (!primaryType.getPropertyDefinitions().containsKey(prop.getId())) {
+ f = createResult(FAILURE, "Property '" + prop.getId()
+ + "' is neither defined by the primary type nor by a secondary type!");
+
+ if (secondaryTypes == null) {
+ addResult(f);
+ } else {
+ boolean foundProperty = false;
+ for (SecondaryType secondaryType : secondaryTypes) {
+ if (secondaryType.getPropertyDefinitions() != null
+ && secondaryType.getPropertyDefinitions().containsKey(prop.getId())) {
+ foundProperty = true;
+ break;
+ }
+ }
+ addResult(assertIsTrue(foundProperty, null, f));
+ }
+ }
+ }
+ }
}