下面列出了怎么用org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration的API类实例代码及写法,或者点击链接到github查看源代码。
@Before
public void setUp() {
contextRunner = new ApplicationContextRunner()
.withPropertyValues(
"mail.smtp.host="+ServerSetupTest.SMTP.getBindAddress(),
"mail.smtp.port="+ServerSetupTest.SMTP.getPort(),
"ogham.sms.smpp.host=127.0.0.1",
"ogham.sms.smpp.port="+smppServer.getPort(),
"spring.freemarker.suffix=")
.withConfiguration(of(TestConfig.class, ThymeleafAutoConfiguration.class, FreeMarkerAutoConfiguration.class, OghamSpringBoot2AutoConfiguration.class));
}
@Before
public void setUp() {
contextRunner = new ApplicationContextRunner()
.withPropertyValues(
"mail.smtp.host="+ServerSetupTest.SMTP.getBindAddress(),
"mail.smtp.port="+ServerSetupTest.SMTP.getPort(),
"ogham.sms.smpp.host=127.0.0.1",
"ogham.sms.smpp.port="+smppServer.getPort(),
"spring.freemarker.suffix=")
.withConfiguration(of(FreeMarkerAutoConfiguration.class, OghamSpringBoot2AutoConfiguration.class));
}
@Test
public void oghamWithFreemarkerAutoConfigWithoutWebContextShouldUseSpringFreemarkerConfiguration() throws Exception {
contextRunner = contextRunner.withConfiguration(of(FreeMarkerAutoConfiguration.class, OghamSpringBoot2AutoConfiguration.class));
contextRunner.run((context) -> {
MessagingService messagingService = context.getBean(MessagingService.class);
checkEmail(messagingService);
checkSms(messagingService);
OghamInternalAssertions.assertThat(messagingService)
.freemarker()
.all()
.configuration()
.defaultEncoding(equalTo(StandardCharsets.UTF_16BE.name()));
});
}
@Test
public void oghamWithFreemarkerAutoConfigInWebContextShouldUseSpringFreemarkerConfiguration() throws Exception {
contextRunner = contextRunner.withConfiguration(of(WebMvcAutoConfiguration.class, FreeMarkerAutoConfiguration.class, OghamSpringBoot2AutoConfiguration.class));
contextRunner.run((context) -> {
MessagingService messagingService = context.getBean(MessagingService.class);
checkEmail(messagingService);
checkSms(messagingService);
OghamInternalAssertions.assertThat(messagingService)
.freemarker()
.all()
.configuration()
.defaultEncoding(equalTo(StandardCharsets.UTF_16BE.name()));
});
}
@Test
public void oghamWithFreemarkerAutoConfigWithoutWebContextAndOghamPropertiesShouldUseSpringFreemarkerConfigurationAndOghamProperties() throws Exception {
contextRunner = contextRunner.withConfiguration(of(FreeMarkerAutoConfiguration.class, OghamSpringBoot2AutoConfiguration.class))
.withPropertyValues("ogham.freemarker.default-encoding="+StandardCharsets.US_ASCII.name());
contextRunner.run((context) -> {
MessagingService messagingService = context.getBean(MessagingService.class);
checkEmail(messagingService);
checkSms(messagingService);
OghamInternalAssertions.assertThat(messagingService)
.freemarker()
.all()
.configuration()
.defaultEncoding(equalTo(StandardCharsets.US_ASCII.name()));
});
}
@Test
public void oghamWithFreemarkerAutoConfigInWebContextAndOghamPropertiesShouldUseSpringFreemarkerConfigurationAndOghamProperties() throws Exception {
contextRunner = contextRunner.withConfiguration(of(WebMvcAutoConfiguration.class, FreeMarkerAutoConfiguration.class, OghamSpringBoot2AutoConfiguration.class))
.withPropertyValues("ogham.freemarker.default-encoding="+StandardCharsets.US_ASCII.name());
contextRunner.run((context) -> {
MessagingService messagingService = context.getBean(MessagingService.class);
checkEmail(messagingService);
checkSms(messagingService);
OghamInternalAssertions.assertThat(messagingService)
.freemarker()
.all()
.configuration()
.defaultEncoding(equalTo(StandardCharsets.US_ASCII.name()));
});
}
@Test
public void oghamWithFreemarkerAutoConfigWithoutWebContextShouldUseSpringFreemarkerConfiguration() throws Exception {
context.register(FreeMarkerAutoConfiguration.class, OghamSpringBoot1AutoConfiguration.class);
context.refresh();
MessagingService messagingService = context.getBean(MessagingService.class);
checkEmail(messagingService);
checkSms(messagingService);
OghamInternalAssertions.assertThat(messagingService)
.freemarker()
.all()
.configuration()
.defaultEncoding(equalTo(StandardCharsets.UTF_16BE.name()));
}
@Test
public void oghamWithFreemarkerAutoConfigInWebContextShouldUseSpringFreemarkerConfiguration() throws Exception {
context.register(WebMvcAutoConfiguration.class, FreeMarkerAutoConfiguration.class, OghamSpringBoot1AutoConfiguration.class);
context.refresh();
MessagingService messagingService = context.getBean(MessagingService.class);
checkEmail(messagingService);
checkSms(messagingService);
OghamInternalAssertions.assertThat(messagingService)
.freemarker()
.all()
.configuration()
.defaultEncoding(equalTo(StandardCharsets.UTF_16BE.name()));
}
@Test
public void oghamWithFreemarkerAutoConfigWithoutWebContextAndOghamPropertiesShouldUseSpringFreemarkerConfigurationAndOghamProperties() throws Exception {
EnvironmentTestUtils.addEnvironment(context, "ogham.freemarker.default-encoding="+StandardCharsets.US_ASCII.name());
context.register(FreeMarkerAutoConfiguration.class, OghamSpringBoot1AutoConfiguration.class);
context.refresh();
MessagingService messagingService = context.getBean(MessagingService.class);
checkEmail(messagingService);
checkSms(messagingService);
OghamInternalAssertions.assertThat(messagingService)
.freemarker()
.all()
.configuration()
.defaultEncoding(equalTo(StandardCharsets.US_ASCII.name()));
}
@Test
public void oghamWithFreemarkerAutoConfigInWebContextAndOghamPropertiesShouldUseSpringFreemarkerConfigurationAndOghamProperties() throws Exception {
EnvironmentTestUtils.addEnvironment(context, "ogham.freemarker.default-encoding="+StandardCharsets.US_ASCII.name());
context.register(WebMvcAutoConfiguration.class, FreeMarkerAutoConfiguration.class, OghamSpringBoot1AutoConfiguration.class);
context.refresh();
MessagingService messagingService = context.getBean(MessagingService.class);
checkEmail(messagingService);
checkSms(messagingService);
OghamInternalAssertions.assertThat(messagingService)
.freemarker()
.all()
.configuration()
.defaultEncoding(equalTo(StandardCharsets.US_ASCII.name()));
}
@Before
public void setUp() {
context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"mail.smtp.host="+ServerSetupTest.SMTP.getBindAddress(),
"mail.smtp.port="+ServerSetupTest.SMTP.getPort(),
"ogham.sms.smpp.host=127.0.0.1",
"ogham.sms.smpp.port="+smppServer.getPort(),
"spring.freemarker.suffix=");
context.register( FreeMarkerAutoConfiguration.class, OghamSpringBoot1AutoConfiguration.class);
context.refresh();
messagingService = context.getBean(MessagingService.class);
}
@Before
public void setUp() {
context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(context,
"mail.smtp.host="+ServerSetupTest.SMTP.getBindAddress(),
"mail.smtp.port="+ServerSetupTest.SMTP.getPort(),
"ogham.sms.smpp.host=127.0.0.1",
"ogham.sms.smpp.port="+smppServer.getPort(),
"spring.freemarker.suffix=");
context.register(TestConfig.class, ThymeleafAutoConfiguration.class, FreeMarkerAutoConfiguration.class, OghamSpringBoot1AutoConfiguration.class);
context.refresh();
messagingService = context.getBean(MessagingService.class);
}