Add actuator endpoint for exposing the Spring Integration graph

See gh-12331
This commit is contained in:
Tim Ysewyn
2018-02-25 15:52:10 +01:00
committed by Stephane Nicoll
parent 3b80b3dd93
commit 8c67ef1079
14 changed files with 486 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
/*
* Copyright 2012-2018 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
*
* http://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.integration;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.integration.support.management.graph.Graph;
import org.springframework.integration.support.management.graph.IntegrationGraphServer;
/**
* {@link Endpoint} to expose the Spring Integration graph.
*
* @author Tim Ysewyn
* @since 2.1.0
*/
@Endpoint(id = "integrationgraph", enableByDefault = false)
public class IntegrationGraphEndpoint {
private final IntegrationGraphServer integrationGraphServer;
/**
* Creates a new {@code IntegrationGraphEndpoint} that exposes a graph containing all the
* Spring Integration components in the given {@code integrationGraphServer}.
*
* @param integrationGraphServer the integration graph server
* @see IntegrationGraphServer
*/
public IntegrationGraphEndpoint(IntegrationGraphServer integrationGraphServer) {
this.integrationGraphServer = integrationGraphServer;
}
@ReadOperation
public Graph graph() {
return this.integrationGraphServer.getGraph();
}
@WriteOperation
public void rebuild() {
this.integrationGraphServer.rebuild();
}
}

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2012-2018 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
*
* http://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.
*/
/**
* Actuator support relating to Spring Integration.
*/
package org.springframework.boot.actuate.integration;

View File

@@ -0,0 +1,70 @@
/*
* Copyright 2012-2018 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
*
* http://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.integration;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.integration.support.management.graph.Graph;
import org.springframework.integration.support.management.graph.IntegrationGraphServer;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.mock;
import static org.mockito.BDDMockito.verify;
import static org.mockito.BDDMockito.when;
/**
* Tests for {@link IntegrationGraphEndpoint}.
*
* @author Tim Ysewyn
*/
public class IntegrationGraphEndpointTests {
@Mock
private IntegrationGraphServer integrationGraphServer;
@InjectMocks
private IntegrationGraphEndpoint integrationGraphEndpoint;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test
public void shouldReturnGraph() {
Graph mockedGraph = mock(Graph.class);
when(this.integrationGraphServer.getGraph()).thenReturn(mockedGraph);
Graph graph = this.integrationGraphEndpoint.graph();
verify(this.integrationGraphServer).getGraph();
assertThat(graph).isEqualTo(mockedGraph);
}
@Test
public void shouldRebuildGraph() {
this.integrationGraphEndpoint.rebuild();
verify(this.integrationGraphServer).rebuild();
}
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright 2012-2018 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
*
* http://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.integration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointRunners;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.support.management.graph.IntegrationGraphServer;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* Integration tests for {@link IntegrationGraphEndpoint} exposed by Jersey, Spring MVC, and WebFlux.
*
* @author Tim Ysewyn
*/
@RunWith(WebEndpointRunners.class)
public class IntegrationGraphEndpointWebIntegrationTests {
private static WebTestClient client;
@Test
public void graph() {
client.get().uri("/actuator/integrationgraph").accept(MediaType.APPLICATION_JSON).exchange()
.expectStatus().isOk().expectBody()
.jsonPath("contentDescriptor.providerVersion").isEqualTo("5.0.3.RELEASE")
.jsonPath("contentDescriptor.providerFormatVersion").isEqualTo(1.0f)
.jsonPath("contentDescriptor.provider").isEqualTo("spring-integration");
}
@Test
public void rebuild() {
client.post().uri("/actuator/integrationgraph").accept(MediaType.APPLICATION_JSON).exchange()
.expectStatus().isNoContent();
}
@Configuration
@EnableIntegration
public static class TestConfiguration {
@Bean
public IntegrationGraphEndpoint endpoint(IntegrationGraphServer integrationGraphServer) {
return new IntegrationGraphEndpoint(integrationGraphServer);
}
@Bean
public IntegrationGraphServer integrationGraphServer() {
return new IntegrationGraphServer();
}
}
}