From bdd3e449980323b9b9cb53155e3fae54d539ec2a Mon Sep 17 00:00:00 2001 From: scroix Date: Fri, 3 May 2024 20:58:08 +1000 Subject: [PATCH] Squashed commit of the following: commit 3c3bd3e065932b3d885a0662521897ef5b601ec8 Author: scroix Date: Wed Apr 24 20:38:13 2024 +1000 Fix broken versioning of nodehost builds - https://github.com/museumsvictoria/nodel/pull/314#issuecomment-2071805006 commit a2a27fd245f69e5ec922cda0cbe2ac27b28bcdef Author: scroix Date: Wed Apr 24 19:29:40 2024 +1000 Apply Java 11 compile patch from @justparking commit 1d9d4adde4de82538fa38102ebeab67114f8286a Author: scroix Date: Wed Apr 24 19:18:20 2024 +1000 Revert "Revert to Java 8 compatible logback dependency" This reverts commit 1b9e15b633979cd1cf47238c5597b235dc19a9f9. commit 1b9e15b633979cd1cf47238c5597b235dc19a9f9 Author: scroix Date: Fri Apr 19 18:46:43 2024 +1000 Revert to Java 8 compatible logback dependency commit ca5bc00075d91de2f6fdc8d471089892b0a93854 Author: scroix Date: Sat Apr 20 12:19:25 2024 +1000 Revert "Merge branch 'feature/introduce-junit-testing' of github.com:scroix/nodel into feature/introduce-junit-testing" This reverts commit 50dfbcbda795317deef1d16c83092ab5ab00f87f, reversing changes made to b1a73ad35cc7b86aa676fff787f7fdd79cb91633. commit 50dfbcbda795317deef1d16c83092ab5ab00f87f Merge: b1a73ad d9830bc Author: scroix Date: Sat Apr 20 12:15:05 2024 +1000 Merge branch 'feature/introduce-junit-testing' of github.com:scroix/nodel into feature/introduce-junit-testing # Conflicts: # nodel-framework/build.gradle # nodel-framework/src/test/java/org/nodel/SimpleNameTest.java commit b1a73ad35cc7b86aa676fff787f7fdd79cb91633 Author: scroix Date: Thu Apr 4 17:42:25 2024 +1100 Add first ever JUnit tests - Cover SimpleNameTest with a couple of test cases - Ensure they pass commit 9a0ebd269a57dd650704fce4f4bcf3e6d23f234c Author: scroix Date: Thu Apr 4 17:41:21 2024 +1100 Add JUnit as a testing framework - Configure Gradle build to include JUnit dependencies commit 1198db33c5a64809f9c99d77026b4865246f6ce2 Author: scroix Date: Fri Apr 5 09:17:53 2024 +1100 Introduce test cases to cover expected names of dynamically generated Actions and Events - These are in preparation for changes related to issue #284 commit da018340171438d9f12bd0bb9518dbd0eb94dd55 Author: scroix Date: Fri Apr 5 09:16:42 2024 +1100 Add GitHubIssue annotation to mark up tests commit a1c0e13ba485962f8db3759a9ad5aebd77c4d64e Author: scroix Date: Fri Apr 5 09:15:51 2024 +1100 minor: Remove public declaration from SimpleNameTest commit c04baf2c8a2e6394dc0b373ef0d555beafe65126 Author: scroix Date: Fri Apr 5 09:14:50 2024 +1100 Add Mockito and Logback test dependencies commit 2daa92bff9661a8bcac55d31fa3607f6c293dcce Author: scroix Date: Thu Apr 4 17:42:25 2024 +1100 Add first ever JUnit tests - Cover SimpleNameTest with a couple of test cases - Ensure they pass commit 14b70338ad82f9c6c4a1325c500cde2fde507f7d Author: scroix Date: Thu Apr 4 17:41:21 2024 +1100 Add JUnit as a testing framework - Configure Gradle build to include JUnit dependencies commit d9830bcb83e03e748c58b0ce78c359b57988c370 Author: scroix Date: Fri Apr 19 18:46:43 2024 +1000 Revert to Java 8 compatible logback dependency commit e74f409039d9d534b9f330b5f413a7dee78977e4 Author: scroix Date: Sat Apr 6 16:11:43 2024 +1100 Revert to original parent build file commit 128dbe28de287090f218b16ee63f97131c29076f Author: scroix Date: Sat Apr 6 16:10:18 2024 +1100 Re-add Gradle job for running tests commit 6a0ed30a2e644b138f5d14c1f26beeb03fef23ac Author: scroix Date: Sat Apr 6 16:08:20 2024 +1100 Revert "minor: ignore IntelliJ IDE files" This reverts commit 9a23d63b90ceef449e763588c8fc6a749a805801. commit 08e99fe8c746b2e93702b3d348bb6b03f71c24f2 Author: scroix Date: Sat Apr 6 16:04:59 2024 +1100 Manually 'rebase' in preparation for PR commit 2ff6ddae755397fad56431a660a466169484f1b0 Merge: e386b21 1440a78 Author: Julien de-Sainte-Croix Date: Sat Apr 6 15:21:28 2024 +1100 Merge branch 'feature/introduce-junit-testing' of github.com:scroix/nodel into feature/introduce-junit-testing # Conflicts: # nodel-framework/build.gradle commit e386b2139a7eee056e9480d5efc2d9d7f83e3c65 Author: scroix Date: Fri Apr 5 09:17:53 2024 +1100 Introduce test cases to cover expected names of dynamically generated Actions and Events - These are in preparation for changes related to issue #284 commit b67c120ff198a50595acd42631b68067c1072641 Author: scroix Date: Fri Apr 5 09:16:42 2024 +1100 Add GitHubIssue annotation to mark up tests commit 9d003b74e5081ddf9bffcfee5db4b3ecc8745dc1 Author: scroix Date: Fri Apr 5 09:15:51 2024 +1100 minor: Remove public declaration from SimpleNameTest commit 5ebcf199b36ced50a11c7fed6f76279b9be7cab0 Author: scroix Date: Fri Apr 5 09:14:50 2024 +1100 Add Mockito and Logback test dependencies commit 7586d243b0b92a430860e5dd580169509c6055f9 Author: scroix Date: Thu Apr 4 17:42:25 2024 +1100 Add first ever JUnit tests - Cover SimpleNameTest with a couple of test cases - Ensure they pass commit e7b7e3eac6e8bf4835bb70b0978800e962ce110c Author: scroix Date: Thu Apr 4 17:41:21 2024 +1100 Add JUnit as a testing framework - Configure Gradle build to include JUnit dependencies commit 9a23d63b90ceef449e763588c8fc6a749a805801 Author: scroix Date: Thu Apr 4 17:40:05 2024 +1100 minor: ignore IntelliJ IDE files commit 1440a78dbab6519a262c048408ee921f142684bd Author: scroix Date: Fri Apr 5 09:17:53 2024 +1100 Introduce test cases to cover expected names of dynamically generated Actions and Events - These are in preparation for changes related to issue #284 commit ac56791db1d5bf714e0895c192c6dcdedd90972f Author: scroix Date: Fri Apr 5 09:16:42 2024 +1100 Add GitHubIssue annotation to mark up tests commit 9e53135d2a962ac43fad0411b9cac1c88d6b53b9 Author: scroix Date: Fri Apr 5 09:15:51 2024 +1100 minor: Remove public declaration from SimpleNameTest commit a37d107950da8ee879c7085be09d5f7258d29efe Author: scroix Date: Fri Apr 5 09:14:50 2024 +1100 Add Mockito and Logback test dependencies commit 61143564bf734fe41ffcc2141d2243d2f8ef34b6 Author: scroix Date: Thu Apr 4 17:42:25 2024 +1100 Add first ever JUnit tests - Cover SimpleNameTest with a couple of test cases - Ensure they pass commit 9328669b430d95bdc252cb950d0feb020584893a Author: scroix Date: Thu Apr 4 17:41:21 2024 +1100 Add JUnit as a testing framework - Configure Gradle build to include JUnit dependencies commit 36a59f38926ce53565ef51d00c2b4348bee14326 Author: scroix Date: Thu Apr 4 17:40:05 2024 +1100 minor: ignore IntelliJ IDE files commit de67ed4e0d0585160c456fb2afaa019c259cfb1a Author: scroix Date: Thu Apr 4 14:51:47 2024 +1100 Rename branch in support of .jar generation - This tackles a tiny regression which saw us lose -dev- handled in the generated .jar filename - We also handle the odd case of building in a git branch which includes a forward slash commit 138c477416a7361aad109ef42f20fc01323ccf08 Author: scroix Date: Thu Apr 4 07:29:27 2024 +1100 Stop targetting specific Gruntfile command - 'default' includes googlefonts build, but the 'build' command does not commit 997b67789bdfa1efdc5cf96204e7177c5cc2302f Author: scroix Date: Sat Mar 30 13:46:36 2024 +1100 Revert "Update gradle-wrapper.jar" This reverts commit 058a4078de75ea2bc9df38d103c28a223f102479. commit 058a4078de75ea2bc9df38d103c28a223f102479 Author: scroix Date: Sat Mar 30 13:46:17 2024 +1100 Update gradle-wrapper.jar commit d23abeb4396cee86e1e4355fd715290d716d5e2e Author: scroix Date: Sat Mar 30 13:41:50 2024 +1100 Switch to Gradle bin commit 90c50663f6891d8699c9c5e1478f34d9defd7491 Author: scroix Date: Sat Mar 30 13:36:28 2024 +1100 Update gradlew files - Using `gradle wrapper` command commit 901871665aeeb72c27c86a66e6f5371ff66477f5 Author: scroix Date: Sat Mar 30 13:24:58 2024 +1100 Move project info variables to top-level build file commit 0cfb6fd2ce0c20633d7e6baf4d584840840a695c Author: scroix Date: Sat Mar 30 13:24:33 2024 +1100 Revert to original devDependencies commit 162d58dfe8be2268bb927f5ccecddf4c0ae48c2a Author: scroix Date: Sat Mar 30 12:03:12 2024 +1100 Revert node version to simplify grunt issue commit 1b0b706ceededf5f92aba8179a43a1a742166fc3 Author: scroix Date: Sat Mar 30 08:13:58 2024 +1100 Add a couple more optimisations commit d65be7156846fe650171f8392a735295e228dc3a Author: scroix Date: Sat Mar 30 07:42:54 2024 +1100 Move the feature to check for file changes into a class commit 027a12977219934cc6c5b24b90b9c422e6a1ce65 Author: scroix Date: Sat Mar 30 07:18:03 2024 +1100 Remove unneccesary dir check during Gradle webui tasks commit 1a766c24e9ba152114319204c4e018bf1ef36dfb Author: scroix Date: Sat Mar 30 07:17:27 2024 +1100 Remove Gradle optimisation flags commit 2fd735b1fc4149743ff856420c47a73fff7f6645 Author: Julien de-Sainte-Croix Date: Fri Mar 29 22:26:53 2024 +1100 Maybe this is working now commit 820dba9d2e78fa331037a281f589356fe014afae Author: Julien de-Sainte-Croix Date: Fri Mar 29 21:57:48 2024 +1100 Remove the grunt script from the package.json commit 3e660866f935a175bdb5f3dfda3ea97825655682 Author: Julien de-Sainte-Croix Date: Fri Mar 29 21:57:37 2024 +1100 Further attempt to cache the grunt task commit 3121adfc7199858b0fd136de49fb7b3fee2bf2b3 Author: Julien de-Sainte-Croix Date: Fri Mar 29 20:51:49 2024 +1100 Add hack for "cache" of grunt tasks commit 48c0b59d205283e2b7ce58b761381d925dbcd5f5 Author: scroix Date: Fri Mar 29 19:43:22 2024 +1100 Attempt to cache grunt commit 8a93e803e38ad100cb6b1dd08a2cd1ccc64e72d1 Author: scroix Date: Fri Mar 29 19:42:47 2024 +1100 Enable some speed-ups commit d151cda5ff1604abec8cad8dab650b235becf61d Author: scroix Date: Fri Mar 29 16:29:48 2024 +1100 Bump node-gradle plugin version to 7.0.2 commit 2c8f6f591ccd60b3b1d86b6b4aa92dc32db12120 Author: scroix Date: Fri Mar 29 16:29:22 2024 +1100 Resolve minor warnings commit 0fcc59ea04066c992f7a1d7ecde4b857a1d09b91 Author: scroix Date: Fri Mar 29 16:28:48 2024 +1100 Replace deprecated jcenter commit c10d6ef9d5724b13ba428073eba63272bf6eafbe Author: Julien de-Sainte-Croix Date: Fri Mar 29 15:10:53 2024 +1100 Bump Gradle version to 7.6.4 commit 9e05637f49d8032a616e7ce32e53ee186f652b6a Author: Julien de-Sainte-Croix Date: Mon Mar 18 21:13:46 2024 +1100 Upgrade Gradle to 7.4 and Node.js to 16.x - Migrate build scripts to be compatible - Bump Node.js version to one which supports ARM/Silicon builds - Configure the node-gradle-plugin --- nodel-framework/build.gradle | 21 ++++- .../src/test/java/org/nodel/GitHubIssue.java | 12 +++ .../test/java/org/nodel/SimpleNameTest.java | 37 ++++++++ .../org/nodel/toolkit/ManagedToolkitTest.java | 91 +++++++++++++++++++ nodel-jyhost/build.gradle | 4 + nodel-webui-js/build.gradle | 4 + 6 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 nodel-framework/src/test/java/org/nodel/GitHubIssue.java create mode 100644 nodel-framework/src/test/java/org/nodel/SimpleNameTest.java create mode 100644 nodel-framework/src/test/java/org/nodel/toolkit/ManagedToolkitTest.java diff --git a/nodel-framework/build.gradle b/nodel-framework/build.gradle index 8e529b62..ff4a9e9a 100644 --- a/nodel-framework/build.gradle +++ b/nodel-framework/build.gradle @@ -14,10 +14,29 @@ jar { } } +compileJava { + options.release = 8 +} + +test { + useJUnitPlatform() + testLogging { + events 'passed', 'skipped', 'failed' + } +} + dependencies { implementation 'joda-time:joda-time:2.6' implementation 'org.slf4j:slf4j-api:1.7.10' // SSH features implementation group: 'com.jcraft', name: 'jsch', version: '0.1.55' -} \ No newline at end of file + + // Test dependencies + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' + testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.0' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0' + testImplementation 'org.mockito:mockito-core:3.+' + testImplementation 'ch.qos.logback:logback-classic:1.4.14' +} + diff --git a/nodel-framework/src/test/java/org/nodel/GitHubIssue.java b/nodel-framework/src/test/java/org/nodel/GitHubIssue.java new file mode 100644 index 00000000..a81c7639 --- /dev/null +++ b/nodel-framework/src/test/java/org/nodel/GitHubIssue.java @@ -0,0 +1,12 @@ +package org.nodel; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +public @interface GitHubIssue { + String value(); // The URL or ID of the GitHub issue +} \ No newline at end of file diff --git a/nodel-framework/src/test/java/org/nodel/SimpleNameTest.java b/nodel-framework/src/test/java/org/nodel/SimpleNameTest.java new file mode 100644 index 00000000..9813959b --- /dev/null +++ b/nodel-framework/src/test/java/org/nodel/SimpleNameTest.java @@ -0,0 +1,37 @@ +package org.nodel; + +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; +import static org.junit.jupiter.api.Assertions.*; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class SimpleNameTest { + + @ParameterizedTest + @ValueSource(strings = { + "node_name", + "Node Name", + "node-name", + "node.name", + "node name" + }) + void testGetOriginalName(String originalName) { + SimpleName name = new SimpleName(originalName); + assertEquals(originalName, name.getOriginalName()); + } + + @ParameterizedTest + @CsvSource({ + "node_name, nodename", + "Node Name, NodeName", + "node-name, nodename", + "node.name, nodename", + "node name, nodename" + }) + public void testGetReducedName(String originalName, String expectedReducedName) { + SimpleName name = new SimpleName(originalName); + assertEquals(expectedReducedName, name.getReducedName()); + } +} \ No newline at end of file diff --git a/nodel-framework/src/test/java/org/nodel/toolkit/ManagedToolkitTest.java b/nodel-framework/src/test/java/org/nodel/toolkit/ManagedToolkitTest.java new file mode 100644 index 00000000..3e51459a --- /dev/null +++ b/nodel-framework/src/test/java/org/nodel/toolkit/ManagedToolkitTest.java @@ -0,0 +1,91 @@ +package org.nodel.toolkit; + +import org.junit.jupiter.api.*; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.nodel.GitHubIssue; +import org.nodel.SimpleName; +import org.nodel.core.NodelServerAction; +import org.nodel.core.NodelServerEvent; +import org.nodel.core.NodelServers; +import org.nodel.host.BaseDynamicNode; +import org.nodel.host.Binding; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +class ManagedToolkitTest { + + private ManagedToolkit managedToolkit; + private Binding metadata; + private ActionFunction actionFunction; + + @FunctionalInterface + interface ActionFunction { + void handle(Object arg); + } + + @BeforeEach + void setUp() { + BaseDynamicNode mockNode = mock(BaseDynamicNode.class); + when(mockNode.getName()).thenReturn(new SimpleName("MockNode")); + managedToolkit = new ManagedToolkit(mockNode); + metadata = new Binding(); + actionFunction = arg -> {}; + } + + @Disabled("Awaiting fix for issue: #284") + @DisplayName("Original name of generated action") + @GitHubIssue("https://github.com/museumsvictoria/nodel/issues/284") + @ParameterizedTest + @CsvSource({ + "Action With Spaces, Action With Spaces", + "Action-With-Hyphens, Action-With-Hyphens", + }) + void testCreateActionWithDefaultName(String actionName, String expectedName) { + try (NodelServerAction action = managedToolkit.createAction(actionName, actionFunction::handle, metadata)) { + assertEquals(expectedName, action.getAction().getOriginalName()); + } + } + + @DisplayName("Reduced name of generated action") + @ParameterizedTest + @CsvSource({ + "Action With Spaces, ActionWithSpaces", + "Action-With-Hyphens, ActionWithHyphens", + }) + void testCreateActionWithReducedName(String actionName, String expectedName) { + try (NodelServerAction action = managedToolkit.createAction(actionName, actionFunction::handle, metadata)) { + assertEquals(expectedName, action.getAction().getReducedName()); + } + } + + @Disabled("Awaiting fix for issue: #284") + @DisplayName("Original name of generated event") + @GitHubIssue("https://github.com/museumsvictoria/nodel/issues/284") + @ParameterizedTest + @CsvSource({ + "Event With Spaces, Event With Spaces", + "Event-With-Hyphens, Event-With-Hyphens", + }) + void testCreateEventWithDefaultName(String eventName, String expectedName) { + try (NodelServerEvent event = managedToolkit.createEvent(eventName, metadata)) { + NodelServers.instance().registerEvent(event); + assertEquals(expectedName, event.getEvent().getOriginalName()); + } + } + + @DisplayName("Reduced name of generated event") + @ParameterizedTest + @CsvSource({ + "Event With Spaces, EventWithSpaces", + "Event-With-Hyphens, EventWithHyphens", + }) + + void testCreateEventWithReducedName(String eventName, String expectedName) { + try (NodelServerEvent event = managedToolkit.createEvent(eventName, metadata)) { + NodelServers.instance().registerEvent(event); + assertEquals(expectedName, event.getEvent().getReducedName()); + } + } +} \ No newline at end of file diff --git a/nodel-jyhost/build.gradle b/nodel-jyhost/build.gradle index b4265d59..20479d9b 100644 --- a/nodel-jyhost/build.gradle +++ b/nodel-jyhost/build.gradle @@ -13,6 +13,10 @@ application { mainClass = 'org.nodel.jyhost.Launch' } +compileJava { + options.release = 8 +} + jar { from "$buildDir/output" archiveBaseName = 'nodel-jyhost' diff --git a/nodel-webui-js/build.gradle b/nodel-webui-js/build.gradle index 4eaa7f8e..8949660a 100644 --- a/nodel-webui-js/build.gradle +++ b/nodel-webui-js/build.gradle @@ -17,6 +17,10 @@ plugins { id 'com.github.node-gradle.node' version '7.0.2' } +compileJava { + options.release = 8 +} + repositories { mavenCentral() }