use of com.bakdata.conquery.models.query.ManagedQuery 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);
}
use of com.bakdata.conquery.models.query.ManagedQuery in project conquery by bakdata.
the class SerializingStoreDumpTest method testCorruptValueDump.
/**
* Tests if entries with corrupted values are dumped.
*/
@Test
public void testCorruptValueDump() throws IOException {
// Set dump directory to this tests temp-dir
config.setUnreadableDataDumpDirectory(tmpDir);
{
// Open a store and insert a valid key-value pair (UserId & User)
SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
store.add(user.getId(), user);
}
{
// Open that store again, with a different config to insert a corrupt entry
// (UserId & ManagedQuery)
SerializingStore<UserId, QueryDescription> store = createSerializedStore(config, env, Validators.newValidator(), new StoreInfo<>(USER_STORE_ID.getName(), UserId.class, QueryDescription.class));
store.add(new UserId("testU2"), cQuery);
}
{
// Reopen the store with the initial value and try to iterate over all entries
// (this triggers the dump or removal of invalid entries)
SerializingStore<UserId, User> store = createSerializedStore(config, env, Validators.newValidator(), USER_STORE_ID);
IterationStatistic expectedResult = new IterationStatistic();
expectedResult.setTotalProcessed(2);
expectedResult.setFailedKeys(0);
expectedResult.setFailedValues(1);
// Iterate (do nothing with the entries themselves)
IterationStatistic result = store.forEach((k, v, s) -> {
});
assertThat(result).isEqualTo(expectedResult);
}
// Test if the correct number of dumpfiles was generated
Condition<File> dumpFileCond = new Condition<>(f -> f.getName().endsWith(SerializingStore.DUMP_FILE_EXTENTION), "dump file");
assertThat(tmpDir.listFiles()).areExactly(1, dumpFileCond);
// Test if the dump is correct
File dumpFile = getDumpFile(dumpFileCond);
assertThat((QueryDescription) Jackson.MAPPER.readerFor(QueryDescription.class).readValue(dumpFile)).isEqualTo(cQuery);
}
use of com.bakdata.conquery.models.query.ManagedQuery in project conquery by bakdata.
the class SerializationTests method managedQuery.
@Test
public void managedQuery() throws JSONException, IOException {
final CentralRegistry registry = new CentralRegistry();
final Dataset dataset = new Dataset("test-dataset");
final User user = new User("test-user", "test-user", STORAGE);
registry.register(dataset);
registry.register(user);
ManagedQuery execution = new ManagedQuery(null, user, dataset);
execution.setTags(new String[] { "test-tag" });
SerializationTestUtil.forType(ManagedExecution.class).registry(registry).test(execution);
}
use of com.bakdata.conquery.models.query.ManagedQuery in project conquery by bakdata.
the class DefaultLabelTest method autoLabelReusedQuery.
@ParameterizedTest
@CsvSource({ "de,Anfrage", "en,Query" })
void autoLabelReusedQuery(Locale locale, String autoLabel) {
I18n.LOCALE.set(locale);
final ManagedQuery managedQuery = new ManagedQuery(null, null, DATASET);
managedQuery.setQueryId(UUID.randomUUID());
CQReusedQuery reused = new CQReusedQuery(managedQuery.getId());
ConceptQuery cq = new ConceptQuery(reused);
ManagedQuery mQuery = cq.toManagedExecution(user, DATASET);
mQuery.setLabel(mQuery.makeAutoLabel(getPrintSettings(locale)));
assertThat(mQuery.getLabel()).isEqualTo(autoLabel + AUTO_LABEL_SUFFIX);
assertThat(mQuery.getLabelWithoutAutoLabelSuffix()).isEqualTo(autoLabel);
}
use of com.bakdata.conquery.models.query.ManagedQuery in project conquery by bakdata.
the class DefaultLabelTest method autoLabelConceptQuery.
@ParameterizedTest
@CsvSource({ "de,Concept", "en,Concept" })
void autoLabelConceptQuery(Locale locale, String autoLabel) {
I18n.LOCALE.set(locale);
CQConcept concept = makeCQConcept("Concept");
ConceptQuery cq = new ConceptQuery(concept);
ManagedQuery mQuery = cq.toManagedExecution(user, DATASET);
mQuery.setLabel(mQuery.makeAutoLabel(getPrintSettings(locale)));
assertThat(mQuery.getLabel()).isEqualTo(autoLabel + AUTO_LABEL_SUFFIX);
assertThat(mQuery.getLabelWithoutAutoLabelSuffix()).isEqualTo(autoLabel);
}
Aggregations