-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avniproject/integration-service#96 - lastModified is not mandatory
- Loading branch information
1 parent
fe98a3c
commit fb31d5c
Showing
6 changed files
with
152 additions
and
29 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
43 changes: 43 additions & 0 deletions
43
avni-server-api/src/main/java/org/avni/server/dao/IndividualSearchParams.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,43 @@ | ||
package org.avni.server.dao; | ||
|
||
import org.avni.server.domain.Concept; | ||
import org.joda.time.DateTime; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class IndividualSearchParams { | ||
private final DateTime lastModifiedDateTime; | ||
private final DateTime now; | ||
private final String subjectTypeName; | ||
private final Map<Concept, String> observations; | ||
private final List<Long> allLocationIds; | ||
|
||
public IndividualSearchParams(DateTime lastModifiedDateTime, DateTime now, String subjectTypeName, Map<Concept, String> observations, List<Long> allLocationIds) { | ||
this.lastModifiedDateTime = lastModifiedDateTime; | ||
this.now = now; | ||
this.subjectTypeName = subjectTypeName; | ||
this.observations = observations; | ||
this.allLocationIds = allLocationIds; | ||
} | ||
|
||
public DateTime getLastModifiedDateTime() { | ||
return lastModifiedDateTime; | ||
} | ||
|
||
public DateTime getNow() { | ||
return now; | ||
} | ||
|
||
public String getSubjectTypeName() { | ||
return subjectTypeName; | ||
} | ||
|
||
public Map<Concept, String> getObservations() { | ||
return observations; | ||
} | ||
|
||
public List<Long> getAllLocationIds() { | ||
return allLocationIds; | ||
} | ||
} |
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
87 changes: 87 additions & 0 deletions
87
...server-api/src/test/java/org/avni/server/web/api/SubjectApiControllerIntegrationTest.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,87 @@ | ||
package org.avni.server.web.api; | ||
|
||
import org.avni.server.common.AbstractControllerIntegrationTest; | ||
import org.avni.server.domain.Concept; | ||
import org.avni.server.domain.Individual; | ||
import org.avni.server.domain.ObservationCollection; | ||
import org.avni.server.domain.SubjectType; | ||
import org.avni.server.domain.factory.txData.ObservationCollectionBuilder; | ||
import org.avni.server.domain.factory.txn.SubjectBuilder; | ||
import org.avni.server.domain.metadata.SubjectTypeBuilder; | ||
import org.avni.server.service.builder.*; | ||
import org.avni.server.web.response.ResponsePage; | ||
import org.joda.time.DateTime; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.test.context.jdbc.Sql; | ||
|
||
import java.util.Collections; | ||
|
||
import static junit.framework.TestCase.assertEquals; | ||
|
||
@Sql(value = {"/tear-down.sql"}, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) | ||
@Sql(value = {"/tear-down.sql"}, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) | ||
public class SubjectApiControllerIntegrationTest extends AbstractControllerIntegrationTest { | ||
@Autowired | ||
private TestDataSetupService testDataSetupService; | ||
@Autowired | ||
private TestSubjectTypeService testSubjectTypeService; | ||
@Autowired | ||
private TestConceptService testConceptService; | ||
@Autowired | ||
private TestGroupService testGroupService; | ||
@Autowired | ||
private TestSubjectService testSubjectService; | ||
@Autowired | ||
private SubjectApiController subjectApiController; | ||
private SubjectType subjectType; | ||
private TestDataSetupService.TestCatchmentData catchmentData; | ||
private Concept concept; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
TestDataSetupService.TestOrganisationData organisationData = testDataSetupService.setupOrganisation(); | ||
catchmentData = testDataSetupService.setupACatchment(); | ||
subjectType = testSubjectTypeService.createWithDefaults( | ||
new SubjectTypeBuilder() | ||
.setMandatoryFieldsForNewEntity() | ||
.setUuid("subjectType1") | ||
.setName("subjectType1") | ||
.build()); | ||
concept = testConceptService.createCodedConcept("Concept Name 1", "Answer 1", "Answer 2"); | ||
ObservationCollection observationCollection = new ObservationCollectionBuilder() | ||
.addObservation(concept, concept.getAnswerConcept("Answer 1")) | ||
.build(); | ||
testGroupService.giveViewSubjectPrivilegeTo(organisationData.getGroup(), subjectType); | ||
Individual subject = new SubjectBuilder() | ||
.withMandatoryFieldsForNewEntity() | ||
.withSubjectType(subjectType) | ||
.withLocation(catchmentData.getAddressLevel1()) | ||
.withObservations(observationCollection) | ||
.build(); | ||
testSubjectService.save(subject); | ||
} | ||
|
||
@Test | ||
public void getSubjectsWithAllParams() { | ||
ResponsePage subjects = subjectApiController.getSubjects(DateTime.now().minusDays(1), | ||
DateTime.now().plusDays(1), | ||
subjectType.getName(), | ||
String.format("{\"%s\": \"%s\"}", concept.getName(), concept.getAnswerConcept("Answer 1").getUuid()), | ||
Collections.singletonList(catchmentData.getAddressLevel1().getUuid()), | ||
PageRequest.of(0, 10)); | ||
assertEquals(1, subjects.getContent().size()); | ||
} | ||
|
||
@Test | ||
public void getSubjectWithoutLastModifiedDateTime() { | ||
ResponsePage subjects = subjectApiController.getSubjects(null, null, | ||
subjectType.getName(), | ||
String.format("{\"%s\": \"%s\"}", concept.getName(), concept.getAnswerConcept("Answer 1").getUuid()), | ||
Collections.singletonList(catchmentData.getAddressLevel1().getUuid()), | ||
PageRequest.of(0, 10)); | ||
assertEquals(1, subjects.getContent().size()); | ||
} | ||
} |