public void test_XMLToken_newSetters_addAttributes1() { XMLTriple triple = new XMLTriple("test","",""); XMLAttributes attr = new XMLAttributes(); XMLToken token = new XMLToken(triple,attr); XMLTriple xt2 = new XMLTriple("name3", "http://name3.org/", "p3"); int i = token.addAttr( "name1", "val1"); assertTrue( i == libsbml.LIBSBML_OPERATION_SUCCESS ); assertTrue( token.getAttributesLength() == 1 ); assertTrue( token.isAttributesEmpty() == false ); assertTrue( ( "name1" != token.getAttrName(0) ) == false ); assertTrue( ( "val1" != token.getAttrValue(0) ) == false ); i = token.addAttr( "name2", "val2", "http://name1.org/", "p1"); assertTrue( i == libsbml.LIBSBML_OPERATION_SUCCESS ); assertTrue( token.getAttributesLength() == 2 ); assertTrue( token.isAttributesEmpty() == false ); assertTrue( ( "name2" != token.getAttrName(1) ) == false ); assertTrue( ( "val2" != token.getAttrValue(1) ) == false ); assertTrue( ( "http://name1.org/" != token.getAttrURI(1) ) == false ); assertTrue( ( "p1" != token.getAttrPrefix(1) ) == false ); i = token.addAttr(xt2, "val2"); assertTrue( i == libsbml.LIBSBML_OPERATION_SUCCESS ); assertTrue( token.getAttributesLength() == 3 ); assertTrue( token.isAttributesEmpty() == false ); assertTrue( ( "name3" != token.getAttrName(2) ) == false ); assertTrue( ( "val2" != token.getAttrValue(2) ) == false ); assertTrue( ( "http://name3.org/" != token.getAttrURI(2) ) == false ); assertTrue( ( "p3" != token.getAttrPrefix(2) ) == false ); xt2 = null; triple = null; attr = null; token = null; }
public void test_XMLToken_attribute_add_remove() { XMLTriple triple = new XMLTriple("test","",""); XMLAttributes attr = new XMLAttributes(); XMLToken token = new XMLToken(triple,attr); XMLTriple xt1 = new XMLTriple("name1", "http://name1.org/", "p1"); XMLTriple xt2 = new XMLTriple("name2", "http://name2.org/", "p2"); XMLTriple xt3 = new XMLTriple("name3", "http://name3.org/", "p3"); XMLTriple xt1a = new XMLTriple("name1", "http://name1a.org/", "p1a"); XMLTriple xt2a = new XMLTriple("name2", "http://name2a.org/", "p2a"); token.addAttr( "name1", "val1", "http://name1.org/", "p1"); token.addAttr(xt2, "val2"); assertTrue( token.getAttributesLength() == 2 ); assertTrue( token.isAttributesEmpty() == false ); assertTrue( ( "name1" != token.getAttrName(0) ) == false ); assertTrue( ( "val1" != token.getAttrValue(0) ) == false ); assertTrue( ( "http://name1.org/" != token.getAttrURI(0) ) == false ); assertTrue( ( "p1" != token.getAttrPrefix(0) ) == false ); assertTrue( ( "name2" != token.getAttrName(1) ) == false ); assertTrue( ( "val2" != token.getAttrValue(1) ) == false ); assertTrue( ( "http://name2.org/" != token.getAttrURI(1) ) == false ); assertTrue( ( "p2" != token.getAttrPrefix(1) ) == false ); assertTrue( token.getAttrValue( "name1") == "" ); assertTrue( token.getAttrValue( "name2") == "" ); assertTrue( ( "val1" != token.getAttrValue( "name1", "http://name1.org/") ) == false ); assertTrue( ( "val2" != token.getAttrValue( "name2", "http://name2.org/") ) == false ); assertTrue( ( "val1" != token.getAttrValue(xt1) ) == false ); assertTrue( ( "val2" != token.getAttrValue(xt2) ) == false ); assertTrue( token.hasAttr(-1) == false ); assertTrue( token.hasAttr(2) == false ); assertTrue( token.hasAttr(0) == true ); assertTrue( token.hasAttr( "name1", "http://name1.org/") == true ); assertTrue( token.hasAttr( "name2", "http://name2.org/") == true ); assertTrue( token.hasAttr( "name3", "http://name3.org/") == false ); assertTrue( token.hasAttr(xt1) == true ); assertTrue( token.hasAttr(xt2) == true ); assertTrue( token.hasAttr(xt3) == false ); token.addAttr( "noprefix", "val3"); assertTrue( token.getAttributesLength() == 3 ); assertTrue( token.isAttributesEmpty() == false ); assertTrue( ( "noprefix" != token.getAttrName(2) ) == false ); assertTrue( ( "val3" != token.getAttrValue(2) ) == false ); assertTrue( token.getAttrURI(2) == "" ); assertTrue( token.getAttrPrefix(2) == "" ); assertTrue( ( "val3" != token.getAttrValue( "noprefix") ) == false ); assertTrue( ( "val3" != token.getAttrValue( "noprefix", "") ) == false ); assertTrue( token.hasAttr( "noprefix" ) == true ); assertTrue( token.hasAttr( "noprefix", "") == true ); token.addAttr(xt1, "mval1"); token.addAttr( "name2", "mval2", "http://name2.org/", "p2"); assertTrue( token.getAttributesLength() == 3 ); assertTrue( token.isAttributesEmpty() == false ); assertTrue( ( "name1" != token.getAttrName(0) ) == false ); assertTrue( ( "mval1" != token.getAttrValue(0) ) == false ); assertTrue( ( "http://name1.org/" != token.getAttrURI(0) ) == false ); assertTrue( ( "p1" != token.getAttrPrefix(0) ) == false ); assertTrue( ( "name2" != token.getAttrName(1) ) == false ); assertTrue( ( "mval2" != token.getAttrValue(1) ) == false ); assertTrue( ( "http://name2.org/" != token.getAttrURI(1) ) == false ); assertTrue( ( "p2" != token.getAttrPrefix(1) ) == false ); assertTrue( token.hasAttr(xt1) == true ); assertTrue( token.hasAttr( "name1", "http://name1.org/") == true ); token.addAttr( "noprefix", "mval3"); assertTrue( token.getAttributesLength() == 3 ); assertTrue( token.isAttributesEmpty() == false ); assertTrue( ( "noprefix" != token.getAttrName(2) ) == false ); assertTrue( ( "mval3" != token.getAttrValue(2) ) == false ); assertTrue( token.getAttrURI(2) == "" ); assertTrue( token.getAttrPrefix(2) == "" ); assertTrue( token.hasAttr( "noprefix") == true ); assertTrue( token.hasAttr( "noprefix", "") == true ); token.addAttr(xt1a, "val1a"); token.addAttr(xt2a, "val2a"); assertTrue( token.getAttributesLength() == 5 ); assertTrue( ( "name1" != token.getAttrName(3) ) == false ); assertTrue( ( "val1a" != token.getAttrValue(3) ) == false ); assertTrue( ( "http://name1a.org/" != token.getAttrURI(3) ) == false ); assertTrue( ( "p1a" != token.getAttrPrefix(3) ) == false ); assertTrue( ( "name2" != token.getAttrName(4) ) == false ); assertTrue( ( "val2a" != token.getAttrValue(4) ) == false ); assertTrue( ( "http://name2a.org/" != token.getAttrURI(4) ) == false ); assertTrue( ( "p2a" != token.getAttrPrefix(4) ) == false ); assertTrue( ( "val1a" != token.getAttrValue( "name1", "http://name1a.org/") ) == false ); assertTrue( ( "val2a" != token.getAttrValue( "name2", "http://name2a.org/") ) == false ); assertTrue( ( "val1a" != token.getAttrValue(xt1a) ) == false ); assertTrue( ( "val2a" != token.getAttrValue(xt2a) ) == false ); token.removeAttr(xt1a); token.removeAttr(xt2a); assertTrue( token.getAttributesLength() == 3 ); token.removeAttr( "name1", "http://name1.org/"); assertTrue( token.getAttributesLength() == 2 ); assertTrue( token.isAttributesEmpty() == false ); assertTrue( ( "name2" != token.getAttrName(0) ) == false ); assertTrue( ( "mval2" != token.getAttrValue(0) ) == false ); assertTrue( ( "http://name2.org/" != token.getAttrURI(0) ) == false ); assertTrue( ( "p2" != token.getAttrPrefix(0) ) == false ); assertTrue( ( "noprefix" != token.getAttrName(1) ) == false ); assertTrue( ( "mval3" != token.getAttrValue(1) ) == false ); assertTrue( token.getAttrURI(1) == "" ); assertTrue( token.getAttrPrefix(1) == "" ); assertTrue( token.hasAttr( "name1", "http://name1.org/") == false ); token.removeAttr(xt2); assertTrue( token.getAttributesLength() == 1 ); assertTrue( token.isAttributesEmpty() == false ); assertTrue( ( "noprefix" != token.getAttrName(0) ) == false ); assertTrue( ( "mval3" != token.getAttrValue(0) ) == false ); assertTrue( token.getAttrURI(0) == "" ); assertTrue( token.getAttrPrefix(0) == "" ); assertTrue( token.hasAttr(xt2) == false ); assertTrue( token.hasAttr( "name2", "http://name2.org/") == false ); token.removeAttr( "noprefix"); assertTrue( token.getAttributesLength() == 0 ); assertTrue( token.isAttributesEmpty() == true ); assertTrue( token.hasAttr( "noprefix" ) == false ); assertTrue( token.hasAttr( "noprefix", "") == false ); token = null; xt1 = null; xt2 = null; xt3 = null; xt1a = null; xt2a = null; triple = null; attr = null; }
public void test_XMLToken_attribute_set_clear() { XMLTriple triple = new XMLTriple("test","",""); XMLAttributes attr = new XMLAttributes(); XMLToken token = new XMLToken(triple,attr); XMLAttributes nattr = new XMLAttributes(); XMLTriple xt1 = new XMLTriple("name1", "http://name1.org/", "p1"); XMLTriple xt2 = new XMLTriple("name2", "http://name2.org/", "p2"); XMLTriple xt3 = new XMLTriple("name3", "http://name3.org/", "p3"); XMLTriple xt4 = new XMLTriple("name4", "http://name4.org/", "p4"); XMLTriple xt5 = new XMLTriple("name5", "http://name5.org/", "p5"); nattr.add(xt1, "val1"); nattr.add(xt2, "val2"); nattr.add(xt3, "val3"); nattr.add(xt4, "val4"); nattr.add(xt5, "val5"); token.setAttributes(nattr); assertTrue( token.getAttributesLength() == 5 ); assertTrue( token.isAttributesEmpty() == false ); assertTrue( ( "name1" != token.getAttrName(0) ) == false ); assertTrue( ( "val1" != token.getAttrValue(0) ) == false ); assertTrue( ( "http://name1.org/" != token.getAttrURI(0) ) == false ); assertTrue( ( "p1" != token.getAttrPrefix(0) ) == false ); assertTrue( ( "name2" != token.getAttrName(1) ) == false ); assertTrue( ( "val2" != token.getAttrValue(1) ) == false ); assertTrue( ( "http://name2.org/" != token.getAttrURI(1) ) == false ); assertTrue( ( "p2" != token.getAttrPrefix(1) ) == false ); assertTrue( ( "name3" != token.getAttrName(2) ) == false ); assertTrue( ( "val3" != token.getAttrValue(2) ) == false ); assertTrue( ( "http://name3.org/" != token.getAttrURI(2) ) == false ); assertTrue( ( "p3" != token.getAttrPrefix(2) ) == false ); assertTrue( ( "name4" != token.getAttrName(3) ) == false ); assertTrue( ( "val4" != token.getAttrValue(3) ) == false ); assertTrue( ( "http://name4.org/" != token.getAttrURI(3) ) == false ); assertTrue( ( "p4" != token.getAttrPrefix(3) ) == false ); assertTrue( ( "name5" != token.getAttrName(4) ) == false ); assertTrue( ( "val5" != token.getAttrValue(4) ) == false ); assertTrue( ( "http://name5.org/" != token.getAttrURI(4) ) == false ); assertTrue( ( "p5" != token.getAttrPrefix(4) ) == false ); XMLTriple ntriple = new XMLTriple("test2","http://test2.org/","p2"); token.setTriple(ntriple); assertTrue( ( "test2" != token.getName() ) == false ); assertTrue( ( "http://test2.org/" != token.getURI() ) == false ); assertTrue( ( "p2" != token.getPrefix() ) == false ); token.clearAttributes(); assertTrue( token.getAttributesLength() == 0 ); assertTrue( token.isAttributesEmpty() != false ); nattr = null; triple = null; ntriple = null; attr = null; token = null; xt1 = null; xt2 = null; xt3 = null; xt4 = null; xt5 = null; }