Skip to content

Commit

Permalink
Switch nrich-webmvc-spring-boot-starter modules dependencies to new n…
Browse files Browse the repository at this point in the history
…rich-logging-spring-boot-starter module and adjust tests
  • Loading branch information
agrancaric committed Apr 26, 2022
1 parent 67a8382 commit 4c3c370
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
3 changes: 2 additions & 1 deletion nrich-webmvc-spring-boot-starter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ dependencies {
annotationProcessor "org.projectlombok:lombok"
compileOnly "org.projectlombok:lombok"

implementation project(":nrich-logging")
implementation project(":nrich-spring-boot")
implementation project(":nrich-webmvc")

runtimeOnly project(":nrich-logging-spring-boot-starter")
runtimeOnly project(":nrich-notification-spring-boot-starter")

implementation "org.springframework.boot:spring-boot-autoconfigure"

testImplementation project(":nrich-logging-spring-boot-starter")
testImplementation project(":nrich-notification-spring-boot-starter")

testRuntimeOnly "ch.qos.logback:logback-classic"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.croz.nrich.webmvc.starter.configuration;

import net.croz.nrich.logging.api.service.LoggingService;
import net.croz.nrich.logging.service.Slf4jLoggingService;
import net.croz.nrich.notification.api.service.BaseNotificationResponseService;
import net.croz.nrich.springboot.condition.ConditionalOnPropertyNotEmpty;
import net.croz.nrich.webmvc.advice.ControllerEditorRegistrationAdvice;
Expand Down Expand Up @@ -51,12 +50,6 @@ public ExceptionHttpStatusResolverService exceptionHttpStatusResolverService(Mes
return new MessageSourceExceptionHttpStatusResolverService(messageSource);
}

@ConditionalOnMissingBean
@Bean
public LoggingService loggingService(MessageSource messageSource) {
return new Slf4jLoggingService(messageSource);
}

@ConditionalOnProperty(name = "nrich.webmvc.controller-advice-enabled", havingValue = "true", matchIfMissing = true)
@Bean
public NotificationErrorHandlingRestControllerAdvice notificationRestControllerAdvice(NrichWebMvcProperties webMvcProperties, BaseNotificationResponseService<?> notificationResponseService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.croz.nrich.webmvc.starter.configuration;

import net.croz.nrich.logging.api.service.LoggingService;
import net.croz.nrich.logging.starter.configuration.NrichLoggingAutoConfiguration;
import net.croz.nrich.notification.starter.configuration.NrichNotificationAutoConfiguration;
import net.croz.nrich.webmvc.advice.ControllerEditorRegistrationAdvice;
import net.croz.nrich.webmvc.advice.NotificationErrorHandlingRestControllerAdvice;
Expand All @@ -18,7 +19,7 @@
class NrichWebMvcAutoConfigurationTest {

private final WebApplicationContextRunner webApplicationContextRunner = new WebApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(NrichNotificationAutoConfiguration.class, NrichWebMvcAutoConfiguration.class));
.withConfiguration(AutoConfigurations.of(NrichLoggingAutoConfiguration.class, NrichNotificationAutoConfiguration.class, NrichWebMvcAutoConfiguration.class));

@Test
void shouldConfigureDefaultConfiguration() {
Expand All @@ -37,18 +38,16 @@ void shouldConfigureDefaultConfiguration() {
@Test
void shouldAddConstrainedLocaleResolverWhenAllowedLocaleListIsNotEmpty() {
// expect
webApplicationContextRunner.withPropertyValues("nrich.webmvc.allowed-locale-list=hr,en")
.withBean(ResourceBundleMessageSource.class).run(context ->
assertThat(context).hasSingleBean(ConstrainedSessionLocaleResolver.class)
);
webApplicationContextRunner.withPropertyValues("nrich.webmvc.allowed-locale-list=hr,en").withBean(ResourceBundleMessageSource.class).run(context ->
assertThat(context).hasSingleBean(ConstrainedSessionLocaleResolver.class)
);
}

@Test
void shouldNotAddAdviceWhenItsDisabled() {
// expect
webApplicationContextRunner.withPropertyValues("nrich.webmvc.controller-advice-enabled=false")
.withBean(ResourceBundleMessageSource.class).run(context ->
assertThat(context).doesNotHaveBean(NotificationErrorHandlingRestControllerAdvice.class)
);
webApplicationContextRunner.withPropertyValues("nrich.webmvc.controller-advice-enabled=false").withBean(ResourceBundleMessageSource.class).run(context ->
assertThat(context).doesNotHaveBean(NotificationErrorHandlingRestControllerAdvice.class)
);
}
}

0 comments on commit 4c3c370

Please sign in to comment.