-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2e4443
commit 441c930
Showing
2 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
38 changes: 35 additions & 3 deletions
38
src/test/java/com/hendisantika/adminlte/SistemApplicationTests.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 |
---|---|---|
@@ -1,13 +1,45 @@ | ||
package com.hendisantika.adminlte; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.testcontainers.shaded.com.fasterxml.jackson.core.JsonProcessingException; | ||
|
||
@SpringBootTest | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; | ||
|
||
@Testcontainers | ||
@SpringBootTest( | ||
properties = { | ||
"management.endpoint.health.show-details=always", | ||
"spring.datasource.url=jdbc:tc:mysql:8.4.0:///test" | ||
}, | ||
webEnvironment = RANDOM_PORT | ||
) | ||
public class SistemApplicationTests { | ||
|
||
@Autowired | ||
private TestRestTemplate restTemplate; | ||
|
||
@Test | ||
public void contextLoads() { | ||
} | ||
@DisplayName("Database status will be UP and Database name should be MySQL") | ||
void databaseIsAvailable() throws JsonProcessingException, com.fasterxml.jackson.core.JsonProcessingException { | ||
var response = restTemplate.getForEntity("/actuator/health", String.class); | ||
|
||
assertThat(response.getBody()).isNotNull(); | ||
|
||
JsonNode root = new ObjectMapper().readTree(response.getBody()); | ||
JsonNode dbComponentNode = root.get("components").get("db"); | ||
|
||
String dbStatus = dbComponentNode.get("status").asText(); | ||
String dbName = dbComponentNode.get("details").get("database").asText(); | ||
|
||
assertThat(dbStatus).isEqualTo("UP"); | ||
assertThat(dbName).isEqualTo("MySQL"); | ||
} | ||
} |
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,44 @@ | ||
CREATE TABLE users | ||
( | ||
username VARCHAR(50) NOT NULL PRIMARY KEY, | ||
password VARCHAR(255) NOT NULL, | ||
enabled boolean NOT NULL | ||
) ENGINE = InnoDb; | ||
CREATE TABLE authorities | ||
( | ||
username VARCHAR(50) NOT NULL, | ||
authority VARCHAR(50) NOT NULL, | ||
FOREIGN KEY (username) REFERENCES users (username), | ||
UNIQUE INDEX authorities_idx_1 (username, authority) | ||
) ENGINE = InnoDb; | ||
|
||
CREATE TABLE customers | ||
( | ||
id bigint(50) NOT NULL PRIMARY KEY AUTO_INCREMENT, | ||
firstname VARCHAR(50) NOT NULL, | ||
lastname VARCHAR(255) NOT NULL, | ||
email VARCHAR(255) NOT NULL UNIQUE, | ||
added_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL | ||
) ENGINE = InnoDb; | ||
|
||
INSERT INTO customers (id, firstname, lastname, email, added_date) | ||
VALUES (1, 'Uchiha', 'Sasuke', '[email protected]', '2020-03-29 07:52:34'), | ||
(2, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(3, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(4, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(5, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(6, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(7, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(8, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(9, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(10, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(11, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(12, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(13, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(14, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(15, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(16, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(17, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(18, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(19, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'), | ||
(20, 'Uzumaki', 'Naruto', '[email protected]', '2020-03-29 08:18:59'); |