Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule;
import lombok.Getter;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;
Expand All @@ -36,6 +37,7 @@

import static org.assertj.core.api.Assertions.assertThat;

@Getter
public abstract class AbstractAdminApplicationTest {

private WebTestClient webClient;
Expand Down Expand Up @@ -153,12 +155,4 @@ protected WebTestClient createWebClient(int port) {
.build();
}

public int getPort() {
return this.port;
}

public WebTestClient getWebClient() {
return this.webClient;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
*
* @author Dennis Schulte
*/
public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest {
class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest {

private ConfigurableApplicationContext instance1;

Expand All @@ -64,7 +64,7 @@ public class AdminApplicationHazelcastTest extends AbstractAdminApplicationTest
private WebTestClient webClient2;

@BeforeEach
public void setUp() {
void setUp() {
System.setProperty("hazelcast.wait.seconds.before.join", "0");
this.instance1 = new SpringApplicationBuilder().sources(TestAdminApplication.class)
.web(WebApplicationType.REACTIVE)
Expand Down Expand Up @@ -114,7 +114,7 @@ public void lifecycle() {
}

@AfterEach
public void shutdown() {
void shutdown() {
this.instance1.close();
this.instance2.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class AdminReactiveApplicationTest extends AbstractAdminApplicationTest {
private ConfigurableApplicationContext instance;

@BeforeEach
public void setUp() {
void setUp() {
this.instance = new SpringApplicationBuilder().sources(TestAdminApplication.class)
.web(WebApplicationType.REACTIVE)
.run("--server.port=0", "--management.endpoints.web.base-path=/mgmt",
Expand All @@ -45,7 +45,7 @@ public void setUp() {
}

@AfterEach
public void shutdown() {
void shutdown() {
this.instance.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class AdminServletApplicationTest extends AbstractAdminApplicationTest {
private ConfigurableApplicationContext instance;

@BeforeEach
public void setUp() {
void setUp() {
this.instance = new SpringApplicationBuilder().sources(TestAdminApplication.class)
.web(WebApplicationType.SERVLET)
.run("--server.port=0", "--management.endpoints.web.base-path=/mgmt",
Expand All @@ -46,7 +46,7 @@ public void setUp() {
}

@AfterEach
public void shutdown() {
void shutdown() {
this.instance.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.time.Duration;

import lombok.Getter;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import org.slf4j.Logger;
Expand All @@ -34,11 +35,11 @@
import de.codecentric.boot.admin.server.domain.values.InstanceId;
import de.codecentric.boot.admin.server.domain.values.Registration;

public class AbstractEventHandlerTest {
class AbstractEventHandlerTest {

private static final Logger log = LoggerFactory.getLogger(AbstractEventHandlerTest.class);

private static final Registration registration = Registration.create("foo", "http://health").build();
private static final Registration registration = Registration.create("foo", "https://health").build();

private static final InstanceRegisteredEvent firstEvent = new InstanceRegisteredEvent(InstanceId.of("id"), 0L,
registration);
Expand All @@ -53,7 +54,7 @@ public class AbstractEventHandlerTest {
2L);

@Test
public void should_resubscribe_after_error() {
void should_resubscribe_after_error() {
TestPublisher<InstanceEvent> testPublisher = TestPublisher.create();

TestEventHandler eventHandler = new TestEventHandler(testPublisher.flux());
Expand All @@ -68,7 +69,7 @@ public void should_resubscribe_after_error() {
}

@Test
public void should_filter() {
void should_filter() {
TestPublisher<InstanceEvent> testPublisher = TestPublisher.create();

TestEventHandler eventHandler = new TestEventHandler(testPublisher.flux());
Expand All @@ -86,6 +87,7 @@ public static final class TestEventHandler extends AbstractEventHandler<Instance

private final Sinks.Many<InstanceEvent> unicast;

@Getter
private final Flux<InstanceEvent> flux;

private TestEventHandler(Publisher<InstanceEvent> publisher) {
Expand All @@ -108,10 +110,6 @@ protected Publisher<Void> handle(Flux<InstanceRegisteredEvent> publisher) {
}).then();
}

public Flux<InstanceEvent> getFlux() {
return this.flux;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,28 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class ApplicationRegistryTest {
class ApplicationRegistryTest {

private InstanceRegistry instanceRegistry;

private ApplicationRegistry applicationRegistry;

@BeforeEach
public void setUp() {
void setUp() {
this.instanceRegistry = mock(InstanceRegistry.class);
InstanceEventPublisher instanceEventPublisher = mock(InstanceEventPublisher.class);
this.applicationRegistry = new ApplicationRegistry(this.instanceRegistry, instanceEventPublisher);
}

@Test
public void getApplications_noRegisteredApplications() {
void getApplications_noRegisteredApplications() {
when(this.instanceRegistry.getInstances()).thenReturn(Flux.just());

StepVerifier.create(this.applicationRegistry.getApplications()).verifyComplete();
}

@Test
public void getApplications_oneRegisteredAndOneUnregisteredApplication() {
void getApplications_oneRegisteredAndOneUnregisteredApplication() {
Instance instance1 = getInstance("App1");
Instance instance2 = getInstance("App2").deregister();

Expand All @@ -75,7 +75,7 @@ public void getApplications_oneRegisteredAndOneUnregisteredApplication() {
}

@Test
public void getApplications_allRegisteredApplications() {
void getApplications_allRegisteredApplications() {
Instance instance1 = getInstance("App1");
Instance instance2 = getInstance("App2");

Expand All @@ -90,30 +90,30 @@ public void getApplications_allRegisteredApplications() {
}

@Test
public void getApplication_noRegisteredApplications() {
void getApplication_noRegisteredApplications() {
when(this.instanceRegistry.getInstances(any(String.class))).thenReturn(Flux.just());

StepVerifier.create(this.applicationRegistry.getApplication("App1")).verifyComplete();
}

@Test
public void getApplication_noMatchingRegisteredApplications() {
void getApplication_noMatchingRegisteredApplications() {
when(this.instanceRegistry.getInstances("App2")).thenReturn(Flux.just(getInstance("App2")));
when(this.instanceRegistry.getInstances(any(String.class))).thenReturn(Flux.just());

StepVerifier.create(this.applicationRegistry.getApplication("App1")).verifyComplete();
}

@Test
public void getApplication_matchingUnregisteredApplications() {
void getApplication_matchingUnregisteredApplications() {
Instance instance = getInstance("App1").deregister();
when(this.instanceRegistry.getInstances("App1")).thenReturn(Flux.just(instance));

StepVerifier.create(this.applicationRegistry.getApplication("App1")).verifyComplete();
}

@Test
public void getApplication_matchingRegisteredApplications() {
void getApplication_matchingRegisteredApplications() {
Instance instance = getInstance("App1");
when(this.instanceRegistry.getInstances("App1")).thenReturn(Flux.just(instance));

Expand All @@ -123,7 +123,7 @@ public void getApplication_matchingRegisteredApplications() {
}

@Test
public void deregister() {
void deregister() {
Instance instance1 = getInstance("App1");
InstanceId instance1Id = instance1.getId();

Expand All @@ -138,7 +138,7 @@ public void deregister() {
}

@Test
public void getBuildVersion() {
void getBuildVersion() {
Instance instance1 = getInstance("App1", "0.1");
Instance instance2 = getInstance("App2", "0.2");

Expand All @@ -158,7 +158,7 @@ public void getBuildVersion() {
@CsvSource({ "UP, UP, UP", "DOWN, DOWN, DOWN", "UNKNOWN, UNKNOWN, UNKNOWN", "UP, DOWN, RESTRICTED",
"UP, UNKNOWN, RESTRICTED", "UP, OUT_OF_SERVICE, RESTRICTED", "UP, OFFLINE, RESTRICTED",
"UP, RESTRICTED, RESTRICTED", "DOWN, UP, RESTRICTED" })
public void getStatus(String instance1Status, String instance2Status, String expectedApplicationStatus) {
void getStatus(String instance1Status, String instance2Status, String expectedApplicationStatus) {
Instance instance1 = getInstance("App1").withStatusInfo(StatusInfo.valueOf(instance1Status));
Instance instance2 = getInstance("App1").withStatusInfo(StatusInfo.valueOf(instance2Status));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@

import static org.assertj.core.api.Assertions.assertThat;

public class CloudFoundryInstanceIdGeneratorTest {
class CloudFoundryInstanceIdGeneratorTest {

private CloudFoundryInstanceIdGenerator instance = new CloudFoundryInstanceIdGenerator(
private final CloudFoundryInstanceIdGenerator instance = new CloudFoundryInstanceIdGenerator(
new HashingInstanceUrlIdGenerator());

@Test
public void test_cloud_foundry_instance_id() {
Registration registration = Registration.create("foo", "http://health")
void test_cloud_foundry_instance_id() {
Registration registration = Registration.create("foo", "https://health")
.metadata("applicationId", "549e64cf-a478-423d-9d6d-02d803a028a8")
.metadata("instanceId", "0")
.build();
Expand All @@ -39,9 +39,9 @@ public void test_cloud_foundry_instance_id() {
}

@Test
public void test_health_url_instance_id() {
Registration registration = Registration.create("foo", "http://health").build();
assertThat(instance.generateId(registration)).isEqualTo(InstanceId.of("8f9960c48139"));
void test_health_url_instance_id() {
Registration registration = Registration.create("foo", "https://health").build();
assertThat(instance.generateId(registration)).isEqualTo(InstanceId.of("cff917ccf90e"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,27 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class EndpointDetectionTriggerTest {
class EndpointDetectionTriggerTest {

private final Instance instance = Instance.create(InstanceId.of("id-1"))
.register(Registration.create("foo", "http://health-1").build());

private TestPublisher<InstanceEvent> events = TestPublisher.create();
private final TestPublisher<InstanceEvent> events = TestPublisher.create();

private EndpointDetector detector = mock(EndpointDetector.class);
private final EndpointDetector detector = mock(EndpointDetector.class);

private EndpointDetectionTrigger trigger;

@BeforeEach
public void setUp() throws Exception {
void setUp() {
when(this.detector.detectEndpoints(any(InstanceId.class))).thenReturn(Mono.empty());
this.trigger = new EndpointDetectionTrigger(this.detector, this.events.flux());
this.trigger.start();
await().until(this.events::wasSubscribed);
}

@Test
public void should_detect_on_status_changed() {
void should_detect_on_status_changed() {
// when status-change event is emitted
this.events.next(
new InstanceStatusChangedEvent(this.instance.getId(), this.instance.getVersion(), StatusInfo.ofDown()));
Expand All @@ -68,7 +68,7 @@ public void should_detect_on_status_changed() {
}

@Test
public void should_detect_on_registration_updated() {
void should_detect_on_registration_updated() {
// when status-change event is emitted
this.events.next(new InstanceRegistrationUpdatedEvent(this.instance.getId(), this.instance.getVersion(),
this.instance.getRegistration()));
Expand All @@ -77,7 +77,7 @@ public void should_detect_on_registration_updated() {
}

@Test
public void should_not_detect_on_non_relevant_event() {
void should_not_detect_on_non_relevant_event() {
// when some non-status-change event is emitted
this.events.next(new InstanceRegisteredEvent(this.instance.getId(), this.instance.getVersion(),
this.instance.getRegistration()));
Expand All @@ -86,7 +86,7 @@ public void should_not_detect_on_non_relevant_event() {
}

@Test
public void should_not_detect_on_trigger_stopped() {
void should_not_detect_on_trigger_stopped() {
// when registered event is emitted but the trigger has been stopped
this.trigger.stop();
clearInvocations(this.detector);
Expand All @@ -97,7 +97,7 @@ public void should_not_detect_on_trigger_stopped() {
}

@Test
public void should_continue_detection_after_error() throws InterruptedException {
void should_continue_detection_after_error() {
// when status-change event is emitted and an error is emitted
when(this.detector.detectEndpoints(any())).thenReturn(Mono.error(IllegalStateException::new))
.thenReturn(Mono.empty());
Expand Down
Loading
Loading