view src/test/java/jp/ac/u_ryukyu/ie/cr/shoshi/jungle/impl/logging/LoggingNodeTest.java @ 80:a833000f64bf

test program repair
author one
date Sun, 31 Aug 2014 03:30:03 +0900
parents 650fe2a0dccc
children
line wrap: on
line source

/*package jp.ac.u_ryukyu.ie.cr.shoshi.jungle.impl.logging;

import java.nio.ByteBuffer;
import org.junit.Assert;
import fj.data.List;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.AttributesContainer;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.AttributesContainerTest;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.ParentTest;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.EditableNodeWrapper;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.LoggingNode;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.OperationLog;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.transaction.DefaultTreeNode;
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;
import junit.framework.TestSuite;

public class LoggingNodeTest extends TestCase
{
	public void testGetLoggerIsNotNull()
	{
		LoggingNode<?> instance = instance();
		OperationLog log = instance.getOperationLog();
		Assert.assertNotNull(log);
	}
	
	public void testGetWrappedIsNotNull()
	{
		LoggingNode<?> instance = instance();
		Object wrap = instance.getWrap();
		Assert.assertNotNull(wrap);
	}
	
	public void testLoggingAddNewChildAt()
	{
		LoggingNode<EditableNodeWrapper<DefaultTreeNode>> instance = instance();
		Either<Error, LoggingNode<EditableNodeWrapper<DefaultTreeNode>>> either = instance.getChildren().addNewChildAt(0);
		if(either.isA()){
			Assert.fail();
		}
		instance = either.b();
		
		List<Command> expectOps = List.list(Command.APPEND_CHILD);
		for(NodeOperation op : instance.getOperationLog()){
			Command actual = op.getCommand();
			Command expect = expectOps.head();
			Assert.assertEquals(expect,actual);
			expectOps = expectOps.tail();
		}
		
		Assert.assertEquals(0,expectOps.length());
	}
	
	public void testLoggingDeleteChildAt()
	{
		LoggingNode<EditableNodeWrapper<DefaultTreeNode>> instance = instance();
		Either<Error, LoggingNode<EditableNodeWrapper<DefaultTreeNode>>> either = instance.getChildren().addNewChildAt(0);
		if(either.isA()){
			Assert.fail();
		}
		instance = either.b();
		either = instance.getChildren().deleteChildAt(0);
		if(either.isA()){
			Assert.fail();
		}
		instance = either.b();
		
		List<Command> expectOps = List.list(Command.APPEND_CHILD,Command.DELETE_CHILD);
		for(NodeOperation op : instance.getOperationLog()){
			Command actual = op.getCommand();
			Command expect = expectOps.head();
			Assert.assertEquals(expect,actual);
			expectOps = expectOps.tail();
		}
		
		Assert.assertEquals(0,expectOps.length());
	}
	
	public void testPutAttributeTest()
	{
		String key = "KEY";
		ByteBuffer value = ByteBuffer.wrap(key.getBytes());
		LoggingNode<EditableNodeWrapper<DefaultTreeNode>> instance = instance();
		Either<Error, LoggingNode<EditableNodeWrapper<DefaultTreeNode>>> either = instance.getAttributes().put(key,value);
		if(either.isA()){
			Assert.fail();
		}
		instance = either.b();
		
		List<Command> expectOps = List.list(Command.PUT_ATTRIBUTE);
		for(NodeOperation op : instance.getOperationLog()){
			Command actual = op.getCommand();
			Command expect = expectOps.head();
			Assert.assertEquals(expect,actual);
		}
		
		Assert.assertEquals(1,expectOps.length());
	}
	
	public void testDeleteAttributeTest()
	{
		String key = "KEY";
		ByteBuffer value = ByteBuffer.wrap(key.getBytes());
		LoggingNode<EditableNodeWrapper<DefaultTreeNode>> instance = instance();
		Either<Error, LoggingNode<EditableNodeWrapper<DefaultTreeNode>>> either = instance.getAttributes().put(key,value);
		if(either.isA()){
			Assert.fail();
		}
		instance = either.b();
		either = instance.getAttributes().delete(key);
		if(either.isA()){
			Assert.fail();
		}
		instance = either.b();
	
		List<Command> expectOps = List.list(Command.PUT_ATTRIBUTE,Command.DELETE_ATTRIBUTE);
		for(NodeOperation op : instance.getOperationLog()){
			Command actual = op.getCommand();
			Command expect = expectOps.head();
			Assert.assertEquals(expect,actual);
			expectOps = expectOps.tail();
		}
		
		Assert.assertEquals(0,expectOps.length());
	}
	
	public static TestSuite suite()
	{
		TestSuite suite = new TestSuite();
		suite.addTestSuite(ParentTestImpl.class);
		suite.addTestSuite(AttributesContainerTestImpl.class);
		suite.addTestSuite(LoggingNodeTest.class);
		return suite;
	}
	
	public static LoggingNode<EditableNodeWrapper<DefaultTreeNode>> instance()
	{
		EditableNodeWrapper<DefaultTreeNode> wrapper = new EditableNodeWrapper<DefaultTreeNode>(new DefaultTreeNode());
		return new LoggingNode<EditableNodeWrapper<DefaultTreeNode>>(wrapper);
	}
	
	public static class ParentTestImpl extends ParentTest<LoggingNode<?>>
	{
		@Override
		public LoggingNode<?> instance()
		{
			return LoggingNodeTest.instance();
		}
	}
	
	public static class AttributesContainerTestImpl extends AttributesContainerTest
	{
		@Override
		public AttributesContainer instance()
		{
			return LoggingNodeTest.instance();
		}
	}
}*/