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 java.util.*;
 
 import static com.ursaj.hfs.HfsTestUtils.setField;
 import static com.ursaj.hfs.server.HfsServletAdapter.ENCODED_MESSAGE_HTTP_PARAMETER;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.testng.Assert.*;

HfsGcServlet test cases.
 
 public class HfsGcServletTest extends HfsServletTestAdapter<HfsFileInfoHfsGcServlet> {
    
Test GC request handling.

Throws:
java.lang.Exception In case of any exception.
 
     @Test
     public void testGcRequest() throws Exception {
         HfsGcServlet servlet = getServlet();
         SortedSet<UUIDalive = new TreeSet<UUID>(.);
 
         for (int i = 0; i < 100; i++) {
             MockHttpServletResponse resp = new MockHttpServletResponse();
             MockHttpServletRequest req = new MockHttpServletRequest("GET""/requestURI");
             HfsGcRequest gcReq = new HfsGcRequestImpl(UUID.randomUUID());
 
             req.setParameter(createToken(gcReq));
             servlet.service(reqresp);
 
             assertEquals(resp.getContentType(), "application/octet-stream");
             HfsGcResponseReader reader = new HfsGcResponseReader(new ByteArrayInputStream(
                 resp.getContentAsByteArray()));
 
             for (UUID uuid : alive.tailSet(gcReq.getFromId()))
                 assertEquals(reader.retrieve(), uuid);
 
             HfsFileInfo info = new HfsFileInfoImpl(UUID.randomUUID(), i + ".txt""text/p;ain"new Date(), 0);
             alive.add(info.getFileId());
             getFileService().storeFiles(Collections.singleton(info));
         }
     }

    
Test GC request failure.

Throws:
java.lang.Exception In case of any exception.
 
     @Test
     public void testGcRequestFailure() throws Exception {
         HfsGcServlet servlet = getServlet();
 
         MockHttpServletResponse resp = new MockHttpServletResponse();
         MockHttpServletRequest req = new MockHttpServletRequest("GET""/requestURI");
         HfsGcRequest gcReq = new HfsGcRequestImpl(UUID.randomUUID());
 
         @SuppressWarnings("unchecked"HfsFileService<HfsFileInfofileService = mock(HfsFileService.class);
         IllegalStateException expected = new IllegalStateException("Test message.");
 
         doThrow(expected).when(fileService).collectAliveFiles(
             any(UUID.class), Matchers.<Consumer<UUIDIOException>>any());
         setField(servlet"fileService"fileService);
 
         try {
             servlet.service(reqresp);
             fail("Expects request handling failed.");
        }
        catch (IllegalStateException e) {
            assertSame(eexpected);
        }
    }
    @Override
    protected HfsGcServlet createServlet() {
        return new HfsGcServlet();
    }
New to GrepCode? Check out our FAQ X