From d4b528eedf69a14bf39e8b24b905a9b37725d5ac Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sat, 3 Jul 2021 00:12:50 +0200 Subject: [PATCH] [DEV] update real separation between the node and the properties --- .../exml/builder/IntrospectionModel.java | 5 +- .../builder/IntrospectionModelComplex.java | 127 +++++++--- .../generator/GeneratorIntrospection.java | 6 +- .../exml/ExmlTestIntrospectionBoolean.java | 239 +++++++++++++++++- 4 files changed, 332 insertions(+), 45 deletions(-) diff --git a/src/org/atriasoft/exml/builder/IntrospectionModel.java b/src/org/atriasoft/exml/builder/IntrospectionModel.java index 460a9dc..daf2d24 100644 --- a/src/org/atriasoft/exml/builder/IntrospectionModel.java +++ b/src/org/atriasoft/exml/builder/IntrospectionModel.java @@ -7,16 +7,17 @@ import org.atriasoft.exml.exception.ExmlBuilderException; public abstract class IntrospectionModel { + protected static final Boolean DEFAULT_ATTRIBUTE = false; protected static final Boolean DEFAULT_CASE_SENSITIVE = true; protected static final Boolean DEFAULT_MANAGED = true; protected static final Boolean DEFAULT_OPTIONAL = false; protected final Class classType; - public List getMethods() { + public List getNodes() { return null; } - public List getProperties() { + public List getAttributes() { return null; } public Class getClassType() { diff --git a/src/org/atriasoft/exml/builder/IntrospectionModelComplex.java b/src/org/atriasoft/exml/builder/IntrospectionModelComplex.java index 0fd0abf..8e90ab7 100644 --- a/src/org/atriasoft/exml/builder/IntrospectionModelComplex.java +++ b/src/org/atriasoft/exml/builder/IntrospectionModelComplex.java @@ -16,7 +16,9 @@ import java.util.stream.Collectors; import org.atriasoft.eStringSerialize.StringSerializer; import org.atriasoft.etk.util.ArraysTools; +import org.atriasoft.exml.annotation.XmlAttribute; import org.atriasoft.exml.annotation.XmlCaseSensitive; +import org.atriasoft.exml.annotation.XmlDefaultAttibute; import org.atriasoft.exml.annotation.XmlDefaultCaseSensitive; import org.atriasoft.exml.annotation.XmlDefaultManaged; import org.atriasoft.exml.annotation.XmlDefaultOptional; @@ -33,23 +35,24 @@ public class IntrospectionModelComplex extends IntrospectionModel { // TODO Optimize this with external object for basic types.... private final Method valueof; // used for the set Text if the object is an end point... - private final List methods = new ArrayList<>(); + private final List nodes = new ArrayList<>(); - private final List properties = new ArrayList<>(); + private final List attributes = new ArrayList<>(); @Override - public List getMethods() { - return this.methods; + public List getNodes() { + return this.nodes; } @Override - public List getProperties() { - return this.properties; + public List getAttributes() { + return this.attributes; } public IntrospectionModelComplex(final Class classType) throws ExmlBuilderException { super(classType); try { + final Boolean isDefaultAttribute = getIsDefaultAttribute(classType, IntrospectionModel.DEFAULT_ATTRIBUTE); final Boolean isDefaultManaged = getIsDefaultManaged(classType, IntrospectionModel.DEFAULT_MANAGED); final Boolean isDefaultOptional = getIsDefaultOptional(classType, IntrospectionModel.DEFAULT_OPTIONAL); final Boolean isDefaultCaseSensitive = getIsDefaultCaseSensitive(classType, IntrospectionModel.DEFAULT_CASE_SENSITIVE); @@ -70,6 +73,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (!Modifier.isPublic(elem.getModifiers())) { continue; } + final Boolean isAttribute = getIsAttribute(elem, isDefaultAttribute); final Boolean isManaged = getIsManaged(elem, isDefaultManaged); final Boolean isOptionnal = getIsOptional(elem, isDefaultOptional); final String[] names = getNames(elem, Tools.decapitalizeFirst(elem.getName())); @@ -77,7 +81,11 @@ public class IntrospectionModelComplex extends IntrospectionModel { final String listName = getListName(elem, null); // TODO check if property does not already exist ... if (isManaged) { - this.properties.add(new IntrospectionPropertyField(elem, names, listName, caseSensitive, isOptionnal)); + if (isAttribute) { + this.attributes.add(new IntrospectionPropertyField(elem, names, listName, caseSensitive, isOptionnal)); + } else { + this.nodes.add(new IntrospectionPropertyField(elem, names, listName, caseSensitive, isOptionnal)); + } } Log.verbose(" - " + elem.toGenericString()); } @@ -234,6 +242,13 @@ public class IntrospectionModelComplex extends IntrospectionModel { if (elem.setter != null && elem.getter != null) { Log.info(" setter: " + elem.setter.toGenericString()); Log.info(" getter: " + elem.getter.toGenericString()); + final Boolean isAttributeSet = getIsAttribute(elem.setter, null); + final Boolean isAttributeGet = getIsAttribute(elem.getter, null); + if (isAttributeSet != null && isAttributeGet != null && isAttributeSet != isAttributeGet) { + throw new Exception("Can net set oposite information on getter and setter"); + } + final Boolean isAttribute = isAttributeSet != null ? isAttributeSet : isAttributeGet != null ? isAttributeGet : isDefaultAttribute; + final Boolean isManagedSet = getIsManaged(elem.setter, null); final Boolean isManagedGet = getIsManaged(elem.getter, null); if (isManagedSet != null && isManagedGet != null && isManagedSet != isManagedGet) { @@ -265,15 +280,21 @@ public class IntrospectionModelComplex extends IntrospectionModel { final String listNameSet = getListName(elem.setter, null); final String listNameGet = getListName(elem.getter, null); final String listName = listNameSet != null? listNameSet: listNameGet; - this.methods.add(new IntrospectionPropertyMethod(elem.setter, elem.getter, names, listName, isCaseSensitive, isOptional)); + if (isAttribute) { + this.attributes.add(new IntrospectionPropertyMethod(elem.setter, elem.getter, names, listName, isCaseSensitive, isOptional)); + } else { + this.nodes.add(new IntrospectionPropertyMethod(elem.setter, elem.getter, names, listName, isCaseSensitive, isOptional)); + } } else { Boolean isManaged = null; Boolean isOptionnal = null; String[] names = null; Boolean isCaseSensitive = null; String listName = null; + Boolean isAttribute = isDefaultAttribute; if (elem.setter != null) { Log.info(" setter: " + elem.setter.toGenericString()); + isAttribute = getIsAttribute(elem.setter, isDefaultAttribute); isManaged = getIsManaged(elem.setter, isDefaultManaged); isOptionnal = getIsOptional(elem.setter, isDefaultOptional); names = getNames(elem.setter, Tools.decapitalizeFirst(elem.name)); @@ -284,6 +305,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } if (elem.getter != null) { Log.info(" getter: " + elem.getter.toGenericString()); + isAttribute = getIsAttribute(elem.getter, isDefaultAttribute); isManaged = getIsManaged(elem.getter, isDefaultManaged); isOptionnal = getIsOptional(elem.getter, isDefaultOptional); names = getNames(elem.getter, Tools.decapitalizeFirst(elem.name)); @@ -293,7 +315,11 @@ public class IntrospectionModelComplex extends IntrospectionModel { Log.info(" getter: null"); } if (isManaged) { - this.methods.add(new IntrospectionPropertyMethod(elem.setter, elem.getter, names, listName, isCaseSensitive, isOptionnal)); + if (isAttribute) { + this.attributes.add(new IntrospectionPropertyMethod(elem.setter, elem.getter, names, listName, isCaseSensitive, isOptionnal)); + } else { + this.nodes.add(new IntrospectionPropertyMethod(elem.setter, elem.getter, names, listName, isCaseSensitive, isOptionnal)); + } } } } @@ -330,16 +356,16 @@ public class IntrospectionModelComplex extends IntrospectionModel { @Override protected List getNodeAvaillable() { List out = new ArrayList<>(); - for (final IntrospectionProperty prop : this.methods) { - out.add(prop.getNames()[0]); - } - for (final IntrospectionProperty prop : this.properties) { + for (final IntrospectionProperty prop : this.nodes) { out.add(prop.getNames()[0]); } +// for (final IntrospectionProperty prop : this.attributes) { +// out.add(prop.getNames()[0]); +// } return out; } - protected IntrospectionProperty findMethodDescription(final String propertyName) throws ExmlBuilderException { - for (final IntrospectionProperty prop : this.methods) { + protected IntrospectionProperty findNodeDescription(final String propertyName) throws ExmlBuilderException { + for (final IntrospectionProperty prop : this.nodes) { if (prop.isCompatible(propertyName)) { return prop; } @@ -348,7 +374,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { } protected IntrospectionProperty findPropertyDescription(final String propertyName) throws ExmlBuilderException { - for (final IntrospectionProperty prop : this.properties) { + for (final IntrospectionProperty prop : this.attributes) { if (prop.isCompatible(propertyName)) { return prop; } @@ -362,7 +388,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { return defaultValue; } if (annotation.length > 1) { - throw new ExmlBuilderException("Must not hame more that "); + throw new ExmlBuilderException("Must not have more that "); } return ((XmlCaseSensitive) annotation[0]).value(); } @@ -373,7 +399,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { return defaultValue; } if (annotation.length > 1) { - throw new ExmlBuilderException("Must not hame more that "); + throw new ExmlBuilderException("Must not have more that "); } return ((XmlCaseSensitive) annotation[0]).value(); } @@ -384,10 +410,21 @@ public class IntrospectionModelComplex extends IntrospectionModel { return defaultValue; } if (annotation.length > 1) { - throw new ExmlBuilderException("Must not hame more that "); + throw new ExmlBuilderException("Must not have more that "); } return ((XmlDefaultCaseSensitive) annotation[0]).value(); } + + private Boolean getIsDefaultAttribute(final Class classType, final Boolean defaultValue) throws ExmlBuilderException { + final Annotation[] annotation = classType.getDeclaredAnnotationsByType(XmlDefaultAttibute.class); + if (annotation.length == 0) { + return defaultValue; + } + if (annotation.length > 1) { + throw new ExmlBuilderException("Must not have more that "); + } + return ((XmlDefaultAttibute) annotation[0]).value(); + } private Boolean getIsDefaultManaged(final Class classType, final Boolean defaultValue) throws ExmlBuilderException { final Annotation[] annotation = classType.getDeclaredAnnotationsByType(XmlDefaultManaged.class); @@ -395,7 +432,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { return defaultValue; } if (annotation.length > 1) { - throw new ExmlBuilderException("Must not hame more that "); + throw new ExmlBuilderException("Must not have more that "); } return ((XmlDefaultManaged) annotation[0]).value(); } @@ -406,18 +443,40 @@ public class IntrospectionModelComplex extends IntrospectionModel { return defaultValue; } if (annotation.length > 1) { - throw new ExmlBuilderException("Must not hame more that "); + throw new ExmlBuilderException("Must not have more that "); } return ((XmlDefaultOptional) annotation[0]).value(); } + protected Boolean getIsAttribute(final Field element, final Boolean parentValue) throws ExmlBuilderException { + final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlAttribute.class); + if (annotation.length == 0) { + return parentValue; + } + if (annotation.length > 1) { + throw new ExmlBuilderException("Must not have more that "); + } + return ((XmlAttribute) annotation[0]).value(); + } + + protected Boolean getIsAttribute(final Method element, final Boolean parentValue) throws ExmlBuilderException { + final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlAttribute.class); + if (annotation.length == 0) { + return parentValue; + } + if (annotation.length > 1) { + throw new ExmlBuilderException("Must not have more that "); + } + return ((XmlAttribute) annotation[0]).value(); + } + protected Boolean getIsManaged(final Field element, final Boolean parentValue) throws ExmlBuilderException { final Annotation[] annotation = element.getDeclaredAnnotationsByType(XmlManaged.class); if (annotation.length == 0) { return parentValue; } if (annotation.length > 1) { - throw new ExmlBuilderException("Must not hame more that "); + throw new ExmlBuilderException("Must not have more that "); } return ((XmlManaged) annotation[0]).value(); } @@ -428,7 +487,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { return parentValue; } if (annotation.length > 1) { - throw new ExmlBuilderException("Must not hame more that "); + throw new ExmlBuilderException("Must not have more that "); } return ((XmlManaged) annotation[0]).value(); } @@ -439,7 +498,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { return parentValue; } if (annotation.length > 1) { - throw new Exception("Must not hame more that "); + throw new Exception("Must not have more that "); } return ((XmlOptional) annotation[0]).value(); } @@ -450,7 +509,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { return parentValue; } if (annotation.length > 1) { - throw new Exception("Must not hame more that "); + throw new Exception("Must not have more that "); } return ((XmlOptional) annotation[0]).value(); } @@ -464,7 +523,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { return new String[] { defaultValue }; } if (annotation.length > 1) { - throw new Exception("Must not hame more that "); + throw new Exception("Must not have more that "); } final String[] tmp = ((XmlName) annotation[0]).value(); if (tmp == null) { @@ -493,7 +552,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { return new String[] { defaultValue }; } if (annotation.length > 1) { - throw new Exception("Must not hame more that "); + throw new Exception("Must not have more that "); } final String[] tmp = ((XmlName) annotation[0]).value(); if (tmp == null) { @@ -519,7 +578,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { return defaultValue; } if (annotation.length > 1) { - throw new Exception("Must not hame more that "); + throw new Exception("Must not have more that "); } final String tmp = ((XmlList) annotation[0]).value(); if (tmp == null) { @@ -533,7 +592,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { return defaultValue; } if (annotation.length > 1) { - throw new Exception("Must not hame more that "); + throw new Exception("Must not have more that "); } final String tmp = ((XmlList) annotation[0]).value(); if (tmp == null) { @@ -555,7 +614,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { private void setValue(final Object data, final String name, final Object value) throws ExmlBuilderException { Log.error(" Set value ='" + name + "' propertyValue='" + value + "' " + value.getClass().getCanonicalName()); // by default use setter to set the property - final IntrospectionProperty propMethode = findMethodDescription(name); + final IntrospectionProperty propMethode = findNodeDescription(name); if (propMethode != null && propMethode.canSetValue()) { Log.verbose(" ==> find '" + Arrays.toString(propMethode.getNames()) + " type=" + propMethode.getType() + " sub-type=" + propMethode.getSubType() ); if (propMethode.getType().isAssignableFrom(value.getClass())) { @@ -676,7 +735,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { public Class getTypeOfSubNode(final Object data, final String nodeName) throws ExmlBuilderException { Log.error(" nodeType='" + nodeName + "'"); // by default use setter to set the property - final IntrospectionProperty propMethode = findMethodDescription(nodeName); + final IntrospectionProperty propMethode = findNodeDescription(nodeName); if (propMethode != null && propMethode.canSetValue()) { Log.error(" ==> find '" + propMethode.getNames()); return propMethode.getType(); @@ -694,7 +753,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { public Class getTypeOfSubNodeList(final Object data, final String nodeName) throws ExmlBuilderException { Log.error(" nodeType='" + nodeName + "'"); // by default use setter to set the property - final IntrospectionProperty propMethode = findMethodDescription(nodeName); + final IntrospectionProperty propMethode = findNodeDescription(nodeName); if (propMethode != null && propMethode.canSetValue()) { Log.error(" ==> find '" + propMethode.getNames()); return propMethode.getSubType(); @@ -711,7 +770,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { public String getTreeNameOfSubNode(final Object data, final String nodeName) throws ExmlBuilderException { Log.error(" nodeType='" + nodeName + "'"); // by default use setter to set the property - final IntrospectionProperty propMethode = findMethodDescription(nodeName); + final IntrospectionProperty propMethode = findNodeDescription(nodeName); if (propMethode != null && propMethode.canSetValue()) { Log.error(" ==> find '" + propMethode.getNames()); return propMethode.getListName(); @@ -780,7 +839,7 @@ public class IntrospectionModelComplex extends IntrospectionModel { public Object getValue(final String propertyName, final String propertyValue) throws ExmlBuilderException { Log.error(" propertyName='" + propertyName + "' propertyValue='" + propertyValue + "' "); // by default use setter to set the property - final IntrospectionProperty propMethode = findMethodDescription(propertyName); + final IntrospectionProperty propMethode = findNodeDescription(propertyName); if (propMethode != null && propMethode.canSetValue()) { Log.verbose(" ==> find '" + propMethode.getNames()); return propMethode.createValue(propertyValue); diff --git a/src/org/atriasoft/exml/generator/GeneratorIntrospection.java b/src/org/atriasoft/exml/generator/GeneratorIntrospection.java index c1daa3e..f15fe12 100644 --- a/src/org/atriasoft/exml/generator/GeneratorIntrospection.java +++ b/src/org/atriasoft/exml/generator/GeneratorIntrospection.java @@ -34,7 +34,7 @@ public class GeneratorIntrospection implements Generator { } public void generateProperties(final Object data, final IntrospectionModel introspection, final StringBuilder tmpp) throws ExmlBuilderException { - List elements = introspection.getProperties(); + List elements = introspection.getAttributes(); if (elements == null) { return; } @@ -54,7 +54,7 @@ public class GeneratorIntrospection implements Generator { } } public void generateSubNodes(final Object data, final IntrospectionModel introspection, final StringBuilder tmpp, final int indent) throws ExmlBuilderException { - List elements = introspection.getMethods(); + List elements = introspection.getNodes(); for (IntrospectionProperty elem : elements) { if (!elem.canGetValue()) { continue; @@ -109,7 +109,7 @@ public class GeneratorIntrospection implements Generator { tmpp.append("<"); tmpp.append(nodeName); generateProperties(data, introspection, tmpp); - if (introspection.getMethods().size() != 0) { + if (introspection.getNodes().size() != 0) { tmpp.append(">"); generateSubNodes(data, introspection, tmpp, indent + 1); Tools.addIndent(tmpp, indent); diff --git a/test/src/test/atriasoft/exml/ExmlTestIntrospectionBoolean.java b/test/src/test/atriasoft/exml/ExmlTestIntrospectionBoolean.java index 6ba9d53..cda2cdb 100644 --- a/test/src/test/atriasoft/exml/ExmlTestIntrospectionBoolean.java +++ b/test/src/test/atriasoft/exml/ExmlTestIntrospectionBoolean.java @@ -100,19 +100,19 @@ public class ExmlTestIntrospectionBoolean { private Boolean valueA; private Boolean valueB; private Boolean valueNull; - public Boolean getValueA() { + public Boolean isValueA() { return this.valueA; } public void setValueA(final Boolean valueA) { this.valueA = valueA; } - public Boolean getValueB() { + public Boolean isValueB() { return this.valueB; } public void setValueB(final Boolean valueB) { this.valueB = valueB; } - public Boolean getValueNull() { + public Boolean isValueNull() { return this.valueNull; } public void setValueNull(final Boolean valueNull) { @@ -134,9 +134,9 @@ public class ExmlTestIntrospectionBoolean { Assertions.assertEquals("", dataTest); final TestBooleanFunc root = Assertions.assertDoesNotThrow(() -> Exml.parseOne(dataTest, TestBooleanFunc.class, ExmlTestIntrospectionBoolean.NODE_NAME)); - Assertions.assertEquals(false, root.getValueA()); - Assertions.assertEquals(true, root.getValueB()); - Assertions.assertEquals(null, root.getValueNull()); + Assertions.assertEquals(false, root.isValueA()); + Assertions.assertEquals(true, root.isValueB()); + Assertions.assertEquals(null, root.isValueNull()); } @XmlDefaultAttibute @@ -203,6 +203,233 @@ public class ExmlTestIntrospectionBoolean { Assertions.assertEquals(false, root.getValues().get(3)); Assertions.assertEquals(true, root.getValues().get(4)); } + + + + + + + + public class TestNodeBoolean { + public Boolean valueA; + public Boolean valueB; + public Boolean valueNull; + } + @Test + public void testModelNodeBoolean() { + TestNodeBoolean elem = new TestNodeBoolean(); + elem.valueA = false; + elem.valueB = true; + elem.valueNull = null; + + StringBuilder builder = new StringBuilder(); + Assertions.assertDoesNotThrow(() -> Exml.generate(elem, ExmlTestIntrospectionBoolean.NODE_NAME, builder)); + String dataTest = builder.toString(); + Log.warning("data generated: " + builder.toString()); + Assertions.assertEquals("\n" + + " false\n" + + " true\n" + + "", dataTest); + + final TestNodeBoolean root = Assertions.assertDoesNotThrow(() -> Exml.parseOne(dataTest, TestNodeBoolean.class, ExmlTestIntrospectionBoolean.NODE_NAME)); + Assertions.assertEquals(false, root.valueA); + Assertions.assertEquals(true, root.valueB); + Assertions.assertEquals(null, root.valueNull); + } + + public class TestArrayNodeBoolean { + public Boolean[] values; + } + @Test + public void testModelArrayNodeBoolean() { + TestArrayNodeBoolean elem = new TestArrayNodeBoolean(); + elem.values = new Boolean[] {false, false, true, false, true}; + + StringBuilder builder = new StringBuilder(); + Assertions.assertDoesNotThrow(() -> Exml.generate(elem, ExmlTestIntrospectionBoolean.NODE_NAME, builder)); + String dataTest = builder.toString(); + Log.warning("data generated: " + builder.toString()); + Assertions.assertEquals("\n" + + " false\n" + + " false\n" + + " true\n" + + " false\n" + + " true\n" + + "", dataTest); + + final TestArrayNodeBoolean root = Assertions.assertDoesNotThrow(() -> Exml.parseOne(dataTest, TestArrayNodeBoolean.class, ExmlTestIntrospectionBoolean.NODE_NAME)); + Assertions.assertEquals(5, root.values.length); + Assertions.assertEquals(false, root.values[0]); + Assertions.assertEquals(false, root.values[1]); + Assertions.assertEquals(true, root.values[2]); + Assertions.assertEquals(false, root.values[3]); + Assertions.assertEquals(true, root.values[4]); + } + + public class TestListNodeBoolean { + public List values; + } + @Test + public void testModelListNodeBoolean() { + TestListNodeBoolean elem = new TestListNodeBoolean(); + elem.values = List.of(false, false, true, false, true); + + StringBuilder builder = new StringBuilder(); + Assertions.assertDoesNotThrow(() -> Exml.generate(elem, ExmlTestIntrospectionBoolean.NODE_NAME, builder)); + String dataTest = builder.toString(); + Log.warning("data generated: " + builder.toString()); + Assertions.assertEquals("", dataTest); + + final TestListNodeBoolean root = Assertions.assertDoesNotThrow(() -> Exml.parseOne(dataTest, TestListNodeBoolean.class, ExmlTestIntrospectionBoolean.NODE_NAME)); + Assertions.assertEquals(5, root.values.size()); + Assertions.assertEquals(false, root.values.get(0)); + Assertions.assertEquals(false, root.values.get(1)); + Assertions.assertEquals(true, root.values.get(2)); + Assertions.assertEquals(false, root.values.get(3)); + Assertions.assertEquals(true, root.values.get(4)); + } + + + public class TestNodeBooleanFunc { + private Boolean valueA; + private Boolean valueB; + private Boolean valueNull; + public Boolean isValueA() { + return this.valueA; + } + public void setValueA(final Boolean valueA) { + this.valueA = valueA; + } + public Boolean isValueB() { + return this.valueB; + } + public void setValueB(final Boolean valueB) { + this.valueB = valueB; + } + public Boolean isValueNull() { + return this.valueNull; + } + public void setValueNull(final Boolean valueNull) { + this.valueNull = valueNull; + } + } + + @Test + public void testModelNodeBooleanFunc() { + TestNodeBooleanFunc elem = new TestNodeBooleanFunc(); + elem.setValueA(false); + elem.setValueB(true); + elem.setValueNull(null); + + StringBuilder builder = new StringBuilder(); + Assertions.assertDoesNotThrow(() -> Exml.generate(elem, ExmlTestIntrospectionBoolean.NODE_NAME, builder)); + String dataTest = builder.toString(); + Log.warning("data generated: " + builder.toString()); + Assertions.assertEquals("\n" + + " false\n" + + " true\n" + + "", dataTest); + + final TestNodeBooleanFunc root = Assertions.assertDoesNotThrow(() -> Exml.parseOne(dataTest, TestNodeBooleanFunc.class, ExmlTestIntrospectionBoolean.NODE_NAME)); + Assertions.assertEquals(false, root.isValueA()); + Assertions.assertEquals(true, root.isValueB()); + Assertions.assertEquals(null, root.isValueNull()); + } + + public class TestArrayNodeBooleanFunc { + private Boolean[] values; + + public Boolean[] getValues() { + return this.values; + } + + public void setValues(final Boolean[] values) { + this.values = values; + } + + } + @Test + public void testModelArrayNodeBooleanFunc() { + TestArrayNodeBooleanFunc elem = new TestArrayNodeBooleanFunc(); + elem.setValues(new Boolean[] {false, false, true, false, true}); + + StringBuilder builder = new StringBuilder(); + Assertions.assertDoesNotThrow(() -> Exml.generate(elem, ExmlTestIntrospectionBoolean.NODE_NAME, builder)); + String dataTest = builder.toString(); + Log.warning("data generated: " + builder.toString()); + Assertions.assertEquals("\n" + + " false\n" + + " false\n" + + " true\n" + + " false\n" + + " true\n" + + "", dataTest); + + final TestArrayNodeBooleanFunc root = Assertions.assertDoesNotThrow(() -> Exml.parseOne(dataTest, TestArrayNodeBooleanFunc.class, ExmlTestIntrospectionBoolean.NODE_NAME)); + Assertions.assertEquals(5, root.getValues().length); + Assertions.assertEquals(false, root.getValues()[0]); + Assertions.assertEquals(false, root.getValues()[1]); + Assertions.assertEquals(true, root.getValues()[2]); + Assertions.assertEquals(false, root.getValues()[3]); + Assertions.assertEquals(true, root.getValues()[4]); + } + + public class TestListNodeBooleanFunc { + private List values; + + public List getValues() { + return this.values; + } + + public void setValues(final List values) { + this.values = values; + } + } + @Test + public void testModelListNodeBooleanFunc() { + TestListNodeBooleanFunc elem = new TestListNodeBooleanFunc(); + elem.setValues(List.of(false, false, true, false, true)); + + StringBuilder builder = new StringBuilder(); + Assertions.assertDoesNotThrow(() -> Exml.generate(elem, ExmlTestIntrospectionBoolean.NODE_NAME, builder)); + String dataTest = builder.toString(); + Log.warning("data generated: " + builder.toString()); + Assertions.assertEquals("", dataTest); + + final TestListNodeBooleanFunc root = Assertions.assertDoesNotThrow(() -> Exml.parseOne(dataTest, TestListNodeBooleanFunc.class, ExmlTestIntrospectionBoolean.NODE_NAME)); + Assertions.assertEquals(5, root.getValues().size()); + Assertions.assertEquals(false, root.getValues().get(0)); + Assertions.assertEquals(false, root.getValues().get(1)); + Assertions.assertEquals(true, root.getValues().get(2)); + Assertions.assertEquals(false, root.getValues().get(3)); + Assertions.assertEquals(true, root.getValues().get(4)); + } + + + + + + + + + + + + + + + + + + + + + + + + + +