Se comenzaron a realizar unit tests

Junto con ello se modificaron las clases para poder hacer la conexion a
una uri diferente para sqlite.
This commit is contained in:
Daniel Cortés
2019-03-30 00:01:31 -03:00
parent 5a46dde8e5
commit fab3950e07
31 changed files with 1020 additions and 64 deletions

View File

@@ -40,6 +40,7 @@ public class Main {
static {
setUpSystemProperties();
DAOManager.setup();
updateDatabase();
}

View File

@@ -113,8 +113,12 @@ public class CajasController {
DAOManager.getEfectivoDAO().insertDefault(efectivo);
Documentos documentos = new Documentos();
documentos.setTarjetas(0);
documentos.setCheques(0);
documentos.setRetiros(0);
documentos.setCaja(c);
DAOManager.getDocumentosDAO().insertDefault(documentos);
DAOManager.getDocumentosDAO().insert(documentos);
return c;
});

View File

@@ -47,18 +47,18 @@ import danielcortes.xyz.models.version.VersionDAO;
public class DAOManager {
private static final CajaDAO cajaDAO;
private static final CalculoFondoDAO calculoFondoDAO;
private static final DocumentosDAO documentosDAO;
private static final EfectivoDAO efectivoDAO;
private static final EgresoDAO egresoDAO;
private static final IngresoDAO ingresoDAO;
private static final TipoEgresoDAO tipoEgresoDAO;
private static final TipoIngresoDAO tipoIngresoDAO;
private static final EstadoResultadoDAO estadoResultadoDAO;
private static final VersionDAO versionDAO;
private static CajaDAO cajaDAO;
private static CalculoFondoDAO calculoFondoDAO;
private static DocumentosDAO documentosDAO;
private static EfectivoDAO efectivoDAO;
private static EgresoDAO egresoDAO;
private static IngresoDAO ingresoDAO;
private static TipoEgresoDAO tipoEgresoDAO;
private static TipoIngresoDAO tipoIngresoDAO;
private static EstadoResultadoDAO estadoResultadoDAO;
private static VersionDAO versionDAO;
static {
public static void setup() {
cajaDAO = new SQLiteCajaDAO();
calculoFondoDAO = new SQLiteCalculoFondoDAO();
documentosDAO = new SQLiteDocumentosDAO();
@@ -71,6 +71,19 @@ public class DAOManager {
versionDAO = new SQLiteVersionDAO();
}
public static void setup(ConnectionHolder connectionHolder){
cajaDAO = new SQLiteCajaDAO(connectionHolder);
calculoFondoDAO = new SQLiteCalculoFondoDAO(connectionHolder);
documentosDAO = new SQLiteDocumentosDAO(connectionHolder);
efectivoDAO = new SQLiteEfectivoDAO(connectionHolder);
egresoDAO = new SQLiteEgresoDAO(connectionHolder);
ingresoDAO = new SQLiteIngresoDAO(connectionHolder);
tipoEgresoDAO = new SQLiteTipoEgresoDAO(connectionHolder);
tipoIngresoDAO = new SQLiteTipoIngresoDAO(connectionHolder);
estadoResultadoDAO = new SQLiteEstadoResultadoDAO(connectionHolder);
versionDAO = new SQLiteVersionDAO(connectionHolder);
}
public static CajaDAO getCajaDAO() {
return cajaDAO;
}

View File

@@ -35,6 +35,10 @@ public class SQLiteConnectionHolder implements ConnectionHolder {
this.databaseURI = Configuration.get("sqlite_database_uri");
}
public SQLiteConnectionHolder(String databaseURI){
this.databaseURI = databaseURI;
}
@Override
public Connection getConnection() throws SQLException {
Connection con = null;

View File

@@ -25,6 +25,7 @@
package danielcortes.xyz.models.caja;
import java.time.LocalDate;
import java.util.Objects;
public class Caja {
public final static Caja EMPTY = new Caja();
@@ -66,6 +67,26 @@ public class Caja {
return "Caja{" +
"id=" + id +
", fecha=" + fecha +
", fondo=" + fondo +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Caja)) {
return false;
}
Caja caja = (Caja) o;
return id == caja.id &&
fondo == caja.fondo &&
Objects.equals(fecha, caja.fecha);
}
@Override
public int hashCode() {
return Objects.hash(id, fecha, fondo);
}
}

View File

@@ -24,6 +24,7 @@
package danielcortes.xyz.models.caja;
import danielcortes.xyz.data.ConnectionHolder;
import danielcortes.xyz.data.SQLiteConnectionHolder;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -38,12 +39,16 @@ import org.apache.logging.log4j.Logger;
public class SQLiteCajaDAO implements CajaDAO {
private static final Logger log = LogManager.getLogger(SQLiteCajaDAO.class);
private SQLiteConnectionHolder connectionHolder;
private ConnectionHolder connectionHolder;
public SQLiteCajaDAO() {
this.connectionHolder = new SQLiteConnectionHolder();
}
public SQLiteCajaDAO(ConnectionHolder connectionHolder) {
this.connectionHolder = connectionHolder;
}
@Override
public List<Caja> getAll() {
log.debug("Se intentara conseguir todas las Cajas");

View File

@@ -25,6 +25,7 @@
package danielcortes.xyz.models.calculo_fondo;
import danielcortes.xyz.models.caja.Caja;
import java.util.Objects;
public class CalculoFondo {
@@ -74,4 +75,24 @@ public class CalculoFondo {
", caja=" + caja +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof CalculoFondo)) {
return false;
}
CalculoFondo that = (CalculoFondo) o;
return id == that.id &&
valor == that.valor &&
Objects.equals(descripcion, that.descripcion) &&
Objects.equals(caja, that.caja);
}
@Override
public int hashCode() {
return Objects.hash(id, valor, descripcion, caja);
}
}

View File

@@ -46,6 +46,10 @@ public class SQLiteCalculoFondoDAO implements CalculoFondoDAO {
this.connectionHolder = new SQLiteConnectionHolder();
}
public SQLiteCalculoFondoDAO(ConnectionHolder connectionHolder) {
this.connectionHolder = connectionHolder;
}
@Override
public List<CalculoFondo> getAll() {
log.debug("Se intentara conseguir todos los CalculosFondo");

View File

@@ -25,6 +25,7 @@
package danielcortes.xyz.models.documentos;
import danielcortes.xyz.models.caja.Caja;
import java.util.Objects;
public class Documentos {
public final static Documentos EMPTY;
@@ -90,4 +91,25 @@ public class Documentos {
", caja=" + caja +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Documentos)) {
return false;
}
Documentos that = (Documentos) o;
return id == that.id &&
cheques == that.cheques &&
tarjetas == that.tarjetas &&
retiros == that.retiros &&
Objects.equals(caja, that.caja);
}
@Override
public int hashCode() {
return Objects.hash(id, cheques, tarjetas, retiros, caja);
}
}

View File

@@ -67,12 +67,6 @@ public interface DocumentosDAO {
*/
void insert(Documentos documentos);
/**
* Inserta un documentos con valores por default.
* @param documentos Instancia del documento a guardar
*/
void insertDefault(Documentos documentos);
/**
* Actualiza un documentos
* @param documentos Documento a actualizar

View File

@@ -46,6 +46,10 @@ public class SQLiteDocumentosDAO implements DocumentosDAO {
this.connectionHolder = new SQLiteConnectionHolder();
}
public SQLiteDocumentosDAO(ConnectionHolder connectionHolder) {
this.connectionHolder = connectionHolder;
}
@Override
public List<Documentos> getAll() {
log.debug("Se intentaran conseguir todos los Documentos");
@@ -193,27 +197,6 @@ public class SQLiteDocumentosDAO implements DocumentosDAO {
log.debug("Se inserto el documentos " + documentos);
}
@Override
public void insertDefault(Documentos documentos) {
log.debug("Se intentara insertar el documento default " + documentos);
String query = "insert into documentos (cheques, tarjetas, retiros, caja_id) values (0,0,0,?)";
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, documentos.getCaja().getId());
ps.executeUpdate();
}
try (PreparedStatement ps = conn.prepareStatement("select last_insert_rowid()")) {
try (ResultSet rs = ps.executeQuery()) {
rs.next();
documentos.setId(rs.getInt(1));
}
}
} catch (SQLException e) {
log.error("Error al intentar insertar el documento por default " + documentos, e);
}
log.debug("Se inserto el documento por default " + documentos);
}
@Override
public void update(Documentos documentos) {
log.debug("Se intentara actualizar el documentos " + documentos);
@@ -240,6 +223,7 @@ public class SQLiteDocumentosDAO implements DocumentosDAO {
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, documentos.getId());
ps.execute();
}
} catch (SQLException e) {
log.error("Error al eliminar el documentos " + documentos, e);

View File

@@ -25,6 +25,7 @@
package danielcortes.xyz.models.efectivo;
import danielcortes.xyz.models.caja.Caja;
import java.util.Objects;
public class Efectivo {
public final static Efectivo EMPTY;
@@ -150,4 +151,33 @@ public class Efectivo {
", caja=" + caja +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Efectivo)) {
return false;
}
Efectivo efectivo = (Efectivo) o;
return id == efectivo.id &&
veinteMil == efectivo.veinteMil &&
diezMil == efectivo.diezMil &&
cincoMil == efectivo.cincoMil &&
dosMil == efectivo.dosMil &&
mil == efectivo.mil &&
quinientos == efectivo.quinientos &&
cien == efectivo.cien &&
cincuenta == efectivo.cincuenta &&
diez == efectivo.diez &&
Objects.equals(caja, efectivo.caja);
}
@Override
public int hashCode() {
return Objects
.hash(id, veinteMil, diezMil, cincoMil, dosMil, mil, quinientos, cien, cincuenta, diez,
caja);
}
}

View File

@@ -47,6 +47,10 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
this.connectionHolder = new SQLiteConnectionHolder();
}
public SQLiteEfectivoDAO(ConnectionHolder connectionHolder) {
this.connectionHolder = connectionHolder;
}
@Override
public List<Efectivo> getAll() {
log.debug("Se intentara conseguir todas los Efectivo");

View File

@@ -26,6 +26,7 @@ package danielcortes.xyz.models.egreso;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
import java.util.Objects;
public class Egreso {
@@ -85,7 +86,8 @@ public class Egreso {
}
@Override
public String toString() {
public String
toString() {
return "Egreso{" +
"id=" + id +
", nro='" + nro + '\'' +
@@ -95,4 +97,26 @@ public class Egreso {
", caja=" + caja +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Egreso)) {
return false;
}
Egreso egreso = (Egreso) o;
return id == egreso.id &&
valor == egreso.valor &&
Objects.equals(nro, egreso.nro) &&
Objects.equals(descripcion, egreso.descripcion) &&
Objects.equals(tipoEgreso, egreso.tipoEgreso) &&
Objects.equals(caja, egreso.caja);
}
@Override
public int hashCode() {
return Objects.hash(id, nro, descripcion, valor, tipoEgreso, caja);
}
}

View File

@@ -52,6 +52,10 @@ public class SQLiteEgresoDAO implements EgresoDAO {
this.connectionHolder = new SQLiteConnectionHolder();
}
public SQLiteEgresoDAO(ConnectionHolder connectionHolder) {
this.connectionHolder = connectionHolder;
}
@Override
public List<Egreso> getAll() {
log.debug("Se intentara conseguir todos los Egreso");

View File

@@ -1,6 +1,7 @@
package danielcortes.xyz.models.estado_resultado;
import java.time.YearMonth;
import java.util.Objects;
public class EstadoResultado {
@@ -182,5 +183,67 @@ public class EstadoResultado {
public void setIvaFavor(int ivaFavor) {
this.ivaFavor = ivaFavor;
}
@Override
public String toString() {
return "EstadoResultado{" +
"id=" + id +
", mes=" + mes +
", costoVenta=" + costoVenta +
", cuentaCorrienteFactura=" + cuentaCorrienteFactura +
", cuentaCorrienteBoleta=" + cuentaCorrienteBoleta +
", cuentaCorrienteSinRespaldo=" + cuentaCorrienteSinRespaldo +
", remuneraciones=" + remuneraciones +
", finiquitos=" + finiquitos +
", aguinaldo=" + aguinaldo +
", bonosPersonal=" + bonosPersonal +
", honorariosContador=" + honorariosContador +
", arriendo=" + arriendo +
", agua=" + agua +
", luz=" + luz +
", gas=" + gas +
", telefono=" + telefono +
", otroServicio=" + otroServicio +
", ppm=" + ppm +
", ivaFavor=" + ivaFavor +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof EstadoResultado)) {
return false;
}
EstadoResultado that = (EstadoResultado) o;
return id == that.id &&
costoVenta == that.costoVenta &&
cuentaCorrienteFactura == that.cuentaCorrienteFactura &&
cuentaCorrienteBoleta == that.cuentaCorrienteBoleta &&
cuentaCorrienteSinRespaldo == that.cuentaCorrienteSinRespaldo &&
remuneraciones == that.remuneraciones &&
finiquitos == that.finiquitos &&
aguinaldo == that.aguinaldo &&
bonosPersonal == that.bonosPersonal &&
honorariosContador == that.honorariosContador &&
arriendo == that.arriendo &&
agua == that.agua &&
luz == that.luz &&
gas == that.gas &&
telefono == that.telefono &&
otroServicio == that.otroServicio &&
Double.compare(that.ppm, ppm) == 0 &&
ivaFavor == that.ivaFavor &&
Objects.equals(mes, that.mes);
}
@Override
public int hashCode() {
return Objects.hash(id, mes, costoVenta, cuentaCorrienteFactura, cuentaCorrienteBoleta,
cuentaCorrienteSinRespaldo, remuneraciones, finiquitos, aguinaldo, bonosPersonal,
honorariosContador, arriendo, agua, luz, gas, telefono, otroServicio, ppm, ivaFavor);
}
}

View File

@@ -1,5 +1,6 @@
package danielcortes.xyz.models.estado_resultado;
import danielcortes.xyz.data.ConnectionHolder;
import danielcortes.xyz.data.SQLiteConnectionHolder;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -16,12 +17,16 @@ import org.apache.logging.log4j.Logger;
public class SQLiteEstadoResultadoDAO implements EstadoResultadoDAO {
private static final Logger log = LogManager.getLogger(SQLiteEstadoResultadoDAO.class);
private SQLiteConnectionHolder connectionHolder;
private ConnectionHolder connectionHolder;
public SQLiteEstadoResultadoDAO() {
this.connectionHolder = new SQLiteConnectionHolder();
}
public SQLiteEstadoResultadoDAO(ConnectionHolder connectionHolder) {
this.connectionHolder = connectionHolder;
}
@Override
public List<EstadoResultado> getAll() {
log.debug("Se intentara conseguir todos los EstadoResultado");

View File

@@ -26,6 +26,7 @@ package danielcortes.xyz.models.ingreso;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
import java.util.Objects;
public class Ingreso {
@@ -115,4 +116,28 @@ public class Ingreso {
", caja=" + caja +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Ingreso)) {
return false;
}
Ingreso ingreso = (Ingreso) o;
return id == ingreso.id &&
valor == ingreso.valor &&
Objects.equals(nroZInicial, ingreso.nroZInicial) &&
Objects.equals(nroZFinal, ingreso.nroZFinal) &&
Objects.equals(nroInicial, ingreso.nroInicial) &&
Objects.equals(nroFinal, ingreso.nroFinal) &&
Objects.equals(tipoIngreso, ingreso.tipoIngreso) &&
Objects.equals(caja, ingreso.caja);
}
@Override
public int hashCode() {
return Objects.hash(id, valor, nroZInicial, nroZFinal, nroInicial, nroFinal, tipoIngreso, caja);
}
}

View File

@@ -52,6 +52,10 @@ public class SQLiteIngresoDAO implements IngresoDAO {
this.connectionHolder = new SQLiteConnectionHolder();
}
public SQLiteIngresoDAO(ConnectionHolder connectionHolder) {
this.connectionHolder = connectionHolder;
}
@Override
public List<Ingreso> getAll() {
log.debug("Se intententaran conseguir todos los Ingreso");

View File

@@ -36,10 +36,6 @@ import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* Objeto DAO que realiza las querys y mapeos necesarios del objeto TipoEgreso. En especifico esta
* implementacion se comunica con la base de datos SQLite
*/
public class SQLiteTipoEgresoDAO implements TipoEgresoDAO {
private static final Logger log = LogManager.getLogger(SQLiteTipoEgresoDAO.class);
@@ -49,6 +45,10 @@ public class SQLiteTipoEgresoDAO implements TipoEgresoDAO {
this.connectionHolder = new SQLiteConnectionHolder();
}
public SQLiteTipoEgresoDAO(ConnectionHolder connectionHolder) {
this.connectionHolder = connectionHolder;
}
@Override
public List<TipoEgreso> getAll() {
log.debug("Se intentara conseguir todos los tipoEgreso");

View File

@@ -48,6 +48,8 @@
package danielcortes.xyz.models.tipo_egreso;
import java.util.Objects;
public class TipoEgreso {
public final static TipoEgreso EMPTY;
@@ -94,4 +96,22 @@ public class TipoEgreso {
", nombre='" + nombre + '\'' +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof TipoEgreso)) {
return false;
}
TipoEgreso that = (TipoEgreso) o;
return id == that.id &&
Objects.equals(nombre, that.nombre);
}
@Override
public int hashCode() {
return Objects.hash(id, nombre);
}
}

View File

@@ -45,6 +45,10 @@ public class SQLiteTipoIngresoDAO implements TipoIngresoDAO {
this.connectionHolder = new SQLiteConnectionHolder();
}
public SQLiteTipoIngresoDAO(ConnectionHolder connectionHolder) {
this.connectionHolder = connectionHolder;
}
@Override
public List<TipoIngreso> getAll() {
log.debug("Se intentara conseguir todos los TipoIngreso");

View File

@@ -48,6 +48,8 @@
package danielcortes.xyz.models.tipo_ingreso;
import java.util.Objects;
public class TipoIngreso {
public final static TipoIngreso EMPTY;
@@ -94,4 +96,22 @@ public class TipoIngreso {
", nombre='" + nombre + '\'' +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof TipoIngreso)) {
return false;
}
TipoIngreso that = (TipoIngreso) o;
return id == that.id &&
Objects.equals(nombre, that.nombre);
}
@Override
public int hashCode() {
return Objects.hash(id, nombre);
}
}

View File

@@ -28,6 +28,10 @@ public class SQLiteVersionDAO implements VersionDAO {
this.connectionHolder = new SQLiteConnectionHolder();
}
public SQLiteVersionDAO(ConnectionHolder connectionHolder) {
this.connectionHolder = connectionHolder;
}
private boolean tableVersionsExists() {
try {
DatabaseMetaData md = this.connectionHolder.getConnection().getMetaData();

View File

@@ -0,0 +1,21 @@
package danielcortes.xyz.utils;
import java.time.LocalDate;
import java.util.concurrent.ThreadLocalRandom;
public class RandomLocalDate {
private static final LocalDate DEFAULT_FROM = LocalDate.of(1970,1,1);
private static final LocalDate DEFAULT_TO = LocalDate.of(2038,1,19);
public static LocalDate random(){
return randomBetween(DEFAULT_FROM, DEFAULT_TO);
}
public static LocalDate randomBetween(LocalDate from, LocalDate to){
long min = from.toEpochDay();
long max = to.toEpochDay();
long random = ThreadLocalRandom.current().nextLong(min, max);
return LocalDate.ofEpochDay(random);
}
}