use of io.micronaut.http.client.multipart.MultipartBody in project check-ins by objectcomputing.
the class EmployeeHoursControllerTest method testCreateEmployeeHoursWithNoTeamMemberId.
@Test
void testCreateEmployeeHoursWithNoTeamMemberId() {
File file = new File("src/test/java/com/objectcomputing/checkins/services/employee_hours/test.csv");
MultipartBody multipartBody = MultipartBody.builder().addPart("file", "test.csv", new MediaType("text/csv"), file).build();
MemberProfile user = createAnUnrelatedUser();
createAndAssignAdminRole(user);
final HttpRequest<MultipartBody> request = HttpRequest.POST("/upload", multipartBody).basicAuth(user.getWorkEmail(), ADMIN_ROLE).contentType(MediaType.MULTIPART_FORM_DATA);
HttpClientResponseException responseException = assertThrows(HttpClientResponseException.class, () -> client.toBlocking().exchange(request, Map.class));
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseException.getStatus());
}
use of io.micronaut.http.client.multipart.MultipartBody in project check-ins by objectcomputing.
the class EmployeeHoursControllerTest method testCreateEmployeeHours.
@Test
void testCreateEmployeeHours() {
File file = new File("src/test/java/com/objectcomputing/checkins/services/employee_hours/test.csv");
MultipartBody multipartBody = MultipartBody.builder().addPart("file", "test.csv", new MediaType("text/csv"), file).build();
MemberProfile memberProfile = createADefaultMemberProfile();
createADefaultMemberProfileForPdl(memberProfile);
MemberProfile user = createAnUnrelatedUser();
createAndAssignAdminRole(user);
final HttpRequest<MultipartBody> request = HttpRequest.POST("/upload", multipartBody).basicAuth(user.getWorkEmail(), ADMIN_ROLE).contentType(MediaType.MULTIPART_FORM_DATA);
final HttpResponse<EmployeeHoursResponseDTO> response = client.toBlocking().exchange(request, EmployeeHoursResponseDTO.class);
EmployeeHoursResponseDTO employeeHoursResponseDTO = response.body();
assertEquals(employeeHoursResponseDTO, response.body());
assertEquals(HttpStatus.OK, response.getStatus());
}
use of io.micronaut.http.client.multipart.MultipartBody in project micronaut-core by micronaut-projects.
the class UploadControllerSpec method testCompletedFileUploadNoNameWithBytes.
@Test
public void testCompletedFileUploadNoNameWithBytes() {
MultipartBody body = MultipartBody.builder().addPart("file", "", MediaType.APPLICATION_JSON_TYPE, "{\"title\":\"Foo\"}".getBytes()).build();
Flux<HttpResponse<String>> flowable = Flux.from(client.exchange(HttpRequest.POST("/upload/completed", body).contentType(MediaType.MULTIPART_FORM_DATA).accept(MediaType.TEXT_PLAIN_TYPE), String.class));
HttpClientResponseException ex = Assertions.assertThrows(HttpClientResponseException.class, () -> flowable.blockFirst());
Map<String, Object> embedded = (Map<String, Object>) ex.getResponse().getBody(Map.class).get().get("_embedded");
Object message = ((Map<String, Object>) ((List) embedded.get("errors")).get(0)).get("message");
assertEquals("Required argument [CompletedFileUpload file] not specified", message);
}
use of io.micronaut.http.client.multipart.MultipartBody in project micronaut-core by micronaut-projects.
the class UploadControllerSpec method testCompletedFileUpload.
@Test
public void testCompletedFileUpload() {
MultipartBody body = MultipartBody.builder().addPart("file", "file.json", MediaType.APPLICATION_JSON_TYPE, "{\"title\":\"Foo\"}".getBytes()).build();
Flux<HttpResponse<String>> flowable = Flux.from(client.exchange(HttpRequest.POST("/upload/completed", body).contentType(MediaType.MULTIPART_FORM_DATA).accept(MediaType.TEXT_PLAIN_TYPE), String.class));
HttpResponse<String> response = flowable.blockFirst();
assertEquals(HttpStatus.OK.getCode(), response.code());
assertEquals("Uploaded", response.getBody().get());
}
use of io.micronaut.http.client.multipart.MultipartBody in project micronaut-core by micronaut-projects.
the class UploadControllerSpec method testFileBytesUpload.
@Test
public void testFileBytesUpload() {
MultipartBody body = MultipartBody.builder().addPart("file", "file.json", MediaType.TEXT_PLAIN_TYPE, "some data".getBytes()).addPart("fileName", "bar").build();
Flux<HttpResponse<String>> flowable = Flux.from(client.exchange(HttpRequest.POST("/upload/bytes", body).contentType(MediaType.MULTIPART_FORM_DATA).accept(MediaType.TEXT_PLAIN_TYPE), String.class));
HttpResponse<String> response = flowable.blockFirst();
assertEquals(HttpStatus.OK.getCode(), response.code());
assertEquals("Uploaded", response.getBody().get());
}
Aggregations