|
| 1 | +/** |
| 2 | + * Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | + * Licensed under the MIT License. See LICENSE in the project root for |
| 4 | + * license information. |
| 5 | + */ |
| 6 | + |
| 7 | +package com.microsoft.azure.autoconfigure.msgraph; |
| 8 | + |
| 9 | +import com.microsoft.azure.msgraph.api.Microsoft; |
| 10 | +import org.assertj.core.api.Assertions; |
| 11 | +import org.junit.Test; |
| 12 | +import org.springframework.boot.autoconfigure.social.SocialWebAutoConfiguration; |
| 13 | +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; |
| 14 | + |
| 15 | +import static org.assertj.core.api.Java6Assertions.assertThat; |
| 16 | + |
| 17 | +public class MicrosoftAutoConfigurationTest { |
| 18 | + @Test |
| 19 | + public void canAutowire() { |
| 20 | + System.setProperty(Constants.APP_ID_PROPERTY, Constants.APP_ID); |
| 21 | + System.setProperty(Constants.APP_SECRET_PROPERTY, Constants.APP_SECRET); |
| 22 | + |
| 23 | + try (AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext()) { |
| 24 | + context.register(MicrosoftAutoConfiguration.class); |
| 25 | + context.register(SocialWebAutoConfiguration.class); |
| 26 | + context.refresh(); |
| 27 | + Assertions.assertThat(context.getBean(Microsoft.class)).isNotNull(); |
| 28 | + } |
| 29 | + |
| 30 | + System.clearProperty(Constants.APP_ID_PROPERTY); |
| 31 | + System.clearProperty(Constants.APP_SECRET_PROPERTY); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + public void cannotAutowire() { |
| 36 | + try (AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext()) { |
| 37 | + context.register(MicrosoftAutoConfiguration.class); |
| 38 | + context.register(SocialWebAutoConfiguration.class); |
| 39 | + context.refresh(); |
| 40 | + |
| 41 | + Microsoft microsoft = null; |
| 42 | + try { |
| 43 | + microsoft = context.getBean(Microsoft.class); |
| 44 | + } catch (Exception e) { |
| 45 | + assertThat(e.getMessage()).contains("No qualifying bean of type 'com.microsoft.azure." + |
| 46 | + "msgraph.api.Microsoft' available"); |
| 47 | + } |
| 48 | + assertThat(microsoft).isNull(); |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments