Search in sources :

Example 1 with CustomBuilderMenuItemBuilder

use of com.thecoderscorner.menu.domain.CustomBuilderMenuItemBuilder in project tcMenu by davetcc.

the class UIRemoteAndFloatMenuItemTest method testAuthenticationItem.

@Test
void testAuthenticationItem(FxRobot robot) throws InterruptedException {
    MenuItem authItem = new CustomBuilderMenuItemBuilder().withId(1001).withName("Auth test").withEepromAddr(-1).withMenuType(CustomBuilderMenuItem.CustomMenuType.AUTHENTICATION).withFunctionName("onAuth").menuItem();
    menuTree.addMenuItem(MenuTree.ROOT, authItem);
    VariableNameGenerator vng = new VariableNameGenerator(menuTree, false);
    var uiAuthPanel = editorUI.createPanelForMenuItem(authItem, menuTree, vng, mockedConsumer);
    // open the sub menu item editor panel
    createMainPanel(uiAuthPanel);
    // firstly check that all the fields are populated properly
    performAllCommonChecks(authItem, false);
    TestUtils.writeIntoField(robot, "#nameField", "new name", 10);
    ArgumentCaptor<MenuItem> captor = ArgumentCaptor.forClass(MenuItem.class);
    verify(mockedConsumer, atLeastOnce()).accept(any(), captor.capture());
    var item = (CustomBuilderMenuItem) captor.getValue();
    assertEquals("new name", item.getName());
    assertEquals(CustomBuilderMenuItem.CustomMenuType.AUTHENTICATION, item.getMenuType());
    FxAssert.verifyThat("#onlineDocsHyperlink", LabeledMatchers.hasText("Online documentation for AuthenticationItem"));
}
Also used : CustomBuilderMenuItem(com.thecoderscorner.menu.domain.CustomBuilderMenuItem) FloatMenuItem(com.thecoderscorner.menu.domain.FloatMenuItem) CustomBuilderMenuItem(com.thecoderscorner.menu.domain.CustomBuilderMenuItem) UIMenuItem(com.thecoderscorner.menu.editorui.uimodel.UIMenuItem) MenuItem(com.thecoderscorner.menu.domain.MenuItem) VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator) CustomBuilderMenuItemBuilder(com.thecoderscorner.menu.domain.CustomBuilderMenuItemBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with CustomBuilderMenuItemBuilder

use of com.thecoderscorner.menu.domain.CustomBuilderMenuItemBuilder in project tcMenu by davetcc.

the class UIRemoteAndFloatMenuItemTest method testRemoteMenuItem.

@Test
void testRemoteMenuItem(FxRobot robot) throws InterruptedException {
    MenuItem remoteItem = new CustomBuilderMenuItemBuilder().withId(1001).withName("Remote Test").withEepromAddr(-1).withMenuType(CustomBuilderMenuItem.CustomMenuType.REMOTE_IOT_MONITOR).withFunctionName("onRemo").menuItem();
    menuTree.addMenuItem(MenuTree.ROOT, remoteItem);
    VariableNameGenerator vng = new VariableNameGenerator(menuTree, false);
    var uiRemotePanel = editorUI.createPanelForMenuItem(remoteItem, menuTree, vng, mockedConsumer);
    // open the sub menu item editor panel
    createMainPanel(uiRemotePanel);
    // firstly check that all the fields are populated properly
    performAllCommonChecks(remoteItem, false);
    TestUtils.writeIntoField(robot, "#nameField", "abc123", 11);
    ArgumentCaptor<MenuItem> captor = ArgumentCaptor.forClass(MenuItem.class);
    verify(mockedConsumer, atLeastOnce()).accept(any(), captor.capture());
    var item = (CustomBuilderMenuItem) captor.getValue();
    assertEquals("abc123", item.getName());
    assertEquals(CustomBuilderMenuItem.CustomMenuType.REMOTE_IOT_MONITOR, item.getMenuType());
    FxAssert.verifyThat("#onlineDocsHyperlink", LabeledMatchers.hasText("Online documentation for Remote/IoT Monitor"));
}
Also used : CustomBuilderMenuItem(com.thecoderscorner.menu.domain.CustomBuilderMenuItem) FloatMenuItem(com.thecoderscorner.menu.domain.FloatMenuItem) CustomBuilderMenuItem(com.thecoderscorner.menu.domain.CustomBuilderMenuItem) UIMenuItem(com.thecoderscorner.menu.editorui.uimodel.UIMenuItem) MenuItem(com.thecoderscorner.menu.domain.MenuItem) VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator) CustomBuilderMenuItemBuilder(com.thecoderscorner.menu.domain.CustomBuilderMenuItemBuilder) Test(org.junit.jupiter.api.Test)

Example 3 with CustomBuilderMenuItemBuilder

use of com.thecoderscorner.menu.domain.CustomBuilderMenuItemBuilder 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 4 with CustomBuilderMenuItemBuilder

use of com.thecoderscorner.menu.domain.CustomBuilderMenuItemBuilder in project tcMenu by davetcc.

the class UICustomMenuItem method getChangedMenuItem.

@Override
protected Optional<CustomBuilderMenuItem> getChangedMenuItem() {
    CustomBuilderMenuItemBuilder builder = CustomBuilderMenuItemBuilder.aCustomBuilderItemBuilder().withExisting(getMenuItem());
    List<FieldError> errors = new ArrayList<>();
    getChangedDefaults(builder, errors);
    return getItemOrReportError(builder.menuItem(), errors);
}
Also used : ArrayList(java.util.ArrayList) CustomBuilderMenuItemBuilder(com.thecoderscorner.menu.domain.CustomBuilderMenuItemBuilder)

Aggregations

CustomBuilderMenuItemBuilder (com.thecoderscorner.menu.domain.CustomBuilderMenuItemBuilder)4 Test (org.junit.jupiter.api.Test)3 CustomBuilderMenuItem (com.thecoderscorner.menu.domain.CustomBuilderMenuItem)2 FloatMenuItem (com.thecoderscorner.menu.domain.FloatMenuItem)2 MenuItem (com.thecoderscorner.menu.domain.MenuItem)2 VariableNameGenerator (com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator)2 UIMenuItem (com.thecoderscorner.menu.editorui.uimodel.UIMenuItem)2 MenuTree (com.thecoderscorner.menu.domain.state.MenuTree)1 CodeGeneratorOptionsBuilder (com.thecoderscorner.menu.editorui.generator.CodeGeneratorOptionsBuilder)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 IoExpanderDefinitionCollection (com.thecoderscorner.menu.editorui.generator.parameters.IoExpanderDefinitionCollection)1 ReadOnlyAuthenticatorDefinition (com.thecoderscorner.menu.editorui.generator.parameters.auth.ReadOnlyAuthenticatorDefinition)1 FlashRemoteId (com.thecoderscorner.menu.editorui.generator.parameters.auth.ReadOnlyAuthenticatorDefinition.FlashRemoteId)1 BspStm32EepromDefinition (com.thecoderscorner.menu.editorui.generator.parameters.eeprom.BspStm32EepromDefinition)1 DefaultXmlPluginLoaderTest (com.thecoderscorner.menu.editorui.generator.plugin.DefaultXmlPluginLoaderTest)1 LibraryStatus (com.thecoderscorner.menu.editorui.generator.util.LibraryStatus)1 ArrayList (java.util.ArrayList)1 BiConsumer (java.util.function.BiConsumer)1