Search in sources :

Example 16 with MultipartBody

use of io.micronaut.http.client.multipart.MultipartBody in project check-ins by objectcomputing.

the class EmployeeHoursFixture method createEmployeeHours.

default List<EmployeeHours> createEmployeeHours() {
    final EmployeeHoursServices employeeHoursServices = null;
    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();
    List<EmployeeHours> employeeHoursList = new ArrayList<>();
    try {
        InputStream inputStream = new FileInputStream(file);
        employeeHoursList = EmployeeaHoursCSVHelper.employeeHrsCsv(inputStream);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return getEmployeeHoursRepository().saveAll(employeeHoursList);
}
Also used : EmployeeHours(com.objectcomputing.checkins.services.employee_hours.EmployeeHours) EmployeeHoursServices(com.objectcomputing.checkins.services.employee_hours.EmployeeHoursServices) MultipartBody(io.micronaut.http.client.multipart.MultipartBody) ArrayList(java.util.ArrayList) MediaType(io.micronaut.http.MediaType)

Example 17 with MultipartBody

use of io.micronaut.http.client.multipart.MultipartBody in project bi-api by Breeding-Insight.

the class TraitUploadControllerIntegrationTest method putTraitUploadMissingMediaType.

@Test
void putTraitUploadMissingMediaType() {
    MultipartBody requestBody = MultipartBody.builder().addPart("file", "test", new byte[1]).build();
    Flowable<HttpResponse<String>> call = client.exchange(PUT("/programs/" + validProgram.getId() + "/trait-upload", requestBody).contentType(MediaType.MULTIPART_FORM_DATA_TYPE).cookie(new NettyCookie("phylo-token", "test-registered-user")), String.class);
    HttpClientResponseException e = Assertions.assertThrows(HttpClientResponseException.class, () -> {
        HttpResponse<String> response = call.blockingFirst();
    });
    assertEquals(HttpStatus.UNSUPPORTED_MEDIA_TYPE, e.getStatus());
}
Also used : HttpClientResponseException(io.micronaut.http.client.exceptions.HttpClientResponseException) MultipartBody(io.micronaut.http.client.multipart.MultipartBody) HttpResponse(io.micronaut.http.HttpResponse) NettyCookie(io.micronaut.http.netty.cookies.NettyCookie) MicronautTest(io.micronaut.test.annotation.MicronautTest) BrAPITest(org.breedinginsight.BrAPITest) DatabaseTest(org.breedinginsight.DatabaseTest)

Aggregations

MultipartBody (io.micronaut.http.client.multipart.MultipartBody)17 HttpResponse (io.micronaut.http.HttpResponse)12 Test (org.junit.Test)10 HttpClientResponseException (io.micronaut.http.client.exceptions.HttpClientResponseException)6 MediaType (io.micronaut.http.MediaType)5 File (java.io.File)5 Map (java.util.Map)3 Test (org.junit.jupiter.api.Test)3 MemberProfile (com.objectcomputing.checkins.services.memberprofile.MemberProfile)2 NettyCookie (io.micronaut.http.netty.cookies.NettyCookie)2 EmployeeHours (com.objectcomputing.checkins.services.employee_hours.EmployeeHours)1 EmployeeHoursServices (com.objectcomputing.checkins.services.employee_hours.EmployeeHoursServices)1 NonNull (io.micronaut.core.annotation.NonNull)1 Nullable (io.micronaut.core.annotation.Nullable)1 MultipartDataFactory (io.micronaut.http.client.multipart.MultipartDataFactory)1 NettyClientSslBuilder (io.micronaut.http.client.netty.ssl.NettyClientSslBuilder)1 MultipartException (io.micronaut.http.multipart.MultipartException)1 NettyHttpRequestBuilder (io.micronaut.http.netty.NettyHttpRequestBuilder)1 NettyHttpResponseBuilder (io.micronaut.http.netty.NettyHttpResponseBuilder)1 UriBuilder (io.micronaut.http.uri.UriBuilder)1