Search in sources :

Example 1 with MD5Util

use of com.alibaba.nacos.config.server.utils.MD5Util in project nacos by alibaba.

the class ConfigServletInnerTest method testDoPollingConfig.

@Test
public void testDoPollingConfig() throws Exception {
    final MockedStatic<MD5Util> md5Util = Mockito.mockStatic(MD5Util.class);
    Map<String, String> clientMd5Map = new HashMap<>();
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    List<String> changedGroups = new ArrayList<>();
    changedGroups.add("1");
    changedGroups.add("2");
    when(MD5Util.compareMd5(request, response, clientMd5Map)).thenReturn(changedGroups);
    when(MD5Util.compareMd5OldResult(changedGroups)).thenReturn("test-old");
    when(MD5Util.compareMd5ResultString(changedGroups)).thenReturn("test-new");
    String actualValue = configServletInner.doPollingConfig(request, response, clientMd5Map, 1);
    Assert.assertEquals(HttpServletResponse.SC_OK + "", actualValue);
    Assert.assertEquals("test-old", response.getHeader(Constants.PROBE_MODIFY_RESPONSE));
    Assert.assertEquals("test-new", response.getHeader(Constants.PROBE_MODIFY_RESPONSE_NEW));
    Assert.assertEquals("no-cache,no-store", response.getHeader("Cache-Control"));
    md5Util.close();
}
Also used : HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MD5Util(com.alibaba.nacos.config.server.utils.MD5Util) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

MD5Util (com.alibaba.nacos.config.server.utils.MD5Util)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1