### Question:
AbstractIRODSPackingInstruction implements IRodsPI { protected Tag createKeyValueTag(final List<KeyValuePair> kvps) throws JargonException { if (kvps == null) { throw new JargonException("kvps are null"); } Tag pair = new Tag(KEY_VAL_PAIR_PI, new Tag(SS_LEN, 0)); int ssLength = 0; if (kvps.size() == 0) { return pair; } for (KeyValuePair kvp : kvps) { pair.addTag(KEYWORD, kvp.getKey()); ssLength++; } pair.getTags()[0].setValue(ssLength); if (ssLength == 0) { return pair; } for (KeyValuePair kvp : kvps) { pair.addTag(S_VALUE, kvp.getValue()); } if (log.isDebugEnabled()) { log.debug("kvp tag: {}", pair.parseTag()); } return pair; } AbstractIRODSPackingInstruction(); @Override String getParsedTags(); abstract Tag getTagValue(); @Override int getApiNumber(); static final String KEY_VAL_PAIR_PI; static final String SS_LEN; static final String KEYWORD; static final String COND_INPUT; static final String S_VALUE; static final String INT_PI; static final String MY_INT; static final String L1_DESC_INX; static final String INX_VAL_PAIR_PI; static final String HEADER_PI; static final String IS_LEN; static final String INX; }### Answer:
@Test public final void testCreateKeyValueTag() throws Exception { DataObjInp dataObjInp = DataObjInp.instance("/abspath", DataObjInp.DEFAULT_CREATE_MODE, DataObjInp.OpenFlags.READ, 0L, 0L, "testResource", null); List<KeyValuePair> kvps = new ArrayList<KeyValuePair>(); kvps.add(KeyValuePair.instance("testkey", "testvalue")); Tag tag = dataObjInp.createKeyValueTag(kvps); String expectedValue = "<KeyValPair_PI><ssLen>1</ssLen>\n<keyWord>testkey</keyWord>\n<svalue>testvalue</svalue>\n</KeyValPair_PI>\n"; Assert.assertEquals("unexpected tag generated for kvp", expectedValue, tag.parseTag()); }
@Test public final void testCreateKeyValueTag2Kvps() throws Exception { DataObjInp dataObjInp = DataObjInp.instance("/abspath", DataObjInp.DEFAULT_CREATE_MODE, DataObjInp.OpenFlags.READ, 0L, 0L, "testResource", null); List<KeyValuePair> kvps = new ArrayList<KeyValuePair>(); kvps.add(KeyValuePair.instance("testkey", "testvalue")); kvps.add(KeyValuePair.instance("testkey2", "testvalue2")); Tag tag = dataObjInp.createKeyValueTag(kvps); String expectedValue = "<KeyValPair_PI><ssLen>2</ssLen>\n<keyWord>testkey</keyWord>\n<keyWord>testkey2</keyWord>\n<svalue>testvalue</svalue>\n<svalue>testvalue2</svalue>\n</KeyValPair_PI>\n"; Assert.assertEquals("unexpected tag generated for kvp", expectedValue, tag.parseTag()); }
@Test public final void testCreateKeyValueTagNoKvps() throws Exception { DataObjInp dataObjInp = DataObjInp.instance("/abspath", DataObjInp.DEFAULT_CREATE_MODE, DataObjInp.OpenFlags.READ, 0L, 0L, "testResource", null); List<KeyValuePair> kvps = new ArrayList<KeyValuePair>(); Tag tag = dataObjInp.createKeyValueTag(kvps); String expectedValue = "<KeyValPair_PI><ssLen>0</ssLen>\n</KeyValPair_PI>\n"; Assert.assertEquals("unexpected tag generated for kvp", expectedValue, tag.parseTag()); }