Search in sources :

Example 1 with LibraryStatus

use of com.thecoderscorner.menu.editorui.generator.util.LibraryStatus in project tcMenu by davetcc.

the class MenuEditorTestCases method testAreaInformationPanelNeedingUpdate.

@Test
void testAreaInformationPanelNeedingUpdate(FxRobot robot) throws Exception {
    when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(true, true, true, false));
    when(installer.getVersionOfLibrary("module.name", AVAILABLE_PLUGIN)).thenReturn(new VersionInfo("1.0.2"));
    openTheCompleteMenuTree(robot);
    SubMenuItem subItem = project.getMenuTree().getSubMenuById(100).orElseThrow();
    TreeView<MenuItem> treeView = robot.lookup("#menuTree").query();
    assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), subItem));
    assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), MenuTree.ROOT));
    Thread.sleep(500);
    verifyThat("#tcMenuStatusArea", LabeledMatchers.hasText("Libraries need updating, check in General Settings"));
}
Also used : LibraryStatus(com.thecoderscorner.menu.editorui.generator.util.LibraryStatus) VersionInfo(com.thecoderscorner.menu.persist.VersionInfo) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) MenuItem(com.thecoderscorner.menu.domain.MenuItem) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) Test(org.junit.jupiter.api.Test)

Example 2 with LibraryStatus

use of com.thecoderscorner.menu.editorui.generator.util.LibraryStatus in project tcMenu by davetcc.

the class MbedGeneratorTest method testMbedConversion.

@SuppressWarnings("unchecked")
@Test
public void testMbedConversion() throws IOException {
    ArduinoSketchFileAdjuster adjuster = Mockito.mock(ArduinoSketchFileAdjuster.class);
    MenuTree tree = buildTreeFromJson(LARGE_MENU_STRUCTURE);
    tree.addMenuItem(MenuTree.ROOT, new CustomBuilderMenuItemBuilder().withId(10001).withName("Authenticator").withMenuType(AUTHENTICATION).withEepromAddr(-1).menuItem());
    tree.addMenuItem(MenuTree.ROOT, new CustomBuilderMenuItemBuilder().withId(10002).withName("IoT Monitor").withMenuType(REMOTE_IOT_MONITOR).withEepromAddr(-1).menuItem());
    ArduinoLibraryInstaller installer = Mockito.mock(ArduinoLibraryInstaller.class);
    when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(true, true, true, true));
    when(installer.getVersionOfLibrary("core-remote", InstallationType.CURRENT_PLUGIN)).thenReturn(VersionInfo.fromString("2.2.1"));
    var flashRemotes = List.of(new FlashRemoteId("name1", "first-uuid"), new FlashRemoteId("name2", "second-uuid"));
    var options = new CodeGeneratorOptionsBuilder().withPlatform(MBED_RTOS.getBoardId()).withAppName("tester").withNewId(SERVER_UUID).withEepromDefinition(new BspStm32EepromDefinition(50)).withAuthenticationDefinition(new ReadOnlyAuthenticatorDefinition("1234", flashRemotes)).withExpanderDefinitions(new IoExpanderDefinitionCollection()).withRecursiveNaming(true).withSaveToSrc(true).codeOptions();
    ArduinoGenerator generator = new ArduinoGenerator(adjuster, installer, MBED_RTOS);
    var firstPlugin = pluginConfig.getPlugins().get(0);
    firstPlugin.getProperties().stream().filter(p -> p.getName().equals("SWITCH_IODEVICE")).findFirst().ifPresent(p -> p.setLatestValue("io23017"));
    assertTrue(generator.startConversion(projectDir, pluginConfig.getPlugins(), tree, List.of(), options));
    var sourceDir = projectDir.resolve("src");
    var cppGenerated = new String(Files.readAllBytes(sourceDir.resolve(projectDir.getFileName() + "_menu.cpp")));
    var hGenerated = new String(Files.readAllBytes(sourceDir.resolve(projectDir.getFileName() + "_menu.h")));
    var pluginGeneratedH = new String(Files.readAllBytes(sourceDir.resolve("source.h")));
    var pluginGeneratedCPP = new String(Files.readAllBytes(sourceDir.resolve("source.cpp")));
    var pluginGeneratedTransport = new String(Files.readAllBytes(sourceDir.resolve("MySpecialTransport.h")));
    var cppTemplate = new String(Objects.requireNonNull(getClass().getResourceAsStream("/generator/templateMbed.cpp")).readAllBytes());
    var hTemplate = new String(Objects.requireNonNull(getClass().getResourceAsStream("/generator/templateMbed.h")).readAllBytes());
    cppGenerated = cppGenerated.replaceAll("#include \"tcmenu[^\"]*\"", "replacedInclude");
    cppTemplate = cppTemplate.replaceAll("#include \"tcmenu[^\"]*\"", "replacedInclude");
    // these files should line up. IF they do not because of the change in the ArduinoGenerator,
    // then make sure the change is good before adjusting the templates.
    assertEqualsIgnoringCRLF(cppTemplate, cppGenerated);
    assertEqualsIgnoringCRLF(hTemplate, hGenerated);
    assertEqualsIgnoringCRLF("CPP_FILE_CONTENT 10 otherKey", pluginGeneratedCPP);
    assertEqualsIgnoringCRLF("H_FILE_CONTENT 10 otherKey", pluginGeneratedH);
    assertEqualsIgnoringCRLF("My Transport file", pluginGeneratedTransport);
    Mockito.verify(adjuster).makeAdjustments(any(BiConsumer.class), eq(projectDir.resolve(sourceDir.resolve("project_main.cpp")).toString()), eq(projectDir.getFileName().toString()), anyCollection());
}
Also used : MenuTree(com.thecoderscorner.menu.domain.state.MenuTree) ArduinoGenerator(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoGenerator) CodeGeneratorOptionsBuilder(com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder) LibraryStatus(com.thecoderscorner.menu.editorui.generator.util.LibraryStatus) FlashRemoteId(com.thecoderscorner.menu.editorui.generator.parameters.auth.ReadOnlyAuthenticatorDefinition.FlashRemoteId) ArduinoSketchFileAdjuster(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoSketchFileAdjuster) BspStm32EepromDefinition(com.thecoderscorner.menu.editorui.generator.parameters.eeprom.BspStm32EepromDefinition) ReadOnlyAuthenticatorDefinition(com.thecoderscorner.menu.editorui.generator.parameters.auth.ReadOnlyAuthenticatorDefinition) ArduinoLibraryInstaller(com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller) IoExpanderDefinitionCollection(com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection) CustomBuilderMenuItemBuilder(com.thecoderscorner.menu.domain.CustomBuilderMenuItemBuilder) BiConsumer(java.util.function.BiConsumer) DefaultXmlPluginLoaderTest(com.thecoderscorner.menu.editorui.generator.plugin.DefaultXmlPluginLoaderTest) Test(org.junit.jupiter.api.Test)

Example 3 with LibraryStatus

use of com.thecoderscorner.menu.editorui.generator.util.LibraryStatus in project tcMenu by davetcc.

the class MenuEditorTestCases method testEditingTheNameAndDescriptionOnRootPanel.

@Test
void testEditingTheNameAndDescriptionOnRootPanel(FxRobot robot) throws Exception {
    when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(true, true, true, true));
    openTheCompleteMenuTree(robot);
    TreeView<MenuItem> treeView = robot.lookup("#menuTree").query();
    assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), MenuTree.ROOT));
    var opts = project.getGeneratorOptions();
    testMainCheckboxState(robot, "#recursiveNamingCheck", () -> project.getGeneratorOptions().isNamingRecursive());
    testMainCheckboxState(robot, "#useCppMainCheck", () -> project.getGeneratorOptions().isUseCppMain());
    testMainCheckboxState(robot, "#saveToSrcCheck", () -> project.getGeneratorOptions().isSaveToSrc());
    FxAssert.verifyThat("#filenameField", LabeledMatchers.hasText(project.getFileName()));
    FxAssert.verifyThat("#appUuidLabel", LabeledMatchers.hasText(opts.getApplicationUUID().toString()));
    FxAssert.verifyThat("#appNameTextField", TextInputControlMatchers.hasText(opts.getApplicationName()));
    FxAssert.verifyThat("#appDescTextArea", TextInputControlMatchers.hasText(project.getDescription()));
    TestUtils.writeIntoField(robot, "#appNameTextField", "newProjName", 10);
    assertTrue(project.isDirty());
    assertEquals("newProjName", project.getGeneratorOptions().getApplicationName());
    TestUtils.writeIntoField(robot, "#appDescTextArea", "my new desc", 12);
    assertTrue(project.isDirty());
    assertEquals("my new desc", project.getDescription());
    var oldUuid = project.getGeneratorOptions().getApplicationUUID();
    when(editorProjectUI.questionYesNo(eq("Really change ID"), any())).thenReturn(true);
    robot.clickOn("#changeIdBtn");
    assertNotEquals(oldUuid, project.getGeneratorOptions().getApplicationUUID());
}
Also used : LibraryStatus(com.thecoderscorner.menu.editorui.generator.util.LibraryStatus) MenuItem(com.thecoderscorner.menu.domain.MenuItem) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) Test(org.junit.jupiter.api.Test)

Example 4 with LibraryStatus

use of com.thecoderscorner.menu.editorui.generator.util.LibraryStatus in project tcMenu by davetcc.

the class MenuEditorTestCases method setUpInstallerLibVersions.

private void setUpInstallerLibVersions() throws IOException {
    // and we are always up to date library wise in unit test land
    when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(true, true, true, true));
    when(installer.findLibraryInstall("tcMenu")).thenReturn(dirHelper.getTcMenuPath());
    when(installer.getArduinoDirectory()).thenReturn(dirHelper.getSketchesDir());
    when(installer.getVersionOfLibrary("java-app", AVAILABLE_APP)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("java-app", CURRENT_APP)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("module.name", AVAILABLE_PLUGIN)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("module.name", CURRENT_PLUGIN)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("tcMenu", AVAILABLE_LIB)).thenReturn(new VersionInfo("1.0.1"));
    when(installer.getVersionOfLibrary("tcMenu", CURRENT_LIB)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("IoAbstraction", AVAILABLE_LIB)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("IoAbstraction", CURRENT_LIB)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("LiquidCrystalIO", AVAILABLE_LIB)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("LiquidCrystalIO", CURRENT_LIB)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("TaskManagerIO", AVAILABLE_LIB)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.getVersionOfLibrary("TaskManagerIO", CURRENT_LIB)).thenReturn(new VersionInfo("1.0.0"));
    when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(false, true, true, true));
}
Also used : LibraryStatus(com.thecoderscorner.menu.editorui.generator.util.LibraryStatus) VersionInfo(com.thecoderscorner.menu.persist.VersionInfo)

Example 5 with LibraryStatus

use of com.thecoderscorner.menu.editorui.generator.util.LibraryStatus in project tcMenu by davetcc.

the class MenuEditorTestCases method testTheRootAreaInformationPanel.

@Test
void testTheRootAreaInformationPanel(FxRobot robot) throws Exception {
    when(installer.statusOfAllLibraries()).thenReturn(new LibraryStatus(true, true, true, true));
    openTheCompleteMenuTree(robot);
    SubMenuItem subItem = project.getMenuTree().getSubMenuById(100).orElseThrow();
    TreeView<MenuItem> treeView = robot.lookup("#menuTree").query();
    assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), subItem));
    assertTrue(recursiveSelectTreeItem(treeView, treeView.getRoot(), MenuTree.ROOT));
    verifyThat("#libdocsurl", (Hyperlink hl) -> hl.getText().equals("Browse docs and watch starter videos (F1 at any time)"));
    verifyThat("#githuburl", (Hyperlink hl) -> hl.getText().equals("Please give us a star on github if you like this tool"));
    robot.clickOn("#libdocsurl");
    verify(editorProjectUI).browseToURL(AppInformationPanel.LIBRARY_DOCS_URL);
    robot.clickOn("#githuburl");
    verify(editorProjectUI).browseToURL(AppInformationPanel.GITHUB_PROJECT_URL);
    Thread.sleep(500);
    verifyThat("#tcMenuStatusArea", LabeledMatchers.hasText("Embedded Arduino libraries all up-to-date"));
    checkTheTreeMatchesMenuTree(robot, MenuTree.ROOT);
}
Also used : LibraryStatus(com.thecoderscorner.menu.editorui.generator.util.LibraryStatus) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) MenuItem(com.thecoderscorner.menu.domain.MenuItem) UISubMenuItem(com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem) Test(org.junit.jupiter.api.Test)

Aggregations

LibraryStatus (com.thecoderscorner.menu.editorui.generator.util.LibraryStatus)7 Test (org.junit.jupiter.api.Test)5 MenuItem (com.thecoderscorner.menu.domain.MenuItem)3 UISubMenuItem (com.thecoderscorner.menu.editorui.uimodel.UISubMenuItem)3 VersionInfo (com.thecoderscorner.menu.persist.VersionInfo)3 MenuTree (com.thecoderscorner.menu.domain.state.MenuTree)2 CodeGeneratorOptionsBuilder (com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder)2 IoExpanderDefinitionCollection (com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection)2 BiConsumer (java.util.function.BiConsumer)2 CustomBuilderMenuItemBuilder (com.thecoderscorner.menu.domain.CustomBuilderMenuItemBuilder)1 ArduinoGenerator (com.thecoderscorner.menu.editorui.generator.arduino.ArduinoGenerator)1 ArduinoLibraryInstaller (com.thecoderscorner.menu.editorui.generator.arduino.ArduinoLibraryInstaller)1 ArduinoSketchFileAdjuster (com.thecoderscorner.menu.editorui.generator.arduino.ArduinoSketchFileAdjuster)1 VariableNameGenerator (com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator)1 EepromAuthenticatorDefinition (com.thecoderscorner.menu.editorui.generator.parameters.auth.EepromAuthenticatorDefinition)1 ReadOnlyAuthenticatorDefinition (com.thecoderscorner.menu.editorui.generator.parameters.auth.ReadOnlyAuthenticatorDefinition)1 FlashRemoteId (com.thecoderscorner.menu.editorui.generator.parameters.auth.ReadOnlyAuthenticatorDefinition.FlashRemoteId)1 AVREepromDefinition (com.thecoderscorner.menu.editorui.generator.parameters.eeprom.AVREepromDefinition)1 BspStm32EepromDefinition (com.thecoderscorner.menu.editorui.generator.parameters.eeprom.BspStm32EepromDefinition)1 CustomDeviceExpander (com.thecoderscorner.menu.editorui.generator.parameters.expander.CustomDeviceExpander)1