Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test-suite-serde-java library #910

Draft
wants to merge 1 commit into
base: 5.0.x
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ include "security-session"
include "security-ldap"
include "security-oauth2"

include "test-suite-serde-java"
include "test-suite-groovy"
include "test-suite"
include "test-suite-utils"
Expand Down
2 changes: 1 addition & 1 deletion test-suite-groovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies {
testImplementation("org.spockframework:spock-core:${spockVersion}") {
exclude module:'groovy-all'
}
runtimeOnly("ch.qos.logback:logback-classic")
testRuntimeOnly("ch.qos.logback:logback-classic")
testImplementation "io.micronaut.test:micronaut-test-spock:$micronautTestVersion"
testImplementation "io.micronaut:micronaut-management"
testImplementation "io.micronaut:micronaut-http-server-netty"
Expand Down
42 changes: 42 additions & 0 deletions test-suite-serde-java/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
plugins {
id 'java-library'
}
repositories {
mavenCentral()
}

dependencies {
testAnnotationProcessor(platform("io.micronaut:micronaut-bom:$micronautVersion"))
testAnnotationProcessor "io.micronaut:micronaut-inject-java"
testAnnotationProcessor("io.micronaut:micronaut-validation")
testAnnotationProcessor("io.micronaut.serde:micronaut-serde-processor:$serdeVersion")
testImplementation(platform("io.micronaut:micronaut-bom:$micronautVersion"))
testImplementation("io.micronaut:micronaut-validation")

testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation "io.micronaut.test:micronaut-test-junit5"
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")

testRuntimeOnly("ch.qos.logback:logback-classic")

testImplementation("io.micronaut:micronaut-http-server-netty")
testImplementation("io.micronaut:micronaut-http-client")
testImplementation project(":security-jwt")
}

tasks.named('test') {
useJUnitPlatform()
}

java {
sourceCompatibility = JavaVersion.toVersion("1.8")
targetCompatibility = JavaVersion.toVersion("1.8")
}


configurations.all {
resolutionStrategy.dependencySubstitution {
substitute(module("io.micronaut:micronaut-jackson-databind"))
.using(module("io.micronaut.serde:micronaut-serde-jackson:$serdeVersion"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.micronaut.security.serdetests;

import io.micronaut.context.annotation.Property;
import io.micronaut.context.annotation.Requires;
import io.micronaut.core.util.StringUtils;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.client.BlockingHttpClient;
import io.micronaut.http.client.HttpClient;
import io.micronaut.http.client.annotation.Client;
import io.micronaut.security.annotation.Secured;
import io.micronaut.security.rules.SecurityRule;
import io.micronaut.security.token.jwt.render.AccessRefreshToken;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import jakarta.annotation.security.PermitAll;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@Property(name = "spec.name", value = "AccessRefreshTokenSerdeSpec")
@Property(name = "micronaut.security.reject-not-found", value = StringUtils.FALSE)
@MicronautTest
public class AccessRefreshTokenSerdeSpec {
@Inject
@Client("/")
HttpClient httpClient;

@Test
void accessRefreshTokenIsSerdeable() {
BlockingHttpClient client = httpClient.toBlocking();
String json = client.retrieve(HttpRequest.GET("/accessRefreshToken"));
assertNotNull(json);
assertEquals("{\"access_token\":\"xxx.yyy.zzz\",\"refresh_token\":\"zzzzooouuu\",\"token_type\":\"Bearer\",\"expires_in\":3600}", json);
}

@Requires(property = "spec.name", value = "AccessRefreshTokenSerdeSpec")
@Controller("/accessRefreshToken")
@Secured(SecurityRule.IS_ANONYMOUS)
static class AccessRefreshTokenSerdeController {

@Get
AccessRefreshToken index() {
return new AccessRefreshToken("xxx.yyy.zzz", "zzzzooouuu", "Bearer", 3600);
}
}
}
10 changes: 10 additions & 0 deletions test-suite-serde-java/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>