Skip to content

Commit

Permalink
[ISSUE #12017] Fix test unit bugs (#12808)
Browse files Browse the repository at this point in the history
* Fix config clone test unit bugs

* Fix server state test unit bugs
  • Loading branch information
RickonZhang0929 authored Nov 1, 2024
1 parent c9cf4c1 commit 8e01081
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.alibaba.nacos.console.controller.v3;

import com.alibaba.nacos.api.model.v2.Result;
import com.alibaba.nacos.common.http.param.MediaType;
import com.alibaba.nacos.console.proxy.ServerStateProxy;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -63,20 +64,23 @@ void setUp() {

@Test
void testServerState() throws Exception {

Map<String, String> state = new HashMap<>();
state.put("state", "OK");

when(serverStateProxy.getServerState()).thenReturn(state);

MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/v3/console/server/state");


MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get("/v3/console/server/state")
.contentType(MediaType.APPLICATION_JSON);

MockHttpServletResponse response = mockMvc.perform(builder).andReturn().getResponse();
String actualValue = response.getContentAsString();
Result<Map<String, String>> result = new ObjectMapper().readValue(actualValue,
new TypeReference<Result<Map<String, String>>>() {

Map<String, String> result = new ObjectMapper().readValue(actualValue,
new TypeReference<Map<String, String>>() {
});
assertEquals("OK", result.getData().get("state"));

assertEquals("OK", result.get("state"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public boolean matches(List<SameNamespaceCloneConfigBean> argument) {
)).thenReturn(expectedResult);

MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.post("/v3/console/cs/config/clone")
.param("src_user", "testUser").param("namespaceId", "testNamespace").param("policy", "ABORT")
.param("src_user", "testUser").param("targetNamespaceId", "testNamespace").param("policy", "ABORT")
.content(new ObjectMapper().writeValueAsString(configBeansList)).contentType(MediaType.APPLICATION_JSON)
.header("X-Real-IP", "127.0.0.1").header("X-Forwarded-For", "127.0.0.1");

Expand Down

0 comments on commit 8e01081

Please sign in to comment.