Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
miyabayt committed Feb 4, 2023
1 parent 90ea282 commit c743d9a
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 48 deletions.
10 changes: 8 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ plugins {
id "groovy"
id "idea"
id "com.github.johnrengelman.shadow" version "7.1.2"
id "io.micronaut.application" version "3.5.3"
id "io.micronaut.application" version "3.6.5"
id "io.micronaut.test-resources" version "3.6.5"
id "com.avast.gradle.docker-compose" version "0.16.9"
id "com.diffplug.spotless" version "${spotlessVersion}"
}
Expand Down Expand Up @@ -90,8 +91,13 @@ dependencies {
implementation "io.swagger.core.v3:swagger-annotations"
implementation "jakarta.annotation:jakarta.annotation-api"

testAnnotationProcessor "io.micronaut:micronaut-inject-java"
testImplementation "org.junit.jupiter:junit-jupiter-api"
testImplementation "io.micronaut.test:micronaut-test-junit5"
testImplementation "io.micronaut.test:micronaut-test-rest-assured"
testImplementation "org.testcontainers:junit-jupiter"
testImplementation "org.testcontainers:r2dbc"
testImplementation "org.testcontainers:mysql"
testImplementation "org.testcontainers:spock"
testImplementation "org.testcontainers:testcontainers"
testImplementation "io.micronaut:micronaut-function"
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version=0.0.1-SNAPSHOT
org.gradle.daemon=false
org.gradle.jvmargs=-Duser.language=ja -Duser.country=JP
micronautVersion=3.6.2
micronautVersion=3.7.4
springSecurityVersion=5.7.3
lombokVersion=1.18.24
spotlessVersion=6.10.0
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.bigtreetc.sample.micronaut.aws.lambda.domain.repository.StaffRepository;
import com.bigtreetc.sample.micronaut.aws.lambda.domain.repository.StaffRoleRepository;
import io.lettuce.core.api.StatefulRedisConnection;
import io.micronaut.runtime.event.annotation.EventListener;
import io.micronaut.scheduling.annotation.Async;
import io.micronaut.security.authentication.Authentication;
import io.micronaut.security.errors.OauthErrorResponseException;
import io.micronaut.security.token.event.RefreshTokenGeneratedEvent;
Expand Down Expand Up @@ -42,8 +42,8 @@ public class RedisRefreshTokenPersistence implements RefreshTokenPersistence {

@Setter private int refreshTokenTimeoutHours = 2;

@Async
@Override
@EventListener
public void persistToken(RefreshTokenGeneratedEvent event) {
if (event != null
&& event.getRefreshToken() != null
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ flyway:
default:
enabled: true
default-schema: micronaut-aws-lambda-rest-sample
url: jdbc:mysql://127.0.0.1:3306/?useSSL=false&characterEncoding=UTF-8
url: jdbc:mysql://127.0.0.1:3306/?allowPublicKeyRetrieval=true&useSSL=false&characterEncoding=UTF-8
driverClassName: com.mysql.cj.jdbc.Driver
username: root
password: passw0rd
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.bigtreetc.sample.micronaut.aws.lambda.controller;

import static org.hamcrest.Matchers.notNullValue;

import io.lettuce.core.RedisClient;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import io.restassured.specification.RequestSpecification;
import jakarta.inject.Inject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

@MicronautTest(transactional = false)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class AuthControllerTest {

@Inject RedisClient redisClient;

@BeforeAll
void beforeAll() {
redisClient.connect();
}

@Test
@DisplayName("認証が通った場合はアクセストークンが返ること")
void testAuth(RequestSpecification spec) {
spec.given()
.formParam("username", "[email protected]")
.formParam("password", "passw0rd")
.when()
.post("/api/auth/login")
.then()
.statusCode(200)
.body("username", notNullValue())
.body("access_token", notNullValue());
}
}
4 changes: 0 additions & 4 deletions src/test/resources/application-function.yml

This file was deleted.

36 changes: 34 additions & 2 deletions src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
datasources:
default:
url: jdbc:tc:mysql:8:///db
driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver
schema-generate: NONE
db-type: mysql
r2dbc:
datasources:
default:
db-type: mysql
flyway:
datasources:
default:
enabled: true
redis:
timeout: 30s
javamail:
authentication:
username: ${SMTP_USERNAME:''}
password: ${SMTP_PASSWORD:''}
properties:
mail:
smtp:
host: 127.0.0.1
port: 1025
logger:
levels:
io.micronaut.data.query: DEBUG

application:
fileUploadLocation: build/sample

test-resources:
containers:
mysql:
image-name: mysql:8
redis:
image-name: redis

0 comments on commit c743d9a

Please sign in to comment.