-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a FullExample which will be a container for all the examples
- Loading branch information
Showing
5 changed files
with
213 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Created on 22 Oct 2024 | ||
* Copyright 2024 Paul Harrison ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License in file LICENSE | ||
*/ | ||
|
||
package org.ivoa.dm.proposal.prop; | ||
|
||
import org.ivoa.dm.proposal.management.ProposalCycle; | ||
import org.ivoa.dm.proposal.management.ProposalManagementModel; | ||
import org.ivoa.dm.proposal.management.SubmittedProposal; | ||
|
||
import jakarta.persistence.EntityManager; | ||
|
||
/** | ||
* Complete example with all example observatories . | ||
* @author Paul Harrison ([email protected]) | ||
* @since 22 Oct 2024 | ||
*/ | ||
public class FullExample { | ||
|
||
|
||
private ObservingProposal proposal; | ||
private ProposalCycle cycle; | ||
private ProposalManagementModel model = new ProposalManagementModel(); | ||
|
||
/** | ||
* create full example. | ||
*/ | ||
public FullExample() { | ||
EmerlinExample emerlin = new EmerlinExample(); | ||
proposal = new ExampleProposal().getProposal(); | ||
cycle = emerlin.getCycle(); | ||
ObservingProposal clonedProposal = AbstractProposalTest.cloneProposal(proposal); | ||
clonedProposal.setSubmitted(true); | ||
SubmittedProposal submittedProposal = emerlin.submitProposal(clonedProposal); | ||
emerlin.allocateProposal(submittedProposal); | ||
|
||
} | ||
|
||
/** | ||
* Save to an RDB. | ||
* @param em the entity manager for the RDB. | ||
*/ | ||
public void saveTodB(EntityManager em) { | ||
|
||
|
||
cycle.persistRefs(em); | ||
em.persist(cycle); | ||
proposal.persistRefs(em); | ||
em.persist(proposal); | ||
|
||
|
||
|
||
} | ||
|
||
/** | ||
* get the management model. | ||
* @return the model. | ||
*/ | ||
public ProposalManagementModel getManagementModel() { | ||
model.addContent(cycle); | ||
return model; | ||
} | ||
|
||
|
||
/** | ||
* get the proposal model. | ||
* @return the model. | ||
*/ | ||
public ProposalModel getProposalModel() { | ||
ProposalModel pmodel = new ProposalModel(); | ||
pmodel.addContent(proposal); | ||
return pmodel; | ||
} | ||
|
||
} | ||
|
||
|
105 changes: 105 additions & 0 deletions
105
src/test/java/org/ivoa/dm/proposal/prop/FullExampleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Created on 22 Oct 2024 | ||
* Copyright 2024 Paul Harrison ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License in file LICENSE | ||
*/ | ||
|
||
package org.ivoa.dm.proposal.prop; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.ivoa.dm.proposal.management.ProposalCycle; | ||
import org.ivoa.dm.proposal.management.ProposalManagementModel; | ||
import org.ivoa.vodml.testing.AutoDBRoundTripTest; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Test the FullExample . | ||
* @author Paul Harrison ([email protected]) | ||
*/ | ||
class FullExampleTest extends AutoDBRoundTripTest<ProposalManagementModel, Long,ProposalCycle> { | ||
|
||
/** | ||
* @throws java.lang.Exception | ||
*/ | ||
@BeforeAll | ||
static void setUpBeforeClass() throws Exception { | ||
|
||
} | ||
|
||
private FullExample example; | ||
|
||
/** | ||
* @throws java.lang.Exception | ||
*/ | ||
@BeforeEach | ||
void setUp() throws Exception { | ||
|
||
example = new FullExample(); | ||
} | ||
|
||
/** | ||
* @throws java.lang.Exception | ||
*/ | ||
@AfterEach | ||
void tearDown() throws Exception { | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* overrides @see org.ivoa.vodml.testing.AutoDBRoundTripTest#entityForDb() | ||
*/ | ||
@Override | ||
public ProposalCycle entityForDb() { | ||
return example.getManagementModel().getContent(ProposalCycle.class).get(0); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* overrides @see org.ivoa.vodml.testing.AutoDBRoundTripTest#testEntity(org.ivoa.vodml.jpa.JPAManipulationsForObjectType) | ||
*/ | ||
@Override | ||
public void testEntity(ProposalCycle e) { | ||
//TODO some testing | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* overrides @see org.ivoa.vodml.testing.AutoRoundTripTest#createModel() | ||
*/ | ||
@Override | ||
public ProposalManagementModel createModel() { | ||
return example.getManagementModel(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* overrides @see org.ivoa.vodml.testing.AutoRoundTripTest#testModel(org.ivoa.vodml.VodmlModel) | ||
*/ | ||
@Override | ||
public void testModel(ProposalManagementModel m) { | ||
//TODO some testing | ||
} | ||
|
||
|
||
/** | ||
* test the full DB save - note the transaction needs to be around the | ||
*/ | ||
@Test | ||
public void testDBSave() { | ||
jakarta.persistence.EntityManager em = setupH2Db(example.getManagementModel().management().pu_name()); | ||
|
||
em.getTransaction().begin(); | ||
example.saveTodB(em); | ||
em.getTransaction().commit(); | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters