06a3cd6c035fbdad64c2edcff898c6c9ac5233e1
[WebAppTest/.git] /
1 package com.prueba.core.context.integration.liquibase.impl;
2
3 import static org.junit.Assert.*;
4
5 import java.util.ArrayList;
6 import java.util.HashMap;
7 import java.util.List;
8 import java.util.Map;
9
10 import javax.sql.DataSource;
11
12 import org.junit.Test;
13
14 import com.prueba.core.context.integration.database.DataBaseAccess;
15 import com.prueba.core.context.integration.database.impl.DataBaseAccessImpl;
16 import com.prueba.core.context.integration.datasource.impl.DoDataSourceContext;
17
18 public class LiquibaseContextIntegrationTest {
19         private static final String CODE = "CODE";
20         private static final String NAME = "NAME";
21         private static final String SURNAME = "SURNAME";
22         private static final String PASSWORD = "PASSWORD";
23         private static final String APP_ROLE_CODE = "APPLICATION_ROLE_CODE";
24         
25         @Test
26         public void whenLoadLiquibaseContextThenReturnSuccessFulQuery() {
27                 final DataSource dataSource = DoDataSourceContext.getInstance().getDataSource();
28                 final LiquibaseContext liquibaseContext = new LiquibaseContext(dataSource);
29                 liquibaseContext.init();
30                 
31                 final DataBaseAccess dataBaseAccess = new DataBaseAccessImpl();
32                 final List<Map<String, String>> dataResult = dataBaseAccess.executeQuery("SELECT * FROM ACCOUNT",
33                                 answer ->
34                 {
35                         final List<Map<String, String>> result = new ArrayList<>();
36                         while (answer.next()) {
37                                 final Map<String, String> row = new HashMap<>();
38                                 row.put(CODE, answer.getString(CODE));
39                                 row.put(NAME, answer.getString(NAME));
40                                 row.put(SURNAME, answer.getString(SURNAME));
41                                 row.put(PASSWORD, answer.getString(PASSWORD));
42                                 row.put(APP_ROLE_CODE, answer.getString(APP_ROLE_CODE));
43                                 result.add(row);
44                         }
45               
46                         return result;
47                 });
48                 
49                 final String expectedCode = "GUMARTIN";
50                 final String expectedName = "Gustavo";
51                 final String expectedSurname = "Martin Morcuende";
52                 final String expectedPassword = "lame";
53                 final String expectedAppRoleCode = "ROLE_APP_ADMIN";
54                 
55                 final Map<String, String> row = dataResult.get(0);
56                 assertNotNull(row);
57                 assertEquals(expectedCode, row.get(CODE));
58                 assertEquals(expectedName, row.get(NAME));
59                 assertEquals(expectedSurname, row.get(SURNAME));
60                 assertEquals(expectedPassword, row.get(PASSWORD));
61                 assertEquals(expectedAppRoleCode, row.get(APP_ROLE_CODE));
62         }
63
64 }