Search in sources :

Example 1 with ExcelConfig

use of com.bakdata.conquery.models.config.ExcelConfig in project conquery by bakdata.

the class ExcelResultRenderTest method writeAndRead.

@Test
void writeAndRead() throws IOException {
    // Prepare every input data
    PrintSettings printSettings = new PrintSettings(true, Locale.GERMAN, null, CONFIG, (cer) -> EntityPrintId.from(Integer.toString(cer.getEntityId()), Integer.toString(cer.getEntityId())), (selectInfo) -> selectInfo.getSelect().getLabel());
    // The Shard nodes send Object[] but since Jackson is used for deserialization, nested collections are always a list because they are not further specialized
    List<EntityResult> results = getTestEntityResults();
    ManagedQuery mquery = new ManagedQuery(null, null, null) {

        public List<ResultInfo> getResultInfos() {
            return getResultTypes().stream().map(ResultTestUtil.TypedSelectDummy::new).map(select -> new SelectResultInfo(select, new CQConcept())).collect(Collectors.toList());
        }

        @Override
        public Stream<EntityResult> streamResults() {
            return results.stream();
        }
    };
    // First we write to the buffer, than we read from it and parse it as TSV
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ExcelRenderer renderer = new ExcelRenderer(new ExcelConfig(), printSettings);
    renderer.renderToStream(ResultTestUtil.ID_FIELDS, mquery, output);
    InputStream inputStream = new ByteArrayInputStream(output.toByteArray());
    List<String> computed = readComputed(inputStream, printSettings);
    List<String> expected = generateExpectedTSV(results, mquery.getResultInfos(), printSettings);
    log.info("Wrote and than read this excel data: {}", computed);
    assertThat(computed).isNotEmpty();
    assertThat(computed).isEqualTo(expected);
}
Also used : ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EntityResult(com.bakdata.conquery.models.query.results.EntityResult) ArrayList(java.util.ArrayList) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) EntityPrintId(com.bakdata.conquery.models.identifiable.mapping.EntityPrintId) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) DataFormatter(org.apache.poi.ss.usermodel.DataFormatter) Cell(org.apache.poi.ss.usermodel.Cell) I18n(com.bakdata.conquery.models.i18n.I18n) ResultType(com.bakdata.conquery.models.externalservice.ResultType) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) ResultTestUtil.getTestEntityResults(com.bakdata.conquery.io.result.ResultTestUtil.getTestEntityResults) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) ResultTestUtil.getResultTypes(com.bakdata.conquery.io.result.ResultTestUtil.getResultTypes) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ExcelConfig(com.bakdata.conquery.models.config.ExcelConfig) Test(org.junit.jupiter.api.Test) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) ResultTestUtil(com.bakdata.conquery.io.result.ResultTestUtil) StringJoiner(java.util.StringJoiner) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) Row(org.apache.poi.ss.usermodel.Row) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) NotNull(org.jetbrains.annotations.NotNull) InputStream(java.io.InputStream) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EntityResult(com.bakdata.conquery.models.query.results.EntityResult) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ResultInfo(com.bakdata.conquery.models.query.resultinfo.ResultInfo) SelectResultInfo(com.bakdata.conquery.models.query.resultinfo.SelectResultInfo) ExcelConfig(com.bakdata.conquery.models.config.ExcelConfig) Test(org.junit.jupiter.api.Test)

Aggregations

CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)1 ResultTestUtil (com.bakdata.conquery.io.result.ResultTestUtil)1 ResultTestUtil.getResultTypes (com.bakdata.conquery.io.result.ResultTestUtil.getResultTypes)1 ResultTestUtil.getTestEntityResults (com.bakdata.conquery.io.result.ResultTestUtil.getTestEntityResults)1 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)1 ExcelConfig (com.bakdata.conquery.models.config.ExcelConfig)1 ResultType (com.bakdata.conquery.models.externalservice.ResultType)1 I18n (com.bakdata.conquery.models.i18n.I18n)1 EntityPrintId (com.bakdata.conquery.models.identifiable.mapping.EntityPrintId)1 ManagedQuery (com.bakdata.conquery.models.query.ManagedQuery)1 PrintSettings (com.bakdata.conquery.models.query.PrintSettings)1 ResultInfo (com.bakdata.conquery.models.query.resultinfo.ResultInfo)1 SelectResultInfo (com.bakdata.conquery.models.query.resultinfo.SelectResultInfo)1 EntityResult (com.bakdata.conquery.models.query.results.EntityResult)1 NonPersistentStoreFactory (com.bakdata.conquery.util.NonPersistentStoreFactory)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1