Skip to content

Commit

Permalink
fixes #123, #124, #125, #153, #154. Dependent on #199
Browse files Browse the repository at this point in the history
  • Loading branch information
BrapiCoordinatorSelby committed Aug 17, 2023
1 parent 1960393 commit ab279e3
Show file tree
Hide file tree
Showing 3 changed files with 575 additions and 421 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,28 @@
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(fluent=true)
@Accessors(fluent = true)
public class PeopleQueryParams extends BrAPIQueryParams {

private String firstName;
private String lastName;
private String personDbId;
private String userID;
private String externalReferenceSource;
private String externalReferenceId;
@Deprecated
private String externalReferenceID;

public String getExternalReferenceId() {
private String commonCropName;
private String externalReferenceId;
@Deprecated
private String externalReferenceID;
private String externalReferenceSource;
private String firstName;
private String lastName;
private String personDbId;
private String programDbId;
private String userID;

public String getExternalReferenceId() {
return externalReferenceId;
}
public String externalReferenceId() {

public String externalReferenceId() {
return externalReferenceId;
}

public void setExternalReferenceId(String externalReferenceId) {
this.externalReferenceId = externalReferenceId;
}
Expand All @@ -55,13 +59,14 @@ public void setExternalReferenceId(String externalReferenceId) {
public String getExternalReferenceID() {
return externalReferenceID;
}

@Deprecated
public String externalReferenceID() {
return externalReferenceID;
}

@Deprecated
public void setExternalReferenceID(String externalReferenceID) {
this.externalReferenceID = externalReferenceID;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
import java.util.List;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* API tests for PeopleApi
Expand All @@ -49,19 +52,13 @@ public class PeopleApiTest extends BrAPIClientTest {
*/
@Test
public void peopleGetTest() throws ApiException {
String firstName = null;
String lastName = null;
String personDbId = null;
String userID = null;
String externalReferenceID = null;
String externalReferenceSource = null;
Integer page = null;
Integer pageSize = null;
String personDbId = "person1";

PeopleQueryParams queryParams = new PeopleQueryParams();
PeopleQueryParams queryParams = new PeopleQueryParams().personDbId(personDbId);
ApiResponse<BrAPIPersonListResponse> response = api.peopleGet(queryParams);

// TODO: test validations
assertEquals(1, response.getBody().getResult().getData().size());
assertEquals(personDbId, response.getBody().getResult().getData().get(0).getPersonDbId());
}
/**
* Get the details for a specific Person
Expand All @@ -73,13 +70,11 @@ public void peopleGetTest() throws ApiException {
*/
@Test
public void peoplePersonDbIdGetTest() throws ApiException {
String personDbId = null;
String personDbId = "person1";

IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
ApiResponse<BrAPIPersonSingleResponse> response = api.peoplePersonDbIdGet(personDbId);
});

// TODO: test validations
assertEquals(personDbId, response.getBody().getResult().getPersonDbId());
}
/**
* Update an existing Person
Expand All @@ -91,14 +86,13 @@ public void peoplePersonDbIdGetTest() throws ApiException {
*/
@Test
public void peoplePersonDbIdPutTest() throws ApiException {
String personDbId = null;
BrAPIPerson body = null;
String personDbId = "person1";
BrAPIPerson body = new BrAPIPerson().firstName("New Name");

IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
ApiResponse<BrAPIPersonSingleResponse> response = api.peoplePersonDbIdPut(personDbId, body);
});

// TODO: test validations
assertEquals(personDbId, response.getBody().getResult().getPersonDbId());
assertEquals(body.getFirstName(), response.getBody().getResult().getFirstName());
}
/**
* Create new People
Expand All @@ -110,11 +104,13 @@ public void peoplePersonDbIdPutTest() throws ApiException {
*/
@Test
public void peoplePostTest() throws ApiException {
List<BrAPIPerson> body = Arrays.asList(new BrAPIPerson());
List<BrAPIPerson> body = Arrays.asList(new BrAPIPerson().firstName("New Name"));

ApiResponse<BrAPIPersonListResponse> response = api.peoplePost(body);

// TODO: test validations
assertEquals(1, response.getBody().getResult().getData().size());
assertNotNull(response.getBody().getResult().getData().get(0).getPersonDbId());
assertEquals("New Name", response.getBody().getResult().getData().get(0).getFirstName());
}
/**
* Submit a search request for People
Expand All @@ -126,11 +122,20 @@ public void peoplePostTest() throws ApiException {
*/
@Test
public void searchPeoplePostTest() throws ApiException {
BrAPIPersonSearchRequest body = new BrAPIPersonSearchRequest();

ApiResponse<Pair<Optional<BrAPIPersonListResponse>, Optional<BrAPIAcceptedSearchResponse>>> response = api.searchPeoplePost(body);

// TODO: test validations
BrAPIPersonSearchRequest body = new BrAPIPersonSearchRequest()
.addPersonDbIdsItem("person1")
.addPersonDbIdsItem("person2");

ApiResponse<Pair<Optional<BrAPIPersonListResponse>, Optional<BrAPIAcceptedSearchResponse>>> response = api
.searchPeoplePost(body);

Optional<BrAPIPersonListResponse> listResponse = response.getBody().getLeft();
Optional<BrAPIAcceptedSearchResponse> searchIdResponse = response.getBody().getRight();
// only results are returned
assertTrue(listResponse.isPresent());
assertFalse(searchIdResponse.isPresent());

assertEquals(2, listResponse.get().getResult().getData().size(), "unexpected number of pedigree nodes returned");
}
/**
* Get the results of a People search request
Expand All @@ -142,15 +147,28 @@ public void searchPeoplePostTest() throws ApiException {
*/
@Test
public void searchPeopleSearchResultsDbIdGetTest() throws ApiException {
String searchResultsDbId = null;
Integer page = null;
Integer pageSize = null;

IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
ApiResponse<Pair<Optional<BrAPIPersonListResponse>, Optional<BrAPIAcceptedSearchResponse>>> response =
api.searchPeopleSearchResultsDbIdGet(searchResultsDbId, page, pageSize);
});

// TODO: test validations
BrAPIPersonSearchRequest baseRequest = new BrAPIPersonSearchRequest()
.addPersonDbIdsItem("person1")
.addPersonDbIdsItem("person1")
.addPersonDbIdsItem("person1")
.addPersonDbIdsItem("person2")
.addPersonDbIdsItem("person2");

ApiResponse<Pair<Optional<BrAPIPersonListResponse>, Optional<BrAPIAcceptedSearchResponse>>> response = this.api.searchPeoplePost(baseRequest);
Optional<BrAPIPersonListResponse> listResponse = response.getBody().getLeft();
Optional<BrAPIAcceptedSearchResponse> searchIdResponse = response.getBody().getRight();
// only search ID is returned
assertFalse(listResponse.isPresent());
assertTrue(searchIdResponse.isPresent());

// Get results from search ID
ApiResponse<Pair<Optional<BrAPIPersonListResponse>, Optional<BrAPIAcceptedSearchResponse>>> searchResponse = this.api.searchPeopleSearchResultsDbIdGet(searchIdResponse.get().getResult().getSearchResultsDbId(), 0, 10);
Optional<BrAPIPersonListResponse> listResponse2 = searchResponse.getBody().getLeft();
Optional<BrAPIAcceptedSearchResponse> searchIdResponse2 = searchResponse.getBody().getRight();
// only results are returned
assertTrue(listResponse2.isPresent());
assertFalse(searchIdResponse2.isPresent());

assertEquals(2, listResponse2.get().getResult().getData().size(), "unexpected number of pedigree nodes returned");
}
}
Loading

0 comments on commit ab279e3

Please sign in to comment.