/** * Creates a new {@link StoreAdapter} on top of a newly created {@link Backend}, using the current {@link * #factory}. * * @param config the configuration of the store/back-end * * @return a new store */ @Nonnull private StoreAdapter createStore(ImmutableConfig config) { return createStore(factory.createBackend(uri, config), config); }
@Nonnull @Override public BackendFactory factory() { BackendFactory factory = mock(InMemoryBackendFactory.class); when(factory.supportsTransient()).thenCallRealMethod(); when(factory.createBackend(any(URI.class), any(ImmutableConfig.class))).thenAnswer((i) -> new BoundInMemoryBackend(id)); return factory; } }
@Test void createResourceRegistered() { PersistentResourceFactory resourceFactory = PersistentResourceFactory.getInstance(); URI uri = mock(URI.class); when(uri.scheme()).thenReturn("mock0"); Backend backend = mock(InMemoryBackend.class); BackendFactory backendFactory = mock(BackendFactory.class); when(backendFactory.createBackend(any(URI.class), any(ImmutableConfig.class))).thenReturn(backend); BackendFactoryRegistry.getInstance().register(uri.scheme(), backendFactory); PersistentResource resource = resourceFactory.createResource(uri); assertThat(resource).isNotNull(); assertThat(resource.getURI()).isSameAs(uri); assertThat(resource.eStore()).isNotNull(); BackendFactoryRegistry.getInstance().unregister(uri.scheme()); }
/** * Creates a new {@link DataMapper} according to the specified options. * * @return a new {@link DataMapper} * * @see Context#config() * @see #defaultConfig() */ @Nonnull public DataMapper createMapper() { Backend backend = context.factory().createBackend(uri, defaultConfig()); return StoreFactory.getInstance().createStore(backend, defaultConfig()); } }
/** * Checks the creation of a {@link fr.inria.atlanmod.neoemf.data.Backend}. */ @ParameterizedTest @MethodSource("allMappings") public void testCreateBackend(ImmutableConfig config, Class<? extends Backend> expectedType) throws IOException { try (Backend backend = context().factory().createBackend(context().createUri(currentTempFile()), config)) { assertThat(backend).isInstanceOf(expectedType); } }
/** * Check the creation of chaining between the default {@link Store}s and a {@link Backend}. */ @Test public void testCreatePersistentStore() throws IOException { try (Backend backend = context().factory().createBackend(context().createUri(currentTempFile()), context().config())) { try (Store store = StoreFactory.getInstance().createStore(backend, context().config())) { assertThat(store).isInstanceOf(NoopStore.class); assertThat(store.backend()).isSameAs(backend); } } }
/** * Checks the copy of a {@link Backend} to another. */ @Test public void testCopyBackend() throws IOException { ImmutableConfig config = context().config(); File file = currentTempFile(); try (Backend transientBackend = new InMemoryBackendFactory().createBackend(new InMemoryUriFactory().createLocalUri(file), new InMemoryConfig())) { try (Backend persistentBackend = context().factory().createBackend(context().createUri(currentTempFile()), config)) { transientBackend.copyTo(persistentBackend); } } }