/** * Set the StoreSuitabilityCheck property * * @param value */ public void setValue(CompositeBlobStore.StoreSuitabilityCheck value) { setValue(value.name()); }
@Override protected void before() throws Throwable { super.before(); if (Objects.nonNull(initial)) { setValue(initial); } cleanUp(); }
@Theory public void testNoneOk(Object persistenceLocation) throws Exception { suitability.setValue(CompositeBlobStore.StoreSuitabilityCheck.NONE); BlobStore store = create(persistenceLocation); assertThat(store, notNullValue(BlobStore.class)); } }
@Test public void testNonDefaultSuitabilityOnAdd() throws Exception { suitability.setValue(CompositeBlobStore.StoreSuitabilityCheck.EMPTY); final BlobStoreInfo info = mock(BlobStoreInfo.class); when(info.getName()).thenReturn("testStore"); when(info.isEnabled()).thenReturn(true); BlobStore subStore = mock(BlobStore.class); when(info.createInstance(Mockito.any(), Mockito.any())) .thenAnswer( invocation -> { assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.EMPTY)); return subStore; }); store = create(); store.handleAddBlobStore(info); verify(info).createInstance(Mockito.any(), Mockito.any()); }
@Test public void testNonDefaultSuitabilityOnStartup() throws Exception { suitability.setValue(CompositeBlobStore.StoreSuitabilityCheck.EMPTY); assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.EMPTY)); final BlobStoreInfo info = mock(BlobStoreInfo.class); when(info.getName()).thenReturn("testStore"); when(info.isEnabled()).thenReturn(true); BlobStore subStore = mock(BlobStore.class); when(info.createInstance(Mockito.any(), Mockito.any())) .thenAnswer( invocation -> { // When this gets called we should be skipping suitability checks assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.NONE)); return subStore; }); configs.add(info); store = create(); verify(info).createInstance(Mockito.any(), Mockito.any()); // Should be back to default after startup. assertThat( CompositeBlobStore.getStoreSuitabilityCheck(), equalTo(CompositeBlobStore.StoreSuitabilityCheck.EMPTY)); }
@SuppressWarnings({"rawtypes", "unchecked"}) @Theory public void testEmptyFail(Object persistenceLocation) throws Exception { suitability.setValue(CompositeBlobStore.StoreSuitabilityCheck.EMPTY); assumeThat(persistenceLocation, (Matcher) not(empty())); exception.expect(EXCEPTION_CLASS); @SuppressWarnings("unused") BlobStore store = create(persistenceLocation); }
@SuppressWarnings({"rawtypes", "unchecked"}) @Theory public void testEmptyOk(Object persistenceLocation) throws Exception { suitability.setValue(CompositeBlobStore.StoreSuitabilityCheck.EMPTY); assumeThat(persistenceLocation, (Matcher) empty()); BlobStore store = create(persistenceLocation); assertThat(store, notNullValue(BlobStore.class)); }
@SuppressWarnings({"unchecked", "rawtypes"}) @Theory public void testExistingFail(Object persistenceLocation) throws Exception { suitability.setValue(CompositeBlobStore.StoreSuitabilityCheck.EXISTING); assumeThat(persistenceLocation, not(either(empty()).or((Matcher) existing()))); exception.expect(EXCEPTION_CLASS); @SuppressWarnings("unused") BlobStore store = create(persistenceLocation); }
@SuppressWarnings({"unchecked", "rawtypes"}) @Theory public void testExistingOk(Object persistenceLocation) throws Exception { suitability.setValue(CompositeBlobStore.StoreSuitabilityCheck.EXISTING); assumeThat(persistenceLocation, (either(empty()).or((Matcher) existing()))); BlobStore store = create(persistenceLocation); assertThat(store, notNullValue(BlobStore.class)); }