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();
}
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());
}
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());
}
Aggregations