Mercurial > hg > Members > tatsuki > bench > jungle-core
view src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/core/nodeeditor/EditableAttributesTest.java @ 41:ed6737db637a
added tests
author | Shoshi TAMAKI |
---|---|
date | Tue, 29 Jan 2013 23:42:54 +0900 |
parents | 6decea87ef88 |
children | a833000f64bf |
line wrap: on
line source
package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.nodeeditor; import java.nio.ByteBuffer; import org.junit.Assert; import fj.P; import fj.P2; import fj.data.List; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableAttributes; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableNode; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.NodeEditorError; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import junit.framework.TestCase; public abstract class EditableAttributesTest<T extends EditableNode<T>> extends TestCase { public abstract EditableAttributes<T> instance(); @SuppressWarnings("unchecked") public static final List<P2<String,ByteBuffer>> ENTRIES = List.list( P.p("KEY1",ByteBuffer.wrap("VALUE1".getBytes())), P.p("KEY2",ByteBuffer.wrap("VALUE2".getBytes())), P.p("KEY3",ByteBuffer.wrap("VALUE3".getBytes())) ); public EditableAttributes<T> createTestData() { EditableAttributes<T> instance = instance(); T node; EditableAttributes<T> attr = instance; for(P2<String,ByteBuffer> entry : ENTRIES){ Either<Error,T> either = attr.put(entry._1(),entry._2()); if(either.isA()){ Assert.fail("error during creating the data."); } node = either.b(); attr = node.getAttributes(); } return attr; } public void testPutDoesNotAcceptNullValue() { EditableAttributes<T> instance = instance(); Either<Error,T> either = instance.put("KEY",null); if(!either.isA()){ Assert.fail("put must returns NULL_VALUE_NOT_ALLOWED when the value was null."); } Assert.assertEquals(NodeEditorError.NULL_VALUE_NOT_ALLOWED,either.a()); either = instance.put(null,ByteBuffer.wrap("VALUE".getBytes())); if(!either.isA()){ Assert.fail("put must returns NULL_VALUE_NOT_ALLOWED when the key was null."); } Assert.assertEquals(NodeEditorError.NULL_VALUE_NOT_ALLOWED,either.a()); } public void testPut() { createTestData(); } public void testDeleteIfKeyExsist() { EditableAttributes<T> attr = createTestData(); for(P2<String,ByteBuffer> entry : ENTRIES){ Either<Error,T> either = attr.delete(entry._1()); if(either.isA()){ Assert.fail("error during deleting exist key."); } attr = either.b().getAttributes(); } } public static final String DUMMY_KEY = "dummy"; public void testDeleteIfKeyNotExist() { EditableAttributes<T> attr = createTestData(); Either<Error,T> either = attr.delete(DUMMY_KEY); if(!either.isA()){ Assert.fail("delete must returns DELETE_KEY_NOT_FOUND when the deleting invalid key."); } } }