LiteralAttribute extends AbstractIndexableAttribute { @Override public int registerXAttribute(XAttribute attr) { if (attr instanceof XAttributeLiteral && this.getKey().equals(attr.getKey())) { String value = ((XAttributeLiteral) attr).getValue(); if (!indexMap.containsKey(value)) { values.add(value); indexMap.put(value, values.size()-1); return (values.size()-1); } else { return -1; } } else { return -1; } } LiteralAttribute(String key, AttributeLevel level); @Override int registerXAttribute(XAttribute attr); @Override ImmutableList<Object> getValues(); @Override int getValueIndex(Object value); @Override Object getValue(int index); @Override int getValueSize();  }
@Test public void testRegisterXAttributeWithInvalidType() { LiteralAttribute att = new LiteralAttribute("concept:name", AttributeLevel.EVENT); int result = att.registerXAttribute(xAttFactory.createAttributeDiscrete("concept:name", 100, null)); Assert.assertEquals(-1, result); }
@Test public void testRegisterXAttributeWithInvalidKey() { LiteralAttribute att = new LiteralAttribute("concept:name", AttributeLevel.EVENT); int result = att.registerXAttribute(xAttFactory.createAttributeLiteral("invalid_key", "test", null)); Assert.assertEquals(-1, result); }
@Test public void testRegisterValidXAttribute() { LiteralAttribute att = new LiteralAttribute("concept:name", AttributeLevel.EVENT); XAttributeLiteral xatt = xAttFactory.createAttributeLiteral("concept:name", "test", null); int result = att.registerXAttribute(xatt); Assert.assertEquals(0, result); }