Skip to content

Commit

Permalink
build: Introduced unit testing (#314 and #322)
Browse files Browse the repository at this point in the history
- Java 11 now required for building
- compilation binaries remain compatible with Java 8
  • Loading branch information
scroix authored May 4, 2024
1 parent c5d34e5 commit 70aa84b
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 1 deletion.
21 changes: 20 additions & 1 deletion nodel-framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

// 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'
}

12 changes: 12 additions & 0 deletions nodel-framework/src/test/java/org/nodel/GitHubIssue.java
Original file line number Diff line number Diff line change
@@ -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
}
37 changes: 37 additions & 0 deletions nodel-framework/src/test/java/org/nodel/SimpleNameTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
4 changes: 4 additions & 0 deletions nodel-jyhost/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ application {
mainClass = 'org.nodel.jyhost.Launch'
}

compileJava {
options.release = 8
}

jar {
from "$buildDir/output"
archiveBaseName = 'nodel-jyhost'
Expand Down
4 changes: 4 additions & 0 deletions nodel-webui-js/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ plugins {
id 'com.github.node-gradle.node' version '7.0.2'
}

compileJava {
options.release = 8
}

repositories {
mavenCentral()
}
Expand Down

0 comments on commit 70aa84b

Please sign in to comment.