Move tests to JUnit 5 wherever possible
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
/**
|
||||
* A test suite for probing weird ordering problems in the tests.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({})
|
||||
@Ignore
|
||||
public class AdhocTestSuite {
|
||||
|
||||
}
|
||||
@@ -41,7 +41,7 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class RabbitHealthIndicatorTests {
|
||||
class RabbitHealthIndicatorTests {
|
||||
|
||||
@Mock
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
@@ -59,13 +59,13 @@ public class RabbitHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenRabbitTemplateIsNullShouldThrowException() {
|
||||
void createWhenRabbitTemplateIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new RabbitHealthIndicator(null))
|
||||
.withMessageContaining("RabbitTemplate must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthWhenConnectionSucceedsShouldReturnUpWithVersion() {
|
||||
void healthWhenConnectionSucceedsShouldReturnUpWithVersion() {
|
||||
Connection connection = mock(Connection.class);
|
||||
given(this.channel.getConnection()).willReturn(connection);
|
||||
given(connection.getServerProperties()).willReturn(Collections.singletonMap("version", "123"));
|
||||
@@ -75,7 +75,7 @@ public class RabbitHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthWhenConnectionFailsShouldReturnDown() {
|
||||
void healthWhenConnectionFailsShouldReturnDown() {
|
||||
given(this.channel.getConnection()).willThrow(new RuntimeException());
|
||||
Health health = new RabbitHealthIndicator(this.rabbitTemplate).health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||
|
||||
@@ -32,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
* @author Dave Syer
|
||||
* @author Vedran Pavic
|
||||
*/
|
||||
public class AuditEventTests {
|
||||
class AuditEventTests {
|
||||
|
||||
@Test
|
||||
public void nowEvent() {
|
||||
void nowEvent() {
|
||||
AuditEvent event = new AuditEvent("phil", "UNKNOWN", Collections.singletonMap("a", (Object) "b"));
|
||||
assertThat(event.getData().get("a")).isEqualTo("b");
|
||||
assertThat(event.getType()).isEqualTo("UNKNOWN");
|
||||
@@ -44,34 +44,34 @@ public class AuditEventTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertStringsToData() {
|
||||
void convertStringsToData() {
|
||||
AuditEvent event = new AuditEvent("phil", "UNKNOWN", "a=b", "c=d");
|
||||
assertThat(event.getData().get("a")).isEqualTo("b");
|
||||
assertThat(event.getData().get("c")).isEqualTo("d");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullPrincipalIsMappedToEmptyString() {
|
||||
void nullPrincipalIsMappedToEmptyString() {
|
||||
AuditEvent auditEvent = new AuditEvent(null, "UNKNOWN", Collections.singletonMap("a", (Object) "b"));
|
||||
assertThat(auditEvent.getPrincipal()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullTimestamp() {
|
||||
void nullTimestamp() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new AuditEvent(null, "phil", "UNKNOWN", Collections.singletonMap("a", (Object) "b")))
|
||||
.withMessageContaining("Timestamp must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullType() {
|
||||
void nullType() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new AuditEvent("phil", null, Collections.singletonMap("a", (Object) "b")))
|
||||
.withMessageContaining("Type must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jsonFormat() throws Exception {
|
||||
void jsonFormat() throws Exception {
|
||||
AuditEvent event = new AuditEvent("johannes", "UNKNOWN",
|
||||
Collections.singletonMap("type", (Object) "BadCredentials"));
|
||||
String json = Jackson2ObjectMapperBuilder.json().build().writeValueAsString(event);
|
||||
|
||||
@@ -31,7 +31,7 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class AuditEventsEndpointTests {
|
||||
class AuditEventsEndpointTests {
|
||||
|
||||
private final AuditEventRepository repository = mock(AuditEventRepository.class);
|
||||
|
||||
@@ -40,14 +40,14 @@ public class AuditEventsEndpointTests {
|
||||
private final AuditEvent event = new AuditEvent("principal", "type", Collections.singletonMap("a", "alpha"));
|
||||
|
||||
@Test
|
||||
public void eventsWithType() {
|
||||
void eventsWithType() {
|
||||
given(this.repository.find(null, null, "type")).willReturn(Collections.singletonList(this.event));
|
||||
List<AuditEvent> result = this.endpoint.events(null, null, "type").getEvents();
|
||||
assertThat(result).isEqualTo(Collections.singletonList(this.event));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eventsCreatedAfter() {
|
||||
void eventsCreatedAfter() {
|
||||
OffsetDateTime now = OffsetDateTime.now();
|
||||
given(this.repository.find(null, now.toInstant(), null)).willReturn(Collections.singletonList(this.event));
|
||||
List<AuditEvent> result = this.endpoint.events(null, now, null).getEvents();
|
||||
@@ -55,7 +55,7 @@ public class AuditEventsEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eventsWithPrincipal() {
|
||||
void eventsWithPrincipal() {
|
||||
given(this.repository.find("Joan", null, null)).willReturn(Collections.singletonList(this.event));
|
||||
List<AuditEvent> result = this.endpoint.events("Joan", null, null).getEvents();
|
||||
assertThat(result).isEqualTo(Collections.singletonList(this.event));
|
||||
|
||||
@@ -20,10 +20,8 @@ import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.minidev.json.JSONArray;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointRunners;
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
@@ -35,35 +33,32 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
* @author Vedran Pavic
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(WebEndpointRunners.class)
|
||||
public class AuditEventsEndpointWebIntegrationTests {
|
||||
class AuditEventsEndpointWebIntegrationTests {
|
||||
|
||||
private static WebTestClient client;
|
||||
|
||||
@Test
|
||||
public void allEvents() {
|
||||
@WebEndpointTest
|
||||
void allEvents(WebTestClient client) {
|
||||
client.get().uri((builder) -> builder.path("/actuator/auditevents").build()).exchange().expectStatus().isOk()
|
||||
.expectBody().jsonPath("events.[*].principal")
|
||||
.isEqualTo(new JSONArray().appendElement("admin").appendElement("admin").appendElement("user"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eventsAfter() {
|
||||
@WebEndpointTest
|
||||
void eventsAfter(WebTestClient client) {
|
||||
client.get()
|
||||
.uri((builder) -> builder.path("/actuator/auditevents")
|
||||
.queryParam("after", "2016-11-01T13:00:00%2B00:00").build())
|
||||
.exchange().expectStatus().isOk().expectBody().jsonPath("events").isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eventsWithPrincipal() {
|
||||
@WebEndpointTest
|
||||
void eventsWithPrincipal(WebTestClient client) {
|
||||
client.get().uri((builder) -> builder.path("/actuator/auditevents").queryParam("principal", "user").build())
|
||||
.exchange().expectStatus().isOk().expectBody().jsonPath("events.[*].principal")
|
||||
.isEqualTo(new JSONArray().appendElement("user"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eventsWithType() {
|
||||
@WebEndpointTest
|
||||
void eventsWithType(WebTestClient client) {
|
||||
client.get().uri((builder) -> builder.path("/actuator/auditevents").queryParam("type", "logout").build())
|
||||
.exchange().expectStatus().isOk().expectBody().jsonPath("events.[*].principal")
|
||||
.isEqualTo(new JSONArray().appendElement("admin")).jsonPath("events.[*].type")
|
||||
|
||||
@@ -34,10 +34,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
* @author Phillip Webb
|
||||
* @author Vedran Pavic
|
||||
*/
|
||||
public class InMemoryAuditEventRepositoryTests {
|
||||
class InMemoryAuditEventRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void lessThanCapacity() {
|
||||
void lessThanCapacity() {
|
||||
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
||||
repository.add(new AuditEvent("dave", "a"));
|
||||
repository.add(new AuditEvent("dave", "b"));
|
||||
@@ -48,7 +48,7 @@ public class InMemoryAuditEventRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void capacity() {
|
||||
void capacity() {
|
||||
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository(2);
|
||||
repository.add(new AuditEvent("dave", "a"));
|
||||
repository.add(new AuditEvent("dave", "b"));
|
||||
@@ -60,14 +60,14 @@ public class InMemoryAuditEventRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addNullAuditEvent() {
|
||||
void addNullAuditEvent() {
|
||||
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> repository.add(null))
|
||||
.withMessageContaining("AuditEvent must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findByPrincipal() {
|
||||
void findByPrincipal() {
|
||||
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
||||
repository.add(new AuditEvent("dave", "a"));
|
||||
repository.add(new AuditEvent("phil", "b"));
|
||||
@@ -80,7 +80,7 @@ public class InMemoryAuditEventRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findByPrincipalAndType() {
|
||||
void findByPrincipalAndType() {
|
||||
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
||||
repository.add(new AuditEvent("dave", "a"));
|
||||
repository.add(new AuditEvent("phil", "b"));
|
||||
@@ -93,7 +93,7 @@ public class InMemoryAuditEventRepositoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findByDate() {
|
||||
void findByDate() {
|
||||
Instant instant = Instant.now();
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
||||
|
||||
@@ -31,10 +31,10 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class AuditListenerTests {
|
||||
class AuditListenerTests {
|
||||
|
||||
@Test
|
||||
public void testStoredEvents() {
|
||||
void testStoredEvents() {
|
||||
AuditEventRepository repository = mock(AuditEventRepository.class);
|
||||
AuditEvent event = new AuditEvent("principal", "type", Collections.emptyMap());
|
||||
AuditListener listener = new AuditListener(repository);
|
||||
|
||||
@@ -42,10 +42,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class BeansEndpointTests {
|
||||
class BeansEndpointTests {
|
||||
|
||||
@Test
|
||||
public void beansAreFound() {
|
||||
void beansAreFound() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(EndpointConfiguration.class);
|
||||
contextRunner.run((context) -> {
|
||||
@@ -59,7 +59,7 @@ public class BeansEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void infrastructureBeansAreOmitted() {
|
||||
void infrastructureBeansAreOmitted() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(EndpointConfiguration.class);
|
||||
contextRunner.run((context) -> {
|
||||
@@ -78,7 +78,7 @@ public class BeansEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lazyBeansAreOmitted() {
|
||||
void lazyBeansAreOmitted() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(EndpointConfiguration.class, LazyBeanConfiguration.class);
|
||||
contextRunner.run((context) -> {
|
||||
@@ -90,7 +90,7 @@ public class BeansEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beansInParentContextAreFound() {
|
||||
void beansInParentContextAreFound() {
|
||||
ApplicationContextRunner parentRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(BeanConfiguration.class);
|
||||
parentRunner.run((parent) -> {
|
||||
|
||||
@@ -43,10 +43,10 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class CachesEndpointTests {
|
||||
class CachesEndpointTests {
|
||||
|
||||
@Test
|
||||
public void allCachesWithSingleCacheManager() {
|
||||
void allCachesWithSingleCacheManager() {
|
||||
CachesEndpoint endpoint = new CachesEndpoint(
|
||||
Collections.singletonMap("test", new ConcurrentMapCacheManager("a", "b")));
|
||||
Map<String, CacheManagerDescriptor> allDescriptors = endpoint.caches().getCacheManagers();
|
||||
@@ -58,7 +58,7 @@ public class CachesEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allCachesWithSeveralCacheManagers() {
|
||||
void allCachesWithSeveralCacheManagers() {
|
||||
Map<String, CacheManager> cacheManagers = new LinkedHashMap<>();
|
||||
cacheManagers.put("test", new ConcurrentMapCacheManager("a", "b"));
|
||||
cacheManagers.put("another", new ConcurrentMapCacheManager("a", "c"));
|
||||
@@ -70,7 +70,7 @@ public class CachesEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namedCacheWithSingleCacheManager() {
|
||||
void namedCacheWithSingleCacheManager() {
|
||||
CachesEndpoint endpoint = new CachesEndpoint(
|
||||
Collections.singletonMap("test", new ConcurrentMapCacheManager("b", "a")));
|
||||
CacheEntry entry = endpoint.cache("a", null);
|
||||
@@ -81,7 +81,7 @@ public class CachesEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namedCacheWithSeveralCacheManagers() {
|
||||
void namedCacheWithSeveralCacheManagers() {
|
||||
Map<String, CacheManager> cacheManagers = new LinkedHashMap<>();
|
||||
cacheManagers.put("test", new ConcurrentMapCacheManager("b", "dupe-cache"));
|
||||
cacheManagers.put("another", new ConcurrentMapCacheManager("c", "dupe-cache"));
|
||||
@@ -91,7 +91,7 @@ public class CachesEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namedCacheWithUnknownCache() {
|
||||
void namedCacheWithUnknownCache() {
|
||||
CachesEndpoint endpoint = new CachesEndpoint(
|
||||
Collections.singletonMap("test", new ConcurrentMapCacheManager("b", "a")));
|
||||
CacheEntry entry = endpoint.cache("unknown", null);
|
||||
@@ -99,7 +99,7 @@ public class CachesEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namedCacheWithWrongCacheManager() {
|
||||
void namedCacheWithWrongCacheManager() {
|
||||
Map<String, CacheManager> cacheManagers = new LinkedHashMap<>();
|
||||
cacheManagers.put("test", new ConcurrentMapCacheManager("b", "a"));
|
||||
cacheManagers.put("another", new ConcurrentMapCacheManager("c", "a"));
|
||||
@@ -109,7 +109,7 @@ public class CachesEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namedCacheWithSeveralCacheManagersWithCacheManagerFilter() {
|
||||
void namedCacheWithSeveralCacheManagersWithCacheManagerFilter() {
|
||||
Map<String, CacheManager> cacheManagers = new LinkedHashMap<>();
|
||||
cacheManagers.put("test", new ConcurrentMapCacheManager("b", "a"));
|
||||
cacheManagers.put("another", new ConcurrentMapCacheManager("c", "a"));
|
||||
@@ -121,7 +121,7 @@ public class CachesEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearAllCaches() {
|
||||
void clearAllCaches() {
|
||||
Cache a = mockCache("a");
|
||||
Cache b = mockCache("b");
|
||||
CachesEndpoint endpoint = new CachesEndpoint(Collections.singletonMap("test", cacheManager(a, b)));
|
||||
@@ -131,7 +131,7 @@ public class CachesEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearCache() {
|
||||
void clearCache() {
|
||||
Cache a = mockCache("a");
|
||||
Cache b = mockCache("b");
|
||||
CachesEndpoint endpoint = new CachesEndpoint(Collections.singletonMap("test", cacheManager(a, b)));
|
||||
@@ -141,7 +141,7 @@ public class CachesEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearCacheWithSeveralCacheManagers() {
|
||||
void clearCacheWithSeveralCacheManagers() {
|
||||
Map<String, CacheManager> cacheManagers = new LinkedHashMap<>();
|
||||
cacheManagers.put("test", cacheManager(mockCache("dupe-cache"), mockCache("b")));
|
||||
cacheManagers.put("another", cacheManager(mockCache("dupe-cache")));
|
||||
@@ -152,7 +152,7 @@ public class CachesEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearCacheWithSeveralCacheManagersWithCacheManagerFilter() {
|
||||
void clearCacheWithSeveralCacheManagersWithCacheManagerFilter() {
|
||||
Map<String, CacheManager> cacheManagers = new LinkedHashMap<>();
|
||||
Cache a = mockCache("a");
|
||||
Cache b = mockCache("b");
|
||||
@@ -167,7 +167,7 @@ public class CachesEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearCacheWithUnknownCache() {
|
||||
void clearCacheWithUnknownCache() {
|
||||
Cache a = mockCache("a");
|
||||
CachesEndpoint endpoint = new CachesEndpoint(Collections.singletonMap("test", cacheManager(a)));
|
||||
assertThat(endpoint.clearCache("unknown", null)).isFalse();
|
||||
@@ -175,7 +175,7 @@ public class CachesEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearCacheWithUnknownCacheManager() {
|
||||
void clearCacheWithUnknownCacheManager() {
|
||||
Cache a = mockCache("a");
|
||||
CachesEndpoint endpoint = new CachesEndpoint(Collections.singletonMap("test", cacheManager(a)));
|
||||
assertThat(endpoint.clearCache("a", "unknown")).isFalse();
|
||||
|
||||
@@ -19,14 +19,11 @@ package org.springframework.boot.actuate.cache;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointRunners;
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
@@ -39,15 +36,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@RunWith(WebEndpointRunners.class)
|
||||
public class CachesEndpointWebIntegrationTests {
|
||||
class CachesEndpointWebIntegrationTests {
|
||||
|
||||
private static WebTestClient client;
|
||||
|
||||
private static ConfigurableApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void allCaches() {
|
||||
@WebEndpointTest
|
||||
void allCaches(WebTestClient client) {
|
||||
client.get().uri("/actuator/caches").exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("cacheManagers.one.caches.a.target").isEqualTo(ConcurrentHashMap.class.getName())
|
||||
.jsonPath("cacheManagers.one.caches.b.target").isEqualTo(ConcurrentHashMap.class.getName())
|
||||
@@ -55,38 +47,38 @@ public class CachesEndpointWebIntegrationTests {
|
||||
.jsonPath("cacheManagers.two.caches.c.target").isEqualTo(ConcurrentHashMap.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namedCache() {
|
||||
@WebEndpointTest
|
||||
void namedCache(WebTestClient client) {
|
||||
client.get().uri("/actuator/caches/b").exchange().expectStatus().isOk().expectBody().jsonPath("name")
|
||||
.isEqualTo("b").jsonPath("cacheManager").isEqualTo("one").jsonPath("target")
|
||||
.isEqualTo(ConcurrentHashMap.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namedCacheWithUnknownName() {
|
||||
@WebEndpointTest
|
||||
void namedCacheWithUnknownName(WebTestClient client) {
|
||||
client.get().uri("/actuator/caches/does-not-exist").exchange().expectStatus().isNotFound();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namedCacheWithNonUniqueName() {
|
||||
@WebEndpointTest
|
||||
void namedCacheWithNonUniqueName(WebTestClient client) {
|
||||
client.get().uri("/actuator/caches/a").exchange().expectStatus().isBadRequest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearNamedCache() {
|
||||
@WebEndpointTest
|
||||
void clearNamedCache(WebTestClient client, ApplicationContext context) {
|
||||
Cache b = context.getBean("one", CacheManager.class).getCache("b");
|
||||
b.put("test", "value");
|
||||
client.delete().uri("/actuator/caches/b").exchange().expectStatus().isNoContent();
|
||||
assertThat(b.get("test")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cleanNamedCacheWithUnknownName() {
|
||||
@WebEndpointTest
|
||||
void cleanNamedCacheWithUnknownName(WebTestClient client) {
|
||||
client.delete().uri("/actuator/caches/does-not-exist").exchange().expectStatus().isNotFound();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearNamedCacheWithNonUniqueName() {
|
||||
@WebEndpointTest
|
||||
void clearNamedCacheWithNonUniqueName(WebTestClient client) {
|
||||
client.get().uri("/actuator/caches/a").exchange().expectStatus().isBadRequest();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.boot.actuate.cassandra;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Row;
|
||||
import com.datastax.driver.core.querybuilder.Select;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.Status;
|
||||
@@ -37,15 +37,15 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Oleksii Bondar
|
||||
*/
|
||||
public class CassandraHealthIndicatorTests {
|
||||
class CassandraHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
public void createWhenCassandraOperationsIsNullShouldThrowException() {
|
||||
void createWhenCassandraOperationsIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new CassandraHealthIndicator(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyHealthStatusWhenExhausted() {
|
||||
void verifyHealthStatusWhenExhausted() {
|
||||
CassandraOperations cassandraOperations = mock(CassandraOperations.class);
|
||||
CqlOperations cqlOperations = mock(CqlOperations.class);
|
||||
ResultSet resultSet = mock(ResultSet.class);
|
||||
@@ -58,7 +58,7 @@ public class CassandraHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyHealthStatusWithVersion() {
|
||||
void verifyHealthStatusWithVersion() {
|
||||
CassandraOperations cassandraOperations = mock(CassandraOperations.class);
|
||||
CqlOperations cqlOperations = mock(CqlOperations.class);
|
||||
ResultSet resultSet = mock(ResultSet.class);
|
||||
|
||||
@@ -37,10 +37,10 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Artsiom Yudovin
|
||||
*/
|
||||
public class CassandraReactiveHealthIndicatorTests {
|
||||
class CassandraReactiveHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
public void testCassandraIsUp() {
|
||||
void testCassandraIsUp() {
|
||||
ReactiveCqlOperations reactiveCqlOperations = mock(ReactiveCqlOperations.class);
|
||||
given(reactiveCqlOperations.queryForObject(any(Select.class), eq(String.class))).willReturn(Mono.just("6.0.0"));
|
||||
ReactiveCassandraOperations reactiveCassandraOperations = mock(ReactiveCassandraOperations.class);
|
||||
@@ -57,7 +57,7 @@ public class CassandraReactiveHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCassandraIsDown() {
|
||||
void testCassandraIsDown() {
|
||||
ReactiveCassandraOperations reactiveCassandraOperations = mock(ReactiveCassandraOperations.class);
|
||||
given(reactiveCassandraOperations.getReactiveCqlOperations())
|
||||
.willThrow(new CassandraInternalException("Connection failed"));
|
||||
|
||||
@@ -42,10 +42,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ShutdownEndpointTests {
|
||||
class ShutdownEndpointTests {
|
||||
|
||||
@Test
|
||||
public void shutdown() {
|
||||
void shutdown() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(EndpointConfig.class);
|
||||
contextRunner.run((context) -> {
|
||||
@@ -67,7 +67,7 @@ public class ShutdownEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shutdownChild() throws Exception {
|
||||
void shutdownChild() throws Exception {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(EmptyConfig.class)
|
||||
.child(EndpointConfig.class).web(WebApplicationType.NONE).run();
|
||||
CountDownLatch latch = context.getBean(EndpointConfig.class).latch;
|
||||
@@ -77,7 +77,7 @@ public class ShutdownEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shutdownParent() throws Exception {
|
||||
void shutdownParent() throws Exception {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(EndpointConfig.class)
|
||||
.child(EmptyConfig.class).web(WebApplicationType.NONE).run();
|
||||
CountDownLatch parentLatch = context.getBean(EndpointConfig.class).latch;
|
||||
|
||||
@@ -35,10 +35,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ConfigurationPropertiesReportEndpointMethodAnnotationsTests {
|
||||
class ConfigurationPropertiesReportEndpointMethodAnnotationsTests {
|
||||
|
||||
@Test
|
||||
public void testNaming() {
|
||||
void testNaming() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(Config.class)
|
||||
.withPropertyValues("other.name:foo", "first.name:bar");
|
||||
contextRunner.run((context) -> {
|
||||
@@ -56,7 +56,7 @@ public class ConfigurationPropertiesReportEndpointMethodAnnotationsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prefixFromBeanMethodConfigurationPropertiesCanOverridePrefixOnClass() {
|
||||
void prefixFromBeanMethodConfigurationPropertiesCanOverridePrefixOnClass() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(OverriddenPrefix.class).withPropertyValues("other.name:foo");
|
||||
contextRunner.run((context) -> {
|
||||
|
||||
@@ -34,10 +34,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ConfigurationPropertiesReportEndpointParentTests {
|
||||
class ConfigurationPropertiesReportEndpointParentTests {
|
||||
|
||||
@Test
|
||||
public void configurationPropertiesClass() {
|
||||
void configurationPropertiesClass() {
|
||||
new ApplicationContextRunner().withUserConfiguration(Parent.class).run((parent) -> {
|
||||
new ApplicationContextRunner().withUserConfiguration(ClassConfigurationProperties.class).withParent(parent)
|
||||
.run((child) -> {
|
||||
@@ -54,7 +54,7 @@ public class ConfigurationPropertiesReportEndpointParentTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configurationPropertiesBeanMethod() {
|
||||
void configurationPropertiesBeanMethod() {
|
||||
new ApplicationContextRunner().withUserConfiguration(Parent.class).run((parent) -> {
|
||||
new ApplicationContextRunner().withUserConfiguration(BeanMethodConfigurationProperties.class)
|
||||
.withParent(parent).run((child) -> {
|
||||
|
||||
@@ -45,10 +45,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ConfigurationPropertiesReportEndpointProxyTests {
|
||||
class ConfigurationPropertiesReportEndpointProxyTests {
|
||||
|
||||
@Test
|
||||
public void testWithProxyClass() {
|
||||
void testWithProxyClass() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(Config.class,
|
||||
SqlExecutor.class);
|
||||
contextRunner.run((context) -> {
|
||||
|
||||
@@ -44,10 +44,10 @@ import static org.assertj.core.api.Assertions.entry;
|
||||
* @author Stephane Nicoll
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
|
||||
@Test
|
||||
public void testNaming() {
|
||||
void testNaming() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(FooConfig.class)
|
||||
.withPropertyValues("foo.name:foo");
|
||||
contextRunner.run((context) -> {
|
||||
@@ -67,7 +67,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testNestedNaming() {
|
||||
void testNestedNaming() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(FooConfig.class)
|
||||
.withPropertyValues("foo.bar.name:foo");
|
||||
contextRunner.run((context) -> {
|
||||
@@ -86,7 +86,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testSelfReferentialProperty() {
|
||||
void testSelfReferentialProperty() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(SelfReferentialConfig.class).withPropertyValues("foo.name:foo");
|
||||
contextRunner.run((context) -> {
|
||||
@@ -107,7 +107,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCycle() {
|
||||
void testCycle() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(CycleConfig.class);
|
||||
contextRunner.run((context) -> {
|
||||
@@ -126,7 +126,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testMap() {
|
||||
void testMap() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(MapConfig.class)
|
||||
.withPropertyValues("foo.map.name:foo");
|
||||
contextRunner.run((context) -> {
|
||||
@@ -145,7 +145,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyMapIsNotAdded() {
|
||||
void testEmptyMapIsNotAdded() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(MapConfig.class);
|
||||
contextRunner.run((context) -> {
|
||||
ConfigurationPropertiesReportEndpoint endpoint = context
|
||||
@@ -164,7 +164,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testList() {
|
||||
void testList() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(ListConfig.class)
|
||||
.withPropertyValues("foo.list[0]:foo");
|
||||
contextRunner.run((context) -> {
|
||||
@@ -183,7 +183,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInetAddress() {
|
||||
void testInetAddress() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(AddressedConfig.class).withPropertyValues("foo.address:192.168.1.10");
|
||||
contextRunner.run((context) -> {
|
||||
@@ -203,7 +203,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testInitializedMapAndList() {
|
||||
void testInitializedMapAndList() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(InitializedMapAndListPropertiesConfig.class)
|
||||
.withPropertyValues("foo.map.entryOne:true", "foo.list[0]:abc");
|
||||
@@ -224,7 +224,7 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hikariDataSourceConfigurationPropertiesBeanCanBeSerialized() {
|
||||
void hikariDataSourceConfigurationPropertiesBeanCanBeSerialized() {
|
||||
ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withUserConfiguration(HikariDataSourceConfig.class);
|
||||
contextRunner.run((context) -> {
|
||||
|
||||
@@ -47,10 +47,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ConfigurationPropertiesReportEndpointTests {
|
||||
class ConfigurationPropertiesReportEndpointTests {
|
||||
|
||||
@Test
|
||||
public void configurationPropertiesAreReturned() {
|
||||
void configurationPropertiesAreReturned() {
|
||||
load((context, properties) -> {
|
||||
assertThat(properties.getBeans().size()).isGreaterThan(0);
|
||||
ConfigurationPropertiesBeanDescriptor nestedProperties = properties.getBeans().get("testProperties");
|
||||
@@ -61,7 +61,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void entriesWithNullValuesAreNotIncluded() {
|
||||
void entriesWithNullValuesAreNotIncluded() {
|
||||
load((context, properties) -> {
|
||||
Map<String, Object> nestedProperties = properties.getBeans().get("testProperties").getProperties();
|
||||
assertThat(nestedProperties).doesNotContainKey("nullValue");
|
||||
@@ -69,7 +69,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultKeySanitization() {
|
||||
void defaultKeySanitization() {
|
||||
load((context, properties) -> {
|
||||
Map<String, Object> nestedProperties = properties.getBeans().get("testProperties").getProperties();
|
||||
assertThat(nestedProperties).isNotNull();
|
||||
@@ -79,7 +79,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customKeySanitization() {
|
||||
void customKeySanitization() {
|
||||
load("property", (context, properties) -> {
|
||||
Map<String, Object> nestedProperties = properties.getBeans().get("testProperties").getProperties();
|
||||
assertThat(nestedProperties).isNotNull();
|
||||
@@ -89,7 +89,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customPatternKeySanitization() {
|
||||
void customPatternKeySanitization() {
|
||||
load(".*pass.*", (context, properties) -> {
|
||||
Map<String, Object> nestedProperties = properties.getBeans().get("testProperties").getProperties();
|
||||
assertThat(nestedProperties).isNotNull();
|
||||
@@ -100,7 +100,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void keySanitizationWithCustomPatternUsingCompositeKeys() {
|
||||
void keySanitizationWithCustomPatternUsingCompositeKeys() {
|
||||
// gh-4415
|
||||
load(Arrays.asList(".*\\.secrets\\..*", ".*\\.hidden\\..*"), (context, properties) -> {
|
||||
Map<String, Object> nestedProperties = properties.getBeans().get("testProperties").getProperties();
|
||||
@@ -114,7 +114,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonCamelCaseProperty() {
|
||||
void nonCamelCaseProperty() {
|
||||
load((context, properties) -> {
|
||||
Map<String, Object> nestedProperties = properties.getBeans().get("testProperties").getProperties();
|
||||
assertThat(nestedProperties.get("myURL")).isEqualTo("https://example.com");
|
||||
@@ -122,7 +122,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleBoolean() {
|
||||
void simpleBoolean() {
|
||||
load((context, properties) -> {
|
||||
Map<String, Object> nestedProperties = properties.getBeans().get("testProperties").getProperties();
|
||||
assertThat(nestedProperties.get("simpleBoolean")).isEqualTo(true);
|
||||
@@ -130,7 +130,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mixedBoolean() {
|
||||
void mixedBoolean() {
|
||||
load((context, properties) -> {
|
||||
Map<String, Object> nestedProperties = properties.getBeans().get("testProperties").getProperties();
|
||||
assertThat(nestedProperties.get("mixedBoolean")).isEqualTo(true);
|
||||
@@ -138,7 +138,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mixedCase() {
|
||||
void mixedCase() {
|
||||
load((context, properties) -> {
|
||||
Map<String, Object> nestedProperties = properties.getBeans().get("testProperties").getProperties();
|
||||
assertThat(nestedProperties.get("mIxedCase")).isEqualTo("mixed");
|
||||
@@ -146,7 +146,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void duration() {
|
||||
void duration() {
|
||||
load((context, properties) -> {
|
||||
Map<String, Object> nestedProperties = properties.getBeans().get("testProperties").getProperties();
|
||||
assertThat(nestedProperties.get("duration")).isEqualTo(Duration.ofSeconds(10).toString());
|
||||
@@ -154,7 +154,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleLetterProperty() {
|
||||
void singleLetterProperty() {
|
||||
load((context, properties) -> {
|
||||
Map<String, Object> nestedProperties = properties.getBeans().get("testProperties").getProperties();
|
||||
assertThat(nestedProperties.get("z")).isEqualTo("zzz");
|
||||
@@ -163,7 +163,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void listsAreSanitized() {
|
||||
void listsAreSanitized() {
|
||||
load((context, properties) -> {
|
||||
Map<String, Object> nestedProperties = properties.getBeans().get("testProperties").getProperties();
|
||||
assertThat(nestedProperties.get("listItems")).isInstanceOf(List.class);
|
||||
@@ -176,7 +176,7 @@ public class ConfigurationPropertiesReportEndpointTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void listsOfListsAreSanitized() {
|
||||
void listsOfListsAreSanitized() {
|
||||
load((context, properties) -> {
|
||||
Map<String, Object> nestedProperties = properties.getBeans().get("testProperties").getProperties();
|
||||
assertThat(nestedProperties.get("listOfListItems")).isInstanceOf(List.class);
|
||||
|
||||
@@ -42,11 +42,11 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Eddú Meléndez
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class CouchbaseHealthIndicatorTests {
|
||||
class CouchbaseHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void couchbaseClusterIsUp() {
|
||||
void couchbaseClusterIsUp() {
|
||||
Cluster cluster = mock(Cluster.class);
|
||||
CouchbaseHealthIndicator healthIndicator = new CouchbaseHealthIndicator(cluster);
|
||||
List<EndpointHealth> endpoints = Arrays.asList(new EndpointHealth(ServiceType.BINARY, LifecycleState.CONNECTED,
|
||||
@@ -63,7 +63,7 @@ public class CouchbaseHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void couchbaseClusterIsDown() {
|
||||
void couchbaseClusterIsDown() {
|
||||
Cluster cluster = mock(Cluster.class);
|
||||
CouchbaseHealthIndicator healthIndicator = new CouchbaseHealthIndicator(cluster);
|
||||
List<EndpointHealth> endpoints = Arrays.asList(
|
||||
|
||||
@@ -39,11 +39,11 @@ import static org.mockito.Mockito.verify;
|
||||
/**
|
||||
* Tests for {@link CouchbaseReactiveHealthIndicator}.
|
||||
*/
|
||||
public class CouchbaseReactiveHealthIndicatorTests {
|
||||
class CouchbaseReactiveHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void couchbaseClusterIsUp() {
|
||||
void couchbaseClusterIsUp() {
|
||||
Cluster cluster = mock(Cluster.class);
|
||||
CouchbaseReactiveHealthIndicator healthIndicator = new CouchbaseReactiveHealthIndicator(cluster);
|
||||
List<EndpointHealth> endpoints = Arrays.asList(new EndpointHealth(ServiceType.BINARY, LifecycleState.CONNECTED,
|
||||
@@ -60,7 +60,7 @@ public class CouchbaseReactiveHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void couchbaseClusterIsDown() {
|
||||
void couchbaseClusterIsDown() {
|
||||
Cluster cluster = mock(Cluster.class);
|
||||
CouchbaseReactiveHealthIndicator healthIndicator = new CouchbaseReactiveHealthIndicator(cluster);
|
||||
List<EndpointHealth> endpoints = Arrays.asList(
|
||||
|
||||
@@ -50,7 +50,7 @@ import static org.mockito.BDDMockito.given;
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@Deprecated
|
||||
public class ElasticsearchHealthIndicatorTests {
|
||||
class ElasticsearchHealthIndicatorTests {
|
||||
|
||||
@Mock
|
||||
private Client client;
|
||||
@@ -72,7 +72,7 @@ public class ElasticsearchHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultConfigurationQueriesAllIndicesWith100msTimeout() {
|
||||
void defaultConfigurationQueriesAllIndicesWith100msTimeout() {
|
||||
TestActionFuture responseFuture = new TestActionFuture();
|
||||
responseFuture.onResponse(new StubClusterHealthResponse());
|
||||
ArgumentCaptor<ClusterHealthRequest> requestCaptor = ArgumentCaptor.forClass(ClusterHealthRequest.class);
|
||||
@@ -84,7 +84,7 @@ public class ElasticsearchHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void certainIndices() {
|
||||
void certainIndices() {
|
||||
this.indicator = new ElasticsearchHealthIndicator(this.client, 100L, "test-index-1", "test-index-2");
|
||||
PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<>();
|
||||
responseFuture.onResponse(new StubClusterHealthResponse());
|
||||
@@ -96,7 +96,7 @@ public class ElasticsearchHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customTimeout() {
|
||||
void customTimeout() {
|
||||
this.indicator = new ElasticsearchHealthIndicator(this.client, 1000L);
|
||||
TestActionFuture responseFuture = new TestActionFuture();
|
||||
responseFuture.onResponse(new StubClusterHealthResponse());
|
||||
@@ -107,7 +107,7 @@ public class ElasticsearchHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthDetails() {
|
||||
void healthDetails() {
|
||||
PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<>();
|
||||
responseFuture.onResponse(new StubClusterHealthResponse());
|
||||
given(this.cluster.health(any(ClusterHealthRequest.class))).willReturn(responseFuture);
|
||||
@@ -125,7 +125,7 @@ public class ElasticsearchHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void redResponseMapsToDown() {
|
||||
void redResponseMapsToDown() {
|
||||
PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<>();
|
||||
responseFuture.onResponse(new StubClusterHealthResponse(ClusterHealthStatus.RED));
|
||||
given(this.cluster.health(any(ClusterHealthRequest.class))).willReturn(responseFuture);
|
||||
@@ -133,7 +133,7 @@ public class ElasticsearchHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void yellowResponseMapsToUp() {
|
||||
void yellowResponseMapsToUp() {
|
||||
PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<>();
|
||||
responseFuture.onResponse(new StubClusterHealthResponse(ClusterHealthStatus.YELLOW));
|
||||
given(this.cluster.health(any(ClusterHealthRequest.class))).willReturn(responseFuture);
|
||||
@@ -141,7 +141,7 @@ public class ElasticsearchHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseTimeout() {
|
||||
void responseTimeout() {
|
||||
PlainActionFuture<ClusterHealthResponse> responseFuture = new PlainActionFuture<>();
|
||||
given(this.cluster.health(any(ClusterHealthRequest.class))).willReturn(responseFuture);
|
||||
Health health = this.indicator.health();
|
||||
|
||||
@@ -44,7 +44,7 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Julian Devia Serna
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
public class ElasticsearchJestHealthIndicatorTests {
|
||||
class ElasticsearchJestHealthIndicatorTests {
|
||||
|
||||
private final JestClient jestClient = mock(JestClient.class);
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ElasticsearchJestHealthIndicatorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void elasticsearchIsUp() throws IOException {
|
||||
void elasticsearchIsUp() throws IOException {
|
||||
given(this.jestClient.execute(any(Action.class))).willReturn(createJestResult(200, true, "green"));
|
||||
Health health = this.healthIndicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
@@ -62,7 +62,7 @@ public class ElasticsearchJestHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void elasticsearchWithYellowStatusIsUp() throws IOException {
|
||||
void elasticsearchWithYellowStatusIsUp() throws IOException {
|
||||
given(this.jestClient.execute(any(Action.class))).willReturn(createJestResult(200, true, "yellow"));
|
||||
Health health = this.healthIndicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
@@ -71,7 +71,7 @@ public class ElasticsearchJestHealthIndicatorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void elasticsearchIsDown() throws IOException {
|
||||
void elasticsearchIsDown() throws IOException {
|
||||
given(this.jestClient.execute(any(Action.class)))
|
||||
.willThrow(new CouldNotConnectException("http://localhost:9200", new IOException()));
|
||||
Health health = this.healthIndicator.health();
|
||||
@@ -80,7 +80,7 @@ public class ElasticsearchJestHealthIndicatorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void elasticsearchIsDownWhenQueryDidNotSucceed() throws IOException {
|
||||
void elasticsearchIsDownWhenQueryDidNotSucceed() throws IOException {
|
||||
given(this.jestClient.execute(any(Action.class))).willReturn(createJestResult(200, false, ""));
|
||||
Health health = this.healthIndicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||
@@ -88,7 +88,7 @@ public class ElasticsearchJestHealthIndicatorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void elasticsearchIsDownByResponseCode() throws IOException {
|
||||
void elasticsearchIsDownByResponseCode() throws IOException {
|
||||
given(this.jestClient.execute(any(Action.class))).willReturn(createJestResult(500, false, ""));
|
||||
Health health = this.healthIndicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||
@@ -97,7 +97,7 @@ public class ElasticsearchJestHealthIndicatorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void elasticsearchIsOutOfServiceByStatus() throws IOException {
|
||||
void elasticsearchIsOutOfServiceByStatus() throws IOException {
|
||||
given(this.jestClient.execute(any(Action.class))).willReturn(createJestResult(200, true, "red"));
|
||||
Health health = this.healthIndicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.OUT_OF_SERVICE);
|
||||
|
||||
@@ -42,7 +42,7 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Artsiom Yudovin
|
||||
* @author Filip Hrisafov
|
||||
*/
|
||||
public class ElasticsearchRestHealthIndicatorTest {
|
||||
class ElasticsearchRestHealthIndicatorTest {
|
||||
|
||||
private final RestClient restClient = mock(RestClient.class);
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ElasticsearchRestHealthIndicatorTest {
|
||||
this.restClient);
|
||||
|
||||
@Test
|
||||
public void elasticsearchIsUp() throws IOException {
|
||||
void elasticsearchIsUp() throws IOException {
|
||||
BasicHttpEntity httpEntity = new BasicHttpEntity();
|
||||
httpEntity.setContent(new ByteArrayInputStream(createJsonResult(200, "green").getBytes()));
|
||||
Response response = mock(Response.class);
|
||||
@@ -65,7 +65,7 @@ public class ElasticsearchRestHealthIndicatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void elasticsearchWithYellowStatusIsUp() throws IOException {
|
||||
void elasticsearchWithYellowStatusIsUp() throws IOException {
|
||||
BasicHttpEntity httpEntity = new BasicHttpEntity();
|
||||
httpEntity.setContent(new ByteArrayInputStream(createJsonResult(200, "yellow").getBytes()));
|
||||
Response response = mock(Response.class);
|
||||
@@ -80,7 +80,7 @@ public class ElasticsearchRestHealthIndicatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void elasticsearchIsDown() throws IOException {
|
||||
void elasticsearchIsDown() throws IOException {
|
||||
given(this.restClient.performRequest(any(Request.class))).willThrow(new IOException("Couldn't connect"));
|
||||
Health health = this.elasticsearchRestHealthIndicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||
@@ -88,7 +88,7 @@ public class ElasticsearchRestHealthIndicatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void elasticsearchIsDownByResponseCode() throws IOException {
|
||||
void elasticsearchIsDownByResponseCode() throws IOException {
|
||||
Response response = mock(Response.class);
|
||||
StatusLine statusLine = mock(StatusLine.class);
|
||||
given(statusLine.getStatusCode()).willReturn(500);
|
||||
@@ -102,7 +102,7 @@ public class ElasticsearchRestHealthIndicatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void elasticsearchIsOutOfServiceByStatus() throws IOException {
|
||||
void elasticsearchIsOutOfServiceByStatus() throws IOException {
|
||||
BasicHttpEntity httpEntity = new BasicHttpEntity();
|
||||
httpEntity.setContent(new ByteArrayInputStream(createJsonResult(200, "red").getBytes()));
|
||||
Response response = mock(Response.class);
|
||||
|
||||
@@ -31,45 +31,45 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
public class EndpointIdTests {
|
||||
class EndpointIdTests {
|
||||
|
||||
@Test
|
||||
public void ofWhenNullThrowsException() {
|
||||
void ofWhenNullThrowsException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> EndpointId.of(null))
|
||||
.withMessage("Value must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofWhenEmptyThrowsException() {
|
||||
void ofWhenEmptyThrowsException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> EndpointId.of("")).withMessage("Value must not be empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofWhenContainsSlashThrowsException() {
|
||||
void ofWhenContainsSlashThrowsException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> EndpointId.of("foo/bar"))
|
||||
.withMessage("Value must only contain valid chars");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofWhenHasBadCharThrowsException() {
|
||||
void ofWhenHasBadCharThrowsException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> EndpointId.of("foo!bar"))
|
||||
.withMessage("Value must only contain valid chars");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofWhenStartsWithNumberThrowsException() {
|
||||
void ofWhenStartsWithNumberThrowsException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> EndpointId.of("1foo"))
|
||||
.withMessage("Value must not start with a number");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofWhenStartsWithUppercaseLetterThrowsException() {
|
||||
void ofWhenStartsWithUppercaseLetterThrowsException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> EndpointId.of("Foo"))
|
||||
.withMessage("Value must not start with an uppercase letter");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofWhenContainsDotIsValid() {
|
||||
void ofWhenContainsDotIsValid() {
|
||||
// Ideally we wouldn't support this but there are existing endpoints using the
|
||||
// pattern. See gh-14773
|
||||
EndpointId endpointId = EndpointId.of("foo.bar");
|
||||
@@ -77,7 +77,7 @@ public class EndpointIdTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofWhenContainsDashIsValid() {
|
||||
void ofWhenContainsDashIsValid() {
|
||||
// Ideally we wouldn't support this but there are existing endpoints using the
|
||||
// pattern. See gh-14773
|
||||
EndpointId endpointId = EndpointId.of("foo-bar");
|
||||
@@ -85,7 +85,7 @@ public class EndpointIdTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ofWhenContainsDeprecatedCharsLogsWarning(CapturedOutput capturedOutput) {
|
||||
void ofWhenContainsDeprecatedCharsLogsWarning(CapturedOutput capturedOutput) {
|
||||
EndpointId.resetLoggedWarnings();
|
||||
EndpointId.of("foo-bar");
|
||||
assertThat(capturedOutput.toString())
|
||||
@@ -93,7 +93,7 @@ public class EndpointIdTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsAndHashCode() {
|
||||
void equalsAndHashCode() {
|
||||
EndpointId one = EndpointId.of("foobar1");
|
||||
EndpointId two = EndpointId.of("fooBar1");
|
||||
EndpointId three = EndpointId.of("foo-bar1");
|
||||
@@ -106,17 +106,17 @@ public class EndpointIdTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toLowerCaseStringReturnsLowercase() {
|
||||
void toLowerCaseStringReturnsLowercase() {
|
||||
assertThat(EndpointId.of("fooBar").toLowerCaseString()).isEqualTo("foobar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringReturnsString() {
|
||||
void toStringReturnsString() {
|
||||
assertThat(EndpointId.of("fooBar").toString()).isEqualTo("fooBar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fromPropertyValueStripsDashes() {
|
||||
void fromPropertyValueStripsDashes() {
|
||||
EndpointId fromPropertyValue = EndpointId.fromPropertyValue("foo-bar");
|
||||
assertThat(fromPropertyValue).isEqualTo(EndpointId.of("fooBar"));
|
||||
}
|
||||
|
||||
@@ -26,10 +26,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class SanitizerTests {
|
||||
class SanitizerTests {
|
||||
|
||||
@Test
|
||||
public void defaults() {
|
||||
void defaults() {
|
||||
Sanitizer sanitizer = new Sanitizer();
|
||||
assertThat(sanitizer.sanitize("password", "secret")).isEqualTo("******");
|
||||
assertThat(sanitizer.sanitize("my-password", "secret")).isEqualTo("******");
|
||||
@@ -43,7 +43,7 @@ public class SanitizerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void regex() {
|
||||
void regex() {
|
||||
Sanitizer sanitizer = new Sanitizer(".*lock.*");
|
||||
assertThat(sanitizer.sanitize("verylOCkish", "secret")).isEqualTo("******");
|
||||
assertThat(sanitizer.sanitize("veryokish", "secret")).isEqualTo("secret");
|
||||
|
||||
@@ -32,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class DiscoveredOperationMethodTests {
|
||||
class DiscoveredOperationMethodTests {
|
||||
|
||||
@Test
|
||||
public void createWhenAnnotationAttributesIsNullShouldThrowException() {
|
||||
void createWhenAnnotationAttributesIsNullShouldThrowException() {
|
||||
Method method = ReflectionUtils.findMethod(getClass(), "example");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new DiscoveredOperationMethod(method, OperationType.READ, null))
|
||||
@@ -43,7 +43,7 @@ public class DiscoveredOperationMethodTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProducesMediaTypesShouldReturnMediaTypes() {
|
||||
void getProducesMediaTypesShouldReturnMediaTypes() {
|
||||
Method method = ReflectionUtils.findMethod(getClass(), "example");
|
||||
AnnotationAttributes annotationAttributes = new AnnotationAttributes();
|
||||
String[] produces = new String[] { "application/json" };
|
||||
|
||||
@@ -43,7 +43,7 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class DiscoveredOperationsFactoryTests {
|
||||
class DiscoveredOperationsFactoryTests {
|
||||
|
||||
private TestDiscoveredOperationsFactory factory;
|
||||
|
||||
@@ -59,7 +59,7 @@ public class DiscoveredOperationsFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createOperationsWhenHasReadMethodShouldCreateOperation() {
|
||||
void createOperationsWhenHasReadMethodShouldCreateOperation() {
|
||||
Collection<TestOperation> operations = this.factory.createOperations(EndpointId.of("test"), new ExampleRead());
|
||||
assertThat(operations).hasSize(1);
|
||||
TestOperation operation = getFirst(operations);
|
||||
@@ -67,7 +67,7 @@ public class DiscoveredOperationsFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createOperationsWhenHasWriteMethodShouldCreateOperation() {
|
||||
void createOperationsWhenHasWriteMethodShouldCreateOperation() {
|
||||
Collection<TestOperation> operations = this.factory.createOperations(EndpointId.of("test"), new ExampleWrite());
|
||||
assertThat(operations).hasSize(1);
|
||||
TestOperation operation = getFirst(operations);
|
||||
@@ -75,7 +75,7 @@ public class DiscoveredOperationsFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createOperationsWhenHasDeleteMethodShouldCreateOperation() {
|
||||
void createOperationsWhenHasDeleteMethodShouldCreateOperation() {
|
||||
Collection<TestOperation> operations = this.factory.createOperations(EndpointId.of("test"),
|
||||
new ExampleDelete());
|
||||
assertThat(operations).hasSize(1);
|
||||
@@ -84,7 +84,7 @@ public class DiscoveredOperationsFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createOperationsWhenMultipleShouldReturnMultiple() {
|
||||
void createOperationsWhenMultipleShouldReturnMultiple() {
|
||||
Collection<TestOperation> operations = this.factory.createOperations(EndpointId.of("test"),
|
||||
new ExampleMultiple());
|
||||
assertThat(operations).hasSize(2);
|
||||
@@ -93,7 +93,7 @@ public class DiscoveredOperationsFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createOperationsShouldProvideOperationMethod() {
|
||||
void createOperationsShouldProvideOperationMethod() {
|
||||
TestOperation operation = getFirst(
|
||||
this.factory.createOperations(EndpointId.of("test"), new ExampleWithParams()));
|
||||
OperationMethod operationMethod = operation.getOperationMethod();
|
||||
@@ -102,7 +102,7 @@ public class DiscoveredOperationsFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createOperationsShouldProviderInvoker() {
|
||||
void createOperationsShouldProviderInvoker() {
|
||||
TestOperation operation = getFirst(
|
||||
this.factory.createOperations(EndpointId.of("test"), new ExampleWithParams()));
|
||||
Map<String, Object> params = Collections.singletonMap("name", 123);
|
||||
@@ -111,7 +111,7 @@ public class DiscoveredOperationsFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createOperationShouldApplyAdvisors() {
|
||||
void createOperationShouldApplyAdvisors() {
|
||||
TestOperationInvokerAdvisor advisor = new TestOperationInvokerAdvisor();
|
||||
this.invokerAdvisors.add(advisor);
|
||||
TestOperation operation = getFirst(this.factory.createOperations(EndpointId.of("test"), new ExampleRead()));
|
||||
|
||||
@@ -37,23 +37,23 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class DiscovererEndpointFilterTests {
|
||||
class DiscovererEndpointFilterTests {
|
||||
|
||||
@Test
|
||||
public void createWhenDiscovererIsNullShouldThrowException() {
|
||||
void createWhenDiscovererIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new TestDiscovererEndpointFilter(null))
|
||||
.withMessageContaining("Discoverer must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenDiscoveredByDiscovererShouldReturnTrue() {
|
||||
void matchWhenDiscoveredByDiscovererShouldReturnTrue() {
|
||||
DiscovererEndpointFilter filter = new TestDiscovererEndpointFilter(TestDiscovererA.class);
|
||||
DiscoveredEndpoint<?> endpoint = mockDiscoveredEndpoint(TestDiscovererA.class);
|
||||
assertThat(filter.match(endpoint)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenNotDiscoveredByDiscovererShouldReturnFalse() {
|
||||
void matchWhenNotDiscoveredByDiscovererShouldReturnFalse() {
|
||||
DiscovererEndpointFilter filter = new TestDiscovererEndpointFilter(TestDiscovererA.class);
|
||||
DiscoveredEndpoint<?> endpoint = mockDiscoveredEndpoint(TestDiscovererB.class);
|
||||
assertThat(filter.match(endpoint)).isFalse();
|
||||
|
||||
@@ -64,10 +64,10 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class EndpointDiscovererTests {
|
||||
class EndpointDiscovererTests {
|
||||
|
||||
@Test
|
||||
public void createWhenApplicationContextIsNullShouldThrowException() {
|
||||
void createWhenApplicationContextIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new TestEndpointDiscoverer(null, mock(ParameterValueMapper.class),
|
||||
Collections.emptyList(), Collections.emptyList()))
|
||||
@@ -75,7 +75,7 @@ public class EndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenParameterValueMapperIsNullShouldThrowException() {
|
||||
void createWhenParameterValueMapperIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new TestEndpointDiscoverer(mock(ApplicationContext.class), null,
|
||||
Collections.emptyList(), Collections.emptyList()))
|
||||
@@ -83,7 +83,7 @@ public class EndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenInvokerAdvisorsIsNullShouldThrowException() {
|
||||
void createWhenInvokerAdvisorsIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new TestEndpointDiscoverer(mock(ApplicationContext.class),
|
||||
mock(ParameterValueMapper.class), null, Collections.emptyList()))
|
||||
@@ -91,7 +91,7 @@ public class EndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenFiltersIsNullShouldThrowException() {
|
||||
void createWhenFiltersIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new TestEndpointDiscoverer(mock(ApplicationContext.class),
|
||||
mock(ParameterValueMapper.class), Collections.emptyList(), null))
|
||||
@@ -99,7 +99,7 @@ public class EndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
||||
void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
||||
load(EmptyConfiguration.class, (context) -> {
|
||||
TestEndpointDiscoverer discoverer = new TestEndpointDiscoverer(context);
|
||||
Collection<TestExposableEndpoint> endpoints = discoverer.getEndpoints();
|
||||
@@ -108,19 +108,19 @@ public class EndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenHasEndpointShouldReturnEndpoint() {
|
||||
void getEndpointsWhenHasEndpointShouldReturnEndpoint() {
|
||||
load(TestEndpointConfiguration.class, this::hasTestEndpoint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenHasEndpointInParentContextShouldReturnEndpoint() {
|
||||
void getEndpointsWhenHasEndpointInParentContextShouldReturnEndpoint() {
|
||||
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext(
|
||||
TestEndpointConfiguration.class);
|
||||
loadWithParent(parent, EmptyConfiguration.class, this::hasTestEndpoint);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenHasSubclassedEndpointShouldReturnEndpoint() {
|
||||
void getEndpointsWhenHasSubclassedEndpointShouldReturnEndpoint() {
|
||||
load(TestEndpointSubclassConfiguration.class, (context) -> {
|
||||
TestEndpointDiscoverer discoverer = new TestEndpointDiscoverer(context);
|
||||
Map<EndpointId, TestExposableEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
|
||||
@@ -134,7 +134,7 @@ public class EndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenTwoEndpointsHaveTheSameIdShouldThrowException() {
|
||||
void getEndpointsWhenTwoEndpointsHaveTheSameIdShouldThrowException() {
|
||||
load(ClashingEndpointConfiguration.class,
|
||||
(context) -> assertThatIllegalStateException()
|
||||
.isThrownBy(new TestEndpointDiscoverer(context)::getEndpoints)
|
||||
@@ -142,7 +142,7 @@ public class EndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenEndpointsArePrefixedWithScopedTargetShouldRegisterOnlyOneEndpoint() {
|
||||
void getEndpointsWhenEndpointsArePrefixedWithScopedTargetShouldRegisterOnlyOneEndpoint() {
|
||||
load(ScopedTargetEndpointConfiguration.class, (context) -> {
|
||||
TestEndpoint expectedEndpoint = context.getBean("testEndpoint", TestEndpoint.class);
|
||||
Collection<TestExposableEndpoint> endpoints = new TestEndpointDiscoverer(context).getEndpoints();
|
||||
@@ -151,7 +151,7 @@ public class EndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenTtlSetToZeroShouldNotCacheInvokeCalls() {
|
||||
void getEndpointsWhenTtlSetToZeroShouldNotCacheInvokeCalls() {
|
||||
load(TestEndpointConfiguration.class, (context) -> {
|
||||
TestEndpointDiscoverer discoverer = new TestEndpointDiscoverer(context, (endpointId) -> 0L);
|
||||
Map<EndpointId, TestExposableEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
|
||||
@@ -163,7 +163,7 @@ public class EndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenTtlSetByIdAndIdDoesNotMatchShouldNotCacheInvokeCalls() {
|
||||
void getEndpointsWhenTtlSetByIdAndIdDoesNotMatchShouldNotCacheInvokeCalls() {
|
||||
load(TestEndpointConfiguration.class, (context) -> {
|
||||
TestEndpointDiscoverer discoverer = new TestEndpointDiscoverer(context,
|
||||
(endpointId) -> (endpointId.equals("foo") ? 500L : 0L));
|
||||
@@ -176,7 +176,7 @@ public class EndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenTtlSetByIdAndIdMatchesShouldCacheInvokeCalls() {
|
||||
void getEndpointsWhenTtlSetByIdAndIdMatchesShouldCacheInvokeCalls() {
|
||||
load(TestEndpointConfiguration.class, (context) -> {
|
||||
TestEndpointDiscoverer discoverer = new TestEndpointDiscoverer(context,
|
||||
(endpointId) -> (endpointId.equals(EndpointId.of("test")) ? 500L : 0L));
|
||||
@@ -194,7 +194,7 @@ public class EndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenHasSpecializedFiltersInNonSpecializedDiscovererShouldFilterEndpoints() {
|
||||
void getEndpointsWhenHasSpecializedFiltersInNonSpecializedDiscovererShouldFilterEndpoints() {
|
||||
load(SpecializedEndpointsConfiguration.class, (context) -> {
|
||||
TestEndpointDiscoverer discoverer = new TestEndpointDiscoverer(context);
|
||||
Map<EndpointId, TestExposableEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
|
||||
@@ -203,7 +203,7 @@ public class EndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenHasSpecializedFiltersInSpecializedDiscovererShouldNotFilterEndpoints() {
|
||||
void getEndpointsWhenHasSpecializedFiltersInSpecializedDiscovererShouldNotFilterEndpoints() {
|
||||
load(SpecializedEndpointsConfiguration.class, (context) -> {
|
||||
SpecializedEndpointDiscoverer discoverer = new SpecializedEndpointDiscoverer(context);
|
||||
Map<EndpointId, SpecializedExposableEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
|
||||
@@ -212,7 +212,7 @@ public class EndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsShouldApplyExtensions() {
|
||||
void getEndpointsShouldApplyExtensions() {
|
||||
load(SpecializedEndpointsConfiguration.class, (context) -> {
|
||||
SpecializedEndpointDiscoverer discoverer = new SpecializedEndpointDiscoverer(context);
|
||||
Map<EndpointId, SpecializedExposableEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
|
||||
@@ -223,7 +223,7 @@ public class EndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointShouldFindParentExtension() {
|
||||
void getEndpointShouldFindParentExtension() {
|
||||
load(SubSpecializedEndpointsConfiguration.class, (context) -> {
|
||||
SpecializedEndpointDiscoverer discoverer = new SpecializedEndpointDiscoverer(context);
|
||||
Map<EndpointId, SpecializedExposableEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
|
||||
@@ -237,7 +237,7 @@ public class EndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsShouldApplyFilters() {
|
||||
void getEndpointsShouldApplyFilters() {
|
||||
load(SpecializedEndpointsConfiguration.class, (context) -> {
|
||||
EndpointFilter<SpecializedExposableEndpoint> filter = (endpoint) -> {
|
||||
EndpointId id = endpoint.getEndpointId();
|
||||
|
||||
@@ -39,10 +39,10 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class ConversionServiceParameterValueMapperTests {
|
||||
class ConversionServiceParameterValueMapperTests {
|
||||
|
||||
@Test
|
||||
public void mapParameterShouldDelegateToConversionService() {
|
||||
void mapParameterShouldDelegateToConversionService() {
|
||||
DefaultFormattingConversionService conversionService = spy(new DefaultFormattingConversionService());
|
||||
ConversionServiceParameterValueMapper mapper = new ConversionServiceParameterValueMapper(conversionService);
|
||||
Object mapped = mapper.mapParameterValue(new TestOperationParameter(Integer.class), "123");
|
||||
@@ -51,7 +51,7 @@ public class ConversionServiceParameterValueMapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapParameterWhenConversionServiceFailsShouldThrowParameterMappingException() {
|
||||
void mapParameterWhenConversionServiceFailsShouldThrowParameterMappingException() {
|
||||
ConversionService conversionService = mock(ConversionService.class);
|
||||
RuntimeException error = new RuntimeException();
|
||||
given(conversionService.convert(any(), any())).willThrow(error);
|
||||
@@ -66,7 +66,7 @@ public class ConversionServiceParameterValueMapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createShouldRegisterIsoOffsetDateTimeConverter() {
|
||||
void createShouldRegisterIsoOffsetDateTimeConverter() {
|
||||
ConversionServiceParameterValueMapper mapper = new ConversionServiceParameterValueMapper();
|
||||
Object mapped = mapper.mapParameterValue(new TestOperationParameter(OffsetDateTime.class),
|
||||
"2011-12-03T10:15:30+01:00");
|
||||
@@ -74,7 +74,7 @@ public class ConversionServiceParameterValueMapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithConversionServiceShouldNotRegisterIsoOffsetDateTimeConverter() {
|
||||
void createWithConversionServiceShouldNotRegisterIsoOffsetDateTimeConverter() {
|
||||
ConversionService conversionService = new DefaultConversionService();
|
||||
ConversionServiceParameterValueMapper mapper = new ConversionServiceParameterValueMapper(conversionService);
|
||||
assertThatExceptionOfType(ParameterMappingException.class).isThrownBy(() -> mapper
|
||||
|
||||
@@ -29,17 +29,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class IsoOffsetDateTimeConverterTests {
|
||||
class IsoOffsetDateTimeConverterTests {
|
||||
|
||||
@Test
|
||||
public void convertShouldConvertIsoDate() {
|
||||
void convertShouldConvertIsoDate() {
|
||||
IsoOffsetDateTimeConverter converter = new IsoOffsetDateTimeConverter();
|
||||
OffsetDateTime time = converter.convert("2011-12-03T10:15:30+01:00");
|
||||
assertThat(time).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerConverterShouldRegister() {
|
||||
void registerConverterShouldRegister() {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
IsoOffsetDateTimeConverter.registerConverter(service);
|
||||
OffsetDateTime time = service.convert("2011-12-03T10:15:30+01:00", OffsetDateTime.class);
|
||||
|
||||
@@ -30,30 +30,30 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class OperationMethodParameterTests {
|
||||
class OperationMethodParameterTests {
|
||||
|
||||
private Method method = ReflectionUtils.findMethod(getClass(), "example", String.class, String.class);
|
||||
|
||||
@Test
|
||||
public void getNameShouldReturnName() {
|
||||
void getNameShouldReturnName() {
|
||||
OperationMethodParameter parameter = new OperationMethodParameter("name", this.method.getParameters()[0]);
|
||||
assertThat(parameter.getName()).isEqualTo("name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTypeShouldReturnType() {
|
||||
void getTypeShouldReturnType() {
|
||||
OperationMethodParameter parameter = new OperationMethodParameter("name", this.method.getParameters()[0]);
|
||||
assertThat(parameter.getType()).isEqualTo(String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isMandatoryWhenNoAnnotationShouldReturnTrue() {
|
||||
void isMandatoryWhenNoAnnotationShouldReturnTrue() {
|
||||
OperationMethodParameter parameter = new OperationMethodParameter("name", this.method.getParameters()[0]);
|
||||
assertThat(parameter.isMandatory()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isMandatoryWhenNullableAnnotationShouldReturnFalse() {
|
||||
void isMandatoryWhenNullableAnnotationShouldReturnFalse() {
|
||||
OperationMethodParameter parameter = new OperationMethodParameter("name", this.method.getParameters()[1]);
|
||||
assertThat(parameter.isMandatory()).isFalse();
|
||||
}
|
||||
|
||||
@@ -42,27 +42,27 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class OperationMethodParametersTests {
|
||||
class OperationMethodParametersTests {
|
||||
|
||||
private Method exampleMethod = ReflectionUtils.findMethod(getClass(), "example", String.class);
|
||||
|
||||
private Method exampleNoParamsMethod = ReflectionUtils.findMethod(getClass(), "exampleNoParams");
|
||||
|
||||
@Test
|
||||
public void createWhenMethodIsNullShouldThrowException() {
|
||||
void createWhenMethodIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new OperationMethodParameters(null, mock(ParameterNameDiscoverer.class)))
|
||||
.withMessageContaining("Method must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenParameterNameDiscovererIsNullShouldThrowException() {
|
||||
void createWhenParameterNameDiscovererIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new OperationMethodParameters(this.exampleMethod, null))
|
||||
.withMessageContaining("ParameterNameDiscoverer must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenParameterNameDiscovererReturnsNullShouldThrowException() {
|
||||
void createWhenParameterNameDiscovererReturnsNullShouldThrowException() {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(
|
||||
() -> new OperationMethodParameters(this.exampleMethod, mock(ParameterNameDiscoverer.class)))
|
||||
@@ -70,28 +70,28 @@ public class OperationMethodParametersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasParametersWhenHasParametersShouldReturnTrue() {
|
||||
void hasParametersWhenHasParametersShouldReturnTrue() {
|
||||
OperationMethodParameters parameters = new OperationMethodParameters(this.exampleMethod,
|
||||
new DefaultParameterNameDiscoverer());
|
||||
assertThat(parameters.hasParameters()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasParametersWhenHasNoParametersShouldReturnFalse() {
|
||||
void hasParametersWhenHasNoParametersShouldReturnFalse() {
|
||||
OperationMethodParameters parameters = new OperationMethodParameters(this.exampleNoParamsMethod,
|
||||
new DefaultParameterNameDiscoverer());
|
||||
assertThat(parameters.hasParameters()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParameterCountShouldReturnParameterCount() {
|
||||
void getParameterCountShouldReturnParameterCount() {
|
||||
OperationMethodParameters parameters = new OperationMethodParameters(this.exampleMethod,
|
||||
new DefaultParameterNameDiscoverer());
|
||||
assertThat(parameters.getParameterCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void iteratorShouldIterateOperationParameters() {
|
||||
void iteratorShouldIterateOperationParameters() {
|
||||
OperationMethodParameters parameters = new OperationMethodParameters(this.exampleMethod,
|
||||
new DefaultParameterNameDiscoverer());
|
||||
Iterator<OperationParameter> iterator = parameters.iterator();
|
||||
@@ -100,7 +100,7 @@ public class OperationMethodParametersTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void streamShouldStreamOperationParameters() {
|
||||
void streamShouldStreamOperationParameters() {
|
||||
OperationMethodParameters parameters = new OperationMethodParameters(this.exampleMethod,
|
||||
new DefaultParameterNameDiscoverer());
|
||||
assertParameters(parameters.stream());
|
||||
|
||||
@@ -32,36 +32,36 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class OperationMethodTests {
|
||||
class OperationMethodTests {
|
||||
|
||||
private Method exampleMethod = ReflectionUtils.findMethod(getClass(), "example", String.class);
|
||||
|
||||
@Test
|
||||
public void createWhenMethodIsNullShouldThrowException() {
|
||||
void createWhenMethodIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new OperationMethod(null, OperationType.READ))
|
||||
.withMessageContaining("Method must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenOperationTypeIsNullShouldThrowException() {
|
||||
void createWhenOperationTypeIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new OperationMethod(this.exampleMethod, null))
|
||||
.withMessageContaining("OperationType must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMethodShouldReturnMethod() {
|
||||
void getMethodShouldReturnMethod() {
|
||||
OperationMethod operationMethod = new OperationMethod(this.exampleMethod, OperationType.READ);
|
||||
assertThat(operationMethod.getMethod()).isEqualTo(this.exampleMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOperationTypeShouldReturnOperationType() {
|
||||
void getOperationTypeShouldReturnOperationType() {
|
||||
OperationMethod operationMethod = new OperationMethod(this.exampleMethod, OperationType.READ);
|
||||
assertThat(operationMethod.getOperationType()).isEqualTo(OperationType.READ);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParametersShouldReturnParameters() {
|
||||
void getParametersShouldReturnParameters() {
|
||||
OperationMethod operationMethod = new OperationMethod(this.exampleMethod, OperationType.READ);
|
||||
OperationParameters parameters = operationMethod.getParameters();
|
||||
assertThat(parameters.getParameterCount()).isEqualTo(1);
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class ReflectiveOperationInvokerTests {
|
||||
class ReflectiveOperationInvokerTests {
|
||||
|
||||
private Example target;
|
||||
|
||||
@@ -56,28 +56,28 @@ public class ReflectiveOperationInvokerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenTargetIsNullShouldThrowException() {
|
||||
void createWhenTargetIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ReflectiveOperationInvoker(null, this.operationMethod, this.parameterValueMapper))
|
||||
.withMessageContaining("Target must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenOperationMethodIsNullShouldThrowException() {
|
||||
void createWhenOperationMethodIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ReflectiveOperationInvoker(this.target, null, this.parameterValueMapper))
|
||||
.withMessageContaining("OperationMethod must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenParameterValueMapperIsNullShouldThrowException() {
|
||||
void createWhenParameterValueMapperIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new ReflectiveOperationInvoker(this.target, this.operationMethod, null))
|
||||
.withMessageContaining("ParameterValueMapper must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeShouldInvokeMethod() {
|
||||
void invokeShouldInvokeMethod() {
|
||||
ReflectiveOperationInvoker invoker = new ReflectiveOperationInvoker(this.target, this.operationMethod,
|
||||
this.parameterValueMapper);
|
||||
Object result = invoker
|
||||
@@ -86,7 +86,7 @@ public class ReflectiveOperationInvokerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeWhenMissingNonNullableArgumentShouldThrowException() {
|
||||
void invokeWhenMissingNonNullableArgumentShouldThrowException() {
|
||||
ReflectiveOperationInvoker invoker = new ReflectiveOperationInvoker(this.target, this.operationMethod,
|
||||
this.parameterValueMapper);
|
||||
assertThatExceptionOfType(MissingParametersException.class).isThrownBy(() -> invoker
|
||||
@@ -94,7 +94,7 @@ public class ReflectiveOperationInvokerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeWhenMissingNullableArgumentShouldInvoke() {
|
||||
void invokeWhenMissingNullableArgumentShouldInvoke() {
|
||||
OperationMethod operationMethod = new OperationMethod(
|
||||
ReflectionUtils.findMethod(Example.class, "reverseNullable", String.class), OperationType.READ);
|
||||
ReflectiveOperationInvoker invoker = new ReflectiveOperationInvoker(this.target, operationMethod,
|
||||
@@ -105,7 +105,7 @@ public class ReflectiveOperationInvokerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeShouldResolveParameters() {
|
||||
void invokeShouldResolveParameters() {
|
||||
ReflectiveOperationInvoker invoker = new ReflectiveOperationInvoker(this.target, this.operationMethod,
|
||||
this.parameterValueMapper);
|
||||
Object result = invoker
|
||||
|
||||
@@ -44,7 +44,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class CachingOperationInvokerAdvisorTests {
|
||||
class CachingOperationInvokerAdvisorTests {
|
||||
|
||||
@Mock
|
||||
private OperationInvoker invoker;
|
||||
@@ -61,7 +61,7 @@ public class CachingOperationInvokerAdvisorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWhenOperationIsNotReadShouldNotAddAdvise() {
|
||||
void applyWhenOperationIsNotReadShouldNotAddAdvise() {
|
||||
OperationParameters parameters = getParameters("get");
|
||||
OperationInvoker advised = this.advisor.apply(EndpointId.of("foo"), OperationType.WRITE, parameters,
|
||||
this.invoker);
|
||||
@@ -69,7 +69,7 @@ public class CachingOperationInvokerAdvisorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWhenHasAtLeaseOneMandatoryParameterShouldNotAddAdvise() {
|
||||
void applyWhenHasAtLeaseOneMandatoryParameterShouldNotAddAdvise() {
|
||||
OperationParameters parameters = getParameters("getWithParameters", String.class, String.class);
|
||||
OperationInvoker advised = this.advisor.apply(EndpointId.of("foo"), OperationType.READ, parameters,
|
||||
this.invoker);
|
||||
@@ -77,7 +77,7 @@ public class CachingOperationInvokerAdvisorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWhenTimeToLiveReturnsNullShouldNotAddAdvise() {
|
||||
void applyWhenTimeToLiveReturnsNullShouldNotAddAdvise() {
|
||||
OperationParameters parameters = getParameters("get");
|
||||
given(this.timeToLive.apply(any())).willReturn(null);
|
||||
OperationInvoker advised = this.advisor.apply(EndpointId.of("foo"), OperationType.READ, parameters,
|
||||
@@ -87,7 +87,7 @@ public class CachingOperationInvokerAdvisorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWhenTimeToLiveIsZeroShouldNotAddAdvise() {
|
||||
void applyWhenTimeToLiveIsZeroShouldNotAddAdvise() {
|
||||
OperationParameters parameters = getParameters("get");
|
||||
given(this.timeToLive.apply(any())).willReturn(0L);
|
||||
OperationInvoker advised = this.advisor.apply(EndpointId.of("foo"), OperationType.READ, parameters,
|
||||
@@ -97,21 +97,21 @@ public class CachingOperationInvokerAdvisorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyShouldAddCacheAdvise() {
|
||||
void applyShouldAddCacheAdvise() {
|
||||
OperationParameters parameters = getParameters("get");
|
||||
given(this.timeToLive.apply(any())).willReturn(100L);
|
||||
assertAdviseIsApplied(parameters);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWithAllOptionalParametersShouldAddAdvise() {
|
||||
void applyWithAllOptionalParametersShouldAddAdvise() {
|
||||
OperationParameters parameters = getParameters("getWithAllOptionalParameters", String.class, String.class);
|
||||
given(this.timeToLive.apply(any())).willReturn(100L);
|
||||
assertAdviseIsApplied(parameters);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyWithSecurityContextShouldAddAdvise() {
|
||||
void applyWithSecurityContextShouldAddAdvise() {
|
||||
OperationParameters parameters = getParameters("getWithSecurityContext", SecurityContext.class, String.class);
|
||||
given(this.timeToLive.apply(any())).willReturn(100L);
|
||||
assertAdviseIsApplied(parameters);
|
||||
|
||||
@@ -40,22 +40,22 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class CachingOperationInvokerTests {
|
||||
class CachingOperationInvokerTests {
|
||||
|
||||
@Test
|
||||
public void createInstanceWithTtlSetToZero() {
|
||||
void createInstanceWithTtlSetToZero() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new CachingOperationInvoker(mock(OperationInvoker.class), 0))
|
||||
.withMessageContaining("TimeToLive");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cacheInTtlRangeWithNoParameter() {
|
||||
void cacheInTtlRangeWithNoParameter() {
|
||||
assertCacheIsUsed(Collections.emptyMap());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cacheInTtlWithNullParameters() {
|
||||
void cacheInTtlWithNullParameters() {
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("first", null);
|
||||
parameters.put("second", null);
|
||||
@@ -77,7 +77,7 @@ public class CachingOperationInvokerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void targetAlwaysInvokedWithParameters() {
|
||||
void targetAlwaysInvokedWithParameters() {
|
||||
OperationInvoker target = mock(OperationInvoker.class);
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("test", "value");
|
||||
@@ -92,7 +92,7 @@ public class CachingOperationInvokerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void targetAlwaysInvokedWithPrincipal() {
|
||||
void targetAlwaysInvokedWithPrincipal() {
|
||||
OperationInvoker target = mock(OperationInvoker.class);
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
SecurityContext securityContext = mock(SecurityContext.class);
|
||||
@@ -107,7 +107,7 @@ public class CachingOperationInvokerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void targetInvokedWhenCacheExpires() throws InterruptedException {
|
||||
void targetInvokedWhenCacheExpires() throws InterruptedException {
|
||||
OperationInvoker target = mock(OperationInvoker.class);
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
InvocationContext context = new InvocationContext(mock(SecurityContext.class), parameters);
|
||||
|
||||
@@ -48,7 +48,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class EndpointMBeanTests {
|
||||
class EndpointMBeanTests {
|
||||
|
||||
private static final Object[] NO_PARAMS = {};
|
||||
|
||||
@@ -59,35 +59,35 @@ public class EndpointMBeanTests {
|
||||
private TestJmxOperationResponseMapper responseMapper = new TestJmxOperationResponseMapper();
|
||||
|
||||
@Test
|
||||
public void createWhenResponseMapperIsNullShouldThrowException() {
|
||||
void createWhenResponseMapperIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new EndpointMBean(null, null, mock(ExposableJmxEndpoint.class)))
|
||||
.withMessageContaining("ResponseMapper must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenEndpointIsNullShouldThrowException() {
|
||||
void createWhenEndpointIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new EndpointMBean(mock(JmxOperationResponseMapper.class), null, null))
|
||||
.withMessageContaining("Endpoint must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMBeanInfoShouldReturnMBeanInfo() {
|
||||
void getMBeanInfoShouldReturnMBeanInfo() {
|
||||
EndpointMBean bean = createEndpointMBean();
|
||||
MBeanInfo info = bean.getMBeanInfo();
|
||||
assertThat(info.getDescription()).isEqualTo("MBean operations for endpoint test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeShouldInvokeJmxOperation() throws MBeanException, ReflectionException {
|
||||
void invokeShouldInvokeJmxOperation() throws MBeanException, ReflectionException {
|
||||
EndpointMBean bean = createEndpointMBean();
|
||||
Object result = bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE);
|
||||
assertThat(result).isEqualTo("result");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeWhenOperationFailedShouldTranslateException() throws MBeanException, ReflectionException {
|
||||
void invokeWhenOperationFailedShouldTranslateException() throws MBeanException, ReflectionException {
|
||||
TestExposableJmxEndpoint endpoint = new TestExposableJmxEndpoint(new TestJmxOperation((arguments) -> {
|
||||
throw new FatalBeanException("test failure");
|
||||
}));
|
||||
@@ -99,8 +99,7 @@ public class EndpointMBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeWhenOperationFailedWithJdkExceptionShouldReuseException()
|
||||
throws MBeanException, ReflectionException {
|
||||
void invokeWhenOperationFailedWithJdkExceptionShouldReuseException() throws MBeanException, ReflectionException {
|
||||
TestExposableJmxEndpoint endpoint = new TestExposableJmxEndpoint(new TestJmxOperation((arguments) -> {
|
||||
throw new UnsupportedOperationException("test failure");
|
||||
}));
|
||||
@@ -111,7 +110,7 @@ public class EndpointMBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeWhenActionNameIsNotAnOperationShouldThrowException() throws MBeanException, ReflectionException {
|
||||
void invokeWhenActionNameIsNotAnOperationShouldThrowException() throws MBeanException, ReflectionException {
|
||||
EndpointMBean bean = createEndpointMBean();
|
||||
assertThatExceptionOfType(ReflectionException.class)
|
||||
.isThrownBy(() -> bean.invoke("missingOperation", NO_PARAMS, NO_SIGNATURE))
|
||||
@@ -120,7 +119,7 @@ public class EndpointMBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeShouldInvokeJmxOperationWithBeanClassLoader() throws ReflectionException, MBeanException {
|
||||
void invokeShouldInvokeJmxOperationWithBeanClassLoader() throws ReflectionException, MBeanException {
|
||||
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
TestExposableJmxEndpoint endpoint = new TestExposableJmxEndpoint(
|
||||
new TestJmxOperation((arguments) -> ClassUtils.getDefaultClassLoader()));
|
||||
@@ -132,7 +131,7 @@ public class EndpointMBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeWhenOperationIsInvalidShouldThrowException() throws MBeanException, ReflectionException {
|
||||
void invokeWhenOperationIsInvalidShouldThrowException() throws MBeanException, ReflectionException {
|
||||
TestJmxOperation operation = new TestJmxOperation() {
|
||||
|
||||
@Override
|
||||
@@ -149,7 +148,7 @@ public class EndpointMBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeWhenMonoResultShouldBlockOnMono() throws MBeanException, ReflectionException {
|
||||
void invokeWhenMonoResultShouldBlockOnMono() throws MBeanException, ReflectionException {
|
||||
TestExposableJmxEndpoint endpoint = new TestExposableJmxEndpoint(
|
||||
new TestJmxOperation((arguments) -> Mono.just("monoResult")));
|
||||
EndpointMBean bean = new EndpointMBean(this.responseMapper, null, endpoint);
|
||||
@@ -158,7 +157,7 @@ public class EndpointMBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeShouldCallResponseMapper() throws MBeanException, ReflectionException {
|
||||
void invokeShouldCallResponseMapper() throws MBeanException, ReflectionException {
|
||||
TestJmxOperationResponseMapper responseMapper = spy(this.responseMapper);
|
||||
EndpointMBean bean = new EndpointMBean(responseMapper, null, this.endpoint);
|
||||
bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE);
|
||||
@@ -167,15 +166,14 @@ public class EndpointMBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAttributeShouldThrowException()
|
||||
throws AttributeNotFoundException, MBeanException, ReflectionException {
|
||||
void getAttributeShouldThrowException() throws AttributeNotFoundException, MBeanException, ReflectionException {
|
||||
EndpointMBean bean = createEndpointMBean();
|
||||
assertThatExceptionOfType(AttributeNotFoundException.class).isThrownBy(() -> bean.getAttribute("test"))
|
||||
.withMessageContaining("EndpointMBeans do not support attributes");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAttributeShouldThrowException()
|
||||
void setAttributeShouldThrowException()
|
||||
throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
|
||||
EndpointMBean bean = createEndpointMBean();
|
||||
assertThatExceptionOfType(AttributeNotFoundException.class)
|
||||
@@ -184,14 +182,14 @@ public class EndpointMBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAttributesShouldReturnEmptyAttributeList() {
|
||||
void getAttributesShouldReturnEmptyAttributeList() {
|
||||
EndpointMBean bean = createEndpointMBean();
|
||||
AttributeList attributes = bean.getAttributes(new String[] { "test" });
|
||||
assertThat(attributes).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setAttributesShouldReturnEmptyAttributeList() {
|
||||
void setAttributesShouldReturnEmptyAttributeList() {
|
||||
EndpointMBean bean = createEndpointMBean();
|
||||
AttributeList sourceAttributes = new AttributeList();
|
||||
sourceAttributes.add(new Attribute("test", "test"));
|
||||
|
||||
@@ -40,21 +40,21 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class JacksonJmxOperationResponseMapperTests {
|
||||
class JacksonJmxOperationResponseMapperTests {
|
||||
|
||||
private JacksonJmxOperationResponseMapper mapper = new JacksonJmxOperationResponseMapper(null);
|
||||
|
||||
private final BasicJsonTester json = new BasicJsonTester(getClass());
|
||||
|
||||
@Test
|
||||
public void createWhenObjectMapperIsNullShouldUseDefaultObjectMapper() {
|
||||
void createWhenObjectMapperIsNullShouldUseDefaultObjectMapper() {
|
||||
JacksonJmxOperationResponseMapper mapper = new JacksonJmxOperationResponseMapper(null);
|
||||
Object mapped = mapper.mapResponse(Collections.singleton("test"));
|
||||
assertThat(this.json.from(mapped.toString())).isEqualToJson("[test]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenObjectMapperIsSpecifiedShouldUseObjectMapper() {
|
||||
void createWhenObjectMapperIsSpecifiedShouldUseObjectMapper() {
|
||||
ObjectMapper objectMapper = spy(ObjectMapper.class);
|
||||
JacksonJmxOperationResponseMapper mapper = new JacksonJmxOperationResponseMapper(objectMapper);
|
||||
Set<String> response = Collections.singleton("test");
|
||||
@@ -63,53 +63,53 @@ public class JacksonJmxOperationResponseMapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapResponseTypeWhenCharSequenceShouldReturnString() {
|
||||
void mapResponseTypeWhenCharSequenceShouldReturnString() {
|
||||
assertThat(this.mapper.mapResponseType(String.class)).isEqualTo(String.class);
|
||||
assertThat(this.mapper.mapResponseType(StringBuilder.class)).isEqualTo(String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapResponseTypeWhenArrayShouldReturnList() {
|
||||
void mapResponseTypeWhenArrayShouldReturnList() {
|
||||
assertThat(this.mapper.mapResponseType(String[].class)).isEqualTo(List.class);
|
||||
assertThat(this.mapper.mapResponseType(Object[].class)).isEqualTo(List.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapResponseTypeWhenCollectionShouldReturnList() {
|
||||
void mapResponseTypeWhenCollectionShouldReturnList() {
|
||||
assertThat(this.mapper.mapResponseType(Collection.class)).isEqualTo(List.class);
|
||||
assertThat(this.mapper.mapResponseType(Set.class)).isEqualTo(List.class);
|
||||
assertThat(this.mapper.mapResponseType(List.class)).isEqualTo(List.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapResponseTypeWhenOtherShouldReturnMap() {
|
||||
void mapResponseTypeWhenOtherShouldReturnMap() {
|
||||
assertThat(this.mapper.mapResponseType(ExampleBean.class)).isEqualTo(Map.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapResponseWhenNullShouldReturnNull() {
|
||||
void mapResponseWhenNullShouldReturnNull() {
|
||||
assertThat(this.mapper.mapResponse(null)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapResponseWhenCharSequenceShouldReturnString() {
|
||||
void mapResponseWhenCharSequenceShouldReturnString() {
|
||||
assertThat(this.mapper.mapResponse(new StringBuilder("test"))).isEqualTo("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapResponseWhenArrayShouldReturnJsonArray() {
|
||||
void mapResponseWhenArrayShouldReturnJsonArray() {
|
||||
Object mapped = this.mapper.mapResponse(new int[] { 1, 2, 3 });
|
||||
assertThat(this.json.from(mapped.toString())).isEqualToJson("[1,2,3]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapResponseWhenCollectionShouldReturnJsonArray() {
|
||||
void mapResponseWhenCollectionShouldReturnJsonArray() {
|
||||
Object mapped = this.mapper.mapResponse(Arrays.asList("a", "b", "c"));
|
||||
assertThat(this.json.from(mapped.toString())).isEqualToJson("[a,b,c]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapResponseWhenOtherShouldReturnMap() {
|
||||
void mapResponseWhenOtherShouldReturnMap() {
|
||||
ExampleBean bean = new ExampleBean();
|
||||
bean.setName("boot");
|
||||
Object mapped = this.mapper.mapResponse(bean);
|
||||
|
||||
@@ -51,7 +51,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class JmxEndpointExporterTests {
|
||||
class JmxEndpointExporterTests {
|
||||
|
||||
@Mock
|
||||
private MBeanServer mBeanServer;
|
||||
@@ -78,21 +78,21 @@ public class JmxEndpointExporterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenMBeanServerIsNullShouldThrowException() {
|
||||
void createWhenMBeanServerIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> new JmxEndpointExporter(null, this.objectNameFactory, this.responseMapper, this.endpoints))
|
||||
.withMessageContaining("MBeanServer must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenObjectNameFactoryIsNullShouldThrowException() {
|
||||
void createWhenObjectNameFactoryIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new JmxEndpointExporter(this.mBeanServer, null, this.responseMapper, this.endpoints))
|
||||
.withMessageContaining("ObjectNameFactory must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenResponseMapperIsNullShouldThrowException() {
|
||||
void createWhenResponseMapperIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(
|
||||
() -> new JmxEndpointExporter(this.mBeanServer, this.objectNameFactory, null, this.endpoints))
|
||||
@@ -100,14 +100,14 @@ public class JmxEndpointExporterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenEndpointsIsNullShouldThrowException() {
|
||||
void createWhenEndpointsIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> new JmxEndpointExporter(this.mBeanServer, this.objectNameFactory, this.responseMapper, null))
|
||||
.withMessageContaining("Endpoints must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void afterPropertiesSetShouldRegisterMBeans() throws Exception {
|
||||
void afterPropertiesSetShouldRegisterMBeans() throws Exception {
|
||||
this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation()));
|
||||
this.exporter.afterPropertiesSet();
|
||||
verify(this.mBeanServer).registerMBean(this.objectCaptor.capture(), this.objectNameCaptor.capture());
|
||||
@@ -116,14 +116,14 @@ public class JmxEndpointExporterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerShouldUseObjectNameFactory() throws Exception {
|
||||
void registerShouldUseObjectNameFactory() throws Exception {
|
||||
this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation()));
|
||||
this.exporter.afterPropertiesSet();
|
||||
verify(this.objectNameFactory).getObjectName(any(ExposableJmxEndpoint.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerWhenObjectNameIsMalformedShouldThrowException() throws Exception {
|
||||
void registerWhenObjectNameIsMalformedShouldThrowException() throws Exception {
|
||||
given(this.objectNameFactory.getObjectName(any(ExposableJmxEndpoint.class)))
|
||||
.willThrow(MalformedObjectNameException.class);
|
||||
this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation()));
|
||||
@@ -132,7 +132,7 @@ public class JmxEndpointExporterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerWhenRegistrationFailsShouldThrowException() throws Exception {
|
||||
void registerWhenRegistrationFailsShouldThrowException() throws Exception {
|
||||
given(this.mBeanServer.registerMBean(any(), any(ObjectName.class)))
|
||||
.willThrow(new MBeanRegistrationException(new RuntimeException()));
|
||||
this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation()));
|
||||
@@ -141,7 +141,7 @@ public class JmxEndpointExporterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyShouldUnregisterMBeans() throws Exception {
|
||||
void destroyShouldUnregisterMBeans() throws Exception {
|
||||
this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation()));
|
||||
this.exporter.afterPropertiesSet();
|
||||
this.exporter.destroy();
|
||||
@@ -150,7 +150,7 @@ public class JmxEndpointExporterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unregisterWhenInstanceNotFoundShouldContinue() throws Exception {
|
||||
void unregisterWhenInstanceNotFoundShouldContinue() throws Exception {
|
||||
this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation()));
|
||||
this.exporter.afterPropertiesSet();
|
||||
willThrow(InstanceNotFoundException.class).given(this.mBeanServer).unregisterMBean(any(ObjectName.class));
|
||||
@@ -158,7 +158,7 @@ public class JmxEndpointExporterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unregisterWhenUnregisterThrowsExceptionShouldThrowException() throws Exception {
|
||||
void unregisterWhenUnregisterThrowsExceptionShouldThrowException() throws Exception {
|
||||
this.endpoints.add(new TestExposableJmxEndpoint(new TestJmxOperation()));
|
||||
this.exporter.afterPropertiesSet();
|
||||
willThrow(new MBeanRegistrationException(new RuntimeException())).given(this.mBeanServer)
|
||||
|
||||
@@ -37,12 +37,12 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class MBeanInfoFactoryTests {
|
||||
class MBeanInfoFactoryTests {
|
||||
|
||||
private MBeanInfoFactory factory = new MBeanInfoFactory(new TestJmxOperationResponseMapper());
|
||||
|
||||
@Test
|
||||
public void getMBeanInfoShouldReturnMBeanInfo() {
|
||||
void getMBeanInfoShouldReturnMBeanInfo() {
|
||||
MBeanInfo info = this.factory.getMBeanInfo(new TestExposableJmxEndpoint(new TestJmxOperation()));
|
||||
assertThat(info).isNotNull();
|
||||
assertThat(info.getClassName()).isEqualTo(EndpointMBean.class.getName());
|
||||
@@ -59,21 +59,21 @@ public class MBeanInfoFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMBeanInfoWhenReadOperationShouldHaveInfoImpact() {
|
||||
void getMBeanInfoWhenReadOperationShouldHaveInfoImpact() {
|
||||
MBeanInfo info = this.factory
|
||||
.getMBeanInfo(new TestExposableJmxEndpoint(new TestJmxOperation(OperationType.READ)));
|
||||
assertThat(info.getOperations()[0].getImpact()).isEqualTo(MBeanOperationInfo.INFO);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMBeanInfoWhenWriteOperationShouldHaveActionImpact() {
|
||||
void getMBeanInfoWhenWriteOperationShouldHaveActionImpact() {
|
||||
MBeanInfo info = this.factory
|
||||
.getMBeanInfo(new TestExposableJmxEndpoint(new TestJmxOperation(OperationType.WRITE)));
|
||||
assertThat(info.getOperations()[0].getImpact()).isEqualTo(MBeanOperationInfo.ACTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMBeanInfoWhenDeleteOperationShouldHaveActionImpact() {
|
||||
void getMBeanInfoWhenDeleteOperationShouldHaveActionImpact() {
|
||||
MBeanInfo info = this.factory
|
||||
.getMBeanInfo(new TestExposableJmxEndpoint(new TestJmxOperation(OperationType.DELETE)));
|
||||
assertThat(info.getOperations()[0].getImpact()).isEqualTo(MBeanOperationInfo.ACTION);
|
||||
@@ -81,7 +81,7 @@ public class MBeanInfoFactoryTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public void getMBeanInfoShouldUseJmxOperationResponseMapper() {
|
||||
void getMBeanInfoShouldUseJmxOperationResponseMapper() {
|
||||
JmxOperationResponseMapper mapper = mock(JmxOperationResponseMapper.class);
|
||||
given(mapper.mapResponseType(String.class)).willReturn((Class) Integer.class);
|
||||
MBeanInfoFactory factory = new MBeanInfoFactory(mapper);
|
||||
@@ -91,7 +91,7 @@ public class MBeanInfoFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMBeanShouldMapOperationParameters() {
|
||||
void getMBeanShouldMapOperationParameters() {
|
||||
List<JmxOperationParameter> parameters = new ArrayList<>();
|
||||
parameters.add(mockParameter("one", String.class, "myone"));
|
||||
parameters.add(mockParameter("two", Object.class, null));
|
||||
|
||||
@@ -45,16 +45,16 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class DiscoveredJmxOperationTests {
|
||||
class DiscoveredJmxOperationTests {
|
||||
|
||||
@Test
|
||||
public void getNameShouldReturnMethodName() {
|
||||
void getNameShouldReturnMethodName() {
|
||||
DiscoveredJmxOperation operation = getOperation("getEnum");
|
||||
assertThat(operation.getName()).isEqualTo("getEnum");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getOutputTypeShouldReturnJmxType() {
|
||||
void getOutputTypeShouldReturnJmxType() {
|
||||
assertThat(getOperation("getEnum").getOutputType()).isEqualTo(String.class);
|
||||
assertThat(getOperation("getDate").getOutputType()).isEqualTo(String.class);
|
||||
assertThat(getOperation("getInstant").getOutputType()).isEqualTo(String.class);
|
||||
@@ -64,25 +64,25 @@ public class DiscoveredJmxOperationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescriptionWhenHasManagedOperationDescriptionShouldUseValueFromAnnotation() {
|
||||
void getDescriptionWhenHasManagedOperationDescriptionShouldUseValueFromAnnotation() {
|
||||
DiscoveredJmxOperation operation = getOperation("withManagedOperationDescription");
|
||||
assertThat(operation.getDescription()).isEqualTo("fromannotation");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDescriptionWhenHasNoManagedOperationShouldGenerateDescription() {
|
||||
void getDescriptionWhenHasNoManagedOperationShouldGenerateDescription() {
|
||||
DiscoveredJmxOperation operation = getOperation("getEnum");
|
||||
assertThat(operation.getDescription()).isEqualTo("Invoke getEnum for endpoint test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParametersWhenHasNoParametersShouldReturnEmptyList() {
|
||||
void getParametersWhenHasNoParametersShouldReturnEmptyList() {
|
||||
DiscoveredJmxOperation operation = getOperation("getEnum");
|
||||
assertThat(operation.getParameters()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParametersShouldReturnJmxTypes() {
|
||||
void getParametersShouldReturnJmxTypes() {
|
||||
DiscoveredJmxOperation operation = getOperation("params");
|
||||
List<JmxOperationParameter> parameters = operation.getParameters();
|
||||
assertThat(parameters.get(0).getType()).isEqualTo(String.class);
|
||||
@@ -93,7 +93,7 @@ public class DiscoveredJmxOperationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParametersWhenHasManagedOperationParameterShouldUseValuesFromAnnotation() {
|
||||
void getParametersWhenHasManagedOperationParameterShouldUseValuesFromAnnotation() {
|
||||
DiscoveredJmxOperation operation = getOperation("withManagedOperationParameters");
|
||||
List<JmxOperationParameter> parameters = operation.getParameters();
|
||||
assertThat(parameters.get(0).getName()).isEqualTo("a1");
|
||||
@@ -103,7 +103,7 @@ public class DiscoveredJmxOperationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getParametersWhenHasNoManagedOperationParameterShouldDeducedValuesName() {
|
||||
void getParametersWhenHasNoManagedOperationParameterShouldDeducedValuesName() {
|
||||
DiscoveredJmxOperation operation = getOperation("params");
|
||||
List<JmxOperationParameter> parameters = operation.getParameters();
|
||||
assertThat(parameters.get(0).getName()).isEqualTo("enumParam");
|
||||
|
||||
@@ -56,15 +56,15 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class JmxEndpointDiscovererTests {
|
||||
class JmxEndpointDiscovererTests {
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
||||
void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
||||
load(EmptyConfiguration.class, (discoverer) -> assertThat(discoverer.getEndpoints()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsShouldDiscoverStandardEndpoints() {
|
||||
void getEndpointsShouldDiscoverStandardEndpoints() {
|
||||
load(TestEndpoint.class, (discoverer) -> {
|
||||
Map<EndpointId, ExposableJmxEndpoint> endpoints = discover(discoverer);
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
|
||||
@@ -95,7 +95,7 @@ public class JmxEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenHasFilteredEndpointShouldOnlyDiscoverJmxEndpoints() {
|
||||
void getEndpointsWhenHasFilteredEndpointShouldOnlyDiscoverJmxEndpoints() {
|
||||
load(MultipleEndpointsConfiguration.class, (discoverer) -> {
|
||||
Map<EndpointId, ExposableJmxEndpoint> endpoints = discover(discoverer);
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"), EndpointId.of("jmx"));
|
||||
@@ -103,14 +103,14 @@ public class JmxEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenJmxExtensionIsMissingEndpointShouldThrowException() {
|
||||
void getEndpointsWhenJmxExtensionIsMissingEndpointShouldThrowException() {
|
||||
load(TestJmxEndpointExtension.class, (discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Invalid extension 'jmxEndpointDiscovererTests.TestJmxEndpointExtension': no endpoint found with id 'test'"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenHasJmxExtensionShouldOverrideStandardEndpoint() {
|
||||
void getEndpointsWhenHasJmxExtensionShouldOverrideStandardEndpoint() {
|
||||
load(OverriddenOperationJmxEndpointConfiguration.class, (discoverer) -> {
|
||||
Map<EndpointId, ExposableJmxEndpoint> endpoints = discover(discoverer);
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
|
||||
@@ -119,7 +119,7 @@ public class JmxEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenHasJmxExtensionWithNewOperationAddsExtraOperation() {
|
||||
void getEndpointsWhenHasJmxExtensionWithNewOperationAddsExtraOperation() {
|
||||
load(AdditionalOperationJmxEndpointConfiguration.class, (discoverer) -> {
|
||||
Map<EndpointId, ExposableJmxEndpoint> endpoints = discover(discoverer);
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
|
||||
@@ -135,7 +135,7 @@ public class JmxEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenHasCacheWithTtlShouldCacheReadOperationWithTtlValue() {
|
||||
void getEndpointsWhenHasCacheWithTtlShouldCacheReadOperationWithTtlValue() {
|
||||
load(TestEndpoint.class, (id) -> 500L, (discoverer) -> {
|
||||
Map<EndpointId, ExposableJmxEndpoint> endpoints = discover(discoverer);
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
|
||||
@@ -149,7 +149,7 @@ public class JmxEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsShouldCacheReadOperations() {
|
||||
void getEndpointsShouldCacheReadOperations() {
|
||||
load(AdditionalOperationJmxEndpointConfiguration.class, (id) -> 500L, (discoverer) -> {
|
||||
Map<EndpointId, ExposableJmxEndpoint> endpoints = discover(discoverer);
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
|
||||
@@ -167,35 +167,35 @@ public class JmxEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenTwoExtensionsHaveTheSameEndpointTypeShouldThrowException() {
|
||||
void getEndpointsWhenTwoExtensionsHaveTheSameEndpointTypeShouldThrowException() {
|
||||
load(ClashingJmxEndpointConfiguration.class, (discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Found multiple extensions for the endpoint bean testEndpoint (testExtensionOne, testExtensionTwo)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenTwoStandardEndpointsHaveTheSameIdShouldThrowException() {
|
||||
void getEndpointsWhenTwoStandardEndpointsHaveTheSameIdShouldThrowException() {
|
||||
load(ClashingStandardEndpointConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException().isThrownBy(discoverer::getEndpoints)
|
||||
.withMessageContaining("Found two endpoints with the id 'test': "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenWhenEndpointHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||
void getEndpointsWhenWhenEndpointHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||
load(ClashingOperationsEndpoint.class, (discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Unable to map duplicate endpoint operations: [MBean call 'getAll'] to jmxEndpointDiscovererTests.ClashingOperationsEndpoint"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenWhenExtensionHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||
void getEndpointsWhenWhenExtensionHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||
load(AdditionalClashingOperationsConfiguration.class, (discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Unable to map duplicate endpoint operations: [MBean call 'getAll'] to testEndpoint (clashingOperationsJmxEndpointExtension)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenExtensionIsNotCompatibleWithTheEndpointTypeShouldThrowException() {
|
||||
void getEndpointsWhenExtensionIsNotCompatibleWithTheEndpointTypeShouldThrowException() {
|
||||
load(InvalidJmxExtensionConfiguration.class, (discoverer) -> assertThatIllegalStateException()
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining(
|
||||
"Endpoint bean 'nonJmxEndpoint' cannot support the extension bean 'nonJmxJmxEndpointExtension'"));
|
||||
|
||||
@@ -37,10 +37,10 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class EndpointLinksResolverTests {
|
||||
class EndpointLinksResolverTests {
|
||||
|
||||
@Test
|
||||
public void linkResolutionWithTrailingSlashStripsSlashOnSelfLink() {
|
||||
void linkResolutionWithTrailingSlashStripsSlashOnSelfLink() {
|
||||
Map<String, Link> links = new EndpointLinksResolver(Collections.emptyList())
|
||||
.resolveLinks("https://api.example.com/actuator/");
|
||||
assertThat(links).hasSize(1);
|
||||
@@ -48,7 +48,7 @@ public class EndpointLinksResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void linkResolutionWithoutTrailingSlash() {
|
||||
void linkResolutionWithoutTrailingSlash() {
|
||||
Map<String, Link> links = new EndpointLinksResolver(Collections.emptyList())
|
||||
.resolveLinks("https://api.example.com/actuator");
|
||||
assertThat(links).hasSize(1);
|
||||
@@ -56,7 +56,7 @@ public class EndpointLinksResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolvedLinksContainsALinkForEachWebEndpointOperation() {
|
||||
void resolvedLinksContainsALinkForEachWebEndpointOperation() {
|
||||
List<WebOperation> operations = new ArrayList<>();
|
||||
operations.add(operationWithPath("/alpha", "alpha"));
|
||||
operations.add(operationWithPath("/alpha/{name}", "alpha-name"));
|
||||
@@ -75,7 +75,7 @@ public class EndpointLinksResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolvedLinksContainsALinkForServletEndpoint() {
|
||||
void resolvedLinksContainsALinkForServletEndpoint() {
|
||||
ExposableServletEndpoint servletEndpoint = mock(ExposableServletEndpoint.class);
|
||||
given(servletEndpoint.getEndpointId()).willReturn(EndpointId.of("alpha"));
|
||||
given(servletEndpoint.isEnableByDefault()).willReturn(true);
|
||||
@@ -89,7 +89,7 @@ public class EndpointLinksResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolvedLinksContainsALinkForControllerEndpoint() {
|
||||
void resolvedLinksContainsALinkForControllerEndpoint() {
|
||||
ExposableControllerEndpoint controllerEndpoint = mock(ExposableControllerEndpoint.class);
|
||||
given(controllerEndpoint.getEndpointId()).willReturn(EndpointId.of("alpha"));
|
||||
given(controllerEndpoint.isEnableByDefault()).willReturn(true);
|
||||
|
||||
@@ -25,55 +25,55 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class EndpointMappingTests {
|
||||
class EndpointMappingTests {
|
||||
|
||||
@Test
|
||||
public void normalizationTurnsASlashIntoAnEmptyString() {
|
||||
void normalizationTurnsASlashIntoAnEmptyString() {
|
||||
assertThat(new EndpointMapping("/").getPath()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizationLeavesAnEmptyStringAsIs() {
|
||||
void normalizationLeavesAnEmptyStringAsIs() {
|
||||
assertThat(new EndpointMapping("").getPath()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizationRemovesATrailingSlash() {
|
||||
void normalizationRemovesATrailingSlash() {
|
||||
assertThat(new EndpointMapping("/test/").getPath()).isEqualTo("/test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizationAddsALeadingSlash() {
|
||||
void normalizationAddsALeadingSlash() {
|
||||
assertThat(new EndpointMapping("test").getPath()).isEqualTo("/test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizationAddsALeadingSlashAndRemovesATrailingSlash() {
|
||||
void normalizationAddsALeadingSlashAndRemovesATrailingSlash() {
|
||||
assertThat(new EndpointMapping("test/").getPath()).isEqualTo("/test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizationLeavesAPathWithALeadingSlashAndNoTrailingSlashAsIs() {
|
||||
void normalizationLeavesAPathWithALeadingSlashAndNoTrailingSlashAsIs() {
|
||||
assertThat(new EndpointMapping("/test").getPath()).isEqualTo("/test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subPathForAnEmptyStringReturnsBasePath() {
|
||||
void subPathForAnEmptyStringReturnsBasePath() {
|
||||
assertThat(new EndpointMapping("/test").createSubPath("")).isEqualTo("/test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subPathWithALeadingSlashIsSeparatedFromBasePathBySingleSlash() {
|
||||
void subPathWithALeadingSlashIsSeparatedFromBasePathBySingleSlash() {
|
||||
assertThat(new EndpointMapping("/test").createSubPath("/one")).isEqualTo("/test/one");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subPathWithoutALeadingSlashIsSeparatedFromBasePathBySingleSlash() {
|
||||
void subPathWithoutALeadingSlashIsSeparatedFromBasePathBySingleSlash() {
|
||||
assertThat(new EndpointMapping("/test").createSubPath("one")).isEqualTo("/test/one");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trailingSlashIsRemovedFromASubPath() {
|
||||
void trailingSlashIsRemovedFromASubPath() {
|
||||
assertThat(new EndpointMapping("/test").createSubPath("one/")).isEqualTo("/test/one");
|
||||
}
|
||||
|
||||
|
||||
@@ -30,29 +30,29 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class EndpointMediaTypesTests {
|
||||
class EndpointMediaTypesTests {
|
||||
|
||||
@Test
|
||||
public void createWhenProducedIsNullShouldThrowException() {
|
||||
void createWhenProducedIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new EndpointMediaTypes(null, Collections.emptyList()))
|
||||
.withMessageContaining("Produced must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenConsumedIsNullShouldThrowException() {
|
||||
void createWhenConsumedIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new EndpointMediaTypes(Collections.emptyList(), null))
|
||||
.withMessageContaining("Consumed must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProducedShouldReturnProduced() {
|
||||
void getProducedShouldReturnProduced() {
|
||||
List<String> produced = Arrays.asList("a", "b", "c");
|
||||
EndpointMediaTypes types = new EndpointMediaTypes(produced, Collections.emptyList());
|
||||
assertThat(types.getProduced()).isEqualTo(produced);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getConsumedShouldReturnConsumed() {
|
||||
void getConsumedShouldReturnConsumed() {
|
||||
List<String> consumed = Arrays.asList("a", "b", "c");
|
||||
EndpointMediaTypes types = new EndpointMediaTypes(Collections.emptyList(), consumed);
|
||||
assertThat(types.getConsumed()).isEqualTo(consumed);
|
||||
|
||||
@@ -37,53 +37,53 @@ import static org.assertj.core.api.Assertions.entry;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class EndpointServletTests {
|
||||
class EndpointServletTests {
|
||||
|
||||
@Test
|
||||
public void createWhenServletClassIsNullShouldThrowException() {
|
||||
void createWhenServletClassIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new EndpointServlet((Class<Servlet>) null))
|
||||
.withMessageContaining("Servlet must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenServletIsNullShouldThrowException() {
|
||||
void createWhenServletIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new EndpointServlet((Servlet) null))
|
||||
.withMessageContaining("Servlet must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithServletClassShouldCreateServletInstance() {
|
||||
void createWithServletClassShouldCreateServletInstance() {
|
||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||
assertThat(endpointServlet.getServlet()).isInstanceOf(TestServlet.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getServletShouldGetServlet() {
|
||||
void getServletShouldGetServlet() {
|
||||
TestServlet servlet = new TestServlet();
|
||||
EndpointServlet endpointServlet = new EndpointServlet(servlet);
|
||||
assertThat(endpointServlet.getServlet()).isEqualTo(servlet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withInitParameterNullName() {
|
||||
void withInitParameterNullName() {
|
||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> endpointServlet.withInitParameter(null, "value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withInitParameterEmptyName() {
|
||||
void withInitParameterEmptyName() {
|
||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> endpointServlet.withInitParameter(" ", "value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withInitParameterShouldReturnNewInstance() {
|
||||
void withInitParameterShouldReturnNewInstance() {
|
||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||
assertThat(endpointServlet.withInitParameter("spring", "boot")).isNotSameAs(endpointServlet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withInitParameterWhenHasExistingShouldMergeParameters() {
|
||||
void withInitParameterWhenHasExistingShouldMergeParameters() {
|
||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class).withInitParameter("a", "b")
|
||||
.withInitParameter("c", "d");
|
||||
assertThat(endpointServlet.withInitParameter("a", "b1").withInitParameter("e", "f").getInitParameters())
|
||||
@@ -91,28 +91,28 @@ public class EndpointServletTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withInitParametersNullName() {
|
||||
void withInitParametersNullName() {
|
||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> endpointServlet.withInitParameters(Collections.singletonMap(null, "value")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withInitParametersEmptyName() {
|
||||
void withInitParametersEmptyName() {
|
||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> endpointServlet.withInitParameters(Collections.singletonMap(" ", "value")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withInitParametersShouldCreateNewInstance() {
|
||||
void withInitParametersShouldCreateNewInstance() {
|
||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||
assertThat(endpointServlet.withInitParameters(Collections.singletonMap("spring", "boot")))
|
||||
.isNotSameAs(endpointServlet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withInitParametersWhenHasExistingShouldMergeParameters() {
|
||||
void withInitParametersWhenHasExistingShouldMergeParameters() {
|
||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class).withInitParameter("a", "b")
|
||||
.withInitParameter("c", "d");
|
||||
Map<String, String> extra = new LinkedHashMap<>();
|
||||
@@ -123,13 +123,13 @@ public class EndpointServletTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withLoadOnStartupNotSetShouldReturnDefaultValue() {
|
||||
void withLoadOnStartupNotSetShouldReturnDefaultValue() {
|
||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);
|
||||
assertThat(endpointServlet.getLoadOnStartup()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withLoadOnStartupSetShouldReturnValue() {
|
||||
void withLoadOnStartupSetShouldReturnValue() {
|
||||
EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class).withLoadOnStartup(3);
|
||||
assertThat(endpointServlet.getLoadOnStartup()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@@ -26,30 +26,30 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class LinkTests {
|
||||
class LinkTests {
|
||||
|
||||
@Test
|
||||
public void createWhenHrefIsNullShouldThrowException() {
|
||||
void createWhenHrefIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new Link(null))
|
||||
.withMessageContaining("HREF must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHrefShouldReturnHref() {
|
||||
void getHrefShouldReturnHref() {
|
||||
String href = "https://example.com";
|
||||
Link link = new Link(href);
|
||||
assertThat(link.getHref()).isEqualTo(href);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isTemplatedWhenContainsPlaceholderShouldReturnTrue() {
|
||||
void isTemplatedWhenContainsPlaceholderShouldReturnTrue() {
|
||||
String href = "https://example.com/{path}";
|
||||
Link link = new Link(href);
|
||||
assertThat(link.isTemplated()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isTemplatedWhenContainsNoPlaceholderShouldReturnFalse() {
|
||||
void isTemplatedWhenContainsNoPlaceholderShouldReturnFalse() {
|
||||
String href = "https://example.com/path";
|
||||
Link link = new Link(href);
|
||||
assertThat(link.isTemplated()).isFalse();
|
||||
|
||||
@@ -37,80 +37,80 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class PathMappedEndpointsTests {
|
||||
class PathMappedEndpointsTests {
|
||||
|
||||
@Test
|
||||
public void createWhenSupplierIsNullShouldThrowException() {
|
||||
void createWhenSupplierIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new PathMappedEndpoints(null, (WebEndpointsSupplier) null))
|
||||
.withMessageContaining("Supplier must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenSuppliersIsNullShouldThrowException() {
|
||||
void createWhenSuppliersIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new PathMappedEndpoints(null, (Collection<EndpointsSupplier<?>>) null))
|
||||
.withMessageContaining("Suppliers must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void iteratorShouldReturnPathMappedEndpoints() {
|
||||
void iteratorShouldReturnPathMappedEndpoints() {
|
||||
PathMappedEndpoints mapped = createTestMapped(null);
|
||||
assertThat(mapped).hasSize(2);
|
||||
assertThat(mapped).extracting("endpointId").containsExactly(EndpointId.of("e2"), EndpointId.of("e3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void streamShouldReturnPathMappedEndpoints() {
|
||||
void streamShouldReturnPathMappedEndpoints() {
|
||||
PathMappedEndpoints mapped = createTestMapped(null);
|
||||
assertThat(mapped.stream()).hasSize(2);
|
||||
assertThat(mapped.stream()).extracting("endpointId").containsExactly(EndpointId.of("e2"), EndpointId.of("e3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRootPathWhenContainsIdShouldReturnRootPath() {
|
||||
void getRootPathWhenContainsIdShouldReturnRootPath() {
|
||||
PathMappedEndpoints mapped = createTestMapped(null);
|
||||
assertThat(mapped.getRootPath(EndpointId.of("e2"))).isEqualTo("p2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRootPathWhenMissingIdShouldReturnNull() {
|
||||
void getRootPathWhenMissingIdShouldReturnNull() {
|
||||
PathMappedEndpoints mapped = createTestMapped(null);
|
||||
assertThat(mapped.getRootPath(EndpointId.of("xx"))).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPathWhenContainsIdShouldReturnRootPath() {
|
||||
void getPathWhenContainsIdShouldReturnRootPath() {
|
||||
assertThat(createTestMapped(null).getPath(EndpointId.of("e2"))).isEqualTo("/p2");
|
||||
assertThat(createTestMapped("/x").getPath(EndpointId.of("e2"))).isEqualTo("/x/p2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPathWhenMissingIdShouldReturnNull() {
|
||||
void getPathWhenMissingIdShouldReturnNull() {
|
||||
PathMappedEndpoints mapped = createTestMapped(null);
|
||||
assertThat(mapped.getPath(EndpointId.of("xx"))).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllRootPathsShouldReturnAllPaths() {
|
||||
void getAllRootPathsShouldReturnAllPaths() {
|
||||
PathMappedEndpoints mapped = createTestMapped(null);
|
||||
assertThat(mapped.getAllRootPaths()).containsExactly("p2", "p3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllPathsShouldReturnAllPaths() {
|
||||
void getAllPathsShouldReturnAllPaths() {
|
||||
assertThat(createTestMapped(null).getAllPaths()).containsExactly("/p2", "/p3");
|
||||
assertThat(createTestMapped("/x").getAllPaths()).containsExactly("/x/p2", "/x/p3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointWhenContainsIdShouldReturnPathMappedEndpoint() {
|
||||
void getEndpointWhenContainsIdShouldReturnPathMappedEndpoint() {
|
||||
PathMappedEndpoints mapped = createTestMapped(null);
|
||||
assertThat(mapped.getEndpoint(EndpointId.of("e2")).getRootPath()).isEqualTo("p2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointWhenMissingIdShouldReturnNull() {
|
||||
void getEndpointWhenMissingIdShouldReturnNull() {
|
||||
PathMappedEndpoints mapped = createTestMapped(null);
|
||||
assertThat(mapped.getEndpoint(EndpointId.of("xx"))).isNull();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ServletEndpointRegistrarTests {
|
||||
class ServletEndpointRegistrarTests {
|
||||
|
||||
@Mock
|
||||
private ServletContext servletContext;
|
||||
@@ -67,28 +67,28 @@ public class ServletEndpointRegistrarTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenServletEndpointsIsNullShouldThrowException() {
|
||||
void createWhenServletEndpointsIsNullShouldThrowException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new ServletEndpointRegistrar(null, null))
|
||||
.withMessageContaining("ServletEndpoints must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStartupShouldRegisterServlets() throws ServletException {
|
||||
void onStartupShouldRegisterServlets() throws ServletException {
|
||||
assertBasePath(null, "/test/*");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStartupWhenHasBasePathShouldIncludeBasePath() throws ServletException {
|
||||
void onStartupWhenHasBasePathShouldIncludeBasePath() throws ServletException {
|
||||
assertBasePath("/actuator", "/actuator/test/*");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStartupWhenHasEmptyBasePathShouldPrefixWithSlash() throws ServletException {
|
||||
void onStartupWhenHasEmptyBasePathShouldPrefixWithSlash() throws ServletException {
|
||||
assertBasePath("", "/test/*");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStartupWhenHasRootBasePathShouldNotAddDuplicateSlash() throws ServletException {
|
||||
void onStartupWhenHasRootBasePathShouldNotAddDuplicateSlash() throws ServletException {
|
||||
assertBasePath("/", "/test/*");
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public class ServletEndpointRegistrarTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStartupWhenHasInitParametersShouldRegisterInitParameters() throws Exception {
|
||||
void onStartupWhenHasInitParametersShouldRegisterInitParameters() throws Exception {
|
||||
ExposableServletEndpoint endpoint = mockEndpoint(
|
||||
new EndpointServlet(TestServlet.class).withInitParameter("a", "b"));
|
||||
ServletEndpointRegistrar registrar = new ServletEndpointRegistrar("/actuator", Collections.singleton(endpoint));
|
||||
@@ -111,7 +111,7 @@ public class ServletEndpointRegistrarTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStartupWhenHasLoadOnStartupShouldRegisterLoadOnStartup() throws Exception {
|
||||
void onStartupWhenHasLoadOnStartupShouldRegisterLoadOnStartup() throws Exception {
|
||||
ExposableServletEndpoint endpoint = mockEndpoint(new EndpointServlet(TestServlet.class).withLoadOnStartup(7));
|
||||
ServletEndpointRegistrar registrar = new ServletEndpointRegistrar("/actuator", Collections.singleton(endpoint));
|
||||
registrar.onStartup(this.servletContext);
|
||||
@@ -119,7 +119,7 @@ public class ServletEndpointRegistrarTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStartupWhenHasNotLoadOnStartupShouldRegisterDefaultValue() throws Exception {
|
||||
void onStartupWhenHasNotLoadOnStartupShouldRegisterDefaultValue() throws Exception {
|
||||
ExposableServletEndpoint endpoint = mockEndpoint(new EndpointServlet(TestServlet.class));
|
||||
ServletEndpointRegistrar registrar = new ServletEndpointRegistrar("/actuator", Collections.singleton(endpoint));
|
||||
registrar.onStartup(this.servletContext);
|
||||
|
||||
@@ -25,31 +25,31 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class WebEndpointResponseTests {
|
||||
class WebEndpointResponseTests {
|
||||
|
||||
@Test
|
||||
public void createWithNoParamsShouldReturn200() {
|
||||
void createWithNoParamsShouldReturn200() {
|
||||
WebEndpointResponse<Object> response = new WebEndpointResponse<>();
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
assertThat(response.getBody()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithStatusShouldReturnStatus() {
|
||||
void createWithStatusShouldReturnStatus() {
|
||||
WebEndpointResponse<Object> response = new WebEndpointResponse<>(404);
|
||||
assertThat(response.getStatus()).isEqualTo(404);
|
||||
assertThat(response.getBody()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithBodyShouldReturnBody() {
|
||||
void createWithBodyShouldReturnBody() {
|
||||
WebEndpointResponse<Object> response = new WebEndpointResponse<>("body");
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
assertThat(response.getBody()).isEqualTo("body");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithBodyAndStatusShouldReturnStatusAndBody() {
|
||||
void createWithBodyAndStatusShouldReturnStatusAndBody() {
|
||||
WebEndpointResponse<Object> response = new WebEndpointResponse<>("body", 500);
|
||||
assertThat(response.getStatus()).isEqualTo(500);
|
||||
assertThat(response.getBody()).isEqualTo("body");
|
||||
|
||||
@@ -27,35 +27,35 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class WebOperationRequestPredicateTests {
|
||||
class WebOperationRequestPredicateTests {
|
||||
|
||||
@Test
|
||||
public void predicatesWithIdenticalPathsAreEqual() {
|
||||
void predicatesWithIdenticalPathsAreEqual() {
|
||||
assertThat(predicateWithPath("/path")).isEqualTo(predicateWithPath("/path"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void predicatesWithDifferentPathsAreNotEqual() {
|
||||
void predicatesWithDifferentPathsAreNotEqual() {
|
||||
assertThat(predicateWithPath("/one")).isNotEqualTo(predicateWithPath("/two"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void predicatesWithIdenticalPathsWithVariablesAreEqual() {
|
||||
void predicatesWithIdenticalPathsWithVariablesAreEqual() {
|
||||
assertThat(predicateWithPath("/path/{foo}")).isEqualTo(predicateWithPath("/path/{foo}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void predicatesWhereOneHasAPathAndTheOtherHasAVariableAreNotEqual() {
|
||||
void predicatesWhereOneHasAPathAndTheOtherHasAVariableAreNotEqual() {
|
||||
assertThat(predicateWithPath("/path/{foo}")).isNotEqualTo(predicateWithPath("/path/foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void predicatesWithSinglePathVariablesInTheSamplePlaceAreEqual() {
|
||||
void predicatesWithSinglePathVariablesInTheSamplePlaceAreEqual() {
|
||||
assertThat(predicateWithPath("/path/{foo1}")).isEqualTo(predicateWithPath("/path/{foo2}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void predicatesWithMultiplePathVariablesInTheSamplePlaceAreEqual() {
|
||||
void predicatesWithMultiplePathVariablesInTheSamplePlaceAreEqual() {
|
||||
assertThat(predicateWithPath("/path/{foo1}/more/{bar1}"))
|
||||
.isEqualTo(predicateWithPath("/path/{foo2}/more/{bar2}"));
|
||||
}
|
||||
|
||||
@@ -79,31 +79,31 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperation() {
|
||||
void readOperation() {
|
||||
load(TestEndpointConfiguration.class, (client) -> client.get().uri("/test").exchange().expectStatus().isOk()
|
||||
.expectBody().jsonPath("All").isEqualTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationWithEndpointsMappedToTheRoot() {
|
||||
void readOperationWithEndpointsMappedToTheRoot() {
|
||||
load(TestEndpointConfiguration.class, "", (client) -> client.get().uri("/test").exchange().expectStatus().isOk()
|
||||
.expectBody().jsonPath("All").isEqualTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationWithSelector() {
|
||||
void readOperationWithSelector() {
|
||||
load(TestEndpointConfiguration.class, (client) -> client.get().uri("/test/one").exchange().expectStatus().isOk()
|
||||
.expectBody().jsonPath("part").isEqualTo("one"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationWithSelectorContainingADot() {
|
||||
void readOperationWithSelectorContainingADot() {
|
||||
load(TestEndpointConfiguration.class, (client) -> client.get().uri("/test/foo.bar").exchange().expectStatus()
|
||||
.isOk().expectBody().jsonPath("part").isEqualTo("foo.bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void linksToOtherEndpointsAreProvided() {
|
||||
void linksToOtherEndpointsAreProvided() {
|
||||
load(TestEndpointConfiguration.class,
|
||||
(client) -> client.get().uri("").exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("_links.length()").isEqualTo(3).jsonPath("_links.self.href").isNotEmpty()
|
||||
@@ -113,43 +113,43 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
}
|
||||
|
||||
@Test
|
||||
public void linksMappingIsDisabledWhenEndpointPathIsEmpty() {
|
||||
void linksMappingIsDisabledWhenEndpointPathIsEmpty() {
|
||||
load(TestEndpointConfiguration.class, "",
|
||||
(client) -> client.get().uri("").exchange().expectStatus().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void operationWithTrailingSlashShouldMatch() {
|
||||
void operationWithTrailingSlashShouldMatch() {
|
||||
load(TestEndpointConfiguration.class, (client) -> client.get().uri("/test/").exchange().expectStatus().isOk()
|
||||
.expectBody().jsonPath("All").isEqualTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationWithSingleQueryParameters() {
|
||||
void readOperationWithSingleQueryParameters() {
|
||||
load(QueryEndpointConfiguration.class, (client) -> client.get().uri("/query?one=1&two=2").exchange()
|
||||
.expectStatus().isOk().expectBody().jsonPath("query").isEqualTo("1 2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationWithSingleQueryParametersAndMultipleValues() {
|
||||
void readOperationWithSingleQueryParametersAndMultipleValues() {
|
||||
load(QueryEndpointConfiguration.class, (client) -> client.get().uri("/query?one=1&one=1&two=2").exchange()
|
||||
.expectStatus().isOk().expectBody().jsonPath("query").isEqualTo("1,1 2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationWithListQueryParameterAndSingleValue() {
|
||||
void readOperationWithListQueryParameterAndSingleValue() {
|
||||
load(QueryWithListEndpointConfiguration.class, (client) -> client.get().uri("/query?one=1&two=2").exchange()
|
||||
.expectStatus().isOk().expectBody().jsonPath("query").isEqualTo("1 [2]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationWithListQueryParameterAndMultipleValues() {
|
||||
void readOperationWithListQueryParameterAndMultipleValues() {
|
||||
load(QueryWithListEndpointConfiguration.class, (client) -> client.get().uri("/query?one=1&two=2&two=2")
|
||||
.exchange().expectStatus().isOk().expectBody().jsonPath("query").isEqualTo("1 [2, 2]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationWithMappingFailureProducesBadRequestResponse() {
|
||||
void readOperationWithMappingFailureProducesBadRequestResponse() {
|
||||
load(QueryEndpointConfiguration.class, (client) -> {
|
||||
WebTestClient.BodyContentSpec body = client.get().uri("/query?two=two").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isBadRequest().expectBody();
|
||||
@@ -158,7 +158,7 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeOperation() {
|
||||
void writeOperation() {
|
||||
load(TestEndpointConfiguration.class, (client) -> {
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("foo", "one");
|
||||
@@ -168,7 +168,7 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeOperationWithVoidResponse() {
|
||||
void writeOperationWithVoidResponse() {
|
||||
load(VoidWriteResponseEndpointConfiguration.class, (context, client) -> {
|
||||
client.post().uri("/voidwrite").exchange().expectStatus().isNoContent().expectBody().isEmpty();
|
||||
verify(context.getBean(EndpointDelegate.class)).write();
|
||||
@@ -176,13 +176,13 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteOperation() {
|
||||
void deleteOperation() {
|
||||
load(TestEndpointConfiguration.class, (client) -> client.delete().uri("/test/one").exchange().expectStatus()
|
||||
.isOk().expectBody().jsonPath("part").isEqualTo("one"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteOperationWithVoidResponse() {
|
||||
void deleteOperationWithVoidResponse() {
|
||||
load(VoidDeleteResponseEndpointConfiguration.class, (context, client) -> {
|
||||
client.delete().uri("/voiddelete").exchange().expectStatus().isNoContent().expectBody().isEmpty();
|
||||
verify(context.getBean(EndpointDelegate.class)).delete();
|
||||
@@ -190,7 +190,7 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullIsPassedToTheOperationWhenArgumentIsNotFoundInPostRequestBody() {
|
||||
void nullIsPassedToTheOperationWhenArgumentIsNotFoundInPostRequestBody() {
|
||||
load(TestEndpointConfiguration.class, (context, client) -> {
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("foo", "one");
|
||||
@@ -200,7 +200,7 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullsArePassedToTheOperationWhenPostRequestHasNoBody() {
|
||||
void nullsArePassedToTheOperationWhenPostRequestHasNoBody() {
|
||||
load(TestEndpointConfiguration.class, (context, client) -> {
|
||||
client.post().uri("/test").contentType(MediaType.APPLICATION_JSON).exchange().expectStatus().isNoContent()
|
||||
.expectBody().isEmpty();
|
||||
@@ -209,25 +209,25 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullResponseFromReadOperationResultsInNotFoundResponseStatus() {
|
||||
void nullResponseFromReadOperationResultsInNotFoundResponseStatus() {
|
||||
load(NullReadResponseEndpointConfiguration.class,
|
||||
(context, client) -> client.get().uri("/nullread").exchange().expectStatus().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullResponseFromDeleteOperationResultsInNoContentResponseStatus() {
|
||||
void nullResponseFromDeleteOperationResultsInNoContentResponseStatus() {
|
||||
load(NullDeleteResponseEndpointConfiguration.class,
|
||||
(context, client) -> client.delete().uri("/nulldelete").exchange().expectStatus().isNoContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullResponseFromWriteOperationResultsInNoContentResponseStatus() {
|
||||
void nullResponseFromWriteOperationResultsInNoContentResponseStatus() {
|
||||
load(NullWriteResponseEndpointConfiguration.class,
|
||||
(context, client) -> client.post().uri("/nullwrite").exchange().expectStatus().isNoContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationWithResourceResponse() {
|
||||
void readOperationWithResourceResponse() {
|
||||
load(ResourceEndpointConfiguration.class, (context, client) -> {
|
||||
byte[] responseBody = client.get().uri("/resource").exchange().expectStatus().isOk().expectHeader()
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM).returnResult(byte[].class)
|
||||
@@ -237,7 +237,7 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationWithResourceWebOperationResponse() {
|
||||
void readOperationWithResourceWebOperationResponse() {
|
||||
load(ResourceWebEndpointResponseEndpointConfiguration.class, (context, client) -> {
|
||||
byte[] responseBody = client.get().uri("/resource").exchange().expectStatus().isOk().expectHeader()
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM).returnResult(byte[].class)
|
||||
@@ -247,19 +247,19 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationWithMonoResponse() {
|
||||
void readOperationWithMonoResponse() {
|
||||
load(MonoResponseEndpointConfiguration.class, (client) -> client.get().uri("/mono").exchange().expectStatus()
|
||||
.isOk().expectBody().jsonPath("a").isEqualTo("alpha"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationWithCustomMediaType() {
|
||||
void readOperationWithCustomMediaType() {
|
||||
load(CustomMediaTypesEndpointConfiguration.class, (client) -> client.get().uri("/custommediatypes").exchange()
|
||||
.expectStatus().isOk().expectHeader().valueMatches("Content-Type", "text/plain(;charset=.*)?"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationWithMissingRequiredParametersReturnsBadRequestResponse() {
|
||||
void readOperationWithMissingRequiredParametersReturnsBadRequestResponse() {
|
||||
load(RequiredParameterEndpointConfiguration.class, (client) -> {
|
||||
WebTestClient.BodyContentSpec body = client.get().uri("/requiredparameters")
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isBadRequest().expectBody();
|
||||
@@ -268,44 +268,44 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationWithMissingNullableParametersIsOk() {
|
||||
void readOperationWithMissingNullableParametersIsOk() {
|
||||
load(RequiredParameterEndpointConfiguration.class,
|
||||
(client) -> client.get().uri("/requiredparameters?foo=hello").exchange().expectStatus().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endpointsProducePrimaryMediaTypeByDefault() {
|
||||
void endpointsProducePrimaryMediaTypeByDefault() {
|
||||
load(TestEndpointConfiguration.class, (client) -> client.get().uri("/test").exchange().expectStatus().isOk()
|
||||
.expectHeader().valueMatches("Content-Type", ACTUATOR_MEDIA_TYPE_PATTERN));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endpointsProduceSecondaryMediaTypeWhenRequested() {
|
||||
void endpointsProduceSecondaryMediaTypeWhenRequested() {
|
||||
load(TestEndpointConfiguration.class, (client) -> client.get().uri("/test").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk().expectHeader().valueMatches("Content-Type", JSON_MEDIA_TYPE_PATTERN));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void linksProducesPrimaryMediaTypeByDefault() {
|
||||
void linksProducesPrimaryMediaTypeByDefault() {
|
||||
load(TestEndpointConfiguration.class, (client) -> client.get().uri("").exchange().expectStatus().isOk()
|
||||
.expectHeader().valueMatches("Content-Type", ACTUATOR_MEDIA_TYPE_PATTERN));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void linksProducesSecondaryMediaTypeWhenRequested() {
|
||||
void linksProducesSecondaryMediaTypeWhenRequested() {
|
||||
load(TestEndpointConfiguration.class, (client) -> client.get().uri("").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk().expectHeader().valueMatches("Content-Type", JSON_MEDIA_TYPE_PATTERN));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void principalIsNullWhenRequestHasNoPrincipal() {
|
||||
void principalIsNullWhenRequestHasNoPrincipal() {
|
||||
load(PrincipalEndpointConfiguration.class,
|
||||
(client) -> client.get().uri("/principal").accept(MediaType.APPLICATION_JSON).exchange().expectStatus()
|
||||
.isOk().expectBody(String.class).isEqualTo("None"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void principalIsAvailableWhenRequestHasAPrincipal() {
|
||||
void principalIsAvailableWhenRequestHasAPrincipal() {
|
||||
load((context) -> {
|
||||
this.authenticatedContextCustomizer.accept(context);
|
||||
context.register(PrincipalEndpointConfiguration.class);
|
||||
@@ -314,7 +314,7 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
}
|
||||
|
||||
@Test
|
||||
public void operationWithAQueryNamedPrincipalCanBeAccessedWhenAuthenticated() {
|
||||
void operationWithAQueryNamedPrincipalCanBeAccessedWhenAuthenticated() {
|
||||
load((context) -> {
|
||||
this.authenticatedContextCustomizer.accept(context);
|
||||
context.register(PrincipalQueryEndpointConfiguration.class);
|
||||
@@ -323,14 +323,14 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
}
|
||||
|
||||
@Test
|
||||
public void securityContextIsAvailableAndHasNullPrincipalWhenRequestHasNoPrincipal() {
|
||||
void securityContextIsAvailableAndHasNullPrincipalWhenRequestHasNoPrincipal() {
|
||||
load(SecurityContextEndpointConfiguration.class,
|
||||
(client) -> client.get().uri("/securitycontext").accept(MediaType.APPLICATION_JSON).exchange()
|
||||
.expectStatus().isOk().expectBody(String.class).isEqualTo("None"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void securityContextIsAvailableAndHasPrincipalWhenRequestHasPrincipal() {
|
||||
void securityContextIsAvailableAndHasPrincipalWhenRequestHasPrincipal() {
|
||||
load((context) -> {
|
||||
this.authenticatedContextCustomizer.accept(context);
|
||||
context.register(SecurityContextEndpointConfiguration.class);
|
||||
@@ -339,14 +339,14 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userInRoleReturnsFalseWhenRequestHasNoPrincipal() {
|
||||
void userInRoleReturnsFalseWhenRequestHasNoPrincipal() {
|
||||
load(UserInRoleEndpointConfiguration.class,
|
||||
(client) -> client.get().uri("/userinrole?role=ADMIN").accept(MediaType.APPLICATION_JSON).exchange()
|
||||
.expectStatus().isOk().expectBody(String.class).isEqualTo("ADMIN: false"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userInRoleReturnsFalseWhenUserIsNotInRole() {
|
||||
void userInRoleReturnsFalseWhenUserIsNotInRole() {
|
||||
load((context) -> {
|
||||
this.authenticatedContextCustomizer.accept(context);
|
||||
context.register(UserInRoleEndpointConfiguration.class);
|
||||
@@ -355,7 +355,7 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userInRoleReturnsTrueWhenUserIsInRole() {
|
||||
void userInRoleReturnsTrueWhenUserIsInRole() {
|
||||
load((context) -> {
|
||||
this.authenticatedContextCustomizer.accept(context);
|
||||
context.register(UserInRoleEndpointConfiguration.class);
|
||||
|
||||
@@ -47,18 +47,18 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ControllerEndpointDiscovererTests {
|
||||
class ControllerEndpointDiscovererTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
||||
void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||
.run(assertDiscoverer((discoverer) -> assertThat(discoverer.getEndpoints()).isEmpty()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsShouldIncludeControllerEndpoints() {
|
||||
void getEndpointsShouldIncludeControllerEndpoints() {
|
||||
this.contextRunner.withUserConfiguration(TestControllerEndpoint.class).run(assertDiscoverer((discoverer) -> {
|
||||
Collection<ExposableControllerEndpoint> endpoints = discoverer.getEndpoints();
|
||||
assertThat(endpoints).hasSize(1);
|
||||
@@ -70,7 +70,7 @@ public class ControllerEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsShouldDiscoverProxyControllerEndpoints() {
|
||||
void getEndpointsShouldDiscoverProxyControllerEndpoints() {
|
||||
this.contextRunner.withUserConfiguration(TestProxyControllerEndpoint.class)
|
||||
.withConfiguration(AutoConfigurations.of(ValidationAutoConfiguration.class))
|
||||
.run(assertDiscoverer((discoverer) -> {
|
||||
@@ -84,7 +84,7 @@ public class ControllerEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsShouldIncludeRestControllerEndpoints() {
|
||||
void getEndpointsShouldIncludeRestControllerEndpoints() {
|
||||
this.contextRunner.withUserConfiguration(TestRestControllerEndpoint.class)
|
||||
.run(assertDiscoverer((discoverer) -> {
|
||||
Collection<ExposableControllerEndpoint> endpoints = discoverer.getEndpoints();
|
||||
@@ -96,7 +96,7 @@ public class ControllerEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsShouldDiscoverProxyRestControllerEndpoints() {
|
||||
void getEndpointsShouldDiscoverProxyRestControllerEndpoints() {
|
||||
this.contextRunner.withUserConfiguration(TestProxyRestControllerEndpoint.class)
|
||||
.withConfiguration(AutoConfigurations.of(ValidationAutoConfiguration.class))
|
||||
.run(assertDiscoverer((discoverer) -> {
|
||||
@@ -110,7 +110,7 @@ public class ControllerEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsShouldNotDiscoverRegularEndpoints() {
|
||||
void getEndpointsShouldNotDiscoverRegularEndpoints() {
|
||||
this.contextRunner.withUserConfiguration(WithRegularEndpointConfiguration.class)
|
||||
.run(assertDiscoverer((discoverer) -> {
|
||||
Collection<ExposableControllerEndpoint> endpoints = discoverer.getEndpoints();
|
||||
@@ -121,7 +121,7 @@ public class ControllerEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointWhenEndpointHasOperationsShouldThrowException() {
|
||||
void getEndpointWhenEndpointHasOperationsShouldThrowException() {
|
||||
this.contextRunner.withUserConfiguration(TestControllerWithOperation.class)
|
||||
.run(assertDiscoverer((discoverer) -> assertThatExceptionOfType(IllegalStateException.class)
|
||||
.isThrownBy(discoverer::getEndpoints)
|
||||
|
||||
@@ -56,18 +56,18 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ServletEndpointDiscovererTests {
|
||||
class ServletEndpointDiscovererTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
||||
void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
||||
this.contextRunner.withUserConfiguration(EmptyConfiguration.class)
|
||||
.run(assertDiscoverer((discoverer) -> assertThat(discoverer.getEndpoints()).isEmpty()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsShouldIncludeServletEndpoints() {
|
||||
void getEndpointsShouldIncludeServletEndpoints() {
|
||||
this.contextRunner.withUserConfiguration(TestServletEndpoint.class).run(assertDiscoverer((discoverer) -> {
|
||||
Collection<ExposableServletEndpoint> endpoints = discoverer.getEndpoints();
|
||||
assertThat(endpoints).hasSize(1);
|
||||
@@ -79,7 +79,7 @@ public class ServletEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsShouldDiscoverProxyServletEndpoints() {
|
||||
void getEndpointsShouldDiscoverProxyServletEndpoints() {
|
||||
this.contextRunner.withUserConfiguration(TestProxyServletEndpoint.class)
|
||||
.withConfiguration(AutoConfigurations.of(ValidationAutoConfiguration.class))
|
||||
.run(assertDiscoverer((discoverer) -> {
|
||||
@@ -93,7 +93,7 @@ public class ServletEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsShouldNotDiscoverRegularEndpoints() {
|
||||
void getEndpointsShouldNotDiscoverRegularEndpoints() {
|
||||
this.contextRunner.withUserConfiguration(WithRegularEndpointConfiguration.class)
|
||||
.run(assertDiscoverer((discoverer) -> {
|
||||
Collection<ExposableServletEndpoint> endpoints = discoverer.getEndpoints();
|
||||
@@ -104,7 +104,7 @@ public class ServletEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointWhenEndpointHasOperationsShouldThrowException() {
|
||||
void getEndpointWhenEndpointHasOperationsShouldThrowException() {
|
||||
this.contextRunner.withUserConfiguration(TestServletEndpointWithOperation.class)
|
||||
.run(assertDiscoverer((discoverer) -> assertThatExceptionOfType(IllegalStateException.class)
|
||||
.isThrownBy(discoverer::getEndpoints)
|
||||
@@ -112,21 +112,21 @@ public class ServletEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointWhenEndpointNotASupplierShouldThrowException() {
|
||||
void getEndpointWhenEndpointNotASupplierShouldThrowException() {
|
||||
this.contextRunner.withUserConfiguration(TestServletEndpointNotASupplier.class)
|
||||
.run(assertDiscoverer((discoverer) -> assertThatExceptionOfType(IllegalStateException.class)
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining("must be a supplier")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointWhenEndpointSuppliesWrongTypeShouldThrowException() {
|
||||
void getEndpointWhenEndpointSuppliesWrongTypeShouldThrowException() {
|
||||
this.contextRunner.withUserConfiguration(TestServletEndpointSupplierOfWrongType.class)
|
||||
.run(assertDiscoverer((discoverer) -> assertThatExceptionOfType(IllegalStateException.class)
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining("must supply an EndpointServlet")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointWhenEndpointSuppliesNullShouldThrowException() {
|
||||
void getEndpointWhenEndpointSuppliesNullShouldThrowException() {
|
||||
this.contextRunner.withUserConfiguration(TestServletEndpointSupplierOfNull.class)
|
||||
.run(assertDiscoverer((discoverer) -> assertThatExceptionOfType(IllegalStateException.class)
|
||||
.isThrownBy(discoverer::getEndpoints).withMessageContaining("must not supply null")));
|
||||
|
||||
@@ -66,15 +66,15 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
* @author Stephane Nicoll
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class WebEndpointDiscovererTests {
|
||||
class WebEndpointDiscovererTests {
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
||||
void getEndpointsWhenNoEndpointBeansShouldReturnEmptyCollection() {
|
||||
load(EmptyConfiguration.class, (discoverer) -> assertThat(discoverer.getEndpoints()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenWebExtensionIsMissingEndpointShouldThrowException() {
|
||||
void getEndpointsWhenWebExtensionIsMissingEndpointShouldThrowException() {
|
||||
load(TestWebEndpointExtensionConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException().isThrownBy(discoverer::getEndpoints)
|
||||
.withMessageContaining(
|
||||
@@ -82,7 +82,7 @@ public class WebEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenHasFilteredEndpointShouldOnlyDiscoverWebEndpoints() {
|
||||
void getEndpointsWhenHasFilteredEndpointShouldOnlyDiscoverWebEndpoints() {
|
||||
load(MultipleEndpointsConfiguration.class, (discoverer) -> {
|
||||
Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
|
||||
@@ -90,7 +90,7 @@ public class WebEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenHasWebExtensionShouldOverrideStandardEndpoint() {
|
||||
void getEndpointsWhenHasWebExtensionShouldOverrideStandardEndpoint() {
|
||||
load(OverriddenOperationWebEndpointExtensionConfiguration.class, (discoverer) -> {
|
||||
Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
|
||||
@@ -101,7 +101,7 @@ public class WebEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenExtensionAddsOperationShouldHaveBothOperations() {
|
||||
void getEndpointsWhenExtensionAddsOperationShouldHaveBothOperations() {
|
||||
load(AdditionalOperationWebEndpointConfiguration.class, (discoverer) -> {
|
||||
Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
|
||||
@@ -113,7 +113,7 @@ public class WebEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenPredicateForWriteOperationThatReturnsVoidShouldHaveNoProducedMediaTypes() {
|
||||
void getEndpointsWhenPredicateForWriteOperationThatReturnsVoidShouldHaveNoProducedMediaTypes() {
|
||||
load(VoidWriteOperationEndpointConfiguration.class, (discoverer) -> {
|
||||
Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("voidwrite"));
|
||||
@@ -124,7 +124,7 @@ public class WebEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenTwoExtensionsHaveTheSameEndpointTypeShouldThrowException() {
|
||||
void getEndpointsWhenTwoExtensionsHaveTheSameEndpointTypeShouldThrowException() {
|
||||
load(ClashingWebEndpointConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException().isThrownBy(discoverer::getEndpoints)
|
||||
.withMessageContaining("Found multiple extensions for the endpoint bean "
|
||||
@@ -132,14 +132,14 @@ public class WebEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenTwoStandardEndpointsHaveTheSameIdShouldThrowException() {
|
||||
void getEndpointsWhenTwoStandardEndpointsHaveTheSameIdShouldThrowException() {
|
||||
load(ClashingStandardEndpointConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException().isThrownBy(discoverer::getEndpoints)
|
||||
.withMessageContaining("Found two endpoints with the id 'test': "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenWhenEndpointHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||
void getEndpointsWhenWhenEndpointHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||
load(ClashingOperationsEndpointConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException().isThrownBy(discoverer::getEndpoints)
|
||||
.withMessageContaining("Unable to map duplicate endpoint operations: "
|
||||
@@ -148,7 +148,7 @@ public class WebEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenExtensionIsNotCompatibleWithTheEndpointTypeShouldThrowException() {
|
||||
void getEndpointsWhenExtensionIsNotCompatibleWithTheEndpointTypeShouldThrowException() {
|
||||
load(InvalidWebExtensionConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException().isThrownBy(discoverer::getEndpoints)
|
||||
.withMessageContaining("Endpoint bean 'nonWebEndpoint' cannot support the "
|
||||
@@ -156,7 +156,7 @@ public class WebEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenWhenExtensionHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||
void getEndpointsWhenWhenExtensionHasTwoOperationsWithTheSameNameShouldThrowException() {
|
||||
load(ClashingSelectorsWebEndpointExtensionConfiguration.class,
|
||||
(discoverer) -> assertThatIllegalStateException().isThrownBy(discoverer::getEndpoints)
|
||||
.withMessageContaining("Unable to map duplicate endpoint operations")
|
||||
@@ -164,7 +164,7 @@ public class WebEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenHasCacheWithTtlShouldCacheReadOperationWithTtlValue() {
|
||||
void getEndpointsWhenHasCacheWithTtlShouldCacheReadOperationWithTtlValue() {
|
||||
load((id) -> 500L, EndpointId::toString, TestEndpointConfiguration.class, (discoverer) -> {
|
||||
Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
|
||||
@@ -178,7 +178,7 @@ public class WebEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenOperationReturnsResourceShouldProduceApplicationOctetStream() {
|
||||
void getEndpointsWhenOperationReturnsResourceShouldProduceApplicationOctetStream() {
|
||||
load(ResourceEndpointConfiguration.class, (discoverer) -> {
|
||||
Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("resource"));
|
||||
@@ -189,7 +189,7 @@ public class WebEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenHasCustomMediaTypeShouldProduceCustomMediaType() {
|
||||
void getEndpointsWhenHasCustomMediaTypeShouldProduceCustomMediaType() {
|
||||
load(CustomMediaTypesEndpointConfiguration.class, (discoverer) -> {
|
||||
Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("custommediatypes"));
|
||||
@@ -203,7 +203,7 @@ public class WebEndpointDiscovererTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEndpointsWhenHasCustomPathShouldReturnCustomPath() {
|
||||
void getEndpointsWhenHasCustomPathShouldReturnCustomPath() {
|
||||
load((id) -> null, (id) -> "custom/" + id, AdditionalOperationWebEndpointConfiguration.class, (discoverer) -> {
|
||||
Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(discoverer.getEndpoints());
|
||||
assertThat(endpoints).containsOnlyKeys(EndpointId.of("test"));
|
||||
|
||||
@@ -58,27 +58,27 @@ import org.springframework.web.util.DefaultUriBuilderFactory;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ControllerEndpointHandlerMappingIntegrationTests {
|
||||
class ControllerEndpointHandlerMappingIntegrationTests {
|
||||
|
||||
private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner(
|
||||
AnnotationConfigReactiveWebServerApplicationContext::new).withUserConfiguration(EndpointConfiguration.class,
|
||||
ExampleWebFluxEndpoint.class);
|
||||
|
||||
@Test
|
||||
public void get() {
|
||||
void get() {
|
||||
this.contextRunner.run(withWebTestClient((webTestClient) -> webTestClient.get().uri("/actuator/example/one")
|
||||
.accept(MediaType.TEXT_PLAIN).exchange().expectStatus().isOk().expectHeader()
|
||||
.contentTypeCompatibleWith(MediaType.TEXT_PLAIN).expectBody(String.class).isEqualTo("One")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWithUnacceptableContentType() {
|
||||
void getWithUnacceptableContentType() {
|
||||
this.contextRunner.run(withWebTestClient((webTestClient) -> webTestClient.get().uri("/actuator/example/one")
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isEqualTo(HttpStatus.NOT_ACCEPTABLE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void post() {
|
||||
void post() {
|
||||
this.contextRunner.run(withWebTestClient((webTestClient) -> webTestClient.post().uri("/actuator/example/two")
|
||||
.syncBody(Collections.singletonMap("id", "test")).exchange().expectStatus().isCreated().expectHeader()
|
||||
.valueEquals(HttpHeaders.LOCATION, "/example/test")));
|
||||
|
||||
@@ -46,12 +46,12 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ControllerEndpointHandlerMappingTests {
|
||||
class ControllerEndpointHandlerMappingTests {
|
||||
|
||||
private final StaticApplicationContext context = new StaticApplicationContext();
|
||||
|
||||
@Test
|
||||
public void mappingWithNoPrefix() throws Exception {
|
||||
void mappingWithNoPrefix() throws Exception {
|
||||
ExposableControllerEndpoint first = firstEndpoint();
|
||||
ExposableControllerEndpoint second = secondEndpoint();
|
||||
ControllerEndpointHandlerMapping mapping = createMapping("", first, second);
|
||||
@@ -62,7 +62,7 @@ public class ControllerEndpointHandlerMappingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mappingWithPrefix() throws Exception {
|
||||
void mappingWithPrefix() throws Exception {
|
||||
ExposableControllerEndpoint first = firstEndpoint();
|
||||
ExposableControllerEndpoint second = secondEndpoint();
|
||||
ControllerEndpointHandlerMapping mapping = createMapping("actuator", first, second);
|
||||
@@ -75,7 +75,7 @@ public class ControllerEndpointHandlerMappingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mappingWithNoPath() throws Exception {
|
||||
void mappingWithNoPath() throws Exception {
|
||||
ExposableControllerEndpoint pathless = pathlessEndpoint();
|
||||
ControllerEndpointHandlerMapping mapping = createMapping("actuator", pathless);
|
||||
assertThat(getHandler(mapping, HttpMethod.GET, "/actuator/pathless"))
|
||||
@@ -85,7 +85,7 @@ public class ControllerEndpointHandlerMappingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mappingNarrowedToMethod() throws Exception {
|
||||
void mappingNarrowedToMethod() throws Exception {
|
||||
ExposableControllerEndpoint first = firstEndpoint();
|
||||
ControllerEndpointHandlerMapping mapping = createMapping("actuator", first);
|
||||
assertThatExceptionOfType(MethodNotAllowedException.class)
|
||||
|
||||
@@ -54,7 +54,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Andy Wilkinson
|
||||
* @see WebFluxEndpointHandlerMapping
|
||||
*/
|
||||
public class WebFluxEndpointIntegrationTests
|
||||
class WebFluxEndpointIntegrationTests
|
||||
extends AbstractWebEndpointIntegrationTests<AnnotationConfigReactiveWebServerApplicationContext> {
|
||||
|
||||
public WebFluxEndpointIntegrationTests() {
|
||||
@@ -74,7 +74,7 @@ public class WebFluxEndpointIntegrationTests
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseToOptionsRequestIncludesCorsHeaders() {
|
||||
void responseToOptionsRequestIncludesCorsHeaders() {
|
||||
load(TestEndpointConfiguration.class,
|
||||
(client) -> client.options().uri("/test").accept(MediaType.APPLICATION_JSON)
|
||||
.header("Access-Control-Request-Method", "POST").header("Origin", "https://example.com")
|
||||
@@ -84,7 +84,7 @@ public class WebFluxEndpointIntegrationTests
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationsThatReturnAResourceSupportRangeRequests() {
|
||||
void readOperationsThatReturnAResourceSupportRangeRequests() {
|
||||
load(ResourceEndpointConfiguration.class, (client) -> {
|
||||
byte[] responseBody = client.get().uri("/resource").header("Range", "bytes=0-3").exchange().expectStatus()
|
||||
.isEqualTo(HttpStatus.PARTIAL_CONTENT).expectHeader()
|
||||
|
||||
@@ -57,27 +57,27 @@ import org.springframework.web.util.DefaultUriBuilderFactory;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ControllerEndpointHandlerMappingIntegrationTests {
|
||||
class ControllerEndpointHandlerMappingIntegrationTests {
|
||||
|
||||
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner(
|
||||
AnnotationConfigServletWebServerApplicationContext::new).withUserConfiguration(EndpointConfiguration.class,
|
||||
ExampleMvcEndpoint.class);
|
||||
|
||||
@Test
|
||||
public void get() {
|
||||
void get() {
|
||||
this.contextRunner.run(withWebTestClient((webTestClient) -> webTestClient.get().uri("/actuator/example/one")
|
||||
.accept(MediaType.TEXT_PLAIN).exchange().expectStatus().isOk().expectHeader()
|
||||
.contentTypeCompatibleWith(MediaType.TEXT_PLAIN).expectBody(String.class).isEqualTo("One")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getWithUnacceptableContentType() {
|
||||
void getWithUnacceptableContentType() {
|
||||
this.contextRunner.run(withWebTestClient((webTestClient) -> webTestClient.get().uri("/actuator/example/one")
|
||||
.accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isEqualTo(HttpStatus.NOT_ACCEPTABLE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void post() {
|
||||
void post() {
|
||||
this.contextRunner.run(withWebTestClient((webTestClient) -> webTestClient.post().uri("/actuator/example/two")
|
||||
.syncBody(Collections.singletonMap("id", "test")).exchange().expectStatus().isCreated().expectHeader()
|
||||
.valueEquals(HttpHeaders.LOCATION, "/example/test")));
|
||||
|
||||
@@ -43,12 +43,12 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Phillip Webb
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ControllerEndpointHandlerMappingTests {
|
||||
class ControllerEndpointHandlerMappingTests {
|
||||
|
||||
private final StaticApplicationContext context = new StaticApplicationContext();
|
||||
|
||||
@Test
|
||||
public void mappingWithNoPrefix() throws Exception {
|
||||
void mappingWithNoPrefix() throws Exception {
|
||||
ExposableControllerEndpoint first = firstEndpoint();
|
||||
ExposableControllerEndpoint second = secondEndpoint();
|
||||
ControllerEndpointHandlerMapping mapping = createMapping("", first, second);
|
||||
@@ -60,7 +60,7 @@ public class ControllerEndpointHandlerMappingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mappingWithPrefix() throws Exception {
|
||||
void mappingWithPrefix() throws Exception {
|
||||
ExposableControllerEndpoint first = firstEndpoint();
|
||||
ExposableControllerEndpoint second = secondEndpoint();
|
||||
ControllerEndpointHandlerMapping mapping = createMapping("actuator", first, second);
|
||||
@@ -73,7 +73,7 @@ public class ControllerEndpointHandlerMappingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mappingNarrowedToMethod() throws Exception {
|
||||
void mappingNarrowedToMethod() throws Exception {
|
||||
ExposableControllerEndpoint first = firstEndpoint();
|
||||
ControllerEndpointHandlerMapping mapping = createMapping("actuator", first);
|
||||
assertThatExceptionOfType(HttpRequestMethodNotSupportedException.class)
|
||||
@@ -81,7 +81,7 @@ public class ControllerEndpointHandlerMappingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mappingWithNoPath() throws Exception {
|
||||
void mappingWithNoPath() throws Exception {
|
||||
ExposableControllerEndpoint pathless = pathlessEndpoint();
|
||||
ControllerEndpointHandlerMapping mapping = createMapping("actuator", pathless);
|
||||
assertThat(mapping.getHandler(request("GET", "/actuator/pathless")).getHandler())
|
||||
|
||||
@@ -64,7 +64,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Andy Wilkinson
|
||||
* @see WebMvcEndpointHandlerMapping
|
||||
*/
|
||||
public class MvcWebEndpointIntegrationTests
|
||||
class MvcWebEndpointIntegrationTests
|
||||
extends AbstractWebEndpointIntegrationTests<AnnotationConfigServletWebServerApplicationContext> {
|
||||
|
||||
public MvcWebEndpointIntegrationTests() {
|
||||
@@ -83,7 +83,7 @@ public class MvcWebEndpointIntegrationTests
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseToOptionsRequestIncludesCorsHeaders() {
|
||||
void responseToOptionsRequestIncludesCorsHeaders() {
|
||||
load(TestEndpointConfiguration.class,
|
||||
(client) -> client.options().uri("/test").accept(MediaType.APPLICATION_JSON)
|
||||
.header("Access-Control-Request-Method", "POST").header("Origin", "https://example.com")
|
||||
@@ -93,7 +93,7 @@ public class MvcWebEndpointIntegrationTests
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationsThatReturnAResourceSupportRangeRequests() {
|
||||
void readOperationsThatReturnAResourceSupportRangeRequests() {
|
||||
load(ResourceEndpointConfiguration.class, (client) -> {
|
||||
byte[] responseBody = client.get().uri("/resource").header("Range", "bytes=0-3").exchange().expectStatus()
|
||||
.isEqualTo(HttpStatus.PARTIAL_CONTENT).expectHeader()
|
||||
@@ -104,12 +104,12 @@ public class MvcWebEndpointIntegrationTests
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenRequestHasTrailingSlashShouldNotBeNull() {
|
||||
void matchWhenRequestHasTrailingSlashShouldNotBeNull() {
|
||||
assertThat(getMatchResult("/spring/")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchWhenRequestHasSuffixShouldBeNull() {
|
||||
void matchWhenRequestHasSuffixShouldBeNull() {
|
||||
assertThat(getMatchResult("/spring.do")).isNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,14 +34,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Brian Clozel
|
||||
* @author Michael McFadyen
|
||||
*/
|
||||
public class WebMvcTagsTests {
|
||||
class WebMvcTagsTests {
|
||||
|
||||
private final MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
private final MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
@Test
|
||||
public void uriTagIsDataRestsEffectiveRepositoryLookupPathWhenAvailable() {
|
||||
void uriTagIsDataRestsEffectiveRepositoryLookupPathWhenAvailable() {
|
||||
this.request.setAttribute(
|
||||
"org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.EFFECTIVE_REPOSITORY_RESOURCE_LOOKUP_PATH",
|
||||
new PathPatternParser().parse("/api/cities"));
|
||||
@@ -51,7 +51,7 @@ public class WebMvcTagsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriTagValueIsBestMatchingPatternWhenAvailable() {
|
||||
void uriTagValueIsBestMatchingPatternWhenAvailable() {
|
||||
this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, "/spring");
|
||||
this.response.setStatus(301);
|
||||
Tag tag = WebMvcTags.uri(this.request, this.response);
|
||||
@@ -59,85 +59,85 @@ public class WebMvcTagsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriTagValueIsRootWhenRequestHasNoPatternOrPathInfo() {
|
||||
void uriTagValueIsRootWhenRequestHasNoPatternOrPathInfo() {
|
||||
assertThat(WebMvcTags.uri(this.request, null).getValue()).isEqualTo("root");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriTagValueIsRootWhenRequestHasNoPatternAndSlashPathInfo() {
|
||||
void uriTagValueIsRootWhenRequestHasNoPatternAndSlashPathInfo() {
|
||||
this.request.setPathInfo("/");
|
||||
assertThat(WebMvcTags.uri(this.request, null).getValue()).isEqualTo("root");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriTagValueIsUnknownWhenRequestHasNoPatternAndNonRootPathInfo() {
|
||||
void uriTagValueIsUnknownWhenRequestHasNoPatternAndNonRootPathInfo() {
|
||||
this.request.setPathInfo("/example");
|
||||
assertThat(WebMvcTags.uri(this.request, null).getValue()).isEqualTo("UNKNOWN");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriTagValueIsRedirectionWhenResponseStatusIs3xx() {
|
||||
void uriTagValueIsRedirectionWhenResponseStatusIs3xx() {
|
||||
this.response.setStatus(301);
|
||||
Tag tag = WebMvcTags.uri(this.request, this.response);
|
||||
assertThat(tag.getValue()).isEqualTo("REDIRECTION");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriTagValueIsNotFoundWhenResponseStatusIs404() {
|
||||
void uriTagValueIsNotFoundWhenResponseStatusIs404() {
|
||||
this.response.setStatus(404);
|
||||
Tag tag = WebMvcTags.uri(this.request, this.response);
|
||||
assertThat(tag.getValue()).isEqualTo("NOT_FOUND");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriTagToleratesCustomResponseStatus() {
|
||||
void uriTagToleratesCustomResponseStatus() {
|
||||
this.response.setStatus(601);
|
||||
Tag tag = WebMvcTags.uri(this.request, this.response);
|
||||
assertThat(tag.getValue()).isEqualTo("root");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriTagIsUnknownWhenRequestIsNull() {
|
||||
void uriTagIsUnknownWhenRequestIsNull() {
|
||||
Tag tag = WebMvcTags.uri(null, null);
|
||||
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outcomeTagIsUnknownWhenResponseIsNull() {
|
||||
void outcomeTagIsUnknownWhenResponseIsNull() {
|
||||
Tag tag = WebMvcTags.outcome(null);
|
||||
assertThat(tag.getValue()).isEqualTo("UNKNOWN");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outcomeTagIsInformationalWhenResponseIs1xx() {
|
||||
void outcomeTagIsInformationalWhenResponseIs1xx() {
|
||||
this.response.setStatus(100);
|
||||
Tag tag = WebMvcTags.outcome(this.response);
|
||||
assertThat(tag.getValue()).isEqualTo("INFORMATIONAL");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outcomeTagIsSuccessWhenResponseIs2xx() {
|
||||
void outcomeTagIsSuccessWhenResponseIs2xx() {
|
||||
this.response.setStatus(200);
|
||||
Tag tag = WebMvcTags.outcome(this.response);
|
||||
assertThat(tag.getValue()).isEqualTo("SUCCESS");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outcomeTagIsRedirectionWhenResponseIs3xx() {
|
||||
void outcomeTagIsRedirectionWhenResponseIs3xx() {
|
||||
this.response.setStatus(301);
|
||||
Tag tag = WebMvcTags.outcome(this.response);
|
||||
assertThat(tag.getValue()).isEqualTo("REDIRECTION");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outcomeTagIsClientErrorWhenResponseIs4xx() {
|
||||
void outcomeTagIsClientErrorWhenResponseIs4xx() {
|
||||
this.response.setStatus(400);
|
||||
Tag tag = WebMvcTags.outcome(this.response);
|
||||
assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outcomeTagIsServerErrorWhenResponseIs5xx() {
|
||||
void outcomeTagIsServerErrorWhenResponseIs5xx() {
|
||||
this.response.setStatus(500);
|
||||
Tag tag = WebMvcTags.outcome(this.response);
|
||||
assertThat(tag.getValue()).isEqualTo("SERVER_ERROR");
|
||||
|
||||
@@ -1,224 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.web.test;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||
import org.junit.runners.model.FrameworkMethod;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
import org.junit.runners.model.Statement;
|
||||
|
||||
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.MergedAnnotations;
|
||||
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.web.util.DefaultUriBuilderFactory;
|
||||
import org.springframework.web.util.DefaultUriBuilderFactory.EncodingMode;
|
||||
|
||||
/**
|
||||
* Base class for web endpoint runners.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
abstract class AbstractWebEndpointRunner extends BlockJUnit4ClassRunner {
|
||||
|
||||
private static final Duration TIMEOUT = Duration.ofMinutes(6);
|
||||
|
||||
private final String name;
|
||||
|
||||
private final TestContext testContext;
|
||||
|
||||
protected AbstractWebEndpointRunner(Class<?> testClass, String name, ContextFactory contextFactory)
|
||||
throws InitializationError {
|
||||
super(testClass);
|
||||
this.name = name;
|
||||
this.testContext = new TestContext(testClass, contextFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String testName(FrameworkMethod method) {
|
||||
return super.testName(method) + "[" + getName() + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Statement withBeforeClasses(Statement statement) {
|
||||
Statement delegate = super.withBeforeClasses(statement);
|
||||
return new Statement() {
|
||||
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
AbstractWebEndpointRunner.this.testContext.beforeClass();
|
||||
delegate.evaluate();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Statement withAfterClasses(Statement statement) {
|
||||
Statement delegate = super.withAfterClasses(statement);
|
||||
return new Statement() {
|
||||
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
try {
|
||||
delegate.evaluate();
|
||||
}
|
||||
finally {
|
||||
AbstractWebEndpointRunner.this.testContext.afterClass();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) {
|
||||
Statement delegate = super.withBefores(method, target, statement);
|
||||
return new Statement() {
|
||||
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
AbstractWebEndpointRunner.this.testContext.beforeTest();
|
||||
delegate.evaluate();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Statement withAfters(FrameworkMethod method, Object target, Statement statement) {
|
||||
Statement delegate = super.withAfters(method, target, statement);
|
||||
return new Statement() {
|
||||
|
||||
@Override
|
||||
public void evaluate() throws Throwable {
|
||||
try {
|
||||
delegate.evaluate();
|
||||
}
|
||||
finally {
|
||||
AbstractWebEndpointRunner.this.testContext.afterTest();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
final class TestContext {
|
||||
|
||||
private final Class<?> testClass;
|
||||
|
||||
private final ContextFactory contextFactory;
|
||||
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
private List<PropertySource<?>> propertySources;
|
||||
|
||||
TestContext(Class<?> testClass, ContextFactory contextFactory) {
|
||||
this.testClass = testClass;
|
||||
this.contextFactory = contextFactory;
|
||||
}
|
||||
|
||||
void beforeClass() {
|
||||
this.applicationContext = createApplicationContext();
|
||||
WebTestClient webTestClient = createWebTestClient();
|
||||
injectIfPossible(this.testClass, webTestClient);
|
||||
injectIfPossible(this.testClass, this.applicationContext);
|
||||
}
|
||||
|
||||
void beforeTest() {
|
||||
capturePropertySources();
|
||||
}
|
||||
|
||||
void afterTest() {
|
||||
restorePropertySources();
|
||||
}
|
||||
|
||||
void afterClass() {
|
||||
if (this.applicationContext != null) {
|
||||
this.applicationContext.close();
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigurableApplicationContext createApplicationContext() {
|
||||
Class<?>[] members = this.testClass.getDeclaredClasses();
|
||||
List<Class<?>> configurationClasses = Stream.of(members).filter(this::isConfiguration)
|
||||
.collect(Collectors.toList());
|
||||
return this.contextFactory.createContext(new ArrayList<>(configurationClasses));
|
||||
}
|
||||
|
||||
private boolean isConfiguration(Class<?> candidate) {
|
||||
return MergedAnnotations.from(candidate, SearchStrategy.EXHAUSTIVE).isPresent(Configuration.class);
|
||||
}
|
||||
|
||||
private WebTestClient createWebTestClient() {
|
||||
DefaultUriBuilderFactory uriBuilderFactory = new DefaultUriBuilderFactory(
|
||||
"http://localhost:" + determinePort());
|
||||
uriBuilderFactory.setEncodingMode(EncodingMode.NONE);
|
||||
return WebTestClient.bindToServer().uriBuilderFactory(uriBuilderFactory).responseTimeout(TIMEOUT).build();
|
||||
}
|
||||
|
||||
private int determinePort() {
|
||||
if (this.applicationContext instanceof AnnotationConfigServletWebServerApplicationContext) {
|
||||
return ((AnnotationConfigServletWebServerApplicationContext) this.applicationContext).getWebServer()
|
||||
.getPort();
|
||||
}
|
||||
return this.applicationContext.getBean(PortHolder.class).getPort();
|
||||
}
|
||||
|
||||
private void injectIfPossible(Class<?> target, Object value) {
|
||||
ReflectionUtils.doWithFields(target, (field) -> {
|
||||
if (Modifier.isStatic(field.getModifiers()) && field.getType().isInstance(value)) {
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
ReflectionUtils.setField(field, null, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void capturePropertySources() {
|
||||
this.propertySources = new ArrayList<>();
|
||||
this.applicationContext.getEnvironment().getPropertySources().forEach(this.propertySources::add);
|
||||
}
|
||||
|
||||
private void restorePropertySources() {
|
||||
List<String> names = new ArrayList<>();
|
||||
MutablePropertySources propertySources = this.applicationContext.getEnvironment().getPropertySources();
|
||||
propertySources.forEach((propertySource) -> names.add(propertySource.getName()));
|
||||
names.forEach(propertySources::remove);
|
||||
this.propertySources.forEach(propertySources::addLast);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.web.test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.glassfish.jersey.server.model.Resource;
|
||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
|
||||
import org.springframework.boot.actuate.endpoint.invoke.convert.ConversionServiceParameterValueMapper;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
|
||||
import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpointDiscoverer;
|
||||
import org.springframework.boot.actuate.endpoint.web.jersey.JerseyEndpointResourceFactory;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jersey.ResourceConfigCustomizer;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* {@link BlockJUnit4ClassRunner} for Jersey.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class JerseyEndpointsRunner extends AbstractWebEndpointRunner {
|
||||
|
||||
JerseyEndpointsRunner(Class<?> testClass) throws InitializationError {
|
||||
super(testClass, "Jersey", JerseyEndpointsRunner::createContext);
|
||||
}
|
||||
|
||||
private static ConfigurableApplicationContext createContext(List<Class<?>> classes) {
|
||||
AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
|
||||
classes.add(JerseyEndpointConfiguration.class);
|
||||
context.register(ClassUtils.toClassArray(classes));
|
||||
context.refresh();
|
||||
return context;
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ImportAutoConfiguration({ JacksonAutoConfiguration.class, JerseyAutoConfiguration.class })
|
||||
static class JerseyEndpointConfiguration {
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
JerseyEndpointConfiguration(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TomcatServletWebServerFactory tomcat() {
|
||||
return new TomcatServletWebServerFactory(0);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ResourceConfig resourceConfig() {
|
||||
return new ResourceConfig();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ResourceConfigCustomizer webEndpointRegistrar() {
|
||||
return this::customize;
|
||||
}
|
||||
|
||||
private void customize(ResourceConfig config) {
|
||||
List<String> mediaTypes = Arrays.asList(MediaType.APPLICATION_JSON, ActuatorMediaType.V2_JSON);
|
||||
EndpointMediaTypes endpointMediaTypes = new EndpointMediaTypes(mediaTypes, mediaTypes);
|
||||
WebEndpointDiscoverer discoverer = new WebEndpointDiscoverer(this.applicationContext,
|
||||
new ConversionServiceParameterValueMapper(), endpointMediaTypes, null, Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
Collection<Resource> resources = new JerseyEndpointResourceFactory().createEndpointResources(
|
||||
new EndpointMapping("/actuator"), discoverer.getEndpoints(), endpointMediaTypes,
|
||||
new EndpointLinksResolver(discoverer.getEndpoints()));
|
||||
config.registerResources(new HashSet<>(resources));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.web.test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.runner.Runner;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
/**
|
||||
* A custom {@link Runner} that tests web endpoints that are made available over HTTP
|
||||
* using Jersey, Spring MVC, and WebFlux.
|
||||
* <p>
|
||||
* The following types can be automatically injected into static fields on the test class:
|
||||
* <ul>
|
||||
* <li>{@link WebTestClient}</li>
|
||||
* <li>{@link ConfigurableApplicationContext}</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* The {@link PropertySource PropertySources} that belong to the application context's
|
||||
* {@link org.springframework.core.env.Environment} are reset at the end of every test.
|
||||
* This means that {@link TestPropertyValues} can be used in a test without affecting the
|
||||
* {@code Environment} of other tests in the same class. The runner always sets the flag
|
||||
* {@code management.endpoints.web.exposure.include} to {@code *} so that web endpoints
|
||||
* are enabled.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class WebEndpointRunners extends Suite {
|
||||
|
||||
public WebEndpointRunners(Class<?> testClass) throws InitializationError {
|
||||
super(testClass, createRunners(testClass));
|
||||
}
|
||||
|
||||
private static List<Runner> createRunners(Class<?> testClass) throws InitializationError {
|
||||
List<Runner> runners = new ArrayList<>();
|
||||
runners.add(new WebFluxEndpointsRunner(testClass));
|
||||
runners.add(new WebMvcEndpointRunner(testClass));
|
||||
runners.add(new JerseyEndpointsRunner(testClass));
|
||||
return runners;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,16 +16,24 @@
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.web.test;
|
||||
|
||||
import java.util.List;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
/**
|
||||
* @author Phillip Webb
|
||||
* Signals that a test should be performed against all web endpoint implementations
|
||||
* (Jersey, Web MVC, and WebFlux)
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@FunctionalInterface
|
||||
interface ContextFactory {
|
||||
|
||||
ConfigurableApplicationContext createContext(List<Class<?>> configurationClasses);
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
@TestTemplate
|
||||
@ExtendWith(WebEndpointTestInvocationContextProvider.class)
|
||||
public @interface WebEndpointTest {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.web.test;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.glassfish.jersey.server.model.Resource;
|
||||
import org.junit.jupiter.api.extension.AfterEachCallback;
|
||||
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
||||
import org.junit.jupiter.api.extension.Extension;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.api.extension.ParameterContext;
|
||||
import org.junit.jupiter.api.extension.ParameterResolutionException;
|
||||
import org.junit.jupiter.api.extension.ParameterResolver;
|
||||
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
|
||||
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
|
||||
import org.springframework.boot.actuate.endpoint.invoke.convert.ConversionServiceParameterValueMapper;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
|
||||
import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpointDiscoverer;
|
||||
import org.springframework.boot.actuate.endpoint.web.jersey.JerseyEndpointResourceFactory;
|
||||
import org.springframework.boot.actuate.endpoint.web.reactive.WebFluxEndpointHandlerMapping;
|
||||
import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jersey.ResourceConfigCustomizer;
|
||||
import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.web.context.WebServerInitializedEvent;
|
||||
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext;
|
||||
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigRegistry;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.MergedAnnotations;
|
||||
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.reactive.HttpHandler;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
||||
import org.springframework.web.util.DefaultUriBuilderFactory;
|
||||
import org.springframework.web.util.DefaultUriBuilderFactory.EncodingMode;
|
||||
|
||||
/**
|
||||
* {@link TestTemplateInvocationContextProvider} for
|
||||
* {@link WebEndpointTest @WebEndpointTest}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class WebEndpointTestInvocationContextProvider implements TestTemplateInvocationContextProvider {
|
||||
|
||||
@Override
|
||||
public boolean supportsTestTemplate(ExtensionContext context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(
|
||||
ExtensionContext extensionContext) {
|
||||
return Stream.of(
|
||||
new WebEndpointsInvocationContext("Jersey",
|
||||
WebEndpointTestInvocationContextProvider::createJerseyContext),
|
||||
new WebEndpointsInvocationContext("WebMvc",
|
||||
WebEndpointTestInvocationContextProvider::createWebMvcContext),
|
||||
new WebEndpointsInvocationContext("WebFlux",
|
||||
WebEndpointTestInvocationContextProvider::createWebFluxContext));
|
||||
}
|
||||
|
||||
private static ConfigurableApplicationContext createJerseyContext(List<Class<?>> classes) {
|
||||
AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
|
||||
classes.add(JerseyEndpointConfiguration.class);
|
||||
context.register(ClassUtils.toClassArray(classes));
|
||||
context.refresh();
|
||||
return context;
|
||||
}
|
||||
|
||||
private static ConfigurableApplicationContext createWebMvcContext(List<Class<?>> classes) {
|
||||
AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
|
||||
classes.add(WebMvcEndpointConfiguration.class);
|
||||
context.register(ClassUtils.toClassArray(classes));
|
||||
context.refresh();
|
||||
return context;
|
||||
}
|
||||
|
||||
private static ConfigurableApplicationContext createWebFluxContext(List<Class<?>> classes) {
|
||||
AnnotationConfigReactiveWebServerApplicationContext context = new AnnotationConfigReactiveWebServerApplicationContext();
|
||||
classes.add(WebFluxEndpointConfiguration.class);
|
||||
context.register(ClassUtils.toClassArray(classes));
|
||||
context.refresh();
|
||||
return context;
|
||||
|
||||
}
|
||||
|
||||
private static class WebEndpointsInvocationContext
|
||||
implements TestTemplateInvocationContext, BeforeEachCallback, AfterEachCallback, ParameterResolver {
|
||||
|
||||
private static final Duration TIMEOUT = Duration.ofMinutes(6);
|
||||
|
||||
private final String name;
|
||||
|
||||
private final Function<List<Class<?>>, ConfigurableApplicationContext> contextFactory;
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
<T extends ConfigurableApplicationContext & AnnotationConfigRegistry> WebEndpointsInvocationContext(String name,
|
||||
Function<List<Class<?>>, ConfigurableApplicationContext> contextFactory) {
|
||||
this.name = name;
|
||||
this.contextFactory = contextFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeEach(ExtensionContext extensionContext) throws Exception {
|
||||
List<Class<?>> configurationClasses = Stream
|
||||
.of(extensionContext.getRequiredTestClass().getDeclaredClasses()).filter(this::isConfiguration)
|
||||
.collect(Collectors.toList());
|
||||
this.context = this.contextFactory.apply(configurationClasses);
|
||||
}
|
||||
|
||||
private boolean isConfiguration(Class<?> candidate) {
|
||||
return MergedAnnotations.from(candidate, SearchStrategy.EXHAUSTIVE).isPresent(Configuration.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterEach(ExtensionContext context) throws Exception {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
|
||||
throws ParameterResolutionException {
|
||||
Class<?> type = parameterContext.getParameter().getType();
|
||||
return type.equals(WebTestClient.class) || type.isAssignableFrom(ConfigurableApplicationContext.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
|
||||
throws ParameterResolutionException {
|
||||
Class<?> type = parameterContext.getParameter().getType();
|
||||
if (type.equals(WebTestClient.class)) {
|
||||
return createWebTestClient();
|
||||
}
|
||||
else {
|
||||
return this.context;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Extension> getAdditionalExtensions() {
|
||||
return Collections.singletonList(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName(int invocationIndex) {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
private WebTestClient createWebTestClient() {
|
||||
DefaultUriBuilderFactory uriBuilderFactory = new DefaultUriBuilderFactory(
|
||||
"http://localhost:" + determinePort());
|
||||
uriBuilderFactory.setEncodingMode(EncodingMode.NONE);
|
||||
return WebTestClient.bindToServer().uriBuilderFactory(uriBuilderFactory).responseTimeout(TIMEOUT).build();
|
||||
}
|
||||
|
||||
private int determinePort() {
|
||||
if (this.context instanceof AnnotationConfigServletWebServerApplicationContext) {
|
||||
return ((AnnotationConfigServletWebServerApplicationContext) this.context).getWebServer().getPort();
|
||||
}
|
||||
return this.context.getBean(PortHolder.class).getPort();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ImportAutoConfiguration({ JacksonAutoConfiguration.class, JerseyAutoConfiguration.class })
|
||||
static class JerseyEndpointConfiguration {
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
JerseyEndpointConfiguration(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TomcatServletWebServerFactory tomcat() {
|
||||
return new TomcatServletWebServerFactory(0);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ResourceConfig resourceConfig() {
|
||||
return new ResourceConfig();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ResourceConfigCustomizer webEndpointRegistrar() {
|
||||
return this::customize;
|
||||
}
|
||||
|
||||
private void customize(ResourceConfig config) {
|
||||
List<String> mediaTypes = Arrays.asList(javax.ws.rs.core.MediaType.APPLICATION_JSON,
|
||||
ActuatorMediaType.V2_JSON);
|
||||
EndpointMediaTypes endpointMediaTypes = new EndpointMediaTypes(mediaTypes, mediaTypes);
|
||||
WebEndpointDiscoverer discoverer = new WebEndpointDiscoverer(this.applicationContext,
|
||||
new ConversionServiceParameterValueMapper(), endpointMediaTypes, null, Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
Collection<Resource> resources = new JerseyEndpointResourceFactory().createEndpointResources(
|
||||
new EndpointMapping("/actuator"), discoverer.getEndpoints(), endpointMediaTypes,
|
||||
new EndpointLinksResolver(discoverer.getEndpoints()));
|
||||
config.registerResources(new HashSet<>(resources));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ImportAutoConfiguration({ JacksonAutoConfiguration.class, WebFluxAutoConfiguration.class })
|
||||
static class WebFluxEndpointConfiguration implements ApplicationListener<WebServerInitializedEvent> {
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
private final PortHolder portHolder = new PortHolder();
|
||||
|
||||
WebFluxEndpointConfiguration(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NettyReactiveWebServerFactory netty() {
|
||||
return new NettyReactiveWebServerFactory(0);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PortHolder portHolder() {
|
||||
return this.portHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(WebServerInitializedEvent event) {
|
||||
this.portHolder.setPort(event.getWebServer().getPort());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HttpHandler httpHandler(ApplicationContext applicationContext) {
|
||||
return WebHttpHandlerBuilder.applicationContext(applicationContext).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebFluxEndpointHandlerMapping webEndpointReactiveHandlerMapping() {
|
||||
List<String> mediaTypes = Arrays.asList(MediaType.APPLICATION_JSON_VALUE, ActuatorMediaType.V2_JSON);
|
||||
EndpointMediaTypes endpointMediaTypes = new EndpointMediaTypes(mediaTypes, mediaTypes);
|
||||
WebEndpointDiscoverer discoverer = new WebEndpointDiscoverer(this.applicationContext,
|
||||
new ConversionServiceParameterValueMapper(), endpointMediaTypes, null, Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
return new WebFluxEndpointHandlerMapping(new EndpointMapping("/actuator"), discoverer.getEndpoints(),
|
||||
endpointMediaTypes, new CorsConfiguration(), new EndpointLinksResolver(discoverer.getEndpoints()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ImportAutoConfiguration({ JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
|
||||
WebMvcAutoConfiguration.class, DispatcherServletAutoConfiguration.class })
|
||||
static class WebMvcEndpointConfiguration {
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
WebMvcEndpointConfiguration(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TomcatServletWebServerFactory tomcat() {
|
||||
return new TomcatServletWebServerFactory(0);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping() {
|
||||
List<String> mediaTypes = Arrays.asList(MediaType.APPLICATION_JSON_VALUE, ActuatorMediaType.V2_JSON);
|
||||
EndpointMediaTypes endpointMediaTypes = new EndpointMediaTypes(mediaTypes, mediaTypes);
|
||||
WebEndpointDiscoverer discoverer = new WebEndpointDiscoverer(this.applicationContext,
|
||||
new ConversionServiceParameterValueMapper(), endpointMediaTypes, null, Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
return new WebMvcEndpointHandlerMapping(new EndpointMapping("/actuator"), discoverer.getEndpoints(),
|
||||
endpointMediaTypes, new CorsConfiguration(), new EndpointLinksResolver(discoverer.getEndpoints()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.web.test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
|
||||
import org.springframework.boot.actuate.endpoint.invoke.convert.ConversionServiceParameterValueMapper;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
|
||||
import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpointDiscoverer;
|
||||
import org.springframework.boot.actuate.endpoint.web.reactive.WebFluxEndpointHandlerMapping;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration;
|
||||
import org.springframework.boot.web.context.WebServerInitializedEvent;
|
||||
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
|
||||
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.reactive.HttpHandler;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
||||
|
||||
/**
|
||||
* {@link BlockJUnit4ClassRunner} for Spring WebFlux.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class WebFluxEndpointsRunner extends AbstractWebEndpointRunner {
|
||||
|
||||
WebFluxEndpointsRunner(Class<?> testClass) throws InitializationError {
|
||||
super(testClass, "Reactive", WebFluxEndpointsRunner::createContext);
|
||||
}
|
||||
|
||||
private static ConfigurableApplicationContext createContext(List<Class<?>> classes) {
|
||||
AnnotationConfigReactiveWebServerApplicationContext context = new AnnotationConfigReactiveWebServerApplicationContext();
|
||||
classes.add(WebFluxEndpointConfiguration.class);
|
||||
context.register(ClassUtils.toClassArray(classes));
|
||||
context.refresh();
|
||||
return context;
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ImportAutoConfiguration({ JacksonAutoConfiguration.class, WebFluxAutoConfiguration.class })
|
||||
static class WebFluxEndpointConfiguration implements ApplicationListener<WebServerInitializedEvent> {
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
private final PortHolder portHolder = new PortHolder();
|
||||
|
||||
WebFluxEndpointConfiguration(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NettyReactiveWebServerFactory netty() {
|
||||
return new NettyReactiveWebServerFactory(0);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PortHolder portHolder() {
|
||||
return this.portHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(WebServerInitializedEvent event) {
|
||||
this.portHolder.setPort(event.getWebServer().getPort());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HttpHandler httpHandler(ApplicationContext applicationContext) {
|
||||
return WebHttpHandlerBuilder.applicationContext(applicationContext).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebFluxEndpointHandlerMapping webEndpointReactiveHandlerMapping() {
|
||||
List<String> mediaTypes = Arrays.asList(MediaType.APPLICATION_JSON_VALUE, ActuatorMediaType.V2_JSON);
|
||||
EndpointMediaTypes endpointMediaTypes = new EndpointMediaTypes(mediaTypes, mediaTypes);
|
||||
WebEndpointDiscoverer discoverer = new WebEndpointDiscoverer(this.applicationContext,
|
||||
new ConversionServiceParameterValueMapper(), endpointMediaTypes, null, Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
return new WebFluxEndpointHandlerMapping(new EndpointMapping("/actuator"), discoverer.getEndpoints(),
|
||||
endpointMediaTypes, new CorsConfiguration(), new EndpointLinksResolver(discoverer.getEndpoints()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.web.test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
|
||||
import org.springframework.boot.actuate.endpoint.invoke.convert.ConversionServiceParameterValueMapper;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointMapping;
|
||||
import org.springframework.boot.actuate.endpoint.web.EndpointMediaTypes;
|
||||
import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpointDiscoverer;
|
||||
import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
|
||||
/**
|
||||
* {@link BlockJUnit4ClassRunner} for Spring MVC.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class WebMvcEndpointRunner extends AbstractWebEndpointRunner {
|
||||
|
||||
WebMvcEndpointRunner(Class<?> testClass) throws InitializationError {
|
||||
super(testClass, "Spring MVC", WebMvcEndpointRunner::createContext);
|
||||
}
|
||||
|
||||
private static ConfigurableApplicationContext createContext(List<Class<?>> classes) {
|
||||
AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
|
||||
classes.add(WebMvcEndpointConfiguration.class);
|
||||
context.register(ClassUtils.toClassArray(classes));
|
||||
context.refresh();
|
||||
return context;
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ImportAutoConfiguration({ JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
|
||||
WebMvcAutoConfiguration.class, DispatcherServletAutoConfiguration.class })
|
||||
static class WebMvcEndpointConfiguration {
|
||||
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
WebMvcEndpointConfiguration(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TomcatServletWebServerFactory tomcat() {
|
||||
return new TomcatServletWebServerFactory(0);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping() {
|
||||
List<String> mediaTypes = Arrays.asList(MediaType.APPLICATION_JSON_VALUE, ActuatorMediaType.V2_JSON);
|
||||
EndpointMediaTypes endpointMediaTypes = new EndpointMediaTypes(mediaTypes, mediaTypes);
|
||||
WebEndpointDiscoverer discoverer = new WebEndpointDiscoverer(this.applicationContext,
|
||||
new ConversionServiceParameterValueMapper(), endpointMediaTypes, null, Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
return new WebMvcEndpointHandlerMapping(new EndpointMapping("/actuator"), discoverer.getEndpoints(),
|
||||
endpointMediaTypes, new CorsConfiguration(), new EndpointLinksResolver(discoverer.getEndpoints()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -50,7 +50,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Madhura Bhave
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class EnvironmentEndpointTests {
|
||||
class EnvironmentEndpointTests {
|
||||
|
||||
@AfterEach
|
||||
public void close() {
|
||||
@@ -58,7 +58,7 @@ public class EnvironmentEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicResponse() {
|
||||
void basicResponse() {
|
||||
ConfigurableEnvironment environment = emptyEnvironment();
|
||||
environment.getPropertySources().addLast(singleKeyPropertySource("one", "my.key", "first"));
|
||||
environment.getPropertySources().addLast(singleKeyPropertySource("two", "my.key", "second"));
|
||||
@@ -71,7 +71,7 @@ public class EnvironmentEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compositeSourceIsHandledCorrectly() {
|
||||
void compositeSourceIsHandledCorrectly() {
|
||||
ConfigurableEnvironment environment = emptyEnvironment();
|
||||
CompositePropertySource source = new CompositePropertySource("composite");
|
||||
source.addPropertySource(new MapPropertySource("one", Collections.singletonMap("foo", "bar")));
|
||||
@@ -85,7 +85,7 @@ public class EnvironmentEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sensitiveKeysHaveTheirValuesSanitized() {
|
||||
void sensitiveKeysHaveTheirValuesSanitized() {
|
||||
TestPropertyValues.of("dbPassword=123456", "apiKey=123456", "mySecret=123456", "myCredentials=123456",
|
||||
"VCAP_SERVICES=123456").applyToSystemProperties(() -> {
|
||||
EnvironmentDescriptor descriptor = new EnvironmentEndpoint(new StandardEnvironment())
|
||||
@@ -106,7 +106,7 @@ public class EnvironmentEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sensitiveKeysMatchingCredentialsPatternHaveTheirValuesSanitized() {
|
||||
void sensitiveKeysMatchingCredentialsPatternHaveTheirValuesSanitized() {
|
||||
TestPropertyValues
|
||||
.of("my.services.amqp-free.credentials.uri=123456", "credentials.http_api_uri=123456",
|
||||
"my.services.cleardb-free.credentials=123456", "foo.mycredentials.uri=123456")
|
||||
@@ -126,7 +126,7 @@ public class EnvironmentEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sensitiveKeysMatchingCustomNameHaveTheirValuesSanitized() {
|
||||
void sensitiveKeysMatchingCustomNameHaveTheirValuesSanitized() {
|
||||
TestPropertyValues.of("dbPassword=123456", "apiKey=123456").applyToSystemProperties(() -> {
|
||||
EnvironmentEndpoint endpoint = new EnvironmentEndpoint(new StandardEnvironment());
|
||||
endpoint.setKeysToSanitize("key");
|
||||
@@ -140,7 +140,7 @@ public class EnvironmentEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sensitiveKeysMatchingCustomPatternHaveTheirValuesSanitized() {
|
||||
void sensitiveKeysMatchingCustomPatternHaveTheirValuesSanitized() {
|
||||
TestPropertyValues.of("dbPassword=123456", "apiKey=123456").applyToSystemProperties(() -> {
|
||||
EnvironmentEndpoint endpoint = new EnvironmentEndpoint(new StandardEnvironment());
|
||||
endpoint.setKeysToSanitize(".*pass.*");
|
||||
@@ -154,7 +154,7 @@ public class EnvironmentEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyWithPlaceholderResolved() {
|
||||
void propertyWithPlaceholderResolved() {
|
||||
ConfigurableEnvironment environment = emptyEnvironment();
|
||||
TestPropertyValues.of("my.foo: ${bar.blah}", "bar.blah: hello").applyTo(environment);
|
||||
EnvironmentDescriptor descriptor = new EnvironmentEndpoint(environment).environment(null);
|
||||
@@ -162,7 +162,7 @@ public class EnvironmentEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyWithPlaceholderNotResolved() {
|
||||
void propertyWithPlaceholderNotResolved() {
|
||||
ConfigurableEnvironment environment = emptyEnvironment();
|
||||
TestPropertyValues.of("my.foo: ${bar.blah}").applyTo(environment);
|
||||
EnvironmentDescriptor descriptor = new EnvironmentEndpoint(environment).environment(null);
|
||||
@@ -171,7 +171,7 @@ public class EnvironmentEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyWithSensitivePlaceholderResolved() {
|
||||
void propertyWithSensitivePlaceholderResolved() {
|
||||
ConfigurableEnvironment environment = emptyEnvironment();
|
||||
TestPropertyValues.of("my.foo: http://${bar.password}://hello", "bar.password: hello").applyTo(environment);
|
||||
EnvironmentDescriptor descriptor = new EnvironmentEndpoint(environment).environment(null);
|
||||
@@ -180,7 +180,7 @@ public class EnvironmentEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyWithSensitivePlaceholderNotResolved() {
|
||||
void propertyWithSensitivePlaceholderNotResolved() {
|
||||
ConfigurableEnvironment environment = emptyEnvironment();
|
||||
TestPropertyValues.of("my.foo: http://${bar.password}://hello").applyTo(environment);
|
||||
EnvironmentDescriptor descriptor = new EnvironmentEndpoint(environment).environment(null);
|
||||
@@ -190,7 +190,7 @@ public class EnvironmentEndpointTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void propertyWithTypeOtherThanStringShouldNotFail() {
|
||||
void propertyWithTypeOtherThanStringShouldNotFail() {
|
||||
ConfigurableEnvironment environment = emptyEnvironment();
|
||||
environment.getPropertySources()
|
||||
.addFirst(singleKeyPropertySource("test", "foo", Collections.singletonMap("bar", "baz")));
|
||||
@@ -201,7 +201,7 @@ public class EnvironmentEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyEntry() {
|
||||
void propertyEntry() {
|
||||
TestPropertyValues.of("my.foo=another").applyToSystemProperties(() -> {
|
||||
StandardEnvironment environment = new StandardEnvironment();
|
||||
TestPropertyValues.of("my.foo=bar", "my.foo2=bar2").applyTo(environment, TestPropertyValues.Type.MAP,
|
||||
@@ -221,7 +221,7 @@ public class EnvironmentEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyEntryNotFound() {
|
||||
void propertyEntryNotFound() {
|
||||
ConfigurableEnvironment environment = emptyEnvironment();
|
||||
environment.getPropertySources().addFirst(singleKeyPropertySource("test", "foo", "bar"));
|
||||
EnvironmentEntryDescriptor descriptor = new EnvironmentEndpoint(environment).environmentEntry("does.not.exist");
|
||||
@@ -233,7 +233,7 @@ public class EnvironmentEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleSourcesWithSameProperty() {
|
||||
void multipleSourcesWithSameProperty() {
|
||||
ConfigurableEnvironment environment = emptyEnvironment();
|
||||
environment.getPropertySources().addFirst(singleKeyPropertySource("one", "a", "alpha"));
|
||||
environment.getPropertySources().addFirst(singleKeyPropertySource("two", "a", "apple"));
|
||||
|
||||
@@ -19,11 +19,9 @@ package org.springframework.boot.actuate.env;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointRunners;
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -32,87 +30,89 @@ import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
@RunWith(WebEndpointRunners.class)
|
||||
public class EnvironmentEndpointWebIntegrationTests {
|
||||
class EnvironmentEndpointWebIntegrationTests {
|
||||
|
||||
private static WebTestClient client;
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
private static ConfigurableApplicationContext context;
|
||||
private WebTestClient client;
|
||||
|
||||
@Before
|
||||
public void prepareEnvironment() {
|
||||
@BeforeEach
|
||||
public void prepareEnvironment(ConfigurableApplicationContext context, WebTestClient client) {
|
||||
TestPropertyValues.of("foo:bar", "fool:baz").applyTo(context);
|
||||
this.client = client;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void home() {
|
||||
client.get().uri("/actuator/env").exchange().expectStatus().isOk().expectBody()
|
||||
@WebEndpointTest
|
||||
void home() {
|
||||
this.client.get().uri("/actuator/env").exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("propertySources[?(@.name=='systemProperties')]").exists();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sub() {
|
||||
client.get().uri("/actuator/env/foo").exchange().expectStatus().isOk().expectBody().jsonPath("property.source")
|
||||
.isEqualTo("test").jsonPath("property.value").isEqualTo("bar");
|
||||
@WebEndpointTest
|
||||
void sub() {
|
||||
this.client.get().uri("/actuator/env/foo").exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("property.source").isEqualTo("test").jsonPath("property.value").isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void regex() {
|
||||
@WebEndpointTest
|
||||
void regex() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("food", null);
|
||||
EnvironmentEndpointWebIntegrationTests.context.getEnvironment().getPropertySources()
|
||||
.addFirst(new MapPropertySource("null-value", map));
|
||||
client.get().uri("/actuator/env?pattern=foo.*").exchange().expectStatus().isOk().expectBody()
|
||||
this.context.getEnvironment().getPropertySources().addFirst(new MapPropertySource("null-value", map));
|
||||
this.client.get().uri("/actuator/env?pattern=foo.*").exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath(forProperty("test", "foo")).isEqualTo("bar").jsonPath(forProperty("test", "fool"))
|
||||
.isEqualTo("baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedPathWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty() {
|
||||
@WebEndpointTest
|
||||
void nestedPathWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("my.foo", "${my.bar}");
|
||||
context.getEnvironment().getPropertySources().addFirst(new MapPropertySource("unresolved-placeholder", map));
|
||||
client.get().uri("/actuator/env/my.foo").exchange().expectStatus().isOk().expectBody()
|
||||
this.context.getEnvironment().getPropertySources()
|
||||
.addFirst(new MapPropertySource("unresolved-placeholder", map));
|
||||
this.client.get().uri("/actuator/env/my.foo").exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("property.value").isEqualTo("${my.bar}").jsonPath(forPropertyEntry("unresolved-placeholder"))
|
||||
.isEqualTo("${my.bar}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedPathWithSensitivePlaceholderShouldSanitize() {
|
||||
@WebEndpointTest
|
||||
void nestedPathWithSensitivePlaceholderShouldSanitize() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("my.foo", "${my.password}");
|
||||
map.put("my.password", "hello");
|
||||
context.getEnvironment().getPropertySources().addFirst(new MapPropertySource("placeholder", map));
|
||||
client.get().uri("/actuator/env/my.foo").exchange().expectStatus().isOk().expectBody()
|
||||
this.context.getEnvironment().getPropertySources().addFirst(new MapPropertySource("placeholder", map));
|
||||
this.client.get().uri("/actuator/env/my.foo").exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("property.value").isEqualTo("******").jsonPath(forPropertyEntry("placeholder"))
|
||||
.isEqualTo("******");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedPathForUnknownKeyShouldReturn404AndBody() {
|
||||
client.get().uri("/actuator/env/this.does.not.exist").exchange().expectStatus().isNotFound().expectBody()
|
||||
@WebEndpointTest
|
||||
void nestedPathForUnknownKeyShouldReturn404AndBody() {
|
||||
this.client.get().uri("/actuator/env/this.does.not.exist").exchange().expectStatus().isNotFound().expectBody()
|
||||
.jsonPath("property").doesNotExist().jsonPath("propertySources[?(@.name=='test')]").exists()
|
||||
.jsonPath("propertySources[?(@.name=='systemProperties')]").exists()
|
||||
.jsonPath("propertySources[?(@.name=='systemEnvironment')]").exists();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedPathMatchedByRegexWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty() {
|
||||
@WebEndpointTest
|
||||
void nestedPathMatchedByRegexWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("my.foo", "${my.bar}");
|
||||
context.getEnvironment().getPropertySources().addFirst(new MapPropertySource("unresolved-placeholder", map));
|
||||
client.get().uri("/actuator/env?pattern=my.*").exchange().expectStatus().isOk().expectBody()
|
||||
this.context.getEnvironment().getPropertySources()
|
||||
.addFirst(new MapPropertySource("unresolved-placeholder", map));
|
||||
this.client.get().uri("/actuator/env?pattern=my.*").exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath("propertySources[?(@.name=='unresolved-placeholder')].properties.['my.foo'].value")
|
||||
.isEqualTo("${my.bar}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedPathMatchedByRegexWithSensitivePlaceholderShouldSanitize() {
|
||||
@WebEndpointTest
|
||||
void nestedPathMatchedByRegexWithSensitivePlaceholderShouldSanitize() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("my.foo", "${my.password}");
|
||||
map.put("my.password", "hello");
|
||||
context.getEnvironment().getPropertySources().addFirst(new MapPropertySource("placeholder", map));
|
||||
client.get().uri("/actuator/env?pattern=my.*").exchange().expectStatus().isOk().expectBody()
|
||||
this.context.getEnvironment().getPropertySources().addFirst(new MapPropertySource("placeholder", map));
|
||||
this.client.get().uri("/actuator/env?pattern=my.*").exchange().expectStatus().isOk().expectBody()
|
||||
.jsonPath(forProperty("placeholder", "my.foo")).isEqualTo("******");
|
||||
}
|
||||
|
||||
|
||||
@@ -36,14 +36,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class FlywayEndpointTests {
|
||||
class FlywayEndpointTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(FlywayAutoConfiguration.class))
|
||||
.withUserConfiguration(EmbeddedDataSourceConfiguration.class).withBean("endpoint", FlywayEndpoint.class);
|
||||
|
||||
@Test
|
||||
public void flywayReportIsProduced() {
|
||||
void flywayReportIsProduced() {
|
||||
this.contextRunner.run((context) -> {
|
||||
Map<String, FlywayDescriptor> flywayBeans = context.getBean(FlywayEndpoint.class).flywayBeans()
|
||||
.getContexts().get(context.getId()).getFlywayBeans();
|
||||
@@ -54,7 +54,7 @@ public class FlywayEndpointTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void whenFlywayHasBeenBaselinedFlywayReportIsProduced() {
|
||||
void whenFlywayHasBeenBaselinedFlywayReportIsProduced() {
|
||||
this.contextRunner.withBean(FlywayMigrationStrategy.class, () -> (flyway) -> {
|
||||
flyway.setBaselineVersionAsString("2");
|
||||
flyway.baseline();
|
||||
|
||||
@@ -25,10 +25,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class ApplicationHealthIndicatorTests {
|
||||
class ApplicationHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
public void indicatesUp() {
|
||||
void indicatesUp() {
|
||||
ApplicationHealthIndicator healthIndicator = new ApplicationHealthIndicator();
|
||||
assertThat(healthIndicator.health().getStatus()).isEqualTo(Status.UP);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import static org.mockito.BDDMockito.given;
|
||||
* @author Phillip Webb
|
||||
* @author Christian Dupuis
|
||||
*/
|
||||
public class CompositeHealthIndicatorTests {
|
||||
class CompositeHealthIndicatorTests {
|
||||
|
||||
private HealthAggregator healthAggregator;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class CompositeHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithIndicators() {
|
||||
void createWithIndicators() {
|
||||
Map<String, HealthIndicator> indicators = new HashMap<>();
|
||||
indicators.put("one", this.one);
|
||||
indicators.put("two", this.two);
|
||||
@@ -70,7 +70,7 @@ public class CompositeHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws Exception {
|
||||
void testSerialization() throws Exception {
|
||||
Map<String, HealthIndicator> indicators = new HashMap<>();
|
||||
indicators.put("db1", this.one);
|
||||
indicators.put("db2", this.two);
|
||||
|
||||
@@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class CompositeReactiveHealthIndicatorTests {
|
||||
class CompositeReactiveHealthIndicatorTests {
|
||||
|
||||
private static final Health UNKNOWN_HEALTH = Health.unknown().withDetail("detail", "value").build();
|
||||
|
||||
@@ -41,7 +41,7 @@ public class CompositeReactiveHealthIndicatorTests {
|
||||
private OrderedHealthAggregator healthAggregator = new OrderedHealthAggregator();
|
||||
|
||||
@Test
|
||||
public void singleIndicator() {
|
||||
void singleIndicator() {
|
||||
CompositeReactiveHealthIndicator indicator = new CompositeReactiveHealthIndicator(this.healthAggregator,
|
||||
new DefaultReactiveHealthIndicatorRegistry(Collections.singletonMap("test", () -> Mono.just(HEALTHY))));
|
||||
StepVerifier.create(indicator.health()).consumeNextWith((h) -> {
|
||||
@@ -52,7 +52,7 @@ public class CompositeReactiveHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longHealth() {
|
||||
void longHealth() {
|
||||
Map<String, ReactiveHealthIndicator> indicators = new HashMap<>();
|
||||
for (int i = 0; i < 50; i++) {
|
||||
indicators.put("test" + i, new TimeoutHealth(10000, Status.UP));
|
||||
@@ -68,7 +68,7 @@ public class CompositeReactiveHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeoutReachedUsesFallback() {
|
||||
void timeoutReachedUsesFallback() {
|
||||
Map<String, ReactiveHealthIndicator> indicators = new HashMap<>();
|
||||
indicators.put("slow", new TimeoutHealth(10000, Status.UP));
|
||||
indicators.put("fast", new TimeoutHealth(10, Status.UP));
|
||||
@@ -83,7 +83,7 @@ public class CompositeReactiveHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeoutNotReached() {
|
||||
void timeoutNotReached() {
|
||||
Map<String, ReactiveHealthIndicator> indicators = new HashMap<>();
|
||||
indicators.put("slow", new TimeoutHealth(10000, Status.UP));
|
||||
indicators.put("fast", new TimeoutHealth(10, Status.UP));
|
||||
|
||||
@@ -33,7 +33,7 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Vedran Pavic
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class DefaultHealthIndicatorRegistryTests {
|
||||
class DefaultHealthIndicatorRegistryTests {
|
||||
|
||||
private HealthIndicator one = mock(HealthIndicator.class);
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DefaultHealthIndicatorRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void register() {
|
||||
void register() {
|
||||
this.registry.register("one", this.one);
|
||||
this.registry.register("two", this.two);
|
||||
assertThat(this.registry.getAll()).hasSize(2);
|
||||
@@ -58,14 +58,14 @@ public class DefaultHealthIndicatorRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerAlreadyUsedName() {
|
||||
void registerAlreadyUsedName() {
|
||||
this.registry.register("one", this.one);
|
||||
assertThatIllegalStateException().isThrownBy(() -> this.registry.register("one", this.two))
|
||||
.withMessageContaining("HealthIndicator with name 'one' already registered");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unregister() {
|
||||
void unregister() {
|
||||
this.registry.register("one", this.one);
|
||||
this.registry.register("two", this.two);
|
||||
assertThat(this.registry.getAll()).hasSize(2);
|
||||
@@ -75,7 +75,7 @@ public class DefaultHealthIndicatorRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unregisterUnknown() {
|
||||
void unregisterUnknown() {
|
||||
this.registry.register("one", this.one);
|
||||
assertThat(this.registry.getAll()).hasSize(1);
|
||||
HealthIndicator two = this.registry.unregister("two");
|
||||
@@ -84,7 +84,7 @@ public class DefaultHealthIndicatorRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllIsASnapshot() {
|
||||
void getAllIsASnapshot() {
|
||||
this.registry.register("one", this.one);
|
||||
Map<String, HealthIndicator> snapshot = this.registry.getAll();
|
||||
assertThat(snapshot).containsOnlyKeys("one");
|
||||
@@ -93,7 +93,7 @@ public class DefaultHealthIndicatorRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllIsImmutable() {
|
||||
void getAllIsImmutable() {
|
||||
this.registry.register("one", this.one);
|
||||
Map<String, HealthIndicator> snapshot = this.registry.getAll();
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(snapshot::clear);
|
||||
|
||||
@@ -34,7 +34,7 @@ import static org.mockito.Mockito.mock;
|
||||
* @author Vedran Pavic
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class DefaultReactiveHealthIndicatorRegistryTests {
|
||||
class DefaultReactiveHealthIndicatorRegistryTests {
|
||||
|
||||
private ReactiveHealthIndicator one = mock(ReactiveHealthIndicator.class);
|
||||
|
||||
@@ -50,7 +50,7 @@ public class DefaultReactiveHealthIndicatorRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void register() {
|
||||
void register() {
|
||||
this.registry.register("one", this.one);
|
||||
this.registry.register("two", this.two);
|
||||
assertThat(this.registry.getAll()).hasSize(2);
|
||||
@@ -59,14 +59,14 @@ public class DefaultReactiveHealthIndicatorRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerAlreadyUsedName() {
|
||||
void registerAlreadyUsedName() {
|
||||
this.registry.register("one", this.one);
|
||||
assertThatIllegalStateException().isThrownBy(() -> this.registry.register("one", this.two))
|
||||
.withMessageContaining("HealthIndicator with name 'one' already registered");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unregister() {
|
||||
void unregister() {
|
||||
this.registry.register("one", this.one);
|
||||
this.registry.register("two", this.two);
|
||||
assertThat(this.registry.getAll()).hasSize(2);
|
||||
@@ -76,7 +76,7 @@ public class DefaultReactiveHealthIndicatorRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unregisterUnknown() {
|
||||
void unregisterUnknown() {
|
||||
this.registry.register("one", this.one);
|
||||
assertThat(this.registry.getAll()).hasSize(1);
|
||||
ReactiveHealthIndicator two = this.registry.unregister("two");
|
||||
@@ -85,7 +85,7 @@ public class DefaultReactiveHealthIndicatorRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllIsASnapshot() {
|
||||
void getAllIsASnapshot() {
|
||||
this.registry.register("one", this.one);
|
||||
Map<String, ReactiveHealthIndicator> snapshot = this.registry.getAll();
|
||||
assertThat(snapshot).containsOnlyKeys("one");
|
||||
@@ -94,7 +94,7 @@ public class DefaultReactiveHealthIndicatorRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAllIsImmutable() {
|
||||
void getAllIsImmutable() {
|
||||
this.registry.register("one", this.one);
|
||||
Map<String, ReactiveHealthIndicator> snapshot = this.registry.getAll();
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(snapshot::clear);
|
||||
|
||||
@@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.entry;
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class HealthEndpointTests {
|
||||
class HealthEndpointTests {
|
||||
|
||||
private static final HealthIndicator one = () -> new Health.Builder().status(Status.UP).withDetail("first", "1")
|
||||
.build();
|
||||
@@ -42,7 +42,7 @@ public class HealthEndpointTests {
|
||||
.build();
|
||||
|
||||
@Test
|
||||
public void statusAndFullDetailsAreExposed() {
|
||||
void statusAndFullDetailsAreExposed() {
|
||||
Map<String, HealthIndicator> healthIndicators = new HashMap<>();
|
||||
healthIndicators.put("up", one);
|
||||
healthIndicators.put("upAgain", two);
|
||||
@@ -57,7 +57,7 @@ public class HealthEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusForComponentIsExposed() {
|
||||
void statusForComponentIsExposed() {
|
||||
HealthEndpoint endpoint = new HealthEndpoint(createHealthIndicator(Collections.singletonMap("test", one)));
|
||||
Health health = endpoint.healthForComponent("test");
|
||||
assertThat(health).isNotNull();
|
||||
@@ -66,14 +66,14 @@ public class HealthEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusForUnknownComponentReturnNull() {
|
||||
void statusForUnknownComponentReturnNull() {
|
||||
HealthEndpoint endpoint = new HealthEndpoint(createHealthIndicator(Collections.emptyMap()));
|
||||
Health health = endpoint.healthForComponent("does-not-exist");
|
||||
assertThat(health).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusForComponentInstanceIsExposed() {
|
||||
void statusForComponentInstanceIsExposed() {
|
||||
CompositeHealthIndicator compositeIndicator = new CompositeHealthIndicator(new OrderedHealthAggregator(),
|
||||
Collections.singletonMap("sub", () -> Health.down().build()));
|
||||
HealthEndpoint endpoint = new HealthEndpoint(
|
||||
@@ -85,7 +85,7 @@ public class HealthEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusForUnknownComponentInstanceReturnNull() {
|
||||
void statusForUnknownComponentInstanceReturnNull() {
|
||||
CompositeHealthIndicator compositeIndicator = new CompositeHealthIndicator(new OrderedHealthAggregator(),
|
||||
Collections.singletonMap("sub", () -> Health.down().build()));
|
||||
HealthEndpoint endpoint = new HealthEndpoint(
|
||||
@@ -95,7 +95,7 @@ public class HealthEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusForComponentInstanceThatIsNotACompositeReturnNull() {
|
||||
void statusForComponentInstanceThatIsNotACompositeReturnNull() {
|
||||
HealthEndpoint endpoint = new HealthEndpoint(
|
||||
createHealthIndicator(Collections.singletonMap("test", () -> Health.up().build())));
|
||||
Health health = endpoint.healthForComponentInstance("test", "does-not-exist");
|
||||
|
||||
@@ -23,15 +23,13 @@ import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointRunners;
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -43,55 +41,55 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(WebEndpointRunners.class)
|
||||
public class HealthEndpointWebIntegrationTests {
|
||||
class HealthEndpointWebIntegrationTests {
|
||||
|
||||
private static WebTestClient client;
|
||||
|
||||
private static ConfigurableApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void whenHealthIsUp200ResponseIsReturned() {
|
||||
@WebEndpointTest
|
||||
void whenHealthIsUp200ResponseIsReturned(WebTestClient client) {
|
||||
client.get().uri("/actuator/health").exchange().expectStatus().isOk().expectBody().jsonPath("status")
|
||||
.isEqualTo("UP").jsonPath("details.alpha.status").isEqualTo("UP").jsonPath("details.bravo.status")
|
||||
.isEqualTo("UP");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenHealthIsDown503ResponseIsReturned() throws Exception {
|
||||
withHealthIndicator("charlie", () -> Health.down().build(), () -> Mono.just(Health.down().build()), () -> {
|
||||
client.get().uri("/actuator/health").exchange().expectStatus().isEqualTo(HttpStatus.SERVICE_UNAVAILABLE)
|
||||
.expectBody().jsonPath("status").isEqualTo("DOWN").jsonPath("details.alpha.status").isEqualTo("UP")
|
||||
.jsonPath("details.bravo.status").isEqualTo("UP").jsonPath("details.charlie.status")
|
||||
.isEqualTo("DOWN");
|
||||
return null;
|
||||
});
|
||||
@WebEndpointTest
|
||||
void whenHealthIsDown503ResponseIsReturned(ApplicationContext context, WebTestClient client) throws Exception {
|
||||
withHealthIndicator(context, "charlie", () -> Health.down().build(), () -> Mono.just(Health.down().build()),
|
||||
() -> {
|
||||
client.get().uri("/actuator/health").exchange().expectStatus()
|
||||
.isEqualTo(HttpStatus.SERVICE_UNAVAILABLE).expectBody().jsonPath("status").isEqualTo("DOWN")
|
||||
.jsonPath("details.alpha.status").isEqualTo("UP").jsonPath("details.bravo.status")
|
||||
.isEqualTo("UP").jsonPath("details.charlie.status").isEqualTo("DOWN");
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenComponentHealthIsDown503ResponseIsReturned() throws Exception {
|
||||
withHealthIndicator("charlie", () -> Health.down().build(), () -> Mono.just(Health.down().build()), () -> {
|
||||
client.get().uri("/actuator/health/charlie").exchange().expectStatus()
|
||||
.isEqualTo(HttpStatus.SERVICE_UNAVAILABLE).expectBody().jsonPath("status").isEqualTo("DOWN");
|
||||
return null;
|
||||
});
|
||||
@WebEndpointTest
|
||||
void whenComponentHealthIsDown503ResponseIsReturned(ApplicationContext context, WebTestClient client)
|
||||
throws Exception {
|
||||
withHealthIndicator(context, "charlie", () -> Health.down().build(), () -> Mono.just(Health.down().build()),
|
||||
() -> {
|
||||
client.get().uri("/actuator/health/charlie").exchange().expectStatus()
|
||||
.isEqualTo(HttpStatus.SERVICE_UNAVAILABLE).expectBody().jsonPath("status")
|
||||
.isEqualTo("DOWN");
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenComponentInstanceHealthIsDown503ResponseIsReturned() throws Exception {
|
||||
@WebEndpointTest
|
||||
void whenComponentInstanceHealthIsDown503ResponseIsReturned(ApplicationContext context, WebTestClient client)
|
||||
throws Exception {
|
||||
CompositeHealthIndicator composite = new CompositeHealthIndicator(new OrderedHealthAggregator(),
|
||||
Collections.singletonMap("one", () -> Health.down().build()));
|
||||
CompositeReactiveHealthIndicator reactiveComposite = new CompositeReactiveHealthIndicator(
|
||||
new OrderedHealthAggregator(), new DefaultReactiveHealthIndicatorRegistry(
|
||||
Collections.singletonMap("one", () -> Mono.just(Health.down().build()))));
|
||||
withHealthIndicator("charlie", composite, reactiveComposite, () -> {
|
||||
withHealthIndicator(context, "charlie", composite, reactiveComposite, () -> {
|
||||
client.get().uri("/actuator/health/charlie/one").exchange().expectStatus()
|
||||
.isEqualTo(HttpStatus.SERVICE_UNAVAILABLE).expectBody().jsonPath("status").isEqualTo("DOWN");
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void withHealthIndicator(String name, HealthIndicator healthIndicator,
|
||||
private void withHealthIndicator(ApplicationContext context, String name, HealthIndicator healthIndicator,
|
||||
ReactiveHealthIndicator reactiveHealthIndicator, Callable<Void> action) throws Exception {
|
||||
Consumer<String> unregister;
|
||||
Consumer<String> reactiveUnregister;
|
||||
@@ -116,8 +114,8 @@ public class HealthEndpointWebIntegrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenHealthIndicatorIsRemovedResponseIsAltered() {
|
||||
@WebEndpointTest
|
||||
void whenHealthIndicatorIsRemovedResponseIsAltered(WebTestClient client, ApplicationContext context) {
|
||||
Consumer<String> reactiveRegister = null;
|
||||
try {
|
||||
ReactiveHealthIndicatorRegistry registry = context.getBean(ReactiveHealthIndicatorRegistry.class);
|
||||
|
||||
@@ -27,10 +27,10 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class HealthIndicatorReactiveAdapterTests {
|
||||
class HealthIndicatorReactiveAdapterTests {
|
||||
|
||||
@Test
|
||||
public void delegateReturnsHealth() {
|
||||
void delegateReturnsHealth() {
|
||||
HealthIndicator delegate = mock(HealthIndicator.class);
|
||||
HealthIndicatorReactiveAdapter adapter = new HealthIndicatorReactiveAdapter(delegate);
|
||||
Health status = Health.up().build();
|
||||
@@ -39,7 +39,7 @@ public class HealthIndicatorReactiveAdapterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delegateThrowError() {
|
||||
void delegateThrowError() {
|
||||
HealthIndicator delegate = mock(HealthIndicator.class);
|
||||
HealthIndicatorReactiveAdapter adapter = new HealthIndicatorReactiveAdapter(delegate);
|
||||
given(delegate.health()).willThrow(new IllegalStateException("Expected"));
|
||||
@@ -47,7 +47,7 @@ public class HealthIndicatorReactiveAdapterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delegateRunsOnTheElasticScheduler() {
|
||||
void delegateRunsOnTheElasticScheduler() {
|
||||
String currentThread = Thread.currentThread().getName();
|
||||
HealthIndicator delegate = () -> Health
|
||||
.status(Thread.currentThread().getName().equals(currentThread) ? Status.DOWN : Status.UP).build();
|
||||
|
||||
@@ -33,30 +33,30 @@ import static org.assertj.core.api.Assertions.entry;
|
||||
* @author Michael Pratt
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class HealthTests {
|
||||
class HealthTests {
|
||||
|
||||
@Test
|
||||
public void statusMustNotBeNull() {
|
||||
void statusMustNotBeNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new Health.Builder(null, null))
|
||||
.withMessageContaining("Status must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithStatus() {
|
||||
void createWithStatus() {
|
||||
Health health = Health.status(Status.UP).build();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithDetails() {
|
||||
void createWithDetails() {
|
||||
Health health = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")).build();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails()).containsOnly(entry("a", "b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsAndHashCode() {
|
||||
void equalsAndHashCode() {
|
||||
Health h1 = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")).build();
|
||||
Health h2 = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")).build();
|
||||
Health h3 = new Health.Builder(Status.UP).build();
|
||||
@@ -69,7 +69,7 @@ public class HealthTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withException() {
|
||||
void withException() {
|
||||
RuntimeException ex = new RuntimeException("bang");
|
||||
Health health = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")).withException(ex).build();
|
||||
assertThat(health.getDetails()).containsOnly(entry("a", "b"),
|
||||
@@ -77,13 +77,13 @@ public class HealthTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withDetails() {
|
||||
void withDetails() {
|
||||
Health health = new Health.Builder(Status.UP, Collections.singletonMap("a", "b")).withDetail("c", "d").build();
|
||||
assertThat(health.getDetails()).containsOnly(entry("a", "b"), entry("c", "d"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withDetailsMap() {
|
||||
void withDetailsMap() {
|
||||
Map<String, Object> details = new LinkedHashMap<>();
|
||||
details.put("a", "b");
|
||||
details.put("c", "d");
|
||||
@@ -92,7 +92,7 @@ public class HealthTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withDetailsMapDuplicateKeys() {
|
||||
void withDetailsMapDuplicateKeys() {
|
||||
Map<String, Object> details = new LinkedHashMap<>();
|
||||
details.put("c", "d");
|
||||
details.put("a", "e");
|
||||
@@ -101,7 +101,7 @@ public class HealthTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withDetailsMultipleMaps() {
|
||||
void withDetailsMultipleMaps() {
|
||||
Map<String, Object> details1 = new LinkedHashMap<>();
|
||||
details1.put("a", "b");
|
||||
details1.put("c", "d");
|
||||
@@ -113,35 +113,35 @@ public class HealthTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unknownWithDetails() {
|
||||
void unknownWithDetails() {
|
||||
Health health = new Health.Builder().unknown().withDetail("a", "b").build();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UNKNOWN);
|
||||
assertThat(health.getDetails()).containsOnly(entry("a", "b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unknown() {
|
||||
void unknown() {
|
||||
Health health = new Health.Builder().unknown().build();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UNKNOWN);
|
||||
assertThat(health.getDetails()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void upWithDetails() {
|
||||
void upWithDetails() {
|
||||
Health health = new Health.Builder().up().withDetail("a", "b").build();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails()).containsOnly(entry("a", "b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void up() {
|
||||
void up() {
|
||||
Health health = new Health.Builder().up().build();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void downWithException() {
|
||||
void downWithException() {
|
||||
RuntimeException ex = new RuntimeException("bang");
|
||||
Health health = Health.down(ex).build();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||
@@ -149,28 +149,28 @@ public class HealthTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void down() {
|
||||
void down() {
|
||||
Health health = Health.down().build();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
|
||||
assertThat(health.getDetails()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outOfService() {
|
||||
void outOfService() {
|
||||
Health health = Health.outOfService().build();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.OUT_OF_SERVICE);
|
||||
assertThat(health.getDetails()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void statusCode() {
|
||||
void statusCode() {
|
||||
Health health = Health.status("UP").build();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void status() {
|
||||
void status() {
|
||||
Health health = Health.status(Status.UP).build();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
assertThat(health.getDetails()).isEmpty();
|
||||
|
||||
@@ -42,14 +42,14 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class HealthWebEndpointResponseMapperTests {
|
||||
class HealthWebEndpointResponseMapperTests {
|
||||
|
||||
private final HealthStatusHttpMapper statusHttpMapper = new HealthStatusHttpMapper();
|
||||
|
||||
private Set<String> authorizedRoles = Collections.singleton("ACTUATOR");
|
||||
|
||||
@Test
|
||||
public void mapDetailsWithDisableDetailsDoesNotInvokeSupplier() {
|
||||
void mapDetailsWithDisableDetailsDoesNotInvokeSupplier() {
|
||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.NEVER);
|
||||
Supplier<Health> supplier = mockSupplier();
|
||||
SecurityContext securityContext = mock(SecurityContext.class);
|
||||
@@ -60,7 +60,7 @@ public class HealthWebEndpointResponseMapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapDetailsWithUnauthorizedUserDoesNotInvokeSupplier() {
|
||||
void mapDetailsWithUnauthorizedUserDoesNotInvokeSupplier() {
|
||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.WHEN_AUTHORIZED);
|
||||
Supplier<Health> supplier = mockSupplier();
|
||||
SecurityContext securityContext = mockSecurityContext("USER");
|
||||
@@ -72,7 +72,7 @@ public class HealthWebEndpointResponseMapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapDetailsWithAuthorizedUserInvokeSupplier() {
|
||||
void mapDetailsWithAuthorizedUserInvokeSupplier() {
|
||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.WHEN_AUTHORIZED);
|
||||
Supplier<Health> supplier = mockSupplier();
|
||||
given(supplier.get()).willReturn(Health.down().build());
|
||||
@@ -85,7 +85,7 @@ public class HealthWebEndpointResponseMapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapDetailsWithUnavailableHealth() {
|
||||
void mapDetailsWithUnavailableHealth() {
|
||||
HealthWebEndpointResponseMapper mapper = createMapper(ShowDetails.ALWAYS);
|
||||
Supplier<Health> supplier = mockSupplier();
|
||||
SecurityContext securityContext = mock(SecurityContext.class);
|
||||
|
||||
@@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Christian Dupuis
|
||||
*/
|
||||
public class OrderedHealthAggregatorTests {
|
||||
class OrderedHealthAggregatorTests {
|
||||
|
||||
private OrderedHealthAggregator healthAggregator;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class OrderedHealthAggregatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultOrder() {
|
||||
void defaultOrder() {
|
||||
Map<String, Health> healths = new HashMap<>();
|
||||
healths.put("h1", new Health.Builder().status(Status.DOWN).build());
|
||||
healths.put("h2", new Health.Builder().status(Status.UP).build());
|
||||
@@ -50,7 +50,7 @@ public class OrderedHealthAggregatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customOrder() {
|
||||
void customOrder() {
|
||||
this.healthAggregator.setStatusOrder(Status.UNKNOWN, Status.UP, Status.OUT_OF_SERVICE, Status.DOWN);
|
||||
Map<String, Health> healths = new HashMap<>();
|
||||
healths.put("h1", new Health.Builder().status(Status.DOWN).build());
|
||||
@@ -61,7 +61,7 @@ public class OrderedHealthAggregatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultOrderWithCustomStatus() {
|
||||
void defaultOrderWithCustomStatus() {
|
||||
Map<String, Health> healths = new HashMap<>();
|
||||
healths.put("h1", new Health.Builder().status(Status.DOWN).build());
|
||||
healths.put("h2", new Health.Builder().status(Status.UP).build());
|
||||
@@ -72,7 +72,7 @@ public class OrderedHealthAggregatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customOrderWithCustomStatus() {
|
||||
void customOrderWithCustomStatus() {
|
||||
this.healthAggregator.setStatusOrder(Arrays.asList("DOWN", "OUT_OF_SERVICE", "UP", "UNKNOWN", "CUSTOM"));
|
||||
Map<String, Health> healths = new HashMap<>();
|
||||
healths.put("h1", new Health.Builder().status(Status.DOWN).build());
|
||||
|
||||
@@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ReactiveHealthIndicatorRegistryFactoryTests {
|
||||
class ReactiveHealthIndicatorRegistryFactoryTests {
|
||||
|
||||
private static final Health UP = new Health.Builder().status(Status.UP).build();
|
||||
|
||||
@@ -38,14 +38,14 @@ public class ReactiveHealthIndicatorRegistryFactoryTests {
|
||||
private final ReactiveHealthIndicatorRegistryFactory factory = new ReactiveHealthIndicatorRegistryFactory();
|
||||
|
||||
@Test
|
||||
public void defaultHealthIndicatorNameFactory() {
|
||||
void defaultHealthIndicatorNameFactory() {
|
||||
ReactiveHealthIndicatorRegistry registry = this.factory.createReactiveHealthIndicatorRegistry(
|
||||
Collections.singletonMap("myHealthIndicator", () -> Mono.just(UP)), null);
|
||||
assertThat(registry.getAll()).containsOnlyKeys("my");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthIndicatorIsAdapted() {
|
||||
void healthIndicatorIsAdapted() {
|
||||
ReactiveHealthIndicatorRegistry registry = this.factory.createReactiveHealthIndicatorRegistry(
|
||||
Collections.singletonMap("test", () -> Mono.just(UP)), Collections.singletonMap("regular", () -> DOWN));
|
||||
assertThat(registry.getAll()).containsOnlyKeys("test", "regular");
|
||||
|
||||
@@ -36,10 +36,10 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
public class InfluxDbHealthIndicatorTests {
|
||||
class InfluxDbHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
public void influxDbIsUp() {
|
||||
void influxDbIsUp() {
|
||||
Pong pong = mock(Pong.class);
|
||||
given(pong.getVersion()).willReturn("0.9");
|
||||
InfluxDB influxDB = mock(InfluxDB.class);
|
||||
@@ -52,7 +52,7 @@ public class InfluxDbHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void influxDbIsDown() {
|
||||
void influxDbIsDown() {
|
||||
InfluxDB influxDB = mock(InfluxDB.class);
|
||||
given(influxDB.ping()).willThrow(new InfluxDBException(new IOException("Connection failed")));
|
||||
InfluxDbHealthIndicator healthIndicator = new InfluxDbHealthIndicator(influxDB);
|
||||
|
||||
@@ -32,12 +32,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class EnvironmentInfoContributorTests {
|
||||
class EnvironmentInfoContributorTests {
|
||||
|
||||
private final StandardEnvironment environment = new StandardEnvironment();
|
||||
|
||||
@Test
|
||||
public void extractOnlyInfoProperty() {
|
||||
void extractOnlyInfoProperty() {
|
||||
TestPropertyValues.of("info.app=my app", "info.version=1.0.0", "foo=bar").applyTo(this.environment);
|
||||
Info actual = contributeFrom(this.environment);
|
||||
assertThat(actual.get("app", String.class)).isEqualTo("my app");
|
||||
@@ -46,7 +46,7 @@ public class EnvironmentInfoContributorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractNoEntry() {
|
||||
void extractNoEntry() {
|
||||
TestPropertyValues.of("foo=bar").applyTo(this.environment);
|
||||
Info actual = contributeFrom(this.environment);
|
||||
assertThat(actual.getDetails()).isEmpty();
|
||||
@@ -54,7 +54,7 @@ public class EnvironmentInfoContributorTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void propertiesFromEnvironmentShouldBindCorrectly() {
|
||||
void propertiesFromEnvironmentShouldBindCorrectly() {
|
||||
TestPropertyValues.of("INFO_ENVIRONMENT_FOO=green").applyTo(this.environment, Type.SYSTEM_ENVIRONMENT);
|
||||
Info actual = contributeFrom(this.environment);
|
||||
assertThat(actual.get("environment", Map.class)).containsEntry("foo", "green");
|
||||
|
||||
@@ -32,11 +32,11 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class GitInfoContributorTests {
|
||||
class GitInfoContributorTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void coerceDate() {
|
||||
void coerceDate() {
|
||||
Properties properties = new Properties();
|
||||
properties.put("branch", "master");
|
||||
properties.put("commit.time", "2016-03-04T14:36:33+0100");
|
||||
@@ -51,7 +51,7 @@ public class GitInfoContributorTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void shortenCommitId() {
|
||||
void shortenCommitId() {
|
||||
Properties properties = new Properties();
|
||||
properties.put("branch", "master");
|
||||
properties.put("commit.id", "8e29a0b0d423d2665c6ee5171947c101a5c15681");
|
||||
@@ -64,7 +64,7 @@ public class GitInfoContributorTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void withGitIdAndAbbrev() {
|
||||
void withGitIdAndAbbrev() {
|
||||
// gh-11892
|
||||
Properties properties = new Properties();
|
||||
properties.put("branch", "master");
|
||||
|
||||
@@ -32,10 +32,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Meang Akira Tanaka
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class InfoEndpointTests {
|
||||
class InfoEndpointTests {
|
||||
|
||||
@Test
|
||||
public void info() {
|
||||
void info() {
|
||||
InfoEndpoint endpoint = new InfoEndpoint(Arrays.asList((builder) -> builder.withDetail("key1", "value1"),
|
||||
(builder) -> builder.withDetail("key2", "value2")));
|
||||
Map<String, Object> info = endpoint.info();
|
||||
@@ -45,7 +45,7 @@ public class InfoEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void infoWithNoContributorsProducesEmptyMap() {
|
||||
void infoWithNoContributorsProducesEmptyMap() {
|
||||
InfoEndpoint endpoint = new InfoEndpoint(Collections.emptyList());
|
||||
Map<String, Object> info = endpoint.info();
|
||||
assertThat(info).isEmpty();
|
||||
|
||||
@@ -20,11 +20,8 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointRunners;
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -38,14 +35,11 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
* @author Stephane Nicoll
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(WebEndpointRunners.class)
|
||||
@TestPropertySource(properties = { "info.app.name=MyService" })
|
||||
public class InfoEndpointWebIntegrationTests {
|
||||
class InfoEndpointWebIntegrationTests {
|
||||
|
||||
private static WebTestClient client;
|
||||
|
||||
@Test
|
||||
public void info() {
|
||||
@WebEndpointTest
|
||||
void info(WebTestClient client) {
|
||||
client.get().uri("/actuator/info").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk()
|
||||
.expectBody().jsonPath("beanName1.key11").isEqualTo("value11").jsonPath("beanName1.key12")
|
||||
.isEqualTo("value12").jsonPath("beanName2.key21").isEqualTo("value21").jsonPath("beanName2.key22")
|
||||
|
||||
@@ -27,16 +27,16 @@ import static org.assertj.core.api.Assertions.entry;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class InfoTests {
|
||||
class InfoTests {
|
||||
|
||||
@Test
|
||||
public void infoIsImmutable() {
|
||||
void infoIsImmutable() {
|
||||
Info info = new Info.Builder().withDetail("foo", "bar").build();
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(info.getDetails()::clear);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void infoTakesCopyOfMap() {
|
||||
void infoTakesCopyOfMap() {
|
||||
Info.Builder builder = new Info.Builder();
|
||||
builder.withDetail("foo", "bar");
|
||||
Info build = builder.build();
|
||||
|
||||
@@ -26,15 +26,15 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class SimpleInfoContributorTests {
|
||||
class SimpleInfoContributorTests {
|
||||
|
||||
@Test
|
||||
public void prefixIsMandatory() {
|
||||
void prefixIsMandatory() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new SimpleInfoContributor(null, new Object()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapSimpleObject() {
|
||||
void mapSimpleObject() {
|
||||
Object o = new Object();
|
||||
Info info = contributeFrom("test", o);
|
||||
assertThat(info.get("test")).isSameAs(o);
|
||||
|
||||
@@ -35,7 +35,7 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Tim Ysewyn
|
||||
*/
|
||||
public class IntegrationGraphEndpointTests {
|
||||
class IntegrationGraphEndpointTests {
|
||||
|
||||
@Mock
|
||||
private IntegrationGraphServer integrationGraphServer;
|
||||
@@ -49,7 +49,7 @@ public class IntegrationGraphEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOperationShouldReturnGraph() {
|
||||
void readOperationShouldReturnGraph() {
|
||||
Graph mockedGraph = mock(Graph.class);
|
||||
given(this.integrationGraphServer.getGraph()).willReturn(mockedGraph);
|
||||
Graph graph = this.integrationGraphEndpoint.graph();
|
||||
@@ -58,7 +58,7 @@ public class IntegrationGraphEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeOperationShouldRebuildGraph() {
|
||||
void writeOperationShouldRebuildGraph() {
|
||||
this.integrationGraphEndpoint.rebuild();
|
||||
verify(this.integrationGraphServer).rebuild();
|
||||
}
|
||||
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
package org.springframework.boot.actuate.integration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointRunners;
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -33,21 +30,18 @@ import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
*
|
||||
* @author Tim Ysewyn
|
||||
*/
|
||||
@RunWith(WebEndpointRunners.class)
|
||||
public class IntegrationGraphEndpointWebIntegrationTests {
|
||||
class IntegrationGraphEndpointWebIntegrationTests {
|
||||
|
||||
private static WebTestClient client;
|
||||
|
||||
@Test
|
||||
public void graph() {
|
||||
@WebEndpointTest
|
||||
void graph(WebTestClient client) {
|
||||
client.get().uri("/actuator/integrationgraph").accept(MediaType.APPLICATION_JSON).exchange().expectStatus()
|
||||
.isOk().expectBody().jsonPath("contentDescriptor.providerVersion").isNotEmpty()
|
||||
.jsonPath("contentDescriptor.providerFormatVersion").isEqualTo(1.0f)
|
||||
.jsonPath("contentDescriptor.provider").isEqualTo("spring-integration");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rebuild() {
|
||||
@WebEndpointTest
|
||||
void rebuild(WebTestClient client) {
|
||||
client.post().uri("/actuator/integrationgraph").accept(MediaType.APPLICATION_JSON).exchange().expectStatus()
|
||||
.isNoContent();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Dave Syer
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class DataSourceHealthIndicatorTests {
|
||||
class DataSourceHealthIndicatorTests {
|
||||
|
||||
private final DataSourceHealthIndicator indicator = new DataSourceHealthIndicator();
|
||||
|
||||
@@ -65,7 +65,7 @@ public class DataSourceHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthIndicatorWithDefaultSettings() {
|
||||
void healthIndicatorWithDefaultSettings() {
|
||||
this.indicator.setDataSource(this.dataSource);
|
||||
Health health = this.indicator.health();
|
||||
assertThat(health.getStatus()).isEqualTo(Status.UP);
|
||||
@@ -74,7 +74,7 @@ public class DataSourceHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthIndicatorWithCustomValidationQuery() {
|
||||
void healthIndicatorWithCustomValidationQuery() {
|
||||
String customValidationQuery = "SELECT COUNT(*) from FOO";
|
||||
new JdbcTemplate(this.dataSource).execute("CREATE TABLE FOO (id INTEGER IDENTITY PRIMARY KEY)");
|
||||
this.indicator.setDataSource(this.dataSource);
|
||||
@@ -86,7 +86,7 @@ public class DataSourceHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthIndicatorWithInvalidValidationQuery() {
|
||||
void healthIndicatorWithInvalidValidationQuery() {
|
||||
String invalidValidationQuery = "SELECT COUNT(*) from BAR";
|
||||
this.indicator.setDataSource(this.dataSource);
|
||||
this.indicator.setQuery(invalidValidationQuery);
|
||||
@@ -98,7 +98,7 @@ public class DataSourceHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void healthIndicatorCloseConnection() throws Exception {
|
||||
void healthIndicatorCloseConnection() throws Exception {
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
Connection connection = mock(Connection.class);
|
||||
given(connection.getMetaData()).willReturn(this.dataSource.getConnection().getMetaData());
|
||||
|
||||
@@ -41,10 +41,10 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class JmsHealthIndicatorTests {
|
||||
class JmsHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
public void jmsBrokerIsUp() throws JMSException {
|
||||
void jmsBrokerIsUp() throws JMSException {
|
||||
ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
|
||||
given(connectionMetaData.getJMSProviderName()).willReturn("JMS test provider");
|
||||
Connection connection = mock(Connection.class);
|
||||
@@ -59,7 +59,7 @@ public class JmsHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jmsBrokerIsDown() throws JMSException {
|
||||
void jmsBrokerIsDown() throws JMSException {
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
given(connectionFactory.createConnection()).willThrow(new JMSException("test", "123"));
|
||||
JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
|
||||
@@ -69,7 +69,7 @@ public class JmsHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jmsBrokerCouldNotRetrieveProviderMetadata() throws JMSException {
|
||||
void jmsBrokerCouldNotRetrieveProviderMetadata() throws JMSException {
|
||||
ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
|
||||
given(connectionMetaData.getJMSProviderName()).willThrow(new JMSException("test", "123"));
|
||||
Connection connection = mock(Connection.class);
|
||||
@@ -84,7 +84,7 @@ public class JmsHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jmsBrokerUsesFailover() throws JMSException {
|
||||
void jmsBrokerUsesFailover() throws JMSException {
|
||||
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
||||
ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
|
||||
given(connectionMetaData.getJMSProviderName()).willReturn("JMS test provider");
|
||||
@@ -99,7 +99,7 @@ public class JmsHealthIndicatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenConnectionStartIsUnresponsiveStatusIsDown() throws JMSException {
|
||||
void whenConnectionStartIsUnresponsiveStatusIsDown() throws JMSException {
|
||||
ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
|
||||
given(connectionMetaData.getJMSProviderName()).willReturn("JMS test provider");
|
||||
Connection connection = mock(Connection.class);
|
||||
|
||||
@@ -35,11 +35,11 @@ import static org.mockito.Mockito.verify;
|
||||
*
|
||||
* @author Eddú Meléndez
|
||||
*/
|
||||
public class LdapHealthIndicatorTests {
|
||||
class LdapHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void ldapIsUp() {
|
||||
void ldapIsUp() {
|
||||
LdapTemplate ldapTemplate = mock(LdapTemplate.class);
|
||||
given(ldapTemplate.executeReadOnly((ContextExecutor<String>) any())).willReturn("3");
|
||||
LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate);
|
||||
@@ -51,7 +51,7 @@ public class LdapHealthIndicatorTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void ldapIsDown() {
|
||||
void ldapIsDown() {
|
||||
LdapTemplate ldapTemplate = mock(LdapTemplate.class);
|
||||
given(ldapTemplate.executeReadOnly((ContextExecutor<String>) any()))
|
||||
.willThrow(new CommunicationException(new javax.naming.CommunicationException("Connection failed")));
|
||||
|
||||
@@ -42,7 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Andy Wilkinson
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class LiquibaseEndpointTests {
|
||||
class LiquibaseEndpointTests {
|
||||
|
||||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(
|
||||
@@ -50,7 +50,7 @@ public class LiquibaseEndpointTests {
|
||||
.withPropertyValues("spring.datasource.generate-unique-name=true");
|
||||
|
||||
@Test
|
||||
public void liquibaseReportIsReturned() {
|
||||
void liquibaseReportIsReturned() {
|
||||
this.contextRunner.withUserConfiguration(Config.class).run((context) -> {
|
||||
Map<String, LiquibaseBean> liquibaseBeans = context.getBean(LiquibaseEndpoint.class).liquibaseBeans()
|
||||
.getContexts().get(context.getId()).getLiquibaseBeans();
|
||||
@@ -59,7 +59,7 @@ public class LiquibaseEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeWithCustomSchema() {
|
||||
void invokeWithCustomSchema() {
|
||||
this.contextRunner.withUserConfiguration(Config.class)
|
||||
.withPropertyValues("spring.liquibase.default-schema=CUSTOMSCHEMA",
|
||||
"spring.datasource.schema=classpath:/db/create-custom-schema.sql")
|
||||
@@ -71,7 +71,7 @@ public class LiquibaseEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeWithCustomTables() {
|
||||
void invokeWithCustomTables() {
|
||||
this.contextRunner.withUserConfiguration(Config.class)
|
||||
.withPropertyValues("spring.liquibase.database-change-log-lock-table=liquibase_database_changelog_lock",
|
||||
"spring.liquibase.database-change-log-table=liquibase_database_changelog")
|
||||
@@ -83,7 +83,7 @@ public class LiquibaseEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionAutoCommitPropertyIsReset() {
|
||||
void connectionAutoCommitPropertyIsReset() {
|
||||
this.contextRunner.withUserConfiguration(Config.class).run((context) -> {
|
||||
DataSource dataSource = context.getBean(DataSource.class);
|
||||
assertThat(getAutoCommit(dataSource)).isTrue();
|
||||
|
||||
@@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class LogFileWebEndpointTests {
|
||||
class LogFileWebEndpointTests {
|
||||
|
||||
private final MockEnvironment environment = new MockEnvironment();
|
||||
|
||||
@@ -55,18 +55,18 @@ public class LogFileWebEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullResponseWithoutLogFile() {
|
||||
void nullResponseWithoutLogFile() {
|
||||
assertThat(this.endpoint.logFile()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullResponseWithMissingLogFile() {
|
||||
void nullResponseWithMissingLogFile() {
|
||||
this.environment.setProperty("logging.file.name", "no_test.log");
|
||||
assertThat(this.endpoint.logFile()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resourceResponseWithLogFile() throws Exception {
|
||||
void resourceResponseWithLogFile() throws Exception {
|
||||
this.environment.setProperty("logging.file.name", this.logFile.getAbsolutePath());
|
||||
Resource resource = this.endpoint.logFile();
|
||||
assertThat(resource).isNotNull();
|
||||
@@ -75,7 +75,7 @@ public class LogFileWebEndpointTests {
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
public void resourceResponseWithLogFileAndDeprecatedProperty() throws Exception {
|
||||
void resourceResponseWithLogFileAndDeprecatedProperty() throws Exception {
|
||||
this.environment.setProperty("logging.file", this.logFile.getAbsolutePath());
|
||||
Resource resource = this.endpoint.logFile();
|
||||
assertThat(resource).isNotNull();
|
||||
@@ -83,7 +83,7 @@ public class LogFileWebEndpointTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resourceResponseWithExternalLogFile() throws Exception {
|
||||
void resourceResponseWithExternalLogFile() throws Exception {
|
||||
LogFileWebEndpoint endpoint = new LogFileWebEndpoint(this.environment, this.logFile);
|
||||
Resource resource = endpoint.logFile();
|
||||
assertThat(resource).isNotNull();
|
||||
|
||||
@@ -19,13 +19,10 @@ package org.springframework.boot.actuate.logging;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointRunners;
|
||||
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -41,40 +38,39 @@ import org.springframework.util.FileCopyUtils;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@RunWith(WebEndpointRunners.class)
|
||||
public class LogFileWebEndpointWebIntegrationTests {
|
||||
class LogFileWebEndpointWebIntegrationTests {
|
||||
|
||||
private static ConfigurableApplicationContext context;
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
private static WebTestClient client;
|
||||
|
||||
@Rule
|
||||
public final TemporaryFolder temp = new TemporaryFolder();
|
||||
private WebTestClient client;
|
||||
|
||||
private File logFile;
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
this.logFile = this.temp.newFile();
|
||||
@BeforeEach
|
||||
public void setUp(@TempDir File temp, WebTestClient client, ConfigurableApplicationContext context)
|
||||
throws IOException {
|
||||
this.logFile = new File(temp, "test.log");
|
||||
this.client = client;
|
||||
this.context = context;
|
||||
FileCopyUtils.copy("--TEST--".getBytes(), this.logFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestProduces404ResponseWhenLogFileNotFound() {
|
||||
client.get().uri("/actuator/logfile").exchange().expectStatus().isNotFound();
|
||||
@WebEndpointTest
|
||||
void getRequestProduces404ResponseWhenLogFileNotFound() {
|
||||
this.client.get().uri("/actuator/logfile").exchange().expectStatus().isNotFound();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestProducesResponseWithLogFile() {
|
||||
TestPropertyValues.of("logging.file.name:" + this.logFile.getAbsolutePath()).applyTo(context);
|
||||
client.get().uri("/actuator/logfile").exchange().expectStatus().isOk().expectHeader()
|
||||
@WebEndpointTest
|
||||
void getRequestProducesResponseWithLogFile() {
|
||||
TestPropertyValues.of("logging.file.name:" + this.logFile.getAbsolutePath()).applyTo(this.context);
|
||||
this.client.get().uri("/actuator/logfile").exchange().expectStatus().isOk().expectHeader()
|
||||
.contentType("text/plain; charset=UTF-8").expectBody(String.class).isEqualTo("--TEST--");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestThatAcceptsTextPlainProducesResponseWithLogFile() {
|
||||
TestPropertyValues.of("logging.file:" + this.logFile.getAbsolutePath()).applyTo(context);
|
||||
client.get().uri("/actuator/logfile").accept(MediaType.TEXT_PLAIN).exchange().expectStatus().isOk()
|
||||
@WebEndpointTest
|
||||
void getRequestThatAcceptsTextPlainProducesResponseWithLogFile() {
|
||||
TestPropertyValues.of("logging.file:" + this.logFile.getAbsolutePath()).applyTo(this.context);
|
||||
this.client.get().uri("/actuator/logfile").accept(MediaType.TEXT_PLAIN).exchange().expectStatus().isOk()
|
||||
.expectHeader().contentType("text/plain; charset=UTF-8").expectBody(String.class).isEqualTo("--TEST--");
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user