Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 84 #172

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ subprojects { proj ->
// }

test {
useTestNG()
useJUnitPlatform()
jvmArgs("-Djdk.attach.allowAttachSelf")
testLogging.showStandardStreams = true
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -41,6 +41,8 @@ jakartaValidationApiVersion=2.0.2
jakartaXmlBindApiVersion=2.3.3
jakartaInjectApiVersion=1.0
junitVersion=4.13
junitJupiterVersion=5.7.0
junitJupiterLauncherVersion=1.7.0
jaxbRuntimeVersion=2.3.2
httpclientVersion=4.5.12
logbackVersion=1.2.3
Original file line number Diff line number Diff line change
@@ -19,7 +19,10 @@ dependencies {
api project(':rico-remoting-server-spring')
api project(':rico-remoting-client')
implementation "org.testng:testng:$testngVersion"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the testng dependency (and version variable) if it is no longer used

implementation "junit:junit:$junitVersion"
testCompile "org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion"
testRuntimeOnly"org.junit.platform:junit-platform-launcher:$junitJupiterLauncherVersion"
compile "org.junit.jupiter:junit-jupiter:$junitJupiterVersion"
compile "org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion"

implementation "org.springframework:spring-web:$springVersion"
implementation "org.springframework:spring-context:$springVersion"
Original file line number Diff line number Diff line change
@@ -21,52 +21,61 @@
import dev.rico.internal.server.remoting.test.SpringTestBootstrap;
import dev.rico.internal.server.remoting.test.TestClientContext;
import org.apiguardian.api.API;
import org.junit.Rule;
import org.junit.rules.ExternalResource;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;


import org.junit.jupiter.api.extension.ExtendWith;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit.jupiter.SpringExtension;




import static org.apiguardian.api.API.Status.MAINTAINED;

/**
* Base class for JUnit based controller tests in Spring. This class can be extended to write custom controller tests.
*
* @see ControllerTest
* @see AbstractJUnit4SpringContextTests
* @see //AbstractJUnit4SpringContextTests
* @see ControllerUnderTest
*
* @author Hendrik Ebbers
*/

@ExtendWith({SpringExtension.class})
@SpringBootTest
@ContextConfiguration(classes = SpringTestBootstrap.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@API(since = "0.x", status = MAINTAINED)
public abstract class SpringJUnitControllerTest extends AbstractJUnit4SpringContextTests implements ControllerTest {
public abstract class SpringJUnitControllerTest implements ControllerTest {

@Autowired
private TestClientContext clientContext;

@Rule
public ExternalResource clientConnector = new ExternalResource() {
@Override
protected void before() throws Throwable {
super.before();
clientContext.connect().get();
}

@Override
protected void after() {
super.after();
try {
clientContext.disconnect().get();
} catch (Exception e) {
throw new ControllerTestException("Can not disconnect client context!", e);
}
@AfterEach
public void closeClient() throws Exception {
try {
clientContext.disconnect().get();
} catch (Exception e) {
throw new ControllerTestException("Can not disconnect client context!", e);
}
};

}

@BeforeEach
public void connectClient() throws Exception {

clientContext.connect().get();
}

public <T> ControllerUnderTest<T> createController(final String controllerName) {
Assert.requireNonBlank(controllerName, "controllerName");
Original file line number Diff line number Diff line change
@@ -13,5 +13,6 @@
requires spring.boot.test;
requires static java.servlet;
requires testng;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if testng is no longer used, then please remove it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like me to delete everything relating to testng? Such as the SpringTestNGControllerTest?

requires junit;
requires org.junit.jupiter;

}
Original file line number Diff line number Diff line change
@@ -16,9 +16,10 @@
*/
package dev.rico.server.remoting.test;

import org.junit.Test;

import static org.junit.Assert.*;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

public class JUnitDemoTest extends SpringJUnitControllerTest {

@@ -68,4 +69,5 @@ public void testInvokeActionAfterDestroy() {
fail("Calling an action after destroy should throw an exception!");
} catch (ControllerTestException e) {}
}

}