1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.tck.tests.crud;
20
21 import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
22 import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.WARNING;
23
24 import java.io.ByteArrayInputStream;
25 import java.math.BigInteger;
26 import java.util.HashMap;
27 import java.util.Map;
28
29 import org.apache.chemistry.opencmis.client.api.Folder;
30 import org.apache.chemistry.opencmis.client.api.Session;
31 import org.apache.chemistry.opencmis.commons.PropertyIds;
32 import org.apache.chemistry.opencmis.commons.data.ContentStream;
33 import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
34 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
35 import org.apache.chemistry.opencmis.commons.impl.IOUtils;
36 import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
37 import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
38
39 public class CreateInvalidTypeTest extends AbstractSessionTest {
40
41 @Override
42 public void init(Map<String, String> parameters) {
43 super.init(parameters);
44 setName("Create Object With Invalid Type Test");
45 setDescription("Tries to create document with a folder type and folder with a document type.");
46 }
47
48 @Override
49 public void run(Session session) {
50
51 Folder testFolder = createTestFolder(session);
52
53 try {
54
55 try {
56 Map<String, Object> properties = new HashMap<String, Object>();
57 properties.put(PropertyIds.NAME, "never.txt");
58 properties.put(PropertyIds.OBJECT_TYPE_ID, getFolderTestTypeId());
59
60 byte[] contentBytes = IOUtils.toUTF8Bytes("nothing");
61 ContentStream contentStream = new ContentStreamImpl("never.txt",
62 BigInteger.valueOf(contentBytes.length), "text/plain", new ByteArrayInputStream(contentBytes));
63
64 testFolder.createDocument(properties, contentStream, null);
65
66 addResult(createResult(FAILURE, "Creation of a document with a folder type shouldn't work!"));
67 } catch (Exception e) {
68 if (!(e instanceof CmisInvalidArgumentException) && !(e instanceof CmisConstraintException)) {
69 addResult(createResult(WARNING,
70 "Creation of a document with a folder type threw an unexcpeted exception: " + e.toString()));
71 }
72 }
73
74
75 try {
76 Map<String, Object> properties = new HashMap<String, Object>();
77 properties.put(PropertyIds.NAME, "never");
78 properties.put(PropertyIds.OBJECT_TYPE_ID, getDocumentTestTypeId());
79
80 testFolder.createFolder(properties);
81
82 addResult(createResult(FAILURE, "Creation of a folder with a document type shouldn't work!"));
83 } catch (Exception e) {
84 if (!(e instanceof CmisInvalidArgumentException) && !(e instanceof CmisConstraintException)) {
85 addResult(createResult(WARNING,
86 "Creation of a folder with a document type threw an unexcpeted exception: " + e.toString()));
87 }
88 }
89 } finally {
90
91 deleteTestFolder();
92 }
93 }
94 }