Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public List<FileEntry> getFileEntriesWithoutContent(List<FileEntry> fileEntries)

@Override
protected boolean existsInObjectStore(FileEntry fileEntry) {
return blobStore.blobMetadata(container, fileEntry.getId()) != null;
return blobStore.blobExists(container, fileEntry.getId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

class JCloudsObjectStoreFileStorageTest {

Expand Down Expand Up @@ -368,4 +376,47 @@ protected void assertFileExists(boolean expectedFileExist, FileEntry actualFile)
assertEquals(expectedFileExist, blobExists);
}

@Test
void existsInObjectStoreWithMockedBlobStoreVerifiesBlobExistsCalled() {
BlobStore mockBlobStore = mock(BlobStore.class);
FileEntry fileEntry = createFileEntry();
JCloudsObjectStoreFileStorage testFileStorage = new JCloudsObjectStoreFileStorage(mockBlobStore, CONTAINER);

when(mockBlobStore.blobExists(CONTAINER, fileEntry.getId())).thenReturn(true);

boolean result = testFileStorage.existsInObjectStore(fileEntry);

verify(mockBlobStore, times(1)).blobExists(CONTAINER, fileEntry.getId());
assertTrue(result);
}

@Test
void existsInObjectStoreWithMockedBlobStoreFileNotFound() {
BlobStore mockBlobStore = mock(BlobStore.class);
FileEntry fileEntry = createFileEntry();
JCloudsObjectStoreFileStorage testFileStorage = new JCloudsObjectStoreFileStorage(mockBlobStore, CONTAINER);

when(mockBlobStore.blobExists(CONTAINER, fileEntry.getId())).thenReturn(false);

boolean result = testFileStorage.existsInObjectStore(fileEntry);

verify(mockBlobStore, times(1)).blobExists(CONTAINER, fileEntry.getId());
assertFalse(result);
}

@Test
void existsInObjectStoreWithMockedBlobStoreVerifiesCorrectContainer() {
BlobStore mockBlobStore = mock(BlobStore.class);
String testContainer = "test-container";
FileEntry fileEntry = createFileEntry();
JCloudsObjectStoreFileStorage testFileStorage = new JCloudsObjectStoreFileStorage(mockBlobStore, testContainer);

when(mockBlobStore.blobExists(testContainer, fileEntry.getId())).thenReturn(true);

boolean result = testFileStorage.existsInObjectStore(fileEntry);

verify(mockBlobStore, times(1)).blobExists(testContainer, fileEntry.getId());
verify(mockBlobStore, never()).blobExists(eq("wrong-container"), any());
assertTrue(result);
}
}
Loading