-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add handling for system namespace to CheckedDistributedStorageAdmin
- Loading branch information
Showing
7 changed files
with
104 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
core/src/test/java/com/scalar/db/common/CheckedDistributedStorageAdminTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.scalar.db.common; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.scalar.db.api.DistributedStorageAdmin; | ||
import com.scalar.db.config.DatabaseConfig; | ||
import com.scalar.db.exception.storage.ExecutionException; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
public class CheckedDistributedStorageAdminTest { | ||
|
||
private static final String SYSTEM_NAMESPACE = "scalardb"; | ||
|
||
@Mock private DistributedStorageAdmin admin; | ||
@Mock private DatabaseConfig databaseConfig; | ||
|
||
private CheckedDistributedStorageAdmin checkedAdmin; | ||
|
||
@BeforeEach | ||
public void setUp() throws Exception { | ||
MockitoAnnotations.openMocks(this).close(); | ||
|
||
// Arrange | ||
when(databaseConfig.getSystemNamespaceName()).thenReturn(SYSTEM_NAMESPACE); | ||
checkedAdmin = new CheckedDistributedStorageAdmin(admin, databaseConfig); | ||
} | ||
|
||
@Test | ||
public void createNamespace_SystemNamespaceNameGiven_ShouldThrowIllegalArgumentException() { | ||
// Arrange | ||
|
||
// Act Assert | ||
assertThatThrownBy(() -> checkedAdmin.createNamespace(SYSTEM_NAMESPACE)) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
public void dropNamespace_SystemNamespaceNameGiven_ShouldThrowIllegalArgumentException() { | ||
// Arrange | ||
|
||
// Act Assert | ||
assertThatThrownBy(() -> checkedAdmin.dropNamespace(SYSTEM_NAMESPACE)) | ||
.isInstanceOf(IllegalArgumentException.class); | ||
} | ||
|
||
@Test | ||
public void namespaceExists_SystemNamespaceNameGiven_ShouldReturnTrue() | ||
throws ExecutionException { | ||
// Arrange | ||
|
||
// Act | ||
boolean actual = checkedAdmin.namespaceExists(SYSTEM_NAMESPACE); | ||
|
||
// Assert | ||
assertThat(actual).isTrue(); | ||
} | ||
|
||
@Test | ||
public void getNamespaceNames_ShouldReturnListWithSystemNamespaceName() | ||
throws ExecutionException { | ||
// Arrange | ||
when(admin.getNamespaceNames()).thenReturn(Collections.emptySet()); | ||
|
||
// Act | ||
Set<String> actual = checkedAdmin.getNamespaceNames(); | ||
|
||
// Assert | ||
assertThat(actual).containsExactly(SYSTEM_NAMESPACE); | ||
} | ||
} |