|
| 1 | +/* |
| 2 | + * Copyright 2012-2017 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.autoconfigure.security.oauth2.client; |
| 18 | + |
| 19 | +import org.junit.Rule; |
| 20 | +import org.junit.Test; |
| 21 | +import org.junit.rules.ExpectedException; |
| 22 | + |
| 23 | +import org.springframework.beans.factory.NoSuchBeanDefinitionException; |
| 24 | +import org.springframework.boot.builder.SpringApplicationBuilder; |
| 25 | +import org.springframework.boot.test.util.EnvironmentTestUtils; |
| 26 | +import org.springframework.context.ConfigurableApplicationContext; |
| 27 | +import org.springframework.core.env.ConfigurableEnvironment; |
| 28 | +import org.springframework.core.env.StandardEnvironment; |
| 29 | + |
| 30 | +import static org.assertj.core.api.Assertions.assertThat; |
| 31 | + |
| 32 | +/** |
| 33 | + * Tests for {@link OAuth2RestOperationsConfiguration}. |
| 34 | + * |
| 35 | + * @author Madhura Bhave |
| 36 | + */ |
| 37 | +public class OAuth2RestOperationsConfigurationTests { |
| 38 | + |
| 39 | + private ConfigurableApplicationContext context; |
| 40 | + |
| 41 | + private ConfigurableEnvironment environment = new StandardEnvironment(); |
| 42 | + |
| 43 | + @Rule |
| 44 | + public ExpectedException thrown = ExpectedException.none(); |
| 45 | + |
| 46 | + @Test |
| 47 | + public void clientIdConditionMatches() throws Exception { |
| 48 | + EnvironmentTestUtils.addEnvironment(this.environment, |
| 49 | + "security.oauth2.client.client-id=acme"); |
| 50 | + this.context = new SpringApplicationBuilder(OAuth2RestOperationsConfiguration.class).environment(this.environment).web(false).run(); |
| 51 | + assertThat(this.context.getBean(OAuth2RestOperationsConfiguration.class)).isNotNull(); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + public void clientIdConditionDoesNotMatch() throws Exception { |
| 56 | + this.context = new SpringApplicationBuilder(OAuth2RestOperationsConfiguration.class).environment(this.environment).web(false).run(); |
| 57 | + this.thrown.expect(NoSuchBeanDefinitionException.class); |
| 58 | + this.context.getBean(OAuth2RestOperationsConfiguration.class); |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments