use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.
the class DOM4JSettingsNodeTest method testGetChildNodes.
/**
* This tests getChildNodes. We'll make sure it returns all the child nodes. First we'll make sure it returns
* nothing when no children are present. Then we'll add some nodes, and make sure it returns them all. Lastly, we'll
* add some more again to make sure they're included in the list.
*/
public void testGetChildNodes() {
//try it with no nodes
List<SettingsNode> children = rootNode.getChildNodes();
assertEquals(0, children.size());
//add some test nodes
SettingsNode childNode1 = rootNode.addChild(SAMPLE_NAME_1);
SettingsNode childNode2 = rootNode.addChild(SAMPLE_NAME_2);
SettingsNode childNode3 = rootNode.addChild(SAMPLE_NAME_3);
//this is a duplicate of childNode2
SettingsNode childNode4 = rootNode.addChild(SAMPLE_NAME_2);
//all should be returned
children = rootNode.getChildNodes();
TestUtility.assertListContents(children, childNode1, childNode2, childNode3, childNode4);
//add some more nodes
SettingsNode childNode5 = rootNode.addChild(SAMPLE_NAME_1);
SettingsNode childNode6 = rootNode.addChild(SAMPLE_NAME_2);
//again, all should be returned
children = rootNode.getChildNodes();
TestUtility.assertListContents(children, childNode1, childNode2, childNode3, childNode4, childNode5, childNode6);
}
use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.
the class DOM4JSettingsNodeTest method testGetValueOfChild.
/**
* This tests getValueOfChild. We're interested in that it gets the child value correctly, but also that it returns
* the default value if either the node or its value isn't present.
*/
public void testGetValueOfChild() {
//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, "myValue");
rootNode.setValueOfChild(SAMPLE_NAME_2, "otherValue");
rootNode.setValueOfChild(SAMPLE_NAME_3, "lastValue");
assertEquals("otherValue", rootNode.getValueOfChild(SAMPLE_NAME_2, "default2"));
assertEquals("myValue", rootNode.getValueOfChild(SAMPLE_NAME_1, "default1"));
assertEquals("lastValue", rootNode.getValueOfChild(SAMPLE_NAME_3, "default3"));
//now try it with one that doesn't exist. We should get the default value
assertEquals("default4", rootNode.getValueOfChild("nonexistent", "default4"));
//now add a single node but don't give it a value (which means its null)
SettingsNode lastNode = rootNode.addChild("valueless");
assertNull(lastNode.getValue());
//now try to get its value. We should get the default value
assertEquals("default5", rootNode.getValueOfChild("valueless", "default5"));
}
use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.
the class DOM4JSettingsNodeTest method testGetNodeAtPath.
/**
* This tests getNodeAtPath. We want to make sure it locates nodes via path from several locations.
*/
public void testGetNodeAtPath() {
//add some sample nodes. I'm indenting these to better show the structure I'm making
SettingsNode childNode1 = rootNode.addChild(SAMPLE_NAME_1);
SettingsNode grandChildNodeA1 = childNode1.addChild("sub_nodeA1");
SettingsNode greatGrandChildNodeA11 = grandChildNodeA1.addChild("sub_sub_nodeA11");
SettingsNode greatGrandChildNodeA12 = grandChildNodeA1.addChild("sub_sub_nodeA12");
SettingsNode grandChildNodeA2 = childNode1.addChild("sub_nodeA2");
SettingsNode greatGrandChildNodeA21 = grandChildNodeA2.addChild("sub_sub_nodeA21");
SettingsNode greatGrandChildNodeA22 = grandChildNodeA2.addChild("sub_sub_nodeA22");
SettingsNode childNode2 = rootNode.addChild(SAMPLE_NAME_2);
SettingsNode grandChildNodeB1 = childNode2.addChild("sub_nodeB1");
SettingsNode greatGrandChildNodeB11 = grandChildNodeB1.addChild("sub_sub_nodeB11");
SettingsNode greatGrandChildNodeB12 = grandChildNodeB1.addChild("sub_sub_nodeB12");
SettingsNode grandChildNodeB2 = childNode2.addChild("sub_nodeB2");
SettingsNode childNode3 = rootNode.addChild(SAMPLE_NAME_3);
//now start searching for some nodes
SettingsNode foundNode1 = rootNode.getNodeAtPath(SAMPLE_NAME_1, "sub_nodeA2", "sub_sub_nodeA22");
assertEquals(greatGrandChildNodeA22, foundNode1);
//try searching from something other than the root. It's still relative to the starting node.
SettingsNode foundNode2 = childNode2.getNodeAtPath("sub_nodeB1", "sub_sub_nodeB11");
assertEquals(greatGrandChildNodeB11, foundNode2);
//try searching for something that doesn't exist at the first level of the sought path.
SettingsNode foundNode3 = rootNode.getNodeAtPath("nonexistent", "sub_nodeA2", "sub_sub_nodeA22");
assertNull(foundNode3);
//try searching for something that doesn't exist at the second level of the sought path
SettingsNode foundNode4 = rootNode.getNodeAtPath(SAMPLE_NAME_3, "sub_nodeA2", "sub_sub_nodeA22");
assertNull(foundNode4);
//try searching for something that doesn't exist at the last level of the sought path
SettingsNode foundNode5 = rootNode.getNodeAtPath(SAMPLE_NAME_2, "sub_nodeB2", "sub_sub_nodeB22");
assertNull(foundNode5);
//try searching for a node using a single path
SettingsNode foundNode6 = rootNode.getNodeAtPath(SAMPLE_NAME_3);
assertEquals(childNode3, foundNode6);
}
use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.
the class PreferencesAssistant method restoreSettings.
/**
* This restores the position of a frame. We not only restore the size, but we'll maximize it if its was maximized when saved.
*/
public static void restoreSettings(SettingsNode settingsNode, JFrame frame, String id, Class windowClass) {
SettingsNode childNode = restoreSettings(settingsNode, (Window) frame, id, windowClass);
if (childNode == null) {
return;
}
int extendedState = childNode.getValueOfChildAsInt(EXTENDED_STATE, frame.getExtendedState());
if (extendedState != JFrame.ICONIFIED) {
frame.setExtendedState(extendedState);
}
}
use of org.gradle.gradleplugin.foundation.settings.SettingsNode in project gradle by gradle.
the class PreferencesAssistant method saveSettings.
public static SettingsNode saveSettings(SettingsNode settingsNode, Window window, String id, Class windowClass) {
Point p = window.getLocation();
Dimension size = window.getSize();
SettingsNode childNode = settingsNode.addChildIfNotPresent(getPrefix(windowClass, id));
childNode.setValueOfChildAsInt(WINDOW_X, p.x);
childNode.setValueOfChildAsInt(WINDOW_Y, p.y);
childNode.setValueOfChildAsInt(WINDOW_WIDTH, size.width);
childNode.setValueOfChildAsInt(WINDOW_HEIGHT, size.height);
return childNode;
}
Aggregations