Skip to content

Commit

Permalink
fix test.
Browse files Browse the repository at this point in the history
  • Loading branch information
s7monk committed Jan 15, 2024
1 parent 6ee995e commit 4ff8e68
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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<List<CatalogInfo>> r =
ObjectMapperUtils.fromJSON(
responseString, new TypeReference<R<List<CatalogInfo>>>() {});
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
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit 4ff8e68

Please sign in to comment.