From 4ff8e684ecfe7b4aa24b7b042b691b921e752732 Mon Sep 17 00:00:00 2001 From: s7monk <“15512826113@163.com”> Date: Mon, 15 Jan 2024 11:21:18 +0800 Subject: [PATCH] fix test. --- .../controller/CatalogControllerTest.java | 36 ++++++++++++++++++- .../controller/DatabaseControllerTest.java | 18 ++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/CatalogControllerTest.java b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/CatalogControllerTest.java index 6f8d7e2c0..46ff60c33 100644 --- a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/CatalogControllerTest.java +++ b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/CatalogControllerTest.java @@ -24,6 +24,7 @@ import org.apache.paimon.web.server.util.ObjectMapperUtils; import com.fasterxml.jackson.core.type.TypeReference; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -47,6 +48,8 @@ public class CatalogControllerTest extends ControllerTestBase { private static final String catalogName = "testCatalog"; + private Integer catalogId; + @BeforeEach public void setup() throws Exception { CatalogDTO catalog = new CatalogDTO(); @@ -62,6 +65,37 @@ public void setup() throws Exception { .contentType(MediaType.APPLICATION_JSON_VALUE) .accept(MediaType.APPLICATION_JSON_VALUE)) .andExpect(MockMvcResultMatchers.status().isOk()); + + // get catalog id. + String responseString = + mockMvc.perform( + MockMvcRequestBuilders.get(catalogPath + "/list") + .cookie(cookie) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andDo(MockMvcResultHandlers.print()) + .andReturn() + .getResponse() + .getContentAsString(); + R> r = + ObjectMapperUtils.fromJSON( + responseString, new TypeReference>>() {}); + catalogId = r.getData().get(0).getId(); + } + + @AfterEach + public void after() throws Exception { + CatalogDTO removeCatalog = new CatalogDTO(); + removeCatalog.setId(catalogId); + removeCatalog.setName(catalogName); + mockMvc.perform( + MockMvcRequestBuilders.post(catalogPath + "/remove") + .cookie(cookie) + .content(ObjectMapperUtils.toJSON(removeCatalog)) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(MockMvcResultMatchers.status().isOk()); } @Test @@ -90,7 +124,7 @@ public void testGetCatalog() throws Exception { @Test public void testRemoveCatalog() throws Exception { CatalogDTO removeCatalog = new CatalogDTO(); - removeCatalog.setId(1); + removeCatalog.setId(catalogId); removeCatalog.setName(catalogName); String responseString = diff --git a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/DatabaseControllerTest.java b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/DatabaseControllerTest.java index 8dc46c974..73eec86c8 100644 --- a/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/DatabaseControllerTest.java +++ b/paimon-web-server/src/test/java/org/apache/paimon/web/server/controller/DatabaseControllerTest.java @@ -26,6 +26,7 @@ import org.apache.paimon.web.server.util.ObjectMapperUtils; import com.fasterxml.jackson.core.type.TypeReference; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -104,6 +105,23 @@ public void setup() throws Exception { .andExpect(MockMvcResultMatchers.status().isOk()); } + @AfterEach + public void after() throws Exception { + DatabaseDTO dropDatabase = new DatabaseDTO(); + dropDatabase.setCatalogName(catalogName); + dropDatabase.setCatalogId(catalogId); + dropDatabase.setName(databaseName); + dropDatabase.setIgnoreIfExists(true); + dropDatabase.setCascade(true); + mockMvc.perform( + MockMvcRequestBuilders.post(databasePath + "/drop") + .cookie(cookie) + .content(ObjectMapperUtils.toJSON(dropDatabase)) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(MockMvcResultMatchers.status().isOk()); + } + @Test public void testListDatabases() throws Exception { String responseString =