|
| 1 | +package org.springframework.security.oauth2.client.jackson2; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.databind.JsonNode; |
| 4 | +import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
| 5 | +import com.fasterxml.jackson.databind.node.ObjectNode; |
| 6 | +import com.fasterxml.jackson.databind.util.StdConverter; |
| 7 | +import org.junit.jupiter.params.ParameterizedTest; |
| 8 | +import org.junit.jupiter.params.provider.Arguments; |
| 9 | +import org.junit.jupiter.params.provider.MethodSource; |
| 10 | +import org.springframework.security.oauth2.core.ClientAuthenticationMethod; |
| 11 | + |
| 12 | +import java.util.stream.Stream; |
| 13 | + |
| 14 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 15 | + |
| 16 | +public class StdConvertersTest { |
| 17 | + |
| 18 | + private final StdConverter<JsonNode, ClientAuthenticationMethod> clientAuthenticationMethodConverter = |
| 19 | + new StdConverters.ClientAuthenticationMethodConverter(); |
| 20 | + |
| 21 | + @ParameterizedTest |
| 22 | + @MethodSource("testClientAuthenticationMethodConverting") |
| 23 | + void testClientAuthenticationMethodConverting(String clientAuthenticationMethod) { |
| 24 | + ObjectNode jsonNode = JsonNodeFactory.instance.objectNode(); |
| 25 | + jsonNode.put("value", clientAuthenticationMethod); |
| 26 | + ClientAuthenticationMethod actual = this.clientAuthenticationMethodConverter.convert(jsonNode); |
| 27 | + assertEquals(clientAuthenticationMethod, actual.getValue()); |
| 28 | + |
| 29 | + } |
| 30 | + |
| 31 | + static Stream<Arguments> testClientAuthenticationMethodConverting() { |
| 32 | + return Stream.of( |
| 33 | + Arguments.of(ClientAuthenticationMethod.CLIENT_SECRET_BASIC.getValue()), |
| 34 | + Arguments.of(ClientAuthenticationMethod.CLIENT_SECRET_POST.getValue()), |
| 35 | + Arguments.of(ClientAuthenticationMethod.PRIVATE_KEY_JWT.getValue()), |
| 36 | + Arguments.of(ClientAuthenticationMethod.NONE.getValue()), |
| 37 | + Arguments.of("custom_method") |
| 38 | + ); |
| 39 | + } |
| 40 | +} |
0 commit comments