Skip to content

Commit

Permalink
tests unitarios para domain
Browse files Browse the repository at this point in the history
  • Loading branch information
yazmin48 committed Dec 30, 2024
1 parent 11bb5b5 commit 4304088
Show file tree
Hide file tree
Showing 25 changed files with 2,337 additions and 354 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ public Candidate() {
}

public String getBio(String displayName) {
if (displayName.toLowerCase().contains("en") || displayName.toLowerCase().contains("english"))
if (displayName.equalsIgnoreCase("en") || displayName.equalsIgnoreCase("english"))
return getBioEnglish();
else if (displayName.toLowerCase().contains("pt") || displayName.toLowerCase().contains("portuguese"))
return getBioPortuguese();
return getBioSpanish();
}

public String getLink(String displayName) {
if (displayName.toLowerCase().contains("en") || displayName.toLowerCase().contains("english"))
if (displayName.equalsIgnoreCase("en") || displayName.equalsIgnoreCase("english"))
return getLinkEnglish();
else if (displayName.toLowerCase().contains("pt") || displayName.toLowerCase().contains("portuguese"))
return getLinkPortuguese();
Expand Down Expand Up @@ -254,4 +254,4 @@ public void setMail(String mail) {
this.mail = mail;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ private void setTitle(String title) {
}

public String getDescription(String displayName) {
if (displayName.toLowerCase().contains("en") || displayName.toLowerCase().contains("english"))
if (displayName.equalsIgnoreCase("en") || displayName.equalsIgnoreCase("english"))
return getDescriptionEnglish();
else if (displayName.toLowerCase().contains("pt") || displayName.toLowerCase().contains("portuguese"))
return getDescriptionPortuguese();
return getDescriptionSpanish();
}

public String getTitle(String displayName) {
if (displayName.toLowerCase().contains("en") || displayName.toLowerCase().contains("english"))
if (displayName.equalsIgnoreCase("en") || displayName.equalsIgnoreCase("english"))
return getTitleEnglish();
else if (displayName.toLowerCase().contains("pt") || displayName.toLowerCase().contains("portuguese"))
return getTitlePortuguese();
Expand Down Expand Up @@ -654,4 +654,4 @@ public void setClosedDate(Date closedDate) {
this.closedDate = closedDate;
}

}
}
25 changes: 0 additions & 25 deletions elections-ejb/src/test/java/net/lacnic/CustomizationDataTest.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import net.lacnic.elections.data.ElectionReport;
import net.lacnic.elections.data.HealthCheck;
import net.lacnic.elections.data.Participation;

public class AditionalDataTest extends TestCase {

Expand Down Expand Up @@ -63,28 +60,27 @@ public void testParticipationData() {
participacion.setElectionStartDate(fechaInicioEleccion);
participacion.setVoted(true);

assertEquals(participacion.getCategory(), categoria);
assertEquals(participacion.getEmail(), email);
assertEquals(participacion.getElectionLinkEN(), linkEleccionEN);
assertEquals(participacion.getElectionLinkPT(), linkEleccionPT);
assertEquals(participacion.getElectionLinkSP(), linkEleccionSP);
assertEquals(participacion.getVoteLink(), linkVotar);
assertEquals(participacion.getName(), nombre);
assertEquals(participacion.getOrgId(), orgId);
assertEquals(participacion.getCountry(), pais);
assertEquals(participacion.getElectionTitleEN(), tituloEleccionEN);
assertEquals(participacion.getElectionTitlePT(), tituloEleccionPT);
assertEquals(participacion.getElectionTitleSP(), tituloEleccionSP);
assertEquals(participacion.getElectionEndDate(), fechaFinEleccion);
assertEquals(participacion.getElectionStartDate(), fechaInicioEleccion);
assertEquals(categoria, participacion.getCategory());
assertEquals(email, participacion.getEmail());
assertEquals(linkEleccionEN, participacion.getElectionLinkEN());
assertEquals(linkEleccionPT, participacion.getElectionLinkPT());
assertEquals(linkEleccionSP, participacion.getElectionLinkSP());
assertEquals(linkVotar, participacion.getVoteLink());
assertEquals(nombre, participacion.getName());
assertEquals(orgId, participacion.getOrgId());
assertEquals(pais, participacion.getCountry());
assertEquals(tituloEleccionEN, participacion.getElectionTitleEN());
assertEquals(tituloEleccionPT, participacion.getElectionTitlePT());
assertEquals(tituloEleccionSP, participacion.getElectionTitleSP());
assertEquals(fechaFinEleccion, participacion.getElectionEndDate());
assertEquals(fechaInicioEleccion, participacion.getElectionStartDate());
assertTrue(participacion.isVoted());
}

public void testElectionReportDataAndHealthCheck() {
// ElectionReport Data
String nombreEleccion;
long usuariosVotaron, usuariosNoVotaron, usuariosTotales, correosPendientes;
nombreEleccion = "test";
String nombreEleccion = "test";
usuariosVotaron = 10;
usuariosNoVotaron = 1;
usuariosTotales = 11;
Expand All @@ -94,16 +90,15 @@ public void testElectionReportDataAndHealthCheck() {

assertNotNull(eleccion);

assertEquals(eleccion.getPendingMails(), correosPendientes);
assertEquals(eleccion.getElectionName(), nombreEleccion);
assertEquals(eleccion.getUsersNotVoted(), usuariosNoVotaron);
assertEquals(eleccion.getUsersVoted(), usuariosVotaron);
assertEquals(eleccion.getUsersTotal(), usuariosTotales);
assertEquals(correosPendientes, eleccion.getPendingMails());
assertEquals(nombreEleccion, eleccion.getElectionName());
assertEquals(usuariosNoVotaron, eleccion.getUsersNotVoted());
assertEquals(usuariosVotaron, eleccion.getUsersVoted());
assertEquals(usuariosTotales, eleccion.getUsersTotal());

// Health check
int intentosDeEnvio;
long ipsAccesosFallidos, sumaAccesosFallidos, correosTotales, correosPendientes2, correosEnviados;
intentosDeEnvio = 1;
int intentosDeEnvio = 1;
ipsAccesosFallidos = 5;
sumaAccesosFallidos = 5;
correosEnviados = 9;
Expand All @@ -117,21 +112,20 @@ public void testElectionReportDataAndHealthCheck() {

assertNotNull(healthChk);

assertEquals(healthChk.getMailsSent(), correosEnviados);
assertEquals(healthChk.getMailsPending(), correosPendientes2);
assertEquals(healthChk.getMailsTotal(), correosTotales);
assertEquals(healthChk.getSendAttempts(), intentosDeEnvio);
assertEquals(healthChk.getFailedAccessIps(), ipsAccesosFallidos);
assertEquals(healthChk.getFailedAccessSum(), sumaAccesosFallidos);
assertEquals(correosEnviados, healthChk.getMailsSent());
assertEquals(correosPendientes2, healthChk.getMailsPending());
assertEquals(correosTotales, healthChk.getMailsTotal());
assertEquals(intentosDeEnvio, healthChk.getSendAttempts());
assertEquals(ipsAccesosFallidos, healthChk.getFailedAccessIps());
assertEquals(sumaAccesosFallidos, healthChk.getFailedAccessSum());
assertEquals(1, elecciones.size());
assertEquals(healthChk.getElections().get(0), elecciones.get(0));
assertEquals(elecciones.get(0), healthChk.getElections().get(0));
}

public void testElectionReportDataSetsRestantes() {

String nombreEleccion;
long usuariosVotaron, usuariosNoVotaron, usuariosTotales, correosPendientes;
nombreEleccion = "test";
String nombreEleccion = "test";
usuariosVotaron = 10;
usuariosNoVotaron = 1;
usuariosTotales = 11;
Expand All @@ -147,47 +141,45 @@ public void testElectionReportDataSetsRestantes() {
eleccion.setUsersTotal(usuariosTotales);
eleccion.setUsersVoted(usuariosVotaron);

assertEquals(eleccion.getPendingMails(), correosPendientes);
assertEquals(eleccion.getElectionName(), nombreEleccion);
assertEquals(eleccion.getUsersNotVoted(), usuariosNoVotaron);
assertEquals(eleccion.getUsersVoted(), usuariosVotaron);
assertEquals(eleccion.getUsersTotal(), usuariosTotales);
assertEquals(nombreEleccion, eleccion.getElectionName());
assertEquals(correosPendientes, eleccion.getPendingMails());
assertEquals(usuariosNoVotaron, eleccion.getUsersNotVoted());
assertEquals(usuariosTotales, eleccion.getUsersTotal());
assertEquals(usuariosVotaron, eleccion.getUsersVoted());
}

public void testHealthCheckSets() {

int intentosDeEnvio;
long ipsAccesosFallidos, sumaAccesosFallidos, correosTotales, correosPendientes2, correosEnviados;
intentosDeEnvio = 1;
long ipsAccesosFallidos, sumaAccesosFallidos, correosTotales, correosPendientes, correosEnviados;
int intentosDeEnvio = 1;
ipsAccesosFallidos = 5;
sumaAccesosFallidos = 5;
correosEnviados = 9;
correosPendientes2 = 1;
correosPendientes = 1;
correosTotales = 10;

List<ElectionReport> elecciones = new ArrayList<>();
elecciones.add(new ElectionReport("", 0, 0, 0, 0));

HealthCheck healthChk = new HealthCheck(intentosDeEnvio, ipsAccesosFallidos, sumaAccesosFallidos, correosTotales, correosPendientes2, correosEnviados, elecciones);
HealthCheck healthChk = new HealthCheck(intentosDeEnvio, ipsAccesosFallidos, sumaAccesosFallidos, correosTotales, correosPendientes, correosEnviados, elecciones);

assertNotNull(healthChk);

healthChk.setElections(elecciones);
healthChk.setFailedAccessIps(ipsAccesosFallidos);
healthChk.setFailedAccessSum(sumaAccesosFallidos);
healthChk.setMailsPending(correosPendientes2);
healthChk.setMailsPending(correosPendientes);
healthChk.setMailsSent(correosEnviados);
healthChk.setMailsTotal(correosTotales);
healthChk.setSendAttempts(intentosDeEnvio);

assertEquals(healthChk.getMailsSent(), correosEnviados);
assertEquals(healthChk.getMailsPending(), correosPendientes2);
assertEquals(healthChk.getMailsTotal(), correosTotales);
assertEquals(healthChk.getSendAttempts(), intentosDeEnvio);
assertEquals(healthChk.getFailedAccessIps(), ipsAccesosFallidos);
assertEquals(healthChk.getFailedAccessSum(), sumaAccesosFallidos);
assertEquals(correosEnviados, healthChk.getMailsSent());
assertEquals(correosPendientes, healthChk.getMailsPending());
assertEquals(correosTotales, healthChk.getMailsTotal());
assertEquals(intentosDeEnvio, healthChk.getSendAttempts());
assertEquals(ipsAccesosFallidos, healthChk.getFailedAccessIps());
assertEquals(sumaAccesosFallidos, healthChk.getFailedAccessSum());
assertEquals(1, elecciones.size());
assertEquals(healthChk.getElections().get(0), elecciones.get(0));
assertEquals(elecciones.get(0), healthChk.getElections().get(0));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import net.lacnic.elections.data.ElectionsResultsData;
import net.lacnic.elections.data.ResultDetailData;

public class ElectionResultsDataTest extends TestCase {

Expand All @@ -25,29 +23,27 @@ public static Test suite() {
public void testResultadoEleccionesData() {

Long availableVoters, participantVoters, percentage, total;
int weigth, max;
String strTotal, strTotalPos;
availableVoters = (long) 1000;
participantVoters = (long) 500;
weigth = 5;
max = 2;
availableVoters = 1000L;
participantVoters = 500L;
int weigth = 5;
int max = 2;

percentage = (participantVoters * 100L) / availableVoters;
total = (participantVoters) * (weigth);
strTotal = "( " + total + " - " + (total * max) + ") ";
strTotalPos = "( " + total + " - " + (total * max) + ") ";
String strTotal = "( " + total + " - " + (total * max) + ") ";
String strTotalPos = "( " + total + " - " + (total * max) + ") ";

ResultDetailData detalleRes = new ResultDetailData(availableVoters, participantVoters, weigth);

assertNotNull(detalleRes);

assertEquals(detalleRes.getPercentage(), percentage);
assertEquals(detalleRes.getPercentageWithSymbol(), percentage + " %");
assertEquals(detalleRes.getEnabled(), availableVoters);
assertEquals(detalleRes.getParticipants(), participantVoters);
assertEquals(detalleRes.getWeight(), Integer.valueOf(weigth));
assertEquals(detalleRes.getTotal(), total);
assertEquals(detalleRes.getTotal(max), strTotal);
assertEquals(percentage, detalleRes.getPercentage());
assertEquals(percentage + " %", detalleRes.getPercentageWithSymbol());
assertEquals(availableVoters, detalleRes.getEnabled());
assertEquals(participantVoters, detalleRes.getParticipants());
assertEquals(Integer.valueOf(weigth), detalleRes.getWeight());
assertEquals(total, detalleRes.getTotal());
assertEquals(strTotal, detalleRes.getTotal(max));

ElectionsResultsData resultado = new ElectionsResultsData(max);

Expand All @@ -61,18 +57,18 @@ public void testResultadoEleccionesData() {
resultado.setTotalEnabled(availableVoters);
resultado.setTotalTotal(total);

assertEquals(resultado.getMax(), max);
assertEquals(resultado.getTotalEnabled(), availableVoters);
assertEquals(resultado.getTotalParticipants(), participantVoters);
assertEquals(resultado.getTotalTotal(), total);
assertEquals(resultado.getTotalPercentageWithSymbol(), percentage + " %");
assertEquals(resultado.getTotalTotalPossible(), strTotalPos);
assertEquals(max, resultado.getMax());
assertEquals(availableVoters, resultado.getTotalEnabled());
assertEquals(participantVoters, resultado.getTotalParticipants());
assertEquals(total, resultado.getTotalTotal());
assertEquals(percentage + " %", resultado.getTotalPercentageWithSymbol());
assertEquals(strTotalPos, resultado.getTotalTotalPossible());

resultado.calculateTotals();

assertEquals(resultado.getTotalEnabled(), availableVoters);
assertEquals(resultado.getTotalParticipants(), participantVoters);
assertEquals(resultado.getTotalTotal(), total);
assertEquals(availableVoters, resultado.getTotalEnabled());
assertEquals(participantVoters, resultado.getTotalParticipants());
assertEquals(total, resultado.getTotalTotal());
}

public void testResultadoEleccionesDataConConstructorPorDefecto() {
Expand All @@ -84,22 +80,20 @@ public void testResultadoEleccionesDataConConstructorPorDefecto() {
assertNotNull(resultado);
resultado.setMax(max);

assertEquals(resultado.getMax(), max);
assertEquals(max, resultado.getMax());
}

public void testResultDetailDataConConstructorPorDefecto() {

Long availableVoters, participantVoters, percentage, total;
int weigth, max;
String strTotal;
availableVoters = (long) 1000;
participantVoters = (long) 500;
weigth = 5;
max = 2;
availableVoters = 1000L;
participantVoters = 500L;
int weigth = 5;
int max = 2;

percentage = (participantVoters * 100L) / availableVoters;
total = (participantVoters) * (weigth);
strTotal = "( " + total + " - " + (total * max) + ") ";
String strTotal = "( " + total + " - " + (total * max) + ") ";

ResultDetailData detalleRes = new ResultDetailData();

Expand All @@ -111,13 +105,13 @@ public void testResultDetailDataConConstructorPorDefecto() {
detalleRes.setWeight(Integer.valueOf(weigth));
detalleRes.setEnabled(availableVoters);

assertEquals(detalleRes.getPercentage(), percentage);
assertEquals(detalleRes.getPercentageWithSymbol(), percentage + " %");
assertEquals(detalleRes.getEnabled(), availableVoters);
assertEquals(detalleRes.getParticipants(), participantVoters);
assertEquals(detalleRes.getWeight(), Integer.valueOf(weigth));
assertEquals(detalleRes.getTotal(), total);
assertEquals(detalleRes.getTotal(max), strTotal);
assertEquals(percentage, detalleRes.getPercentage());
assertEquals(percentage + " %", detalleRes.getPercentageWithSymbol());
assertEquals(availableVoters, detalleRes.getEnabled());
assertEquals(participantVoters, detalleRes.getParticipants());
assertEquals(Integer.valueOf(weigth), detalleRes.getWeight());
assertEquals(total, detalleRes.getTotal());
assertEquals(strTotal, detalleRes.getTotal(max));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public void testTableReportDataStringId() {

assertNotNull(tableReportData);

assertEquals(tableReportData.getId(), id);
assertEquals(tableReportData.getDescription(), description);
assertEquals(id, tableReportData.getId());
assertEquals(description, tableReportData.getDescription());
}

public void testTableReportDataStringIdSets() {
Expand All @@ -40,8 +40,8 @@ public void testTableReportDataStringIdSets() {
tableReportData.setId(id);
tableReportData.setDescription(description);

assertEquals(tableReportData.getId(), id);
assertEquals(tableReportData.getDescription(), description);
assertEquals(id, tableReportData.getId());
assertEquals(description, tableReportData.getDescription());
}

}
Loading

0 comments on commit 4304088

Please sign in to comment.