-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the AxonServerConnectionManager Add tests for the AxonServerHealthIndicator Add tests for the AxonServerActuatorAutoConfiguration #1964
- Loading branch information
Showing
4 changed files
with
159 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...autoconfigure/src/test/java/org/axonframework/actuator/AxonServerHealthIndicatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2010-2022. Axon Framework | ||
* | ||
* 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.axonframework.actuator; | ||
|
||
import org.axonframework.axonserver.connector.AxonServerConnectionManager; | ||
import org.junit.jupiter.api.*; | ||
import org.springframework.boot.actuate.health.Health; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
/** | ||
* Test class validating the {@link AxonServerHealthIndicator}. | ||
* | ||
* @author Steven van Beelen | ||
*/ | ||
class AxonServerHealthIndicatorTest { | ||
|
||
@Test | ||
void testDoHealthCheck() { | ||
String testContextOne = "context-one"; | ||
String testContextTwo = "context-two"; | ||
String expectedDetailsContextOne = testContextOne + ".connection.active"; | ||
String expectedDetailsContextTwo = testContextTwo + ".connection.active"; | ||
|
||
Map<String, Boolean> testConnections = new HashMap<>(); | ||
testConnections.put(testContextOne, true); | ||
testConnections.put(testContextTwo, false); | ||
|
||
AxonServerConnectionManager connectionManager = mock(AxonServerConnectionManager.class); | ||
when(connectionManager.connections()).thenReturn(testConnections); | ||
|
||
AxonServerHealthIndicator testSubject = new AxonServerHealthIndicator(connectionManager); | ||
|
||
Health.Builder healthBuilder = new Health.Builder(); | ||
|
||
testSubject.doHealthCheck(healthBuilder); | ||
|
||
Health result = healthBuilder.build(); | ||
Map<String, Object> details = result.getDetails(); | ||
assertFalse(details.isEmpty()); | ||
assertEquals(2, details.size()); | ||
Object detailsContextOne = details.get(expectedDetailsContextOne); | ||
assertNotNull(detailsContextOne); | ||
assertTrue((Boolean) detailsContextOne); | ||
Object detailsContextTwo = details.get(expectedDetailsContextTwo); | ||
assertNotNull(detailsContextTwo); | ||
assertFalse((Boolean) detailsContextTwo); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...java/org/axonframework/springboot/autoconfig/AxonServerActuatorAutoConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2010-2022. Axon Framework | ||
* | ||
* 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.axonframework.springboot.autoconfig; | ||
|
||
import org.axonframework.actuator.AxonServerHealthIndicator; | ||
import org.junit.jupiter.api.*; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
import org.springframework.context.annotation.EnableMBeanExport; | ||
import org.springframework.jmx.support.RegistrationPolicy; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Test class validating the {@link AxonServerActuatorAutoConfiguration}. | ||
* | ||
* @author Steven van Beelen | ||
*/ | ||
class AxonServerActuatorAutoConfigurationTest { | ||
|
||
private ApplicationContextRunner testApplicationContext; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
testApplicationContext = new ApplicationContextRunner(); | ||
} | ||
|
||
@Test | ||
void testAxonServerHealthIndicatorIsNotCreatedForAxonServerDisabled() { | ||
testApplicationContext.withUserConfiguration(TestContext.class) | ||
.withPropertyValues("axon.axonserver.enabled:false") | ||
.run(context -> assertThat(context).doesNotHaveBean(AxonServerHealthIndicator.class)); | ||
} | ||
|
||
@Test | ||
void testAxonServerHealthIndicatorIsCreated() { | ||
testApplicationContext.withUserConfiguration(TestContext.class) | ||
.withPropertyValues("axon.axonserver.enabled:true") | ||
.run(context -> assertThat(context).hasSingleBean(AxonServerHealthIndicator.class)); | ||
} | ||
|
||
@ContextConfiguration | ||
@EnableAutoConfiguration | ||
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING) | ||
private static class TestContext { | ||
|
||
} | ||
} |