Skip to content

Commit 3ec5329

Browse files
committed
major reworking of unit tests
should be easier to add new examples/tests
1 parent 7cdf586 commit 3ec5329

17 files changed

Lines changed: 301 additions & 263 deletions

build.gradle.kts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ tasks.named<Jar>("sourcesJar") {
5757
from(tasks.named("vodmlGenerateJava"))
5858
}
5959

60-
61-
62-
6360
tasks.test {
6461
useJUnitPlatform()
6562
}
@@ -111,8 +108,8 @@ tasks.register<Exec>("doSite"){
111108
tasks.withType<Jar> { duplicatesStrategy = DuplicatesStrategy.INCLUDE } //IMPL bugfix - see https://stackoverflow.com/questions/67265308/gradle-entry-classpath-is-a-duplicate-but-no-duplicate-handling-strategy-has-b
112109

113110
dependencies {
114-
api("org.javastro.ivoa.vo-dml:ivoa-base:1.1.5-SNAPSHOT")
115-
api("org.javastro.ivoa.dm:coordinateDM:1.1.5-SNAPSHOT")
111+
api("net.ivoa.vo-dml:ivoa-base:1.1-SNAPSHOT")
112+
api("net.ivoa.dm:coordinateDM:1.1-SNAPSHOT")
116113
// implementation("org.javastro:ivoa-entities:0.9.3-SNAPSHOT")
117114

118115
// annotationProcessor ("org.hibernate.orm:hibernate-processor:7.0.8.Final")

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencyResolutionManagement {
1717
will not be necessary when this library is released as a non-SNAPSHOT version.
1818
*/
1919
maven {
20-
url= uri("https://central.sonatype.com/repository/maven-snapshots/")
20+
url= uri("https://repo.dev.uksrc.org/repository/maven-snapshots/")
2121
}
2222
}
2323
}

src/test/java/org/ivoa/dm/proposal/prop/AbstractProposalTest.java

Lines changed: 163 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
package org.ivoa.dm.proposal.prop;
1111

12+
import static org.ivoa.dm.proposal.prop.BaseExample.makeList;
1213
import static org.junit.jupiter.api.Assertions.*;
1314

1415
import java.util.List;
@@ -24,9 +25,7 @@
2425
import com.fasterxml.jackson.core.JsonProcessingException;
2526
import com.fasterxml.jackson.databind.ObjectMapper;
2627

27-
import org.ivoa.dm.proposal.management.ProposalCycle;
28-
import org.ivoa.dm.proposal.management.ProposalManagementModel;
29-
import org.ivoa.dm.proposal.management.SubmittedProposal;
28+
import org.ivoa.dm.proposal.management.*;
3029
import org.ivoa.dm.stc.coords.SpaceSys;
3130
import org.ivoa.vodml.ModelDescription;
3231
import org.junit.jupiter.api.*;
@@ -45,15 +44,16 @@ public abstract class AbstractProposalTest extends org.ivoa.vodml.testing.Abstra
4544
.getLogger(AbstractProposalTest.class);
4645

4746
protected ExampleGenerator ex;
48-
protected exampleFactory ef;
47+
protected ExampleFactory ef;
4948
protected EntityManager em;
5049
protected Long proposalId;
5150
protected ObservingProposal proposal;
52-
protected ModelDescription modelDescription;
51+
private final ModelDescription modelDescription;
5352
protected Long cycleId;
5453
protected ProposalCycle cycle;
54+
protected ProposalManagementModel model;
5555

56-
@BeforeAll
56+
@BeforeAll
5757
public void beforeAll() {
5858
em = setupH2Db(ProposalModel.pu_name(),modelDescription.allClassNames());
5959
}
@@ -88,25 +88,50 @@ protected void retrieveCycle() {
8888
}
8989

9090

91-
public interface exampleFactory {
91+
92+
public interface ExampleFactory {
9293
ExampleGenerator create();
9394
}
9495

95-
public AbstractProposalTest(ModelDescription md,exampleFactory ef) {
96-
this.modelDescription = md;
96+
public AbstractProposalTest(ExampleFactory ef) {
9797
this.ef= ef;
98+
model = new ProposalManagementModel();
99+
this.modelDescription = model.management().description();
100+
98101
}
99102

100-
protected abstract void doUrTest();
103+
101104

102105

103106
@Test
104107
@Order(1)
105108
void UrTest() { // this test has to be done first to make sure that the basic database save has been done
106-
doUrTest();
109+
ex = ef.create();
110+
111+
em.getTransaction().begin();
112+
proposal = ex.getProposal();
113+
cycle = ex.getCycle();
114+
model.addContent(proposal);
115+
model.addContent(cycle);
116+
model.management().persistRefs(em);
117+
em.persist(proposal);
118+
em.persist(cycle);
119+
em.getTransaction().commit();
120+
proposalId = proposal.getId();
121+
cycleId = cycle.getId();
122+
123+
107124
}
108125

109126

127+
/**
128+
* This test just tests basic XML serialization of a proposal as standalone
129+
* @throws JAXBException
130+
* @throws TransformerConfigurationException
131+
* @throws ParserConfigurationException
132+
* @throws TransformerFactoryConfigurationError
133+
* @throws TransformerException
134+
*/
110135
@org.junit.jupiter.api.Test
111136
@Order(1000)
112137
void proposalDmJaxbTest() throws JAXBException, TransformerConfigurationException,
@@ -115,7 +140,7 @@ void proposalDmJaxbTest() throws JAXBException, TransformerConfigurationExceptio
115140
logger.debug("starting test");
116141

117142
ProposalModel model = new ProposalModel();
118-
model.addContent(proposal);
143+
model.addContent(ex.getProposal());
119144
model.processReferences();
120145
validateModel(model);
121146

@@ -125,6 +150,21 @@ void proposalDmJaxbTest() throws JAXBException, TransformerConfigurationExceptio
125150

126151
}
127152

153+
/**
154+
* This tests basic JSON serialization of the proposal as standalone
155+
* @throws JsonProcessingException
156+
*/
157+
@org.junit.jupiter.api.Test
158+
@Order(1000)
159+
void proposalDmJSONTest() throws JsonProcessingException {
160+
ProposalModel model = new ProposalModel();
161+
model.addContent(ex.getProposal());
162+
model.processReferences();
163+
ProposalModel modelin = modelRoundTripJSONwithTest(model);
164+
List<ObservingProposal> props = modelin.getContent(ObservingProposal.class);
165+
assertEquals(1, props.size());
166+
}
167+
128168
@org.junit.jupiter.api.Test
129169
@Order(1010)
130170
void proposalDmJPATest() {
@@ -139,16 +179,7 @@ void proposalDmJPATest() {
139179

140180

141181

142-
@org.junit.jupiter.api.Test
143-
@Order(1010)
144-
void proposalDmJSONTest() throws JsonProcessingException {
145-
ProposalModel model = new ProposalModel();
146-
model.addContent(ex.getProposal());
147-
model.processReferences();
148-
ProposalModel modelin = modelRoundTripJSONwithTest(model);
149-
List<ObservingProposal> props = modelin.getContent(ObservingProposal.class);
150-
assertEquals(1, props.size());
151-
}
182+
152183

153184
@org.junit.jupiter.api.Test
154185
@Order(1010)
@@ -169,55 +200,126 @@ public void testObservations() {
169200
assertEquals( 1, proposal.observations.size(), "number of observations");
170201
Observation obs = proposal.observations.get(0);
171202
assertNotNull(obs.target);
172-
assertTrue(obs.target.get(0) instanceof CelestialTarget);
203+
assertInstanceOf(CelestialTarget.class, obs.target.get(0));
173204
CelestialTarget target = (CelestialTarget)obs.target.get(0);
174-
SpaceSys cosys = (SpaceSys) target.sourceCoordinates.getCoordSys();
205+
SpaceSys cosys = target.sourceCoordinates.getCoordSys();
175206
assertNotNull(cosys);
176207

177208

178209
}
179-
@org.junit.jupiter.api.Test
180-
@Order(1020)
181-
public void testDeleteTarget() {
182210

183-
Observation obs = proposal.observations.get(0);
184-
assertNotNull(obs.target);
185-
em.getTransaction().begin();
186-
em.remove(obs.target.get(0)); // TODO perhaps really want to investigate list member deletion more...
187-
em.getTransaction().commit();
188-
189-
211+
212+
213+
@Test
214+
@Order(1110)
215+
public void testTACQuery() throws JsonProcessingException {
216+
TypedQuery<TAC> q = em.createQuery("SELECT o FROM TAC o", TAC.class);
217+
TAC tac = q.getSingleResult();
218+
System.out.println(tac.getMembers().get(0).getId());
219+
String json = ProposalManagementModel.jsonMapper().writeValueAsString(tac);
220+
System.out.println(json);
221+
190222
}
191-
@org.junit.jupiter.api.Test
192-
@Order(1020)
193-
public void testObservationTarget() {
194-
195-
//copy obs
196-
em.getTransaction().begin();
197-
TypedQuery<ObservingProposal> q = em.createQuery("SELECT o FROM ObservingProposal o", ObservingProposal.class);
198-
List<ObservingProposal> res = q.getResultList();
199-
ObservingProposal prop = res.get(0);
200-
prop.forceLoad();
201-
Observation obs = prop.observations.get(0);
202-
Observation obs2 = obs.copyMe();
203-
em.persist(obs2);
204-
prop.addToObservations(obs2);
205-
em.merge(prop);
206-
em.getTransaction().commit();
207-
//delete target
208-
em.getTransaction().begin();
209-
assertNotNull(obs.target);
210-
211-
em.remove(obs.target.get(0)); // TODO perhaps really want to investigate list member deletion more...
212-
em.getTransaction().commit();
213-
214-
223+
224+
@Test
225+
@Order(1120)
226+
void doTOCworkTest() throws JAXBException,
227+
ParserConfigurationException,
228+
TransformerFactoryConfigurationError, TransformerException, JsonProcessingException {
229+
logger.debug("starting test");
230+
model.createContext();
231+
SubmittedProposal submittedProposal = ex.submitProposal(proposal, cycle);
232+
cycle.setSubmittedProposals(
233+
makeList(submittedProposal));
234+
235+
AllocatedProposal allocatedProposal = ex.allocateProposal(submittedProposal);
236+
cycle.setAllocatedProposals(makeList(
237+
allocatedProposal
238+
));
239+
cycle.updateClonedReferences();
240+
//save out the work
241+
em.getTransaction().begin();
242+
em.persist(submittedProposal);
243+
em.persist(allocatedProposal);
244+
em.getTransaction().commit();
245+
246+
doSerialization(model);
247+
215248
}
216249

217-
public static ObservingProposal cloneProposal(ObservingProposal p)
250+
public void doSerialization(ProposalManagementModel thisModel) throws JsonProcessingException, JAXBException, ParserConfigurationException, TransformerException {
251+
validateModel(thisModel);
252+
ProposalManagementModel modelin = modelRoundTripXMLwithTest(thisModel);
253+
List<ProposalCycle> revs = modelin.getContent(ProposalCycle.class);
254+
assertEquals(1, revs.size());
255+
256+
ProposalManagementModel modelinj = modelRoundTripJSONwithTest(thisModel);
257+
List<ProposalCycle> revsj = modelinj.getContent(ProposalCycle.class);
258+
assertEquals(1, revsj.size());
259+
260+
}
261+
262+
@org.junit.jupiter.api.Test
263+
@Order(1210)
264+
public void retrieveTest() throws JAXBException, ParserConfigurationException, JsonProcessingException, TransformerException {
265+
//flush any existing entities
266+
em.clear();
267+
em.getEntityManagerFactory().getCache().evictAll();
268+
retrieveProposal();
269+
retrieveCycle();
270+
ProposalManagementModel thismodel = new ProposalManagementModel();
271+
thismodel.addContent(proposal);
272+
thismodel.addContent(cycle);
273+
assertEquals(1, cycle.getSubmittedProposals().size());
274+
assertEquals(1, cycle.getAllocatedProposals().size());
275+
doSerialization(thismodel);
276+
}
277+
278+
279+
280+
@org.junit.jupiter.api.Test
281+
@Order(1220)
282+
public void testDeleteTarget() {
283+
284+
Observation obs = proposal.observations.get(0);
285+
assertNotNull(obs.target);
286+
em.getTransaction().begin();
287+
em.remove(obs.target.get(0)); // TODO perhaps really want to investigate list member deletion more...
288+
em.getTransaction().commit();
289+
290+
291+
}
292+
293+
@org.junit.jupiter.api.Test
294+
@Order(2110)
295+
public void testObservationTarget() {
296+
297+
//copy obs
298+
em.getTransaction().begin();
299+
TypedQuery<ObservingProposal> q = em.createQuery("SELECT o FROM ObservingProposal o", ObservingProposal.class);
300+
List<ObservingProposal> res = q.getResultList();
301+
ObservingProposal prop = res.get(0);
302+
prop.forceLoad();
303+
Observation obs = prop.observations.get(0);
304+
Observation obs2 = obs.copyMe();
305+
em.persist(obs2);
306+
prop.addToObservations(obs2);
307+
em.merge(prop);
308+
em.getTransaction().commit();
309+
//delete target
310+
em.getTransaction().begin();
311+
assertNotNull(obs.target);
312+
313+
em.remove(obs.target.get(0)); // TODO perhaps really want to investigate list member deletion more...
314+
em.getTransaction().commit();
315+
316+
317+
}
318+
319+
public static ObservingProposal cloneProposal(ProposalManagementModel themodel, ObservingProposal p)
218320
{
219-
ProposalModel pm = new ProposalModel();
220-
pm.createContext();//FIXME this is an area where the API for https://github.com/ivoa/vo-dml/issues/42 is not great
321+
322+
themodel.createContext();//FIXME this is an area where the API for https://github.com/ivoa/vo-dml/issues/42 is not great
221323
final ObservingProposal frozenProposal = new ObservingProposal(p); // make a copy of the proposal to put into the submitted proposal
222324
frozenProposal.updateClonedReferences();
223325
return frozenProposal;

src/test/java/org/ivoa/dm/proposal/prop/BaseExample.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ public abstract class BaseExample {
2828
/** SPACE_SYS.
2929
*/
3030
//IMPL - removed the CartesianCoordSpace from the definitions below because you have to include the axis definitions which is a pain....
31-
protected static final SpaceSys GEO_SYS = new SpaceSys().withFrame(new SpaceFrame(new StdRefLocation("TOPOCENTER"), "ICRS", null, ""));//FIXME - this should really define the frame better - STC coords library should have some standard model instances...
31+
protected static final SpaceSys GEO_SYS = new SpaceSys().withFrame(new SpaceFrame(new StdRefLocation("TOPOCENTER"), "BODY", null, ""));//FIXME - this should really define the frame better - STC coords library should have some standard model instances...
32+
//FIXME 2. the spaceRefFrame should be something like ECEF but http://www.ivoa.net/rdf/refframe does not have that.
3233

33-
protected static final SpaceSys ICRS_SYS = new SpaceSys().withFrame(new SpaceFrame(new StdRefLocation("TOPOCENTER"), "ICRS", null, ""));//FIXME - this should really define the frame better - STC coords library should have some standard model instances...
34+
protected static final SpaceSys ICRS_SYS = new SpaceSys().withFrame(new SpaceFrame(new StdRefLocation("BARYCENTER"), "ICRS", null, ""));//FIXME - this should really define the frame better - STC coords library should have some standard model instances...
3435
protected static final Organization[] institutes = {
3536
new Organization("org", "org address",new Ivoid("ivo://org/anorg"), null),//TODO is null same as not setting?
3637
new Organization("org2", "org2 address",new Ivoid("ivo://org/org2"), null)
@@ -51,7 +52,7 @@ public abstract class BaseExample {
5152

5253
protected Reviewer[] reviewers = {new Reviewer(people[2]),
5354
new Reviewer(people[3]),
54-
new Reviewer(people[4])// reviewer not on TAC
55+
new Reviewer(people[4])// reviewer not on TAC (note that in the current code they would need to be added to references explicitly)
5556
};
5657

5758
protected TAC tac = new TAC( makeList(

0 commit comments

Comments
 (0)