Skip to content

Commit

Permalink
test : Context test for TargetAnnotations
Browse files Browse the repository at this point in the history
  • Loading branch information
wwan13 committed May 27, 2024
1 parent fa3686b commit e46ae20
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}

0 comments on commit e46ae20

Please sign in to comment.