Skip to content

Commit

Permalink
add some extra jackson id tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pahjbo committed Aug 21, 2023
1 parent 3991f6a commit ceedacd
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions src/test/java/org/ivoa/dm/proposal/prop/EmerlinExampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
import com.fasterxml.jackson.core.JsonProcessingException;

import org.ivoa.dm.proposal.management.ProposalCycle;
import org.ivoa.dm.proposal.management.ProposalManagementModel;
import org.ivoa.dm.proposal.management.TAC;

import jakarta.persistence.Query;
import jakarta.persistence.TypedQuery;


/**
Expand Down Expand Up @@ -77,7 +82,93 @@ public void testJackson() throws JsonProcessingException


}
@org.junit.jupiter.api.Test
public void testJacksonOjectIds( ) throws JsonProcessingException {

ProposalManagementModel pm = new ProposalManagementModel();
pm.addContent(ex.getCycle());
pm.processReferences();
TAC tac = pm.getContent(ProposalCycle.class).get(0).getTac();
String json = ProposalManagementModel.jsonMapper().writeValueAsString(tac);
System.out.println(json);
TAC ntac = ProposalModel.jsonMapper().readValue(json, TAC.class);

String njn = "{\n"
+ " \"members\": [\n"
+ " {\n"
+ " \"role\": \"CHAIR\",\n"
+ " \"member\": {\n"
+ " \"_id\": 1,\n"
+ " \"person\": {\n"
+ " \"_id\": 1,\n"
+ " \"fullName\": \"TAC Chair\",\n"
+ " \"eMail\": \"[email protected]\",\n"
+ " \"orcidId\": {\n"
+ " \"value\": \"https://notreallyorcid.org/0000-0001-0002-005\"\n"
+ " },\n"
+ " \"homeInstitute\": {\n"
+ " \"@type\": \"proposal:Organization\",\n"
+ " \"_id\": 1,\n"
+ " \"name\": \"org2\",\n"
+ " \"address\": \"org2 address\",\n"
+ " \"ivoid\": {\n"
+ " \"value\": \"ivo://org/org2\"\n"
+ " },\n"
+ " \"wikiId\": null\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " },\n"
+ " {\n"
+ " \"role\": \"SCIENCEREVIEWER\",\n"
+ " \"member\": {\n"
+ " \"_id\": 2,\n"
+ " \"person\": {\n"
+ " \"_id\": 2,\n"
+ " \"fullName\": \"TAC member\",\n"
+ " \"eMail\": \"[email protected]\",\n"
+ " \"orcidId\": {\n"
+ " \"value\": \"https://notreallyorcid.org/0000-0001-0002-006\"\n"
+ " },\n"
+ " \"homeInstitute\": {\n"
+ " \"@type\": \"proposal:Organization\",\n"
+ " \"_id\": 2,\n"
+ " \"name\": \"org\",\n"
+ " \"address\": \"org address\",\n"
+ " \"ivoid\": {\n"
+ " \"value\": \"ivo://org/anorg\"\n"
+ " },\n"
+ " \"wikiId\": null\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " ]\n"
+ "}\n";

TAC ntac2 = ProposalModel.jsonMapper().readValue(njn, TAC.class);

}

@org.junit.jupiter.api.Test
public void testDbQuery() throws JsonProcessingException {

jakarta.persistence.EntityManager em = setupH2Db(ProposalModel.pu_name());
em.getTransaction().begin();

final ProposalCycle cycle = ex.getCycle();
cycle.persistRefs(em);
em.persist(cycle);
em.getTransaction().commit();

TypedQuery<TAC> q = em.createQuery("SELECT o FROM TAC o", TAC.class);
TAC tac = q.getSingleResult();
System.out.println(tac.getMembers().get(0).getId());
String json = ProposalManagementModel.jsonMapper().writeValueAsString(tac);
System.out.println(json);

}


}

Expand Down

0 comments on commit ceedacd

Please sign in to comment.