Search in sources :

Example 1 with DynamicDataSource

use of com.alibaba.nacos.config.server.service.datasource.DynamicDataSource in project nacos by alibaba.

the class ConfigOpsControllerTest method testDerbyOps.

@Test
public void testDerbyOps() throws Exception {
    MockedStatic propertyUtil = Mockito.mockStatic(PropertyUtil.class);
    when(PropertyUtil.isEmbeddedStorage()).thenReturn(true);
    propertyUtil.close();
    Mockito.mockStatic(DynamicDataSource.class);
    DynamicDataSource dataSource = Mockito.mock(DynamicDataSource.class);
    when(DynamicDataSource.getInstance()).thenReturn(dataSource);
    LocalDataSourceServiceImpl dataSourceService = Mockito.mock(LocalDataSourceServiceImpl.class);
    when(dataSource.getDataSource()).thenReturn(dataSourceService);
    JdbcTemplate template = Mockito.mock(JdbcTemplate.class);
    when(dataSourceService.getJdbcTemplate()).thenReturn(template);
    when(template.queryForList("SELECT * FROM TEST")).thenReturn(new ArrayList<>());
    MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(Constants.OPS_CONTROLLER_PATH + "/derby").param("sql", "SELECT * FROM TEST");
    String actualValue = mockMvc.perform(builder).andReturn().getResponse().getContentAsString();
    Assert.assertEquals("200", JacksonUtils.toObj(actualValue).get("code").toString());
}
Also used : LocalDataSourceServiceImpl(com.alibaba.nacos.config.server.service.datasource.LocalDataSourceServiceImpl) MockedStatic(org.mockito.MockedStatic) DynamicDataSource(com.alibaba.nacos.config.server.service.datasource.DynamicDataSource) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.Test)

Aggregations

DynamicDataSource (com.alibaba.nacos.config.server.service.datasource.DynamicDataSource)1 LocalDataSourceServiceImpl (com.alibaba.nacos.config.server.service.datasource.LocalDataSourceServiceImpl)1 Test (org.junit.Test)1 MockedStatic (org.mockito.MockedStatic)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)1