use of io.micronaut.http.HttpResponse in project bi-api by Breeding-Insight.
the class MetadataFilterIntegrationTest method filterNotCalledNoAnnotation.
@Test
public void filterNotCalledNoAnnotation() {
// Check that the metadata filter does not add metadata when annotation is missing
Response mockedResponse = getResponseMock();
when(userController.users(any(QueryParams.class))).thenReturn(HttpResponse.ok(mockedResponse));
Flowable<HttpResponse<String>> call = client.exchange(GET("/users").cookie(new NettyCookie("phylo-token", "test-registered-user")), String.class);
HttpResponse<String> response = call.blockingFirst();
assertEquals(HttpStatus.OK, response.getStatus());
JsonObject metadata = JsonParser.parseString(response.body()).getAsJsonObject().getAsJsonObject("metadata");
assertTrue(metadata == null, "Metadata was populated, but shouldn't have been");
}
use of io.micronaut.http.HttpResponse in project bi-api by Breeding-Insight.
the class BrapiAuthorizeControllerIntegrationTest method redirectMissingRequiredParameters.
@Test
void redirectMissingRequiredParameters() {
Flowable<HttpResponse<String>> call = client.exchange(GET(String.format("/programs/%s/brapi/authorize", validProgram.getId())).cookie(new NettyCookie("phylo-token", "test-registered-user")), String.class);
HttpClientResponseException e = Assertions.assertThrows(HttpClientResponseException.class, () -> {
HttpResponse<String> response = call.blockingFirst();
});
assertEquals(HttpStatus.BAD_REQUEST, e.getStatus());
}
use of io.micronaut.http.HttpResponse in project bi-api by Breeding-Insight.
the class BrAPIV2ControllerIntegrationTest method testPostGetVariablesProxy.
@Test
@SneakyThrows
public void testPostGetVariablesProxy() {
BrAPIObservationVariable variable = generateVariable();
Flowable<HttpResponse<String>> postCall = biClient.exchange(POST(String.format("%s/programs/%s/brapi/v2/variables", biApiVersion, validProgram.getId().toString()), Arrays.asList(variable)).contentType(MediaType.APPLICATION_JSON).bearerAuth("test-registered-user"), String.class);
HttpResponse<String> postResponse;
try {
postResponse = postCall.blockingFirst();
} catch (Exception e) {
throw new Exception(e);
}
// check the POST call was successful
assertEquals(HttpStatus.OK, postResponse.getStatus());
BrAPIObservationVariable createdVariable = GSON.fromJson(postResponse.body(), BrAPIObservationVariableListResponse.class).getResult().getData().get(0);
// and that a variable is returned
assertNotNull(createdVariable);
// and that the variable has been assigned an ID
assertNotNull(createdVariable.getObservationVariableDbId(), "observationVariableDbId is null");
Flowable<HttpResponse<String>> getCall = biClient.exchange(GET(String.format("%s/programs/%s/brapi/v2/variables/%s", biApiVersion, validProgram.getId().toString(), createdVariable.getObservationVariableDbId())).bearerAuth("test-registered-user"), String.class);
HttpResponse<String> getResponse;
try {
getResponse = getCall.blockingFirst();
} catch (Exception e) {
throw new Exception(e);
}
assertEquals(HttpStatus.OK, getResponse.getStatus());
assertNotNull(getResponse.body(), "Response body is empty");
BrAPIObservationVariableSingleResponse brAPIObservationVariableSingleResponse = GSON.fromJson(getResponse.body(), BrAPIObservationVariableSingleResponse.class);
BrAPIObservationVariable fetchedVariable = brAPIObservationVariableSingleResponse.getResult();
assertNotNull(fetchedVariable, "Observation Variable was not found");
assertEquals(createdVariable.getObservationVariableDbId(), fetchedVariable.getObservationVariableDbId());
// make sure the original values sent in the POST were saved correctly
assertEquals(variable.getObservationVariableName(), fetchedVariable.getObservationVariableName());
assertEquals(variable.getExternalReferences(), fetchedVariable.getExternalReferences());
assertEquals(variable.getCommonCropName(), fetchedVariable.getCommonCropName());
assertNotNull(fetchedVariable.getTrait(), "Trait is null");
assertEquals(createdVariable.getTrait().getTraitDbId(), fetchedVariable.getTrait().getTraitDbId());
// make sure the original values sent in the POST were saved correctly
assertEquals(variable.getTrait().getTraitName(), fetchedVariable.getTrait().getTraitName());
assertEquals(variable.getTrait().getTraitClass(), fetchedVariable.getTrait().getTraitClass());
assertNotNull(fetchedVariable.getMethod(), "Method is null");
assertEquals(createdVariable.getMethod().getMethodDbId(), fetchedVariable.getMethod().getMethodDbId());
// make sure the original values sent in the POST were saved correctly
assertEquals(variable.getMethod().getMethodName(), fetchedVariable.getMethod().getMethodName());
assertEquals(variable.getMethod().getMethodClass(), fetchedVariable.getMethod().getMethodClass());
assertNotNull(fetchedVariable.getScale(), "Scale is null");
assertEquals(createdVariable.getScale().getScaleDbId(), fetchedVariable.getScale().getScaleDbId());
// make sure the original values sent in the POST were saved correctly
assertEquals(variable.getScale().getScaleName(), fetchedVariable.getScale().getScaleName());
Flowable<HttpResponse<String>> getScaleCall = biClient.exchange(GET(String.format("%s/programs/%s/brapi/v2/scales/%s", biApiVersion, validProgram.getId().toString(), createdVariable.getScale().getScaleDbId())).bearerAuth("test-registered-user"), String.class);
HttpResponse<String> getScaleResponse;
try {
getScaleResponse = getScaleCall.blockingFirst();
} catch (Exception e) {
throw new Exception(e);
}
assertEquals(HttpStatus.OK, getScaleResponse.getStatus());
BrAPIScale scaleResponse = GSON.fromJson(JsonParser.parseString(getScaleResponse.body()).getAsJsonObject().getAsJsonObject("result"), BrAPIScale.class);
// TODO this is not being returned
// assertEquals(variable.getScale().getDataType(), scaleResponse.getDataType());
}
use of io.micronaut.http.HttpResponse in project bi-api by Breeding-Insight.
the class BrAPIV2ControllerIntegrationTest method testRootServerInfo.
@Test
public void testRootServerInfo() {
Flowable<HttpResponse<String>> call = biClient.exchange(GET("/brapi/v2/serverinfo"), String.class);
HttpResponse<String> response = call.blockingFirst();
assertEquals(HttpStatus.OK, response.getStatus());
assertNotNull(response.body(), "Response body is empty");
JsonObject result = JsonParser.parseString(response.body()).getAsJsonObject().getAsJsonObject("result");
BrAPIServerInfo serverInfo = GSON.fromJson(result, BrAPIServerInfo.class);
assertEquals("Breeding Insight Platform", serverInfo.getOrganizationName());
assertEquals("bi-api", serverInfo.getServerName());
assertEquals("bidevteam@cornell.edu", serverInfo.getContactEmail());
assertEquals("breedinginsight.org", serverInfo.getOrganizationURL());
}
use of io.micronaut.http.HttpResponse in project bi-api by Breeding-Insight.
the class BrAPIV2ControllerIntegrationTest method testPutVariablesProxy.
@Test
@SneakyThrows
public void testPutVariablesProxy() {
BrAPIObservationVariable variable = generateVariable();
Flowable<HttpResponse<String>> postCall = biClient.exchange(POST(String.format("%s/programs/%s/brapi/v2/variables", biApiVersion, validProgram.getId().toString()), Arrays.asList(variable)).contentType(MediaType.APPLICATION_JSON).bearerAuth("test-registered-user"), String.class);
HttpResponse<String> postResponse;
try {
postResponse = postCall.blockingFirst();
} catch (Exception e) {
throw new Exception(e);
}
// check the POST call was successful
assertEquals(HttpStatus.OK, postResponse.getStatus());
BrAPIObservationVariable createdVariable = GSON.fromJson(postResponse.body(), BrAPIObservationVariableListResponse.class).getResult().getData().get(0);
createdVariable.setObservationVariableName("Updated variable name");
Flowable<HttpResponse<String>> putCall = biClient.exchange(PUT(String.format("%s/programs/%s/brapi/v2/variables/%s", biApiVersion, validProgram.getId().toString(), createdVariable.getObservationVariableDbId()), variable).contentType(MediaType.APPLICATION_JSON).bearerAuth("test-registered-user"), String.class);
HttpResponse<String> putResponse;
try {
putResponse = putCall.blockingFirst();
} catch (Exception e) {
throw new Exception(e);
}
// check the PUT call was successful
assertEquals(HttpStatus.OK, putResponse.getStatus());
Flowable<HttpResponse<String>> getCall = biClient.exchange(GET(String.format("%s/programs/%s/brapi/v2/variables/%s", biApiVersion, validProgram.getId().toString(), createdVariable.getObservationVariableDbId())).bearerAuth("test-registered-user"), String.class);
HttpResponse<String> getResponse;
try {
getResponse = getCall.blockingFirst();
} catch (Exception e) {
throw new Exception(e);
}
assertEquals(HttpStatus.OK, getResponse.getStatus());
BrAPIObservationVariableSingleResponse brAPIObservationVariableSingleResponse = GSON.fromJson(getResponse.body(), BrAPIObservationVariableSingleResponse.class);
BrAPIObservationVariable fetchedVariable = brAPIObservationVariableSingleResponse.getResult();
// make sure the updated value persisted
assertEquals(variable.getObservationVariableName(), fetchedVariable.getObservationVariableName());
}
Aggregations