Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#132. Dependent on #199
  • Loading branch information
BrapiCoordinatorSelby committed Aug 18, 2023
1 parent 1960393 commit e89e963
Show file tree
Hide file tree
Showing 4 changed files with 1,456 additions and 1,307 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,142 +25,160 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import java.time.LocalDate;
import java.util.Arrays;
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 TrialsApi
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class TrialsApiTest extends BrAPIClientTest {

private final TrialsApi api = new TrialsApi(this.apiClient);

/**
* Submit a search request for Trials
*
* Advanced searching for the programs resource. See Search Services for additional implementation details.
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void searchTrialsPostTest() throws ApiException {
BrAPITrialSearchRequest body = new BrAPITrialSearchRequest();

ApiResponse<Pair<Optional<BrAPITrialListResponse>, Optional<BrAPIAcceptedSearchResponse>>> response = api.searchTrialsPost(body);

// TODO: test validations
}
/**
* Get the results of a Trials search request
*
* Advanced searching for the trials resource. See Search Services for additional implementation details.
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void searchTrialsSearchResultsDbIdGetTest() throws ApiException {
String searchResultsDbId = null;
Integer page = null;
Integer pageSize = null;

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

// TODO: test validations
}
/**
* Get a filtered list of Trials
*
* Retrieve a filtered list of breeding Trials. A Trial is a collection of Studies
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void trialsGetTest() throws ApiException {
Boolean active = null;
String commonCropName = null;
String contactDbId = null;
String programDbId = null;
String locationDbId = null;
LocalDate searchDateRangeStart = null;
LocalDate searchDateRangeEnd = null;
String studyDbId = null;
String trialDbId = null;
String trialName = null;
String trialPUI = null;
String sortBy = null;
String sortOrder = null;
String externalReferenceID = null;
String externalReferenceSource = null;
Integer page = null;
Integer pageSize = null;

TrialQueryParams queryParams = new TrialQueryParams();
ApiResponse<BrAPITrialListResponse> response = api.trialsGet(queryParams);

// TODO: test validations
}
/**
* Create new trials
*
* Create new breeding Trials. A Trial represents a collection of related Studies. &#x60;trialDbId&#x60; is generated by the server.
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void trialsPostTest() throws ApiException {
List<BrAPITrial> body = Arrays.asList(new BrAPITrial());

ApiResponse<BrAPITrialListResponse> response = api.trialsPost(body);

// TODO: test validations
}
/**
* Get the details of a specific Trial
*
* Get the details of a specific Trial
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void trialsTrialDbIdGetTest() throws ApiException {
String trialDbId = null;

IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
ApiResponse<BrAPITrialSingleResponse> response = api.trialsTrialDbIdGet(trialDbId);
});

// TODO: test validations
}
/**
* Update the details of an existing Trial
*
* Update the details of an existing Trial
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void trialsTrialDbIdPutTest() throws ApiException {
String trialDbId = null;
BrAPITrial body = null;

IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
ApiResponse<BrAPITrialSingleResponse> response = api.trialsTrialDbIdPut(trialDbId, body);
});

// TODO: test validations
}
private final TrialsApi api = new TrialsApi(this.apiClient);

/**
* Submit a search request for Trials
*
* Advanced searching for the programs resource. See Search Services for
* additional implementation details.
*
* @throws ApiException if the Api call fails
*/
@Test
public void searchTrialsPostTest() throws ApiException {
BrAPITrialSearchRequest body = new BrAPITrialSearchRequest()
.addTrialDbIdsItem("trial1")
.addTrialDbIdsItem("trial2");

ApiResponse<Pair<Optional<BrAPITrialListResponse>, Optional<BrAPIAcceptedSearchResponse>>> response = api
.searchTrialsPost(body);

Optional<BrAPITrialListResponse> 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 Trials search request
*
* Advanced searching for the trials resource. See Search Services for
* additional implementation details.
*
* @throws ApiException if the Api call fails
*/
@Test
public void searchTrialsSearchResultsDbIdGetTest() throws ApiException {
BrAPITrialSearchRequest body = new BrAPITrialSearchRequest()
.addTrialDbIdsItem("trial1")
.addTrialDbIdsItem("trial2")
.addTrialDbIdsItem("trial3")
.addTrialDbIdsItem("trial2")
.addTrialDbIdsItem("trial1");

ApiResponse<Pair<Optional<BrAPITrialListResponse>, Optional<BrAPIAcceptedSearchResponse>>> response = api
.searchTrialsPost(body);

Optional<BrAPITrialListResponse> 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<BrAPITrialListResponse>, Optional<BrAPIAcceptedSearchResponse>>> searchResponse = this.api
.searchTrialsSearchResultsDbIdGet(searchIdResponse.get().getResult().getSearchResultsDbId(), 0, 10);
Optional<BrAPITrialListResponse> listResponse2 = searchResponse.getBody().getLeft();
Optional<BrAPIAcceptedSearchResponse> searchIdResponse2 = searchResponse.getBody().getRight();
// only results are returned
assertTrue(listResponse2.isPresent());
assertFalse(searchIdResponse2.isPresent());

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

/**
* Get a filtered list of Trials
*
* Retrieve a filtered list of breeding Trials. A Trial is a collection of
* Studies
*
* @throws ApiException if the Api call fails
*/
@Test
public void trialsGetTest() throws ApiException {
String trialDbId = "trial1";

TrialQueryParams queryParams = new TrialQueryParams().trialDbId(trialDbId);
ApiResponse<BrAPITrialListResponse> response = api.trialsGet(queryParams);

assertEquals(1, response.getBody().getResult().getData().size());
assertEquals(trialDbId, response.getBody().getResult().getData().get(0).getTrialDbId());
}

/**
* Create new trials
*
* Create new breeding Trials. A Trial represents a collection of related
* Studies. &#x60;trialDbId&#x60; is generated by the server.
*
* @throws ApiException if the Api call fails
*/
@Test
public void trialsPostTest() throws ApiException {
BrAPITrial trial = new BrAPITrial()
.trialName("New Trial Name");
List<BrAPITrial> body = Arrays.asList(trial);

ApiResponse<BrAPITrialListResponse> response = api.trialsPost(body);

assertEquals(1, response.getBody().getResult().getData().size());
assertEquals(trial.getTrialName(), response.getBody().getResult().getData().get(0).getTrialName());
assertNotNull(response.getBody().getResult().getData().get(0).getTrialDbId());
}

/**
* Get the details of a specific Trial
*
* Get the details of a specific Trial
*
* @throws ApiException if the Api call fails
*/
@Test
public void trialsTrialDbIdGetTest() throws ApiException {
String trialDbId = "trial1";

ApiResponse<BrAPITrialSingleResponse> response = api.trialsTrialDbIdGet(trialDbId);

assertEquals(trialDbId, response.getBody().getResult().getTrialDbId());
}

/**
* Update the details of an existing Trial
*
* Update the details of an existing Trial
*
* @throws ApiException if the Api call fails
*/
@Test
public void trialsTrialDbIdPutTest() throws ApiException {
String trialDbId = "trial1";
BrAPITrial body = new BrAPITrial().trialName("New Trial Name");

ApiResponse<BrAPITrialSingleResponse> response = api.trialsTrialDbIdPut(trialDbId, body);

assertEquals(trialDbId, response.getBody().getResult().getTrialDbId());
assertEquals(body.getTrialName(), response.getBody().getResult().getTrialName());
}
}
Loading

0 comments on commit e89e963

Please sign in to comment.