/** HashedEntityId. */
  @Test
  public void testHashedParserLoop() throws Exception {
    final EntityIdFactory factory =
        EntityIdFactory.getFactory((RowKeyFormat) mHashedLayout.getDesc().getKeysFormat());
    final EntityId eid = factory.getEntityId("hashedRowKey");

    assertEquals(eid, ToolUtils.createEntityIdFromUserInputs(eid.toShellString(), mHashedLayout));
  }
  /** RawEntityId. */
  @Test
  public void testRawParserLoop() throws Exception {
    final EntityIdFactory factory =
        EntityIdFactory.getFactory((RowKeyFormat) mRawLayout.getDesc().getKeysFormat());
    final EntityId eid = factory.getEntityIdFromHBaseRowKey(Bytes.toBytes("rawRowKey"));

    assertEquals(eid, ToolUtils.createEntityIdFromUserInputs(eid.toShellString(), mRawLayout));
  }
  /** HBaseEntityId. */
  @Test
  public void testHBaseEIDtoRawEID() throws Exception {
    final EntityIdFactory factory =
        EntityIdFactory.getFactory((RowKeyFormat) mRawLayout.getDesc().getKeysFormat());
    final EntityId reid = factory.getEntityId("rawEID");
    final EntityId hbeid = HBaseEntityId.fromHBaseRowKey(reid.getHBaseRowKey());

    assertEquals(reid, ToolUtils.createEntityIdFromUserInputs(hbeid.toShellString(), mRawLayout));
  }
  @Test
  public void testEmptyString() throws IOException {
    final EntityIdFactory factory =
        EntityIdFactory.getFactory((RowKeyFormat2) mFormattedLayout.getDesc().getKeysFormat());
    final EntityId eid = factory.getEntityId("", "", "", null, null);

    assertEquals(
        eid, ToolUtils.createEntityIdFromUserInputs("['', '', '', null, null]", mFormattedLayout));
  }
  @Test
  public void testTooFewComponents() throws IOException {
    final EntityIdFactory factory =
        EntityIdFactory.getFactory((RowKeyFormat2) mFormattedLayout.getDesc().getKeysFormat());
    final EntityId eid = factory.getEntityId("dummy", "str1", "str2", 5, null);

    assertEquals(
        eid,
        ToolUtils.createEntityIdFromUserInputs("['dummy', 'str1', 'str2', 5]", mFormattedLayout));
  }
  @Test
  public void testHBaseEIDtoFormattedEID() throws Exception {
    final EntityIdFactory factory =
        EntityIdFactory.getFactory((RowKeyFormat2) mFormattedLayout.getDesc().getKeysFormat());
    final EntityId feid = factory.getEntityId("dummy", "str1", "str2", 5, 10);
    final EntityId hbeid = HBaseEntityId.fromHBaseRowKey(feid.getHBaseRowKey());

    assertEquals(
        feid, ToolUtils.createEntityIdFromUserInputs(hbeid.toShellString(), mFormattedLayout));
  }
 /** FormattedEntityId. */
 @Test
 public void testTooLargeInt() throws Exception {
   try {
     ToolUtils.createEntityIdFromUserInputs(
         "['dummy', 'str1', 'str2', 2147483648, 10]", mFormattedLayout);
     fail("Should fail with EntityIdException.");
   } catch (EntityIdException eie) {
     assertEquals(
         "Invalid type for component 2147483648 at index 3 in kijiRowKey", eie.getMessage());
   }
 }
  @Test
  public void testNonNullFollowsNull() throws IOException {

    try {
      ToolUtils.createEntityIdFromUserInputs(
          "['dummy', 'str1', 'str2', null, 5]", mFormattedLayout);
      fail("Should fail with EntityIdException.");
    } catch (EntityIdException eie) {
      assertEquals("Non null component follows null component", eie.getMessage());
    }
  }
  @Test
  public void testTooLargeLong() throws Exception {

    try {
      ToolUtils.createEntityIdFromUserInputs(
          "['dummy', 'str1', 'str2', 5, 9223372036854775808]", mFormattedLayout);
      fail("Should fail with EntityIdException.");
    } catch (IOException ioe) {
      assertEquals(
          "Invalid JSON value: '9223372036854775808', expecting string, " + "int, long, or null.",
          ioe.getMessage());
    }
  }
示例#10
0
  @Test
  public void testASCIIChars() throws Exception {
    final EntityIdFactory factory =
        EntityIdFactory.getFactory((RowKeyFormat2) mFormattedLayout.getDesc().getKeysFormat());

    for (byte b = 32; b < 127; b++) {
      for (byte b2 = 32; b2 < 127; b2++) {
        final EntityId eid =
            factory.getEntityId(
                String.format("dumm%sy", new String(new byte[] {b, b2}, "Utf-8")),
                "str1",
                "str2",
                5,
                10L);

        assertEquals(
            eid, ToolUtils.createEntityIdFromUserInputs(eid.toShellString(), mFormattedLayout));
      }
    }
  }