Skip to content

Commit

Permalink
Migrate TestNG tests to JUnit 5 (#1358)
Browse files Browse the repository at this point in the history
Migrates TestNG tests to JUnit 5, fixes broken tests, temporarily disables some mock-based tests.

Signed-off-by: system24seven <david@system24seven.com>
Co-authored-by: Kevin Herron <kevinherron@gmail.com>
Co-authored-by: Aurélien Pupier <apupier@redhat.com>
  • Loading branch information
3 people authored Jan 3, 2025
1 parent 368a5d3 commit 82fc1ba
Show file tree
Hide file tree
Showing 79 changed files with 757 additions and 733 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/maven-verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Run `mvn verify` on JDK 17

on:
pull_request:
branches: [ "dev/1.0" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven

- name: Build and Verify with Maven
run: mvn -B verify
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Jenkins](https://img.shields.io/jenkins/build/https/ci.eclipse.org/milo/job/Milo_Deploy.svg)](https://ci.eclipse.org/milo/)
[![Maven Central](https://img.shields.io/maven-central/v/org.eclipse.milo/milo.svg)](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.eclipse.milo%22%20AND%20a%3A%22milo%22)

Milo is an open-source implementation of OPC UA (currently targeting 1.03). It includes a high-performance stack (channels, serialization, data structures, security) as well as client and server SDKs built on top of the stack.
Milo is an open-source implementation of OPC UA (currently targeting 1.05). It includes a high-performance stack (channels, serialization, data structures, security) as well as client and server SDKs built on top of the stack.

Stack Overflow tag: [milo](http://stackoverflow.com/questions/tagged/milo)

Expand All @@ -27,7 +27,7 @@ Releases are published to Maven Central and snapshots to Sonatype.
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>milo-sdk-client</artifactId>
<version>0.6.10</version>
<version>1.0.0</version>
</dependency>
```

Expand All @@ -37,7 +37,7 @@ Releases are published to Maven Central and snapshots to Sonatype.
<dependency>
<groupId>org.eclipse.milo</groupId>
<artifactId>milo-sdk-server</artifactId>
<version>0.6.10</version>
<version>1.0.0</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected void assertRoundTripUsingToString(
System.out.println("encodedValue:\t" + ByteBufUtil.hexDump(encodedValue));

Object decodedValue = codec.decode(context, new OpcUaBinaryDecoder(context).setBuffer(buffer));
assertEquals(decodedValue.toString(), originalValue.toString());
assertEquals(originalValue.toString(), decodedValue.toString());
System.out.println("decodedValue:\t" + decodedValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@ private void testReadDataTypeDictionaryBytes(ByteString dictionary, int fragment
ByteString typeDictionaryBs =
dictionaryReader.readDataTypeDictionaryBytes(NodeId.NULL_VALUE, fragmentSize).get();

Assertions.assertEquals(typeDictionaryBs, dictionary);
Assertions.assertEquals(dictionary, typeDictionaryBs);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 the Eclipse Milo Authors
* Copyright (c) 2025 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -10,12 +10,7 @@

package org.eclipse.milo.opcua.sdk.client;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

import java.util.EnumSet;
import java.util.List;
Expand Down Expand Up @@ -53,8 +48,7 @@ public void browse() throws UaException {
n.getNodeClass()));

if (n instanceof UaVariableNode) {
System.out.println(
"\u2514\u2500 value = " + ((UaVariableNode) n).getValue().getValue());
System.out.println("└─ value = " + ((UaVariableNode) n).getValue().getValue());
}
});
}
Expand Down Expand Up @@ -190,11 +184,11 @@ public void getNode() throws UaException {

UaNode serverNode = addressSpace.getNode(NodeIds.Server);
assertNotNull(serverNode);
assertTrue(serverNode instanceof ServerTypeNode);
assertInstanceOf(ServerTypeNode.class, serverNode);

UaNode serverStatusNode = addressSpace.getNode(NodeIds.Server_ServerStatus);
assertNotNull(serverStatusNode);
assertTrue(serverStatusNode instanceof ServerStatusTypeNode);
assertInstanceOf(ServerStatusTypeNode.class, serverStatusNode);
}

@Test
Expand Down
9 changes: 3 additions & 6 deletions opc-ua-sdk/sdk-server/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2024 the Eclipse Milo Authors
~ Copyright (c) 2025 the Eclipse Milo Authors
~
~ This program and the accompanying materials are made
~ available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -46,19 +46,16 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 the Eclipse Milo Authors
* Copyright (c) 2025 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -11,53 +11,53 @@
package org.eclipse.milo.opcua.sdk.core;

import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.ubyte;
import static org.testng.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

public class AccessLevelTest {

@Test
public void testToValue() {
for (AccessLevel accessLevel : AccessLevel.values()) {
assertEquals(AccessLevel.toValue(accessLevel), ubyte(accessLevel.getValue()));
assertEquals(ubyte(accessLevel.getValue()), AccessLevel.toValue(accessLevel));
}

assertEquals(AccessLevel.toValue(AccessLevel.NONE), ubyte(0));
assertEquals(ubyte(0), AccessLevel.toValue(AccessLevel.NONE));

assertEquals(
AccessLevel.toValue(AccessLevel.READ_ONLY).intValue(), AccessLevel.CurrentRead.getValue());
AccessLevel.CurrentRead.getValue(), AccessLevel.toValue(AccessLevel.READ_ONLY).intValue());

assertEquals(
AccessLevel.toValue(AccessLevel.READ_WRITE).intValue(),
AccessLevel.CurrentRead.getValue() | AccessLevel.CurrentWrite.getValue());
AccessLevel.CurrentRead.getValue() | AccessLevel.CurrentWrite.getValue(),
AccessLevel.toValue(AccessLevel.READ_WRITE).intValue());

assertEquals(
AccessLevel.toValue(AccessLevel.HISTORY_READ_ONLY).intValue(),
AccessLevel.HistoryRead.getValue());
AccessLevel.HistoryRead.getValue(),
AccessLevel.toValue(AccessLevel.HISTORY_READ_ONLY).intValue());

assertEquals(
AccessLevel.toValue(AccessLevel.HISTORY_READ_WRITE).intValue(),
AccessLevel.HistoryRead.getValue() | AccessLevel.HistoryWrite.getValue());
AccessLevel.HistoryRead.getValue() | AccessLevel.HistoryWrite.getValue(),
AccessLevel.toValue(AccessLevel.HISTORY_READ_WRITE).intValue());
}

@Test
public void testFromValue() {
assertEquals(AccessLevel.fromValue(0), AccessLevel.NONE);
assertEquals(AccessLevel.NONE, AccessLevel.fromValue(0));

assertEquals(AccessLevel.fromValue(AccessLevel.CurrentRead.getValue()), AccessLevel.READ_ONLY);
assertEquals(AccessLevel.READ_ONLY, AccessLevel.fromValue(AccessLevel.CurrentRead.getValue()));

assertEquals(
AccessLevel.READ_WRITE,
AccessLevel.fromValue(
AccessLevel.CurrentRead.getValue() | AccessLevel.CurrentWrite.getValue()),
AccessLevel.READ_WRITE);
AccessLevel.CurrentRead.getValue() | AccessLevel.CurrentWrite.getValue()));

assertEquals(
AccessLevel.fromValue(AccessLevel.HistoryRead.getValue()), AccessLevel.HISTORY_READ_ONLY);
AccessLevel.HISTORY_READ_ONLY, AccessLevel.fromValue(AccessLevel.HistoryRead.getValue()));

assertEquals(
AccessLevel.HISTORY_READ_WRITE,
AccessLevel.fromValue(
AccessLevel.HistoryRead.getValue() | AccessLevel.HistoryWrite.getValue()),
AccessLevel.HISTORY_READ_WRITE);
AccessLevel.HistoryRead.getValue() | AccessLevel.HistoryWrite.getValue()));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 the Eclipse Milo Authors
* Copyright (c) 2025 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -10,11 +10,11 @@

package org.eclipse.milo.opcua.sdk.core;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.eclipse.milo.opcua.stack.core.types.structured.EUInformation;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

public class CefactEngineeringUnitsTest {

Expand All @@ -23,7 +23,7 @@ public void test() {
assertTrue(CefactEngineeringUnits.getAll().length > 0);

for (EUInformation eu : CefactEngineeringUnits.getAll()) {
assertEquals(CefactEngineeringUnits.getByUnitId(eu.getUnitId()), eu);
assertEquals(eu, CefactEngineeringUnits.getByUnitId(eu.getUnitId()));
}
}
}
Loading

0 comments on commit 82fc1ba

Please sign in to comment.