Skip to content

Commit

Permalink
Upgrade test suite to JUnit 5 (#91)
Browse files Browse the repository at this point in the history
* Migrate TemplateTest.java

* Migrate TransloaditTest.java

* Migrate AssemblyTest.java and AssemblyMultiThreadingTest.java

* Migrate OptionsBuilderTest.java

* Migrate RequestTest.java

* Migrate StepsTest.java

* Migrate AssemblyResponseTest.java RequestTest.java

* Update ResponseTest.java

* Update AsyncAssemblyTest.java

* Remove residual imports

* - Remove jUnit4 and its dependencies
 - Add changes to CHANGELOG.md

* Prettify some tests and classes => Linting

* Bump up ridiculously low line limit. It's 2024 not 1994.

* Bump up checkout action's version.

* Apply the newest patches for security reasons.
  • Loading branch information
cdr-chakotay committed Apr 23, 2024
1 parent 4956418 commit 27bdf97
Show file tree
Hide file tree
Showing 18 changed files with 288 additions and 316 deletions.
2 changes: 1 addition & 1 deletion .github/linters/sun_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<module name="FileLength"/>
<module name="LineLength">
<property name="fileExtensions" value="java"/>
<property name="max" value="120"/>
<property name="max" value="150"/>
</module>

<!-- Checks for whitespace -->
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lintChanges.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v2
with:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Unreleased ###
* Migrated test suite from JUnit4 to JUnit 5
* Upgrade okhttp to 4.12.0 as a security update

### 1.0.0 / 2022-12-14 ###
#### Major Release
Warning: This version includes breaking changes and some experimental features, please keep that in mind when using it.
Expand Down
13 changes: 10 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,21 @@ dependencies {
implementation 'org.jetbrains:annotations:23.0.0'
implementation 'io.tus.java.client:tus-java-client:0.4.5'
implementation 'joda-time:joda-time:2.12.2'
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'org.json:json:20231013'
implementation 'commons-codec:commons-codec:1.15'
implementation 'io.socket:socket.io-client:2.1.0'

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mock-server:mockserver-junit-rule:5.15.0'
testImplementation 'org.mock-server:mockserver-junit-jupiter-no-dependencies:5.15.0'
testImplementation 'org.mockito:mockito-core:4.8.0'
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.1'
}

test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}

tasks.register('sourcesJar', Jar) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/transloadit/sdk/Assembly.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.util.UUID;
// CHECKSTYLE:OFF
import io.tus.java.client.TusUploader;
// CHECKTYLE:ON
// CHECKSTYLE:ON


/**
Expand Down Expand Up @@ -819,7 +819,7 @@ protected String obtainUploadUrlSuffix() {
}

/**
* Returns the current Thread List
* Returns the current Thread List.
* @return List of Type TusUploadRunnable
*/
protected ArrayList<TusUploadRunnable> getThreadList() {
Expand Down
33 changes: 15 additions & 18 deletions src/test/java/com/transloadit/sdk/AssemblyMultiThreadingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import com.transloadit.sdk.exceptions.RequestException;
import com.transloadit.sdk.response.AssemblyResponse;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.mockserver.client.MockServerClient;
import org.mockserver.junit.MockServerRule;
import org.mockserver.junit.jupiter.MockServerExtension;
import org.mockserver.junit.jupiter.MockServerSettings;
import org.mockserver.matchers.Times;
import org.mockserver.model.HttpRequest;
import org.mockserver.model.HttpResponse;
Expand All @@ -21,23 +23,18 @@
import java.nio.file.Files;
import java.nio.file.Paths;

import static org.junit.Assert.assertEquals;
import static org.mockserver.model.RegexBody.regex;

/**
* Unit test for the multi threading features of {@link Assembly Assembly.class}.
*/
@ExtendWith(MockServerExtension.class) // MockServerExtension is used to start and stop the MockServer
@MockServerSettings(ports = MockHttpService.PORT) // MockServerSettings is used to define the port of the MockServer
public class AssemblyMultiThreadingTest extends MockHttpService {
/**
* MockServer can be run using the MockServerRule.
*/
@Rule
public MockServerRule mockServerRule = new MockServerRule(this, true, PORT);

/**
* MockServerClient makes HTTP requests to a MockServer instance.
*/
private MockServerClient mockServerClient;
private final MockServerClient mockServerClient = new MockServerClient("localhost", PORT);

/**
* Links to {@link Assembly} instance to perform the tests on.
Expand All @@ -53,7 +50,7 @@ public class AssemblyMultiThreadingTest extends MockHttpService {
* individual test
* and resets the mockServerClient. Also sets {@link AssemblyMultiThreadingTest#assemblyFinished} {@code = false}.
*/
@Before
@BeforeEach
public void setUp() throws Exception {
assembly = new MockTusAssemblyMultiThreading(transloadit);
assembly.wipeAssemblyID();
Expand Down Expand Up @@ -189,8 +186,8 @@ public void onAssemblyResultFinished(String stepName, JSONObject result) {
mockServerClient.verify(HttpRequest.request()
.withPath("/resumable/files").withMethod("POST"), VerificationTimes.atLeast(3));

assertEquals(response.json().get("assembly_id"), "02ce6150ea2811e6a35a8d1e061a5b71");
assertEquals(response.json().get("ok"), "ASSEMBLY_UPLOADING");
Assertions.assertEquals(response.json().get("assembly_id"), "02ce6150ea2811e6a35a8d1e061a5b71");
Assertions.assertEquals(response.json().get("ok"), "ASSEMBLY_UPLOADING");
}

/**
Expand Down Expand Up @@ -246,7 +243,7 @@ public void onAssemblyResultFinished(String stepName, JSONObject result) {
}
};
assembly.setRunnableAssemblyListener(listener);
assertEquals(listener, assembly.getRunnableAssemblyListener());
Assertions.assertEquals(listener, assembly.getRunnableAssemblyListener());
}

/**
Expand Down Expand Up @@ -286,7 +283,7 @@ public void abortUploads() throws LocalOperationException, RequestException, IOE
Mockito.verify(spyListener).onError(exceptionArgumentCaptor.capture());
String errorMessage = "Uploads aborted";
String exceptionMessage = exceptionArgumentCaptor.getValue().getMessage();
assertEquals(exceptionMessage, errorMessage);
Assertions.assertEquals(exceptionMessage, errorMessage);
}

/**
Expand All @@ -300,7 +297,7 @@ public void pauseUploads() throws IOException, LocalOperationException, RequestE


String uploadSize = "" + new File("LICENSE").length();
assertEquals(uploadSize, "1077"); // verify, that test sizes can work
Assertions.assertEquals(uploadSize, "1077"); // verify, that test sizes can work
String uploadChunkSize = "1";
assembly = new MockTusAssemblyMultiThreading(transloadit);
assembly.wipeAssemblyID();
Expand Down
Loading

0 comments on commit 27bdf97

Please sign in to comment.