X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Fautoconfigure%2FSimpleMapperServiceAutoConfigurationTest.java;fp=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Fautoconfigure%2FSimpleMapperServiceAutoConfigurationTest.java;h=0000000000000000000000000000000000000000;hb=fd93d60388fecb8ec83dc5c0a411bc1cbe3d1d67;hp=3f9f5f0b0d015e9f0d4cf1ca67e8d26523b3a7a0;hpb=13bc66491ff7d0524655dc01d9c9360e9147abd5;p=simple-mapper diff --git a/src/test/java/de/juplo/autoconfigure/SimpleMapperServiceAutoConfigurationTest.java b/src/test/java/de/juplo/autoconfigure/SimpleMapperServiceAutoConfigurationTest.java deleted file mode 100644 index 3f9f5f0..0000000 --- a/src/test/java/de/juplo/autoconfigure/SimpleMapperServiceAutoConfigurationTest.java +++ /dev/null @@ -1,132 +0,0 @@ -package de.juplo.autoconfigure; - - -import com.fasterxml.jackson.core.JsonFactory; -import de.juplo.jackson.SimpleMapperService; -import static org.junit.Assert.assertEquals; -import org.junit.Test; -import org.springframework.context.annotation.Configuration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.context.annotation.Bean; - - - -public class SimpleMapperServiceAutoConfigurationTest -{ - private final Logger LOG = - LoggerFactory.getLogger(SimpleMapperServiceAutoConfigurationTest.class); - - - @Test - public void emptyConfiguration() - { - LOG.info("<-- Start Of New Test-Case!"); - - ConfigurableApplicationContext context = load(EmptyConfiguration.class); - - SimpleMapperService service = context.getBean(SimpleMapperService.class); - assertNotNull(service); - assertNotNull(service.getFactory()); - JsonFactory factory = context.getBean(JsonFactory.class); - assertNotNull(factory); - assertEquals(factory, service.getFactory()); - - context.close(); - } - - @Test - public void factoryConfigured() - { - LOG.info("<-- Start Of New Test-Case!"); - - ConfigurableApplicationContext context = load(FactoryConfigured.class); - - SimpleMapperService service = context.getBean(SimpleMapperService.class); - assertNotNull(service); - assertNotNull(service.getFactory()); - JsonFactory factory = context.getBean(JsonFactory.class); - assertNotNull(factory); - assertEquals(FactoryConfigured.factory, factory); - assertEquals(factory, service.getFactory()); - - context.close(); - } - - @Test - public void serviceConfigured() - { - LOG.info("<-- Start Of New Test-Case!"); - - ConfigurableApplicationContext context = load(ServiceConfigured.class); - - SimpleMapperService service = context.getBean(SimpleMapperService.class); - assertNotNull(service); - assertNotNull(service.getFactory()); - assertEquals(ServiceConfigured.factory, service.getFactory()); - try - { - context.getBean(JsonFactory.class); - fail("A bean of type JsonFactory was found!"); - } - catch(NoSuchBeanDefinitionException e) - { - LOG.trace("expected exception", e); - } - - context.close(); - } - - - @Configuration - static class EmptyConfiguration - { - } - - @Configuration - static class FactoryConfigured - { - static JsonFactory factory = new JsonFactory(); - - - @Bean - public JsonFactory factory() - { - return factory; - } - } - - @Configuration - static class ServiceConfigured - { - static JsonFactory factory = new JsonFactory(); - static SimpleMapperService service = new SimpleMapperService(factory); - - - @Bean - public SimpleMapperService service() - { - return service; - } - } - - - private ConfigurableApplicationContext load(Class config, String... pairs) - { - AnnotationConfigApplicationContext ctx = - new AnnotationConfigApplicationContext(); - ctx.register(config); - ctx.register(SimpleMapperServiceAutoConfiguration.class); // << Does not work as expected, if the autoconfiguration is registered before the configuration! - AutoConfigurationReportLoggingInitializer report = - new AutoConfigurationReportLoggingInitializer(); - report.initialize(ctx); - ctx.refresh(); - return ctx; - } -}