Skip to content

Commit

Permalink
Fixed pathes, warnings, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gsteinacker committed Dec 15, 2017
1 parent 4028b59 commit f5603e0
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 76 deletions.
Expand Up @@ -42,7 +42,7 @@ public static Given an_unhealthy_application() {
}

public static When the_internal_health_is_retrieved() throws IOException {
getResource("http://localhost:8084/testcore/application/health", Optional.<String>empty());
getResource("http://localhost:8084/testcore/actuator/health", Optional.<String>empty());
return When.INSTANCE;
}

Expand Down
Expand Up @@ -4,11 +4,11 @@
import org.junit.Test;
import org.springframework.beans.factory.UnsatisfiedDependencyException;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment;

public class LdapConfigurationTest {

Expand All @@ -28,12 +28,13 @@ public void close() {
@Test
public void shouldRegisterLdapFilter() {
this.context.register(EnableAutoConfig.class);
addEnvironment(this.context,
"edison.application.management.base-path=/internal",
"edison.ldap.enabled=true",
"edison.ldap.host=localhost",
"edison.ldap.base-dn=test-dn",
"edison.ldap.rdn-identifier=test-rdn");
TestPropertyValues
.of("edison.application.management.base-path=/internal")
.and("edison.ldap.enabled=true")
.and("edison.ldap.host=localhost")
.and("edison.ldap.base-dn=test-dn")
.and("edison.ldap.rdn-identifier=test-rdn")
.applyTo(context);
this.context.refresh();

assertThat(this.context.containsBean("ldapAuthenticationFilter"), is(true));
Expand All @@ -42,9 +43,10 @@ public void shouldRegisterLdapFilter() {
@Test
public void shouldNotRegisterLdapFilterIfDisabled() {
this.context.register(EnableAutoConfig.class);
addEnvironment(this.context,
"edison.application.management.base-path=/internal",
"edison.ldap.enabled=false");
TestPropertyValues
.of("edison.application.management.base-path=/internal")
.and("edison.ldap.enabled=false")
.applyTo(context);
this.context.refresh();

assertThat(this.context.containsBean("ldapAuthenticationFilter"), is(false));
Expand All @@ -53,9 +55,10 @@ public void shouldNotRegisterLdapFilterIfDisabled() {
@Test(expected = UnsatisfiedDependencyException.class)
public void shouldValidateProperties() {
this.context.register(EnableAutoConfig.class);
addEnvironment(this.context,
"edison.application.management.base-path=/internal",
"edison.ldap.enabled=true");
TestPropertyValues
.of("edison.application.management.base-path=/internal")
.and("edison.ldap.enabled=true")
.applyTo(context);

this.context.refresh();
}
Expand Down
Expand Up @@ -26,31 +26,28 @@ public void shouldHealthyOnStartup() throws Exception {
@Test
public void shouldIndicateErrorWhileShutdown() throws Exception {
// given
GracefulShutdownHealthIndicator gracefulShutdownHealthIndicator = spy(
new GracefulShutdownHealthIndicator(mock(GracefulShutdownProperties.class)));
class TestGracefulShutdownHealthIndicator extends GracefulShutdownHealthIndicator {
boolean waitForShutdownCalled = false;

TestGracefulShutdownHealthIndicator(GracefulShutdownProperties properties) {
super(properties);
}

@Override
void waitForShutdown() throws InterruptedException {
assertThat(health(), is(down().build()));
waitForShutdownCalled = true;
super.waitForShutdown();
}
}
TestGracefulShutdownHealthIndicator gracefulShutdownHealthIndicator =
new TestGracefulShutdownHealthIndicator(mock(GracefulShutdownProperties.class));
Runnable runnable = mock(Runnable.class);

doAnswer(invocation -> {
assertThat(gracefulShutdownHealthIndicator.health(), is(up().build()));
return null;
}).when(gracefulShutdownHealthIndicator).waitForSettingHealthCheckToDown();

doAnswer(invocation -> {
assertThat(gracefulShutdownHealthIndicator.health(), is(down().build()));
return null;
}).when(gracefulShutdownHealthIndicator).waitForShutdown();

// when
gracefulShutdownHealthIndicator.stop(runnable);

// then
InOrder order = inOrder(gracefulShutdownHealthIndicator, runnable);

// on first wait call status should still be OK
order.verify(gracefulShutdownHealthIndicator).waitForSettingHealthCheckToDown();
// on second wait call status should be switched to ERROR
order.verify(gracefulShutdownHealthIndicator).waitForShutdown();
// after second wait call shutdown chain should be executed
order.verify(runnable).run();
assertThat(gracefulShutdownHealthIndicator.waitForShutdownCalled, is(true));
}
}
Expand Up @@ -3,13 +3,13 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment;

public class DisableEndpointPostProcessorTest {

Expand All @@ -36,7 +36,7 @@ public void shouldRegisterBean() {

@Test
public void shouldDisableEndpoint() {
addEnvironment(ctx, "endpoints.someTest.enabled=true");
TestPropertyValues.of("endpoints.someTest.enabled=true").applyTo(ctx);
ctx.register(TestEndpointConfiguration.class);
ctx.register(RemoveTestEndpointConfiguration.class);
ctx.refresh();
Expand Down
Expand Up @@ -2,13 +2,13 @@

import org.junit.After;
import org.junit.Test;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import static de.otto.edison.navigation.NavBarItem.top;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment;

public class NavBarConfigurationTest {

Expand All @@ -23,7 +23,7 @@ public void close() {

@Test
public void shouldHaveRightNavBar() {
addEnvironment(context, "edison.application.management.base-path=/internal");
TestPropertyValues.of("edison.application.management.base-path=/internal").applyTo(context);
context.register(NavBarConfiguration.class);
context.refresh();

Expand Down
@@ -1,16 +1,15 @@
package de.otto.edison.registry.client;

import org.asynchttpclient.AsyncHttpClient;
import de.otto.edison.status.configuration.ApplicationInfoConfiguration;
import org.asynchttpclient.DefaultAsyncHttpClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment;

public class AsyncHttpRegistryClientTest {

Expand All @@ -31,7 +30,7 @@ public void close() {
@Test
public void shouldDoNothingIfNotEnabled() throws Exception {
// given
addEnvironment(context, "edison.serviceregistry.enabled=false");
TestPropertyValues.of("edison.serviceregistry.enabled=false").applyTo(context);
context.register(DefaultAsyncHttpClient.class);
context.register(ApplicationInfoConfiguration.class);
context.register(AsyncHttpRegistryClient.class);
Expand All @@ -47,8 +46,10 @@ public void shouldDoNothingIfNotEnabled() throws Exception {
@Test
public void shouldHaveRegistryIfServersAndServicePresent() throws Exception {
// given
addEnvironment(context, "edison.serviceregistry.servers=http://foo");
addEnvironment(context, "edison.serviceregistry.service=http://test");
TestPropertyValues
.of("edison.serviceregistry.servers=http://foo")
.and("edison.serviceregistry.service=http://test")
.applyTo(context);
context.register(DefaultAsyncHttpClient.class);
context.register(ApplicationInfoConfiguration.class);
context.register(AsyncHttpRegistryClient.class);
Expand All @@ -60,8 +61,10 @@ public void shouldHaveRegistryIfServersAndServicePresent() throws Exception {
@Test
public void shouldDoNothingIfNoServersAreSet() throws Exception {
// given
addEnvironment(context, "edison.serviceregistry.enabled=true");
addEnvironment(context, "edison.serviceregistry.servers=");
TestPropertyValues
.of("edison.serviceregistry.enabled=true")
.and("edison.serviceregistry.servers=")
.applyTo(context);
context.register(DefaultAsyncHttpClient.class);
context.register(ApplicationInfoConfiguration.class);
context.register(AsyncHttpRegistryClient.class);
Expand All @@ -75,8 +78,10 @@ public void shouldDoNothingIfNoServersAreSet() throws Exception {
@Test
public void shouldDoNothingIfNoServiceAreSet() throws Exception {
// given
addEnvironment(context, "edison.serviceregistry.enabled=true");
addEnvironment(context, "edison.serviceregistry.service=");
TestPropertyValues
.of("edison.serviceregistry.enabled=true")
.and("edison.serviceregistry.service=")
.applyTo(context);
context.register(DefaultAsyncHttpClient.class);
context.register(ApplicationInfoConfiguration.class);
context.register(AsyncHttpRegistryClient.class);
Expand All @@ -90,9 +95,11 @@ public void shouldDoNothingIfNoServiceAreSet() throws Exception {
@Test
public void shouldDoNothingIfRegistryDisabled() throws Exception {
// given
addEnvironment(context, "edison.serviceregistry.enabled=false");
addEnvironment(context, "edison.serviceregistry.servers=http://foo");
addEnvironment(context, "edison.serviceregistry.service=http://test");
TestPropertyValues
.of("edison.serviceregistry.enabled=false")
.and("edison.serviceregistry.servers=http://foo")
.and("edison.serviceregistry.service=http://test")
.applyTo(context);
context.register(DefaultAsyncHttpClient.class);
context.register(ApplicationInfoConfiguration.class);
context.register(AsyncHttpRegistryClient.class);
Expand Down
Expand Up @@ -82,8 +82,8 @@ public static void info(final String message) {
/**
* Publishes an event with the given level to all currently running jobs
*
* @param level
* @param message
* @param level the level used to log the message
* @param message the message
* @since 1.1.0
*/
public static void broadcast(final Level level, final String message) {
Expand Down
Expand Up @@ -94,6 +94,7 @@ public class JobStatusCalculator {
* @param numberOfJobs the total number of jobs to take into calculation.
* @param maxFailedJobs the maximum number of jobs that that are accepted to fail.
* @param jobRepository repository to fetch the last {@code numberOfJobs}.
* @param edisonManagementBasePath the base-path used to generate links to the job details
*/
public JobStatusCalculator(final String key,
final int numberOfJobs,
Expand All @@ -116,6 +117,7 @@ public JobStatusCalculator(final String key,
*
* @param key key of the calculator
* @param jobRepository the repository
* @param edisonManagementBasePath the base-path used to generate links to the job details
* @return JobStatusCalculator
*/
public static JobStatusCalculator warningOnLastJobFailed(final String key,
Expand All @@ -131,6 +133,7 @@ public static JobStatusCalculator warningOnLastJobFailed(final String key,
*
* @param key key of the calculator
* @param jobRepository the repository
* @param edisonManagementBasePath the base-path used to generate links to the job details
* @return JobStatusCalculator
*/
public static JobStatusCalculator errorOnLastJobFailed(final String key,
Expand All @@ -147,6 +150,7 @@ public static JobStatusCalculator errorOnLastJobFailed(final String key,
* @param key key of the calculator
* @param numJobs the number of last jobs used to calculate the job status
* @param jobRepository the repository
* @param edisonManagementBasePath the base-path used to generate links to the job details
* @return JobStatusCalculator
*/
public static JobStatusCalculator errorOnLastNumJobsFailed(final String key,
Expand Down
Expand Up @@ -29,8 +29,8 @@ public class TogglzConfiguration {

@Bean
@ConditionalOnMissingBean(name = "togglzFilter")
public FilterRegistrationBean togglzFilter() {
final FilterRegistrationBean filterRegistration = new FilterRegistrationBean();
public FilterRegistrationBean<TogglzFilter> togglzFilter() {
final FilterRegistrationBean<TogglzFilter> filterRegistration = new FilterRegistrationBean<>();
filterRegistration.setFilter(new TogglzFilter());
filterRegistration.addUrlPatterns("/*");
return filterRegistration;
Expand Down
Expand Up @@ -20,12 +20,12 @@ public class TogglzConsoleConfiguration {
public static final String TOGGLES_URL_PATTERN = "/toggles/console/*";

@Bean
public ServletRegistrationBean togglzServlet(final @Value("${edison.application.management.base-path:/internal}") String prefix,
final NavBar rightNavBar) {
public ServletRegistrationBean<?> togglzServlet(final @Value("${edison.application.management.base-path:/internal}") String prefix,
final NavBar rightNavBar) {

// Register Togglz Console in the right "Admin" navigation bar:
rightNavBar.register(navBarItem(bottom(), "Feature Toggles", prefix + "/toggles/console"));
// Register TogglzConsoleServlet:
return new ServletRegistrationBean(new TogglzConsoleServlet(), prefix + TOGGLES_URL_PATTERN);
return new ServletRegistrationBean<>(new TogglzConsoleServlet(), prefix + TOGGLES_URL_PATTERN);
}
}
Expand Up @@ -2,11 +2,11 @@

import org.junit.After;
import org.junit.Test;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment;

public class TogglzConfigurationTest {

Expand All @@ -23,7 +23,7 @@ public void close() {
public void shouldRegisterTogglzConsoleServlet() {
this.context.register(TogglzConfiguration.class);
this.context.register(InMemoryFeatureStateRepositoryConfiguration.class);
addEnvironment(this.context, "edison.application.management.base-path=/internal");
TestPropertyValues.of("edison.application.management.base-path=/internal").applyTo(context);
this.context.refresh();

assertThat(this.context.containsBean("togglzFilter"), is(true));
Expand Down
Expand Up @@ -3,11 +3,11 @@
import de.otto.edison.navigation.NavBarConfiguration;
import org.junit.After;
import org.junit.Test;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.springframework.boot.test.util.EnvironmentTestUtils.addEnvironment;

public class TogglzConsoleConfigurationTest {

Expand All @@ -24,7 +24,7 @@ public void close() {
public void shouldRegisterTogglzConsoleServlet() {
this.context.register(TogglzConsoleConfiguration.class);
this.context.register(NavBarConfiguration.class);
addEnvironment(this.context, "edison.application.management.base-path=/internal");
TestPropertyValues.of("edison.application.management.base-path=/internal").applyTo(context);
this.context.refresh();

assertThat(this.context.containsBean("togglzServlet"), is(true));
Expand All @@ -34,7 +34,7 @@ public void shouldRegisterTogglzConsoleServlet() {
public void shouldNotRegisterTogglzConsoleServletIfDisabled() {
this.context.register(TogglzConsoleConfiguration.class);
this.context.register(NavBarConfiguration.class);
addEnvironment(this.context, "edison.application.management.base-path=/internal", "edison.togglz.console.enabled=false");
TestPropertyValues.of("edison.application.management.base-path=/internal", "edison.togglz.console.enabled=false").applyTo(context);
this.context.refresh();

assertThat(this.context.containsBean("togglzServlet"), is(false));
Expand Down

0 comments on commit f5603e0

Please sign in to comment.