Skip to content

Commit

Permalink
test case fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyiyue1102 committed Nov 5, 2024
1 parent a4339d6 commit 2624497
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import com.alibaba.nacos.config.server.model.ConfigInfo;
import com.alibaba.nacos.config.server.model.ConfigInfo4Beta;
import com.alibaba.nacos.config.server.model.ConfigInfo4Tag;
import com.alibaba.nacos.config.server.model.ConfigInfoAggr;
import com.alibaba.nacos.config.server.model.ConfigInfoBase;
import com.alibaba.nacos.config.server.model.ConfigInfoBetaWrapper;
import com.alibaba.nacos.config.server.model.ConfigInfoChanged;
import com.alibaba.nacos.config.server.model.ConfigInfoGrayWrapper;
import com.alibaba.nacos.config.server.model.ConfigInfoStateWrapper;
import com.alibaba.nacos.config.server.model.ConfigInfoTagWrapper;
import com.alibaba.nacos.config.server.model.ConfigInfoWrapper;
Expand Down Expand Up @@ -55,8 +55,8 @@ class ConfigRowMapperInjectorTest {
@Test
void testInit() {
ConfigRowMapperInjector configRowMapperInjector = new ConfigRowMapperInjector();
assertEquals(ConfigRowMapperInjector.CONFIG_INFO_WRAPPER_ROW_MAPPER,
RowMapperManager.getRowMapper(ConfigRowMapperInjector.CONFIG_INFO_WRAPPER_ROW_MAPPER.getClass().getCanonicalName()));
assertEquals(ConfigRowMapperInjector.CONFIG_INFO_WRAPPER_ROW_MAPPER, RowMapperManager.getRowMapper(
ConfigRowMapperInjector.CONFIG_INFO_WRAPPER_ROW_MAPPER.getClass().getCanonicalName()));
}

@Test
Expand Down Expand Up @@ -319,26 +319,37 @@ void testConfigInfoBaseRowMapper() throws SQLException {
}

@Test
void testConfigInfoAggrRowMapper() throws SQLException {
void testConfigInfoGrayRowMapper() throws SQLException {

ConfigInfoAggr preConfig = new ConfigInfoAggr();
ConfigInfoGrayWrapper preConfig = new ConfigInfoGrayWrapper();
preConfig.setDataId("testDataId");
preConfig.setGroup("group_id11");
preConfig.setContent("content1123434t");
preConfig.setDatumId("datum4567890");
preConfig.setGrayName("grayName");
preConfig.setGrayRule("rule12345");
preConfig.setTenant("tenang34567890");
preConfig.setAppName("app3456789");
preConfig.setEncryptedDataKey("key12345");
Timestamp timestamp = Timestamp.valueOf("2024-12-12 12:34:34");
ResultSetImpl resultSet = Mockito.mock(ResultSetImpl.class);
Mockito.when(resultSet.getString(eq("data_id"))).thenReturn(preConfig.getDataId());
Mockito.when(resultSet.getString(eq("group_id"))).thenReturn(preConfig.getGroup());
Mockito.when(resultSet.getString(eq("tenant_id"))).thenReturn(preConfig.getTenant());
Mockito.when(resultSet.getString(eq("datum_id"))).thenReturn(preConfig.getDatumId());
Mockito.when(resultSet.getString(eq("gray_name"))).thenReturn(preConfig.getGrayName());
Mockito.when(resultSet.getString(eq("app_name"))).thenReturn(preConfig.getAppName());

Mockito.when(resultSet.getString(eq("gray_rule"))).thenReturn(preConfig.getGrayRule());
Mockito.when(resultSet.getTimestamp(eq("gmt_modified"))).thenReturn(timestamp);

Mockito.when(resultSet.getString(eq("content"))).thenReturn(preConfig.getContent());
Mockito.when(resultSet.getString(eq("app"))).thenReturn(preConfig.getAppName());
ConfigRowMapperInjector.ConfigInfoAggrRowMapper configInfoWrapperRowMapper = new ConfigRowMapperInjector.ConfigInfoAggrRowMapper();
Mockito.when(resultSet.getString(eq("encrypted_data_key"))).thenReturn(preConfig.getEncryptedDataKey());

ConfigRowMapperInjector.ConfigInfoGrayWrapperRowMapper configInfoWrapperRowMapper = new ConfigRowMapperInjector.ConfigInfoGrayWrapperRowMapper();

ConfigInfoAggr configInfoWrapper = configInfoWrapperRowMapper.mapRow(resultSet, 10);
ConfigInfoGrayWrapper configInfoWrapper = configInfoWrapperRowMapper.mapRow(resultSet, 10);
assertEquals(preConfig, configInfoWrapper);
assertEquals(timestamp.getTime(), configInfoWrapper.getLastModified());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.
#

com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoAggrMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoBetaMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoTagMapperByMySql
Expand All @@ -25,7 +24,6 @@ com.alibaba.nacos.plugin.datasource.impl.mysql.TenantInfoMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.TenantCapacityMapperByMySql
com.alibaba.nacos.plugin.datasource.impl.mysql.GroupCapacityMapperByMysql

com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoAggrMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoBetaMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoMapperByDerby
com.alibaba.nacos.plugin.datasource.impl.derby.ConfigInfoTagMapperByDerby
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.impl.mysql.AbstractMapperByMysql;
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoAggrMapper;
import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoGrayMapperByMySql;
import com.alibaba.nacos.plugin.datasource.mapper.Mapper;
import com.alibaba.nacos.plugin.datasource.mapper.TestMapper;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -78,7 +78,7 @@ void testFindMapper() {
void testEnableDataSourceLogJoin() {
MapperManager.join(new TestMapper());
MapperManager instance = MapperManager.instance(true);
ConfigInfoAggrMapper mapper = instance.findMapper(DataSourceConstant.MYSQL, "enable_data_source_log_test");
ConfigInfoGrayMapperByMySql mapper = instance.findMapper(DataSourceConstant.MYSQL, "enable_data_source_log_test");
assertNotNull(mapper);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
import com.alibaba.nacos.plugin.datasource.impl.TestInterface;
import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoAggrMapperByMySql;
import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoGrayMapperByMySql;

/**
* Implement interfaces other than Mapper. just for test
*
* @author mikolls
**/
public class TestMapper extends ConfigInfoAggrMapperByMySql implements TestInterface {
public class TestMapper extends ConfigInfoGrayMapperByMySql implements TestInterface {

@Override
public String getTableName() {
Expand Down

0 comments on commit 2624497

Please sign in to comment.