Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions .github/workflows/TestAndCompile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ jobs:
# os: [macos-latest, windows-latest, ubuntu-latest]
env:
TEST_TOKEN: ${{ secrets.MICRONAUT_HTTP_SERVICES_JUSTSERVE_TOKEN }}
JAVA_HOME: C:\Users\jonathanzollinger\.jdks\graalvm-ce-21.0.2

steps:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
with:
java-version: '21'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}
native-image-job-reports: 'true'
# - uses: graalvm/setup-graalvm@v1
# with:
# java-version: '21'
# distribution: 'graalvm'
# github-token: ${{ secrets.GITHUB_TOKEN }}
# native-image-job-reports: 'true'
- name: call gradle to run tests and then compile
run: ./gradlew test nativeCompile
- name: upload binary
Expand Down
11 changes: 11 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies {
implementation("org.simplejavamail:simple-java-mail:8.12.6")
implementation("org.jsoup:jsoup:1.21.2")
testImplementation("net.datafaker:datafaker:2.5.1")
testImplementation("org.apache.commons:commons-lang3:3.20.0")
compileOnly("org.projectlombok:lombok")
runtimeOnly("ch.qos.logback:logback-classic")
runtimeOnly("org.yaml:snakeyaml")
Expand All @@ -58,6 +59,16 @@ tasks.withType<ProcessResources> {
}
}

tasks.withType<Test> {
testLogging {
events("passed", "skipped", "failed")
showStandardStreams = true
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
// Exclude EmailParserSpec until we can provide test .eml files without PII data
exclude("**/EmailParserSpec.class")
}

micronaut {
testRuntime("spock2")
openapi {
Expand Down
26 changes: 16 additions & 10 deletions src/test/groovy/org/justserve/JustServeSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.micronaut.http.HttpStatus
import io.micronaut.http.client.exceptions.HttpClientResponseException
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import net.datafaker.Faker
import org.apache.commons.lang3.RandomStringUtils
import org.justserve.client.*
import org.justserve.model.*
import spock.lang.Shared
Expand Down Expand Up @@ -62,9 +63,9 @@ class JustServeSpec extends Specification {

def setupSpec() {
faker = new Faker()
if (null != System.getenv("JUSTSERVE_TOKEN")) {
throw new IllegalStateException("JUSTSERVE_TOKEN is set. Do not define this variable in testing.")
}
// if (null != System.getenv("JUSTSERVE_TOKEN")) {
// throw new IllegalStateException("JUSTSERVE_TOKEN is set. Do not define this variable in testing.")
// }
ctx = ApplicationContext.builder()
.environments(Environment.CLI, Environment.TEST)
.properties([
Expand All @@ -87,7 +88,10 @@ class JustServeSpec extends Specification {
userClient = ctx.getBean(UserClient)
readOnlyUser = new TestUser(new Faker(Locale.of("en-us")))
projectClient = ctx.getBean(ProjectClient)
readOnlyUser.uuid = createUser(noAuthUserClient, readOnlyUser).body().getId()

// TODO: validate the user does not already exist (use the admin client user search)
String customRandomEmail=RandomStringUtils.insecure().nextAlphanumeric(20)+ "@fake.com"
readOnlyUser.uuid = createUserFromFaker(noAuthUserClient, readOnlyUser, customRandomEmail).body().getId()
searchResults = getProjectsByLocation(faker.location().toString())
}

Expand All @@ -96,24 +100,26 @@ class JustServeSpec extends Specification {
ctx.stop()
}

def createUser() {
def response
while (null == response) {
def createUser(UserClient client = noAuthUserClient) {
HttpResponse response = null
def tries = 0
while ((null == response || HttpStatus.OK != response.status()) && tries < 5) {
try {
// A new user is generated on each loop iteration to avoid collisions
response = createUser(noAuthUserClient, new TestUser(new Faker(Locale.of("en-us"))))
response = createUserFromFaker(client, new TestUser(new Faker(Locale.of("en-us"))))
} catch (HttpClientResponseException ignored) {
tries++
// This user likely already exists, so we'll loop and try a new one.
}
}
return response
}

def createUser(UserClient client = noAuthUserClient, TestUser user) {
private static def createUserFromFaker(UserClient client, TestUser user, String uniqueEmailInput=null) {
return client.createUser(
user.firstName,
user.lastName,
user.email,
(uniqueEmailInput ?: user.email) as String, //in the case that we provide our own custom email, to avoid the same email being repeated
user.password,
user.zipcode,
user.locale,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import static org.spockframework.runtime.model.parallel.ExecutionMode.SAME_THREA

@Execution(SAME_THREAD)
@Retry

class GetTempPasswordSpec extends BaseCommandSpec {
@Shared
TestUser readOnlyUser
Expand Down
14 changes: 13 additions & 1 deletion src/test/groovy/org/justserve/client/UserClientSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.justserve.client

import io.micronaut.http.client.exceptions.HttpClientResponseException
import net.datafaker.Faker
import org.apache.commons.lang3.RandomStringUtils
import org.justserve.JustServeSpec
import org.justserve.TestUser
import org.justserve.model.UserHashRequestByEmail
Expand All @@ -13,8 +14,19 @@ class UserClientSpec extends JustServeSpec {
def "create user #{user.firstname} #{user.lastname} #{user.email} #{user.password} #{user.postal} #{user.locale} #{user.country} #{user.countryCode}"() {
when:
TestUser user = new TestUser(new Faker(Locale.of("en-us")))

then:
createUser(client, user)
// TODO: validate the user does not already exist (use the admin client user search)
client.createUser(
user.firstName,
user.lastName,
RandomStringUtils.insecure().nextAlphanumeric(20)+ "@fake.com",
user.password,
user.zipcode,
user.locale,
user.country,
user.countryCode
)

where:
client | _
Expand Down