manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1437540 - /manifoldcf/trunk/tests/solr/src/test/java/org/apache/manifoldcf/solr_tests/MockSolrService.java
Date Wed, 23 Jan 2013 16:23:16 GMT
Author: kwright
Date: Wed Jan 23 16:23:15 2013
New Revision: 1437540

URL: http://svn.apache.org/viewvc?rev=1437540&view=rev
Log:
Add a mock solr server, so we can write a test for the IOException issues

Added:
    manifoldcf/trunk/tests/solr/src/test/java/org/apache/manifoldcf/solr_tests/MockSolrService.java
  (with props)

Added: manifoldcf/trunk/tests/solr/src/test/java/org/apache/manifoldcf/solr_tests/MockSolrService.java
URL: http://svn.apache.org/viewvc/manifoldcf/trunk/tests/solr/src/test/java/org/apache/manifoldcf/solr_tests/MockSolrService.java?rev=1437540&view=auto
==============================================================================
--- manifoldcf/trunk/tests/solr/src/test/java/org/apache/manifoldcf/solr_tests/MockSolrService.java
(added)
+++ manifoldcf/trunk/tests/solr/src/test/java/org/apache/manifoldcf/solr_tests/MockSolrService.java
Wed Jan 23 16:23:15 2013
@@ -0,0 +1,144 @@
+/* $Id$ */
+
+/**
+* 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.manifoldcf.rss_tests;
+
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.util.thread.QueuedThreadPool;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+
+import java.io.*;
+import java.util.*;
+
+/** Mock wiki service */
+public class MockSolrService
+{
+  Server server;
+  SolrServlet servlet;
+    
+  public MockSolrService()
+  {
+    server = new Server(8188);
+    server.setThreadPool(new QueuedThreadPool(35));
+    servlet = new SolrServlet();
+    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
+    context.setContextPath("/");
+    server.setHandler(context);
+    context.addServlet(new ServletHolder(servlet), "/*");
+  }
+    
+  public void start() throws Exception
+  {
+    server.start();
+  }
+    
+  public void stop() throws Exception
+  {
+    server.stop();
+  }
+
+  
+  public static class SolrServlet extends HttpServlet
+  {
+    public SolrServlet()
+    {
+    }
+    
+    @Override
+    public void service(HttpServletRequest req, HttpServletResponse res)
+      throws IOException
+    {
+      try
+      {
+        // Get path part of request URL
+        String pathPart = req.getPathInfo();
+        if (pathPart == null)
+          generateMissingPageResponse(res);
+        else if (pathPart.equals("/admin/ping"))
+        {
+          generatePingResponse(res);
+        }
+        else if (pathPart.equals("/update/extract"))
+        {
+          generateUpdateResponse(res);
+        }
+        else if (pathPart.equals("/update"))
+        {
+          generateDeleteResponse(res);
+        }
+        else
+          generateMissingPageResponse(res);
+      }
+      catch (IOException e)
+      {
+        e.printStackTrace();
+        throw e;
+      }
+
+    }
+
+    protected static void generatePingResponse(HttpServletResponse res)
+      throws IOException
+    {
+      res.setStatus(HttpServletResponse.SC_OK);
+      res.setContentType("text/xml; charset=utf-8");
+      res.getWriter().printf("<solr>\n");
+      res.getWriter().printf("</solr>\n");
+    }
+    
+    protected static void generateUpdateResponse(HttpServletResponse res)
+      throws IOException
+    {
+      res.setStatus(HttpServletResponse.SC_OK);
+      res.setContentType("text/xml; charset=utf-8");
+      res.getWriter().printf("<result>\n");
+      res.getWriter().printf("  <doc name=\"something\"/>\n");
+      res.getWriter().printf("</result>\n");
+    }
+    
+    protected static void generateDeleteResponse(HttpServletResponse res)
+      throws IOException
+    {
+      res.setStatus(HttpServletResponse.SC_OK);
+      res.setContentType("text/xml; charset=utf-8");
+      res.getWriter().printf("<result>\n");
+      res.getWriter().printf("  <doc name=\"something\"/>\n");
+      res.getWriter().printf("</result>\n");
+    }
+    
+    protected static void generateMissingPageResponse(HttpServletResponse res)
+      throws IOException
+    {
+      res.sendError(HttpServletResponse.SC_NOT_FOUND);
+    }
+    
+    protected static void generateBadArgumentResponse(HttpServletResponse res)
+      throws IOException
+    {
+      res.sendError(HttpServletResponse.SC_BAD_REQUEST);
+    }
+
+  }
+
+}

Propchange: manifoldcf/trunk/tests/solr/src/test/java/org/apache/manifoldcf/solr_tests/MockSolrService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: manifoldcf/trunk/tests/solr/src/test/java/org/apache/manifoldcf/solr_tests/MockSolrService.java
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message