Skip to content

Commit

Permalink
tests unitarios para dao y domain restante
Browse files Browse the repository at this point in the history
  • Loading branch information
yazmin48 committed Jan 2, 2025
1 parent 4304088 commit 6e5d702
Show file tree
Hide file tree
Showing 48 changed files with 5,216 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,17 @@ public AuditorDao(EntityManager em) {
this.em = em;
}

/**
* Gets Auditor by id.
*
* @param auditorId Auditor id.
* @return Returns the Auditor entity corresponding to the id
*/
public Auditor getAuditor(long auditorId) {
TypedQuery<Auditor> q = em.createQuery("SELECT a FROM Auditor a WHERE a.auditorId = :auditorId", Auditor.class);
q.setParameter("auditorId", auditorId);
return q.getSingleResult();
}

/**
* Gets all the auditor from the system.
*
* @return returns all the auditors present on the system.
*/
public List<Auditor> getAuditorsAll() {
TypedQuery<Auditor> q = em.createQuery("SELECT a FROM Auditor a", Auditor.class);
return q.getResultList();
}

/**
* Gets a list of Auditors related to a particular election.
*
* @param electionId Election identifier.
* @return Returns a list of auditor related to a particular election.
*/
public List<Auditor> getElectionAuditors(long electionId) {
TypedQuery<Auditor> q = em.createQuery("SELECT a FROM Auditor a WHERE a.election.electionId = :electionId", Auditor.class);
q.setParameter(ELECTION_ID, electionId);
Expand Down Expand Up @@ -74,12 +57,6 @@ public Auditor getAuditorByResultToken(String resultToken) {
return q.getSingleResult();
}

/**
* Gets a list of result tokens from the Auditors
*
*
* @return returns a list of result tokens from the Auditors
*/
public List<String> getAllAuditorsUUIDs() {
TypedQuery<String> q = em.createQuery("SELECT a.resultToken FROM Auditor a", String.class);
return q.getResultList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@

import net.lacnic.elections.domain.ElectionEmailTemplate;

import static net.lacnic.elections.utils.Constants.ELECTION_ID;
import static net.lacnic.elections.utils.Constants.TEMPLATE_TYPE;

public class ElectionEmailTemplateDao {

private static final Logger appLogger = LogManager.getLogger("ejbAppLogger");

private EntityManager em;
private static final String ELECTION_ID = "electionId";
private static final String TEMPLATE_TYPE = "templateType";

public ElectionEmailTemplateDao(EntityManager em) {
this.em = em;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import net.lacnic.elections.domain.IpAccess;


public class IpAccessDao {

private static final Logger appLogger = LogManager.getLogger("ejbAppLogger");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package net.lacnic.elections.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;

public class ReportDao {

Expand All @@ -14,9 +13,6 @@ public ReportDao(EntityManager em) {
this.em = em;
}

public ReportDao() {
}

/**
* Gets the amount of emails in the system
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
package net.lacnic.elections.domain;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Transient;

import net.lacnic.elections.utils.DateTimeUtils;
import net.lacnic.elections.utils.LinksUtils;
import net.lacnic.elections.utils.StringUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.joda.time.DateTime;

import net.lacnic.elections.utils.DateTimeUtils;
import net.lacnic.elections.utils.LinksUtils;
import net.lacnic.elections.utils.StringUtils;
import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

@Entity
public class Election implements Serializable {
Expand Down Expand Up @@ -233,14 +223,19 @@ public void initDatesStartEndDates() {
if (!getAuxEndDate().isEmpty() && !getAuxStartDate().isEmpty() && !getAuxStartHour().isEmpty() && !getAuxEndHour().isEmpty()) {
String startDatetime = getAuxStartDate() + " " + getAuxStartHour();
String endDatetime = getAuxEndDate() + " " + getAuxEndHour();
SimpleDateFormat sdf = new SimpleDateFormat(DateTimeUtils.ELECTION_DATE_TIME_FORMAT);

DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateTimeUtils.ELECTION_DATE_TIME_FORMAT);

try {
Date beforeSubtractStart = sdf.parse(startDatetime);
Date beforeSubtractEnd = sdf.parse(endDatetime);
LocalDateTime startLocalDateTime = LocalDateTime.parse(startDatetime, formatter);
LocalDateTime endLocalDateTime = LocalDateTime.parse(endDatetime, formatter);

Date beforeSubtractStart = Date.from(startLocalDateTime.atZone(ZoneId.systemDefault()).toInstant());
Date beforeSubtractEnd = Date.from(endLocalDateTime.atZone(ZoneId.systemDefault()).toInstant());

setStartDate(new DateTime(beforeSubtractStart).minusHours(getDiffUTC()).toDate());
setEndDate(new DateTime(beforeSubtractEnd).minusHours(getDiffUTC()).toDate());
} catch (ParseException e) {
} catch (Exception e) {
appLogger.error(e);
}
}
Expand All @@ -252,14 +247,18 @@ public void initDatesStartEndDates() {
public void initStringsStartEndDates() {
Date unchangedStartDate = getStartDate();
Date unchangedEndDate = getEndDate();

if (unchangedEndDate != null && unchangedStartDate != null) {
SimpleDateFormat day = new SimpleDateFormat(DateTimeUtils.ELECTION_DATE_FORMAT);
SimpleDateFormat hour = new SimpleDateFormat(DateTimeUtils.ELECTION_TIME_FORMAT);
DateTimeFormatter dayFormatter = DateTimeFormatter.ofPattern(DateTimeUtils.ELECTION_DATE_FORMAT);
DateTimeFormatter hourFormatter = DateTimeFormatter.ofPattern(DateTimeUtils.ELECTION_TIME_FORMAT);

ZonedDateTime startZonedDateTime = unchangedStartDate.toInstant().atZone(ZoneId.systemDefault()).plusHours(getDiffUTC());
ZonedDateTime endZonedDateTime = unchangedEndDate.toInstant().atZone(ZoneId.systemDefault()).plusHours(getDiffUTC());

setAuxStartDate(day.format(new DateTime(getStartDate()).plusHours(getDiffUTC()).toDate()));
setAuxStartHour(hour.format(new DateTime(getStartDate()).plusHours(getDiffUTC()).toDate()));
setAuxEndDate(day.format(new DateTime(getEndDate()).plusHours(getDiffUTC()).toDate()));
setAuxEndHour(hour.format(new DateTime(getEndDate()).plusHours(getDiffUTC()).toDate()));
setAuxStartDate(startZonedDateTime.format(dayFormatter));
setAuxStartHour(startZonedDateTime.format(hourFormatter));
setAuxEndDate(endZonedDateTime.format(dayFormatter));
setAuxEndHour(endZonedDateTime.format(hourFormatter));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package net.lacnic.elections.domain;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

import javax.persistence.Column;
Expand Down Expand Up @@ -192,22 +194,39 @@ public void copyLanguageURLs(String language) {
}

public String getStartDateString() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(SIMPLE_DATE_FORMAT);
return simpleDateFormat.format(new DateTime(getStartDate()).plusHours(getDiffUTC()).toDate()) + UTC;
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(SIMPLE_DATE_FORMAT);
LocalDateTime adjustedDateTime = new DateTime(getStartDate())
.plusHours(getDiffUTC())
.toDate()
.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
return adjustedDateTime.format(dateTimeFormatter) + UTC;
}

public String getEndDateString() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(SIMPLE_DATE_FORMAT);
return simpleDateFormat.format(new DateTime(getEndDate()).plusHours(getDiffUTC()).toDate()) + UTC;
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(SIMPLE_DATE_FORMAT);
LocalDateTime adjustedDateTime = new DateTime(getEndDate())
.plusHours(getDiffUTC())
.toDate()
.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
return adjustedDateTime.format(dateTimeFormatter) + UTC;
}

public String getClosedDateString() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(SIMPLE_DATE_FORMAT);
if (this.getClosedDate() == null) {
return "";
} else {
return simpleDateFormat.format(new DateTime(getClosedDate()).plusHours(getDiffUTC()).toDate()) + UTC;
}
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(SIMPLE_DATE_FORMAT);
LocalDateTime adjustedDateTime = new DateTime(getClosedDate())
.plusHours(getDiffUTC())
.toDate()
.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
return adjustedDateTime.format(dateTimeFormatter) + UTC;
}

public String getResultLink() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,21 +315,4 @@ public void setClosedDate(String closedDate) {
this.closedDate = closedDate;
}

@Override
public boolean equals(Object election) {
if (this == election) {
return true;
}
if (election == null || getClass() != election.getClass()) {
return false;
}
ElectionTableReport other = (ElectionTableReport) election;
return this.electionId.equals(other.electionId);
}

@Override
public int hashCode() {
return electionId.hashCode();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import java.util.Map;

/**
* This class is used to store system constants like template paths, services
* URLs, etc.
* This class is used to store system constants like template paths, services URLs, etc.
*
* @author LACNIC
*
*/
public class Constants {

private static HashMap<String, String> parameters = new HashMap<>();
private static Map<String, String> parameters = new HashMap<>();

// Parameter names for 'parameter' database table
public static final String APP = "APP";
Expand Down Expand Up @@ -62,6 +61,20 @@ public class Constants {
public static final String API_ELECTIONS = "api-Elections";
public static final String ELECTIONS_MANAGER = "elections-manager";

public static final String ELECTION_ID = "electionId";
public static final String TEMPLATE_TYPE = "templateType";
public static final String VOTE_ID = "voteId";
public static final String ORG_ID = "orgID";
public static final String USER_VOTER_ID = "userVoterId";
public static final String VOTE_AMOUNT = "voteAmount";
public static final String ACTIVITY_ID = "activityId";
public static final String CANDIDATE_ID = "candidateId";
public static final String AUDITOR_ID = "auditorId";
public static final String CANDIDATE_ORDER = "candidateOrder";
public static final String COMMISSIONER_ID = "commissionerId";
public static final String ELECTION_EMAIL_TEMPLATE_ID = "electionEmailTemplateId";
public static final String EMAIL_HISTORY_ID = "emailHistoryId";

private Constants() {
throw new IllegalStateException("Utility class");
}
Expand Down Expand Up @@ -90,7 +103,7 @@ public static Map<String, String> getParameters() {
return parameters;
}

public static void setParameters(HashMap<String, String> parameters) {
public static void setParameters(Map<String, String> parameters) {
Constants.parameters = parameters;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package net.lacnic.elections.utils;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateTimeUtils {
Expand All @@ -15,16 +17,22 @@ private DateTimeUtils() {

public static String getTableServicesDateTimeString(Date dateTime) {
if (dateTime != null) {
SimpleDateFormat dateFormat = new SimpleDateFormat(TABLE_SERVICES_DATE_TIME_FORMAT);
return dateFormat.format(dateTime);
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(TABLE_SERVICES_DATE_TIME_FORMAT);
LocalDateTime localDateTime = dateTime.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
return localDateTime.format(dateFormatter);
}
return null;
}

public static String getElectionDateTimeString(Date dateTime) {
if (dateTime != null) {
SimpleDateFormat dateFormat = new SimpleDateFormat(ELECTION_DATE_TIME_FORMAT);
return dateFormat.format(dateTime);
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(ELECTION_DATE_TIME_FORMAT);
LocalDateTime localDateTime = dateTime.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
return localDateTime.format(dateFormatter);
}
return null;
}
Expand Down
Loading

0 comments on commit 6e5d702

Please sign in to comment.