--- /dev/null
+package com.prueba.api.persistence;
+
+public class Account {
+ private final String code;
+ private final String name;
+ private final String surname;
+ private final String password;
+ private final String role;
+
+ public Account(String code, String name, String surname, String password, String role) {
+ this.code = code;
+ this.name = name;
+ this.surname = surname;
+ this.password = password;
+ this.role = role;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getSurname() {
+ return surname;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getRole() {
+ return role;
+ }
+
+}
import com.prueba.authorization.persistence.dao.AuthorizationDao;
public class AuthorizationServicesImpl {
+ private static final String USER_NAME_PARAM = "{username}";
public boolean isAuthorized(String httpMethod, String url, String userName) {
final AuthorizationDao dao = new AuthorizationDao();
return urls.stream().anyMatch(urlMap ->
{
- String urlPatternValue = urlMap.get(AuthorizationDao.URL_PATTERN);
- String httpMethodValue = urlMap.get(AuthorizationDao.HTTP_METHOD);
+ final String urlPatternValue = urlMap.get(AuthorizationDao.URL_PATTERN);
+ final String urlReplacedPatternValue = urlPatternValue.replace(USER_NAME_PARAM, userName);
+ final String httpMethodValue = urlMap.get(AuthorizationDao.HTTP_METHOD);
- return urlPatternValue.equals(url) && httpMethodValue.equals(httpMethod);
+ return urlReplacedPatternValue.equals(url) && httpMethodValue.equals(httpMethod);
});
}
import java.net.InetSocketAddress;
import com.prueba.core.context.ApplicationContext;
+import com.prueba.core.context.security.authenticator.CustomBasicAuthenticator;
+import com.prueba.core.context.security.handle.ApiHandler;
import com.prueba.core.context.security.handle.LoginHandler;
import com.prueba.core.context.security.handle.PagesHandler;
import com.prueba.core.context.web.application.ApplicationWebContext;
+
+import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpServer;
public class MainRun {
HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
server.createContext(PagesHandler.CONTEXT, appContext.getWebHandler());
server.createContext(LoginHandler.CONTEXT, appContext.getLoginHandler());
+
+ HttpContext apiContext = server.createContext(ApiHandler.CONTEXT, appContext.getApiHandler());
+ apiContext.setAuthenticator(new CustomBasicAuthenticator(ApiHandler.CONTEXT));
+
server.setExecutor(null);
server.start();
HttpHandler getLoginHandler();
- public HttpHandler getSessionHandler();
+ HttpHandler getSessionHandler();
+
+ HttpHandler getApiHandler();
}
List<Map<String, String>> executeResultSet(final TResult resultSet) throws SQLException;
}
+ public interface ExecuteUpdateStatement<TResult> {
+ void executeStatement(final PreparedStatement statement) throws SQLException;
+ }
+
public interface FillPreparedStatement {
void doFill(final PreparedStatement statement) throws SQLException;
}
@Override
public List<Map<String, String>> executeQuery(
String query, ExecuteResultSet<ResultSet> executeResultSet, FillPreparedStatement fillStatement) {
+
List<Map<String, String>> result = null;
try {
result = this.executeQueryThrowable(query, executeResultSet, fillStatement);
}
+ public void executeUpdate(String query, FillPreparedStatement fillStatement) {
+
+ try {
+ this.executeUpdateThrowable(query, fillStatement);
+ } catch (SQLException exception) {
+ LOGGER.error("Query error: ", exception);
+ }
+
+ }
+
+ protected void executeUpdateThrowable(
+ String query, FillPreparedStatement fillStatement) throws SQLException {
+ try {
+ final Connection connection = this.dataSource.getConnection();
+
+ this.doExecuteUpdate(
+ query,
+ connection,
+ preparedStatement ->
+ {
+ fillStatement.doFill(preparedStatement);
+
+ preparedStatement.executeUpdate();
+ });
+ } finally {
+ dataSource.getConnection().close();
+ }
+ }
+
+ protected void doExecuteUpdate (
+ final String query,
+ final Connection connection,
+ final ExecuteUpdateStatement<ResultSet> executeUpdateStatement) throws SQLException {
+
+ try (final PreparedStatement preparedStatement = connection.prepareStatement(query)) {
+ executeUpdateStatement.executeStatement(preparedStatement);
+ }
+
+ }
}
package com.prueba.core.context.security.authenticator;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.sql.DataSource;
-
-import com.prueba.core.context.integration.database.DataBaseAccess;
-import com.prueba.core.context.integration.database.impl.DataBaseAccessImpl;
+import com.prueba.core.context.security.authenticator.persistence.AuthenticationInfo;
+import com.prueba.core.context.security.persistence.context.BasicAuthenticationContext;
+import com.prueba.services.impl.LoginServiceImpl;
import com.sun.net.httpserver.BasicAuthenticator;
public class CustomBasicAuthenticator extends BasicAuthenticator {
- private static final String CODE = "CODE";
- private static final String NAME = "NAME";
- private static final String SURNAME = "SURNAME";
- private static final String PASSWORD = "PASSWORD";
- private static final String APP_ROLE_CODE = "APPLICATION_ROLE_CODE";
-
- private final DataSource dataSource;
- public CustomBasicAuthenticator(String context, DataSource dataSource) {
+ public CustomBasicAuthenticator(String context) {
super(context);
-
- this.dataSource = dataSource;
}
@Override
public boolean checkCredentials(String username, String password) {
- List<Map<String, String>> results = this.doQuery(username, password);
+ final LoginServiceImpl loginService = new LoginServiceImpl();
- if (results.isEmpty()) {
- return false;
- } else {
+ if (loginService.isValidUser(username, password)) {
+ BasicAuthenticationContext.setAuthentication(new AuthenticationInfo(username));
+
return true;
+ } else {
+ BasicAuthenticationContext.setAuthentication(null);
+
+ return false;
}
}
-
-
- protected List<Map<String, String>> doQuery(String username, String password) {
- final DataBaseAccess dataBaseAccess = new DataBaseAccessImpl(this.dataSource);
- return dataBaseAccess.executeQuery("SELECT * FROM ACCOUNT WHERE CODE = ? AND PASSWORD = ?",
- answer ->
- {
- final List<Map<String, String>> result = new ArrayList<>();
- while (answer.next()) {
- final Map<String, String> row = new HashMap<>();
- row.put(CODE, answer.getString(CODE));
- row.put(NAME, answer.getString(NAME));
- row.put(SURNAME, answer.getString(SURNAME));
- row.put(PASSWORD, answer.getString(PASSWORD));
- row.put(APP_ROLE_CODE, answer.getString(APP_ROLE_CODE));
- result.add(row);
- }
-
- return result;
- },
- preparedStatement -> {
- preparedStatement.setString(1, username);
- preparedStatement.setString(2, password);
- });
- }
}
--- /dev/null
+package com.prueba.core.context.security.authenticator.persistence;
+
+public class AuthenticationInfo {
+ private final String userName;
+
+ public AuthenticationInfo(String userName) {
+ this.userName = userName;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+}
--- /dev/null
+package com.prueba.core.context.security.handle;
+
+import java.io.IOException;
+
+import com.prueba.authorization.services.impl.AuthorizationServicesImpl;
+import com.prueba.core.context.security.authenticator.persistence.AuthenticationInfo;
+import com.prueba.core.context.security.persistence.context.BasicAuthenticationContext;
+import com.prueba.resources.controllers.ApiController;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpHandler;
+
+public class ApiHandler implements HttpHandler {
+ public static final String CONTEXT = "/app/api/";
+
+ private final ApiController apiController = new ApiController();
+ private final AuthorizationServicesImpl authorizationService = new AuthorizationServicesImpl();
+
+ @Override
+ public void handle(HttpExchange httpExchange) throws IOException {
+ AuthenticationInfo authenticationInfo = BasicAuthenticationContext.getAuthentication();
+
+ if(authorizationService.isAuthorized(httpExchange.getRequestMethod(),
+ httpExchange.getRequestURI().toString(), authenticationInfo.getUserName())) {
+
+ apiController.handle(httpExchange);
+
+ } else {
+ httpExchange.sendResponseHeaders(403, 0);
+ }
+ }
+}
import com.prueba.authorization.services.impl.AuthorizationServicesImpl;
import com.prueba.core.context.security.persistence.SessionInfo;
import com.prueba.core.context.security.persistence.Sessions;
+import com.prueba.core.context.security.persistence.context.SessionContext;
import com.prueba.resources.controllers.PagesController;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
public void handle(HttpExchange httpExchange) throws IOException {
this.sessionHandler.handle(httpExchange);
- final SessionInfo sessionInfo = SessionHandler.getLocalSession();
if (Sessions.getInstance().isValidSession(httpExchange)) {
+ final SessionInfo sessionInfo = SessionContext.getSession();
if(authorizationService.isAuthorized(httpExchange.getRequestMethod(),
httpExchange.getRequestURI().toString(), sessionInfo.getUsername())) {
- pagesController.handle(httpExchange);
-
+ pagesController.handle(httpExchange);
} else {
httpExchange.sendResponseHeaders(403, 0);
}
import com.prueba.core.context.security.persistence.SessionInfo;
import com.prueba.core.context.security.persistence.Sessions;
+import com.prueba.core.context.security.persistence.context.SessionContext;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
public class SessionHandler implements HttpHandler {
private static final String COOKIE_HEADER = "Cookie";
- private static final ThreadLocal<SessionInfo> localContextSession = new ThreadLocal<>();
@Override
public void handle(HttpExchange httpExchange) throws IOException {
final SessionInfo sessionInfo = getSessionInfo(httpExchange);
- localContextSession.set(sessionInfo);
+ SessionContext.setSession(sessionInfo);
}
protected SessionInfo getSessionInfo(HttpExchange httpExchange) {
return sessionInfo;
}
-
- public static SessionInfo getLocalSession() {
- return localContextSession.get();
- }
}
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
-import com.prueba.core.context.security.handle.SessionHandler;
+import com.prueba.core.context.security.persistence.context.SessionContext;
import com.sun.net.httpserver.HttpExchange;
public class Sessions {
}
public boolean isValidSession(HttpExchange httpExchange) {
- final SessionInfo sessionInfo = SessionHandler.getLocalSession();
+ final SessionInfo sessionInfo = SessionContext.getSession();
boolean isValid = false;
--- /dev/null
+package com.prueba.core.context.security.persistence.context;
+
+import com.prueba.core.context.security.authenticator.persistence.AuthenticationInfo;
+
+public class BasicAuthenticationContext {
+ private static final ThreadLocal<AuthenticationInfo> localContextSession = new ThreadLocal<>();
+
+ public static void setAuthentication(AuthenticationInfo authenticationInfo) {
+ localContextSession.set(authenticationInfo);
+ }
+
+ public static AuthenticationInfo getAuthentication() {
+ return localContextSession.get();
+ }
+}
--- /dev/null
+package com.prueba.core.context.security.persistence.context;
+
+import com.prueba.core.context.security.persistence.SessionInfo;
+
+public class SessionContext {
+ private static final ThreadLocal<SessionInfo> localContextSession = new ThreadLocal<>();
+
+ public static void setSession(SessionInfo sessionInfo) {
+ localContextSession.set(sessionInfo);
+ }
+
+ public static SessionInfo getSession() {
+ return localContextSession.get();
+ }
+}
import com.prueba.core.context.ApplicationContext;
import com.prueba.core.context.integration.datasource.impl.DoDataSourceContext;
import com.prueba.core.context.integration.liquibase.impl.LiquibaseContext;
+import com.prueba.core.context.security.handle.ApiHandler;
import com.prueba.core.context.security.handle.LoginHandler;
import com.prueba.core.context.security.handle.SessionHandler;
import com.prueba.core.context.security.handle.PagesHandler;
private final HttpHandler sessionHandler;
private final HttpHandler webHttpHandler;
private final HttpHandler loginHandler;
+ private final HttpHandler apiHandler;
private ApplicationWebContext() {
this.dataSource = DoDataSourceContext.getInstance().getDataSource();
this.liquibaseContext = new LiquibaseContext(dataSource);
this.liquibaseContext.init();
this.sessionHandler = new SessionHandler();
+ this.apiHandler = new ApiHandler();
this.webHttpHandler = new PagesHandler(sessionHandler);
this.loginHandler = new LoginHandler(sessionHandler);
}
public HttpHandler getSessionHandler() {
return this.sessionHandler;
}
+
+ @Override
+ public HttpHandler getApiHandler() {
+ return this.apiHandler;
+ }
}
--- /dev/null
+package com.prueba.persistence.dao;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+import com.prueba.api.persistence.Account;
+import com.prueba.core.context.integration.database.impl.DataBaseAccessImpl;
+import com.prueba.core.context.web.application.ApplicationWebContext;
+
+public class AccountDao {
+ private static final String CODE = "CODE";
+ private static final String NAME = "NAME";
+ private static final String SURNAME = "SURNAME";
+ private static final String PASSWORD = "PASSWORD";
+ private static final String APP_ROLE_CODE = "APPLICATION_ROLE_CODE";
+
+ public Account findAccountByCode(String accountCode) {
+ final DataSource dataSource = ApplicationWebContext.getInstance().getDataSource();
+ final DataBaseAccessImpl dataBaseAccess = new DataBaseAccessImpl(dataSource);
+
+ final List<Map<String, String>> results =
+ dataBaseAccess.executeQuery("SELECT * FROM ACCOUNT WHERE CODE = ?",
+ answer ->
+ {
+ final List<Map<String, String>> result = new ArrayList<>();
+ while (answer.next()) {
+ final Map<String, String> row = new HashMap<>();
+ row.put(CODE, answer.getString(CODE));
+ row.put(NAME, answer.getString(NAME));
+ row.put(SURNAME, answer.getString(SURNAME));
+ row.put(PASSWORD, answer.getString(PASSWORD));
+ row.put(APP_ROLE_CODE, answer.getString(APP_ROLE_CODE));
+ result.add(row);
+ }
+
+ return result;
+ },
+ preparedStatement -> {
+ preparedStatement.setString(1, accountCode);
+ });
+
+ Account account = null;
+ if (!results.isEmpty()) {
+ final Map<String, String> row = results.get(0);
+
+ account = new Account(row.get(CODE), row.get(NAME),
+ row.get(SURNAME), row.get(PASSWORD), row.get(APP_ROLE_CODE));
+ }
+
+ return account;
+ }
+
+ public void createAccount(Account account) {
+ final DataSource dataSource = ApplicationWebContext.getInstance().getDataSource();
+ final DataBaseAccessImpl dataBaseAccess = new DataBaseAccessImpl(dataSource);
+
+ dataBaseAccess.executeUpdate(
+ "INSERT INTO ACCOUNT VALUES (?, ?, ?, ?, ?)",
+ preparedStatement -> {
+ preparedStatement.setString(1, account.getCode());
+ preparedStatement.setString(2, account.getName());
+ preparedStatement.setString(3, account.getSurname());
+ preparedStatement.setString(4, account.getPassword());
+ preparedStatement.setString(5, account.getRole());
+ });
+
+ }
+
+ public void deleteAccountByCode(String code) {
+ final DataSource dataSource = ApplicationWebContext.getInstance().getDataSource();
+ final DataBaseAccessImpl dataBaseAccess = new DataBaseAccessImpl(dataSource);
+
+ dataBaseAccess.executeUpdate("DELETE FROM ACCOUNT WHERE CODE = ?",
+ preparedStatement -> {
+ preparedStatement.setString(1, code);
+ });
+
+ }
+}
--- /dev/null
+package com.prueba.resources.controllers;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.prueba.api.persistence.Account;
+import com.prueba.core.web.controller.Controller;
+import com.prueba.services.impl.ApiServiceImpl;
+import com.sun.net.httpserver.HttpExchange;
+
+public class ApiController implements Controller {
+
+ @Override
+ public void handle(HttpExchange httpExchange) throws IOException {
+ String requestMethod = httpExchange.getRequestMethod();
+ ApiServiceImpl apiService = new ApiServiceImpl();
+
+ String body = getBody(httpExchange);
+
+ ObjectMapper mapper = new ObjectMapper();
+ Account account = mapper.readValue(body, Account.class);
+
+ switch (requestMethod) {
+ case "GET":
+ apiService.findAccountByCode("GUMARTIN");
+ break;
+ case "POST":
+ apiService.createAccount(account);
+ break;
+ case "DELETE":
+ apiService.deleteAccountByCode("GUMARTIN");
+ break;
+ default:
+ httpExchange.sendResponseHeaders(404, 0);
+ break;
+ }
+
+
+
+ }
+
+ protected String getBody (HttpExchange httpExchange) throws IOException {
+ try(final InputStream inputStream = httpExchange.getRequestBody();
+ final ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream()) {
+
+ final int bufferSize = 1024;
+ final byte[] buffer = new byte[bufferSize];
+
+ int len = 0;
+ while ((len = inputStream.read(buffer)) != -1) {
+ byteBuffer.write(buffer, 0, len);
+ }
+
+ return new String(byteBuffer.toByteArray(), Charset.forName("UTF-8"));
+ }
+ }
+}
final String requestedURI = httpExchange.getRequestURI().toString();
if (requestedURI.startsWith("/app/login/login.html")) {
- loginService.processLogin(httpExchange);
+
+ final String requestMethod = httpExchange.getRequestMethod();
+
+ switch (requestMethod) {
+ case "GET":
+ loginService.processLoginGet(httpExchange);
+ break;
+ case "POST":
+ loginService.processLoginPost(httpExchange);
+ break;
+ default:
+ httpExchange.sendResponseHeaders(404, 0);
+ break;
+ }
+
} else if (requestedURI.startsWith("/app/login/logout.html")) {
loginService.processLogoutGet(httpExchange);
} else {
import java.io.IOException;
import java.io.OutputStream;
-import com.prueba.core.context.security.handle.SessionHandler;
import com.prueba.core.context.security.persistence.SessionInfo;
+import com.prueba.core.context.security.persistence.context.SessionContext;
import com.prueba.core.web.controller.Controller;
import com.prueba.view.login.PageImpl;
import com.sun.net.httpserver.HttpExchange;
}
protected String getSafeUserName() {
- SessionInfo sessionInfo = SessionHandler.getLocalSession();
+ SessionInfo sessionInfo = SessionContext.getSession();
String userName = "";
if (sessionInfo != null) {
--- /dev/null
+package com.prueba.services.impl;
+
+import com.prueba.api.persistence.Account;
+import com.prueba.persistence.dao.AccountDao;
+
+public class ApiServiceImpl {
+
+ public Account findAccountByCode(String accountCode) {
+ AccountDao accountDao = new AccountDao();
+
+ return accountDao.findAccountByCode(accountCode);
+ }
+
+ public void createAccount(Account account) {
+ AccountDao accountDao = new AccountDao();
+
+ accountDao.createAccount(account);
+ }
+
+ public void deleteAccountByCode(String accountCode) {
+ AccountDao accountDao = new AccountDao();
+
+ accountDao.deleteAccountByCode(accountCode);
+ }
+}
import java.nio.charset.Charset;
import java.util.UUID;
-import com.prueba.core.context.security.handle.SessionHandler;
import com.prueba.core.context.security.persistence.SessionInfo;
import com.prueba.core.context.security.persistence.Sessions;
+import com.prueba.core.context.security.persistence.context.SessionContext;
import com.prueba.persistence.dao.LoginDao;
import com.prueba.view.login.LoginFormImpl;
import com.sun.net.httpserver.Headers;
httpExchange.sendResponseHeaders(200, 0);
}
- public void processLogin(HttpExchange httpExchange) throws IOException {
- final String requestMethod = httpExchange.getRequestMethod();
-
- switch (requestMethod) {
- case "GET":
- this.processLoginGet(httpExchange);
- break;
- case "POST":
- this.processLoginPost(httpExchange);
- break;
- default:
- httpExchange.sendResponseHeaders(404, 0);
- break;
- }
- }
-
- protected void processLoginGet(HttpExchange httpExchange) throws IOException {
+ public void processLoginGet(HttpExchange httpExchange) throws IOException {
final String requestedURI = httpExchange.getRequestURI().toString();
- final SessionInfo sessionInfo = SessionHandler.getLocalSession();
+ final SessionInfo sessionInfo = SessionContext.getSession();
final LoginFormImpl loginForm = new LoginFormImpl();
String html = "";
}
- protected void processLoginPost(HttpExchange httpExchange) throws IOException {
- final SessionInfo sessionInfo = SessionHandler.getLocalSession();
+ public void processLoginPost(HttpExchange httpExchange) throws IOException {
+ final SessionInfo sessionInfo = SessionContext.getSession();
if (!Sessions.getInstance().isValidSession(httpExchange)) {
String body = this.getBody(httpExchange);
('/app/pages/page_3.html', 'GET'),
('/app/api/{username}', 'GET'),
('/app/api/{username}', 'PUT'),
-('/app/api/{username}', 'POST');
+('/app/api/{username}', 'POST'),
+('/app/api/{username}', 'DELETE');
INSERT INTO APPLICATION_RESOURCE_APPLICATION_ROLE (APPLICATION_RESOURCE_URL_PATTERN, APPLICATION_RESOURCE_HTTP_METHOD, APPLICATION_ROLE_CODE) values
('/app/api/{username}', 'GET', 'ROLE_APP_PAGE_3'),
('/app/api/{username}', 'GET', 'ROLE_APP_ADMIN'),
('/app/api/{username}', 'PUT', 'ROLE_APP_ADMIN'),
-('/app/api/{username}', 'POST', 'ROLE_APP_ADMIN');
+('/app/api/{username}', 'POST', 'ROLE_APP_ADMIN'),
+('/app/api/{username}', 'DELETE', 'ROLE_APP_ADMIN');
INSERT INTO ACCOUNT (CODE, NAME, SURNAME, PASSWORD, APPLICATION_ROLE_CODE) values
--- /dev/null
+package com.prueba.persistence.dao;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import javax.sql.DataSource;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.prueba.api.persistence.Account;
+import com.prueba.core.context.integration.datasource.impl.DoDataSourceContext;
+import com.prueba.core.context.integration.liquibase.impl.LiquibaseContext;
+
+public class AccountDaoIntegrationTest {
+ private AccountDao accountDao;
+ private DataSource dataSource;
+ private LiquibaseContext liquibaseContext;
+
+ @Before
+ public void init() {
+ dataSource = DoDataSourceContext.getInstance().getDataSource();
+ liquibaseContext = new LiquibaseContext(dataSource);
+ liquibaseContext.init();
+ accountDao = new AccountDao();
+ }
+
+ @Test
+ public void whenCreateNewAccountThenRetrieveNewAccount() {
+ Account expectedAccount = doSampleAccount();
+
+ accountDao.createAccount(expectedAccount);
+
+ Account account = accountDao.findAccountByCode(expectedAccount.getCode());
+
+ assertNotNull(account);
+ assertEquals(expectedAccount.getCode(), account.getCode());
+ assertEquals(expectedAccount.getName(), account.getName());
+ assertEquals(expectedAccount.getSurname(), account.getSurname());
+ assertEquals(expectedAccount.getPassword(), account.getPassword());
+ assertEquals(expectedAccount.getRole(), account.getRole());
+ }
+
+ @Test
+ public void whenDeleteAccountThenDoNotRetrieveAgainAccount() {
+ Account expectedAccount = doOtherSampleAccount();
+
+ accountDao.createAccount(expectedAccount);
+ Account account = accountDao.findAccountByCode(expectedAccount.getCode());
+
+ assertNotNull(account);
+ assertEquals(expectedAccount.getCode(), account.getCode());
+ assertEquals(expectedAccount.getName(), account.getName());
+ assertEquals(expectedAccount.getSurname(), account.getSurname());
+ assertEquals(expectedAccount.getPassword(), account.getPassword());
+ assertEquals(expectedAccount.getRole(), account.getRole());
+
+ accountDao.deleteAccountByCode(expectedAccount.getCode());
+
+ account = accountDao.findAccountByCode(expectedAccount.getCode());
+ assertNull(account);
+ }
+
+ private Account doSampleAccount() {
+ final String expectedCode = "PRUEBA";
+ final String expectedName = "Gustavo";
+ final String expectedSurname = "Martin Morcuende";
+ final String expectedPassword = "lame";
+ final String expectedAppRoleCode = "ROLE_APP_ADMIN";
+
+ return new Account(expectedCode, expectedName, expectedSurname, expectedPassword, expectedAppRoleCode);
+ }
+
+ private Account doOtherSampleAccount() {
+ final String expectedCode = "OTRAPRUEBA";
+ final String expectedName = "Gustavo";
+ final String expectedSurname = "Martin Morcuende";
+ final String expectedPassword = "lame";
+ final String expectedAppRoleCode = "ROLE_APP_ADMIN";
+
+ return new Account(expectedCode, expectedName, expectedSurname, expectedPassword, expectedAppRoleCode);
+ }
+}