diff --git a/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/main/java/com/health/base/SolaceHealthIndicator.java b/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/main/java/com/health/base/SolaceHealthIndicator.java index abd8f35..61ad1df 100644 --- a/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/main/java/com/health/base/SolaceHealthIndicator.java +++ b/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/main/java/com/health/base/SolaceHealthIndicator.java @@ -42,7 +42,7 @@ protected void healthUp() { protected void healthReconnecting(@Nullable T eventArgs) { try { writeLock.lock(); - health = addSessionEventDetails(Health.status(STATUS_RECONNECTING), eventArgs).build(); + health = addEventDetails(Health.status(STATUS_RECONNECTING), eventArgs).build(); logDebugStatus(STATUS_RECONNECTING); } finally { writeLock.unlock(); @@ -52,14 +52,14 @@ protected void healthReconnecting(@Nullable T eventArgs) { protected void healthDown(@Nullable T eventArgs) { try { writeLock.lock(); - health = addSessionEventDetails(Health.down(), eventArgs).build(); + health = addEventDetails(Health.down(), eventArgs).build(); logDebugStatus(String.valueOf(Status.DOWN)); } finally { writeLock.unlock(); } } - public Health.Builder addSessionEventDetails(Health.Builder builder, @Nullable T eventArgs) { + public Health.Builder addEventDetails(Health.Builder builder, @Nullable T eventArgs) { if (eventArgs == null) { return builder; } diff --git a/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/test/java/com/health/base/SolaceHealthIndicatorTest.java b/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/test/java/com/health/base/SolaceHealthIndicatorTest.java new file mode 100644 index 0000000..df76971 --- /dev/null +++ b/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/test/java/com/health/base/SolaceHealthIndicatorTest.java @@ -0,0 +1,64 @@ +package com.health.base; + +import com.solacesystems.jcsmp.FlowEvent; +import com.solacesystems.jcsmp.FlowEventArgs; +import com.solacesystems.jcsmp.SessionEvent; +import com.solacesystems.jcsmp.SessionEventArgs; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.Status; + +import static org.junit.jupiter.api.Assertions.*; + +class SolaceHealthIndicatorTest { + + private SolaceHealthIndicator solaceHealthIndicator; + + @BeforeEach + void setUp() { + this.solaceHealthIndicator = new SolaceHealthIndicator(); + } + + @Test + void healthUp() { + this.solaceHealthIndicator.healthUp(); + assertEquals(this.solaceHealthIndicator.getHealth(), Health.up().build()); + } + + @Test + void healthReconnecting() { + this.solaceHealthIndicator.healthReconnecting(null); + assertEquals(this.solaceHealthIndicator.getHealth(), Health.status("RECONNECTING").build()); + } + + @Test + void healthDown() { + this.solaceHealthIndicator.healthDown(null); + assertEquals(this.solaceHealthIndicator.getHealth(), Health.down().build()); + } + + @Test + void addFlowEventDetails() { + // as SessionEventArgs constructor has package level access modifier, we have to test with FlowEventArgs only + FlowEventArgs flowEventArgs = new FlowEventArgs(FlowEvent.FLOW_DOWN, "String_infoStr", + new Exception("Test Exception"), 500); + Health health = this.solaceHealthIndicator.addEventDetails(Health.down(),flowEventArgs).build(); + + assertEquals(health.getStatus(), Status.DOWN); + assertEquals(health.getDetails().get("error"), "java.lang.Exception: Test Exception"); + assertEquals(health.getDetails().get("responseCode"), 500); + } + + @Test + void getHealth() { + this.solaceHealthIndicator.setHealth(Health.up().build()); + assertEquals(this.solaceHealthIndicator.getHealth(), Health.up().build()); + } + + @Test + void setHealth() { + this.solaceHealthIndicator.setHealth(Health.down().build()); + assertEquals(this.solaceHealthIndicator.getHealth(), Health.down().build()); + } +} \ No newline at end of file diff --git a/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/test/java/com/health/indicators/SolaceFlowHealthIndicatorTest.java b/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/test/java/com/health/indicators/SolaceFlowHealthIndicatorTest.java new file mode 100644 index 0000000..ecc9b25 --- /dev/null +++ b/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/test/java/com/health/indicators/SolaceFlowHealthIndicatorTest.java @@ -0,0 +1,50 @@ +package com.health.indicators; + +import com.health.base.SolaceHealthIndicator; +import com.solacesystems.jcsmp.FlowEvent; +import com.solacesystems.jcsmp.FlowEventArgs; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.Status; + +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; + +class SolaceFlowHealthIndicatorTest { + + private SolaceFlowHealthIndicator solaceHealthIndicator; + + @BeforeEach + void setUp() { + this.solaceHealthIndicator = new SolaceFlowHealthIndicator(); + } + + @Test + void up() { + this.solaceHealthIndicator.up(); + assertEquals(this.solaceHealthIndicator.getHealth(), Health.up().build()); + } + + @Test + void reconnecting() { + FlowEventArgs flowEventArgs = new FlowEventArgs(FlowEvent.FLOW_RECONNECTING, "String_infoStr", + new Exception("Test Exception"), 500); + this.solaceHealthIndicator.reconnecting(flowEventArgs); + assertEquals(this.solaceHealthIndicator.getHealth().getStatus(), Health.status("RECONNECTING").build().getStatus()); + assertEquals(this.solaceHealthIndicator.getHealth().getDetails().get("error"), "java.lang.Exception: Test Exception"); + assertEquals(this.solaceHealthIndicator.getHealth().getDetails().get("responseCode"), 500); + + } + + @Test + void down() { + FlowEventArgs flowEventArgs = new FlowEventArgs(FlowEvent.FLOW_DOWN, "String_infoStr", + new Exception("Test Exception"), 500); + this.solaceHealthIndicator.down(flowEventArgs); + assertEquals(this.solaceHealthIndicator.getHealth().getStatus(), Status.DOWN); + assertEquals(this.solaceHealthIndicator.getHealth().getDetails().get("error"), "java.lang.Exception: Test Exception"); + assertEquals(this.solaceHealthIndicator.getHealth().getDetails().get("responseCode"), 500); + } +} \ No newline at end of file diff --git a/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/test/java/com/health/indicators/SolaceSessionHealthIndicatorTest.java b/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/test/java/com/health/indicators/SolaceSessionHealthIndicatorTest.java new file mode 100644 index 0000000..bfefbe3 --- /dev/null +++ b/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/test/java/com/health/indicators/SolaceSessionHealthIndicatorTest.java @@ -0,0 +1,38 @@ +package com.health.indicators; + +import com.solacesystems.jcsmp.FlowEvent; +import com.solacesystems.jcsmp.FlowEventArgs; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.Status; + +import static org.junit.jupiter.api.Assertions.*; + +class SolaceSessionHealthIndicatorTest { + + private SolaceSessionHealthIndicator solaceHealthIndicator; + + @BeforeEach + void setUp() { + this.solaceHealthIndicator = new SolaceSessionHealthIndicator(); + } + + @Test + void up() { + this.solaceHealthIndicator.up(); + assertEquals(this.solaceHealthIndicator.getHealth(), Health.up().build()); + } + + @Test + void reconnecting() { + this.solaceHealthIndicator.reconnecting(null); + assertEquals(this.solaceHealthIndicator.getHealth().getStatus(), Health.status("RECONNECTING").build().getStatus()); + } + + @Test + void down() { + this.solaceHealthIndicator.down(null); + assertEquals(this.solaceHealthIndicator.getHealth().getStatus(), Status.DOWN); + } +} \ No newline at end of file