forked from unitycatalog/unitycatalog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build/sbt javafmtAll on tests in server module (unitycatalog#194)
**PR Checklist** - [x] A description of the changes is added to the description of this PR. - [ ] If there is a related issue, make sure it is linked to this PR. - [ ] If you've fixed a bug or added code that should be tested, add tests! - [ ] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** This formats the tests in the`server` module
- Loading branch information
Showing
22 changed files
with
1,112 additions
and
986 deletions.
There are no files selected for viewing
49 changes: 24 additions & 25 deletions
49
server/src/test/java/io/unitycatalog/server/base/BaseCRUDTest.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 |
---|---|---|
@@ -1,41 +1,40 @@ | ||
package io.unitycatalog.server.base; | ||
|
||
import static io.unitycatalog.server.utils.TestUtils.CATALOG_NAME; | ||
import static io.unitycatalog.server.utils.TestUtils.CATALOG_NEW_NAME; | ||
|
||
import io.unitycatalog.server.base.catalog.CatalogOperations; | ||
import java.util.Optional; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Optional; | ||
|
||
import static io.unitycatalog.server.utils.TestUtils.CATALOG_NAME; | ||
import static io.unitycatalog.server.utils.TestUtils.CATALOG_NEW_NAME; | ||
|
||
@RunWith(Parameterized.class) | ||
public abstract class BaseCRUDTest extends BaseServerTest { | ||
|
||
protected CatalogOperations catalogOperations; | ||
protected CatalogOperations catalogOperations; | ||
|
||
@After | ||
public void cleanUp() { | ||
try { | ||
catalogOperations.deleteCatalog(CATALOG_NAME, Optional.of(true)); | ||
} catch (Exception e) { | ||
// Ignore | ||
} | ||
try { | ||
catalogOperations.deleteCatalog(CATALOG_NEW_NAME, Optional.of(true)); | ||
} catch (Exception e) { | ||
// Ignore | ||
} | ||
@After | ||
public void cleanUp() { | ||
try { | ||
catalogOperations.deleteCatalog(CATALOG_NAME, Optional.of(true)); | ||
} catch (Exception e) { | ||
// Ignore | ||
} | ||
|
||
@Before | ||
@Override | ||
public void setUp() { | ||
super.setUp(); | ||
catalogOperations = createCatalogOperations(serverConfig); | ||
try { | ||
catalogOperations.deleteCatalog(CATALOG_NEW_NAME, Optional.of(true)); | ||
} catch (Exception e) { | ||
// Ignore | ||
} | ||
} | ||
|
||
@Before | ||
@Override | ||
public void setUp() { | ||
super.setUp(); | ||
catalogOperations = createCatalogOperations(serverConfig); | ||
} | ||
|
||
protected abstract CatalogOperations createCatalogOperations(ServerConfig serverConfig); | ||
protected abstract CatalogOperations createCatalogOperations(ServerConfig serverConfig); | ||
} |
86 changes: 40 additions & 46 deletions
86
server/src/test/java/io/unitycatalog/server/base/BaseServerTest.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 |
---|---|---|
@@ -1,64 +1,58 @@ | ||
package io.unitycatalog.server.base; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import io.unitycatalog.server.UnityCatalogServer; | ||
import io.unitycatalog.server.utils.TestUtils; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import org.junit.After; | ||
import org.junit.AfterClass; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
@RunWith(Parameterized.class) | ||
public abstract class BaseServerTest { | ||
|
||
@Parameterized.Parameter | ||
public static ServerConfig serverConfig; | ||
private static UnityCatalogServer unityCatalogServer; | ||
@Parameterized.Parameter public static ServerConfig serverConfig; | ||
private static UnityCatalogServer unityCatalogServer; | ||
|
||
/** | ||
* To test against UC server, add | ||
* UC server endpoint as server URL and PAT token as auth token | ||
* e.g. ServerConfig("https://<server-url>", "<PAT-token>") | ||
* Multiple server configurations can be added to test against multiple servers | ||
* @return | ||
*/ | ||
@Parameterized.Parameters | ||
public static Collection<ServerConfig> data() { | ||
return List.of( | ||
new ServerConfig("http://localhost", "") | ||
); | ||
} | ||
/** | ||
* To test against UC server, add UC server endpoint as server URL and PAT token as auth token | ||
* e.g. ServerConfig("https://<server-url>", "<PAT-token>") Multiple server configurations can be | ||
* added to test against multiple servers | ||
* | ||
* @return | ||
*/ | ||
@Parameterized.Parameters | ||
public static Collection<ServerConfig> data() { | ||
return List.of(new ServerConfig("http://localhost", "")); | ||
} | ||
|
||
@Before | ||
public void setUp() { | ||
if (serverConfig == null) { | ||
throw new IllegalArgumentException("Server config is required"); | ||
} | ||
if (serverConfig.getServerUrl() == null) { | ||
throw new IllegalArgumentException("Server URL is required"); | ||
} | ||
if (serverConfig.getAuthToken() == null) { | ||
throw new IllegalArgumentException("Auth token is required"); | ||
} | ||
if (serverConfig.getServerUrl().contains("localhost")) { | ||
System.out.println("Running tests on localhost.."); | ||
// start the server on a random port | ||
int port = TestUtils.getRandomPort(); | ||
System.setProperty("server.env", "test"); | ||
unityCatalogServer = new UnityCatalogServer(port); | ||
unityCatalogServer.start(); | ||
serverConfig.setServerUrl("http://localhost:" + port); | ||
} | ||
@Before | ||
public void setUp() { | ||
if (serverConfig == null) { | ||
throw new IllegalArgumentException("Server config is required"); | ||
} | ||
if (serverConfig.getServerUrl() == null) { | ||
throw new IllegalArgumentException("Server URL is required"); | ||
} | ||
if (serverConfig.getAuthToken() == null) { | ||
throw new IllegalArgumentException("Auth token is required"); | ||
} | ||
if (serverConfig.getServerUrl().contains("localhost")) { | ||
System.out.println("Running tests on localhost.."); | ||
// start the server on a random port | ||
int port = TestUtils.getRandomPort(); | ||
System.setProperty("server.env", "test"); | ||
unityCatalogServer = new UnityCatalogServer(port); | ||
unityCatalogServer.start(); | ||
serverConfig.setServerUrl("http://localhost:" + port); | ||
} | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
if (unityCatalogServer != null) { | ||
unityCatalogServer.stop(); | ||
} | ||
@After | ||
public void tearDown() { | ||
if (unityCatalogServer != null) { | ||
unityCatalogServer.stop(); | ||
} | ||
} | ||
} |
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
126 changes: 62 additions & 64 deletions
126
server/src/test/java/io/unitycatalog/server/base/catalog/BaseCatalogCRUDTest.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 |
---|---|---|
@@ -1,85 +1,83 @@ | ||
package io.unitycatalog.server.base.catalog; | ||
|
||
import static io.unitycatalog.server.utils.TestUtils.*; | ||
|
||
import io.unitycatalog.client.ApiException; | ||
import io.unitycatalog.client.model.CatalogInfo; | ||
import io.unitycatalog.client.model.CreateCatalog; | ||
import io.unitycatalog.client.model.UpdateCatalog; | ||
import io.unitycatalog.server.base.BaseCRUDTest; | ||
import io.unitycatalog.server.persist.PropertyRepository; | ||
import org.junit.*; | ||
|
||
import io.unitycatalog.client.model.CatalogInfo; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import static io.unitycatalog.server.utils.TestUtils.*; | ||
import org.junit.*; | ||
|
||
public abstract class BaseCatalogCRUDTest extends BaseCRUDTest { | ||
|
||
protected void assertCatalog(CatalogInfo catalogInfo, String name, String comment) { | ||
Assert.assertEquals(name, catalogInfo.getName()); | ||
Assert.assertEquals(comment, catalogInfo.getComment()); | ||
Assert.assertNotNull(catalogInfo.getCreatedAt()); | ||
// TODO: Also assert properties once CLI supports it | ||
} | ||
protected void assertCatalog(CatalogInfo catalogInfo, String name, String comment) { | ||
Assert.assertEquals(name, catalogInfo.getName()); | ||
Assert.assertEquals(comment, catalogInfo.getComment()); | ||
Assert.assertNotNull(catalogInfo.getCreatedAt()); | ||
// TODO: Also assert properties once CLI supports it | ||
} | ||
|
||
protected void assertCatalogExists(List<CatalogInfo> catalogList, String name, String comment) { | ||
Assert.assertTrue(catalogList.stream().anyMatch(c -> | ||
Objects.equals(c.getName(), name) && Objects.equals(c.getComment(), comment))); | ||
} | ||
protected void assertCatalogExists(List<CatalogInfo> catalogList, String name, String comment) { | ||
Assert.assertTrue( | ||
catalogList.stream() | ||
.anyMatch( | ||
c -> Objects.equals(c.getName(), name) && Objects.equals(c.getComment(), comment))); | ||
} | ||
|
||
protected void assertCatalogNotExists(List<CatalogInfo> catalogList, String name) { | ||
Assert.assertFalse(catalogList.stream().anyMatch(c -> | ||
Objects.equals(c.getName(), name))); | ||
} | ||
protected void assertCatalogNotExists(List<CatalogInfo> catalogList, String name) { | ||
Assert.assertFalse(catalogList.stream().anyMatch(c -> Objects.equals(c.getName(), name))); | ||
} | ||
|
||
@Test | ||
public void testCatalogCRUD() throws ApiException { | ||
// Create a catalog | ||
System.out.println("Testing create catalog.."); | ||
CreateCatalog createCatalog = new CreateCatalog() | ||
.name(CATALOG_NAME) | ||
.comment(COMMENT) | ||
.properties(PROPERTIES); | ||
CatalogInfo catalogInfo = catalogOperations.createCatalog(createCatalog); | ||
assertCatalog(catalogInfo, CATALOG_NAME, COMMENT); | ||
@Test | ||
public void testCatalogCRUD() throws ApiException { | ||
// Create a catalog | ||
System.out.println("Testing create catalog.."); | ||
CreateCatalog createCatalog = | ||
new CreateCatalog().name(CATALOG_NAME).comment(COMMENT).properties(PROPERTIES); | ||
CatalogInfo catalogInfo = catalogOperations.createCatalog(createCatalog); | ||
assertCatalog(catalogInfo, CATALOG_NAME, COMMENT); | ||
|
||
// List catalogs | ||
System.out.println("Testing list catalogs.."); | ||
List<CatalogInfo> catalogList = catalogOperations.listCatalogs(); | ||
Assert.assertNotNull(catalogList); | ||
assertCatalogExists(catalogList, CATALOG_NAME, COMMENT); | ||
// List catalogs | ||
System.out.println("Testing list catalogs.."); | ||
List<CatalogInfo> catalogList = catalogOperations.listCatalogs(); | ||
Assert.assertNotNull(catalogList); | ||
assertCatalogExists(catalogList, CATALOG_NAME, COMMENT); | ||
|
||
// Get catalog | ||
System.out.println("Testing get catalog.."); | ||
CatalogInfo catalogInfo2 = catalogOperations.getCatalog(CATALOG_NAME); | ||
Assert.assertEquals(catalogInfo, catalogInfo2); | ||
// Get catalog | ||
System.out.println("Testing get catalog.."); | ||
CatalogInfo catalogInfo2 = catalogOperations.getCatalog(CATALOG_NAME); | ||
Assert.assertEquals(catalogInfo, catalogInfo2); | ||
|
||
// Calling update catalog with nothing to update should not change anything | ||
System.out.println("Testing updating catalog with nothing to update.."); | ||
UpdateCatalog emptyUpdateCatalog = new UpdateCatalog(); | ||
CatalogInfo emptyUpdateCatalogInfo = catalogOperations.updateCatalog(CATALOG_NAME, emptyUpdateCatalog); | ||
CatalogInfo catalogInfo3 = catalogOperations.getCatalog(CATALOG_NAME); | ||
Assert.assertEquals(catalogInfo, catalogInfo3); | ||
// Calling update catalog with nothing to update should not change anything | ||
System.out.println("Testing updating catalog with nothing to update.."); | ||
UpdateCatalog emptyUpdateCatalog = new UpdateCatalog(); | ||
CatalogInfo emptyUpdateCatalogInfo = | ||
catalogOperations.updateCatalog(CATALOG_NAME, emptyUpdateCatalog); | ||
CatalogInfo catalogInfo3 = catalogOperations.getCatalog(CATALOG_NAME); | ||
Assert.assertEquals(catalogInfo, catalogInfo3); | ||
|
||
// Update catalog name without updating comment | ||
System.out.println("Testing update catalog: changing name.."); | ||
UpdateCatalog updateCatalog = new UpdateCatalog().newName(CATALOG_NEW_NAME); | ||
CatalogInfo updatedCatalogInfo = catalogOperations.updateCatalog(CATALOG_NAME, updateCatalog); | ||
assertCatalog(updatedCatalogInfo, CATALOG_NEW_NAME, COMMENT); | ||
// Update catalog name without updating comment | ||
System.out.println("Testing update catalog: changing name.."); | ||
UpdateCatalog updateCatalog = new UpdateCatalog().newName(CATALOG_NEW_NAME); | ||
CatalogInfo updatedCatalogInfo = catalogOperations.updateCatalog(CATALOG_NAME, updateCatalog); | ||
assertCatalog(updatedCatalogInfo, CATALOG_NEW_NAME, COMMENT); | ||
|
||
// Update catalog comment without updating name | ||
System.out.println("Testing update catalog: changing comment.."); | ||
UpdateCatalog updateCatalog2 = new UpdateCatalog().comment(CATALOG_NEW_COMMENT); | ||
CatalogInfo updatedCatalogInfo2 = catalogOperations.updateCatalog(CATALOG_NEW_NAME, updateCatalog2); | ||
assertCatalog(updatedCatalogInfo2, CATALOG_NEW_NAME, CATALOG_NEW_COMMENT); | ||
// Update catalog comment without updating name | ||
System.out.println("Testing update catalog: changing comment.."); | ||
UpdateCatalog updateCatalog2 = new UpdateCatalog().comment(CATALOG_NEW_COMMENT); | ||
CatalogInfo updatedCatalogInfo2 = | ||
catalogOperations.updateCatalog(CATALOG_NEW_NAME, updateCatalog2); | ||
assertCatalog(updatedCatalogInfo2, CATALOG_NEW_NAME, CATALOG_NEW_COMMENT); | ||
|
||
// Delete catalog | ||
System.out.println("Testing delete catalog.."); | ||
catalogOperations.deleteCatalog(CATALOG_NEW_NAME, Optional.of(false)); | ||
catalogList = catalogOperations.listCatalogs(); | ||
Assert.assertNotNull(catalogList); | ||
assertCatalogNotExists(catalogList, CATALOG_NEW_NAME); | ||
} | ||
} | ||
// Delete catalog | ||
System.out.println("Testing delete catalog.."); | ||
catalogOperations.deleteCatalog(CATALOG_NEW_NAME, Optional.of(false)); | ||
catalogList = catalogOperations.listCatalogs(); | ||
Assert.assertNotNull(catalogList); | ||
assertCatalogNotExists(catalogList, CATALOG_NEW_NAME); | ||
} | ||
} |
18 changes: 10 additions & 8 deletions
18
server/src/test/java/io/unitycatalog/server/base/catalog/CatalogOperations.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 |
---|---|---|
@@ -1,18 +1,20 @@ | ||
package io.unitycatalog.server.base.catalog; | ||
|
||
|
||
import io.unitycatalog.client.ApiException; | ||
import io.unitycatalog.client.model.CatalogInfo; | ||
import io.unitycatalog.client.model.CreateCatalog; | ||
import io.unitycatalog.client.model.UpdateCatalog; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface CatalogOperations { | ||
CatalogInfo createCatalog(CreateCatalog createCatalog) throws ApiException; | ||
List<CatalogInfo> listCatalogs() throws ApiException; | ||
CatalogInfo getCatalog(String name) throws ApiException; | ||
CatalogInfo updateCatalog(String name, UpdateCatalog updateCatalog) throws ApiException; | ||
void deleteCatalog(String name, Optional<Boolean> force) throws ApiException; | ||
} | ||
CatalogInfo createCatalog(CreateCatalog createCatalog) throws ApiException; | ||
|
||
List<CatalogInfo> listCatalogs() throws ApiException; | ||
|
||
CatalogInfo getCatalog(String name) throws ApiException; | ||
|
||
CatalogInfo updateCatalog(String name, UpdateCatalog updateCatalog) throws ApiException; | ||
|
||
void deleteCatalog(String name, Optional<Boolean> force) throws ApiException; | ||
} |
Oops, something went wrong.