This project has retired. For details please refer to its Attic page.
AbstractTckIT xref

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.fit.tck;
20  
21  import static org.junit.Assert.assertTrue;
22  
23  import java.io.File;
24  import java.util.HashMap;
25  import java.util.List;
26  import java.util.Map;
27  
28  import org.apache.chemistry.opencmis.commons.SessionParameter;
29  import org.apache.chemistry.opencmis.commons.enums.BindingType;
30  import org.apache.chemistry.opencmis.tck.CmisTest;
31  import org.apache.chemistry.opencmis.tck.CmisTestGroup;
32  import org.apache.chemistry.opencmis.tck.CmisTestProgressMonitor;
33  import org.apache.chemistry.opencmis.tck.CmisTestReport;
34  import org.apache.chemistry.opencmis.tck.CmisTestResult;
35  import org.apache.chemistry.opencmis.tck.CmisTestResultStatus;
36  import org.apache.chemistry.opencmis.tck.impl.TestParameters;
37  import org.apache.chemistry.opencmis.tck.report.TextReport;
38  import org.apache.chemistry.opencmis.tck.runner.AbstractRunner;
39  import org.junit.Test;
40  
41  public abstract class AbstractTckIT extends AbstractRunner {
42      public static final String HOST = "localhost";
43      public static final int PORT = 19080;
44  
45      public static final String REPOSITORY_ID = "test";
46      public static final String USER = "test";
47      public static final String PASSWORD = "test";
48  
49      public abstract Map<String, String> getSessionParameters();
50  
51      public abstract BindingType getBindingType();
52  
53      public Map<String, String> getBaseSessionParameters() {
54          Map<String, String> parameters = new HashMap<String, String>();
55  
56          parameters.put(SessionParameter.REPOSITORY_ID, REPOSITORY_ID);
57          parameters.put(SessionParameter.USER, USER);
58          parameters.put(SessionParameter.PASSWORD, PASSWORD);
59  
60          parameters.put(TestParameters.DEFAULT_DOCUMENT_TYPE, "VersionableType");
61          parameters.put(TestParameters.DEFAULT_FOLDER_TYPE, "cmis:folder");
62  
63          return parameters;
64      }
65  
66      @Test
67      public void runTck() throws Exception {
68          // set up TCK and run it
69          setParameters(getSessionParameters());
70          loadDefaultTckGroups();
71  
72          run(new TestProgressMonitor());
73  
74          // write report
75          File target = new File("target");
76          target.mkdir();
77  
78          CmisTestReport report = new TextReport();
79          report.createReport(getParameters(), getGroups(), new File(target, "tck-result-" + getBindingType().value()
80                  + ".txt"));
81  
82          // find failures
83          for (CmisTestGroup group : getGroups()) {
84              for (CmisTest test : group.getTests()) {
85                  for (CmisTestResult result : test.getResults()) {
86                      assertTrue(result.getStatus() != CmisTestResultStatus.FAILURE);
87                      assertTrue(result.getStatus() != CmisTestResultStatus.UNEXPECTED_EXCEPTION);
88                  }
89              }
90          }
91      }
92  
93      public static CmisTestResultStatus getWorst(List<CmisTestResult> results) {
94          if ((results == null) || (results.isEmpty())) {
95              return CmisTestResultStatus.OK;
96          }
97  
98          int max = 0;
99  
100         for (CmisTestResult result : results) {
101             if (max < result.getStatus().getLevel()) {
102                 max = result.getStatus().getLevel();
103             }
104         }
105 
106         return CmisTestResultStatus.fromLevel(max);
107     }
108 
109     private static class TestProgressMonitor implements CmisTestProgressMonitor {
110         public void startGroup(CmisTestGroup group) {
111             System.out.println();
112             System.out.println(group.getName() + " (" + group.getTests().size() + " tests)");
113         }
114 
115         public void endGroup(CmisTestGroup group) {
116             System.out.println();
117         }
118 
119         public void startTest(CmisTest test) {
120             System.out.print("  " + test.getName());
121         }
122 
123         public void endTest(CmisTest test) {
124             System.out.print(" (" + test.getTime() + "ms): ");
125             System.out.println(getWorst(test.getResults()));
126         }
127 
128         public void message(String msg) {
129             System.out.println(msg);
130         }
131     }
132 }