1 package com.prueba.core.context.integration.liquibase.impl;
3 import static org.junit.Assert.*;
5 import java.util.ArrayList;
6 import java.util.HashMap;
10 import javax.sql.DataSource;
12 import org.junit.Before;
13 import org.junit.Test;
15 import com.prueba.core.context.integration.database.DataBaseAccess;
16 import com.prueba.core.context.integration.database.impl.DataBaseAccessImpl;
17 import com.prueba.core.context.integration.datasource.impl.DoDataSourceContext;
19 public class LiquibaseContextIntegrationTest {
20 private static final String CODE = "CODE";
21 private static final String NAME = "NAME";
22 private static final String SURNAME = "SURNAME";
23 private static final String PASSWORD = "PASSWORD";
24 private static final String APP_ROLE_CODE = "APPLICATION_ROLE_CODE";
26 private DataSource dataSource;
27 private LiquibaseContext liquibaseContext;
31 dataSource = DoDataSourceContext.getInstance().getDataSource();
32 liquibaseContext = new LiquibaseContext(dataSource);
33 liquibaseContext.init();
37 public void whenLoadLiquibaseContextThenReturnResultsFromDatabase() {
38 final DataBaseAccess dataBaseAccess = new DataBaseAccessImpl();
39 final List<Map<String, String>> dataResult = dataBaseAccess.executeQuery("SELECT * FROM ACCOUNT",
42 final List<Map<String, String>> result = new ArrayList<>();
43 while (answer.next()) {
44 final Map<String, String> row = new HashMap<>();
45 row.put(CODE, answer.getString(CODE));
46 row.put(NAME, answer.getString(NAME));
47 row.put(SURNAME, answer.getString(SURNAME));
48 row.put(PASSWORD, answer.getString(PASSWORD));
49 row.put(APP_ROLE_CODE, answer.getString(APP_ROLE_CODE));
55 preparedStatement -> {
59 final String expectedCode = "GUMARTIN";
60 final String expectedName = "Gustavo";
61 final String expectedSurname = "Martin Morcuende";
62 final String expectedPassword = "lame";
63 final String expectedAppRoleCode = "ROLE_APP_ADMIN";
65 final Map<String, String> row = dataResult.get(0);
67 assertEquals(expectedCode, row.get(CODE));
68 assertEquals(expectedName, row.get(NAME));
69 assertEquals(expectedSurname, row.get(SURNAME));
70 assertEquals(expectedPassword, row.get(PASSWORD));
71 assertEquals(expectedAppRoleCode, row.get(APP_ROLE_CODE));
75 public void whenLoadLiquibaseContextThenReturnResultsFromDatabaseUsingParameters() {
76 final DataBaseAccess dataBaseAccess = new DataBaseAccessImpl();
77 final List<Map<String, String>> dataResult = dataBaseAccess.executeQuery("SELECT * FROM ACCOUNT WHERE CODE = ?",
80 final List<Map<String, String>> result = new ArrayList<>();
81 while (answer.next()) {
82 final Map<String, String> row = new HashMap<>();
83 row.put(CODE, answer.getString(CODE));
84 row.put(NAME, answer.getString(NAME));
85 row.put(SURNAME, answer.getString(SURNAME));
86 row.put(PASSWORD, answer.getString(PASSWORD));
87 row.put(APP_ROLE_CODE, answer.getString(APP_ROLE_CODE));
93 preparedStatement -> {
94 preparedStatement.setString(1, "GUMARTIN");
97 final String expectedCode = "GUMARTIN";
98 final String expectedName = "Gustavo";
99 final String expectedSurname = "Martin Morcuende";
100 final String expectedPassword = "lame";
101 final String expectedAppRoleCode = "ROLE_APP_ADMIN";
103 final Map<String, String> row = dataResult.get(0);
105 assertEquals(expectedCode, row.get(CODE));
106 assertEquals(expectedName, row.get(NAME));
107 assertEquals(expectedSurname, row.get(SURNAME));
108 assertEquals(expectedPassword, row.get(PASSWORD));
109 assertEquals(expectedAppRoleCode, row.get(APP_ROLE_CODE));
113 public void whenLoadLiquibaseContextAndNotUserFoundThenDoNotReturResultsFromDatabase() {
114 final DataBaseAccess dataBaseAccess = new DataBaseAccessImpl();
115 final List<Map<String, String>> dataResult = dataBaseAccess.executeQuery("SELECT * FROM ACCOUNT WHERE CODE = ?",
118 final List<Map<String, String>> result = new ArrayList<>();
119 while (answer.next()) {
120 final Map<String, String> row = new HashMap<>();
121 row.put(CODE, answer.getString(CODE));
122 row.put(NAME, answer.getString(NAME));
123 row.put(SURNAME, answer.getString(SURNAME));
124 row.put(PASSWORD, answer.getString(PASSWORD));
125 row.put(APP_ROLE_CODE, answer.getString(APP_ROLE_CODE));
131 preparedStatement -> {
132 preparedStatement.setString(1, "DONOTEXIST");
136 assertTrue(dataResult.isEmpty());