diff --git a/JShellAPI/build.gradle b/JShellAPI/build.gradle index 7a2380b..9314dec 100644 --- a/JShellAPI/build.gradle +++ b/JShellAPI/build.gradle @@ -13,14 +13,27 @@ dependencies { implementation 'com.github.docker-java:docker-java-transport-httpclient5:3.3.6' implementation 'com.github.docker-java:docker-java-core:3.3.6' - testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation('org.springframework.boot:spring-boot-starter-test') { + configurations { + all { + exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' + exclude group: 'ch.qos.logback', module: 'logback-classic' + exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j' + } + } + } + testImplementation gradleTestKit() + annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" + } +def imageName = 'togetherjava.org:5001/togetherjava/jshellbackend:master' ?: 'latest'; + jib { from.image = 'eclipse-temurin:21' to { - image = 'togetherjava.org:5001/togetherjava/jshellbackend:master' ?: 'latest' + image = imageName auth { username = System.getenv('ORG_REGISTRY_USER') ?: '' password = System.getenv('ORG_REGISTRY_PASSWORD') ?: '' @@ -36,4 +49,43 @@ shadowJar { archiveBaseName.set('JShellPlaygroundBackend') archiveClassifier.set('') archiveVersion.set('') -} \ No newline at end of file +} + +tasks.register('buildDockerImage') { + group = 'Docker' + description = 'builds jshellwrapper as docker image' + dependsOn jibDockerBuild + doFirst{ + println('creating docker image...') + } + doLast{ + println('docker image is ready for use') + } +} + +tasks.register('removeDockerImage', Exec) { + group = 'Docker' + description = 'removes jshellwrapper image' + commandLine 'docker', 'rmi', '-f', imageName + doLast{ + println('docker image has been removed') + } +} + +tasks.named('test') { + dependsOn tasks.named('buildDockerImage') + + doFirst { + try { + println 'Running JShellAPI tests...' + } catch (Exception e) { + println 'JShellAPI tests failed' + tasks.named('removeDockerImage').get().execute() + throw e + } + } + doLast { + println 'JShellAPI tests completed.' + } + finalizedBy tasks.named('removeDockerImage') +} diff --git a/JShellAPI/src/test/java/org/togetherjava/jshellapi/JShellApiTests.java b/JShellAPI/src/test/java/org/togetherjava/jshellapi/JShellApiTests.java new file mode 100644 index 0000000..57254a5 --- /dev/null +++ b/JShellAPI/src/test/java/org/togetherjava/jshellapi/JShellApiTests.java @@ -0,0 +1,16 @@ +package org.togetherjava.jshellapi; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.assertj.core.api.Assertions.assertThat; + +// TODO - write some integrations +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class JShellApiTests { + + @Test + public void test() { + assertThat(true).isTrue(); + } +}