--- /dev/null
+package de.juplo.facebook.errors;
+
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import org.junit.After;
+import org.junit.Test;
+import org.springframework.context.annotation.Configuration;
+import static org.junit.Assert.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer;
+import org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.mock.env.MockEnvironment;
+import org.springframework.security.oauth2.client.OAuth2RestTemplate;
+import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+
+
+
+public class FacebookErrorsOAuth2AutoConfigurationTest
+{
+ private final Logger LOG =
+ LoggerFactory.getLogger(FacebookErrorsOAuth2AutoConfigurationTest.class);
+
+
+ private ConfigurableApplicationContext context;
+
+
+ @After
+ public void tearDown()
+ {
+ if (this.context != null)
+ this.context.close();
+ }
+
+
+ @Test
+ public void defaultNonWebConfiguration()
+ {
+ LOG.info("<-- Start Of New Test-Case!");
+ Map<String, String> properties = new HashMap<>();
+ properties.put("security.oauth2.client.client-id", "CLIENT_ID");
+ context = loadNonWebApplicationContext(EmptyConfiguration.class, properties);
+ OAuth2RestTemplate template = context.getBean(OAuth2RestTemplate.class);
+ assertEquals(OAuth2GraphApiErrorHandler.class, template.getErrorHandler().getClass());
+ }
+
+ @Test
+ public void defaultWebConfiguration()
+ {
+ LOG.info("<-- Start Of New Test-Case!");
+ Map<String, String> properties = new HashMap<>();
+ properties.put("security.oauth2.client.client-id", "CLIENT_ID");
+ context = loadWebApplicationContext(EmptyConfiguration.class, properties);
+ OAuth2RestTemplate template = context.getBean(OAuth2RestTemplate.class);
+ assertEquals(OAuth2GraphApiErrorHandler.class, template.getErrorHandler().getClass());
+ }
+
+
+ @Configuration
+ static class EmptyConfiguration
+ {
+ }
+
+
+ private ConfigurableApplicationContext loadNonWebApplicationContext(
+ Class<?> config,
+ Map<String, String> properties
+ )
+ {
+ AnnotationConfigApplicationContext ctx =
+ new AnnotationConfigApplicationContext();
+ if (properties != null)
+ {
+ MockEnvironment env = new MockEnvironment();
+ for (Entry<String, String> entry : properties.entrySet())
+ env.withProperty(entry.getKey(), entry.getValue());
+ ctx.setEnvironment(env);
+ }
+ ctx.register(FacebookErrorsOAuth2AutoConfiguration.class);
+ ctx.register(OAuth2AutoConfiguration.class);
+ ctx.register(config);
+ AutoConfigurationReportLoggingInitializer report =
+ new AutoConfigurationReportLoggingInitializer();
+ report.initialize(ctx);
+ ctx.refresh();
+ return ctx;
+ }
+
+ private ConfigurableApplicationContext loadWebApplicationContext(
+ Class<?> config,
+ Map<String, String> properties
+ )
+ {
+ AnnotationConfigWebApplicationContext ctx =
+ new AnnotationConfigWebApplicationContext();
+ if (properties != null)
+ {
+ MockEnvironment env = new MockEnvironment();
+ for (Entry<String, String> entry : properties.entrySet())
+ env.withProperty(entry.getKey(), entry.getValue());
+ ctx.setEnvironment(env);
+ }
+ ctx.register(FacebookErrorsOAuth2AutoConfiguration.class);
+ ctx.register(OAuth2AutoConfiguration.class);
+ ctx.register(config);
+ AutoConfigurationReportLoggingInitializer report =
+ new AutoConfigurationReportLoggingInitializer();
+ report.initialize(ctx);
+ ctx.refresh();
+ return ctx;
+ }
+}