All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.chemistry.opencmis.tck.runner.WebRunnerServlet Maven / Gradle / Ivy

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.chemistry.opencmis.tck.runner;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.chemistry.opencmis.tck.CmisTest;
import org.apache.chemistry.opencmis.tck.CmisTestGroup;
import org.apache.chemistry.opencmis.tck.CmisTestProgressMonitor;
import org.apache.chemistry.opencmis.tck.report.CoreHtmlReport;

/**
 * Web Runner.
 */
public class WebRunnerServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html; charset=UTF-8");

        PrintWriter pw = resp.getWriter();

        printHeader(pw);

        pw.println("

OpenCMIS TCK

"); pw.println("
"); pw.println(""); pw.println(""); pw.println(""); pw.println(""); pw.println(""); pw.println(""); pw.println(""); pw.println(""); printFooter(pw); } @SuppressWarnings("unchecked") @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setBufferSize(0); resp.setContentType("text/html; charset=UTF-8"); PrintWriter pw = resp.getWriter(); printHeader(pw); Map parameters = new HashMap(); Map parameterMap = req.getParameterMap(); if (parameterMap != null) { for (Map.Entry entry : parameterMap.entrySet()) { if (entry.getValue() == null || entry.getValue().length < 1) { continue; } parameters.put(entry.getKey(), entry.getValue()[0]); } } try { WebRunner runner = new WebRunner(); runner.setParameters(parameters); runner.loadDefaultTckGroups(); pw.println("
"); pw.println("

Running OpenCMIS TCK

"); runner.run(new WebProgressMonitor(pw)); pw.println("
"); // let progress div disappear pw.println(""); (new CoreHtmlReport()).createReport(runner.getParameters(), runner.getGroups(), pw); } catch (Exception e) { pw.println("

Exception

"); pw.println("\n
");
            e.printStackTrace(pw);
            pw.println("\n
"); } printFooter(pw); } protected void printHeader(PrintWriter pw) throws IOException { pw.println(""); pw.println("\nOpenCMIS TCK"); CoreHtmlReport.printStyle(pw); pw.println(""); } protected void printFooter(PrintWriter pw) throws IOException { pw.println("\n"); pw.flush(); } private static class WebRunner extends AbstractRunner { } private static class WebProgressMonitor implements CmisTestProgressMonitor { private final PrintWriter pw; public WebProgressMonitor(PrintWriter pw) { this.pw = pw; } @Override public void startGroup(CmisTestGroup group) { pw.println("

" + group.getName() + " (" + group.getTests().size() + " tests)

"); pw.flush(); } @Override public void endGroup(CmisTestGroup group) { pw.println("
"); pw.flush(); } @Override public void startTest(CmisTest test) { pw.print("   " + test.getName() + " ... "); pw.flush(); } @Override public void endTest(CmisTest test) { pw.println("completed
"); pw.flush(); } @Override public void message(String msg) { pw.println(msg); pw.flush(); } } }









AtomPub URL:
Username:
Password:
Repository Id: