Exemplo n.º 1
0
  @Test
  public void test_keyMetaInformation_shouldPass() {
    // setup key with meta
    Key key = Key.create(KEY_1_NAME, Key.KEY_VALUE, KEY_1_VALUE, Key.KEY_END);
    key.setMeta(KEY_1_META_1_NAME, KEY_1_META_1_VALUE);
    key.setMeta(KEY_1_META_2_NAME, KEY_1_META_2_VALUE);
    key.rewindMeta();

    // check meta
    Key meta_1 = key.currentMeta();
    assertEquals(KEY_1_META_1_NAME, meta_1.getName());
    assertEquals(KEY_1_META_1_VALUE, meta_1.getString());
    Key meta_2 = key.nextMeta();
    assertEquals(KEY_1_META_2_NAME, meta_2.getName());
    assertEquals(KEY_1_META_2_VALUE, meta_2.getString());

    // setup another key
    Key key2 = Key.create(KEY_2_NAME, Key.KEY_VALUE, KEY_2_VALUE, Key.KEY_END);
    key2.copyAllMeta(key);
    key2.rewindMeta();

    // check meta for second key
    Key meta_1_2 = key2.currentMeta();
    assertEquals(KEY_1_META_1_NAME, meta_1_2.getName());
    assertEquals(KEY_1_META_1_VALUE, meta_1_2.getString());
    Key meta_2_2 = key2.nextMeta();
    assertEquals(KEY_1_META_2_NAME, meta_2_2.getName());
    assertEquals(KEY_1_META_2_VALUE, meta_2_2.getString());
  }
Exemplo n.º 2
0
 @Test
 public void test_keyGetBaseName_shouldPass() {
   Key key = Key.create(KEY_1_NAME, Key.KEY_VALUE, KEY_1_VALUE, Key.KEY_END);
   Key key2 = Key.create(KEY_2_NAME, Key.KEY_VALUE, KEY_2_VALUE, Key.KEY_END);
   assertEquals(KEY_1_NAME_PART_4, key.getBaseName());
   assertEquals(KEY_2_NAME_PART_4, key2.getBaseName());
 }
Exemplo n.º 3
0
 @Test
 public void test_keyCompare_shouldPass() {
   Key key = Key.create(KEY_1_NAME, Key.KEY_VALUE, KEY_1_VALUE, Key.KEY_END);
   Key key2 = Key.create(KEY_2_NAME, Key.KEY_VALUE, KEY_2_VALUE, Key.KEY_END);
   assertEquals(0, key.cmp(key));
   assertEquals(-1, key.cmp(key2));
   assertEquals(1, key2.cmp(key));
 }
Exemplo n.º 4
0
 @Test
 public void test_keyGetValueSize_shouldPass() {
   Key key = Key.create(KEY_1_NAME, Key.KEY_VALUE, KEY_1_VALUE, Key.KEY_END);
   Key key2 = Key.create(KEY_2_NAME, Key.KEY_VALUE, KEY_2_VALUE, Key.KEY_END);
   Key key3 = Key.create(KEY_3_NAME, Key.KEY_VALUE, KEY_3_VALUE, Key.KEY_END);
   assertEquals(KEY_1_VALUE.length() + 1, key.getValueSize());
   assertEquals(KEY_2_VALUE.length() + 1, key2.getValueSize());
   assertEquals(KEY_3_VALUE.length() + 1, key3.getValueSize());
 }
Exemplo n.º 5
0
 @Test
 public void test_keyIsBelow_shouldPass() {
   Key key = Key.create(KEY_10_NAME, Key.KEY_VALUE, KEY_10_VALUE, Key.KEY_END);
   Key key2 = Key.create(KEY_11_NAME, Key.KEY_VALUE, KEY_11_VALUE, Key.KEY_END);
   Key key3 = Key.create(KEY_12_NAME, Key.KEY_VALUE, KEY_12_VALUE, Key.KEY_END);
   assertEquals(true, key2.isBelow(key));
   assertEquals(true, key3.isBelow(key));
   assertEquals(true, key3.isBelow(key2));
   assertEquals(false, key.isBelow(key));
 }
Exemplo n.º 6
0
 @Test
 public void test_keyRelation_shouldPass() {
   Key key = Key.create(KEY_10_NAME, Key.KEY_VALUE, KEY_10_VALUE, Key.KEY_END);
   Key key2 = Key.create(KEY_11_NAME, Key.KEY_VALUE, KEY_11_VALUE, Key.KEY_END);
   Key key3 = Key.create(KEY_12_NAME, Key.KEY_VALUE, KEY_12_VALUE, Key.KEY_END);
   assertEquals(0, key.rel(key));
   assertEquals(1, key.rel(key2));
   assertEquals(2, key.rel(key3));
   assertEquals(1, key2.rel(key3));
 }
Exemplo n.º 7
0
 @Test
 public void test_keySetName_shouldPass() {
   String new_keyname = "/some_random/test/stuff_or/whatever";
   Key key = Key.create(KEY_1_NAME, Key.KEY_VALUE, KEY_1_VALUE, Key.KEY_END);
   key.setName(new_keyname);
   assertEquals(new_keyname, key.getName());
 }
Exemplo n.º 8
0
 @Test(expected = KeyInvalidName.class)
 public void test_keySetName_shouldFail() {
   String new_keyname = "some_random/test/stuff_or/whatever"; // initial slash missing
   Key key = Key.create(KEY_1_NAME, Key.KEY_VALUE, KEY_1_VALUE, Key.KEY_END);
   key.setName(new_keyname);
   assertEquals(new_keyname, key.getName());
 }
Exemplo n.º 9
0
 @Test
 public void test_keySetBaseName_shouldPass() {
   // note: slashes in basename will be escaped
   String new_basename = "/some_random/string";
   Key key = Key.create(KEY_1_NAME, Key.KEY_VALUE, KEY_1_VALUE, Key.KEY_END);
   key.setBaseName(new_basename);
   assertEquals(new_basename, key.getBaseName());
 }
Exemplo n.º 10
0
 @Test
 public void test_keyGetSetString_shouldPass() {
   String new_string = "some_random new key value.blub";
   Key key = Key.create(KEY_1_NAME, Key.KEY_VALUE, KEY_1_VALUE, Key.KEY_END);
   assertEquals(KEY_1_VALUE, key.getString());
   key.setString(new_string);
   assertEquals(new_string, key.getString());
 }
Exemplo n.º 11
0
 @Test
 public void test_createKeyFromPointer_shouldPass() {
   Key key = Key.create(KEY_1_NAME, Key.KEY_VALUE, KEY_1_VALUE, Key.KEY_END);
   Key key2 = new Key(key.get());
   assertEquals(key.toString(), key2.toString()); // equal key name
   assertEquals(key.getString(), key2.getString()); // equal key value
   assertEquals(key.get(), key2.get()); // equal pointer
 }
Exemplo n.º 12
0
 @Test
 public void test_keyWithBooleanValue_shouldPass() {
   Key key = Key.create(KEY_2_NAME, Key.KEY_VALUE, KEY_2_VALUE, Key.KEY_END);
   assertEquals(key.getBoolean(), false);
   key.setBoolean(true);
   assertEquals(key.getBoolean(), true);
   key.setString("false");
   assertEquals(key.getBoolean(), false);
   assertEquals(key.getString(), "false");
 }
Exemplo n.º 13
0
 @Test
 public void test_keyNameIterator_shouldPass() {
   Key key = Key.create(KEY_1_NAME, Key.KEY_VALUE, KEY_1_VALUE, Key.KEY_END);
   Iterator<String> iterator = key.iterator();
   assertTrue(iterator.hasNext());
   assertEquals(KEY_1_NAME_PART_1, iterator.next());
   assertTrue(iterator.hasNext());
   assertEquals(KEY_1_NAME_PART_2, iterator.next());
   assertTrue(iterator.hasNext());
   assertEquals(KEY_1_NAME_PART_3, iterator.next());
   assertTrue(iterator.hasNext());
   assertEquals(KEY_1_NAME_PART_4, iterator.next());
   assertFalse(iterator.hasNext());
 }
Exemplo n.º 14
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());
 }
Exemplo n.º 15
0
 @Test
 public void test_createKey_shouldPass() {
   Key key = Key.create(KEY_1_NAME, Key.KEY_VALUE, KEY_1_VALUE, Key.KEY_END);
   assertEquals(KEY_1_NAME, key.toString());
   assertEquals(KEY_1_VALUE, key.getString());
 }
Exemplo n.º 16
0
 @Test
 public void test_keyWithShortValue_shouldPass() {
   Key key = Key.create(KEY_4_NAME, Key.KEY_VALUE, KEY_4_VALUE, Key.KEY_END);
   assertEquals(true, Short.parseShort(KEY_4_VALUE) == key.getShort().shortValue());
 }
Exemplo n.º 17
0
 @Test(expected = NumberFormatException.class)
 public void test_keyWithTooBigIntegerValue_shouldFail() {
   Key key = Key.create(KEY_6_NAME, Key.KEY_VALUE, KEY_6_VALUE, Key.KEY_END);
   // assert only to trigger key.getInteger() function which throws exception
   assertEquals(false, Long.parseLong(KEY_6_VALUE) == key.getInteger().intValue());
 }
Exemplo n.º 18
0
 @Test
 public void test_keyWithIntegerValue_shouldPass() {
   Key key = Key.create(KEY_5_NAME, Key.KEY_VALUE, KEY_5_VALUE, Key.KEY_END);
   assertEquals(true, Integer.parseInt(KEY_5_VALUE) == key.getInteger().intValue());
 }
Exemplo n.º 19
0
 @Test
 public void test_keyWithLongValue_shouldPass() {
   Key key = Key.create(KEY_6_NAME, Key.KEY_VALUE, KEY_6_VALUE, Key.KEY_END);
   assertEquals(true, Long.parseLong(KEY_6_VALUE) == key.getLong().longValue());
 }
Exemplo n.º 20
0
 @Test(expected = NumberFormatException.class)
 public void test_keyWithTooBigLongValue_shouldFail() {
   Key key = Key.create(KEY_7_NAME, Key.KEY_VALUE, KEY_7_VALUE, Key.KEY_END);
   // assert only to trigger key.getLong() function which throws exception
   assertEquals(false, 1 == key.getLong().longValue());
 }
Exemplo n.º 21
0
 @Test
 public void test_keyWithFloatValue_shouldPass() {
   Key key = Key.create(KEY_8_NAME, Key.KEY_VALUE, KEY_8_VALUE, Key.KEY_END);
   assertEquals(Float.parseFloat(KEY_8_VALUE), key.getFloat().floatValue(), 0.0f);
 }
Exemplo n.º 22
0
 @Test
 public void test_keyWithDoubleValue_shouldPass() {
   Key key = Key.create(KEY_9_NAME, Key.KEY_VALUE, KEY_9_VALUE, Key.KEY_END);
   assertEquals(Double.parseDouble(KEY_9_VALUE), key.getDouble().doubleValue(), 0.0d);
 }
Exemplo n.º 23
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());
 }