Search in sources :

Example 1 with ExportFormatMessage

use of org.talend.dataprep.format.export.ExportFormatMessage in project data-prep by Talend.

the class BaseFormatTest method testFormat.

protected void testFormat(ExportFormat format, String expectedJson) throws IOException {
    StringWriter writer = new StringWriter();
    final ExportFormatMessage exportFormatMessage = beanConversionService.convert(format, ExportFormatMessage.class);
    mapper.writer().writeValue(writer, exportFormatMessage);
    assertThat(writer.toString(), sameJSONAsFile(BaseFormatTest.class.getResourceAsStream(expectedJson)));
}
Also used : StringWriter(java.io.StringWriter) ExportFormatMessage(org.talend.dataprep.format.export.ExportFormatMessage)

Example 2 with ExportFormatMessage

use of org.talend.dataprep.format.export.ExportFormatMessage in project data-prep by Talend.

the class CSVFormatTest method csv.

@Test
public void csv() {
    // when
    final ExportFormatMessage exportFormatMessage = beanConversionService.convert(format, ExportFormatMessage.class);
    // then
    assertEquals("text/csv", exportFormatMessage.getMimeType());
    assertEquals("CSV", exportFormatMessage.getId());
    assertEquals("Local CSV file", exportFormatMessage.getName());
    assertEquals(true, exportFormatMessage.isNeedParameters());
    assertEquals(false, exportFormatMessage.isDefaultExport());
    assertEquals(true, exportFormatMessage.isEnabled());
    assertEquals("", exportFormatMessage.getDisableReason());
    assertEquals("Export to CSV", exportFormatMessage.getTitle());
    List<Parameter> parameters = exportFormatMessage.getParameters();
    assertNotNull(parameters);
    assertEquals(6, parameters.size());
}
Also used : ExportFormatMessage(org.talend.dataprep.format.export.ExportFormatMessage) Parameter(org.talend.dataprep.parameters.Parameter) Test(org.junit.Test)

Example 3 with ExportFormatMessage

use of org.talend.dataprep.format.export.ExportFormatMessage in project data-prep by Talend.

the class ExportFormatConversions method doWith.

@Override
public BeanConversionService doWith(BeanConversionService conversionService, String beanName, ApplicationContext applicationContext) {
    final MessagesBundle messagesBundle = applicationContext.getBean(MessagesBundle.class);
    conversionService.register(// 
    fromBean(ExportFormat.class).toBeans(// 
    ExportFormatMessage.class).using(ExportFormatMessage.class, (exportFormat, exportFormatMessage) -> {
        final String code = "export." + exportFormat.getName() + ".display";
        final String displayName = messagesBundle.getString(LocaleContextHolder.getLocale(), code);
        exportFormatMessage.setId(exportFormat.getName());
        exportFormatMessage.setName(displayName);
        exportFormatMessage.setSupportSampling(exportFormat.supportSampling());
        return exportFormatMessage;
    }).build());
    return conversionService;
}
Also used : ExportFormatMessage(org.talend.dataprep.format.export.ExportFormatMessage) MessagesBundle(org.talend.dataprep.i18n.MessagesBundle)

Example 4 with ExportFormatMessage

use of org.talend.dataprep.format.export.ExportFormatMessage in project data-prep by Talend.

the class ExportAPITest method get_all_export_types.

@Test
public void get_all_export_types() throws Exception {
    // given
    ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    // when
    String actualJsonString = RestAssured.when().get("/api/export/formats").asString();
    List<ExportFormatMessage> exportFormatMessageList = mapper.readValue(actualJsonString, new TypeReference<List<ExportFormatMessage>>() {
    });
    ExportFormatMessage exportFormatMessageCSV = exportFormatMessageList.get(0);
    ExportFormatMessage exportFormatMessageXLSX = exportFormatMessageList.get(1);
    // then
    assertEquals("text/csv", exportFormatMessageCSV.getMimeType());
    assertEquals("CSV", exportFormatMessageCSV.getId());
    assertEquals("Local CSV file", exportFormatMessageCSV.getName());
    assertEquals(true, exportFormatMessageCSV.isNeedParameters());
    assertEquals(false, exportFormatMessageCSV.isDefaultExport());
    assertEquals(true, exportFormatMessageCSV.isEnabled());
    assertEquals(true, exportFormatMessageCSV.isSupportSampling());
    assertEquals("", exportFormatMessageCSV.getDisableReason());
    assertEquals("Export to CSV", exportFormatMessageCSV.getTitle());
    List<Parameter> parametersCSV = exportFormatMessageCSV.getParameters();
    assertNotNull(parametersCSV);
    assertEquals(6, parametersCSV.size());
    // Andthen
    assertEquals("application/vnd.ms-excel", exportFormatMessageXLSX.getMimeType());
    assertEquals("XLSX", exportFormatMessageXLSX.getId());
    assertEquals("Local XLSX file", exportFormatMessageXLSX.getName());
    assertEquals(true, exportFormatMessageXLSX.isNeedParameters());
    assertEquals(true, exportFormatMessageXLSX.isDefaultExport());
    assertEquals(true, exportFormatMessageXLSX.isEnabled());
    assertEquals(true, exportFormatMessageXLSX.isSupportSampling());
    assertEquals("", exportFormatMessageXLSX.getDisableReason());
    assertEquals("Export to XLSX", exportFormatMessageXLSX.getTitle());
    List<Parameter> parametersXLS = exportFormatMessageXLSX.getParameters();
    assertNotNull(parametersXLS);
    assertEquals(1, parametersXLS.size());
}
Also used : ExportFormatMessage(org.talend.dataprep.format.export.ExportFormatMessage) Parameter(org.talend.dataprep.parameters.Parameter) List(java.util.List) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with ExportFormatMessage

use of org.talend.dataprep.format.export.ExportFormatMessage in project data-prep by Talend.

the class ExportPreparationStep method whenIGetExportFormat.

@When("^I get the export formats for the preparation \"(.*)\"$")
public void whenIGetExportFormat(String preparationName) throws IOException {
    String preparationId = context.getPreparationId(suffixName(preparationName));
    Response apiResponse = api.getExportFormats(preparationId);
    ExportFormatMessage[] parameters = objectMapper.readValue(apiResponse.getBody().asString(), ExportFormatMessage[].class);
    context.storePreparationExportFormat(suffixName(preparationName), parameters);
}
Also used : Response(com.jayway.restassured.response.Response) ExportFormatMessage(org.talend.dataprep.format.export.ExportFormatMessage) When(cucumber.api.java.en.When)

Aggregations

ExportFormatMessage (org.talend.dataprep.format.export.ExportFormatMessage)5 Test (org.junit.Test)2 Parameter (org.talend.dataprep.parameters.Parameter)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Response (com.jayway.restassured.response.Response)1 When (cucumber.api.java.en.When)1 StringWriter (java.io.StringWriter)1 List (java.util.List)1 MessagesBundle (org.talend.dataprep.i18n.MessagesBundle)1