assertTrue (appliSetAttr_0 != null);
//assertEquals ((CompositeImpl)appliSetAttr_0.getMainInst () != null);
System.out.println(" Testing attributes on main implem declared: location = {living, kitchen, bedroom}");
Implementation impl = appliSetAttr.getMainImpl(); //S1toS2Final
Specification spec = impl.getSpec() ;
Instance inst = null ;
inst = impl.getInst() ; // any instance
System.out.println("Tested instance : " + inst + ". TestedImpl : " + impl + " Tested spec : " + spec);
//check attributes defined in the xml
System.out.println("=========== start testing xml attributes");
assertEquals (spec.getProperty("S1-Attr"), "coucou") ;
assertNotEquals (spec.getProperty("s1-attr"), "coucou") ; //case sensitive for attr
assertNotEquals (spec.getProperty("S1-Attr"), "Coucou") ; // case sensitive for value
assertEquals (impl.getProperty("S1-Attr"), "coucou") ;
assertEquals (inst.getProperty("S1-Attr"), "coucou") ;
assertEquals (spec.getProperty("S1-Enum"), "s1-2") ;
assertEquals (impl.getProperty("S1-Enum"), "s1-2") ;
assertEquals (inst.getProperty("S1-Enum"), "s1-2") ;
//default values S1toS2Final-Attr
assertNotEquals (spec.getProperty("s1b"), "true") ;
assertEquals (impl.getProperty("s1b"), "true") ;
assertEquals (inst.getProperty("s1b"), "true") ;
assertEquals (impl.getProperty("location"), "bedroom") ;
assertEquals (inst.getProperty("S1toS2Final-Bool"), "true") ;
assertNotEquals (impl.getProperty("S1toS2Final-Bool"), "true") ;
assertTrue (impl.getProperty("S1toS2Final-Attr") == null) ;
assertTrue (inst.getProperty("S1toS2Final-Attr") == null) ;
assertEquals (impl.getProperty("testEnumere"), "v2") ;
assertEquals (inst.getProperty("testEnumere"), "v2") ;
// assertTrue (inst.getProperty("S1toS2Final-Bool") == null) ;
// assertEquals (inst.getProperty("S1toS2Final-String"), "a String Value") ;
// assertTrue (inst.getProperty("badAttr") == null) ;
System.out.println("=========== passed testing xml attributes");
System.out.println("=========== start testing setting attributes");
// <property name="autoString" value="aValue" type="string"/>
// <property name="autoSet" value="Z-1, Z-2" type="{Z-0, Z-1, Z-2, Z-3}"/>
//setting auto defined attributes
assertEquals (impl.getProperty("autoString"), "aValue") ;
assertEquals (inst.getProperty("autoString"), "aValue") ;
assertEquals (impl.getProperty("autoSet"), "Z-1, Z-2") ;
assertEquals (inst.getProperty("autoSet"), "Z-1, Z-2") ;
impl.setProperty("autoString", "New-value") ;
assertEquals (impl.getProperty("autoString"), "New-value") ;
assertEquals (inst.getProperty("autoString"), "New-value") ;
impl.setProperty("autoSet", "Z-3, Z-2") ;
assertEquals (impl.getProperty("autoSet"), "Z-3, Z-2") ;
assertEquals (inst.getProperty("autoSet"), "Z-3, Z-2") ;
//is it allowed to set an attribute at the level of its definition ? If YES, it should be equal.
impl.setProperty("S1toS2Final-String1", "falseVal") ;
assertEquals(impl.getProperty("S1toS2Final-String1"), "falseVal");
//Setting spec attributes.
spec.setProperty("xxx", "value") ;
assertTrue (spec.getProperty("xxx") == null) ;
spec.setProperty("S1-Attr", "New-value") ;
assertEquals (spec.getProperty("S1-Attr"), "New-value") ;
assertEquals (impl.getProperty("S1-Attr"), "New-value") ;
assertEquals (inst.getProperty("S1-Attr"), "New-value") ;
spec.setProperty("S1-Enum", "New-value") ;
assertEquals (spec.getProperty("S1-Enum"), "s1-2") ;
spec.setProperty("S1-Enum", "s1-3") ;
assertEquals (spec.getProperty("S1-Enum"), "s1-3") ;
assertEquals (impl.getProperty("S1-Enum"), "s1-3") ;
assertEquals (inst.getProperty("S1-Enum"), "s1-3") ;
impl.setProperty("S1-Enum", "s1-1") ;
assertEquals (spec.getProperty("S1-Enum"), "s1-3") ;
assertEquals (impl.getProperty("S1-Enum"), "s1-3") ;
assertEquals (inst.getProperty("S1-Enum"), "s1-3") ;
impl.setProperty("location", "living"); // good
assertEquals(impl.getProperty("location"), "living");
assertEquals(inst.getProperty("location"), "living");
impl.setProperty("location", "Living"); // error: Value is case sensitive
assertEquals(impl.getProperty("location"), "living");
impl.setProperty("location", "anywhere"); // error: false value
assertEquals(impl.getProperty("location"), "living");
impl.setProperty("testMain", "valeurTestMain"); // error: not defined
assertTrue(impl.getProperty("testMain") == null);
impl.setProperty("impl-name", "5"); // error: final attribute
assertEquals(impl.getProperty("impl-name"), impl.getName());
//boolean
impl.setProperty("s1b", "5"); // error: bool attribute
assertNotEquals(impl.getProperty("s1b"), "5");
impl.setProperty("s1b", "true"); // Ok
assertEquals(impl.getProperty("s1b"), "true");
assertEquals(inst.getProperty("s1b"), "true");
//integer
impl.setProperty("s1i", "entier"); // error: int attribute
assertTrue(impl.getProperty("s1i") == null);
impl.setProperty("s1i", "5"); // Ok
assertEquals(impl.getProperty("s1i"), "5");
assertEquals(inst.getProperty("s1i"), "5");
impl.setProperty("s1i", "5, 7, 55,985"); // Ok
assertNotEquals(impl.getProperty("s1i"), "5, 7, 55,985");
// assertEquals(inst.getProperty("s1i"), "5, 7, 55,985");
// impl.setProperty("s1i", "5, zz, 55,985"); // wrong
// assertNotEquals(impl.getProperty("s1i"), "5, zz, 55,985");
boolean ok ;
assertTrue ( inst.match("(s1i>=4)")) ;
assertTrue (!inst.match("(s1i<=4)")) ;
assertTrue (!inst.match("(s1i>=6)")) ;
assertTrue ( inst.match("(s1i<=6)")) ;
assertTrue (!inst.match("(s1i>=10)")) ;
assertTrue ( inst.match("(s1i<=10)")) ;
assertTrue ( inst.match("(s1i>=01)")) ;
assertTrue (!inst.match("(s1i<=01)")) ;
assertTrue ( inst.match("(s1i>=-61)")) ;
assertTrue (!inst.match("(s1i<=-61)")) ;
impl.setProperty("S1-Attr", "5"); // error: cannot redefine
assertEquals(spec.getProperty("S1-Attr"), "New-value");
//field and internal. Set by program when starting
assertEquals(inst.getProperty("fieldAttr"), "initial set by program");
String s = "to set the field attribute" ;
((TestAttr)inst.getServiceObject()).callS1 (s) ; //callS1 sets the attribute to s