-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from chinmoy12c/hotfix/fix_failing_tests
Fixed failing tests in health service
- Loading branch information
Showing
4 changed files
with
43 additions
and
28 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
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 |
---|---|---|
@@ -1,50 +1,56 @@ | ||
package com.uci.utils; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.uci.utils.kafka.KafkaConfig; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.boot.actuate.health.Status; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@SpringBootTest(classes = UtilsTestConfig.class) | ||
class UtilHealthServiceTest { | ||
|
||
@Autowired | ||
UtilHealthService utilHealthService; | ||
|
||
@MockBean | ||
@Mock | ||
KafkaConfig kafkaConfig; | ||
|
||
@MockBean | ||
@Mock | ||
BotService botService; | ||
|
||
@Mock | ||
ObjectMapper mapper; | ||
|
||
@InjectMocks | ||
UtilHealthService utilHealthService; | ||
|
||
@AfterAll | ||
static void teardown() { | ||
System.out.println("teardown"); | ||
} | ||
|
||
@Test | ||
void getKafkaHealthNode() { | ||
Mockito.when(mapper.createObjectNode()).thenReturn(new ObjectMapper().createObjectNode()); | ||
Mockito.when(kafkaConfig.kafkaHealthIndicator()).thenReturn(() -> Health.up().build()); | ||
JsonNode result = utilHealthService.getKafkaHealthNode().block(); | ||
assertNotNull(result); | ||
assertTrue(result.get("healthy").asBoolean()); | ||
assertEquals(result.get("status").textValue(), Status.UP.getCode()); | ||
} | ||
|
||
@Test | ||
void getCampaignUrlHealthNode() { | ||
Mockito.when(mapper.createObjectNode()).thenReturn(new ObjectMapper().createObjectNode()); | ||
utilHealthService.campaignUrl = "NON_EXISTENT_URL"; | ||
JsonNode result = utilHealthService.getCampaignUrlHealthNode().block(); | ||
assertNotNull(result); | ||
assertFalse(result.get("healthy").asBoolean()); | ||
assertEquals(result.get("status").textValue(), Status.DOWN.getCode()); | ||
} | ||
} |
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