@Test
 public void test() throws IOException, ClassNotFoundException {
   this.test((Serializable) null, true);
   this.test("test", true);
   this.test(Boolean.TRUE, true);
   this.test(Byte.valueOf(Byte.MAX_VALUE), true);
   this.test(Character.valueOf(Character.MAX_VALUE), true);
   this.test(Double.valueOf(Double.MAX_VALUE), true);
   this.test(Float.valueOf(Float.MAX_VALUE), true);
   this.test(Integer.valueOf(Integer.MAX_VALUE), true);
   this.test(Long.valueOf(Long.MAX_VALUE), true);
   this.test(Short.valueOf(Short.MAX_VALUE), true);
   this.test(new String[] {"test"}, true);
   this.test(new boolean[] {Boolean.TRUE}, true);
   this.test(new byte[] {Byte.MAX_VALUE}, true);
   this.test(new char[] {Character.MAX_VALUE}, true);
   this.test(new double[] {Double.MAX_VALUE}, true);
   this.test(new float[] {Float.MAX_VALUE}, true);
   this.test(new int[] {Integer.MAX_VALUE}, true);
   this.test(new long[] {Long.MAX_VALUE}, true);
   this.test(new short[] {Short.MAX_VALUE}, true);
   this.test(new Boolean[] {Boolean.TRUE}, true);
   this.test(new Byte[] {Byte.valueOf(Byte.MAX_VALUE)}, true);
   this.test(new Character[] {Character.valueOf(Character.MAX_VALUE)}, true);
   this.test(new Double[] {Double.valueOf(Double.MAX_VALUE)}, true);
   this.test(new Float[] {Float.valueOf(Float.MAX_VALUE)}, true);
   this.test(new Integer[] {Integer.valueOf(Integer.MAX_VALUE)}, true);
   this.test(new Long[] {Long.valueOf(Long.MAX_VALUE)}, true);
   this.test(new Short[] {Short.valueOf(Short.MAX_VALUE)}, true);
   this.test(this.getClass(), false);
   this.test(new Date(System.currentTimeMillis()), false);
   this.test(new Object(), false);
 }
 /**
  * Test conversion. The value are provided by {@link
  * org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
  *
  * @throws Exception
  */
 @Test
 public void testConvert_Byte_Hex() throws Exception {
   Configuration config = ConfigurationProvider.getConfiguration();
   Optional<Byte> valueRead = config.getOptional("tests.converter.byte.hex.lowerX", Byte.class);
   assertTrue(valueRead.isPresent());
   assertEquals(valueRead.get().byteValue(), Byte.decode("0x2F").byteValue());
   valueRead = config.getOptional("tests.converter.byte.hex.upperX", Byte.class);
   assertTrue(valueRead.isPresent());
   assertEquals(valueRead.get().byteValue(), Byte.decode("0X3F").byteValue());
 }
 /**
  * Test conversion. The value are provided by {@link
  * org.apache.tamaya.core.internal.converters.ConverterTestsPropertySource}.
  *
  * @throws Exception
  */
 @Test
 public void testConvert_Byte_Octal() throws Exception {
   Configuration config = ConfigurationProvider.getConfiguration();
   Optional<Byte> valueRead = config.getOptional("tests.converter.byte.octal", Byte.class);
   assertTrue(valueRead.isPresent());
   assertEquals(valueRead.get().byteValue(), Byte.decode("02").byteValue());
 }
  @Before
  public void before() {
    // add dummy span-event list
    List<TSpanEvent> spanEventList = new ArrayList<TSpanEvent>();
    spanEventList.add(new TSpanEvent());
    span.setSpanEventList(spanEventList);
    span.setSpanEventListIsSet(true);

    // init byte buffer
    Arrays.fill(buf, Byte.valueOf("0"));
  }
  @Test
  public void shouldForwardReadCallsBlindly() throws Exception {
    ChannelBuffer buf = createStrictMock(ChannelBuffer.class);
    expect(buf.readerIndex()).andReturn(0).anyTimes();
    expect(buf.writerIndex()).andReturn(0).anyTimes();
    expect(buf.capacity()).andReturn(0).anyTimes();

    expect(buf.getBytes(1, (GatheringByteChannel) null, 2)).andReturn(3);
    buf.getBytes(4, (OutputStream) null, 5);
    buf.getBytes(6, (byte[]) null, 7, 8);
    buf.getBytes(9, (ChannelBuffer) null, 10, 11);
    buf.getBytes(12, (ByteBuffer) null);
    expect(buf.getByte(13)).andReturn(Byte.valueOf((byte) 14));
    expect(buf.getShort(15)).andReturn(Short.valueOf((short) 16));
    expect(buf.getUnsignedMedium(17)).andReturn(18);
    expect(buf.getInt(19)).andReturn(20);
    expect(buf.getLong(21)).andReturn(22L);

    ByteBuffer bb = ByteBuffer.allocate(100);
    ByteBuffer[] bbs = {ByteBuffer.allocate(101), ByteBuffer.allocate(102)};

    expect(buf.toByteBuffer(23, 24)).andReturn(bb);
    expect(buf.toByteBuffers(25, 26)).andReturn(bbs);
    expect(buf.capacity()).andReturn(27);

    replay(buf);

    ChannelBuffer roBuf = unmodifiableBuffer(buf);
    assertEquals(3, roBuf.getBytes(1, (GatheringByteChannel) null, 2));
    roBuf.getBytes(4, (OutputStream) null, 5);
    roBuf.getBytes(6, (byte[]) null, 7, 8);
    roBuf.getBytes(9, (ChannelBuffer) null, 10, 11);
    roBuf.getBytes(12, (ByteBuffer) null);
    assertEquals((byte) 14, roBuf.getByte(13));
    assertEquals((short) 16, roBuf.getShort(15));
    assertEquals(18, roBuf.getUnsignedMedium(17));
    assertEquals(20, roBuf.getInt(19));
    assertEquals(22L, roBuf.getLong(21));

    ByteBuffer roBB = roBuf.toByteBuffer(23, 24);
    assertEquals(100, roBB.capacity());
    assertTrue(roBB.isReadOnly());

    ByteBuffer[] roBBs = roBuf.toByteBuffers(25, 26);
    assertEquals(2, roBBs.length);
    assertEquals(101, roBBs[0].capacity());
    assertTrue(roBBs[0].isReadOnly());
    assertEquals(102, roBBs[1].capacity());
    assertTrue(roBBs[1].isReadOnly());
    assertEquals(27, roBuf.capacity());

    verify(buf);
  }
  @Test
  public void shouldForwardReadCallsBlindly() throws Exception {
    ByteBuf buf = createStrictMock(ByteBuf.class);
    expect(buf.order()).andReturn(BIG_ENDIAN).anyTimes();
    expect(buf.maxCapacity()).andReturn(65536).anyTimes();
    expect(buf.readerIndex()).andReturn(0).anyTimes();
    expect(buf.writerIndex()).andReturn(0).anyTimes();
    expect(buf.capacity()).andReturn(0).anyTimes();

    expect(buf.getBytes(1, (GatheringByteChannel) null, 2)).andReturn(3);
    expect(buf.getBytes(4, (OutputStream) null, 5)).andReturn(buf);
    expect(buf.getBytes(6, (byte[]) null, 7, 8)).andReturn(buf);
    expect(buf.getBytes(9, (ByteBuf) null, 10, 11)).andReturn(buf);
    expect(buf.getBytes(12, (ByteBuffer) null)).andReturn(buf);
    expect(buf.getByte(13)).andReturn(Byte.valueOf((byte) 14));
    expect(buf.getShort(15)).andReturn(Short.valueOf((short) 16));
    expect(buf.getUnsignedMedium(17)).andReturn(18);
    expect(buf.getInt(19)).andReturn(20);
    expect(buf.getLong(21)).andReturn(22L);

    ByteBuffer bb = ByteBuffer.allocate(100);

    expect(buf.nioBuffer(23, 24)).andReturn(bb);
    expect(buf.capacity()).andReturn(27);

    replay(buf);

    ByteBuf roBuf = unmodifiableBuffer(buf);
    assertEquals(3, roBuf.getBytes(1, (GatheringByteChannel) null, 2));
    roBuf.getBytes(4, (OutputStream) null, 5);
    roBuf.getBytes(6, (byte[]) null, 7, 8);
    roBuf.getBytes(9, (ByteBuf) null, 10, 11);
    roBuf.getBytes(12, (ByteBuffer) null);
    assertEquals((byte) 14, roBuf.getByte(13));
    assertEquals((short) 16, roBuf.getShort(15));
    assertEquals(18, roBuf.getUnsignedMedium(17));
    assertEquals(20, roBuf.getInt(19));
    assertEquals(22L, roBuf.getLong(21));

    ByteBuffer roBB = roBuf.nioBuffer(23, 24);
    assertEquals(100, roBB.capacity());
    assertTrue(roBB.isReadOnly());

    assertEquals(27, roBuf.capacity());

    verify(buf);
  }
 @Test
 public void test_uint8_t() throws IOException {
   for (Integer exp : expected_uint8) {
     UnsignedByte result = binFileReader.uint8_t();
     assertEquals(
         "uint8_t " + Integer.toHexString(exp) + " asInt()",
         (Integer) Byte.toUnsignedInt(exp.byteValue()),
         result.asInt());
     assertEquals(
         "uint8_t " + Integer.toHexString(exp) + " getSignedValue()",
         (Byte) exp.byteValue(),
         result.getSignedValue());
     assertEquals(
         "uint8_t " + Integer.toHexString(exp) + " toString()",
         Integer.toString((((exp < 0 ? exp + 256 : exp)))),
         result.toString());
   }
 }
 @Test
 public void test_manuel_uint8_t() throws IOException {
   // 73 4B C3 BC
   // 115, 75, -61, -68
   byte[] input = {115, 75, -61, -68};
   int[] expected = {0x73, 0x4B, 0xC3, 0xBC};
   BinFileReader binFileReader =
       new BinFileReader(new BufferedInputStream(new ByteArrayInputStream(input)));
   for (int i = 0; i < input.length; i++) {
     UnsignedByte result = binFileReader.uint8_t();
     Integer exp = expected[i];
     assertEquals(
         "uint8_t " + Integer.toHexString(exp) + " asInt()",
         (Integer) Byte.toUnsignedInt(exp.byteValue()),
         result.asInt());
     assertEquals(
         "uint8_t " + Integer.toHexString(exp) + " getSignedValue()",
         (Byte) exp.byteValue(),
         result.getSignedValue());
   }
 }
  /**
   * 测试启动前方法.
   *
   * @throws java.lang.Exception 普通异常.
   */
  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    // 获取原数据库内容
    IDataSet backupDataset = TestDBHelper.backupDataBase();
    // 构建测试用的数据
    // 指定测试用到的表
    DefaultTable userTable =
        new DefaultTable(
            "t_user", backupDataset.getTable("t_user").getTableMetaData().getColumns());
    DefaultTable roleTable =
        new DefaultTable(
            "t_role", backupDataset.getTable("t_role").getTableMetaData().getColumns());
    DefaultTable menuItemTable =
        new DefaultTable(
            "t_menuitem", backupDataset.getTable("t_menuitem").getTableMetaData().getColumns());
    DefaultTable rolemenuitemmapTable =
        new DefaultTable(
            "t_rolemenuitemmap",
            backupDataset.getTable("t_rolemenuitemmap").getTableMetaData().getColumns());

    // 写入数据
    Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2012-01-12 23:30:20");
    Object[] userData1 = {
      Long.valueOf("1"),
      "user1",
      "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
      date,
      Long.valueOf("1"),
      null,
      null,
      Byte.valueOf("0"),
      Byte.valueOf("0"),
      Long.valueOf("0")
    };
    userTable.addRow(userData1);

    Object[] roleData1 = {
      Long.valueOf("1"),
      "访客",
      date,
      Long.valueOf("1"),
      null,
      null,
      Byte.valueOf("0"),
      Byte.valueOf("0"),
      Long.valueOf("0")
    };
    roleTable.addRow(roleData1);
    Object[] roleData2 = {
      Long.valueOf("2"),
      "超级管理员",
      date,
      Long.valueOf("1"),
      null,
      null,
      Byte.valueOf("0"),
      Byte.valueOf("0"),
      Long.valueOf("0")
    };
    roleTable.addRow(roleData2);

    Object[] roleData4 = {
      Long.valueOf("4"),
      "role4",
      date,
      Long.valueOf("1"),
      null,
      null,
      Byte.valueOf("0"),
      Byte.valueOf("0"),
      Long.valueOf("0")
    };
    roleTable.addRow(roleData4);
    // testEditRole使用
    Object[] roleData5 = {
      Long.valueOf("5"),
      "role5",
      date,
      Long.valueOf("1"),
      null,
      null,
      Byte.valueOf("0"),
      Byte.valueOf("0"),
      Long.valueOf("0")
    };
    roleTable.addRow(roleData5);
    // testPageRole使用
    Object[] roleData6 = {
      Long.valueOf("6"),
      "page",
      date,
      Long.valueOf("1"),
      null,
      null,
      Byte.valueOf("0"),
      Byte.valueOf("0"),
      Long.valueOf("0")
    };
    roleTable.addRow(roleData6);

    Object[] menuItemData1 = {
      1,
      "MenuName",
      "menuItemName1",
      "icon1",
      1,
      "sfds",
      "sdf",
      "sdf",
      0,
      "2015-06-15 15:15:27",
      "1",
      "2015-06-15 15:15:27",
      null,
      '0',
      '0',
      0
    };
    menuItemTable.addRow(menuItemData1);
    Object[] menuItemData2 = {
      2,
      "MenuName",
      "menuItemName2",
      "icon1",
      1,
      "sfds",
      "sdf",
      "sdf",
      0,
      "2015-06-15 15:15:27",
      "1",
      "2015-06-15 15:15:27",
      null,
      '0',
      '0',
      0
    };
    menuItemTable.addRow(menuItemData2);
    Object[] menuItemData3 = {
      Long.valueOf("3"),
      "MenuName",
      "menuItemName3",
      "icon1",
      1,
      "sfds",
      "sdf",
      "sdf",
      0,
      "2015-06-15 15:15:27",
      "1",
      "2015-06-15 15:15:27",
      null,
      '0',
      '0',
      0
    };
    menuItemTable.addRow(menuItemData3);
    Object[] menuItemData4 = {
      Long.valueOf("4"),
      "MenuName",
      "menuItemName4",
      "icon1",
      1,
      "sfds",
      "sdf",
      "sdf",
      0,
      "2015-06-15 15:15:27",
      "1",
      "2015-06-15 15:15:27",
      null,
      '0',
      '0',
      0
    };
    menuItemTable.addRow(menuItemData4);

    Object[] rolemenuitemmapData1 = {
      1, 1, 1, "2015-06-15 15:16:40", 1, "2015-06-15 15:15:27", null, 0, 0, 0
    };
    rolemenuitemmapTable.addRow(rolemenuitemmapData1);
    Object[] rolemenuitemmapData2 = {
      2, 2, 1, "2015-06-15 15:16:40", 1, "2015-06-15 15:15:27", null, 0, 0, 0
    };
    rolemenuitemmapTable.addRow(rolemenuitemmapData2);
    Object[] rolemenuitemmapData3 = {
      Long.valueOf("3"), 1, 2, "2015-06-15 15:16:40", 1, "2015-06-15 15:15:27", 0, 0, 0, null
    };
    rolemenuitemmapTable.addRow(rolemenuitemmapData3);
    Object[] rolemenuitemmapData4 = {
      Long.valueOf("4"),
      2,
      Long.valueOf("3"),
      "2015-06-15 15:16:40",
      1,
      "2015-06-15 15:15:27",
      null,
      0,
      0,
      0
    };
    rolemenuitemmapTable.addRow(rolemenuitemmapData4);
    Object[] rolemenuitemmapData5 = {
      Long.valueOf("5"),
      2,
      Long.valueOf("4"),
      "2015-06-15 15:16:40",
      1,
      "2015-06-15 15:15:27",
      null,
      0,
      0,
      0
    };
    rolemenuitemmapTable.addRow(rolemenuitemmapData5);

    // 组合表
    DefaultTable[] tables = {userTable, roleTable, menuItemTable, rolemenuitemmapTable};
    // 创建测试数据库的引用以准备写入数据库中
    IDataSet tempDataSet = new DefaultDataSet(tables);
    // 写入数据库
    DatabaseOperation.CLEAN_INSERT.execute(TestDBHelper.getConn(), tempDataSet);
  }
示例#10
0
 @Test(expected = NumberFormatException.class)
 public void test_keyWithWrongByteValue_ShouldFail() {
   Key key = Key.create(KEY_4_NAME, Key.KEY_VALUE, KEY_4_VALUE, Key.KEY_END);
   // assert only to trigger key.getByte() function which throws exception
   assertEquals(false, Byte.parseByte(KEY_4_VALUE) == key.getByte().byteValue());
 }
示例#11
0
 @Test
 public void test_keyWithByteValue_shouldPass() {
   Key key = Key.create(KEY_3_NAME, Key.KEY_VALUE, KEY_3_VALUE, Key.KEY_END);
   assertEquals(true, Byte.parseByte(KEY_3_VALUE) == key.getByte().byteValue());
 }