Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
<module>vaadin-testbench-unit</module>
<module>vaadin-testbench-unit-junit5</module>
<module>vaadin-testbench-unit-quarkus</module>
<module>testing-support/uiunit-test-components</module>
<module>testing-support/uiunit-component-testers</module>
</modules>
<repositories>
<repository>
Expand Down
63 changes: 63 additions & 0 deletions testing-support/uiunit-component-testers/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2000-2025 Vaadin Ltd
~
~ This program is available under Vaadin Commercial License and Service Terms.
~
~ See <https://vaadin.com/commercial-license-and-service-terms> for the full
~ license.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-testbench-parent</artifactId>
<version>10.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>uiunit-component-testers</artifactId>
<packaging>jar</packaging>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-server</artifactId>
<version>${flow.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-testbench-unit-shared</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>uiunit-test-components</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<configuration>
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
</configuration>
<version>1.6.8</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2000-2025 Vaadin Ltd
*
* This program is available under Vaadin Commercial License and Service Terms.
*
* See <https://vaadin.com/commercial-license-and-service-terms> for the full
* license.
*/
package com.vaadin.testbench.dontscan.noclassdeffound;

import com.vaadin.testbench.unit.ComponentTester;
import com.vaadin.testbench.unit.Tests;

/**
* Dummy tester referencing a class from a third-party JAR that might not be
* available at runtime. This is used to verify that scanning for testers does
* not fail when the referenced component class is not on the classpath.
*/
@Tests(NoClassDefFoundComponent.class)
public class NoClassDefFoundComponentTester<T extends NoClassDefFoundComponent>
extends ComponentTester<T> {

public NoClassDefFoundComponentTester(T component) {
super(component);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2000-2025 Vaadin Ltd
*
* This program is available under Vaadin Commercial License and Service Terms.
*
* See <https://vaadin.com/commercial-license-and-service-terms> for the full
* license.
*/
package com.vaadin.testbench.dontscan.typenotpresent;

import com.vaadin.flow.component.Component;
import com.vaadin.testbench.unit.ComponentTester;
import com.vaadin.testbench.unit.Tests;

/**
* Dummy tester whose annotation references a class from a third-party JAR that
* might not be available at runtime. This is used to verify that scanning for
* testers does not fail when the referenced component class is not on the
* classpath.
*/
@Tests(TypeNotPresentComponent.class)
public class TypeNotPresentComponentTester extends ComponentTester<Component> {

public TypeNotPresentComponentTester(Component component) {
super(component);
}
}
50 changes: 50 additions & 0 deletions testing-support/uiunit-test-components/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (C) 2000-2025 Vaadin Ltd
~
~ This program is available under Vaadin Commercial License and Service Terms.
~
~ See <https://vaadin.com/commercial-license-and-service-terms> for the full
~ license.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-testbench-parent</artifactId>
<version>10.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>uiunit-test-components</artifactId>
<packaging>jar</packaging>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-server</artifactId>
<version>${flow.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<configuration>
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
</configuration>
<version>1.6.8</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (C) 2000-2025 Vaadin Ltd
*
* This program is available under Vaadin Commercial License and Service Terms.
*
* See <https://vaadin.com/commercial-license-and-service-terms> for the full
* license.
*/

package com.vaadin.testbench.dontscan.noclassdeffound;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Tag;

@Tag("span")
public class NoClassDefFoundComponent extends Component {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (C) 2000-2025 Vaadin Ltd
*
* This program is available under Vaadin Commercial License and Service Terms.
*
* See <https://vaadin.com/commercial-license-and-service-terms> for the full
* license.
*/

package com.vaadin.testbench.dontscan.typenotpresent;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Tag;

@Tag("span")
public class TypeNotPresentComponent extends Component {
}
11 changes: 11 additions & 0 deletions vaadin-testbench-unit-junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,17 @@
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>uiunit-component-testers</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

import com.vaadin.testbench.unit.CommercialTesterWrappers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -24,7 +25,7 @@
import com.vaadin.testbench.unit.ViewPackages;

@ViewPackages
class ChartTesterTest extends UIUnitTest {
class ChartTesterTest extends UIUnitTest implements CommercialTesterWrappers {

ColumnChartView view;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2000-2025 Vaadin Ltd
*
* This program is available under Vaadin Commercial License and Service Terms.
*
* See <https://vaadin.com/commercial-license-and-service-terms> for the full
* license.
*/

package com.vaadin.testbench.unit;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

// Ensure that scanning testers does not fail when a tester references
// a component class that is not present on the classpath.
public class TesterScanTest {

@Test
public void scanForTesters_testerForClassNotInClasspath_doNotThrowOnClassNotFoundException() {
// Loads a dummy tester annotated with @Tests using an FQN to a
// non-existing component class.
Assertions.assertDoesNotThrow(() -> BaseUIUnitTest
.scanForTesters("com.vaadin.testbench.dontscan.classnotfound"));
}

@Test
public void scanForTesters_testerForClassNotInClasspath_doNotThrowNoClassDefFound() {
// Loads a dummy tester annotated with @Tests referencing a class in
// another module with provided scope so the test itself is not able to
// load the class.
Assertions.assertDoesNotThrow(() -> BaseUIUnitTest.scanForTesters(
"com.vaadin.testbench.dontscan.noclassdeffound"));
}

@Test
public void scanForTesters_testerForClassNotInClasspath_doNotThrowTypeNotPresentException() {
// Loads a dummy tester annotated with @Tests referencing a class in
// another module with provided scope so the test itself is not able to
// load the class.
Assertions.assertDoesNotThrow(() -> BaseUIUnitTest.scanForTesters(
"com.vaadin.testbench.dontscan.typenotpresent"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.github.classgraph.ClassGraph;
import io.github.classgraph.ClassInfoList;
import io.github.classgraph.ScanResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.vaadin.flow.component.Component;
Expand Down Expand Up @@ -63,6 +64,8 @@
*/
public abstract class BaseUIUnitTest {

private static final Logger LOGGER = LoggerFactory
.getLogger(BaseUIUnitTest.class.getPackageName());
private static final ConcurrentHashMap<String, Routes> routesCache = new ConcurrentHashMap<>();

protected static final Map<Class<?>, Class<? extends ComponentTester>> testers = new HashMap<>();
Expand All @@ -85,7 +88,8 @@ public abstract class BaseUIUnitTest {
Capabilities.of(Capability.PRE_TRIAL));
}

private static Map<Class<?>, Class<? extends ComponentTester>> scanForTesters(
// Visible for test
static Map<Class<?>, Class<? extends ComponentTester>> scanForTesters(
String... packages) {
try (ScanResult scan = new ClassGraph().enableClassInfo()
.enableAnnotationInfo().acceptPackages(packages).scan(2)) {
Expand Down Expand Up @@ -114,19 +118,39 @@ private static Map<Class<?>, Class<? extends ComponentTester>> scanForTesters(
try {
return UtilsKt.findClassOrThrow(clazz);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
logTypeLoadingIssue(e,
"Tester '{}' cannot be loaded because of missing component class '{}' on classpath",
classInfo.getName(), clazz);
}
}).forEach(clazz -> testerMap.put(clazz,
(Class<? extends ComponentTester>) tester));

} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
return null;
}).filter(Objects::nonNull)
.forEach(clazz -> testerMap.put(clazz,
(Class<? extends ComponentTester>) tester));

} catch (TypeNotPresentException e) {
logTypeLoadingIssue(e,
"Tester '{}' cannot be loaded because of missing class '{}' on classpath",
classInfo.getName(), e.typeName());
} catch (ClassNotFoundException
| NoClassDefFoundError e) {
logTypeLoadingIssue(e,
"Tester '{}' cannot be loaded because of missing class on classpath: {}",
classInfo.getName(), e.getMessage());
}
});
return Collections.unmodifiableMap(testerMap);
}
}

private static void logTypeLoadingIssue(Throwable ex, String message,
Object... args) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(message, args, ex);
} else {
LOGGER.warn(message, args);
}
}

protected synchronized Routes discoverRoutes() {
return discoverRoutes(scanPackages());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* Provides factory method to create testers for commercial components.
*/
@SuppressWarnings("unchecked")
public interface CommercialTestWrappers {
public interface CommercialTesterWrappers {

/**
* Create a tester for the given Chart instance.
Expand Down
Loading