Package com.google.code.hs4j.command.text

Source Code of com.google.code.hs4j.command.text.InsertCommandUnitTest

package com.google.code.hs4j.command.text;

import static org.junit.Assert.*;

import java.sql.SQLException;

import org.junit.Test;

import com.google.code.hs4j.command.text.AbstractCommand.ParseState;
import com.google.code.hs4j.network.buffer.IoBuffer;

public class InsertCommandUnitTest extends AbstractCommandUnitTest {
  @Override
  public AbstractCommand createCommand() {
    final String id = "1";
    final byte[][] values = { "1".getBytes(), "dennis".getBytes(),
        "password".getBytes() };
    return new InsertCommand(id, values);
  }

  @Test
  public void testEncodeDecode() throws SQLException {
    assertNull(this.cmd.getIoBuffer());
    this.cmd.encode();
    IoBuffer buf = this.cmd.getIoBuffer();
    assertNotNull(buf);
    assertEquals(0, buf.position());
    assertTrue(buf.limit() > 0);

    assertEquals("1\t+\t3\t1\tdennis\tpassword\n", new String(buf.array(),
        0, buf.limit()));

    IoBuffer buffer = IoBuffer.allocate(4);
    buffer.put("0\t1\n".getBytes());
    buffer.flip();

    assertEquals(1, this.cmd.getLatch().getCount());
    assertTrue(this.cmd.decode(null, buffer));
    assertEquals(0, this.cmd.getResponseStatus());
    assertEquals(1, this.cmd.getNumColumns());

    assertEquals(ParseState.DONE, this.cmd.getCurrentState());
    assertEquals(0, this.cmd.getLatch().getCount());
    assertNull(this.cmd.getExceptionMessage());
  }
}
TOP

Related Classes of com.google.code.hs4j.command.text.InsertCommandUnitTest

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.