Java tutorial
/* * Copyright 2010 Talis Information Ltd * * 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.talis.storage.memory; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.util.Arrays; import javax.ws.rs.core.MediaType; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.IOUtils; import org.junit.Test; import com.talis.storage.AbstractStoreTest; import com.talis.storage.Store; import com.talis.storage.StoredItem; import com.talis.storage.SubmittedItem; public class MemoryStoreTest extends AbstractStoreTest { @Override protected Store getStore() { return new MemoryStore(); } @Test public void storedItemEtagIsMd5OfEntity() throws Exception { SubmittedItem submitted = new SubmittedItem(MediaType.TEXT_PLAIN_TYPE, new ByteArrayInputStream(data)); StoredItem stored = store.write(itemURI, submitted); String expectedEtag = DigestUtils.md5Hex(data); assertEquals(expectedEtag, stored.getEtag()); } /** * At the moment, on MemoryStore can guarantee the entity of the * StoredItem returned by write will match that of the * SubmittedItem because there's no chunking involved. See * TODO item in S3Store.write() re: making an entity stream * using reconstructChunks() or similar when writing */ @Test public void storedItemHasExpectedEntity() throws Exception { SubmittedItem submitted = new SubmittedItem(MediaType.TEXT_PLAIN_TYPE, new ByteArrayInputStream(data)); StoredItem stored = store.write(itemURI, submitted); assertTrue(Arrays.equals(data, IOUtils.toByteArray(stored.getEntity()))); } }