Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2011 Ursa Project LLC (http://ursaj.com) 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 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 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.

Parameters:
<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.

Throws:
java.lang.Exception In case of any exception.
 
     @BeforeMethod
     public void setUp() throws Exception {
          = new HfsMemoryFileService<T>();
 
         MockServletContext context = new MockServletContext();
 
         context.setContextPath("/test");
 
         MockServletConfig config = new MockServletConfig(context"Test servlet.");
 
         assertNotNull(config.getServletName());
 
          = createServlet();
         .init(config);
     }

    
Tear down test.
 
     @AfterMethod
     public void tearDown() {
         .destroy();
          = null;
          = null;
     }

    
Create servlet for tests.

Returns:
Servlet to test.
 
     @Test
     protected abstract S createServlet();

    
Get servlet to test.

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

    
Get file service bound to servlet.

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

    
Marshal message into URI-safe string token.

Parameters:
message Message to marshal.
Returns:
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