LocalStorageServiceFactoryImpl implements StorageServiceFactory { @Override public StorageService getStorageService(String instanceId, String bagName) throws JasDBStorageException { String storageServiceKey = instanceId + "_" + bagName; if(storageServices.containsKey(storageServiceKey)) { return storageServices.get(storageServiceKey); } else if(metadataStore.containsBag(instanceId, bagName)) { return getOrCreateStorageService(instanceId, bagName); } return null; }  @PostConstruct void initializeServices(); @Override StorageService getStorageService(String instanceId, String bagName); @Override StorageService getOrCreateStorageService(String instanceId, String bagName); @Override void removeStorageService(String instanceId, String bagName); @Override void removeAllStorageService(String instanceId); @Override void shutdownServiceFactory();  }
@Test public void testGetStorageService() throws Exception { when(metadataStore.containsBag(TEST_INSTANCE, TEST_BAG_NAME)).thenReturn(true); when(metadataStore.containsInstance(TEST_INSTANCE)).thenReturn(true); when(metadataStore.getInstance(TEST_INSTANCE)).thenReturn(new InstanceMeta(TEST_INSTANCE, jasdbHomeFolder)); StorageService storageService = storageServiceFactory.getStorageService(TEST_INSTANCE, TEST_BAG_NAME); assertNotNull(storageService); assertThat(storageService, is(this.storageService)); verify(storageService, times(1)).openService(eq(configuration)); StorageService nonExistingStorageService = storageServiceFactory.getStorageService(TEST_INSTANCE, NONEXISTING_BAG); assertNull(nonExistingStorageService); nonExistingStorageService = storageServiceFactory.getStorageService(NONEXISTING_INSTANCE, NONEXISTING_BAG); assertNull(nonExistingStorageService); }