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
Show file tree
Hide file tree
Changes from 8 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
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ subprojects { proj ->
// }

test {
useTestNG()
useJUnitPlatform()
//useTestNG()
rubyAnneB marked this conversation as resolved.
Show resolved Hide resolved
jvmArgs("-Djdk.attach.allowAttachSelf")
testLogging.showStandardStreams = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ dependencies {
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:5.7.0")
rubyAnneB marked this conversation as resolved.
Show resolved Hide resolved
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.7.0")

compile 'org.junit.jupiter:junit-jupiter:5.7.0'
compile("org.junit.jupiter:junit-jupiter-engine:5.7.0")

implementation "org.springframework:spring-web:$springVersion"
implementation "org.springframework:spring-context:$springVersion"
implementation "org.springframework:spring-test:$springVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static <T> ControllerUnderTest<T> createController(final TestClientContex
final ControllerProxy<T> proxy = (ControllerProxy<T>) clientContext.createController(controllerName, parameters).get();
return new ControllerUnderTestWrapper<>(clientContext, proxy);
} catch (Exception e) {
e.printStackTrace();
rubyAnneB marked this conversation as resolved.
Show resolved Hide resolved
throw new ControllerTestException("Can't create controller proxy", e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,57 +21,66 @@
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 {
rubyAnneB marked this conversation as resolved.
Show resolved Hide resolved

@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");
try {
return ClientTestFactory.createController(clientContext, controllerName);
return ClientTestFactory.createController(clientContext, controllerName);
rubyAnneB marked this conversation as resolved.
Show resolved Hide resolved
} catch (Exception e) {
throw new ControllerTestException("Can't create controller proxy", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@
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;

//adding junit 5 to the module
rubyAnneB marked this conversation as resolved.
Show resolved Hide resolved
requires org.junit.jupiter;


}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
*/
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.*;
rubyAnneB marked this conversation as resolved.
Show resolved Hide resolved

public class JUnitDemoTest extends SpringJUnitControllerTest {

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

rubyAnneB marked this conversation as resolved.
Show resolved Hide resolved


}