Search in sources :

Example 1 with AnalogMenuItem

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

the class UIAnalogMenuItemTest method testEnteringValidValuesIntoAnalogEditor.

@Test
void testEnteringValidValuesIntoAnalogEditor(FxRobot robot) throws InterruptedException {
    MenuItem analogItem = menuTree.getMenuById(1).orElseThrow();
    VariableNameGenerator vng = new VariableNameGenerator(menuTree, false);
    var uiSubItem = editorUI.createPanelForMenuItem(analogItem, menuTree, vng, mockedConsumer);
    // open the sub menu item editor panel
    createMainPanel(uiSubItem);
    // firstly check that all the fields are populated properly
    performAllCommonChecks(analogItem, true);
    robot.clickOn("#offsetField");
    robot.eraseText(5);
    robot.write("-180");
    robot.clickOn("#unitNameField");
    robot.eraseText(5);
    robot.write("dB");
    robot.clickOn("#divisorField");
    robot.eraseText(5);
    robot.write("2");
    robot.clickOn("#maxValueField");
    robot.eraseText(5);
    robot.write("255");
    verifyThatThereAreNoErrorsReported();
    ArgumentCaptor<MenuItem> captor = ArgumentCaptor.forClass(MenuItem.class);
    verify(mockedConsumer, atLeastOnce()).accept(any(), captor.capture());
    AnalogMenuItem item = (AnalogMenuItem) captor.getValue();
    assertEquals(-180, item.getOffset());
    assertEquals(255, item.getMaxValue());
    assertEquals(2, item.getDivisor());
    assertEquals("dB", item.getUnitName());
}
Also used : AnalogMenuItem(com.thecoderscorner.menu.domain.AnalogMenuItem) MenuItem(com.thecoderscorner.menu.domain.MenuItem) AnalogMenuItem(com.thecoderscorner.menu.domain.AnalogMenuItem) VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator) Test(org.junit.jupiter.api.Test)

Example 2 with AnalogMenuItem

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

the class SimpleWebSocketExample method main.

public static void main(String[] args) throws Exception {
    ConsoleHandler handler = new ConsoleHandler();
    handler.setFormatter(new SimpleFormatter());
    handler.setLevel(Level.FINEST);
    Logger.getLogger("").addHandler(handler);
    Logger.getLogger("").setLevel(Level.FINEST);
    var tree = DomainFixtures.fullEspAmplifierTestTree();
    var executor = Executors.newSingleThreadScheduledExecutor();
    var clock = Clock.systemDefaultZone();
    MenuCommandProtocol tagValProtocol = new TagValMenuCommandProtocol();
    var menuManager = new MenuManagerServer(executor, tree, "WS Test", UUID.randomUUID(), new PropertiesAuthenticator("./auth.properties", new NoDialogFacilities()), clock);
    menuManager.addConnectionManager(new WebSocketServerConnectionManager(tagValProtocol, 3333, clock));
    menuManager.addConnectionManager(new SocketServerConnectionManager(tagValProtocol, executor, 3334, clock));
    menuManager.start();
    var menuList = menuManager.getManagedMenu().getMenuById(21).orElseThrow();
    menuManager.updateMenuItem(menuList, List.of("salad", "pasta", "pizza"));
    if (Boolean.getBoolean("sendSimulatedUpdates")) {
        executor.scheduleAtFixedRate(() -> {
            menuManager.updateMenuItem(menuList, randomListData());
        }, 5000, 5000, TimeUnit.MILLISECONDS);
        executor.scheduleAtFixedRate(() -> {
            if (menuManager.isAnyRemoteConnection())
                return;
            var menuVolume = (AnalogMenuItem) tree.getMenuById(1).orElseThrow();
            var menuLeftVU = (AnalogMenuItem) tree.getMenuById(15).orElseThrow();
            var menuRightVU = (AnalogMenuItem) tree.getMenuById(16).orElseThrow();
            int amt = (int) (Math.random() * 2000);
            if (Math.random() > 0.5) {
                menuManager.updateMenuItem(menuLeftVU, MenuItemHelper.getValueFor(menuLeftVU, tree, 0) + amt);
                menuManager.updateMenuItem(menuRightVU, MenuItemHelper.getValueFor(menuRightVU, tree, 0) - amt);
            } else {
                menuManager.updateMenuItem(menuLeftVU, MenuItemHelper.getValueFor(menuLeftVU, tree, 0) - amt);
                menuManager.updateMenuItem(menuRightVU, MenuItemHelper.getValueFor(menuRightVU, tree, 0) + amt);
            }
            menuManager.updateMenuItem(menuVolume, Math.random() * menuVolume.getMaxValue());
        }, 150, 150, TimeUnit.MILLISECONDS);
    }
}
Also used : TagValMenuCommandProtocol(com.thecoderscorner.menu.remote.protocol.TagValMenuCommandProtocol) AnalogMenuItem(com.thecoderscorner.menu.domain.AnalogMenuItem) MenuCommandProtocol(com.thecoderscorner.menu.remote.MenuCommandProtocol) TagValMenuCommandProtocol(com.thecoderscorner.menu.remote.protocol.TagValMenuCommandProtocol) MenuManagerServer(com.thecoderscorner.menu.mgr.MenuManagerServer) SimpleFormatter(java.util.logging.SimpleFormatter) PropertiesAuthenticator(com.thecoderscorner.menu.auth.PropertiesAuthenticator) NoDialogFacilities(com.thecoderscorner.menu.mgr.NoDialogFacilities) ConsoleHandler(java.util.logging.ConsoleHandler) SocketServerConnectionManager(com.thecoderscorner.menu.remote.mgrclient.SocketServerConnectionManager)

Example 3 with AnalogMenuItem

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

the class UIAnalogMenuItemTest method testValidValuesNearLimits.

@Test
void testValidValuesNearLimits(FxRobot robot) throws InterruptedException {
    MenuItem analogItem = menuTree.getMenuById(1).orElseThrow();
    VariableNameGenerator vng = new VariableNameGenerator(menuTree, false);
    var uiSubItem = editorUI.createPanelForMenuItem(analogItem, menuTree, vng, mockedConsumer);
    // open the sub menu item editor panel
    createMainPanel(uiSubItem);
    // firstly check that all the fields are populated properly
    performAllCommonChecks(analogItem, true);
    robot.clickOn("#offsetField");
    robot.eraseText(5);
    robot.write("-32768");
    robot.clickOn("#unitNameField");
    robot.eraseText(5);
    robot.write("");
    robot.clickOn("#divisorField");
    robot.eraseText(5);
    robot.write("10000");
    robot.clickOn("#maxValueField");
    robot.eraseText(5);
    robot.write("65535");
    // select any other field to commit edit.
    robot.clickOn("#unitNameField");
    verifyThatThereAreNoErrorsReported();
    ArgumentCaptor<MenuItem> captor = ArgumentCaptor.forClass(MenuItem.class);
    verify(mockedConsumer, atLeastOnce()).accept(any(), captor.capture());
    AnalogMenuItem item = (AnalogMenuItem) captor.getValue();
    assertEquals(-32768, item.getOffset());
    assertEquals(65535, item.getMaxValue());
    assertEquals(10000, item.getDivisor());
    assertEquals("", item.getUnitName());
}
Also used : AnalogMenuItem(com.thecoderscorner.menu.domain.AnalogMenuItem) MenuItem(com.thecoderscorner.menu.domain.MenuItem) AnalogMenuItem(com.thecoderscorner.menu.domain.AnalogMenuItem) VariableNameGenerator(com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator) Test(org.junit.jupiter.api.Test)

Aggregations

AnalogMenuItem (com.thecoderscorner.menu.domain.AnalogMenuItem)3 MenuItem (com.thecoderscorner.menu.domain.MenuItem)2 VariableNameGenerator (com.thecoderscorner.menu.editorui.generator.core.VariableNameGenerator)2 Test (org.junit.jupiter.api.Test)2 PropertiesAuthenticator (com.thecoderscorner.menu.auth.PropertiesAuthenticator)1 MenuManagerServer (com.thecoderscorner.menu.mgr.MenuManagerServer)1 NoDialogFacilities (com.thecoderscorner.menu.mgr.NoDialogFacilities)1 MenuCommandProtocol (com.thecoderscorner.menu.remote.MenuCommandProtocol)1 SocketServerConnectionManager (com.thecoderscorner.menu.remote.mgrclient.SocketServerConnectionManager)1 TagValMenuCommandProtocol (com.thecoderscorner.menu.remote.protocol.TagValMenuCommandProtocol)1 ConsoleHandler (java.util.logging.ConsoleHandler)1 SimpleFormatter (java.util.logging.SimpleFormatter)1