use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.
the class DOM4JSettingsNodeTest method testGetValueOfChildAsLong.
/**
* This tests getValueOfChildAsLong. We're interested in that it gets the child value correctly, but also that it
* returns the default value if either the node, its value isn't present, or the valid isn't illegal as an long.
*/
public void testGetValueOfChildAsLong() {
//make sure we have no children first
List<SettingsNode> children = rootNode.getChildNodes();
assertEquals(0, children.size());
//set the value of a child
rootNode.setValueOfChild(SAMPLE_NAME_1, "1000000000");
rootNode.setValueOfChild(SAMPLE_NAME_2, "8400000000");
rootNode.setValueOfChild(SAMPLE_NAME_3, "0983000000");
assertEquals(8400000000l, rootNode.getValueOfChildAsLong(SAMPLE_NAME_2, 5500000000l));
assertEquals(1000000000l, rootNode.getValueOfChildAsLong(SAMPLE_NAME_1, 6600000000l));
assertEquals(983000000l, rootNode.getValueOfChildAsLong(SAMPLE_NAME_3, 7700000000l));
//now try it with one that doesn't exist. We should get the default value
assertEquals(4400000000l, rootNode.getValueOfChildAsLong("nonexistent", 4400000000l));
//now add a single node but don't give it a value (which means its null)
SettingsNode valuelessNode = rootNode.addChild("valueless");
assertNull(valuelessNode.getValue());
//now try to get its value. We should get the default value
assertEquals(1700000000l, rootNode.getValueOfChildAsLong("valueless", 1700000000l));
//now add a single node that has an illegal value
SettingsNode illegalNode = rootNode.addChild("illegal");
illegalNode.setValue("abcdefg");
//now try to get its value. We should get the default value
assertEquals(33300000000l, rootNode.getValueOfChildAsLong("illegal", 33300000000l));
}
use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.
the class DOM4JSettingsNodeTest method testSetValueOfChildAsBoolean.
/**
* This tests setValueOfChildAsBoolean. We're going to make sure the value is set as well as that repeated calls to
* this don't add child nodes.
*/
public void testSetValueOfChildAsBoolean() {
//make sure we have no children first
List<SettingsNode> children = rootNode.getChildNodes();
assertEquals(0, children.size());
//set the value of a child
rootNode.setValueOfChildAsBoolean(SAMPLE_NAME_1, true);
//verify it was set properly
SettingsNode childNode1 = rootNode.getChildNode(SAMPLE_NAME_1);
assertNotNull(childNode1);
assertEquals("true", childNode1.getValue());
//make sure there's only 1 child.
children = rootNode.getChildNodes();
assertEquals(1, children.size());
//set the value again. This should set the value and NOT add an additional node
rootNode.setValueOfChildAsBoolean(SAMPLE_NAME_1, false);
childNode1 = rootNode.getChildNode(SAMPLE_NAME_1);
assertNotNull(childNode1);
assertEquals("false", childNode1.getValue());
//make sure there's still only 1 child.
children = rootNode.getChildNodes();
assertEquals(1, children.size());
//set the value again to the same value. Again, this should set the value and NOT add an additional node
rootNode.setValueOfChildAsBoolean(SAMPLE_NAME_1, false);
childNode1 = rootNode.getChildNode(SAMPLE_NAME_1);
assertNotNull(childNode1);
assertEquals("false", childNode1.getValue());
//make sure there's still only 1 child.
children = rootNode.getChildNodes();
assertEquals(1, children.size());
}
use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.
the class DOM4JSettingsNodeTest method testAddChild.
/**
* This tests that addChild actually works. We'll verify a child isn't present, then add one.
*/
public void testAddChild() {
//make sure we have no child named 'fred' at the DOM4J level
assertNull(rootElement.element(SAMPLE_NAME_1));
//as such, we shouldn't have one at the DOM4JSettingsNode level either.
assertNull(rootNode.getChildNode(SAMPLE_NAME_1));
SettingsNode settingsNode = rootNode.addChild(SAMPLE_NAME_1);
assertNotNull(settingsNode);
//and now it should be present under both.
assertNotNull(Dom4JUtility.getChild(rootElement, DOM4JSettingsNode.TAG_NAME, DOM4JSettingsNode.NAME_ATTRIBUTE, SAMPLE_NAME_1));
assertNotNull(rootNode.getChildNode(SAMPLE_NAME_1));
}
use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.
the class DOM4JSettingsNodeTest method testAddingChildrenIfNotPresent.
/**
* This tests that if you call addChildIfNotPresent, it actually adds a child that is not present. We'll verify a
* child isn't present, then add one.
*/
public void testAddingChildrenIfNotPresent() {
//make sure we have no child named 'fred' at the DOM4J level
assertNull(rootElement.element(SAMPLE_NAME_1));
//as such, we shouldn't have one at the DOM4JSettingsNode level either.
assertNull(rootNode.getChildNode(SAMPLE_NAME_1));
SettingsNode settingsNode = rootNode.addChildIfNotPresent(SAMPLE_NAME_1);
assertNotNull(settingsNode);
//and now it should be present under both.
assertNotNull(Dom4JUtility.getChild(rootElement, DOM4JSettingsNode.TAG_NAME, DOM4JSettingsNode.NAME_ATTRIBUTE, SAMPLE_NAME_1));
assertNotNull(rootNode.getChildNode(SAMPLE_NAME_1));
}
use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.
the class DOM4JSettingsNodeTest method testGetValueOfChildAsInt.
/**
* This tests getValueOfChildAsInt. We're interested in that it gets the child value correctly, but also that it
* returns the default value if either the node, its value isn't present, or the valid isn't illegal as an int.
*/
public void testGetValueOfChildAsInt() {
//make sure we have no children first
List<SettingsNode> children = rootNode.getChildNodes();
assertEquals(0, children.size());
//set the value of a child
rootNode.setValueOfChild(SAMPLE_NAME_1, "1");
rootNode.setValueOfChild(SAMPLE_NAME_2, "84");
rootNode.setValueOfChild(SAMPLE_NAME_3, "0983");
assertEquals(84, rootNode.getValueOfChildAsInt(SAMPLE_NAME_2, 55));
assertEquals(1, rootNode.getValueOfChildAsInt(SAMPLE_NAME_1, 66));
assertEquals(983, rootNode.getValueOfChildAsInt(SAMPLE_NAME_3, 77));
//now try it with one that doesn't exist. We should get the default value
assertEquals(44, rootNode.getValueOfChildAsInt("nonexistent", 44));
//now add a single node but don't give it a value (which means its null)
SettingsNode valuelessNode = rootNode.addChild("valueless");
assertNull(valuelessNode.getValue());
//now try to get its value. We should get the default value
assertEquals(17, rootNode.getValueOfChildAsInt("valueless", 17));
//now add a single node that has an illegal value
SettingsNode illegalNode = rootNode.addChild("illegal");
illegalNode.setValue("abcdefg");
//now try to get its value. We should get the default value
assertEquals(333, rootNode.getValueOfChildAsInt("illegal", 333));
}
Aggregations