Skip to content

Commit 9dc586e

Browse files
committed
[Testing][JShellAPI] Settings up gradle tasks for testing; ;
Note: this includes adding a 1st class for tests;
1 parent daddfe9 commit 9dc586e

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed

Diff for: JShellAPI/build.gradle

+55-3
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,27 @@ dependencies {
1313
implementation 'com.github.docker-java:docker-java-transport-httpclient5:3.3.6'
1414
implementation 'com.github.docker-java:docker-java-core:3.3.6'
1515

16-
testImplementation 'org.springframework.boot:spring-boot-starter-test'
16+
testImplementation('org.springframework.boot:spring-boot-starter-test') {
17+
configurations {
18+
all {
19+
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
20+
exclude group: 'ch.qos.logback', module: 'logback-classic'
21+
exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
22+
}
23+
}
24+
}
25+
testImplementation gradleTestKit()
26+
1727
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
28+
1829
}
1930

31+
def imageName = 'togetherjava.org:5001/togetherjava/jshellbackend:master' ?: 'latest';
32+
2033
jib {
2134
from.image = 'eclipse-temurin:21'
2235
to {
23-
image = 'togetherjava.org:5001/togetherjava/jshellbackend:master' ?: 'latest'
36+
image = imageName
2437
auth {
2538
username = System.getenv('ORG_REGISTRY_USER') ?: ''
2639
password = System.getenv('ORG_REGISTRY_PASSWORD') ?: ''
@@ -36,4 +49,43 @@ shadowJar {
3649
archiveBaseName.set('JShellPlaygroundBackend')
3750
archiveClassifier.set('')
3851
archiveVersion.set('')
39-
}
52+
}
53+
54+
tasks.register('buildDockerImage') {
55+
group = 'Docker'
56+
description = 'builds jshellwrapper as docker image'
57+
dependsOn jibDockerBuild
58+
doFirst{
59+
println('creating docker image...')
60+
}
61+
doLast{
62+
println('docker image is ready for use')
63+
}
64+
}
65+
66+
tasks.register('removeDockerImage', Exec) {
67+
group = 'Docker'
68+
description = 'removes jshellwrapper image'
69+
commandLine 'docker', 'rmi', '-f', imageName
70+
doLast{
71+
println('docker image has been removed')
72+
}
73+
}
74+
75+
tasks.named('test') {
76+
dependsOn tasks.named('buildDockerImage')
77+
78+
doFirst {
79+
try {
80+
println 'Running JShellAPI tests...'
81+
} catch (Exception e) {
82+
println 'JShellAPI tests failed'
83+
tasks.named('removeDockerImage').get().execute()
84+
throw e
85+
}
86+
}
87+
doLast {
88+
println 'JShellAPI tests completed.'
89+
}
90+
finalizedBy tasks.named('removeDockerImage')
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.togetherjava.jshellapi;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
8+
// TODO - write some integrations
9+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
10+
public class JShellApiTests {
11+
12+
@Test
13+
public void test() {
14+
assertThat(true).isTrue();
15+
}
16+
}

0 commit comments

Comments
 (0)