From e46ae20e7bd3d8c843f54244202c25b8955cf674 Mon Sep 17 00:00:00 2001 From: wwan13 Date: Mon, 27 May 2024 10:50:35 +0900 Subject: [PATCH] test : Context test for TargetAnnotations --- .../context/TargetAnnotationsContextTest.java | 40 +++++++++++++++++++ .../context/config/TestContextConfig.java | 10 +++++ 2 files changed, 50 insertions(+) create mode 100644 src/test/java/io/wwan13/wintersecurity/context/TargetAnnotationsContextTest.java diff --git a/src/test/java/io/wwan13/wintersecurity/context/TargetAnnotationsContextTest.java b/src/test/java/io/wwan13/wintersecurity/context/TargetAnnotationsContextTest.java new file mode 100644 index 0000000..4b6ad5b --- /dev/null +++ b/src/test/java/io/wwan13/wintersecurity/context/TargetAnnotationsContextTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.wwan13.wintersecurity.context; + +import io.wwan13.wintersecurity.ContextTest; +import io.wwan13.wintersecurity.context.config.TestContextConfig; +import io.wwan13.wintersecurity.resolve.TargetAnnotations; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Import; + +import static org.assertj.core.api.Assertions.assertThat; + +@Import(TestContextConfig.class) +public class TargetAnnotationsContextTest extends ContextTest { + + @Autowired + TargetAnnotations targetAnnotations; + + @Test + void should_RegisteredInSpringIocWithEnteredValue_when_ContextLoaded() { + // given, then, then + assertThat(targetAnnotations) + .isInstanceOf(TargetAnnotations.class); + } +} diff --git a/src/test/java/io/wwan13/wintersecurity/context/config/TestContextConfig.java b/src/test/java/io/wwan13/wintersecurity/context/config/TestContextConfig.java index 71386ea..61c4d28 100644 --- a/src/test/java/io/wwan13/wintersecurity/context/config/TestContextConfig.java +++ b/src/test/java/io/wwan13/wintersecurity/context/config/TestContextConfig.java @@ -21,6 +21,9 @@ import io.wwan13.wintersecurity.config.WebSecurityConfigurer; import io.wwan13.wintersecurity.jwt.payload.DefaultPayload; import io.wwan13.wintersecurity.jwt.support.JwtPropertiesRegistry; +import io.wwan13.wintersecurity.resolve.RequestUserId; +import io.wwan13.wintersecurity.resolve.RequestUserRoles; +import io.wwan13.wintersecurity.resolve.support.TargetAnnotationsRegistry; import org.springframework.boot.test.context.TestConfiguration; @TestConfiguration @@ -46,4 +49,11 @@ public void configureJwt(JwtPropertiesRegistry registry) { .payloadClazz(DefaultPayload.class) .subjectClazz(long.class); } + + @Override + public void registerResolveTargets(TargetAnnotationsRegistry registry) { + registry + .addSubjectResolveAnnotation(RequestUserId.class) + .addRolesResolveAnnotation(RequestUserRoles.class); + } }