use of com.bakdata.conquery.models.query.ManagedQuery in project conquery by bakdata.
the class SerializingStoreDumpTest method testCorruptKeyDump.
/**
* Tests if entries with corrupted keys are dumped.
*/
@Test
public void testCorruptKeyDump() 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(new UserId("testU1"), user);
}
{
// Open that store again, with a different config to insert a corrupt entry
// (String & ManagedQuery)
SerializingStore<String, QueryDescription> store = createSerializedStore(config, env, Validators.newValidator(), new StoreInfo<>(USER_STORE_ID.getName(), String.class, QueryDescription.class));
store.add("not a valid conquery Id", 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(1);
expectedResult.setFailedValues(0);
// 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 DefaultLabelTest method autoLabelUploadQuery.
@ParameterizedTest
@CsvSource({ "de,Hochgeladene-Liste", "en,Uploaded-List" })
void autoLabelUploadQuery(Locale locale, String autoLabel) {
I18n.LOCALE.set(locale);
CQExternal external = new CQExternal(List.of(), new String[0][0]);
ConceptQuery cq = new ConceptQuery(external);
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 autoLabelComplexQuery.
@ParameterizedTest
@CsvSource({ "de,Hochgeladene-Liste Anfrage Concept1 Concept2 und weitere", "en,Uploaded-List Query Concept1 Concept2 and further" })
void autoLabelComplexQuery(Locale locale, String autoLabel) {
I18n.LOCALE.set(locale);
final ManagedQuery managedQuery = new ManagedQuery(null, null, DATASET);
managedQuery.setQueryId(UUID.randomUUID());
CQAnd and = new CQAnd();
CQConcept concept1 = makeCQConcept("Concept1");
CQConcept concept2 = makeCQConcept("Concept2");
CQConcept concept3 = makeCQConcept("Concept3veryveryveryveryveryveryveryverylooooooooooooooooooooonglabel");
and.setChildren(List.of(new CQExternal(List.of(), new String[0][0]), new CQReusedQuery(managedQuery.getId()), concept1, concept2, concept3));
ConceptQuery cq = new ConceptQuery(and);
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 PermissionCleanupTaskTest method doDeletePermissionsOfOwnedReference.
@Test
void doDeletePermissionsOfOwnedReference() {
assertThat(STORAGE.getAllExecutions()).isEmpty();
// Created owned execution
final ManagedQuery managedQueryOwned = createManagedQuery();
// Setup user
User user = new User("test", "test", STORAGE);
User user2 = new User("test2", "test2", STORAGE);
STORAGE.updateUser(user);
user.addPermission(ExecutionPermission.onInstance(AbilitySets.QUERY_CREATOR, managedQueryOwned.getId()));
managedQueryOwned.setOwner(user);
STORAGE.updateExecution(managedQueryOwned);
// Created not owned execution
final ManagedQuery managedQueryNotOwned = createManagedQuery();
// Setup user
user.addPermission(ExecutionPermission.onInstance(Ability.READ, managedQueryNotOwned.getId()));
// Set owner
managedQueryNotOwned.setOwner(user2);
STORAGE.updateExecution(managedQueryNotOwned);
deletePermissionsOfOwnedInstances(STORAGE, ExecutionPermission.DOMAIN.toLowerCase(), ManagedExecutionId.Parser.INSTANCE, STORAGE::getExecution);
assertThat(user.getPermissions()).containsOnly(ExecutionPermission.onInstance(Ability.READ, managedQueryNotOwned.getId()));
}
use of com.bakdata.conquery.models.query.ManagedQuery in project conquery by bakdata.
the class PermissionCleanupTaskTest method doDeletePartialPermissionWithInvalidReference.
@Test
void doDeletePartialPermissionWithInvalidReference() {
assertThat(STORAGE.getAllExecutions()).isEmpty();
final ManagedQuery managedQuery1 = createManagedQuery();
final ManagedQuery managedQuery2 = createManagedQuery();
// Removing the second execution
STORAGE.removeExecution(managedQuery2.getId());
User user = new User("test", "test", STORAGE);
STORAGE.updateUser(user);
user.addPermission(// Build a permission with multiple instances
new WildcardPermission(List.of(Set.of(ExecutionPermission.DOMAIN), Set.of(Ability.READ.toString().toLowerCase()), Set.of(managedQuery1.getId().toString(), managedQuery2.getId().toString())), Instant.now()));
deleteQueryPermissionsWithMissingRef(STORAGE, STORAGE.getAllUsers());
assertThat(user.getPermissions()).containsOnly(ExecutionPermission.onInstance(Ability.READ, managedQuery1.getId()));
}
Aggregations