view src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/nodeeditor/EditableAttributesTest.java @ 0:44465893e8b8

first Commit
author Kazuma
date Wed, 30 Nov 2016 01:47:55 +0900
parents
children
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 TreeNode;
import TreeNodeAttributes;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.trasnformer.EditableAttributes;
import NodeEditorError;
import Either;
import Error;
import junit.framework.TestCase;

public abstract class EditableAttributesTest<T extends TreeNode<T>> extends TestCase
{
	public abstract TreeNodeAttributes<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 TreeNodeAttributes<T> createTestData()
	{
		TreeNodeAttributes<T> instance = instance();
		
		T node;
		TreeNodeAttributes<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()
	{
		TreeNodeAttributes<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()
	{
		TreeNodeAttributes<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()
	{
		TreeNodeAttributes<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.");
		}
	}
}
*/