Skip to content
This repository was archived by the owner on Mar 31, 2023. It is now read-only.

[Node Manager] Junit test with MockIgniteServer #201

Merged
merged 15 commits into from
May 21, 2020
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
@@ -1,6 +1,9 @@
#redis configuration
spring.redis.host=localhost
spring.redis.port=6380
#ignite configuration
ignite.host=localhost
ignite.port=10800
ignite.port=10801
ignite.key-store-path=keystore.jks
ignite.key-store-password=123456
ignite.trust-store-path=truststore.jks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package com.futurewei.alcor.nodemanager.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.futurewei.alcor.common.db.ignite.MockIgniteServer;
import com.futurewei.alcor.common.exception.ParameterUnexpectedValueException;
import com.futurewei.alcor.nodemanager.service.NodeService;
import com.futurewei.alcor.web.entity.NodeInfo;
Expand All @@ -35,15 +36,17 @@
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

import static org.junit.Assert.assertTrue;
import java.util.Objects;

import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@SpringBootTest()
@AutoConfigureMockMvc
public class NodeControllerTest {
public class NodeControllerTest extends MockIgniteServer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the node manager UTs currently need MockIgniteServer as it doesn't have real e2e test cases. But it is okay to add in advance so that you could add more e2e UTs in the future.

private static final ObjectMapper om = new ObjectMapper();
@MockBean
NodeService service;
Expand Down Expand Up @@ -125,7 +128,7 @@ public void test_createNodeInfo_invalidInputNull() throws Exception {
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isBadRequest())
.andExpect((rslt) -> assertTrue(rslt.getResolvedException().getClass() != null));
.andExpect((rslt) -> assertNotNull(Objects.requireNonNull(rslt.getResolvedException()).getClass()));
}

@Test
Expand Down Expand Up @@ -182,7 +185,7 @@ public void test_getNodeInfoByNodeId_invalidId() throws Exception {
MvcResult result = this.mockMvc.perform(get("/nodes/" + strNodeId))
.andDo(print())
.andReturn();
assertTrue(result.getResponse().getContentAsString().length() == 0);
assertEquals(0, result.getResponse().getContentAsString().length());
}

@Test
Expand All @@ -193,7 +196,7 @@ public void deleteNodeInfo() throws Exception {
.andDo(print())
.andExpect(status().isOk())
.andReturn();
assertTrue(result.getResponse().getContentAsString().equals(strNodeId));
assertEquals(result.getResponse().getContentAsString(), strNodeId);
}

@Test
Expand All @@ -202,6 +205,6 @@ public void deleteNodeInfo_invalidId() throws Exception {
MvcResult result = this.mockMvc.perform(delete("/nodes/" + strNodeId))
.andDo(print())
.andReturn();
assertTrue(result.getResponse().getContentAsString().length() == 0);
assertEquals(0, result.getResponse().getContentAsString().length());
}
}