Package net.rubyeye.xmemcached.test.unittest.commands.text

Source Code of net.rubyeye.xmemcached.test.unittest.commands.text.BaseTextCommandUnitTest

package net.rubyeye.xmemcached.test.unittest.commands.text;

import java.nio.ByteBuffer;

import junit.framework.TestCase;
import net.rubyeye.xmemcached.CommandFactory;
import net.rubyeye.xmemcached.buffer.BufferAllocator;
import net.rubyeye.xmemcached.buffer.SimpleBufferAllocator;
import net.rubyeye.xmemcached.command.Command;
import net.rubyeye.xmemcached.command.TextCommandFactory;
import net.rubyeye.xmemcached.exception.MemcachedDecodeException;

public class BaseTextCommandUnitTest extends TestCase {
  static final String DECODE_ERROR_SESSION_WILL_BE_CLOSED = "Decode error,session will be closed";
  protected CommandFactory commandFactory;
  protected BufferAllocator bufferAllocator;

  @Override
  public void setUp() {
    this.bufferAllocator = new SimpleBufferAllocator();
    this.commandFactory = new TextCommandFactory();
  }

  protected void checkDecodeNullAndNotLineByteBuffer(Command command) {
    assertFalse(command.decode(null, null));
    assertFalse(command.decode(null, ByteBuffer.allocate(0)));
    assertFalse(command.decode(null, ByteBuffer.wrap("test".getBytes())));
  }

  protected void checkDecodeInvalidLine(Command command, String invalidLine) {
    try {

      command.decode(null, ByteBuffer.wrap(invalidLine.getBytes()));
      fail();
    } catch (MemcachedDecodeException e) {
      assertTrue(true);
       assertEquals(DECODE_ERROR_SESSION_WILL_BE_CLOSED + ",line="
          + invalidLine.replace("\r\n", ""), e.getMessage());
    }
  }
 
  public void testDecodeError(){
   
  }

  protected void checkDecodeValidLine(Command command, String validLine) {
    assertTrue(command.decode(null, ByteBuffer.wrap(validLine.getBytes())));
  }

  protected void checkByteBufferEquals(Command command, String line) {
    assertEquals(ByteBuffer.wrap(line.getBytes()), command.getIoBuffer()
        .buf());
  }
}
TOP

Related Classes of net.rubyeye.xmemcached.test.unittest.commands.text.BaseTextCommandUnitTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.