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.storage;
import static com.ursaj.hfs.HfsTestUtils.assertThrows;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertSame;

public class HfsDefaultStorageTest {
    
Test read operation.

Throws:
java.lang.Exception In case of any exception.
    @Test
    public void testRead() throws Exception {
        final UUID uniqueId = UUID.randomUUID();
        final String text = uniqueId.toString() + "@" + System.currentTimeMillis();
        final HfsClient client = mock(HfsClient.class);
        final HfsDefaultStorage storage = new HfsDefaultStorage(null) {
            @Override
            protected HfsClient getClient() {
                return client;
            }
        };
        File tempFile = File.createTempFile("test""tmp");
        tempFile.deleteOnExit();
        FileUtils.write(tempFiletext);
        doReturn(tempFile.toURI().toString()).when(client).createPublishUri(eq(uniqueId), isNull(String.class));
        assertEquals(IOUtils.toString(storage.read(uniqueId)), text);
    }

    
Test write operation.

Throws:
java.lang.Exception In case of any exception.
    @Test
    public void testWrite() throws Exception {
        HfsDefaultStorage storage = new HfsDefaultStorage(null);
        assertThrows(UnsupportedOperationException.class"Direct upload operation is not supported.",
            storage"write"new HfsConsumer<OutputStreamIOException>(Collections.<OutputStream>emptyList()));
    }

    
Test client resolution.

Throws:
java.lang.Exception In case of any exception.
    @Test
    public void testClientResolution() throws Exception {
        HfsDefaultStorage storage = new HfsDefaultStorage("localhost");
        assertSame(storage.getClient(), HfsFactory.getClient("localhost"));
        storage = new HfsDefaultStorage(null);
        assertThrows(IllegalArgumentException.class"Failed to resolve HFS client"storage"getClient");
    }
New to GrepCode? Check out our FAQ X