-
Notifications
You must be signed in to change notification settings - Fork 1
BI-1832 - Treatment factors not being stored in BreedBase #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2ff1b76
Store treatments in additional info and populate if missing in treatm…
nickpalladino dfd2fc0
Add tests
nickpalladino 890051e
Moved adding treatment to additional info into dao
nickpalladino 5cf2c2d
Made json processing variables final
nickpalladino e72f52b
Updated comment
nickpalladino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
144 changes: 144 additions & 0 deletions
144
src/test/java/org/breedinginsight/brapps/importer/daos/BrAPIObservationUnitDAOTest.java
This file contains hidden or 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,144 @@ | ||
| package org.breedinginsight.brapps.importer.daos; | ||
|
|
||
| import com.google.gson.Gson; | ||
| import io.kowalski.fannypack.FannyPack; | ||
| import io.micronaut.http.client.RxHttpClient; | ||
| import io.micronaut.http.client.annotation.Client; | ||
| import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
| import lombok.SneakyThrows; | ||
| import org.brapi.client.v2.JSON; | ||
| import org.brapi.v2.model.pheno.BrAPIObservationTreatment; | ||
| import org.brapi.v2.model.pheno.BrAPIObservationUnit; | ||
| import org.breedinginsight.BrAPITest; | ||
| import org.breedinginsight.api.model.v1.request.ProgramRequest; | ||
| import org.breedinginsight.api.model.v1.request.SpeciesRequest; | ||
| import org.breedinginsight.api.v1.controller.TestTokenValidator; | ||
| import org.breedinginsight.brapi.v2.constants.BrAPIAdditionalInfoFields; | ||
| import org.breedinginsight.brapps.importer.model.ImportProgress; | ||
| import org.breedinginsight.brapps.importer.model.ImportUpload; | ||
| import org.breedinginsight.dao.db.tables.pojos.SpeciesEntity; | ||
| import org.breedinginsight.daos.SpeciesDAO; | ||
| import org.breedinginsight.daos.UserDAO; | ||
| import org.breedinginsight.model.Program; | ||
| import org.breedinginsight.model.User; | ||
| import org.breedinginsight.services.ProgramService; | ||
| import org.jooq.DSLContext; | ||
| import org.junit.jupiter.api.*; | ||
|
|
||
| import javax.inject.Inject; | ||
| import java.util.List; | ||
|
|
||
| import static org.breedinginsight.TestUtils.insertAndFetchTestProgram; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| @MicronautTest | ||
| @TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
| @TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
| public class BrAPIObservationUnitDAOTest extends BrAPITest { | ||
|
|
||
| private FannyPack fp; | ||
|
|
||
| @Inject | ||
| private DSLContext dsl; | ||
|
|
||
| @Inject | ||
| private SpeciesDAO speciesDAO; | ||
|
|
||
| @Inject | ||
| private UserDAO userDAO; | ||
|
|
||
| @Inject | ||
| private BrAPIObservationUnitDAO obsUnitDAO; | ||
|
|
||
| @Inject | ||
| private ProgramService programService; | ||
|
|
||
| private Program validProgram; | ||
|
|
||
| private Gson gson; | ||
| private ImportUpload upload; | ||
|
|
||
| private BrAPIObservationTreatment testTreatment; | ||
|
|
||
| @Inject | ||
| @Client("/${micronaut.bi.api.version}") | ||
| RxHttpClient biClient; | ||
|
|
||
| @BeforeAll | ||
| @SneakyThrows | ||
| public void setup() { | ||
|
|
||
| ImportProgress progress = ImportProgress.builder().build(); | ||
|
|
||
| upload = ImportUpload.uploadBuilder() | ||
| .progress(progress) | ||
| .build(); | ||
|
|
||
| gson = new JSON().getGson(); | ||
|
|
||
| // Add species needed to create program | ||
| fp = FannyPack.fill("src/test/resources/sql/brapi/species.sql"); | ||
| super.getBrapiDsl().execute(fp.get("InsertSpecies")); | ||
| SpeciesEntity validSpecies = speciesDAO.findAll().get(0); | ||
|
|
||
| // Insert system admin role so can create program | ||
| FannyPack securityFp = FannyPack.fill("src/test/resources/sql/ProgramSecuredAnnotationRuleIntegrationTest.sql"); | ||
| User testUser = userDAO.getUserByOrcId(TestTokenValidator.TEST_USER_ORCID).get(); | ||
| dsl.execute(securityFp.get("InsertSystemRoleAdmin"), testUser.getId().toString()); | ||
|
|
||
| SpeciesRequest speciesRequest = SpeciesRequest.builder() | ||
| .commonName(validSpecies.getCommonName()) | ||
| .id(validSpecies.getId()) | ||
| .build(); | ||
|
|
||
| ProgramRequest program = ProgramRequest.builder() | ||
| .name("Test Program") | ||
| .species(speciesRequest) | ||
| .key("TEST") | ||
| .build(); | ||
|
|
||
| // create test program | ||
| validProgram = insertAndFetchTestProgram(gson, biClient, program); | ||
| // updated with brapi db id | ||
| validProgram = programService.getById(validProgram.getId()).get(); | ||
|
|
||
| testTreatment = new BrAPIObservationTreatment(); | ||
| testTreatment.setFactor("ou1 treatment"); | ||
| } | ||
|
|
||
| @Test | ||
| @SneakyThrows | ||
| @Order(1) | ||
| public void testCreateObservationUnitAdditionalInfoSingleTreatmentFactor() { | ||
| // create observation unit with treatments only in additional info to simulate breedbase not populating | ||
| // treatments field | ||
| BrAPIObservationUnit ou1 = new BrAPIObservationUnit(); | ||
| ou1.setObservationUnitName("test1"); | ||
| ou1.putAdditionalInfoItem(BrAPIAdditionalInfoFields.TREATMENTS, List.of(testTreatment)); | ||
| ou1.setProgramDbId(validProgram.getBrapiProgram().getProgramDbId()); | ||
|
|
||
| List<BrAPIObservationUnit> ous = List.of(ou1); | ||
| List<BrAPIObservationUnit> createdOus = obsUnitDAO.createBrAPIObservationUnits(ous, validProgram.getId(), upload); | ||
| singleTreatmentAsserts(createdOus, testTreatment); | ||
| } | ||
|
|
||
| @Test | ||
| @SneakyThrows | ||
| @Order(2) | ||
| public void testGetObservationUnitAdditionalInfoSingleTreatmentFactor() { | ||
| List<BrAPIObservationUnit> createdOus = obsUnitDAO.getObservationUnitByName(List.of("test1"), validProgram); | ||
| singleTreatmentAsserts(createdOus, testTreatment); | ||
| } | ||
|
|
||
| private void singleTreatmentAsserts(List<BrAPIObservationUnit> obsUnits, BrAPIObservationTreatment expectedTreatment) { | ||
| assertEquals(1, obsUnits.size(), "Expected 1 observation unit"); | ||
|
|
||
| BrAPIObservationUnit ou = obsUnits.get(0); | ||
| List<BrAPIObservationTreatment> treatments = ou.getTreatments(); | ||
| assertEquals(1, treatments.size(), "Expected treatments property"); | ||
|
|
||
| BrAPIObservationTreatment treatment = treatments.get(0); | ||
| assertEquals(expectedTreatment, treatment, "Expected treatments to be same"); | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this test be updated to set the treatments in the
Treatmentsfield rather than in theadditionalInfo?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this test I wanted to simulate what breedbase would do which would be to only have the treatments in the additionalinfo and not the treatments field.