use of com.thecoderscorner.menu.domain.state.MenuTree in project tcMenu by davetcc.
the class MenuIdChooserImplTest method testIdEepromGenerationOnEmptyTree.
@Test
public void testIdEepromGenerationOnEmptyTree() {
MenuTree menuTree = new MenuTree();
chooser = new MenuIdChooserImpl(menuTree);
assertEquals(1, chooser.nextHighestId());
assertEquals(2, chooser.nextHighestEeprom());
EnumMenuItem item = EnumMenuItemBuilder.anEnumMenuItemBuilder().withId(1).withEepromAddr(-1).withName("Test").withEnumList(Collections.emptyList()).menuItem();
menuTree.addMenuItem(MenuTree.ROOT, item);
assertEquals(2, chooser.nextHighestEeprom());
}
use of com.thecoderscorner.menu.domain.state.MenuTree in project tcMenu by davetcc.
the class MenuEditorTestCases method assertOnItemInTree.
/**
* Assert if the item was (or was not) found anywhere in the tree
* @param itemToAdd item to check
* @param shouldBeThere if it should be expected to be there or not.
*/
private void assertOnItemInTree(MenuItem itemToAdd, boolean shouldBeThere) {
MenuTree tree = project.getMenuTree();
Set<MenuItem> items = tree.getAllSubMenus().stream().flatMap(sub -> tree.getMenuItems(sub).stream()).collect(Collectors.toSet());
assertEquals(shouldBeThere, items.contains(itemToAdd));
}
use of com.thecoderscorner.menu.domain.state.MenuTree in project tcMenu by davetcc.
the class MenuEditorTestCases method checkTheTreeMatchesMenuTree.
/**
* Perform a deep check on the top two levels of the tree
* @param robot the fx robot
* @param selected the item that should be selected.
*/
private void checkTheTreeMatchesMenuTree(FxRobot robot, MenuItem selected) {
// First get the tree and make sure it has a ROOT menu item
TreeView<MenuItem> treeView = robot.lookup("#menuTree").query();
assertEquals(MenuTree.ROOT, treeView.getRoot().getValue());
assertEquals(selected, treeView.getSelectionModel().getSelectedItem().getValue());
// now we check the top level entries.
MenuTree menuTree = project.getMenuTree();
List<MenuItem> childItems = treeView.getRoot().getChildren().stream().map(TreeItem::getValue).collect(Collectors.toList());
assertEquals(menuTree.getMenuItems(MenuTree.ROOT), childItems);
// now check any elements in the first level down by comparing the tree view against
// the menuTree.
menuTree.getMenuItems(MenuTree.ROOT).stream().filter(MenuItem::hasChildren).forEach(subMenu -> {
Optional<TreeItem<MenuItem>> subTree = treeView.getRoot().getChildren().stream().filter(item -> item.getValue().getId() == subMenu.getId()).findFirst();
assertTrue(subTree.isPresent());
List<MenuItem> subChildTree = subTree.get().getChildren().stream().map(TreeItem::getValue).collect(Collectors.toList());
assertEquals(menuTree.getMenuItems(subMenu), subChildTree);
});
}
use of com.thecoderscorner.menu.domain.state.MenuTree in project tcMenu by davetcc.
the class CurrentEditorProjectTest method testOpening.
@Test
public void testOpening() throws IOException {
project.applyCommand(NEW, item1, MenuTree.ROOT);
Mockito.when(editorUI.questionYesNo(any(), any())).thenReturn(true);
Mockito.when(editorUI.findFileNameFromUser(true)).thenReturn(Optional.of("filename"));
MenuTree replacementMenu = TestUtils.buildSimpleTree();
Mockito.when(persistor.open("filename")).thenReturn(new MenuTreeWithCodeOptions(replacementMenu, new CodeGeneratorOptionsBuilder().codeOptions(), "my project description"));
project.openProject();
assertEquals(replacementMenu, project.getMenuTree());
}
use of com.thecoderscorner.menu.domain.state.MenuTree in project tcMenu by davetcc.
the class FileBasedProjectPersistorTest method testSaveThenLoad.
@Test
public void testSaveThenLoad() throws IOException {
Path projFile = dir.resolve("projectSave.emf");
FileBasedProjectPersistor persistor = new FileBasedProjectPersistor();
MenuTree tree = TestUtils.buildCompleteTree();
List<String> remoteUuids = List.of("uuid3");
List<CreatorProperty> propsList = Collections.singletonList(new CreatorProperty("name", "desc", "extra desc", "123", DISPLAY, CreatorProperty.PropType.USE_IN_DEFINE, CannedPropertyValidators.textValidator(), new AlwaysApplicable()));
var options = new CodeGeneratorOptionsBuilder().withPlatform(ARDUINO_AVR.getBoardId()).withDisplay("uuid1").withInput("uuid2").withTheme("uuid4").withRemotes(remoteUuids).withProperties(propsList).withAppName("app name").withNewId(APPLICATION_UUID).withEepromDefinition(new NoEepromDefinition()).withAuthenticationDefinition(new NoAuthenticatorDefinition()).withExpanderDefinitions(new IoExpanderDefinitionCollection()).codeOptions();
persistor.save(projFile.toString(), "", tree, options);
MenuTreeWithCodeOptions openResult = persistor.open(projFile.toString());
compareTrees(tree, openResult.getMenuTree());
assertEquals(ARDUINO_AVR.getBoardId(), openResult.getOptions().getEmbeddedPlatform());
assertEquals("uuid1", openResult.getOptions().getLastDisplayUuid());
assertEquals("uuid2", openResult.getOptions().getLastInputUuid());
assertEquals("uuid3", openResult.getOptions().getLastRemoteCapabilitiesUuids().get(0));
assertEquals("app name", openResult.getOptions().getApplicationName());
assertEquals("app name", openResult.getOptions().getApplicationName());
assertEquals(APPLICATION_UUID, openResult.getOptions().getApplicationUUID());
List<CreatorProperty> returnedProps = openResult.getOptions().getLastProperties();
assertEquals("123", returnedProps.get(0).getLatestValue());
assertEquals("name", returnedProps.get(0).getName());
assertEquals(DISPLAY, returnedProps.get(0).getSubsystem());
}
Aggregations