Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2011 Ursa Project LLC ( Licensed 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 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 com.ursaj.hfs.server;
 import static com.ursaj.hfs.HfsTestUtils.getField;
 import static com.ursaj.hfs.server.HfsServletAdapter.CLIENT_NAME_INIT_PARAMETER;
 import static com.ursaj.hfs.server.HfsServletAdapter.FILE_SERVICE_CONTEXT_ATTRIBUTE;
 import static org.testng.Assert.assertNotNull;

Base class for HFS servlet(s) tests.

<T> File information type your application works with.
<S> Servlet class to test.
 public abstract class HfsServletTestAdapter<T extends HfsFileInfo, S extends HttpServlet> {
HFS client name to use in tests.
     public static final String HFS_CLIENT_NAME = "test@localhost";

File service to store uploaded files.
     private HfsFileService<T> fileService;

Servlet to test.
     private S servlet;

Set up test.

java.lang.Exception In case of any exception.
     public void setUp() throws Exception {
          = new HfsMemoryFileService<T>();
         MockServletContext context = new MockServletContext();
         MockServletConfig config = new MockServletConfig(context"Test servlet.");
          = createServlet();

Tear down test.
     public void tearDown() {
          = null;
          = null;

Create servlet for tests.

Servlet to test.
     protected abstract S createServlet();

Get servlet to test.

Servlet to test.
     protected S getServlet() {
         return ;

Get file service bound to servlet.

File service bound to servlet.
    protected HfsFileService<T> getFileService() {
        return ;

Marshal message into URI-safe string token.

message Message to marshal.
Marshaled message as URI-safe string token.
    protected String createToken(Object message) {
        HfsClient client = HfsFactory.getClient();
        HfsMessageMarshaller marshaller = getField(client"marshaller"HfsMessageMarshaller.class);
        return marshaller.createToken(message);
New to GrepCode? Check out our FAQ X