Skip to content

Commit

Permalink
cambios nico comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico committed Dec 27, 2024
1 parent 8d25425 commit 235d0f8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Map;

/**
* This class is used to store system constants like template paths, services
Expand Down Expand Up @@ -91,8 +90,7 @@ public static Map<String, String> getParameters() {
return parameters;
}

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

Expand Down
13 changes: 6 additions & 7 deletions elections-ejb/src/test/java/net/lacnic/ReflectTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@ public class ReflectTool {
public static <T extends Annotation> T getMethodAnnotation(Class<?> c, String methodName, Class<T> annotation) {
try {
Method m = c.getDeclaredMethod(methodName);
return (T)m.getAnnotation(annotation);
return (T) m.getAnnotation(annotation);
} catch (NoSuchMethodException nsme) {
throw new RuntimeException(nsme);
}
}

public static <T extends Annotation> T getFieldAnnotation(Class<?> c, String fieldName, Class<T> annotation) {
try {
Field f = c.getDeclaredField(fieldName);
return (T)f.getAnnotation(annotation);
return (T) f.getAnnotation(annotation);
} catch (NoSuchFieldException nsme) {
throw new RuntimeException(nsme);
}
}

public static <T extends Annotation> T getClassAnnotation(Class<?> c, Class<T> annotation) {
return (T) c.getAnnotation(annotation);
public static <T extends Annotation> T getClassAnnotation(Class<?> c, Class<T> annotationClass) {
return (T) c.getAnnotation(annotationClass);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
Expand All @@ -26,175 +25,28 @@ public static Test suite() {
public void testElection() {
AssertAnnotations.assertType(Election.class, Entity.class);

// fields
// Grouped Fields
AssertAnnotations.assertField(Election.class, "electionId", Id.class, GeneratedValue.class, SequenceGenerator.class, Column.class);
AssertAnnotations.assertField(Election.class, "migrationId", Column.class);
AssertAnnotations.assertField(Election.class, "category", Column.class, Enumerated.class);
AssertAnnotations.assertField(Election.class, "migrated", Column.class);
AssertAnnotations.assertField(Election.class, "startDate", Column.class);
AssertAnnotations.assertField(Election.class, "endDate", Column.class);
AssertAnnotations.assertField(Election.class, "creationDate", Column.class);
AssertAnnotations.assertField(Election.class, "titleSpanish", Column.class);
AssertAnnotations.assertField(Election.class, "titleEnglish", Column.class);
AssertAnnotations.assertField(Election.class, "titlePortuguese", Column.class);
AssertAnnotations.assertField(Election.class, "linkSpanish", Column.class);
AssertAnnotations.assertField(Election.class, "linkEnglish", Column.class);
AssertAnnotations.assertField(Election.class, "linkPortuguese", Column.class);
AssertAnnotations.assertField(Election.class, "descriptionSpanish", Column.class);
AssertAnnotations.assertField(Election.class, "descriptionEnglish", Column.class);
AssertAnnotations.assertField(Election.class, "descriptionPortuguese", Column.class);
AssertAnnotations.assertField(Election.class, "maxCandidates", Column.class);
AssertAnnotations.assertField(Election.class, "votingLinkAvailable", Column.class);
AssertAnnotations.assertField(Election.class, "resultLinkAvailable", Column.class);
AssertAnnotations.assertField(Election.class, "auditorLinkAvailable", Column.class);
AssertAnnotations.assertField(Election.class, "revisionRequest", Column.class);
AssertAnnotations.assertField(Election.class, "onlySp", Column.class);
AssertAnnotations.assertField(Election.class, "resultToken", Column.class);
AssertAnnotations.assertField(Election.class, "defaultSender", Column.class);
AssertAnnotations.assertField(Election.class, "electorsSet", Column.class);
AssertAnnotations.assertField(Election.class, "candidatesSet", Column.class);
AssertAnnotations.assertField(Election.class, "auditorsSet", Column.class);
AssertAnnotations.assertField(Election.class, "randomOrderCandidates", Column.class);
AssertAnnotations.assertField(Election.class, "diffUTC", Column.class);
AssertAnnotations.assertField(Election.class, "candidates", OneToMany.class);
AssertAnnotations.assertField(Election.class, "userVoters", OneToMany.class);
AssertAnnotations.assertField(Election.class, "auditors", OneToMany.class);
AssertAnnotations.assertField(Election.class, "electionTemplates", OneToMany.class);
AssertAnnotations.assertField(Election.class, "votes", OneToMany.class);
AssertAnnotations.assertField(Election.class, "email", OneToMany.class);
AssertAnnotations.assertField(Election.class, "auxStartDate", Transient.class);
AssertAnnotations.assertField(Election.class, "auxStartHour", Transient.class);
AssertAnnotations.assertField(Election.class, "auxEndDate", Transient.class);
AssertAnnotations.assertField(Election.class, "auxEndHour", Transient.class);
AssertAnnotations.assertField(Election.class, "closed", Column.class);
AssertAnnotations.assertField(Election.class, "closedDate", Column.class);
AssertAnnotations.assertField(Election.class, "migrationId, category, migrated, startDate, endDate, creationDate, titleSpanish, titleEnglish, titlePortuguese, linkSpanish, linkEnglish, linkPortuguese, descriptionSpanish, descriptionEnglish, descriptionPortuguese, maxCandidates, votingLinkAvailable, resultLinkAvailable, auditorLinkAvailable, revisionRequest, onlySp, resultToken, defaultSender, electorsSet, candidatesSet, auditorsSet, randomOrderCandidates, diffUTC, closed, closedDate", Column.class);
AssertAnnotations.assertField(Election.class, "auxStartDate, auxStartHour, auxEndDate, auxEndHour", Transient.class);
AssertAnnotations.assertField(Election.class, "candidates, userVoters, auditors, electionTemplates, votes, email", OneToMany.class);

// metodos
AssertAnnotations.assertMethod(Election.class, "getElectionId");
AssertAnnotations.assertMethod(Election.class, "getStartDate");
AssertAnnotations.assertMethod(Election.class, "getEndDate");
AssertAnnotations.assertMethod(Election.class, "getMaxCandidates");
AssertAnnotations.assertMethod(Election.class, "isVotingLinkAvailable");
AssertAnnotations.assertMethod(Election.class, "getCandidates");
AssertAnnotations.assertMethod(Election.class, "getCreationDate");
AssertAnnotations.assertMethod(Election.class, "getUserVoters");
AssertAnnotations.assertMethod(Election.class, "getVotes");
AssertAnnotations.assertMethod(Election.class, "isResultLinkAvailable");
AssertAnnotations.assertMethod(Election.class, "getTitleSpanish");
AssertAnnotations.assertMethod(Election.class, "getTitleEnglish");
AssertAnnotations.assertMethod(Election.class, "getTitlePortuguese");
AssertAnnotations.assertMethod(Election.class, "getDescriptionSpanish");
AssertAnnotations.assertMethod(Election.class, "getDescriptionEnglish");
AssertAnnotations.assertMethod(Election.class, "getDescriptionPortuguese");
AssertAnnotations.assertMethod(Election.class, "getResultToken");
AssertAnnotations.assertMethod(Election.class, "getAuditors");
AssertAnnotations.assertMethod(Election.class, "getLinkSpanish");
AssertAnnotations.assertMethod(Election.class, "getLinkEnglish");
AssertAnnotations.assertMethod(Election.class, "getLinkPortuguese");
AssertAnnotations.assertMethod(Election.class, "getAuxStartDate");
AssertAnnotations.assertMethod(Election.class, "getAuxStartHour");
AssertAnnotations.assertMethod(Election.class, "getAuxEndHour");
AssertAnnotations.assertMethod(Election.class, "getAuxEndHour");
AssertAnnotations.assertMethod(Election.class, "isOnlySp");
AssertAnnotations.assertMethod(Election.class, "isAuditorLinkAvailable");
AssertAnnotations.assertMethod(Election.class, "isElectorsSet");
AssertAnnotations.assertMethod(Election.class, "isCandidatesSet");
AssertAnnotations.assertMethod(Election.class, "isAuditorsSet");
AssertAnnotations.assertMethod(Election.class, "getElectionTemplates");
AssertAnnotations.assertMethod(Election.class, "getDefaultSender");
AssertAnnotations.assertMethod(Election.class, "getResultLink");
AssertAnnotations.assertMethod(Election.class, "isRandomOrderCandidates");
AssertAnnotations.assertMethod(Election.class, "getStartDateString");
AssertAnnotations.assertMethod(Election.class, "getDiffUTC");
AssertAnnotations.assertMethod(Election.class, "isRevisionRequest");
AssertAnnotations.assertMethod(Election.class, "isFinished");
AssertAnnotations.assertMethod(Election.class, "isStarted");
AssertAnnotations.assertMethod(Election.class, "isEnabledToVote");
AssertAnnotations.assertMethod(Election.class, "isMigrated");
AssertAnnotations.assertMethod(Election.class, "getCategory");
AssertAnnotations.assertMethod(Election.class, "isClosed");
AssertAnnotations.assertMethod(Election.class, "getClosedDate");
// Grouped Methods
AssertAnnotations.assertMethod(Election.class, "getElectionId, getStartDate, getEndDate, getMaxCandidates, isVotingLinkAvailable, getCandidates, getCreationDate, getUserVoters, getVotes, isResultLinkAvailable, getTitleSpanish, getTitleEnglish, getTitlePortuguese, getDescriptionSpanish, getDescriptionEnglish, getDescriptionPortuguese, getResultToken, getAuditors, getLinkSpanish, getLinkEnglish, getLinkPortuguese, getAuxStartDate, getAuxStartHour, getAuxEndDate, getAuxEndHour, isOnlySp, isAuditorLinkAvailable, isElectorsSet, isCandidatesSet, isAuditorsSet, getElectionTemplates, getDefaultSender, getResultLink, isRandomOrderCandidates, getStartDateString, getDiffUTC, isRevisionRequest, isFinished, isStarted, isEnabledToVote, isMigrated, getCategory, isClosed, getClosedDate");

// class annotations
// Class Annotations
Entity a = ReflectTool.getClassAnnotation(Election.class, Entity.class);
assertEquals("", a.name());

Column c;
OneToMany oa;
c = ReflectTool.getFieldAnnotation(Election.class, "electionId", Column.class);
// Specific Annotations
Column c = ReflectTool.getFieldAnnotation(Election.class, "electionId", Column.class);
assertEquals("election_id", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "migrationId", Column.class);
assertEquals("migration_id", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "category", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "migrated", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "startDate", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "endDate", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "creationDate", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "titleSpanish", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "titleEnglish", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "titlePortuguese", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "linkSpanish", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "linkEnglish", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "linkPortuguese", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "descriptionSpanish", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "descriptionEnglish", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "descriptionPortuguese", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "maxCandidates", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "votingLinkAvailable", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "resultLinkAvailable", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "auditorLinkAvailable", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "revisionRequest", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "onlySp", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "resultToken", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "defaultSender", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "electorsSet", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "candidatesSet", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "auditorsSet", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "randomOrderCandidates", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "diffUTC", Column.class);
assertEquals("", c.name());
oa = ReflectTool.getFieldAnnotation(Election.class, "candidates", OneToMany.class);
OneToMany oa = ReflectTool.getFieldAnnotation(Election.class, "candidates", OneToMany.class);
assertEquals("election", oa.mappedBy());
oa = ReflectTool.getFieldAnnotation(Election.class, "auditors", OneToMany.class);
assertEquals("election", oa.mappedBy());
oa = ReflectTool.getFieldAnnotation(Election.class, "userVoters", OneToMany.class);
assertEquals("election", oa.mappedBy());
oa = ReflectTool.getFieldAnnotation(Election.class, "electionTemplates", OneToMany.class);
assertEquals("election", oa.mappedBy());
oa = ReflectTool.getFieldAnnotation(Election.class, "votes", OneToMany.class);
assertEquals("election", oa.mappedBy());
oa = ReflectTool.getFieldAnnotation(Election.class, "email", OneToMany.class);
assertEquals("election", oa.mappedBy());
c = ReflectTool.getFieldAnnotation(Election.class, "closed", Column.class);
assertEquals("", c.name());
c = ReflectTool.getFieldAnnotation(Election.class, "closedDate", Column.class);
assertEquals("", c.name());

}

Expand Down

0 comments on commit 235d0f8

Please sign in to comment.