Search in sources :

Example 1 with NonPersistentStoreFactory

use of com.bakdata.conquery.util.NonPersistentStoreFactory in project conquery by bakdata.

the class FormConfigTest method setupTestClass.

@BeforeAll
public void setupTestClass() throws Exception {
    datasetId = dataset.getId();
    datasetId1 = dataset1.getId();
    // Mock DatasetRegistry for translation
    namespacesMock = Mockito.mock(DatasetRegistry.class);
    doAnswer(invocation -> {
        throw new UnsupportedOperationException("Not yet implemented");
    }).when(namespacesMock).getOptional(any());
    doAnswer(invocation -> {
        final DatasetId id = invocation.getArgument(0);
        Namespace namespaceMock = Mockito.mock(Namespace.class);
        if (id.equals(datasetId)) {
            when(namespaceMock.getDataset()).thenReturn(dataset);
        } else if (id.equals(datasetId1)) {
            when(namespaceMock.getDataset()).thenReturn(dataset1);
        } else {
            throw new IllegalStateException("Unkown dataset id.");
        }
        return namespaceMock;
    }).when(namespacesMock).get(any(DatasetId.class));
    when(namespacesMock.getAllDatasets()).thenReturn(List.of(dataset, dataset1));
    when(namespacesMock.injectIntoNew(any(ObjectMapper.class))).thenCallRealMethod();
    when(namespacesMock.inject(any(MutableInjectableValues.class))).thenCallRealMethod();
    storage = new NonPersistentStoreFactory().createMetaStorage();
    ((MutableInjectableValues) FormConfigProcessor.getMAPPER().getInjectableValues()).add(IdResolveContext.class, namespacesMock);
    processor = new FormConfigProcessor(validator, storage, namespacesMock);
    controller = new AuthorizationController(storage, new DevelopmentAuthorizationConfig());
    controller.start();
}
Also used : AuthorizationController(com.bakdata.conquery.models.auth.AuthorizationController) DevelopmentAuthorizationConfig(com.bakdata.conquery.models.config.auth.DevelopmentAuthorizationConfig) FormConfigProcessor(com.bakdata.conquery.models.forms.frontendconfiguration.FormConfigProcessor) MutableInjectableValues(com.bakdata.conquery.io.jackson.MutableInjectableValues) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) Namespace(com.bakdata.conquery.models.worker.Namespace) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with NonPersistentStoreFactory

use of com.bakdata.conquery.util.NonPersistentStoreFactory in project conquery by bakdata.

the class CopyUserTest method testUserCopy.

@Test
void testUserCopy() {
    final DatasetRegistry registry = new DatasetRegistry(0);
    MetaStorage storage = new NonPersistentStoreFactory().createMetaStorage();
    registry.setMetaStorage(storage);
    // Create test role
    Role role = new Role("role", "role", storage);
    storage.addRole(role);
    role.addPermission(DatasetPermission.onInstance(Ability.READ, new DatasetId("dataset0")));
    // Create test group
    Group group = new Group("group", "group", storage);
    storage.addGroup(group);
    group.addPermission(DatasetPermission.onInstance(Ability.READ, new DatasetId("dataset1")));
    // Create original user with role and group mapping
    User originUser = new User("user", "user", storage);
    storage.addUser(originUser);
    originUser.addRole(role);
    group.addMember(originUser);
    // Do copy
    User copy = AuthorizationController.flatCopyUser(originUser, "copytest", storage);
    // Check that it is not the same user
    assertThat(copy).usingRecursiveComparison().isNotEqualTo(originUser);
    // Check that the copy does not have any mappings
    assertThat(group.containsMember(copy)).isFalse();
    assertThat(copy.getRoles()).isEmpty();
    // Check that the flat map worked
    assertThat(copy.getPermissions()).containsExactlyInAnyOrderElementsOf(originUser.getEffectivePermissions());
}
Also used : Role(com.bakdata.conquery.models.auth.entities.Role) Group(com.bakdata.conquery.models.auth.entities.Group) User(com.bakdata.conquery.models.auth.entities.User) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) DatasetId(com.bakdata.conquery.models.identifiable.ids.specific.DatasetId) Test(org.junit.jupiter.api.Test)

Example 3 with NonPersistentStoreFactory

use of com.bakdata.conquery.util.NonPersistentStoreFactory in project conquery by bakdata.

the class DefaultLabelTest method beforeAll.

@BeforeAll
public static void beforeAll() {
    STORAGE.openStores(new NonPersistentStoreFactory());
    I18n.init();
    doAnswer((invocation -> {
        return CONCEPT;
    })).when(DATASET_REGISTRY).resolve(CONCEPT.getId());
}
Also used : CsvSource(org.junit.jupiter.params.provider.CsvSource) ManagedQuery(com.bakdata.conquery.models.query.ManagedQuery) ConqueryConfig(com.bakdata.conquery.models.config.ConqueryConfig) ManagedForm(com.bakdata.conquery.models.forms.managed.ManagedForm) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LocalDateTime(java.time.LocalDateTime) PrintSettings(com.bakdata.conquery.models.query.PrintSettings) BeforeAll(org.junit.jupiter.api.BeforeAll) Locale(java.util.Locale) Mockito.doAnswer(org.mockito.Mockito.doAnswer) I18n(com.bakdata.conquery.models.i18n.I18n) CQAnd(com.bakdata.conquery.apiv1.query.concept.specific.CQAnd) TreeConcept(com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept) AUTO_LABEL_SUFFIX(com.bakdata.conquery.models.execution.ManagedExecution.AUTO_LABEL_SUFFIX) CQExternal(com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal) UUID(java.util.UUID) User(com.bakdata.conquery.models.auth.entities.User) Dataset(com.bakdata.conquery.models.datasets.Dataset) ExportForm(com.bakdata.conquery.apiv1.forms.export_form.ExportForm) ConceptQuery(com.bakdata.conquery.apiv1.query.ConceptQuery) Mockito(org.mockito.Mockito) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DatasetRegistry(com.bakdata.conquery.models.worker.DatasetRegistry) CQReusedQuery(com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery) CQConcept(com.bakdata.conquery.apiv1.query.concept.specific.CQConcept) NotNull(org.jetbrains.annotations.NotNull) MetaStorage(com.bakdata.conquery.io.storage.MetaStorage) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) NonPersistentStoreFactory(com.bakdata.conquery.util.NonPersistentStoreFactory) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

DatasetRegistry (com.bakdata.conquery.models.worker.DatasetRegistry)3 NonPersistentStoreFactory (com.bakdata.conquery.util.NonPersistentStoreFactory)3 MetaStorage (com.bakdata.conquery.io.storage.MetaStorage)2 User (com.bakdata.conquery.models.auth.entities.User)2 DatasetId (com.bakdata.conquery.models.identifiable.ids.specific.DatasetId)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 ExportForm (com.bakdata.conquery.apiv1.forms.export_form.ExportForm)1 ConceptQuery (com.bakdata.conquery.apiv1.query.ConceptQuery)1 CQAnd (com.bakdata.conquery.apiv1.query.concept.specific.CQAnd)1 CQConcept (com.bakdata.conquery.apiv1.query.concept.specific.CQConcept)1 CQReusedQuery (com.bakdata.conquery.apiv1.query.concept.specific.CQReusedQuery)1 CQExternal (com.bakdata.conquery.apiv1.query.concept.specific.external.CQExternal)1 MutableInjectableValues (com.bakdata.conquery.io.jackson.MutableInjectableValues)1 AuthorizationController (com.bakdata.conquery.models.auth.AuthorizationController)1 Group (com.bakdata.conquery.models.auth.entities.Group)1 Role (com.bakdata.conquery.models.auth.entities.Role)1 ConqueryConfig (com.bakdata.conquery.models.config.ConqueryConfig)1 DevelopmentAuthorizationConfig (com.bakdata.conquery.models.config.auth.DevelopmentAuthorizationConfig)1 Dataset (com.bakdata.conquery.models.datasets.Dataset)1 TreeConcept (com.bakdata.conquery.models.datasets.concepts.tree.TreeConcept)1