Search in sources :

Example 1 with MenuTree

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());
}
Also used : MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) EnumMenuItem(com.thecoderscorner.menu.domain.EnumMenuItem) Test(org.junit.jupiter.api.Test)

Example 2 with MenuTree

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));
}
Also used : MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) javafx.scene.control(javafx.scene.control) LibraryStatus(com.thecoderscorner.menu.editorui.generator.util.LibraryStatus) PersistedMenu(com.thecoderscorner.menu.persist.PersistedMenu) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LibraryVersionDetector(com.thecoderscorner.menu.editorui.generator.LibraryVersionDetector) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) LabeledMatchers(org.testfx.matcher.control.LabeledMatchers) ConfigurationStorage(com.thecoderscorner.menu.editorui.storage.ConfigurationStorage) Start(org.testfx.framework.junit5.Start) MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) Pane(javafx.scene.layout.Pane) CodePluginConfig(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginConfig) MenuItem(com.thecoderscorner.menu.domain.MenuItem) FxAssert.verifyThat(org.testfx.api.FxAssert.verifyThat) VersionInfo(com.thecoderscorner.menu.persist.VersionInfo) Collectors(java.util.stream.Collectors) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) Platform(javafx.application.Platform) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) TCMENU_DIR(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoDirectoryStructureHelper.DirectoryPath.TCMENU_DIR) VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator) InstallationType(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller.InstallationType) Scene(javafx.scene.Scene) java.util(java.util) TextInputControlMatchers(org.testfx.matcher.control.TextInputControlMatchers) com.thecoderscorner.menu.editorui.project(com.thecoderscorner.menu.editorui.project) Supplier(java.util.function.Supplier) ArduinoLibraryInstaller(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller) TestUtils(com.thecoderscorner.menu.editorui.util.TestUtils) ArgumentCaptor(org.mockito.ArgumentCaptor) ReleaseType(com.thecoderscorner.menu.editorui.generator.OnlineLibraryVersionDetector.ReleaseType) FXMLLoader(javafx.fxml.FXMLLoader) BiConsumer(java.util.function.BiConsumer) FxRobot(org.testfx.api.FxRobot) TestUtils.pushCtrlAndKey(com.thecoderscorner.menu.editorui.util.TestUtils.pushCtrlAndKey) SKETCHES_DIR(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoDirectoryStructureHelper.DirectoryPath.SKETCHES_DIR) ApplicationExtension(org.testfx.framework.junit5.ApplicationExtension) KeyCode(javafx.scene.input.KeyCode) com.thecoderscorner.menu.domain(com.thecoderscorner.menu.domain) MenuEditorController(com.thecoderscorner.menu.editorui.controller.MenuEditorController) CurrentProjectEditorUI(com.thecoderscorner.menu.editorui.uimodel.CurrentProjectEditorUI) IOException(java.io.IOException) FxAssert(org.testfx.api.FxAssert) AppInformationPanel(com.thecoderscorner.menu.editorui.dialog.AppInformationPanel) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) ArduinoDirectoryStructureHelper(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoDirectoryStructureHelper) Stage(javafx.stage.Stage) Assertions(org.junit.jupiter.api.Assertions) CodePluginManager(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginManager) MenuItem(com.thecoderscorner.menu.domain.MenuItem) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem)

Example 3 with MenuTree

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);
    });
}
Also used : MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) javafx.scene.control(javafx.scene.control) LibraryStatus(com.thecoderscorner.menu.editorui.generator.util.LibraryStatus) PersistedMenu(com.thecoderscorner.menu.persist.PersistedMenu) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LibraryVersionDetector(com.thecoderscorner.menu.editorui.generator.LibraryVersionDetector) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) LabeledMatchers(org.testfx.matcher.control.LabeledMatchers) ConfigurationStorage(com.thecoderscorner.menu.editorui.storage.ConfigurationStorage) Start(org.testfx.framework.junit5.Start) MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) Pane(javafx.scene.layout.Pane) CodePluginConfig(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginConfig) MenuItem(com.thecoderscorner.menu.domain.MenuItem) FxAssert.verifyThat(org.testfx.api.FxAssert.verifyThat) VersionInfo(com.thecoderscorner.menu.persist.VersionInfo) Collectors(java.util.stream.Collectors) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) Platform(javafx.application.Platform) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) TCMENU_DIR(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoDirectoryStructureHelper.DirectoryPath.TCMENU_DIR) VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator) InstallationType(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller.InstallationType) Scene(javafx.scene.Scene) java.util(java.util) TextInputControlMatchers(org.testfx.matcher.control.TextInputControlMatchers) com.thecoderscorner.menu.editorui.project(com.thecoderscorner.menu.editorui.project) Supplier(java.util.function.Supplier) ArduinoLibraryInstaller(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller) TestUtils(com.thecoderscorner.menu.editorui.util.TestUtils) ArgumentCaptor(org.mockito.ArgumentCaptor) ReleaseType(com.thecoderscorner.menu.editorui.generator.OnlineLibraryVersionDetector.ReleaseType) FXMLLoader(javafx.fxml.FXMLLoader) BiConsumer(java.util.function.BiConsumer) FxRobot(org.testfx.api.FxRobot) TestUtils.pushCtrlAndKey(com.thecoderscorner.menu.editorui.util.TestUtils.pushCtrlAndKey) SKETCHES_DIR(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoDirectoryStructureHelper.DirectoryPath.SKETCHES_DIR) ApplicationExtension(org.testfx.framework.junit5.ApplicationExtension) KeyCode(javafx.scene.input.KeyCode) com.thecoderscorner.menu.domain(com.thecoderscorner.menu.domain) MenuEditorController(com.thecoderscorner.menu.editorui.controller.MenuEditorController) CurrentProjectEditorUI(com.thecoderscorner.menu.editorui.uimodel.CurrentProjectEditorUI) IOException(java.io.IOException) FxAssert(org.testfx.api.FxAssert) AppInformationPanel(com.thecoderscorner.menu.editorui.dialog.AppInformationPanel) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) ArduinoDirectoryStructureHelper(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoDirectoryStructureHelper) Stage(javafx.stage.Stage) Assertions(org.junit.jupiter.api.Assertions) CodePluginManager(com.thecoderscorner.menu.editorui.generator.plugin.CodePluginManager) MenuItem(com.thecoderscorner.menu.domain.MenuItem) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem)

Example 4 with MenuTree

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());
}
Also used : MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) CodeGeneratorOptionsBuilder(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with MenuTree

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());
}
Also used : Path(java.nio.file.Path) MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) NoEepromDefinition(com.thecoderscorner.menu.editorui.generator.parameters.eeprom.NoEepromDefinition) CreatorProperty(com.thecoderscorner.menu.editorui.generator.core.CreatorProperty) CodeGeneratorOptionsBuilder(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder) AlwaysApplicable(com.thecoderscorner.menu.editorui.generator.applicability.AlwaysApplicable) NoAuthenticatorDefinition(com.thecoderscorner.menu.editorui.generator.parameters.auth.NoAuthenticatorDefinition) IoExpanderDefinitionCollection(com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection) Test(org.junit.jupiter.api.Test)

Aggregations

MenuTree (com.thecoderscorner.menu.domain.state.MenuTree)18 Test (org.junit.jupiter.api.Test)8 CodeGeneratorOptionsBuilder (com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder)4 LibraryStatus (com.thecoderscorner.menu.editorui.generator.util.LibraryStatus)4 BiConsumer (java.util.function.BiConsumer)4 MenuItem (com.thecoderscorner.menu.domain.MenuItem)3 ArduinoLibraryInstaller (com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller)3 VariableNameGenerator (com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator)3 IoExpanderDefinitionCollection (com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 com.thecoderscorner.menu.domain (com.thecoderscorner.menu.domain)2 MenuEditorController (com.thecoderscorner.menu.editorui.controller.MenuEditorController)2 AppInformationPanel (com.thecoderscorner.menu.editorui.dialog.AppInformationPanel)2 LibraryVersionDetector (com.thecoderscorner.menu.editorui.generator.LibraryVersionDetector)2 ReleaseType (com.thecoderscorner.menu.editorui.generator.OnlineLibraryVersionDetector.ReleaseType)2 ArduinoDirectoryStructureHelper (com.thecoderscorner.menu.editorui.generator.arduino.ArduinoDirectoryStructureHelper)2 SKETCHES_DIR (com.thecoderscorner.menu.editorui.generator.arduino.ArduinoDirectoryStructureHelper.DirectoryPath.SKETCHES_DIR)2 TCMENU_DIR (com.thecoderscorner.menu.editorui.generator.arduino.ArduinoDirectoryStructureHelper.DirectoryPath.TCMENU_DIR)2 InstallationType (com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller.InstallationType)2 CodePluginConfig (com.thecoderscorner.menu.editorui.generator.plugin.CodePluginConfig)2