View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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.util.Map;
25  
26  import org.apache.chemistry.opencmis.client.api.Document;
27  import org.apache.chemistry.opencmis.client.api.Folder;
28  import org.apache.chemistry.opencmis.client.api.Session;
29  import org.apache.chemistry.opencmis.commons.data.ContentStream;
30  import org.apache.chemistry.opencmis.commons.impl.IOUtils;
31  import org.apache.chemistry.opencmis.tck.CmisTestResult;
32  import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
33  
34  /**
35   * Document names test.
36   */
37  public class NameCharsetTest extends AbstractSessionTest {
38  
39      private static final String[] NAMES = new String[] { //
40      "\u0064\u006f\u0063\u0075\u006d\u0065\u006e\u0074", //
41              "\u0053\u0063\u0068\u0072\u0069\u0066\u0074\u0073\u0074\u00fc\u0063\u006b", //
42              "\u0648\u062b\u064a\u0642\u0629", //
43              "\u0073\u0259\u006e\u0259\u0064", //
44              "\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442", //
45              "\u6587\u4ef6", //
46              "\u03ad\u03b3\u03b3\u03c1\u03b1\u03c6\u03bf", //
47              "\u0aa6\u0ab8\u0acd\u0aa4\u0abe\u0ab5\u0ac7\u0a9c", //
48              "\u0926\u0938\u094d\u0924\u093e\u0935\u0947\u091c\u093c", //
49              "\u0064\u006f\u0069\u0063\u0069\u006d\u00e9\u0061\u0064", //
50              "\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8", //
51              "\u05d3\u05d0\u05b8\u05e7\u05d5\u05de\u05e2\u05e0\u05d8", //
52              "\u0ca6\u0cbe\u0c96\u0cb2\u0cc6", //
53              "\ubb38\uc11c", //
54              "\u0633\u0646\u062f", //
55              "\u0b86\u0bb5\u0ba3\u0bae\u0bcd", //
56              "\u0c2a\u0c24\u0c4d\u0c30\u0c02", //
57              "\u0e40\u0e2d\u0e01\u0e2a\u0e32\u0e23", //
58              "\u062f\u0633\u062a\u0627\u0648\u06cc\u0632", //
59              "\u0074\u00e0\u0069\u0020\u006c\u0069\u1ec7\u0075", //
60              "a&b", //
61              "abc%_Pxyz" };
62  
63      @Override
64      public void init(Map<String, String> parameters) {
65          super.init(parameters);
66          setName("Name Charset Test");
67          setDescription("Creates and deletes documents with special characters in cmis:name.");
68      }
69  
70      @Override
71      public void run(Session session) {
72          CmisTestResult f;
73  
74          // create a test folder
75          Folder testFolder = createTestFolder(session);
76  
77          try {
78              for (int i = 0; i < NAMES.length; i++) {
79                  Document doc = null;
80                  Document doc2 = null;
81                  try {
82                      doc = null;
83                      doc = createDocument(session, testFolder, NAMES[i], NAMES[i]);
84  
85                      // get the newly created object by path
86                      String path = doc.getPaths().get(0);
87                      doc2 = (Document) session.getObjectByPath(path, SELECT_ALL_NO_CACHE_OC);
88                      addResult(checkObject(session, doc2, getAllProperties(doc2), "New document object spec compliance"));
89  
90                      f = createResult(FAILURE, "Names of the created and the fetched document don't match!");
91                      assertEquals(NAMES[i], doc2.getName(), null, f);
92  
93                      ContentStream contentStream = doc.getContentStream();
94  
95                      f = createResult(FAILURE, "Document has no content!");
96                      assertNotNull(contentStream, null, f);
97  
98                      IOUtils.consumeAndClose(contentStream.getStream());
99                  } catch (Exception e) {
100                     addResult(createResult(WARNING, "The name '" + NAMES[i] + "' raised this exception: " + e, e, false));
101                 } finally {
102                     if (doc != null) {
103                         // delete it
104                         try {
105                             doc.delete(true);
106                         } catch (Exception e) {
107                             // ignore
108                         }
109                     }
110                 }
111             }
112 
113             addResult(createInfoResult("Tested " + NAMES.length + " different names."));
114         } finally {
115             // delete the test folder
116             deleteTestFolder();
117         }
118     }
119 }