1 package de.juplo.facebook.errors;
4 import java.util.HashMap;
6 import java.util.Map.Entry;
7 import org.junit.After;
9 import org.springframework.context.annotation.Configuration;
10 import static org.junit.Assert.*;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13 import org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer;
14 import org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration;
15 import org.springframework.context.ConfigurableApplicationContext;
16 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
17 import org.springframework.mock.env.MockEnvironment;
18 import org.springframework.security.oauth2.client.OAuth2RestTemplate;
19 import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
23 public class FacebookErrorsOAuth2AutoConfigurationTest
25 private final Logger LOG =
26 LoggerFactory.getLogger(FacebookErrorsOAuth2AutoConfigurationTest.class);
29 private ConfigurableApplicationContext context;
33 public void tearDown()
35 if (this.context != null)
41 public void defaultNonWebConfiguration()
43 LOG.info("<-- Start Of New Test-Case!");
44 Map<String, String> properties = new HashMap<>();
45 properties.put("security.oauth2.client.client-id", "CLIENT_ID");
46 context = loadNonWebApplicationContext(EmptyConfiguration.class, properties);
47 OAuth2RestTemplate template = context.getBean(OAuth2RestTemplate.class);
48 assertEquals(OAuth2GraphApiErrorHandler.class, template.getErrorHandler().getClass());
52 public void defaultWebConfiguration()
54 LOG.info("<-- Start Of New Test-Case!");
55 Map<String, String> properties = new HashMap<>();
56 properties.put("security.oauth2.client.client-id", "CLIENT_ID");
57 context = loadWebApplicationContext(EmptyConfiguration.class, properties);
58 OAuth2RestTemplate template = context.getBean(OAuth2RestTemplate.class);
59 assertEquals(OAuth2GraphApiErrorHandler.class, template.getErrorHandler().getClass());
64 static class EmptyConfiguration
69 private ConfigurableApplicationContext loadNonWebApplicationContext(
71 Map<String, String> properties
74 AnnotationConfigApplicationContext ctx =
75 new AnnotationConfigApplicationContext();
76 if (properties != null)
78 MockEnvironment env = new MockEnvironment();
79 for (Entry<String, String> entry : properties.entrySet())
80 env.withProperty(entry.getKey(), entry.getValue());
81 ctx.setEnvironment(env);
83 ctx.register(FacebookErrorsOAuth2AutoConfiguration.class);
84 ctx.register(OAuth2AutoConfiguration.class);
86 AutoConfigurationReportLoggingInitializer report =
87 new AutoConfigurationReportLoggingInitializer();
88 report.initialize(ctx);
93 private ConfigurableApplicationContext loadWebApplicationContext(
95 Map<String, String> properties
98 AnnotationConfigWebApplicationContext ctx =
99 new AnnotationConfigWebApplicationContext();
100 if (properties != null)
102 MockEnvironment env = new MockEnvironment();
103 for (Entry<String, String> entry : properties.entrySet())
104 env.withProperty(entry.getKey(), entry.getValue());
105 ctx.setEnvironment(env);
107 ctx.register(FacebookErrorsOAuth2AutoConfiguration.class);
108 ctx.register(OAuth2AutoConfiguration.class);
109 ctx.register(config);
110 AutoConfigurationReportLoggingInitializer report =
111 new AutoConfigurationReportLoggingInitializer();
112 report.initialize(ctx);