upgrade module naocs-plugin from junit4 to junit5 (#12229)
This commit is contained in:
parent
ab6591ac83
commit
21bfac76e7
@ -16,32 +16,33 @@
|
||||
|
||||
package com.alibaba.nacos.plugin.auth.api;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class IdentityContextTest {
|
||||
class IdentityContextTest {
|
||||
|
||||
private static final String TEST = "test";
|
||||
|
||||
private IdentityContext identityContext;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
identityContext = new IdentityContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetParameter() {
|
||||
void testGetParameter() {
|
||||
assertNull(identityContext.getParameter(TEST));
|
||||
identityContext.setParameter(TEST, TEST);
|
||||
assertEquals(TEST, identityContext.getParameter(TEST));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetParameterWithDefaultValue() {
|
||||
void testGetParameterWithDefaultValue() {
|
||||
assertEquals(TEST, identityContext.getParameter(TEST, TEST));
|
||||
identityContext.setParameter(TEST, TEST + "new");
|
||||
assertEquals(TEST + "new", identityContext.getParameter(TEST, TEST));
|
||||
@ -49,8 +50,10 @@ public class IdentityContextTest {
|
||||
assertEquals(1L, actual);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testGetParameterWithNullDefaultValue() {
|
||||
identityContext.getParameter(TEST, null);
|
||||
@Test
|
||||
void testGetParameterWithNullDefaultValue() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
identityContext.getParameter(TEST, null);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -16,29 +16,29 @@
|
||||
|
||||
package com.alibaba.nacos.plugin.auth.api;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class LoginIdentityContextTest {
|
||||
class LoginIdentityContextTest {
|
||||
|
||||
private static final String TEST = "test";
|
||||
|
||||
private LoginIdentityContext loginIdentityContext;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
loginIdentityContext = new LoginIdentityContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetParameter() {
|
||||
void testSetParameter() {
|
||||
assertNull(loginIdentityContext.getParameter(TEST));
|
||||
assertTrue(loginIdentityContext.getAllKey().isEmpty());
|
||||
loginIdentityContext.setParameter(TEST, TEST);
|
||||
@ -47,7 +47,7 @@ public class LoginIdentityContextTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetParameters() {
|
||||
void testSetParameters() {
|
||||
assertNull(loginIdentityContext.getParameter(TEST));
|
||||
assertTrue(loginIdentityContext.getAllKey().isEmpty());
|
||||
Map<String, String> map = new HashMap<>(2);
|
||||
|
@ -17,31 +17,30 @@
|
||||
package com.alibaba.nacos.plugin.auth.api;
|
||||
|
||||
import com.alibaba.nacos.plugin.auth.constant.ActionTypes;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class PermissionTest {
|
||||
class PermissionTest {
|
||||
|
||||
private Permission permission;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
permission = new Permission(Resource.EMPTY_RESOURCE, ActionTypes.WRITE.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals(
|
||||
"Permission{resource='Resource{namespaceId='', group='', name='', type='', properties=null}', action='w'}",
|
||||
void testToString() {
|
||||
assertEquals("Permission{resource='Resource{namespaceId='', group='', name='', type='', properties=null}', action='w'}",
|
||||
permission.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetResource() {
|
||||
void testSetResource() {
|
||||
Permission permission = new Permission();
|
||||
Properties properties = new Properties();
|
||||
Resource resource = new Resource("NS", "G", "N", "TEST", properties);
|
||||
@ -54,7 +53,7 @@ public class PermissionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAction() {
|
||||
void testSetAction() {
|
||||
Permission permission = new Permission();
|
||||
permission.setAction(ActionTypes.READ.toString());
|
||||
assertEquals(ActionTypes.READ.toString(), permission.getAction());
|
||||
|
@ -17,21 +17,20 @@
|
||||
package com.alibaba.nacos.plugin.auth.api;
|
||||
|
||||
import com.alibaba.nacos.plugin.auth.constant.SignType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class RequestResourceTest {
|
||||
class RequestResourceTest {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildNamingRequestResource() {
|
||||
RequestResource actual = RequestResource.namingBuilder().setNamespace("NS").setGroup("G").setResource("Service")
|
||||
.build();
|
||||
void testBuildNamingRequestResource() {
|
||||
RequestResource actual = RequestResource.namingBuilder().setNamespace("NS").setGroup("G").setResource("Service").build();
|
||||
assertEquals(SignType.NAMING, actual.getType());
|
||||
assertEquals("NS", actual.getNamespace());
|
||||
assertEquals("G", actual.getGroup());
|
||||
@ -39,9 +38,8 @@ public class RequestResourceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildConfigRequestResource() {
|
||||
RequestResource actual = RequestResource.configBuilder().setNamespace("NS").setGroup("G").setResource("dataId")
|
||||
.build();
|
||||
void testBuildConfigRequestResource() {
|
||||
RequestResource actual = RequestResource.configBuilder().setNamespace("NS").setGroup("G").setResource("dataId").build();
|
||||
assertEquals(SignType.CONFIG, actual.getType());
|
||||
assertEquals("NS", actual.getNamespace());
|
||||
assertEquals("G", actual.getGroup());
|
||||
|
@ -16,20 +16,20 @@
|
||||
|
||||
package com.alibaba.nacos.plugin.auth.constant;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class ActionTypesTest {
|
||||
class ActionTypesTest {
|
||||
|
||||
@Test
|
||||
public void testToStringForRead() {
|
||||
void testToStringForRead() {
|
||||
ActionTypes actual = ActionTypes.valueOf("READ");
|
||||
assertEquals("r", actual.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToStringForWrite() {
|
||||
void testToStringForWrite() {
|
||||
ActionTypes actual = ActionTypes.valueOf("WRITE");
|
||||
assertEquals("w", actual.toString());
|
||||
}
|
||||
|
@ -16,25 +16,24 @@
|
||||
|
||||
package com.alibaba.nacos.plugin.auth.constant;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class ConstantsTest {
|
||||
class ConstantsTest {
|
||||
|
||||
@Test
|
||||
public void testConstantsForAuth() {
|
||||
void testConstantsForAuth() {
|
||||
assertEquals("nacos.core.auth.enabled", Constants.Auth.NACOS_CORE_AUTH_ENABLED);
|
||||
assertEquals("nacos.core.auth.system.type", Constants.Auth.NACOS_CORE_AUTH_SYSTEM_TYPE);
|
||||
assertEquals("nacos.core.auth.caching.enabled", Constants.Auth.NACOS_CORE_AUTH_CACHING_ENABLED);
|
||||
assertEquals("nacos.core.auth.server.identity.key", Constants.Auth.NACOS_CORE_AUTH_SERVER_IDENTITY_KEY);
|
||||
assertEquals("nacos.core.auth.server.identity.value", Constants.Auth.NACOS_CORE_AUTH_SERVER_IDENTITY_VALUE);
|
||||
assertEquals("nacos.core.auth.enable.userAgentAuthWhite",
|
||||
Constants.Auth.NACOS_CORE_AUTH_ENABLE_USER_AGENT_AUTH_WHITE);
|
||||
assertEquals("nacos.core.auth.enable.userAgentAuthWhite", Constants.Auth.NACOS_CORE_AUTH_ENABLE_USER_AGENT_AUTH_WHITE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstantsForResource() {
|
||||
void testConstantsForResource() {
|
||||
assertEquals(":", Constants.Resource.SPLITTER);
|
||||
assertEquals("*", Constants.Resource.ANY);
|
||||
assertEquals("action", Constants.Resource.ACTION);
|
||||
@ -42,14 +41,14 @@ public class ConstantsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstantsForIdentity() {
|
||||
void testConstantsForIdentity() {
|
||||
assertEquals("identity_id", Constants.Identity.IDENTITY_ID);
|
||||
assertEquals("X-Real-IP", Constants.Identity.X_REAL_IP);
|
||||
assertEquals("remote_ip", Constants.Identity.REMOTE_IP);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstantsForSignType() {
|
||||
void testConstantsForSignType() {
|
||||
assertEquals("naming", SignType.NAMING);
|
||||
assertEquals("config", SignType.CONFIG);
|
||||
assertEquals("console", SignType.CONSOLE);
|
||||
|
@ -17,28 +17,28 @@
|
||||
package com.alibaba.nacos.plugin.auth.exception;
|
||||
|
||||
import com.alibaba.nacos.api.common.Constants;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class AccessExceptionTest {
|
||||
class AccessExceptionTest {
|
||||
|
||||
@Test
|
||||
public void testNewAccessExceptionWithCode() {
|
||||
void testNewAccessExceptionWithCode() {
|
||||
AccessException actual = new AccessException(403);
|
||||
assertEquals(403, actual.getErrCode());
|
||||
assertEquals(Constants.NULL, actual.getErrMsg());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewAccessExceptionWithMsg() {
|
||||
void testNewAccessExceptionWithMsg() {
|
||||
AccessException actual = new AccessException("Test");
|
||||
assertEquals("Test", actual.getErrMsg());
|
||||
assertEquals(0, actual.getErrCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewAccessExceptionWithNoArgs() {
|
||||
void testNewAccessExceptionWithNoArgs() {
|
||||
AccessException actual = new AccessException();
|
||||
assertEquals(Constants.NULL, actual.getErrMsg());
|
||||
assertEquals(0, actual.getErrCode());
|
||||
|
@ -19,13 +19,12 @@ package com.alibaba.nacos.plugin.auth.spi.client;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.common.http.client.NacosRestTemplate;
|
||||
import com.alibaba.nacos.common.spi.NacosServiceLoader;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
@ -34,6 +33,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* {@link ClientAuthPluginManager} unit test.
|
||||
*
|
||||
@ -41,8 +43,8 @@ import java.util.Set;
|
||||
* @date 2021-08-12 12:56
|
||||
*/
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ClientAuthPluginManagerTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ClientAuthPluginManagerTest {
|
||||
|
||||
private ClientAuthPluginManager clientAuthPluginManager;
|
||||
|
||||
@ -52,37 +54,36 @@ public class ClientAuthPluginManagerTest {
|
||||
@Mock
|
||||
private NacosRestTemplate nacosRestTemplate;
|
||||
|
||||
@Before
|
||||
public void setUp() throws NoSuchFieldException, IllegalAccessException {
|
||||
@BeforeEach
|
||||
void setUp() throws NoSuchFieldException, IllegalAccessException {
|
||||
clientAuthPluginManager = new ClientAuthPluginManager();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws NacosException, NoSuchFieldException, IllegalAccessException {
|
||||
@AfterEach
|
||||
void tearDown() throws NacosException, NoSuchFieldException, IllegalAccessException {
|
||||
getServiceLoaderMap().remove(AbstractClientAuthService.class);
|
||||
clientAuthPluginManager.shutdown();
|
||||
}
|
||||
|
||||
private Map<Class<?>, Collection<Class<?>>> getServiceLoaderMap()
|
||||
throws NoSuchFieldException, IllegalAccessException {
|
||||
private Map<Class<?>, Collection<Class<?>>> getServiceLoaderMap() throws NoSuchFieldException, IllegalAccessException {
|
||||
Field servicesField = NacosServiceLoader.class.getDeclaredField("SERVICES");
|
||||
servicesField.setAccessible(true);
|
||||
return (Map<Class<?>, Collection<Class<?>>>) servicesField.get(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAuthServiceSpiImplSet() {
|
||||
void testGetAuthServiceSpiImplSet() {
|
||||
clientAuthPluginManager.init(serverlist, nacosRestTemplate);
|
||||
Set<ClientAuthService> clientAuthServiceSet = clientAuthPluginManager.getAuthServiceSpiImplSet();
|
||||
Assert.assertFalse(clientAuthServiceSet.isEmpty());
|
||||
assertFalse(clientAuthServiceSet.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAuthServiceSpiImplSetForEmpty() throws NoSuchFieldException, IllegalAccessException {
|
||||
void testGetAuthServiceSpiImplSetForEmpty() throws NoSuchFieldException, IllegalAccessException {
|
||||
getServiceLoaderMap().put(AbstractClientAuthService.class, Collections.emptyList());
|
||||
clientAuthPluginManager.init(serverlist, nacosRestTemplate);
|
||||
Set<ClientAuthService> clientAuthServiceSet = clientAuthPluginManager.getAuthServiceSpiImplSet();
|
||||
Assert.assertTrue(clientAuthServiceSet.isEmpty());
|
||||
assertTrue(clientAuthServiceSet.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,17 +16,19 @@
|
||||
|
||||
package com.alibaba.nacos.plugin.auth.spi.server;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* {@link AuthPluginManager} unit test.
|
||||
*
|
||||
@ -34,38 +36,37 @@ import java.util.Optional;
|
||||
* @date 2021-08-12 12:56
|
||||
*/
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AuthPluginManagerTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class AuthPluginManagerTest {
|
||||
|
||||
private static final String TYPE = "test";
|
||||
|
||||
private AuthPluginManager authPluginManager;
|
||||
|
||||
@Mock
|
||||
private AuthPluginService authPluginService;
|
||||
|
||||
private static final String TYPE = "test";
|
||||
|
||||
@Before
|
||||
public void setUp() throws NoSuchFieldException, IllegalAccessException {
|
||||
@BeforeEach
|
||||
void setUp() throws NoSuchFieldException, IllegalAccessException {
|
||||
authPluginManager = AuthPluginManager.getInstance();
|
||||
Class<AuthPluginManager> authPluginManagerClass = AuthPluginManager.class;
|
||||
Field authPlugins = authPluginManagerClass.getDeclaredField("authServiceMap");
|
||||
authPlugins.setAccessible(true);
|
||||
Map<String, AuthPluginService> authServiceMap = (Map<String, AuthPluginService>) authPlugins
|
||||
.get(authPluginManager);
|
||||
Map<String, AuthPluginService> authServiceMap = (Map<String, AuthPluginService>) authPlugins.get(authPluginManager);
|
||||
authServiceMap.put(TYPE, authPluginService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInstance() {
|
||||
void testGetInstance() {
|
||||
AuthPluginManager instance = AuthPluginManager.getInstance();
|
||||
|
||||
Assert.assertNotNull(instance);
|
||||
assertNotNull(instance);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAuthServiceSpiImpl() {
|
||||
void testFindAuthServiceSpiImpl() {
|
||||
Optional<AuthPluginService> authServiceImpl = authPluginManager.findAuthServiceSpiImpl(TYPE);
|
||||
Assert.assertTrue(authServiceImpl.isPresent());
|
||||
assertTrue(authServiceImpl.isPresent());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,52 +21,58 @@ import com.alibaba.nacos.plugin.config.constants.ConfigChangePointCutTypes;
|
||||
import com.alibaba.nacos.plugin.config.model.ConfigChangeRequest;
|
||||
import com.alibaba.nacos.plugin.config.model.ConfigChangeResponse;
|
||||
import com.alibaba.nacos.plugin.config.spi.ConfigChangePluginService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* ConfigChangePluginManagerTests.
|
||||
*
|
||||
* @author liyunfei
|
||||
**/
|
||||
public class ConfigChangePluginManagerTests {
|
||||
class ConfigChangePluginManagerTests {
|
||||
|
||||
@Test
|
||||
public void testInstance() {
|
||||
void testInstance() {
|
||||
ConfigChangePluginManager instance = ConfigChangePluginManager.getInstance();
|
||||
Assert.assertNotNull(instance);
|
||||
assertNotNull(instance);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void initPluginServices() {
|
||||
|
||||
@BeforeEach
|
||||
void initPluginServices() {
|
||||
ConfigChangePluginManager.join(new ConfigChangePluginService() {
|
||||
@Override
|
||||
public void execute(ConfigChangeRequest configChangeRequest, ConfigChangeResponse configChangeResponse) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigChangeExecuteTypes executeType() {
|
||||
return ConfigChangeExecuteTypes.EXECUTE_BEFORE_TYPE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getServiceType() {
|
||||
return "test1";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigChangePointCutTypes[] pointcutMethodNames() {
|
||||
return new ConfigChangePointCutTypes[]{ConfigChangePointCutTypes.PUBLISH_BY_HTTP, ConfigChangePointCutTypes.PUBLISH_BY_RPC};
|
||||
return new ConfigChangePointCutTypes[] {ConfigChangePointCutTypes.PUBLISH_BY_HTTP,
|
||||
ConfigChangePointCutTypes.PUBLISH_BY_RPC};
|
||||
}
|
||||
});
|
||||
ConfigChangePluginManager.join(new ConfigChangePluginService() {
|
||||
@ -74,25 +80,25 @@ public class ConfigChangePluginManagerTests {
|
||||
public void execute(ConfigChangeRequest configChangeRequest, ConfigChangeResponse configChangeResponse) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigChangeExecuteTypes executeType() {
|
||||
return ConfigChangeExecuteTypes.EXECUTE_BEFORE_TYPE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getServiceType() {
|
||||
return "test2";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 200;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigChangePointCutTypes[] pointcutMethodNames() {
|
||||
return new ConfigChangePointCutTypes[]{ConfigChangePointCutTypes.IMPORT_BY_HTTP, ConfigChangePointCutTypes.PUBLISH_BY_RPC};
|
||||
return new ConfigChangePointCutTypes[] {ConfigChangePointCutTypes.IMPORT_BY_HTTP, ConfigChangePointCutTypes.PUBLISH_BY_RPC};
|
||||
}
|
||||
});
|
||||
ConfigChangePluginManager.join(new ConfigChangePluginService() {
|
||||
@ -100,105 +106,100 @@ public class ConfigChangePluginManagerTests {
|
||||
public void execute(ConfigChangeRequest configChangeRequest, ConfigChangeResponse configChangeResponse) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigChangeExecuteTypes executeType() {
|
||||
return ConfigChangeExecuteTypes.EXECUTE_AFTER_TYPE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getServiceType() {
|
||||
return "test3";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 400;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigChangePointCutTypes[] pointcutMethodNames() {
|
||||
return new ConfigChangePointCutTypes[]{ConfigChangePointCutTypes.IMPORT_BY_HTTP, ConfigChangePointCutTypes.PUBLISH_BY_RPC,
|
||||
return new ConfigChangePointCutTypes[] {ConfigChangePointCutTypes.IMPORT_BY_HTTP, ConfigChangePointCutTypes.PUBLISH_BY_RPC,
|
||||
ConfigChangePointCutTypes.REMOVE_BATCH_HTTP, ConfigChangePointCutTypes.REMOVE_BY_RPC,
|
||||
ConfigChangePointCutTypes.REMOVE_BY_HTTP};
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ConfigChangePluginManager.join(new ConfigChangePluginService() {
|
||||
@Override
|
||||
public void execute(ConfigChangeRequest configChangeRequest, ConfigChangeResponse configChangeResponse) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigChangeExecuteTypes executeType() {
|
||||
return ConfigChangeExecuteTypes.EXECUTE_AFTER_TYPE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getServiceType() {
|
||||
return "test4";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return 600;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ConfigChangePointCutTypes[] pointcutMethodNames() {
|
||||
return new ConfigChangePointCutTypes[]{ConfigChangePointCutTypes.PUBLISH_BY_HTTP, ConfigChangePointCutTypes.REMOVE_BATCH_HTTP,
|
||||
ConfigChangePointCutTypes.REMOVE_BY_RPC, ConfigChangePointCutTypes.REMOVE_BY_HTTP};
|
||||
return new ConfigChangePointCutTypes[] {ConfigChangePointCutTypes.PUBLISH_BY_HTTP,
|
||||
ConfigChangePointCutTypes.REMOVE_BATCH_HTTP, ConfigChangePointCutTypes.REMOVE_BY_RPC,
|
||||
ConfigChangePointCutTypes.REMOVE_BY_HTTP};
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFindPluginServiceQueueByPointcut() {
|
||||
List<ConfigChangePluginService> configChangePluginServices = ConfigChangePluginManager
|
||||
.findPluginServicesByPointcut(ConfigChangePointCutTypes.PUBLISH_BY_HTTP);
|
||||
Assert.assertEquals(2, configChangePluginServices.size());
|
||||
Assert.assertTrue(isSorted(configChangePluginServices));
|
||||
configChangePluginServices = ConfigChangePluginManager
|
||||
.findPluginServicesByPointcut(ConfigChangePointCutTypes.PUBLISH_BY_RPC);
|
||||
Assert.assertEquals(3, configChangePluginServices.size());
|
||||
Assert.assertTrue(isSorted(configChangePluginServices));
|
||||
configChangePluginServices = ConfigChangePluginManager
|
||||
.findPluginServicesByPointcut(ConfigChangePointCutTypes.IMPORT_BY_HTTP);
|
||||
Assert.assertEquals(2, configChangePluginServices.size());
|
||||
Assert.assertTrue(isSorted(configChangePluginServices));
|
||||
configChangePluginServices = ConfigChangePluginManager
|
||||
.findPluginServicesByPointcut(ConfigChangePointCutTypes.REMOVE_BATCH_HTTP);
|
||||
Assert.assertEquals(2, configChangePluginServices.size());
|
||||
Assert.assertTrue(isSorted(configChangePluginServices));
|
||||
configChangePluginServices = ConfigChangePluginManager
|
||||
.findPluginServicesByPointcut(ConfigChangePointCutTypes.REMOVE_BY_RPC);
|
||||
Assert.assertEquals(2, configChangePluginServices.size());
|
||||
Assert.assertTrue(isSorted(configChangePluginServices));
|
||||
configChangePluginServices = ConfigChangePluginManager
|
||||
.findPluginServicesByPointcut(ConfigChangePointCutTypes.REMOVE_BY_HTTP);
|
||||
Assert.assertEquals(2, configChangePluginServices.size());
|
||||
Assert.assertTrue(isSorted(configChangePluginServices));
|
||||
void testFindPluginServiceQueueByPointcut() {
|
||||
List<ConfigChangePluginService> configChangePluginServices = ConfigChangePluginManager.findPluginServicesByPointcut(
|
||||
ConfigChangePointCutTypes.PUBLISH_BY_HTTP);
|
||||
assertEquals(2, configChangePluginServices.size());
|
||||
assertTrue(isSorted(configChangePluginServices));
|
||||
configChangePluginServices = ConfigChangePluginManager.findPluginServicesByPointcut(ConfigChangePointCutTypes.PUBLISH_BY_RPC);
|
||||
assertEquals(3, configChangePluginServices.size());
|
||||
assertTrue(isSorted(configChangePluginServices));
|
||||
configChangePluginServices = ConfigChangePluginManager.findPluginServicesByPointcut(ConfigChangePointCutTypes.IMPORT_BY_HTTP);
|
||||
assertEquals(2, configChangePluginServices.size());
|
||||
assertTrue(isSorted(configChangePluginServices));
|
||||
configChangePluginServices = ConfigChangePluginManager.findPluginServicesByPointcut(ConfigChangePointCutTypes.REMOVE_BATCH_HTTP);
|
||||
assertEquals(2, configChangePluginServices.size());
|
||||
assertTrue(isSorted(configChangePluginServices));
|
||||
configChangePluginServices = ConfigChangePluginManager.findPluginServicesByPointcut(ConfigChangePointCutTypes.REMOVE_BY_RPC);
|
||||
assertEquals(2, configChangePluginServices.size());
|
||||
assertTrue(isSorted(configChangePluginServices));
|
||||
configChangePluginServices = ConfigChangePluginManager.findPluginServicesByPointcut(ConfigChangePointCutTypes.REMOVE_BY_HTTP);
|
||||
assertEquals(2, configChangePluginServices.size());
|
||||
assertTrue(isSorted(configChangePluginServices));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFindPluginServiceByServiceType() {
|
||||
Optional<ConfigChangePluginService> configChangePluginServiceOptional = ConfigChangePluginManager
|
||||
.getInstance().findPluginServiceImpl("test1");
|
||||
Assert.assertTrue(configChangePluginServiceOptional.isPresent());
|
||||
void testFindPluginServiceByServiceType() {
|
||||
Optional<ConfigChangePluginService> configChangePluginServiceOptional = ConfigChangePluginManager.getInstance()
|
||||
.findPluginServiceImpl("test1");
|
||||
assertTrue(configChangePluginServiceOptional.isPresent());
|
||||
configChangePluginServiceOptional = ConfigChangePluginManager.getInstance().findPluginServiceImpl("test2");
|
||||
Assert.assertTrue(configChangePluginServiceOptional.isPresent());
|
||||
assertTrue(configChangePluginServiceOptional.isPresent());
|
||||
configChangePluginServiceOptional = ConfigChangePluginManager.getInstance().findPluginServiceImpl("test3");
|
||||
Assert.assertTrue(configChangePluginServiceOptional.isPresent());
|
||||
assertTrue(configChangePluginServiceOptional.isPresent());
|
||||
configChangePluginServiceOptional = ConfigChangePluginManager.getInstance().findPluginServiceImpl("test4");
|
||||
Assert.assertTrue(configChangePluginServiceOptional.isPresent());
|
||||
assertTrue(configChangePluginServiceOptional.isPresent());
|
||||
configChangePluginServiceOptional = ConfigChangePluginManager.getInstance().findPluginServiceImpl("test5");
|
||||
Assert.assertFalse(configChangePluginServiceOptional.isPresent());
|
||||
assertFalse(configChangePluginServiceOptional.isPresent());
|
||||
}
|
||||
|
||||
|
||||
private boolean isSorted(List<ConfigChangePluginService> list) {
|
||||
return IntStream.range(0, list.size() - 1)
|
||||
.allMatch(i -> list.get(i).getOrder() <= list.get(i + 1).getOrder());
|
||||
return IntStream.range(0, list.size() - 1).allMatch(i -> list.get(i).getOrder() <= list.get(i + 1).getOrder());
|
||||
}
|
||||
}
|
||||
|
@ -26,9 +26,8 @@ import com.alibaba.nacos.plugin.control.tps.TpsControlManager;
|
||||
import com.alibaba.nacos.plugin.control.tps.rule.RuleDetail;
|
||||
import com.alibaba.nacos.plugin.control.tps.rule.TpsControlRule;
|
||||
import com.alibaba.nacos.plugin.control.utils.EnvUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
@ -36,10 +35,13 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ControlManagerCenterTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
class ControlManagerCenterTest {
|
||||
|
||||
@Before
|
||||
public void initInstance() throws NoSuchFieldException, IllegalAccessException {
|
||||
@BeforeEach
|
||||
void initInstance() throws NoSuchFieldException, IllegalAccessException {
|
||||
//reset instance for reload spi
|
||||
Field instanceControlConfigs = ControlConfigs.class.getDeclaredField("instance");
|
||||
instanceControlConfigs.setAccessible(true);
|
||||
@ -69,29 +71,28 @@ public class ControlManagerCenterTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInstance() {
|
||||
void testGetInstance() {
|
||||
ControlConfigs.getInstance().setControlManagerType("test");
|
||||
ControlManagerCenter controlManagerCenter = ControlManagerCenter.getInstance();
|
||||
ConnectionControlManager connectionControlManager = controlManagerCenter.getConnectionControlManager();
|
||||
Assert.assertEquals("testConnection", connectionControlManager.getName());
|
||||
assertEquals("testConnection", connectionControlManager.getName());
|
||||
TpsControlManager tpsControlManager = controlManagerCenter.getTpsControlManager();
|
||||
Assert.assertEquals("testTps", tpsControlManager.getName());
|
||||
Assert.assertNotNull(controlManagerCenter.getRuleStorageProxy());
|
||||
assertEquals("testTps", tpsControlManager.getName());
|
||||
assertNotNull(controlManagerCenter.getRuleStorageProxy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInstanceWithDefault() {
|
||||
void testGetInstanceWithDefault() {
|
||||
ControlManagerCenter controlManagerCenter = ControlManagerCenter.getInstance();
|
||||
ConnectionControlManager connectionControlManager = controlManagerCenter.getConnectionControlManager();
|
||||
Assert.assertEquals("noLimit", connectionControlManager.getName());
|
||||
assertEquals("noLimit", connectionControlManager.getName());
|
||||
TpsControlManager tpsControlManager = controlManagerCenter.getTpsControlManager();
|
||||
Assert.assertEquals("noLimit", tpsControlManager.getName());
|
||||
assertEquals("noLimit", tpsControlManager.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReloadTpsControlRule() throws Exception {
|
||||
String localRuleStorageBaseDir =
|
||||
EnvUtils.getNacosHome() + File.separator + "tmpTps" + File.separator + "tps" + File.separator;
|
||||
void testReloadTpsControlRule() throws Exception {
|
||||
String localRuleStorageBaseDir = EnvUtils.getNacosHome() + File.separator + "tmpTps" + File.separator + "tps" + File.separator;
|
||||
ControlConfigs.getInstance().setLocalRuleStorageBaseDir(localRuleStorageBaseDir);
|
||||
resetRuleStorageProxy();
|
||||
final ControlManagerCenter controlManagerCenter = ControlManagerCenter.getInstance();
|
||||
@ -108,8 +109,8 @@ public class ControlManagerCenterTest {
|
||||
controlManagerCenter.getTpsControlManager().applyTpsRule("test", tpsControlRule);
|
||||
TpsControlRule testTpsControlRule = controlManagerCenter.getTpsControlManager().getRules().get("test");
|
||||
|
||||
Assert.assertEquals(100, testTpsControlRule.getPointRule().getMaxCount());
|
||||
Assert.assertEquals("test", testTpsControlRule.getPointRule().getRuleName());
|
||||
assertEquals(100, testTpsControlRule.getPointRule().getMaxCount());
|
||||
assertEquals("test", testTpsControlRule.getPointRule().getRuleName());
|
||||
|
||||
TpsControlRule tpsControlRule2 = new TpsControlRule();
|
||||
tpsControlRule2.setPointName("test");
|
||||
@ -126,12 +127,12 @@ public class ControlManagerCenterTest {
|
||||
//wait event
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
TpsControlRule testTpsControlRule2 = controlManagerCenter.getTpsControlManager().getRules().get("test");
|
||||
Assert.assertEquals(200, testTpsControlRule2.getPointRule().getMaxCount());
|
||||
Assert.assertEquals("test2", testTpsControlRule2.getPointRule().getRuleName());
|
||||
assertEquals(200, testTpsControlRule2.getPointRule().getMaxCount());
|
||||
assertEquals("test2", testTpsControlRule2.getPointRule().getRuleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReloadTpsControlRuleExternal() throws Exception {
|
||||
void testReloadTpsControlRuleExternal() throws Exception {
|
||||
String localRuleStorageBaseDir =
|
||||
EnvUtils.getNacosHome() + File.separator + "tmpTps" + File.separator + "tpsExternal" + File.separator;
|
||||
ControlConfigs.getInstance().setLocalRuleStorageBaseDir(localRuleStorageBaseDir);
|
||||
@ -152,8 +153,8 @@ public class ControlManagerCenterTest {
|
||||
controlManagerCenter.getTpsControlManager().applyTpsRule("test", tpsControlRule);
|
||||
TpsControlRule testTpsControlRule = controlManagerCenter.getTpsControlManager().getRules().get("test");
|
||||
|
||||
Assert.assertEquals(100, testTpsControlRule.getPointRule().getMaxCount());
|
||||
Assert.assertEquals("test", testTpsControlRule.getPointRule().getRuleName());
|
||||
assertEquals(100, testTpsControlRule.getPointRule().getMaxCount());
|
||||
assertEquals("test", testTpsControlRule.getPointRule().getRuleName());
|
||||
|
||||
TpsControlRule tpsControlRule2 = new TpsControlRule();
|
||||
tpsControlRule2.setPointName("test");
|
||||
@ -170,15 +171,14 @@ public class ControlManagerCenterTest {
|
||||
//wait event
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
TpsControlRule testTpsControlRule2 = controlManagerCenter.getTpsControlManager().getRules().get("test");
|
||||
Assert.assertEquals(200, testTpsControlRule2.getPointRule().getMaxCount());
|
||||
Assert.assertEquals("test2", testTpsControlRule2.getPointRule().getRuleName());
|
||||
assertEquals(200, testTpsControlRule2.getPointRule().getMaxCount());
|
||||
assertEquals("test2", testTpsControlRule2.getPointRule().getRuleName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReloadConnectionControlRule() throws Exception {
|
||||
void testReloadConnectionControlRule() throws Exception {
|
||||
String localRuleStorageBaseDir =
|
||||
EnvUtils.getNacosHome() + File.separator + "tmpConnection" + File.separator + "connection"
|
||||
+ File.separator;
|
||||
EnvUtils.getNacosHome() + File.separator + "tmpConnection" + File.separator + "connection" + File.separator;
|
||||
ControlConfigs.getInstance().setLocalRuleStorageBaseDir(localRuleStorageBaseDir);
|
||||
resetRuleStorageProxy();
|
||||
ConnectionControlRule connectionLimitRule = new ConnectionControlRule();
|
||||
@ -191,7 +191,7 @@ public class ControlManagerCenterTest {
|
||||
//apply rule
|
||||
connectionControlManager.applyConnectionLimitRule(connectionLimitRule);
|
||||
ConnectionControlRule connectionLimitRule1 = connectionControlManager.getConnectionLimitRule();
|
||||
Assert.assertEquals(100, connectionLimitRule1.getCountLimit());
|
||||
assertEquals(100, connectionLimitRule1.getCountLimit());
|
||||
|
||||
ConnectionControlRule connectionLimitRule2 = new ConnectionControlRule();
|
||||
connectionLimitRule2.setCountLimit(200);
|
||||
@ -203,14 +203,13 @@ public class ControlManagerCenterTest {
|
||||
//wait event
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
ConnectionControlRule connectionLimitRule3 = connectionControlManager.getConnectionLimitRule();
|
||||
Assert.assertEquals(200, connectionLimitRule3.getCountLimit());
|
||||
assertEquals(200, connectionLimitRule3.getCountLimit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReloadConnectionControlRuleExternal() throws Exception {
|
||||
void testReloadConnectionControlRuleExternal() throws Exception {
|
||||
String localRuleStorageBaseDir =
|
||||
EnvUtils.getNacosHome() + File.separator + "tmpConnection" + File.separator + "connectionExternal"
|
||||
+ File.separator;
|
||||
EnvUtils.getNacosHome() + File.separator + "tmpConnection" + File.separator + "connectionExternal" + File.separator;
|
||||
ControlConfigs.getInstance().setLocalRuleStorageBaseDir(localRuleStorageBaseDir);
|
||||
ControlConfigs.getInstance().setRuleExternalStorage("test");
|
||||
resetRuleStorageProxy();
|
||||
@ -224,7 +223,7 @@ public class ControlManagerCenterTest {
|
||||
//apply rule
|
||||
connectionControlManager.applyConnectionLimitRule(connectionLimitRule);
|
||||
ConnectionControlRule connectionLimitRule1 = connectionControlManager.getConnectionLimitRule();
|
||||
Assert.assertEquals(100, connectionLimitRule1.getCountLimit());
|
||||
assertEquals(100, connectionLimitRule1.getCountLimit());
|
||||
|
||||
ConnectionControlRule connectionLimitRule2 = new ConnectionControlRule();
|
||||
connectionLimitRule2.setCountLimit(200);
|
||||
@ -236,6 +235,6 @@ public class ControlManagerCenterTest {
|
||||
//wait event
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
ConnectionControlRule connectionLimitRule3 = connectionControlManager.getConnectionLimitRule();
|
||||
Assert.assertEquals(200, connectionLimitRule3.getCountLimit());
|
||||
assertEquals(200, connectionLimitRule3.getCountLimit());
|
||||
}
|
||||
}
|
||||
|
@ -20,18 +20,20 @@ import com.alibaba.nacos.plugin.control.connection.request.ConnectionCheckReques
|
||||
import com.alibaba.nacos.plugin.control.connection.response.ConnectionCheckCode;
|
||||
import com.alibaba.nacos.plugin.control.connection.response.ConnectionCheckResponse;
|
||||
import com.alibaba.nacos.plugin.control.connection.rule.ConnectionControlRule;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* two fixed metrics, total 30, iptotal 15, detail is testa(total-20,iptotal-10),testb(total-10,iptotal-5).
|
||||
*/
|
||||
public class DefaultConnectionControlManagerTest {
|
||||
class DefaultConnectionControlManagerTest {
|
||||
|
||||
DefaultConnectionControlManager connectionControlManager = new DefaultConnectionControlManager();
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
void test() {
|
||||
|
||||
ConnectionControlRule connectionControlRule = new ConnectionControlRule();
|
||||
|
||||
@ -40,8 +42,8 @@ public class DefaultConnectionControlManagerTest {
|
||||
connectionControlRule.setCountLimit(40);
|
||||
connectionControlManager.applyConnectionLimitRule(connectionControlRule);
|
||||
check = connectionControlManager.check(connectionCheckRequest);
|
||||
Assert.assertTrue(check.isSuccess());
|
||||
Assert.assertEquals(ConnectionCheckCode.CHECK_SKIP, check.getCode());
|
||||
assertTrue(check.isSuccess());
|
||||
assertEquals(ConnectionCheckCode.CHECK_SKIP, check.getCode());
|
||||
|
||||
}
|
||||
|
||||
|
@ -16,31 +16,32 @@
|
||||
|
||||
package com.alibaba.nacos.plugin.control.tps;
|
||||
|
||||
import com.alibaba.nacos.plugin.control.tps.barrier.TpsBarrier;
|
||||
import com.alibaba.nacos.plugin.control.tps.barrier.DefaultNacosTpsBarrier;
|
||||
import com.alibaba.nacos.plugin.control.tps.barrier.TpsBarrier;
|
||||
import com.alibaba.nacos.plugin.control.tps.request.TpsCheckRequest;
|
||||
import com.alibaba.nacos.plugin.control.tps.response.TpsCheckResponse;
|
||||
import com.alibaba.nacos.plugin.control.tps.rule.RuleDetail;
|
||||
import com.alibaba.nacos.plugin.control.tps.rule.TpsControlRule;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DefaultNacosTpsBarrierTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class DefaultNacosTpsBarrierTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
@AfterEach
|
||||
void after() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalPointPassAndDeny() {
|
||||
void testNormalPointPassAndDeny() {
|
||||
String testTpsBarrier = "test_barrier";
|
||||
|
||||
// max 5tps
|
||||
@ -63,7 +64,7 @@ public class DefaultNacosTpsBarrierTest {
|
||||
// 5tps check pass
|
||||
for (int i = 0; i < 5; i++) {
|
||||
TpsCheckResponse tpsCheckResponse = tpsBarrier.applyTps(tpsCheckRequest);
|
||||
Assert.assertTrue(tpsCheckResponse.isSuccess());
|
||||
assertTrue(tpsCheckResponse.isSuccess());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,10 +16,9 @@
|
||||
|
||||
package com.alibaba.nacos.plugin.control.utils;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -30,46 +29,52 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DiskUtilsTest {
|
||||
private static File testFile;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class DiskUtilsTest {
|
||||
|
||||
private static final String TMP_PATH = EnvUtils.getNacosHome() + File.separator + "data" + File.separator + "tmp" + File.separator;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws IOException {
|
||||
private static File testFile;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() throws IOException {
|
||||
testFile = DiskUtils.createTmpFile("nacostmp", ".ut");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDown() throws IOException {
|
||||
@AfterAll
|
||||
static void tearDown() throws IOException {
|
||||
testFile.deleteOnExit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTouch() throws IOException {
|
||||
void testTouch() throws IOException {
|
||||
File file = Paths.get(TMP_PATH, "touch.ut").toFile();
|
||||
Assert.assertFalse(file.exists());
|
||||
assertFalse(file.exists());
|
||||
DiskUtils.touch(file);
|
||||
Assert.assertTrue(file.exists());
|
||||
assertTrue(file.exists());
|
||||
file.deleteOnExit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTouchWithFileName() throws IOException {
|
||||
void testTouchWithFileName() throws IOException {
|
||||
File file = Paths.get(TMP_PATH, UUID.randomUUID().toString()).toFile();
|
||||
Assert.assertFalse(file.exists());
|
||||
assertFalse(file.exists());
|
||||
DiskUtils.touch(file.getParent(), file.getName());
|
||||
Assert.assertTrue(file.exists());
|
||||
assertTrue(file.exists());
|
||||
file.deleteOnExit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTmpFile() throws IOException {
|
||||
void testCreateTmpFile() throws IOException {
|
||||
File tmpFile = null;
|
||||
try {
|
||||
tmpFile = DiskUtils.createTmpFile("nacos1", ".ut");
|
||||
Assert.assertTrue(tmpFile.getName().startsWith("nacos1"));
|
||||
Assert.assertTrue(tmpFile.getName().endsWith(".ut"));
|
||||
assertTrue(tmpFile.getName().startsWith("nacos1"));
|
||||
assertTrue(tmpFile.getName().endsWith(".ut"));
|
||||
} finally {
|
||||
if (tmpFile != null) {
|
||||
tmpFile.deleteOnExit();
|
||||
@ -78,13 +83,13 @@ public class DiskUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateTmpFileWithPath() throws IOException {
|
||||
void testCreateTmpFileWithPath() throws IOException {
|
||||
File tmpFile = null;
|
||||
try {
|
||||
tmpFile = DiskUtils.createTmpFile(TMP_PATH, "nacos1", ".ut");
|
||||
Assert.assertEquals(TMP_PATH, tmpFile.getParent() + File.separator);
|
||||
Assert.assertTrue(tmpFile.getName().startsWith("nacos1"));
|
||||
Assert.assertTrue(tmpFile.getName().endsWith(".ut"));
|
||||
assertEquals(TMP_PATH, tmpFile.getParent() + File.separator);
|
||||
assertTrue(tmpFile.getName().startsWith("nacos1"));
|
||||
assertTrue(tmpFile.getName().endsWith(".ut"));
|
||||
} finally {
|
||||
if (tmpFile != null) {
|
||||
tmpFile.deleteOnExit();
|
||||
@ -93,94 +98,93 @@ public class DiskUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadFile() {
|
||||
Assert.assertNotNull(DiskUtils.readFile(testFile));
|
||||
void testReadFile() {
|
||||
assertNotNull(DiskUtils.readFile(testFile));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadFileWithInputStream() throws FileNotFoundException {
|
||||
Assert.assertNotNull(DiskUtils.readFile(new FileInputStream(testFile)));
|
||||
void testReadFileWithInputStream() throws FileNotFoundException {
|
||||
assertNotNull(DiskUtils.readFile(new FileInputStream(testFile)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadFileWithPath() {
|
||||
Assert.assertNotNull(DiskUtils.readFile(testFile.getParent(), testFile.getName()));
|
||||
void testReadFileWithPath() {
|
||||
assertNotNull(DiskUtils.readFile(testFile.getParent(), testFile.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadFileBytes() {
|
||||
Assert.assertNotNull(DiskUtils.readFileBytes(testFile));
|
||||
void testReadFileBytes() {
|
||||
assertNotNull(DiskUtils.readFileBytes(testFile));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadFileBytesWithPath() {
|
||||
Assert.assertNotNull(DiskUtils.readFileBytes(testFile.getParent(), testFile.getName()));
|
||||
void testReadFileBytesWithPath() {
|
||||
assertNotNull(DiskUtils.readFileBytes(testFile.getParent(), testFile.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeFile() {
|
||||
Assert.assertTrue(DiskUtils.writeFile(testFile, "unit test".getBytes(StandardCharsets.UTF_8), false));
|
||||
Assert.assertEquals("unit test", DiskUtils.readFile(testFile));
|
||||
void writeFile() {
|
||||
assertTrue(DiskUtils.writeFile(testFile, "unit test".getBytes(StandardCharsets.UTF_8), false));
|
||||
assertEquals("unit test", DiskUtils.readFile(testFile));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteQuietly() throws IOException {
|
||||
void deleteQuietly() throws IOException {
|
||||
File tmpFile = DiskUtils.createTmpFile(UUID.randomUUID().toString(), ".ut");
|
||||
DiskUtils.deleteQuietly(tmpFile);
|
||||
Assert.assertFalse(tmpFile.exists());
|
||||
assertFalse(tmpFile.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteQuietlyWithPath() throws IOException {
|
||||
void testDeleteQuietlyWithPath() throws IOException {
|
||||
String dir = TMP_PATH + "/" + "diskutils";
|
||||
DiskUtils.forceMkdir(dir);
|
||||
DiskUtils.createTmpFile(dir, "nacos", ".ut");
|
||||
Path path = Paths.get(dir);
|
||||
DiskUtils.deleteQuietly(path);
|
||||
|
||||
Assert.assertFalse(path.toFile().exists());
|
||||
assertFalse(path.toFile().exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteFile() throws IOException {
|
||||
void testDeleteFile() throws IOException {
|
||||
File tmpFile = DiskUtils.createTmpFile(UUID.randomUUID().toString(), ".ut");
|
||||
Assert.assertTrue(DiskUtils.deleteFile(tmpFile.getParent(), tmpFile.getName()));
|
||||
Assert.assertFalse(DiskUtils.deleteFile(tmpFile.getParent(), tmpFile.getName()));
|
||||
assertTrue(DiskUtils.deleteFile(tmpFile.getParent(), tmpFile.getName()));
|
||||
assertFalse(DiskUtils.deleteFile(tmpFile.getParent(), tmpFile.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteDirectory() throws IOException {
|
||||
void deleteDirectory() throws IOException {
|
||||
Path diskutils = Paths.get(TMP_PATH, "diskutils");
|
||||
File file = diskutils.toFile();
|
||||
if (!file.exists()) {
|
||||
file.mkdir();
|
||||
}
|
||||
|
||||
Assert.assertTrue(file.exists());
|
||||
assertTrue(file.exists());
|
||||
DiskUtils.deleteDirectory(diskutils.toString());
|
||||
Assert.assertFalse(file.exists());
|
||||
assertFalse(file.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForceMkdir() throws IOException {
|
||||
File dir = Paths.get(TMP_PATH, UUID.randomUUID().toString(), UUID.randomUUID().toString())
|
||||
.toFile();
|
||||
void testForceMkdir() throws IOException {
|
||||
File dir = Paths.get(TMP_PATH, UUID.randomUUID().toString(), UUID.randomUUID().toString()).toFile();
|
||||
DiskUtils.forceMkdir(dir);
|
||||
Assert.assertTrue(dir.exists());
|
||||
assertTrue(dir.exists());
|
||||
dir.deleteOnExit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testForceMkdirWithPath() throws IOException {
|
||||
void testForceMkdirWithPath() throws IOException {
|
||||
Path path = Paths.get(TMP_PATH, UUID.randomUUID().toString(), UUID.randomUUID().toString());
|
||||
DiskUtils.forceMkdir(path.toString());
|
||||
File file = path.toFile();
|
||||
Assert.assertTrue(file.exists());
|
||||
assertTrue(file.exists());
|
||||
file.deleteOnExit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteDirThenMkdir() throws IOException {
|
||||
void deleteDirThenMkdir() throws IOException {
|
||||
Path path = Paths.get(TMP_PATH, UUID.randomUUID().toString());
|
||||
DiskUtils.forceMkdir(path.toString());
|
||||
|
||||
@ -190,15 +194,15 @@ public class DiskUtilsTest {
|
||||
DiskUtils.deleteDirThenMkdir(path.toString());
|
||||
|
||||
File file = path.toFile();
|
||||
Assert.assertTrue(file.exists());
|
||||
Assert.assertTrue(file.isDirectory());
|
||||
Assert.assertTrue(file.list() == null || file.list().length == 0);
|
||||
assertTrue(file.exists());
|
||||
assertTrue(file.isDirectory());
|
||||
assertTrue(file.list() == null || file.list().length == 0);
|
||||
|
||||
file.deleteOnExit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyDirectory() throws IOException {
|
||||
void testCopyDirectory() throws IOException {
|
||||
Path srcPath = Paths.get(TMP_PATH, UUID.randomUUID().toString());
|
||||
DiskUtils.forceMkdir(srcPath.toString());
|
||||
File nacos = DiskUtils.createTmpFile(srcPath.toString(), "nacos", ".ut");
|
||||
@ -207,36 +211,36 @@ public class DiskUtilsTest {
|
||||
DiskUtils.copyDirectory(srcPath.toFile(), destPath.toFile());
|
||||
|
||||
File file = Paths.get(destPath.toString(), nacos.getName()).toFile();
|
||||
Assert.assertTrue(file.exists());
|
||||
assertTrue(file.exists());
|
||||
|
||||
DiskUtils.deleteDirectory(srcPath.toString());
|
||||
DiskUtils.deleteDirectory(destPath.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyFile() throws IOException {
|
||||
void testCopyFile() throws IOException {
|
||||
File nacos = DiskUtils.createTmpFile("nacos", ".ut");
|
||||
DiskUtils.copyFile(testFile, nacos);
|
||||
|
||||
Assert.assertEquals(DiskUtils.readFile(testFile), DiskUtils.readFile(nacos));
|
||||
assertEquals(DiskUtils.readFile(testFile), DiskUtils.readFile(nacos));
|
||||
|
||||
nacos.deleteOnExit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void openFile() {
|
||||
void openFile() {
|
||||
File file = DiskUtils.openFile(testFile.getParent(), testFile.getName());
|
||||
Assert.assertNotNull(file);
|
||||
Assert.assertEquals(testFile.getPath(), file.getPath());
|
||||
Assert.assertEquals(testFile.getName(), file.getName());
|
||||
assertNotNull(file);
|
||||
assertEquals(testFile.getPath(), file.getPath());
|
||||
assertEquals(testFile.getName(), file.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOpenFileWithPath() {
|
||||
void testOpenFileWithPath() {
|
||||
File file = DiskUtils.openFile(testFile.getParent(), testFile.getName(), false);
|
||||
Assert.assertNotNull(file);
|
||||
Assert.assertEquals(testFile.getPath(), file.getPath());
|
||||
Assert.assertEquals(testFile.getName(), file.getName());
|
||||
assertNotNull(file);
|
||||
assertEquals(testFile.getPath(), file.getPath());
|
||||
assertEquals(testFile.getName(), file.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,26 +16,27 @@
|
||||
|
||||
package com.alibaba.nacos.plugin.control.utils;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class EnvUtilsTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class EnvUtilsTest {
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
@AfterEach
|
||||
void tearDown() throws Exception {
|
||||
System.clearProperty("nacos.home");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
void test() {
|
||||
String nacosHome = EnvUtils.getNacosHome();
|
||||
Assert.assertEquals(System.getProperty("user.home") + File.separator + "nacos", nacosHome);
|
||||
assertEquals(System.getProperty("user.home") + File.separator + "nacos", nacosHome);
|
||||
|
||||
System.setProperty("nacos.home", "test");
|
||||
String testHome = EnvUtils.getNacosHome();
|
||||
Assert.assertEquals("test", testHome);
|
||||
assertEquals("test", testHome);
|
||||
}
|
||||
}
|
||||
|
@ -21,33 +21,35 @@ import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper;
|
||||
import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoAggrMapper;
|
||||
import com.alibaba.nacos.plugin.datasource.mapper.Mapper;
|
||||
import com.alibaba.nacos.plugin.datasource.mapper.TestMapper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
public class MapperManagerTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
class MapperManagerTest {
|
||||
|
||||
@Test
|
||||
public void testInstance() {
|
||||
void testInstance() {
|
||||
MapperManager instance = MapperManager.instance(false);
|
||||
Assert.assertNotNull(instance);
|
||||
assertNotNull(instance);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadInitial() throws NoSuchFieldException, IllegalAccessException {
|
||||
void testLoadInitial() throws NoSuchFieldException, IllegalAccessException {
|
||||
MapperManager instance = MapperManager.instance(false);
|
||||
instance.loadInitial();
|
||||
Class<MapperManager> mapperManagerClass = MapperManager.class;
|
||||
Field declaredField = mapperManagerClass.getDeclaredField("MAPPER_SPI_MAP");
|
||||
declaredField.setAccessible(true);
|
||||
Map<String, Map<String, Mapper>> map = (Map<String, Map<String, Mapper>>) declaredField.get(instance);
|
||||
Assert.assertEquals(2, map.size());
|
||||
assertEquals(2, map.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoin() {
|
||||
void testJoin() {
|
||||
MapperManager.join(new AbstractMapper() {
|
||||
@Override
|
||||
public String getTableName() {
|
||||
@ -61,23 +63,23 @@ public class MapperManagerTest {
|
||||
});
|
||||
MapperManager instance = MapperManager.instance(false);
|
||||
Mapper mapper = instance.findMapper(DataSourceConstant.MYSQL, "test");
|
||||
Assert.assertNotNull(mapper);
|
||||
assertNotNull(mapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindMapper() {
|
||||
void testFindMapper() {
|
||||
testJoin();
|
||||
MapperManager instance = MapperManager.instance(false);
|
||||
Mapper mapper = instance.findMapper(DataSourceConstant.MYSQL, "test");
|
||||
Assert.assertNotNull(mapper);
|
||||
assertNotNull(mapper);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEnableDataSourceLogJoin() {
|
||||
void testEnableDataSourceLogJoin() {
|
||||
MapperManager.join(new TestMapper());
|
||||
MapperManager instance = MapperManager.instance(true);
|
||||
ConfigInfoAggrMapper mapper = instance.findMapper(DataSourceConstant.MYSQL, "enable_data_source_log_test");
|
||||
Assert.assertNotNull(mapper);
|
||||
assertNotNull(mapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,9 @@ package com.alibaba.nacos.plugin.datasource.impl;
|
||||
|
||||
/**
|
||||
* A custom interface. just for test
|
||||
*
|
||||
* @author mikolls
|
||||
**/
|
||||
public interface TestInterface {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,24 +22,25 @@ import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigInfoAggrMapperByDerbyTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ConfigInfoAggrMapperByDerbyTest {
|
||||
|
||||
private ConfigInfoAggrMapperByDerby configInfoAggrMapperByDerby;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
this.configInfoAggrMapperByDerby = new ConfigInfoAggrMapperByDerby();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchRemoveAggr() {
|
||||
void testBatchRemoveAggr() {
|
||||
List<String> datumList = Arrays.asList("1", "2", "3", "4", "5");
|
||||
String dataId = "data-id";
|
||||
String groupId = "group-id";
|
||||
@ -57,13 +58,13 @@ public class ConfigInfoAggrMapperByDerbyTest {
|
||||
String sql = result.getSql();
|
||||
List<Object> paramList = result.getParamList();
|
||||
|
||||
Assert.assertEquals(sql, "DELETE FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? "
|
||||
+ "AND datum_id IN (?, ?, ?, ?, ?)");
|
||||
Assert.assertEquals(paramList, argList);
|
||||
assertEquals(sql,
|
||||
"DELETE FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? " + "AND datum_id IN (?, ?, ?, ?, ?)");
|
||||
assertEquals(paramList, argList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAggrConfigInfoCount() {
|
||||
void testAggrConfigInfoCount() {
|
||||
List<String> datumIds = Arrays.asList("1", "2", "3", "4", "5");
|
||||
String dataId = "data-id";
|
||||
String groupId = "group-id";
|
||||
@ -82,14 +83,13 @@ public class ConfigInfoAggrMapperByDerbyTest {
|
||||
String sql = mapperResult.getSql();
|
||||
List<Object> paramList = mapperResult.getParamList();
|
||||
|
||||
Assert.assertEquals(sql,
|
||||
"SELECT count(*) FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? "
|
||||
+ "AND datum_id IN (?, ?, ?, ?, ?)");
|
||||
Assert.assertEquals(paramList, argList);
|
||||
assertEquals(sql, "SELECT count(*) FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? "
|
||||
+ "AND datum_id IN (?, ?, ?, ?, ?)");
|
||||
assertEquals(paramList, argList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoAggrIsOrdered() {
|
||||
void testFindConfigInfoAggrIsOrdered() {
|
||||
String dataId = "data-id";
|
||||
String groupId = "group-id";
|
||||
String tenantId = "tenant-id";
|
||||
@ -103,13 +103,13 @@ public class ConfigInfoAggrMapperByDerbyTest {
|
||||
String sql = mapperResult.getSql();
|
||||
List<Object> paramList = mapperResult.getParamList();
|
||||
|
||||
Assert.assertEquals(sql, "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM "
|
||||
assertEquals(sql, "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM "
|
||||
+ "config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY datum_id");
|
||||
Assert.assertEquals(paramList, CollectionUtils.list(dataId, groupId, tenantId));
|
||||
assertEquals(paramList, CollectionUtils.list(dataId, groupId, tenantId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoAggrByPageFetchRows() {
|
||||
void testFindConfigInfoAggrByPageFetchRows() {
|
||||
String dataId = "data-id";
|
||||
String groupId = "group-id";
|
||||
String tenantId = "tenant-id";
|
||||
@ -126,27 +126,26 @@ public class ConfigInfoAggrMapperByDerbyTest {
|
||||
MapperResult mapperResult = configInfoAggrMapperByDerby.findConfigInfoAggrByPageFetchRows(context);
|
||||
String sql = mapperResult.getSql();
|
||||
List<Object> paramList = mapperResult.getParamList();
|
||||
Assert.assertEquals(sql,
|
||||
"SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE "
|
||||
+ "data_id=? AND group_id=? AND tenant_id=? ORDER BY datum_id OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY");
|
||||
Assert.assertEquals(paramList, CollectionUtils.list(dataId, groupId, tenantId));
|
||||
assertEquals(sql, "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE "
|
||||
+ "data_id=? AND group_id=? AND tenant_id=? ORDER BY datum_id OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY");
|
||||
assertEquals(paramList, CollectionUtils.list(dataId, groupId, tenantId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllAggrGroupByDistinct() {
|
||||
void testFindAllAggrGroupByDistinct() {
|
||||
MapperResult sql = configInfoAggrMapperByDerby.findAllAggrGroupByDistinct(null);
|
||||
Assert.assertEquals(sql.getSql(), "SELECT DISTINCT data_id, group_id, tenant_id FROM config_info_aggr");
|
||||
assertEquals("SELECT DISTINCT data_id, group_id, tenant_id FROM config_info_aggr", sql.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = configInfoAggrMapperByDerby.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.CONFIG_INFO_AGGR);
|
||||
assertEquals(TableConstant.CONFIG_INFO_AGGR, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = configInfoAggrMapperByDerby.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.DERBY);
|
||||
assertEquals(DataSourceConstant.DERBY, dataSource);
|
||||
}
|
||||
}
|
||||
|
@ -22,17 +22,17 @@ import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigInfoBetaMapperByDerbyTest {
|
||||
|
||||
private ConfigInfoBetaMapperByDerby configInfoBetaMapperByDerby;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ConfigInfoBetaMapperByDerbyTest {
|
||||
|
||||
int startRow = 0;
|
||||
|
||||
@ -52,8 +52,10 @@ public class ConfigInfoBetaMapperByDerbyTest {
|
||||
|
||||
MapperContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
private ConfigInfoBetaMapperByDerby configInfoBetaMapperByDerby;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
configInfoBetaMapperByDerby = new ConfigInfoBetaMapperByDerby();
|
||||
|
||||
context = new MapperContext(startRow, pageSize);
|
||||
@ -67,7 +69,7 @@ public class ConfigInfoBetaMapperByDerbyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateConfigInfo4BetaCas() {
|
||||
void testUpdateConfigInfo4BetaCas() {
|
||||
String newContent = "new Content";
|
||||
String newMD5 = "newMD5";
|
||||
String srcIp = "1.1.1.1";
|
||||
@ -106,35 +108,33 @@ public class ConfigInfoBetaMapperByDerbyTest {
|
||||
MapperResult mapperResult = configInfoBetaMapperByDerby.updateConfigInfo4BetaCas(context);
|
||||
|
||||
String sql = mapperResult.getSql();
|
||||
Assert.assertEquals(sql, "UPDATE config_info_beta SET content = ?,md5 = ?,beta_ips = ?,src_ip = ?,src_user = ?,"
|
||||
assertEquals(sql, "UPDATE config_info_beta SET content = ?,md5 = ?,beta_ips = ?,src_ip = ?,src_user = ?,"
|
||||
+ "gmt_modified = ?,app_name = ? WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND "
|
||||
+ "(md5 = ? OR md5 is null OR md5 = '')");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(),
|
||||
new Object[] {newContent, newMD5, betaIps, srcIp, srcUser, time, appNameTmp, dataId, group, tenantId,
|
||||
md5});
|
||||
assertArrayEquals(new Object[] {newContent, newMD5, betaIps, srcIp, srcUser, time, appNameTmp, dataId, group, tenantId, md5},
|
||||
mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllConfigInfoBetaForDumpAllFetchRows() {
|
||||
void testFindAllConfigInfoBetaForDumpAllFetchRows() {
|
||||
MapperResult result = configInfoBetaMapperByDerby.findAllConfigInfoBetaForDumpAllFetchRows(context);
|
||||
String sql = result.getSql();
|
||||
List<Object> paramList = result.getParamList();
|
||||
Assert.assertEquals(sql,
|
||||
"SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,beta_ips FROM "
|
||||
+ "( SELECT id FROM config_info_beta ORDER BY id OFFSET " + startRow + " ROWS FETCH NEXT "
|
||||
+ pageSize + " ROWS ONLY ) g, " + "config_info_beta t WHERE g.id = t.id");
|
||||
Assert.assertEquals(paramList, Arrays.asList(startRow, pageSize));
|
||||
assertEquals(sql, "SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,beta_ips FROM "
|
||||
+ "( SELECT id FROM config_info_beta ORDER BY id OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY ) g, "
|
||||
+ "config_info_beta t WHERE g.id = t.id");
|
||||
assertEquals(paramList, Arrays.asList(startRow, pageSize));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = configInfoBetaMapperByDerby.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.CONFIG_INFO_BETA);
|
||||
assertEquals(TableConstant.CONFIG_INFO_BETA, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = configInfoBetaMapperByDerby.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.DERBY);
|
||||
assertEquals(DataSourceConstant.DERBY, dataSource);
|
||||
}
|
||||
}
|
||||
|
@ -23,16 +23,16 @@ import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigInfoMapperByDerbyTest {
|
||||
|
||||
private ConfigInfoMapperByDerby configInfoMapperByDerby;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ConfigInfoMapperByDerbyTest {
|
||||
|
||||
private final Object[] emptyObjs = new Object[] {};
|
||||
|
||||
@ -58,8 +58,10 @@ public class ConfigInfoMapperByDerbyTest {
|
||||
|
||||
MapperContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
private ConfigInfoMapperByDerby configInfoMapperByDerby;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
configInfoMapperByDerby = new ConfigInfoMapperByDerby();
|
||||
|
||||
context = new MapperContext(startRow, pageSize);
|
||||
@ -74,256 +76,243 @@ public class ConfigInfoMapperByDerbyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigMaxId() {
|
||||
void testFindConfigMaxId() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findConfigMaxId(null);
|
||||
Assert.assertEquals(mapperResult.getSql(), "SELECT MAX(id) FROM config_info");
|
||||
assertEquals("SELECT MAX(id) FROM config_info", mapperResult.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllDataIdAndGroup() {
|
||||
void testFindAllDataIdAndGroup() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findAllDataIdAndGroup(null);
|
||||
Assert.assertEquals(mapperResult.getSql(), "SELECT DISTINCT data_id, group_id FROM config_info");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertEquals("SELECT DISTINCT data_id, group_id FROM config_info", mapperResult.getSql());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoByAppCountRows() {
|
||||
void testFindConfigInfoByAppCountRows() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findConfigInfoByAppCountRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT count(*) FROM config_info WHERE tenant_id LIKE ? AND app_name = ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, appName});
|
||||
assertEquals("SELECT count(*) FROM config_info WHERE tenant_id LIKE ? AND app_name = ?", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {tenantId, appName}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoByAppFetchRows() {
|
||||
void testFindConfigInfoByAppFetchRows() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findConfigInfoByAppFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT ID,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE tenant_id LIKE"
|
||||
+ " ? AND app_name = ? OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, appName});
|
||||
assertEquals(mapperResult.getSql(), "SELECT ID,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE tenant_id LIKE"
|
||||
+ " ? AND app_name = ? OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY");
|
||||
assertArrayEquals(new Object[] {tenantId, appName}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigInfoLikeTenantCount() {
|
||||
void testConfigInfoLikeTenantCount() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.configInfoLikeTenantCount(context);
|
||||
Assert.assertEquals(mapperResult.getSql(), "SELECT count(*) FROM config_info WHERE tenant_id LIKE ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId});
|
||||
assertEquals("SELECT count(*) FROM config_info WHERE tenant_id LIKE ?", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {tenantId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTenantIdList() {
|
||||
void testGetTenantIdList() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.getTenantIdList(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT tenant_id FROM config_info WHERE tenant_id != '' GROUP BY tenant_id OFFSET " + startRow
|
||||
+ " ROWS FETCH NEXT " + pageSize + " ROWS ONLY");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT tenant_id FROM config_info WHERE tenant_id != '' GROUP BY tenant_id OFFSET " + startRow + " ROWS FETCH NEXT "
|
||||
+ pageSize + " ROWS ONLY");
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGroupIdList() {
|
||||
void testGetGroupIdList() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.getGroupIdList(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT group_id FROM config_info WHERE tenant_id ='' GROUP BY group_id OFFSET " + startRow
|
||||
+ " ROWS FETCH NEXT " + pageSize + " ROWS ONLY");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT group_id FROM config_info WHERE tenant_id ='' GROUP BY group_id OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize
|
||||
+ " ROWS ONLY");
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllConfigKey() {
|
||||
void testFindAllConfigKey() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findAllConfigKey(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
" SELECT data_id,group_id,app_name FROM ( SELECT id FROM config_info WHERE tenant_id LIKE"
|
||||
+ " ? ORDER BY id OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize
|
||||
+ " ROWS ONLY ) g, config_info t WHERE g.id = t.id ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId});
|
||||
assertEquals(mapperResult.getSql(),
|
||||
" SELECT data_id,group_id,app_name FROM ( SELECT id FROM config_info WHERE tenant_id LIKE" + " ? ORDER BY id OFFSET "
|
||||
+ startRow + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY ) g, config_info t WHERE g.id = t.id ");
|
||||
assertArrayEquals(new Object[] {tenantId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllConfigInfoBaseFetchRows() {
|
||||
void testFindAllConfigInfoBaseFetchRows() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findAllConfigInfoBaseFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT t.id,data_id,group_id,content,md5 FROM ( SELECT id FROM config_info ORDER BY " + "id OFFSET "
|
||||
+ startRow + " ROWS FETCH NEXT " + pageSize
|
||||
+ " ROWS ONLY ) g, config_info t WHERE g.id = t.id ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT t.id,data_id,group_id,content,md5 FROM ( SELECT id FROM config_info ORDER BY " + "id OFFSET " + startRow
|
||||
+ " ROWS FETCH NEXT " + pageSize + " ROWS ONLY ) g, config_info t WHERE g.id = t.id ");
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllConfigInfoFragment() {
|
||||
void testFindAllConfigInfoFragment() {
|
||||
//with content
|
||||
context.putContextParameter(ContextConstant.NEED_CONTENT, "true");
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findAllConfigInfoFragment(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,type FROM config_info "
|
||||
+ "WHERE id > ? ORDER BY id ASC OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize
|
||||
+ " ROWS ONLY");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {id});
|
||||
assertEquals(mapperResult.getSql(), "SELECT id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,type FROM config_info "
|
||||
+ "WHERE id > ? ORDER BY id ASC OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY");
|
||||
assertArrayEquals(new Object[] {id}, mapperResult.getParamList().toArray());
|
||||
//with out content
|
||||
context.putContextParameter(ContextConstant.NEED_CONTENT, "false");
|
||||
|
||||
|
||||
MapperResult mapperResult2 = configInfoMapperByDerby.findAllConfigInfoFragment(context);
|
||||
Assert.assertEquals(mapperResult2.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,md5,gmt_modified,type FROM config_info "
|
||||
+ "WHERE id > ? ORDER BY id ASC OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize
|
||||
+ " ROWS ONLY");
|
||||
Assert.assertArrayEquals(mapperResult2.getParamList().toArray(), new Object[] {id});
|
||||
assertEquals(mapperResult2.getSql(), "SELECT id,data_id,group_id,tenant_id,app_name,md5,gmt_modified,type FROM config_info "
|
||||
+ "WHERE id > ? ORDER BY id ASC OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY");
|
||||
assertArrayEquals(new Object[] {id}, mapperResult2.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindChangeConfig() {
|
||||
void testFindChangeConfig() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findChangeConfig(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT id, data_id, group_id, tenant_id, app_name, content, gmt_modified, encrypted_data_key FROM config_info "
|
||||
+ "WHERE gmt_modified >= ? and id > ? order by id OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {startTime, lastMaxId, pageSize});
|
||||
assertArrayEquals(new Object[] {startTime, lastMaxId, pageSize}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindChangeConfigCountRows() {
|
||||
void testFindChangeConfigCountRows() {
|
||||
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findChangeConfigCountRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT count(*) FROM config_info WHERE 1=1 AND app_name = ? AND gmt_modified >=? AND gmt_modified <=? ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {appName, startTime, endTime});
|
||||
assertEquals("SELECT count(*) FROM config_info WHERE 1=1 AND app_name = ? AND gmt_modified >=? AND gmt_modified <=? ",
|
||||
mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {appName, startTime, endTime}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindChangeConfigFetchRows() {
|
||||
void testFindChangeConfigFetchRows() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findChangeConfigFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_modified FROM config_info "
|
||||
+ "WHERE 1=1 AND app_name = ? AND gmt_modified >=? AND gmt_modified <=? OFFSET " + startRow
|
||||
+ " ROWS FETCH NEXT " + pageSize + " ROWS ONLY");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {appName, startTime, endTime});
|
||||
assertEquals(mapperResult.getSql(), "SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_modified FROM config_info "
|
||||
+ "WHERE 1=1 AND app_name = ? AND gmt_modified >=? AND gmt_modified <=? OFFSET " + startRow + " ROWS FETCH NEXT "
|
||||
+ pageSize + " ROWS ONLY");
|
||||
assertArrayEquals(new Object[] {appName, startTime, endTime}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListGroupKeyMd5ByPageFetchRows() {
|
||||
void testListGroupKeyMd5ByPageFetchRows() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.listGroupKeyMd5ByPageFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
" SELECT t.id,data_id,group_id,tenant_id,app_name,type,md5,gmt_modified FROM ( SELECT id FROM config_info "
|
||||
+ "ORDER BY id OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize
|
||||
+ " ROWS ONLY ) g, config_info t WHERE g.id = t.id");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllConfigInfo4Export() {
|
||||
void testFindAllConfigInfo4Export() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findAllConfigInfo4Export(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_create,gmt_modified,src_user,"
|
||||
+ "src_ip,c_desc,c_use,effect,c_schema,encrypted_data_key FROM config_info WHERE id IN (?, ?, ?, ?, ?) ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), ids.toArray());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), ids.toArray());
|
||||
|
||||
context.putWhereParameter(FieldConstant.IDS, null);
|
||||
mapperResult = configInfoMapperByDerby.findAllConfigInfo4Export(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_create,gmt_modified,src_user,"
|
||||
+ "src_ip,c_desc,c_use,effect,c_schema,encrypted_data_key FROM config_info WHERE tenant_id = ? AND app_name= ? ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, appName});
|
||||
assertArrayEquals(new Object[] {tenantId, appName}, mapperResult.getParamList().toArray());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoBaseLikeCountRows() {
|
||||
void testFindConfigInfoBaseLikeCountRows() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findConfigInfoBaseLikeCountRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(), "SELECT count(*) FROM config_info WHERE 1=1 AND tenant_id='' ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertEquals("SELECT count(*) FROM config_info WHERE 1=1 AND tenant_id='' ", mapperResult.getSql());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoBaseLikeFetchRows() {
|
||||
void testFindConfigInfoBaseLikeFetchRows() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findConfigInfoBaseLikeFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE 1=1 AND tenant_id='' "
|
||||
+ "OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE 1=1 AND tenant_id='' " + "OFFSET " + startRow
|
||||
+ " ROWS FETCH NEXT " + pageSize + " ROWS ONLY");
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfo4PageCountRows() {
|
||||
void testFindConfigInfo4PageCountRows() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findConfigInfo4PageCountRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT count(*) FROM config_info WHERE tenant_id=? AND app_name=? ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, appName});
|
||||
assertEquals("SELECT count(*) FROM config_info WHERE tenant_id=? AND app_name=? ", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {tenantId, appName}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfo4PageFetchRows() {
|
||||
void testFindConfigInfo4PageFetchRows() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findConfigInfo4PageFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,content,type FROM config_info WHERE tenant_id=? AND app_name=? "
|
||||
+ " OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, appName});
|
||||
assertArrayEquals(new Object[] {tenantId, appName}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoBaseByGroupFetchRows() {
|
||||
void testFindConfigInfoBaseByGroupFetchRows() {
|
||||
context.putWhereParameter(FieldConstant.GROUP_ID, groupId);
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findConfigInfoBaseByGroupFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=? " + "OFFSET "
|
||||
+ startRow + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {groupId, tenantId});
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=? " + "OFFSET " + startRow
|
||||
+ " ROWS FETCH NEXT " + pageSize + " ROWS ONLY");
|
||||
assertArrayEquals(new Object[] {groupId, tenantId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoLike4PageCountRows() {
|
||||
void testFindConfigInfoLike4PageCountRows() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findConfigInfoLike4PageCountRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT count(*) FROM config_info WHERE tenant_id LIKE ? AND app_name = ? ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, appName});
|
||||
assertEquals("SELECT count(*) FROM config_info WHERE tenant_id LIKE ? AND app_name = ? ", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {tenantId, appName}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoLike4PageFetchRows() {
|
||||
void testFindConfigInfoLike4PageFetchRows() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findConfigInfoLike4PageFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key FROM config_info "
|
||||
+ "WHERE tenant_id LIKE ? AND app_name = ? OFFSET " + startRow + " ROWS FETCH NEXT "
|
||||
+ pageSize + " ROWS ONLY");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, appName});
|
||||
assertEquals(mapperResult.getSql(), "SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key FROM config_info "
|
||||
+ "WHERE tenant_id LIKE ? AND app_name = ? OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY");
|
||||
assertArrayEquals(new Object[] {tenantId, appName}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllConfigInfoFetchRows() {
|
||||
void testFindAllConfigInfoFetchRows() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findAllConfigInfoFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
" SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 FROM ( SELECT id FROM config_info "
|
||||
+ "WHERE tenant_id LIKE ? ORDER BY id OFFSET ? ROWS FETCH NEXT ? ROWS ONLY ) g, config_info t WHERE g.id = t.id ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, startRow, pageSize});
|
||||
assertArrayEquals(new Object[] {tenantId, startRow, pageSize}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfosByIds() {
|
||||
void testFindConfigInfosByIds() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.findConfigInfosByIds(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,content,md5 FROM config_info WHERE id IN (?, ?, ?, ?, ?) ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), ids.toArray());
|
||||
assertEquals("SELECT id,data_id,group_id,tenant_id,app_name,content,md5 FROM config_info WHERE id IN (?, ?, ?, ?, ?) ",
|
||||
mapperResult.getSql());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), ids.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveConfigInfoByIdsAtomic() {
|
||||
void testRemoveConfigInfoByIdsAtomic() {
|
||||
MapperResult mapperResult = configInfoMapperByDerby.removeConfigInfoByIdsAtomic(context);
|
||||
Assert.assertEquals(mapperResult.getSql(), "DELETE FROM config_info WHERE id IN (?, ?, ?, ?, ?) ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), ids.toArray());
|
||||
assertEquals("DELETE FROM config_info WHERE id IN (?, ?, ?, ?, ?) ", mapperResult.getSql());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), ids.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String sql = configInfoMapperByDerby.getTableName();
|
||||
Assert.assertEquals(sql, TableConstant.CONFIG_INFO);
|
||||
assertEquals(TableConstant.CONFIG_INFO, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String sql = configInfoMapperByDerby.getDataSource();
|
||||
Assert.assertEquals(sql, DataSourceConstant.DERBY);
|
||||
assertEquals(DataSourceConstant.DERBY, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateConfigInfoAtomicCas() {
|
||||
void testUpdateConfigInfoAtomicCas() {
|
||||
String newContent = "new Content";
|
||||
String newMD5 = "newMD5";
|
||||
String srcIp = "1.1.1.1";
|
||||
@ -358,12 +347,12 @@ public class ConfigInfoMapperByDerbyTest {
|
||||
context.putWhereParameter(FieldConstant.MD5, md5);
|
||||
|
||||
MapperResult mapperResult = configInfoMapperByDerby.updateConfigInfoAtomicCas(context);
|
||||
Assert.assertEquals(mapperResult.getSql(), "UPDATE config_info SET "
|
||||
+ "content=?, md5 = ?, src_ip=?,src_user=?,gmt_modified=?, app_name=?,c_desc=?,c_use=?,"
|
||||
+ "effect=?,type=?,c_schema=?,encrypted_data_key=? "
|
||||
+ "WHERE data_id=? AND group_id=? AND tenant_id=? AND (md5=? OR md5 IS NULL OR md5='')");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(),
|
||||
new Object[] {newContent, newMD5, srcIp, srcUser, time, appNameTmp, desc, use, effect, type, schema,
|
||||
encrypedDataKey, dataId, group, tenantId, md5});
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"UPDATE config_info SET " + "content=?, md5 = ?, src_ip=?,src_user=?,gmt_modified=?, app_name=?,c_desc=?,c_use=?,"
|
||||
+ "effect=?,type=?,c_schema=?,encrypted_data_key=? "
|
||||
+ "WHERE data_id=? AND group_id=? AND tenant_id=? AND (md5=? OR md5 IS NULL OR md5='')");
|
||||
assertArrayEquals(
|
||||
new Object[] {newContent, newMD5, srcIp, srcUser, time, appNameTmp, desc, use, effect, type, schema, encrypedDataKey,
|
||||
dataId, group, tenantId, md5}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
}
|
||||
|
@ -22,16 +22,16 @@ import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigInfoTagMapperByDerbyTest {
|
||||
|
||||
private ConfigInfoTagMapperByDerby configInfoTagMapperByDerby;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ConfigInfoTagMapperByDerbyTest {
|
||||
|
||||
private final Object[] emptyObjs = new Object[] {};
|
||||
|
||||
@ -53,8 +53,10 @@ public class ConfigInfoTagMapperByDerbyTest {
|
||||
|
||||
MapperContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
private ConfigInfoTagMapperByDerby configInfoTagMapperByDerby;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
configInfoTagMapperByDerby = new ConfigInfoTagMapperByDerby();
|
||||
|
||||
context = new MapperContext(startRow, pageSize);
|
||||
@ -68,7 +70,7 @@ public class ConfigInfoTagMapperByDerbyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateConfigInfo4TagCas() {
|
||||
void testUpdateConfigInfo4TagCas() {
|
||||
String newContent = "new Content";
|
||||
String newMD5 = "newMD5";
|
||||
String srcIp = "1.1.1.1";
|
||||
@ -106,34 +108,31 @@ public class ConfigInfoTagMapperByDerbyTest {
|
||||
|
||||
MapperResult mapperResult = configInfoTagMapperByDerby.updateConfigInfo4TagCas(context);
|
||||
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE config_info_tag SET content = ?, md5 = ?, src_ip = ?,src_user = ?,gmt_modified = ?,"
|
||||
+ "app_name = ? WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND tag_id = ? AND "
|
||||
+ "(md5 = ? OR md5 IS NULL OR md5 = '')");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(),
|
||||
new Object[] {newContent, newMD5, srcIp, srcUser, time, appNameTmp, dataId, group, tenantId, tagId,
|
||||
md5});
|
||||
assertEquals(mapperResult.getSql(), "UPDATE config_info_tag SET content = ?, md5 = ?, src_ip = ?,src_user = ?,gmt_modified = ?,"
|
||||
+ "app_name = ? WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND tag_id = ? AND "
|
||||
+ "(md5 = ? OR md5 IS NULL OR md5 = '')");
|
||||
assertArrayEquals(new Object[] {newContent, newMD5, srcIp, srcUser, time, appNameTmp, dataId, group, tenantId, tagId, md5},
|
||||
mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllConfigInfoTagForDumpAllFetchRows() {
|
||||
void testFindAllConfigInfoTagForDumpAllFetchRows() {
|
||||
MapperResult mapperResult = configInfoTagMapperByDerby.findAllConfigInfoTagForDumpAllFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified FROM "
|
||||
+ "( SELECT id FROM config_info_tag ORDER BY id OFFSET " + startRow + " ROWS FETCH NEXT "
|
||||
+ pageSize + " ROWS ONLY ) g, " + "config_info_tag t WHERE g.id = t.id");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertEquals(mapperResult.getSql(), "SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified FROM "
|
||||
+ "( SELECT id FROM config_info_tag ORDER BY id OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY ) g, "
|
||||
+ "config_info_tag t WHERE g.id = t.id");
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = configInfoTagMapperByDerby.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.CONFIG_INFO_TAG);
|
||||
assertEquals(TableConstant.CONFIG_INFO_TAG, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = configInfoTagMapperByDerby.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.DERBY);
|
||||
assertEquals(DataSourceConstant.DERBY, dataSource);
|
||||
}
|
||||
}
|
||||
|
@ -22,16 +22,16 @@ import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigInfoTagsRelationMapperByDerbyTest {
|
||||
|
||||
private ConfigInfoTagsRelationMapperByDerby configInfoTagsRelationMapperByDerby;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ConfigInfoTagsRelationMapperByDerbyTest {
|
||||
|
||||
int startRow = 0;
|
||||
|
||||
@ -43,8 +43,10 @@ public class ConfigInfoTagsRelationMapperByDerbyTest {
|
||||
|
||||
MapperContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
private ConfigInfoTagsRelationMapperByDerby configInfoTagsRelationMapperByDerby;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
this.configInfoTagsRelationMapperByDerby = new ConfigInfoTagsRelationMapperByDerby();
|
||||
context = new MapperContext(startRow, pageSize);
|
||||
context.putWhereParameter(FieldConstant.TENANT_ID, tenantId);
|
||||
@ -52,60 +54,57 @@ public class ConfigInfoTagsRelationMapperByDerbyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfo4PageCountRows() {
|
||||
void testFindConfigInfo4PageCountRows() {
|
||||
MapperResult mapperResult = configInfoTagsRelationMapperByDerby.findConfigInfoLike4PageCountRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id WHERE "
|
||||
+ "a.tenant_id LIKE ? AND b.tag_name IN (?, ?, ?, ?, ?) ");
|
||||
assertEquals(mapperResult.getSql(), "SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id WHERE "
|
||||
+ "a.tenant_id LIKE ? AND b.tag_name IN (?, ?, ?, ?, ?) ");
|
||||
List<Object> list = CollectionUtils.list(tenantId);
|
||||
list.addAll(Arrays.asList(tagArr));
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfo4PageFetchRows() {
|
||||
void testFindConfigInfo4PageFetchRows() {
|
||||
MapperResult mapperResult = configInfoTagsRelationMapperByDerby.findConfigInfo4PageFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN "
|
||||
+ "config_tags_relation b ON a.id=b.id WHERE a.tenant_id=? AND b.tag_name IN (?, ?, ?, ?, ?) "
|
||||
+ "OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY");
|
||||
List<Object> list = CollectionUtils.list(tenantId);
|
||||
list.addAll(Arrays.asList(tagArr));
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoLike4PageCountRows() {
|
||||
void testFindConfigInfoLike4PageCountRows() {
|
||||
MapperResult mapperResult = configInfoTagsRelationMapperByDerby.findConfigInfoLike4PageCountRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id "
|
||||
+ "WHERE a.tenant_id LIKE ? AND b.tag_name IN (?, ?, ?, ?, ?) ");
|
||||
assertEquals(mapperResult.getSql(), "SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id "
|
||||
+ "WHERE a.tenant_id LIKE ? AND b.tag_name IN (?, ?, ?, ?, ?) ");
|
||||
List<Object> list = CollectionUtils.list(tenantId);
|
||||
list.addAll(Arrays.asList(tagArr));
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tsetFindConfigInfoLike4PageFetchRows() {
|
||||
void tsetFindConfigInfoLike4PageFetchRows() {
|
||||
MapperResult mapperResult = configInfoTagsRelationMapperByDerby.findConfigInfoLike4PageFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT a.ID,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a "
|
||||
+ "LEFT JOIN config_tags_relation b ON a.id=b.id WHERE a.tenant_id LIKE ? AND b.tag_name "
|
||||
+ "IN (?, ?, ?, ?, ?) OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY");
|
||||
assertEquals(mapperResult.getSql(), "SELECT a.ID,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a "
|
||||
+ "LEFT JOIN config_tags_relation b ON a.id=b.id WHERE a.tenant_id LIKE ? AND b.tag_name "
|
||||
+ "IN (?, ?, ?, ?, ?) OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY");
|
||||
List<Object> list = CollectionUtils.list(tenantId);
|
||||
list.addAll(Arrays.asList(tagArr));
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = configInfoTagsRelationMapperByDerby.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.CONFIG_TAGS_RELATION);
|
||||
assertEquals(TableConstant.CONFIG_TAGS_RELATION, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = configInfoTagsRelationMapperByDerby.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.DERBY);
|
||||
assertEquals(DataSourceConstant.DERBY, dataSource);
|
||||
}
|
||||
}
|
||||
|
@ -21,15 +21,15 @@ import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class GroupCapacityMapperByDerbyTest {
|
||||
|
||||
private GroupCapacityMapperByDerby groupCapacityMapperByDerby;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class GroupCapacityMapperByDerbyTest {
|
||||
|
||||
private final Object[] emptyObjs = new Object[] {};
|
||||
|
||||
@ -45,8 +45,10 @@ public class GroupCapacityMapperByDerbyTest {
|
||||
|
||||
MapperContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
private GroupCapacityMapperByDerby groupCapacityMapperByDerby;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
this.groupCapacityMapperByDerby = new GroupCapacityMapperByDerby();
|
||||
context = new MapperContext(startRow, pageSize);
|
||||
context.putUpdateParameter(FieldConstant.GMT_MODIFIED, modified);
|
||||
@ -56,19 +58,19 @@ public class GroupCapacityMapperByDerbyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = groupCapacityMapperByDerby.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.GROUP_CAPACITY);
|
||||
assertEquals(TableConstant.GROUP_CAPACITY, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = groupCapacityMapperByDerby.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.DERBY);
|
||||
assertEquals(DataSourceConstant.DERBY, dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertIntoSelect() {
|
||||
void testInsertIntoSelect() {
|
||||
Object group = "group";
|
||||
Object quota = "quota";
|
||||
Object maxAggrSize = 10;
|
||||
@ -85,16 +87,16 @@ public class GroupCapacityMapperByDerbyTest {
|
||||
context.putUpdateParameter(FieldConstant.GMT_MODIFIED, modified);
|
||||
|
||||
MapperResult mapperResult = groupCapacityMapperByDerby.insertIntoSelect(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"INSERT INTO group_capacity (group_id, quota, usage, max_size, max_aggr_count, max_aggr_size,gmt_create,"
|
||||
+ " gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info");
|
||||
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(),
|
||||
new Object[] {group, quota, maxSize, maxAggrCount, maxAggrSize, createTime, modified});
|
||||
assertArrayEquals(new Object[] {group, quota, maxSize, maxAggrCount, maxAggrSize, createTime, modified},
|
||||
mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertIntoSelectByWhere() {
|
||||
void testInsertIntoSelectByWhere() {
|
||||
Object group = "group";
|
||||
Object quota = "quota";
|
||||
Object maxAggrSize = 10;
|
||||
@ -112,74 +114,72 @@ public class GroupCapacityMapperByDerbyTest {
|
||||
context.putUpdateParameter(FieldConstant.GMT_MODIFIED, modified);
|
||||
|
||||
MapperResult mapperResult = groupCapacityMapperByDerby.insertIntoSelectByWhere(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"INSERT INTO group_capacity (group_id, quota, usage, max_size, max_aggr_count, max_aggr_size, gmt_create,"
|
||||
+ " gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info WHERE group_id=? AND tenant_id = ''");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(),
|
||||
new Object[] {group, quota, maxSize, maxAggrCount, maxAggrSize, createTime, modified, group});
|
||||
assertArrayEquals(new Object[] {group, quota, maxSize, maxAggrCount, maxAggrSize, createTime, modified, group},
|
||||
mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementUsageByWhereQuotaEqualZero() {
|
||||
void testIncrementUsageByWhereQuotaEqualZero() {
|
||||
Object usage = 1;
|
||||
context.putWhereParameter(FieldConstant.USAGE, usage);
|
||||
MapperResult mapperResult = groupCapacityMapperByDerby.incrementUsageByWhereQuotaEqualZero(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE group_capacity SET usage = usage + 1, gmt_modified = ? WHERE group_id = ? AND usage < ? AND quota = 0");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, groupId, usage});
|
||||
assertEquals("UPDATE group_capacity SET usage = usage + 1, gmt_modified = ? WHERE group_id = ? AND usage < ? AND quota = 0",
|
||||
mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {modified, groupId, usage}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementUsageByWhereQuotaNotEqualZero() {
|
||||
void testIncrementUsageByWhereQuotaNotEqualZero() {
|
||||
|
||||
MapperResult mapperResult = groupCapacityMapperByDerby.incrementUsageByWhereQuotaNotEqualZero(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE group_capacity SET usage = usage + 1, gmt_modified = ? WHERE group_id = ? AND usage < quota AND quota != 0");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, groupId});
|
||||
assertEquals("UPDATE group_capacity SET usage = usage + 1, gmt_modified = ? WHERE group_id = ? AND usage < quota AND quota != 0",
|
||||
mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {modified, groupId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementUsageByWhere() {
|
||||
void testIncrementUsageByWhere() {
|
||||
MapperResult mapperResult = groupCapacityMapperByDerby.incrementUsageByWhere(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE group_capacity SET usage = usage + 1, gmt_modified = ? WHERE group_id = ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, groupId});
|
||||
assertEquals("UPDATE group_capacity SET usage = usage + 1, gmt_modified = ? WHERE group_id = ?", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {modified, groupId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecrementUsageByWhere() {
|
||||
void testDecrementUsageByWhere() {
|
||||
MapperResult mapperResult = groupCapacityMapperByDerby.decrementUsageByWhere(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE group_capacity SET usage = usage - 1, gmt_modified = ? WHERE group_id = ? AND usage > 0");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, groupId});
|
||||
assertEquals("UPDATE group_capacity SET usage = usage - 1, gmt_modified = ? WHERE group_id = ? AND usage > 0",
|
||||
mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {modified, groupId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateUsage() {
|
||||
void testUpdateUsage() {
|
||||
MapperResult mapperResult = groupCapacityMapperByDerby.updateUsage(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE group_capacity SET usage = (SELECT count(*) FROM config_info), gmt_modified = ? WHERE group_id = ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, groupId});
|
||||
assertEquals("UPDATE group_capacity SET usage = (SELECT count(*) FROM config_info), gmt_modified = ? WHERE group_id = ?",
|
||||
mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {modified, groupId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateUsageByWhere() {
|
||||
void testUpdateUsageByWhere() {
|
||||
MapperResult mapperResult = groupCapacityMapperByDerby.updateUsageByWhere(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"UPDATE group_capacity SET usage = (SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id = ''),"
|
||||
+ " gmt_modified = ? WHERE group_id= ?");
|
||||
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {groupId, modified, groupId});
|
||||
assertArrayEquals(new Object[] {groupId, modified, groupId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectGroupInfoBySize() {
|
||||
void testSelectGroupInfoBySize() {
|
||||
Object id = 1;
|
||||
context.putWhereParameter(FieldConstant.ID, id);
|
||||
MapperResult mapperResult = groupCapacityMapperByDerby.selectGroupInfoBySize(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT id, group_id FROM group_capacity WHERE id > ? OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY");
|
||||
assertEquals("SELECT id, group_id FROM group_capacity WHERE id > ? OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY", mapperResult.getSql());
|
||||
context.putWhereParameter(FieldConstant.GMT_CREATE, createTime);
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {id, pageSize});
|
||||
assertArrayEquals(new Object[] {id, pageSize}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
}
|
||||
|
@ -21,15 +21,15 @@ import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class HistoryConfigInfoMapperByDerbyTest {
|
||||
|
||||
private HistoryConfigInfoMapperByDerby historyConfigInfoMapperByDerby;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class HistoryConfigInfoMapperByDerbyTest {
|
||||
|
||||
int startRow = 0;
|
||||
|
||||
@ -45,8 +45,10 @@ public class HistoryConfigInfoMapperByDerbyTest {
|
||||
|
||||
MapperContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
private HistoryConfigInfoMapperByDerby historyConfigInfoMapperByDerby;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
historyConfigInfoMapperByDerby = new HistoryConfigInfoMapperByDerby();
|
||||
context = new MapperContext(startRow, pageSize);
|
||||
context.putWhereParameter(FieldConstant.START_TIME, startTime);
|
||||
@ -58,33 +60,32 @@ public class HistoryConfigInfoMapperByDerbyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveConfigHistory() {
|
||||
void testRemoveConfigHistory() {
|
||||
MapperResult mapperResult = historyConfigInfoMapperByDerby.removeConfigHistory(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"DELETE FROM his_config_info WHERE id IN( SELECT id FROM his_config_info WHERE gmt_modified < ? "
|
||||
+ "OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY)");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {startTime, limitSize});
|
||||
assertArrayEquals(new Object[] {startTime, limitSize}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigHistoryCountByTime() {
|
||||
void testFindConfigHistoryCountByTime() {
|
||||
MapperResult mapperResult = historyConfigInfoMapperByDerby.findConfigHistoryCountByTime(context);
|
||||
Assert.assertEquals(mapperResult.getSql(), "SELECT count(*) FROM his_config_info WHERE gmt_modified < ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {startTime});
|
||||
assertEquals("SELECT count(*) FROM his_config_info WHERE gmt_modified < ?", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {startTime}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindDeletedConfig() {
|
||||
void testFindDeletedConfig() {
|
||||
MapperResult mapperResult = historyConfigInfoMapperByDerby.findDeletedConfig(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT data_id, group_id, tenant_id,gmt_modified,nid FROM his_config_info WHERE op_type = 'D' "
|
||||
+ "AND gmt_modified >= ? and nid > ? order by nid OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY");
|
||||
assertEquals(mapperResult.getSql(), "SELECT data_id, group_id, tenant_id,gmt_modified,nid FROM his_config_info WHERE op_type = 'D' "
|
||||
+ "AND gmt_modified >= ? and nid > ? order by nid OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY");
|
||||
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {startTime, lastMaxId, pageSize});
|
||||
assertArrayEquals(new Object[] {startTime, lastMaxId, pageSize}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigHistoryFetchRows() {
|
||||
void testFindConfigHistoryFetchRows() {
|
||||
Object dataId = "dataId";
|
||||
Object groupId = "groupId";
|
||||
Object tenantId = "tenantId";
|
||||
@ -94,32 +95,31 @@ public class HistoryConfigInfoMapperByDerbyTest {
|
||||
context.putWhereParameter(FieldConstant.TENANT_ID, tenantId);
|
||||
context.putWhereParameter(FieldConstant.DATA_ID, dataId);
|
||||
MapperResult mapperResult = historyConfigInfoMapperByDerby.findConfigHistoryFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info "
|
||||
+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {dataId, groupId, tenantId});
|
||||
assertArrayEquals(new Object[] {dataId, groupId, tenantId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetailPreviousConfigHistory() {
|
||||
void testDetailPreviousConfigHistory() {
|
||||
Object id = "1";
|
||||
context.putWhereParameter(FieldConstant.ID, id);
|
||||
MapperResult mapperResult = historyConfigInfoMapperByDerby.detailPreviousConfigHistory(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT nid,data_id,group_id,tenant_id,app_name,content,md5,src_user,src_ip,op_type,gmt_create,"
|
||||
+ "gmt_modified,encrypted_data_key FROM his_config_info WHERE nid = (SELECT max(nid) FROM his_config_info WHERE id = ?)");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {id});
|
||||
assertEquals(mapperResult.getSql(), "SELECT nid,data_id,group_id,tenant_id,app_name,content,md5,src_user,src_ip,op_type,gmt_create,"
|
||||
+ "gmt_modified,encrypted_data_key FROM his_config_info WHERE nid = (SELECT max(nid) FROM his_config_info WHERE id = ?)");
|
||||
assertArrayEquals(new Object[] {id}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = historyConfigInfoMapperByDerby.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.HIS_CONFIG_INFO);
|
||||
assertEquals(TableConstant.HIS_CONFIG_INFO, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = historyConfigInfoMapperByDerby.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.DERBY);
|
||||
assertEquals(DataSourceConstant.DERBY, dataSource);
|
||||
}
|
||||
}
|
||||
|
@ -21,28 +21,30 @@ import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class TenantCapacityMapperByDerbyTest {
|
||||
|
||||
private TenantCapacityMapperByDerby tenantCapacityMapperByDerby;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class TenantCapacityMapperByDerbyTest {
|
||||
|
||||
String tenantId = "tenantId";
|
||||
|
||||
MapperContext context;
|
||||
|
||||
private TenantCapacityMapperByDerby tenantCapacityMapperByDerby;
|
||||
|
||||
private Object modified = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
private Object oldModified = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
private Object usage = 1;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
tenantCapacityMapperByDerby = new TenantCapacityMapperByDerby();
|
||||
context = new MapperContext();
|
||||
context.putUpdateParameter(FieldConstant.GMT_MODIFIED, modified);
|
||||
@ -53,75 +55,70 @@ public class TenantCapacityMapperByDerbyTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = tenantCapacityMapperByDerby.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.TENANT_CAPACITY);
|
||||
assertEquals(TableConstant.TENANT_CAPACITY, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = tenantCapacityMapperByDerby.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.DERBY);
|
||||
assertEquals(DataSourceConstant.DERBY, dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementUsageWithDefaultQuotaLimit() {
|
||||
void testIncrementUsageWithDefaultQuotaLimit() {
|
||||
MapperResult mapperResult = tenantCapacityMapperByDerby.incrementUsageWithDefaultQuotaLimit(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE tenant_capacity SET usage = usage + 1, gmt_modified = ? WHERE tenant_id = ? AND usage <"
|
||||
+ " ? AND quota = 0");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, tenantId, usage});
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"UPDATE tenant_capacity SET usage = usage + 1, gmt_modified = ? WHERE tenant_id = ? AND usage <" + " ? AND quota = 0");
|
||||
assertArrayEquals(new Object[] {modified, tenantId, usage}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementUsageWithQuotaLimit() {
|
||||
void testIncrementUsageWithQuotaLimit() {
|
||||
MapperResult mapperResult = tenantCapacityMapperByDerby.incrementUsageWithQuotaLimit(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE tenant_capacity SET usage = usage + 1, gmt_modified = ? WHERE tenant_id = ? AND usage < "
|
||||
+ "quota AND quota != 0");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, tenantId});
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"UPDATE tenant_capacity SET usage = usage + 1, gmt_modified = ? WHERE tenant_id = ? AND usage < " + "quota AND quota != 0");
|
||||
assertArrayEquals(new Object[] {modified, tenantId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementUsage() {
|
||||
void testIncrementUsage() {
|
||||
MapperResult mapperResult = tenantCapacityMapperByDerby.incrementUsage(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE tenant_capacity SET usage = usage + 1, gmt_modified = ? WHERE tenant_id = ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, tenantId});
|
||||
assertEquals("UPDATE tenant_capacity SET usage = usage + 1, gmt_modified = ? WHERE tenant_id = ?", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {modified, tenantId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecrementUsage() {
|
||||
void testDecrementUsage() {
|
||||
MapperResult mapperResult = tenantCapacityMapperByDerby.decrementUsage(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE tenant_capacity SET usage = usage - 1, gmt_modified = ? WHERE tenant_id = ? AND usage > 0");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, tenantId});
|
||||
assertEquals("UPDATE tenant_capacity SET usage = usage - 1, gmt_modified = ? WHERE tenant_id = ? AND usage > 0",
|
||||
mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {modified, tenantId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCorrectUsage() {
|
||||
void testCorrectUsage() {
|
||||
MapperResult mapperResult = tenantCapacityMapperByDerby.correctUsage(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE tenant_capacity SET usage = (SELECT count(*) FROM config_info WHERE tenant_id = ?), "
|
||||
+ "gmt_modified = ? WHERE tenant_id = ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, modified, tenantId});
|
||||
assertEquals(mapperResult.getSql(), "UPDATE tenant_capacity SET usage = (SELECT count(*) FROM config_info WHERE tenant_id = ?), "
|
||||
+ "gmt_modified = ? WHERE tenant_id = ?");
|
||||
assertArrayEquals(new Object[] {tenantId, modified, tenantId}, mapperResult.getParamList().toArray());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCapacityList4CorrectUsage() {
|
||||
void testGetCapacityList4CorrectUsage() {
|
||||
Object id = 1;
|
||||
Object limit = 10;
|
||||
context.putWhereParameter(FieldConstant.ID, id);
|
||||
context.putWhereParameter(FieldConstant.LIMIT_SIZE, limit);
|
||||
MapperResult mapperResult = tenantCapacityMapperByDerby.getCapacityList4CorrectUsage(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT id, tenant_id FROM tenant_capacity WHERE id>? OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {id, limit});
|
||||
assertEquals("SELECT id, tenant_id FROM tenant_capacity WHERE id>? OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {id, limit}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertTenantCapacity() {
|
||||
void testInsertTenantCapacity() {
|
||||
Object group = "group";
|
||||
Object quota = "quota";
|
||||
Object maxAggrSize = 10;
|
||||
@ -142,10 +139,10 @@ public class TenantCapacityMapperByDerbyTest {
|
||||
context.putWhereParameter(FieldConstant.TENANT_ID, tenantId);
|
||||
|
||||
MapperResult mapperResult = tenantCapacityMapperByDerby.insertTenantCapacity(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"INSERT INTO tenant_capacity (tenant_id, quota, usage, max_size, max_aggr_count, max_aggr_size, "
|
||||
+ "gmt_create, gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info WHERE tenant_id=?;");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(),
|
||||
new Object[] {tenantId, quota, maxSize, maxAggrCount, maxAggrSize, createTime, modified, tenantId});
|
||||
assertArrayEquals(new Object[] {tenantId, quota, maxSize, maxAggrCount, maxAggrSize, createTime, modified, tenantId},
|
||||
mapperResult.getParamList().toArray());
|
||||
}
|
||||
}
|
||||
|
@ -18,28 +18,29 @@ package com.alibaba.nacos.plugin.datasource.impl.derby;
|
||||
|
||||
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TenantInfoMapperByDerbyTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class TenantInfoMapperByDerbyTest {
|
||||
|
||||
private TenantInfoMapperByDerby tenantInfoMapperByDerby;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
tenantInfoMapperByDerby = new TenantInfoMapperByDerby();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = tenantInfoMapperByDerby.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.TENANT_INFO);
|
||||
assertEquals(TableConstant.TENANT_INFO, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = tenantInfoMapperByDerby.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.DERBY);
|
||||
assertEquals(DataSourceConstant.DERBY, dataSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,27 +22,25 @@ import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class ConfigInfoAggrMapperByMySqlTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ConfigInfoAggrMapperByMySqlTest {
|
||||
|
||||
private ConfigInfoAggrMapperByMySql configInfoAggrMapperByMySql;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
configInfoAggrMapperByMySql = new ConfigInfoAggrMapperByMySql();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchRemoveAggr() {
|
||||
void testBatchRemoveAggr() {
|
||||
List<String> datumList = Arrays.asList("1", "2", "3", "4", "5");
|
||||
String dataId = "data-id";
|
||||
String groupId = "group-id";
|
||||
@ -61,14 +59,14 @@ public class ConfigInfoAggrMapperByMySqlTest {
|
||||
String sql = mapperResult.getSql();
|
||||
List<Object> paramList = mapperResult.getParamList();
|
||||
|
||||
Assert.assertEquals(sql, "DELETE FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? "
|
||||
+ "AND datum_id IN (?, ?, ?, ?, ?)");
|
||||
assertEquals(sql,
|
||||
"DELETE FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? " + "AND datum_id IN (?, ?, ?, ?, ?)");
|
||||
|
||||
Assert.assertEquals(paramList, argList);
|
||||
assertEquals(paramList, argList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAggrConfigInfoCount() {
|
||||
void testAggrConfigInfoCount() {
|
||||
List<String> datumIds = Arrays.asList("1", "2", "3", "4", "5");
|
||||
String dataId = "data-id";
|
||||
String groupId = "group-id";
|
||||
@ -87,14 +85,13 @@ public class ConfigInfoAggrMapperByMySqlTest {
|
||||
String sql = mapperResult.getSql();
|
||||
List<Object> paramList = mapperResult.getParamList();
|
||||
|
||||
Assert.assertEquals(sql,
|
||||
"SELECT count(*) FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? "
|
||||
+ "AND datum_id IN (?, ?, ?, ?, ?)");
|
||||
Assert.assertEquals(paramList, argList);
|
||||
assertEquals(sql, "SELECT count(*) FROM config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? "
|
||||
+ "AND datum_id IN (?, ?, ?, ?, ?)");
|
||||
assertEquals(paramList, argList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoAggrIsOrdered() {
|
||||
void testFindConfigInfoAggrIsOrdered() {
|
||||
String dataId = "data-id";
|
||||
String groupId = "group-id";
|
||||
String tenantId = "tenant-id";
|
||||
@ -108,13 +105,13 @@ public class ConfigInfoAggrMapperByMySqlTest {
|
||||
String sql = mapperResult.getSql();
|
||||
List<Object> paramList = mapperResult.getParamList();
|
||||
|
||||
Assert.assertEquals(sql, "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM "
|
||||
assertEquals(sql, "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM "
|
||||
+ "config_info_aggr WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY datum_id");
|
||||
Assert.assertEquals(paramList, Arrays.asList(dataId, groupId, tenantId));
|
||||
assertEquals(paramList, Arrays.asList(dataId, groupId, tenantId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoAggrByPageFetchRows() {
|
||||
void testFindConfigInfoAggrByPageFetchRows() {
|
||||
String dataId = "data-id";
|
||||
String groupId = "group-id";
|
||||
String tenantId = "tenant-id";
|
||||
@ -132,28 +129,26 @@ public class ConfigInfoAggrMapperByMySqlTest {
|
||||
String sql = mapperResult.getSql();
|
||||
List<Object> paramList = mapperResult.getParamList();
|
||||
|
||||
Assert.assertEquals(sql,
|
||||
"SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE "
|
||||
+ "data_id= ? AND group_id= ? AND tenant_id= ? ORDER BY datum_id LIMIT 0,5");
|
||||
Assert.assertEquals(paramList, Arrays.asList(dataId, groupId, tenantId));
|
||||
assertEquals(sql, "SELECT data_id,group_id,tenant_id,datum_id,app_name,content FROM config_info_aggr WHERE "
|
||||
+ "data_id= ? AND group_id= ? AND tenant_id= ? ORDER BY datum_id LIMIT 0,5");
|
||||
assertEquals(paramList, Arrays.asList(dataId, groupId, tenantId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllAggrGroupByDistinct() {
|
||||
void testFindAllAggrGroupByDistinct() {
|
||||
MapperResult mapperResult = configInfoAggrMapperByMySql.findAllAggrGroupByDistinct(null);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT DISTINCT data_id, group_id, tenant_id FROM config_info_aggr");
|
||||
assertEquals("SELECT DISTINCT data_id, group_id, tenant_id FROM config_info_aggr", mapperResult.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = configInfoAggrMapperByMySql.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.CONFIG_INFO_AGGR);
|
||||
assertEquals(TableConstant.CONFIG_INFO_AGGR, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = configInfoAggrMapperByMySql.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.MYSQL);
|
||||
assertEquals(DataSourceConstant.MYSQL, dataSource);
|
||||
}
|
||||
}
|
||||
|
@ -22,17 +22,17 @@ import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigInfoBetaMapperByMySqlTest {
|
||||
|
||||
private ConfigInfoBetaMapperByMySql configInfoBetaMapperByMySql;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ConfigInfoBetaMapperByMySqlTest {
|
||||
|
||||
int startRow = 0;
|
||||
|
||||
@ -52,8 +52,10 @@ public class ConfigInfoBetaMapperByMySqlTest {
|
||||
|
||||
MapperContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
private ConfigInfoBetaMapperByMySql configInfoBetaMapperByMySql;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
configInfoBetaMapperByMySql = new ConfigInfoBetaMapperByMySql();
|
||||
|
||||
context = new MapperContext(startRow, pageSize);
|
||||
@ -67,7 +69,7 @@ public class ConfigInfoBetaMapperByMySqlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateConfigInfo4BetaCas() {
|
||||
void testUpdateConfigInfo4BetaCas() {
|
||||
String newContent = "new Content";
|
||||
String newMD5 = "newMD5";
|
||||
String srcIp = "1.1.1.1";
|
||||
@ -107,35 +109,33 @@ public class ConfigInfoBetaMapperByMySqlTest {
|
||||
|
||||
String sql = mapperResult.getSql();
|
||||
List<Object> paramList = mapperResult.getParamList();
|
||||
Assert.assertEquals(sql,
|
||||
assertEquals(sql,
|
||||
"UPDATE config_info_beta SET content = ?,md5 = ?,beta_ips = ?,src_ip = ?,src_user = ?,gmt_modified = ?,app_name = ? "
|
||||
+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND (md5 = ? OR md5 is null OR md5 = '')");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(),
|
||||
new Object[] {newContent, newMD5, betaIps, srcIp, srcUser, time, appNameTmp, dataId, group, tenantId,
|
||||
md5});
|
||||
assertArrayEquals(new Object[] {newContent, newMD5, betaIps, srcIp, srcUser, time, appNameTmp, dataId, group, tenantId, md5},
|
||||
mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllConfigInfoBetaForDumpAllFetchRows() {
|
||||
void testFindAllConfigInfoBetaForDumpAllFetchRows() {
|
||||
MapperResult result = configInfoBetaMapperByMySql.findAllConfigInfoBetaForDumpAllFetchRows(context);
|
||||
String sql = result.getSql();
|
||||
List<Object> paramList = result.getParamList();
|
||||
Assert.assertEquals(sql,
|
||||
" SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,beta_ips,encrypted_data_key "
|
||||
+ " FROM ( SELECT id FROM config_info_beta ORDER BY id LIMIT " + startRow + "," + pageSize
|
||||
+ " )" + " g, config_info_beta t WHERE g.id = t.id ");
|
||||
Assert.assertEquals(paramList, Arrays.asList(startRow, pageSize));
|
||||
assertEquals(sql, " SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,beta_ips,encrypted_data_key "
|
||||
+ " FROM ( SELECT id FROM config_info_beta ORDER BY id LIMIT " + startRow + "," + pageSize + " )"
|
||||
+ " g, config_info_beta t WHERE g.id = t.id ");
|
||||
assertEquals(paramList, Arrays.asList(startRow, pageSize));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = configInfoBetaMapperByMySql.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.CONFIG_INFO_BETA);
|
||||
assertEquals(TableConstant.CONFIG_INFO_BETA, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = configInfoBetaMapperByMySql.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.MYSQL);
|
||||
assertEquals(DataSourceConstant.MYSQL, dataSource);
|
||||
}
|
||||
}
|
||||
|
@ -24,16 +24,16 @@ import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigInfoMapperByMySqlTest {
|
||||
|
||||
private ConfigInfoMapperByMySql configInfoMapperByMySql;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ConfigInfoMapperByMySqlTest {
|
||||
|
||||
private final Object[] emptyObjs = new Object[] {};
|
||||
|
||||
@ -59,8 +59,10 @@ public class ConfigInfoMapperByMySqlTest {
|
||||
|
||||
MapperContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
private ConfigInfoMapperByMySql configInfoMapperByMySql;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
configInfoMapperByMySql = new ConfigInfoMapperByMySql();
|
||||
|
||||
context = new MapperContext(startRow, pageSize);
|
||||
@ -76,253 +78,239 @@ public class ConfigInfoMapperByMySqlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigMaxId() {
|
||||
void testFindConfigMaxId() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findConfigMaxId(null);
|
||||
Assert.assertEquals(mapperResult.getSql(), "SELECT MAX(id) FROM config_info");
|
||||
assertEquals("SELECT MAX(id) FROM config_info", mapperResult.getSql());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllDataIdAndGroup() {
|
||||
void testFindAllDataIdAndGroup() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findAllDataIdAndGroup(null);
|
||||
Assert.assertEquals(mapperResult.getSql(), "SELECT DISTINCT data_id, group_id FROM config_info");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertEquals("SELECT DISTINCT data_id, group_id FROM config_info", mapperResult.getSql());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoByAppCountRows() {
|
||||
void testFindConfigInfoByAppCountRows() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findConfigInfoByAppCountRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT count(*) FROM config_info WHERE tenant_id LIKE ? AND app_name = ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, appName});
|
||||
assertEquals("SELECT count(*) FROM config_info WHERE tenant_id LIKE ? AND app_name = ?", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {tenantId, appName}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoByAppFetchRows() {
|
||||
void testFindConfigInfoByAppFetchRows() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findConfigInfoByAppFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,content FROM config_info WHERE tenant_id LIKE ? AND app_name= ? LIMIT "
|
||||
+ startRow + "," + pageSize);
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, appName});
|
||||
assertArrayEquals(new Object[] {tenantId, appName}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigInfoLikeTenantCount() {
|
||||
void testConfigInfoLikeTenantCount() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.configInfoLikeTenantCount(context);
|
||||
Assert.assertEquals(mapperResult.getSql(), "SELECT count(*) FROM config_info WHERE tenant_id LIKE ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId});
|
||||
assertEquals("SELECT count(*) FROM config_info WHERE tenant_id LIKE ?", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {tenantId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTenantIdList() {
|
||||
void testGetTenantIdList() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.getTenantIdList(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT tenant_id FROM config_info WHERE tenant_id != '" + NamespaceUtil.getNamespaceDefaultId()
|
||||
+ "' GROUP BY tenant_id LIMIT " + startRow + "," + pageSize);
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertEquals(mapperResult.getSql(), "SELECT tenant_id FROM config_info WHERE tenant_id != '" + NamespaceUtil.getNamespaceDefaultId()
|
||||
+ "' GROUP BY tenant_id LIMIT " + startRow + "," + pageSize);
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGroupIdList() {
|
||||
void testGetGroupIdList() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.getGroupIdList(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT group_id FROM config_info WHERE tenant_id ='' GROUP BY group_id LIMIT " + startRow + ","
|
||||
+ pageSize);
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT group_id FROM config_info WHERE tenant_id ='' GROUP BY group_id LIMIT " + startRow + "," + pageSize);
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllConfigKey() {
|
||||
void testFindAllConfigKey() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findAllConfigKey(context);
|
||||
Assert.assertEquals(mapperResult.getSql(), " SELECT data_id,group_id,app_name FROM ( "
|
||||
+ " SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id LIMIT " + context.getStartRow() + ","
|
||||
+ context.getPageSize() + " )" + " g, config_info t WHERE g.id = t.id ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId});
|
||||
assertEquals(mapperResult.getSql(),
|
||||
" SELECT data_id,group_id,app_name FROM ( " + " SELECT id FROM config_info WHERE tenant_id LIKE ? ORDER BY id LIMIT "
|
||||
+ context.getStartRow() + "," + context.getPageSize() + " )" + " g, config_info t WHERE g.id = t.id ");
|
||||
assertArrayEquals(new Object[] {tenantId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllConfigInfoBaseFetchRows() {
|
||||
void testFindAllConfigInfoBaseFetchRows() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findAllConfigInfoBaseFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT t.id,data_id,group_id,content,md5 FROM ( SELECT id FROM config_info ORDER BY id LIMIT " + context.getStartRow() + ","
|
||||
+ context.getPageSize() + " ) g, config_info t WHERE g.id = t.id ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT t.id,data_id,group_id,content,md5 FROM ( SELECT id FROM config_info ORDER BY id LIMIT " + context.getStartRow()
|
||||
+ "," + context.getPageSize() + " ) g, config_info t WHERE g.id = t.id ");
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllConfigInfoFragment() {
|
||||
void testFindAllConfigInfoFragment() {
|
||||
//with content
|
||||
context.putContextParameter(ContextConstant.NEED_CONTENT, "true");
|
||||
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findAllConfigInfoFragment(context);
|
||||
Assert.assertEquals(
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,type,encrypted_data_key "
|
||||
+ "FROM config_info WHERE id > ? ORDER BY id ASC LIMIT " + startRow + "," + pageSize,
|
||||
mapperResult.getSql());
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {id});
|
||||
assertEquals("SELECT id,data_id,group_id,tenant_id,app_name,content,md5,gmt_modified,type,encrypted_data_key "
|
||||
+ "FROM config_info WHERE id > ? ORDER BY id ASC LIMIT " + startRow + "," + pageSize, mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {id}, mapperResult.getParamList().toArray());
|
||||
|
||||
context.putContextParameter(ContextConstant.NEED_CONTENT, "false");
|
||||
MapperResult mapperResult2 = configInfoMapperByMySql.findAllConfigInfoFragment(context);
|
||||
Assert.assertEquals("SELECT id,data_id,group_id,tenant_id,app_name,md5,gmt_modified,type,encrypted_data_key "
|
||||
+ "FROM config_info WHERE id > ? ORDER BY id ASC LIMIT " + startRow + "," + pageSize,
|
||||
mapperResult2.getSql());
|
||||
Assert.assertArrayEquals(mapperResult2.getParamList().toArray(), new Object[] {id});
|
||||
assertEquals("SELECT id,data_id,group_id,tenant_id,app_name,md5,gmt_modified,type,encrypted_data_key "
|
||||
+ "FROM config_info WHERE id > ? ORDER BY id ASC LIMIT " + startRow + "," + pageSize, mapperResult2.getSql());
|
||||
assertArrayEquals(new Object[] {id}, mapperResult2.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindChangeConfig() {
|
||||
void testFindChangeConfig() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findChangeConfig(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT id, data_id, group_id, tenant_id, app_name,md5, gmt_modified, encrypted_data_key FROM config_info"
|
||||
+ " WHERE gmt_modified >= ? and id > ? order by id limit ? ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {startTime, lastMaxId, pageSize});
|
||||
assertArrayEquals(new Object[] {startTime, lastMaxId, pageSize}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindChangeConfigCountRows() {
|
||||
void testFindChangeConfigCountRows() {
|
||||
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findChangeConfigCountRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT count(*) FROM config_info WHERE 1=1 AND app_name = ? AND gmt_modified >=? AND gmt_modified <=? ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {appName, startTime, endTime});
|
||||
assertEquals("SELECT count(*) FROM config_info WHERE 1=1 AND app_name = ? AND gmt_modified >=? AND gmt_modified <=? ",
|
||||
mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {appName, startTime, endTime}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindChangeConfigFetchRows() {
|
||||
void testFindChangeConfigFetchRows() {
|
||||
Object lastMaxId = 100;
|
||||
context.putWhereParameter(FieldConstant.LAST_MAX_ID, lastMaxId);
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findChangeConfigFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,type,md5,gmt_modified FROM config_info "
|
||||
+ "WHERE 1=1 AND tenant_id = ? AND app_name = ? AND gmt_modified >=? AND gmt_modified <=? AND id > "
|
||||
+ lastMaxId + " ORDER BY id ASC LIMIT " + startRow + "," + pageSize);
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(),
|
||||
new Object[] {tenantId, appName, startTime, endTime});
|
||||
assertEquals(mapperResult.getSql(), "SELECT id,data_id,group_id,tenant_id,app_name,type,md5,gmt_modified FROM config_info "
|
||||
+ "WHERE 1=1 AND tenant_id = ? AND app_name = ? AND gmt_modified >=? AND gmt_modified <=? AND id > " + lastMaxId
|
||||
+ " ORDER BY id ASC LIMIT " + startRow + "," + pageSize);
|
||||
assertArrayEquals(new Object[] {tenantId, appName, startTime, endTime}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListGroupKeyMd5ByPageFetchRows() {
|
||||
void testListGroupKeyMd5ByPageFetchRows() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.listGroupKeyMd5ByPageFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT t.id,data_id,group_id,tenant_id,app_name,md5,type,gmt_modified,encrypted_data_key FROM "
|
||||
+ "( SELECT id FROM config_info ORDER BY id LIMIT 0,5 ) g, config_info t WHERE g.id = t.id");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertEquals(mapperResult.getSql(), "SELECT t.id,data_id,group_id,tenant_id,app_name,md5,type,gmt_modified,encrypted_data_key FROM "
|
||||
+ "( SELECT id FROM config_info ORDER BY id LIMIT 0,5 ) g, config_info t WHERE g.id = t.id");
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllConfigInfo4Export() {
|
||||
void testFindAllConfigInfo4Export() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findAllConfigInfo4Export(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_create,gmt_modified,src_user,"
|
||||
+ "src_ip,c_desc,c_use,effect,c_schema,encrypted_data_key FROM config_info WHERE id IN (?, ?, ?, ?, ?) ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), ids.toArray());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), ids.toArray());
|
||||
|
||||
context.putWhereParameter(FieldConstant.IDS, null);
|
||||
mapperResult = configInfoMapperByMySql.findAllConfigInfo4Export(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,content,type,md5,gmt_create,gmt_modified,src_user,"
|
||||
+ "src_ip,c_desc,c_use,effect,c_schema,encrypted_data_key FROM config_info WHERE tenant_id = ? AND app_name= ? ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, appName});
|
||||
assertArrayEquals(new Object[] {tenantId, appName}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoBaseLikeCountRows() {
|
||||
void testFindConfigInfoBaseLikeCountRows() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findConfigInfoBaseLikeCountRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(), "SELECT count(*) FROM config_info WHERE 1=1 AND tenant_id='' ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertEquals("SELECT count(*) FROM config_info WHERE 1=1 AND tenant_id='' ", mapperResult.getSql());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoBaseLikeFetchRows() {
|
||||
void testFindConfigInfoBaseLikeFetchRows() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findConfigInfoBaseLikeFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE 1=1 AND tenant_id='' LIMIT "
|
||||
+ startRow + "," + pageSize);
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,content FROM config_info WHERE 1=1 AND tenant_id='' LIMIT " + startRow + ","
|
||||
+ pageSize);
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfo4PageCountRows() {
|
||||
void testFindConfigInfo4PageCountRows() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findConfigInfo4PageCountRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT count(*) FROM config_info WHERE tenant_id=? AND app_name=? ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, appName});
|
||||
assertEquals("SELECT count(*) FROM config_info WHERE tenant_id=? AND app_name=? ", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {tenantId, appName}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfo4PageFetchRows() {
|
||||
void testFindConfigInfo4PageFetchRows() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findConfigInfo4PageFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,content,type,encrypted_data_key FROM config_info"
|
||||
+ " WHERE tenant_id=? AND app_name=? LIMIT " + startRow + "," + pageSize);
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, appName});
|
||||
assertEquals(mapperResult.getSql(), "SELECT id,data_id,group_id,tenant_id,app_name,content,type,encrypted_data_key FROM config_info"
|
||||
+ " WHERE tenant_id=? AND app_name=? LIMIT " + startRow + "," + pageSize);
|
||||
assertArrayEquals(new Object[] {tenantId, appName}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoBaseByGroupFetchRows() {
|
||||
void testFindConfigInfoBaseByGroupFetchRows() {
|
||||
context.putWhereParameter(FieldConstant.GROUP_ID, groupId);
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findConfigInfoBaseByGroupFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=? LIMIT " + startRow
|
||||
+ "," + pageSize);
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {groupId, tenantId});
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,content FROM config_info WHERE group_id=? AND tenant_id=? LIMIT " + startRow + "," + pageSize);
|
||||
assertArrayEquals(new Object[] {groupId, tenantId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoLike4PageCountRows() {
|
||||
void testFindConfigInfoLike4PageCountRows() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findConfigInfoLike4PageCountRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT count(*) FROM config_info WHERE tenant_id LIKE ? AND app_name = ? ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, appName});
|
||||
assertEquals("SELECT count(*) FROM config_info WHERE tenant_id LIKE ? AND app_name = ? ", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {tenantId, appName}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoLike4PageFetchRows() {
|
||||
void testFindConfigInfoLike4PageFetchRows() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findConfigInfoLike4PageFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key FROM config_info "
|
||||
+ "WHERE tenant_id LIKE ? AND app_name = ? LIMIT " + startRow + "," + pageSize);
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, appName});
|
||||
assertEquals(mapperResult.getSql(), "SELECT id,data_id,group_id,tenant_id,app_name,content,encrypted_data_key FROM config_info "
|
||||
+ "WHERE tenant_id LIKE ? AND app_name = ? LIMIT " + startRow + "," + pageSize);
|
||||
assertArrayEquals(new Object[] {tenantId, appName}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllConfigInfoFetchRows() {
|
||||
void testFindAllConfigInfoFetchRows() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findAllConfigInfoFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT t.id,data_id,group_id,tenant_id,app_name,content,md5 FROM ( SELECT id FROM config_info "
|
||||
+ "WHERE tenant_id LIKE ? ORDER BY id LIMIT ?,? ) g, config_info t WHERE g.id = t.id ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, startRow, pageSize});
|
||||
assertArrayEquals(new Object[] {tenantId, startRow, pageSize}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfosByIds() {
|
||||
void testFindConfigInfosByIds() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.findConfigInfosByIds(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT id,data_id,group_id,tenant_id,app_name,content,md5 FROM config_info WHERE id IN (?, ?, ?, ?, ?) ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), ids.toArray());
|
||||
assertEquals("SELECT id,data_id,group_id,tenant_id,app_name,content,md5 FROM config_info WHERE id IN (?, ?, ?, ?, ?) ",
|
||||
mapperResult.getSql());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), ids.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveConfigInfoByIdsAtomic() {
|
||||
void testRemoveConfigInfoByIdsAtomic() {
|
||||
MapperResult mapperResult = configInfoMapperByMySql.removeConfigInfoByIdsAtomic(context);
|
||||
Assert.assertEquals(mapperResult.getSql(), "DELETE FROM config_info WHERE id IN (?, ?, ?, ?, ?) ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), ids.toArray());
|
||||
assertEquals("DELETE FROM config_info WHERE id IN (?, ?, ?, ?, ?) ", mapperResult.getSql());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), ids.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String sql = configInfoMapperByMySql.getTableName();
|
||||
Assert.assertEquals(sql, TableConstant.CONFIG_INFO);
|
||||
assertEquals(TableConstant.CONFIG_INFO, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String sql = configInfoMapperByMySql.getDataSource();
|
||||
Assert.assertEquals(sql, DataSourceConstant.MYSQL);
|
||||
assertEquals(DataSourceConstant.MYSQL, sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateConfigInfoAtomicCas() {
|
||||
void testUpdateConfigInfoAtomicCas() {
|
||||
String newContent = "new Content";
|
||||
String newMD5 = "newMD5";
|
||||
String srcIp = "1.1.1.1";
|
||||
@ -357,12 +345,12 @@ public class ConfigInfoMapperByMySqlTest {
|
||||
context.putWhereParameter(FieldConstant.MD5, md5);
|
||||
|
||||
MapperResult mapperResult = configInfoMapperByMySql.updateConfigInfoAtomicCas(context);
|
||||
Assert.assertEquals(mapperResult.getSql(), "UPDATE config_info SET "
|
||||
+ "content=?, md5 = ?, src_ip=?,src_user=?,gmt_modified=?, app_name=?,c_desc=?,"
|
||||
+ "c_use=?,effect=?,type=?,c_schema=?,encrypted_data_key=? "
|
||||
+ "WHERE data_id=? AND group_id=? AND tenant_id=? AND (md5=? OR md5 IS NULL OR md5='')");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(),
|
||||
new Object[] {newContent, newMD5, srcIp, srcUser, time, appNameTmp, desc, use, effect, type, schema,
|
||||
encryptedDataKey, dataId, group, tenantId, md5});
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"UPDATE config_info SET " + "content=?, md5 = ?, src_ip=?,src_user=?,gmt_modified=?, app_name=?,c_desc=?,"
|
||||
+ "c_use=?,effect=?,type=?,c_schema=?,encrypted_data_key=? "
|
||||
+ "WHERE data_id=? AND group_id=? AND tenant_id=? AND (md5=? OR md5 IS NULL OR md5='')");
|
||||
assertArrayEquals(
|
||||
new Object[] {newContent, newMD5, srcIp, srcUser, time, appNameTmp, desc, use, effect, type, schema, encryptedDataKey,
|
||||
dataId, group, tenantId, md5}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
}
|
||||
|
@ -22,16 +22,16 @@ import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigInfoTagMapperByMySqlTest {
|
||||
|
||||
private ConfigInfoTagMapperByMySql configInfoTagMapperByMySql;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ConfigInfoTagMapperByMySqlTest {
|
||||
|
||||
private final Object[] emptyObjs = new Object[] {};
|
||||
|
||||
@ -53,8 +53,10 @@ public class ConfigInfoTagMapperByMySqlTest {
|
||||
|
||||
MapperContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
private ConfigInfoTagMapperByMySql configInfoTagMapperByMySql;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
configInfoTagMapperByMySql = new ConfigInfoTagMapperByMySql();
|
||||
|
||||
context = new MapperContext(startRow, pageSize);
|
||||
@ -68,7 +70,7 @@ public class ConfigInfoTagMapperByMySqlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateConfigInfo4TagCas() {
|
||||
void testUpdateConfigInfo4TagCas() {
|
||||
String newContent = "new Content";
|
||||
String newMD5 = "newMD5";
|
||||
String srcIp = "1.1.1.1";
|
||||
@ -106,34 +108,31 @@ public class ConfigInfoTagMapperByMySqlTest {
|
||||
|
||||
MapperResult mapperResult = configInfoTagMapperByMySql.updateConfigInfo4TagCas(context);
|
||||
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE config_info_tag SET content = ?, md5 = ?, src_ip = ?,src_user = ?,gmt_modified = ?,"
|
||||
+ "app_name = ? WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND tag_id = ? AND "
|
||||
+ "(md5 = ? OR md5 IS NULL OR md5 = '')");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(),
|
||||
new Object[] {newContent, newMD5, srcIp, srcUser, time, appNameTmp, dataId, group, tenantId, tagId,
|
||||
md5});
|
||||
assertEquals(mapperResult.getSql(), "UPDATE config_info_tag SET content = ?, md5 = ?, src_ip = ?,src_user = ?,gmt_modified = ?,"
|
||||
+ "app_name = ? WHERE data_id = ? AND group_id = ? AND tenant_id = ? AND tag_id = ? AND "
|
||||
+ "(md5 = ? OR md5 IS NULL OR md5 = '')");
|
||||
assertArrayEquals(new Object[] {newContent, newMD5, srcIp, srcUser, time, appNameTmp, dataId, group, tenantId, tagId, md5},
|
||||
mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllConfigInfoTagForDumpAllFetchRows() {
|
||||
void testFindAllConfigInfoTagForDumpAllFetchRows() {
|
||||
MapperResult mapperResult = configInfoTagMapperByMySql.findAllConfigInfoTagForDumpAllFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
" SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified FROM ( "
|
||||
+ "SELECT id FROM config_info_tag ORDER BY id LIMIT " + startRow + "," + pageSize
|
||||
+ " ) g, config_info_tag t WHERE g.id = t.id ");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
assertEquals(mapperResult.getSql(), " SELECT t.id,data_id,group_id,tenant_id,tag_id,app_name,content,md5,gmt_modified FROM ( "
|
||||
+ "SELECT id FROM config_info_tag ORDER BY id LIMIT " + startRow + "," + pageSize
|
||||
+ " ) g, config_info_tag t WHERE g.id = t.id ");
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), emptyObjs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = configInfoTagMapperByMySql.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.CONFIG_INFO_TAG);
|
||||
assertEquals(TableConstant.CONFIG_INFO_TAG, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = configInfoTagMapperByMySql.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.MYSQL);
|
||||
assertEquals(DataSourceConstant.MYSQL, dataSource);
|
||||
}
|
||||
}
|
||||
|
@ -22,16 +22,16 @@ import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigTagsRelationMapperByMySqlTest {
|
||||
|
||||
private ConfigTagsRelationMapperByMySql configTagsRelationMapperByMySql;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class ConfigTagsRelationMapperByMySqlTest {
|
||||
|
||||
int startRow = 0;
|
||||
|
||||
@ -43,8 +43,10 @@ public class ConfigTagsRelationMapperByMySqlTest {
|
||||
|
||||
MapperContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
private ConfigTagsRelationMapperByMySql configTagsRelationMapperByMySql;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
configTagsRelationMapperByMySql = new ConfigTagsRelationMapperByMySql();
|
||||
context = new MapperContext(startRow, pageSize);
|
||||
context.putWhereParameter(FieldConstant.TENANT_ID, tenantId);
|
||||
@ -52,58 +54,54 @@ public class ConfigTagsRelationMapperByMySqlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoLike4PageCountRows() {
|
||||
void testFindConfigInfoLike4PageCountRows() {
|
||||
MapperResult mapperResult = configTagsRelationMapperByMySql.findConfigInfoLike4PageCountRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id WHERE "
|
||||
+ "a.tenant_id LIKE ? AND b.tag_name IN (?, ?, ?, ?, ?) ");
|
||||
assertEquals(mapperResult.getSql(), "SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id WHERE "
|
||||
+ "a.tenant_id LIKE ? AND b.tag_name IN (?, ?, ?, ?, ?) ");
|
||||
List<Object> list = CollectionUtils.list(tenantId);
|
||||
list.addAll(Arrays.asList(tagArr));
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfo4PageCountRows() {
|
||||
void testFindConfigInfo4PageCountRows() {
|
||||
MapperResult mapperResult = configTagsRelationMapperByMySql.findConfigInfo4PageCountRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id "
|
||||
+ "WHERE a.tenant_id=? AND b.tag_name IN (?, ?, ?, ?, ?) ");
|
||||
assertEquals(mapperResult.getSql(), "SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id "
|
||||
+ "WHERE a.tenant_id=? AND b.tag_name IN (?, ?, ?, ?, ?) ");
|
||||
List<Object> list = CollectionUtils.list(tenantId);
|
||||
list.addAll(Arrays.asList(tagArr));
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfo4PageFetchRows() {
|
||||
void testFindConfigInfo4PageFetchRows() {
|
||||
context.putWhereParameter(FieldConstant.DATA_ID, "dataID1");
|
||||
context.putWhereParameter(FieldConstant.GROUP_ID, "groupID1");
|
||||
context.putWhereParameter(FieldConstant.APP_NAME, "AppName1");
|
||||
context.putWhereParameter(FieldConstant.CONTENT, "Content1");
|
||||
|
||||
MapperResult mapperResult = configTagsRelationMapperByMySql.findConfigInfo4PageFetchRows(context);
|
||||
Assert.assertEquals(
|
||||
"SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info "
|
||||
+ "a LEFT JOIN config_tags_relation b ON a.id=b.id "
|
||||
+ "WHERE a.tenant_id=? AND a.data_id=? AND a.group_id=? AND a.app_name=? AND a.content LIKE ? "
|
||||
+ " AND b.tag_name IN (?, ?, ?, ?, ?) LIMIT "
|
||||
+ startRow + "," + pageSize, mapperResult.getSql());
|
||||
assertEquals("SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info "
|
||||
+ "a LEFT JOIN config_tags_relation b ON a.id=b.id "
|
||||
+ "WHERE a.tenant_id=? AND a.data_id=? AND a.group_id=? AND a.app_name=? AND a.content LIKE ? "
|
||||
+ " AND b.tag_name IN (?, ?, ?, ?, ?) LIMIT " + startRow + "," + pageSize, mapperResult.getSql());
|
||||
List<Object> list = CollectionUtils.list(tenantId);
|
||||
list.add("dataID1");
|
||||
list.add("groupID1");
|
||||
list.add("AppName1");
|
||||
list.add("Content1");
|
||||
list.addAll(Arrays.asList(tagArr));
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigInfoLike4PageCountRowss() {
|
||||
void testFindConfigInfoLike4PageCountRowss() {
|
||||
context.putWhereParameter(FieldConstant.DATA_ID, "dataID1");
|
||||
context.putWhereParameter(FieldConstant.GROUP_ID, "groupID1");
|
||||
context.putWhereParameter(FieldConstant.APP_NAME, "AppName1");
|
||||
context.putWhereParameter(FieldConstant.CONTENT, "Content1");
|
||||
MapperResult mapperResult = configTagsRelationMapperByMySql.findConfigInfoLike4PageCountRows(context);
|
||||
Assert.assertEquals("SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id "
|
||||
assertEquals("SELECT count(*) FROM config_info a LEFT JOIN config_tags_relation b ON a.id=b.id "
|
||||
+ "WHERE a.tenant_id LIKE ? AND a.data_id LIKE ? AND a.group_id LIKE ? AND a.app_name = ? "
|
||||
+ "AND a.content LIKE ? AND b.tag_name IN (?, ?, ?, ?, ?) ", mapperResult.getSql());
|
||||
List<Object> list = CollectionUtils.list(tenantId);
|
||||
@ -112,39 +110,38 @@ public class ConfigTagsRelationMapperByMySqlTest {
|
||||
list.add("AppName1");
|
||||
list.add("Content1");
|
||||
list.addAll(Arrays.asList(tagArr));
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tsetFindConfigInfoLike4PageFetchRows() {
|
||||
void tsetFindConfigInfoLike4PageFetchRows() {
|
||||
context.putWhereParameter(FieldConstant.DATA_ID, "dataID1");
|
||||
context.putWhereParameter(FieldConstant.GROUP_ID, "groupID1");
|
||||
context.putWhereParameter(FieldConstant.APP_NAME, "AppName1");
|
||||
context.putWhereParameter(FieldConstant.CONTENT, "Content1");
|
||||
MapperResult mapperResult = configTagsRelationMapperByMySql.findConfigInfoLike4PageFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN"
|
||||
+ " config_tags_relation b ON a.id=b.id WHERE a.tenant_id LIKE ? AND a.data_id LIKE ? "
|
||||
+ "AND a.group_id LIKE ? AND a.app_name = ? AND a.content LIKE ? AND b.tag_name IN (?, ?, ?, ?, ?) LIMIT "
|
||||
+ startRow + "," + pageSize);
|
||||
assertEquals(mapperResult.getSql(), "SELECT a.id,a.data_id,a.group_id,a.tenant_id,a.app_name,a.content FROM config_info a LEFT JOIN"
|
||||
+ " config_tags_relation b ON a.id=b.id WHERE a.tenant_id LIKE ? AND a.data_id LIKE ? "
|
||||
+ "AND a.group_id LIKE ? AND a.app_name = ? AND a.content LIKE ? AND b.tag_name IN (?, ?, ?, ?, ?) LIMIT " + startRow
|
||||
+ "," + pageSize);
|
||||
List<Object> list = CollectionUtils.list(tenantId);
|
||||
list.add("dataID1");
|
||||
list.add("groupID1");
|
||||
list.add("AppName1");
|
||||
list.add("Content1");
|
||||
list.addAll(Arrays.asList(tagArr));
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
assertArrayEquals(mapperResult.getParamList().toArray(), list.toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = configTagsRelationMapperByMySql.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.CONFIG_TAGS_RELATION);
|
||||
assertEquals(TableConstant.CONFIG_TAGS_RELATION, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = configTagsRelationMapperByMySql.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.MYSQL);
|
||||
assertEquals(DataSourceConstant.MYSQL, dataSource);
|
||||
}
|
||||
}
|
||||
|
@ -21,15 +21,15 @@ import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class GroupCapacityMapperByMysqlTest {
|
||||
|
||||
private GroupCapacityMapperByMysql groupCapacityMapperByMysql;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class GroupCapacityMapperByMysqlTest {
|
||||
|
||||
private final Object[] emptyObjs = new Object[] {};
|
||||
|
||||
@ -45,8 +45,10 @@ public class GroupCapacityMapperByMysqlTest {
|
||||
|
||||
MapperContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
private GroupCapacityMapperByMysql groupCapacityMapperByMysql;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
groupCapacityMapperByMysql = new GroupCapacityMapperByMysql();
|
||||
context = new MapperContext(startRow, pageSize);
|
||||
context.putUpdateParameter(FieldConstant.GMT_MODIFIED, modified);
|
||||
@ -56,19 +58,19 @@ public class GroupCapacityMapperByMysqlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = groupCapacityMapperByMysql.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.GROUP_CAPACITY);
|
||||
assertEquals(TableConstant.GROUP_CAPACITY, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = groupCapacityMapperByMysql.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.MYSQL);
|
||||
assertEquals(DataSourceConstant.MYSQL, dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertIntoSelect() {
|
||||
void testInsertIntoSelect() {
|
||||
Object group = "group";
|
||||
Object quota = "quota";
|
||||
Object maxAggrSize = 10;
|
||||
@ -80,21 +82,21 @@ public class GroupCapacityMapperByMysqlTest {
|
||||
context.putUpdateParameter(FieldConstant.MAX_SIZE, maxSize);
|
||||
context.putUpdateParameter(FieldConstant.MAX_AGGR_SIZE, maxAggrSize);
|
||||
context.putUpdateParameter(FieldConstant.MAX_AGGR_COUNT, maxAggrCount);
|
||||
|
||||
|
||||
context.putUpdateParameter(FieldConstant.GMT_CREATE, createTime);
|
||||
context.putUpdateParameter(FieldConstant.GMT_MODIFIED, modified);
|
||||
|
||||
MapperResult mapperResult = groupCapacityMapperByMysql.insertIntoSelect(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"INSERT INTO group_capacity (group_id, quota, usage, max_size, max_aggr_count, max_aggr_size,gmt_create,"
|
||||
+ " gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info");
|
||||
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(),
|
||||
new Object[] {group, quota, maxSize, maxAggrCount, maxAggrSize, createTime, modified});
|
||||
assertArrayEquals(new Object[] {group, quota, maxSize, maxAggrCount, maxAggrSize, createTime, modified},
|
||||
mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertIntoSelectByWhere() {
|
||||
void testInsertIntoSelectByWhere() {
|
||||
Object group = "group";
|
||||
Object quota = "quota";
|
||||
Object maxAggrSize = 10;
|
||||
@ -112,72 +114,71 @@ public class GroupCapacityMapperByMysqlTest {
|
||||
context.putUpdateParameter(FieldConstant.GMT_MODIFIED, modified);
|
||||
|
||||
MapperResult mapperResult = groupCapacityMapperByMysql.insertIntoSelectByWhere(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"INSERT INTO group_capacity (group_id, quota, usage, max_size, max_aggr_count, max_aggr_size, gmt_create,"
|
||||
+ " gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info WHERE group_id=? AND tenant_id = ''");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(),
|
||||
new Object[] {group, quota, maxSize, maxAggrCount, maxAggrSize, createTime, modified, group});
|
||||
assertArrayEquals(new Object[] {group, quota, maxSize, maxAggrCount, maxAggrSize, createTime, modified, group},
|
||||
mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementUsageByWhereQuotaEqualZero() {
|
||||
void testIncrementUsageByWhereQuotaEqualZero() {
|
||||
Object usage = 1;
|
||||
context.putWhereParameter(FieldConstant.USAGE, usage);
|
||||
MapperResult mapperResult = groupCapacityMapperByMysql.incrementUsageByWhereQuotaEqualZero(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE group_capacity SET usage = usage + 1, gmt_modified = ? WHERE group_id = ? AND usage < ? AND quota = 0");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, groupId, usage});
|
||||
assertEquals("UPDATE group_capacity SET usage = usage + 1, gmt_modified = ? WHERE group_id = ? AND usage < ? AND quota = 0",
|
||||
mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {modified, groupId, usage}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementUsageByWhereQuotaNotEqualZero() {
|
||||
void testIncrementUsageByWhereQuotaNotEqualZero() {
|
||||
|
||||
MapperResult mapperResult = groupCapacityMapperByMysql.incrementUsageByWhereQuotaNotEqualZero(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE group_capacity SET usage = usage + 1, gmt_modified = ? WHERE group_id = ? AND usage < quota AND quota != 0");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, groupId});
|
||||
assertEquals("UPDATE group_capacity SET usage = usage + 1, gmt_modified = ? WHERE group_id = ? AND usage < quota AND quota != 0",
|
||||
mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {modified, groupId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementUsageByWhere() {
|
||||
void testIncrementUsageByWhere() {
|
||||
MapperResult mapperResult = groupCapacityMapperByMysql.incrementUsageByWhere(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE group_capacity SET usage = usage + 1, gmt_modified = ? WHERE group_id = ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, groupId});
|
||||
assertEquals("UPDATE group_capacity SET usage = usage + 1, gmt_modified = ? WHERE group_id = ?", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {modified, groupId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecrementUsageByWhere() {
|
||||
void testDecrementUsageByWhere() {
|
||||
MapperResult mapperResult = groupCapacityMapperByMysql.decrementUsageByWhere(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE group_capacity SET usage = usage - 1, gmt_modified = ? WHERE group_id = ? AND usage > 0");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, groupId});
|
||||
assertEquals("UPDATE group_capacity SET usage = usage - 1, gmt_modified = ? WHERE group_id = ? AND usage > 0",
|
||||
mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {modified, groupId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateUsage() {
|
||||
void testUpdateUsage() {
|
||||
MapperResult mapperResult = groupCapacityMapperByMysql.updateUsage(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE group_capacity SET usage = (SELECT count(*) FROM config_info), gmt_modified = ? WHERE group_id = ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, groupId});
|
||||
assertEquals("UPDATE group_capacity SET usage = (SELECT count(*) FROM config_info), gmt_modified = ? WHERE group_id = ?",
|
||||
mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {modified, groupId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateUsageByWhere() {
|
||||
void testUpdateUsageByWhere() {
|
||||
MapperResult mapperResult = groupCapacityMapperByMysql.updateUsageByWhere(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"UPDATE group_capacity SET usage = (SELECT count(*) FROM config_info WHERE group_id=? AND tenant_id = ''),"
|
||||
+ " gmt_modified = ? WHERE group_id= ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {groupId, modified, groupId});
|
||||
assertArrayEquals(new Object[] {groupId, modified, groupId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectGroupInfoBySize() {
|
||||
void testSelectGroupInfoBySize() {
|
||||
Object id = 1;
|
||||
context.putWhereParameter(FieldConstant.ID, id);
|
||||
MapperResult mapperResult = groupCapacityMapperByMysql.selectGroupInfoBySize(context);
|
||||
Assert.assertEquals(mapperResult.getSql(), "SELECT id, group_id FROM group_capacity WHERE id > ? LIMIT ?");
|
||||
assertEquals("SELECT id, group_id FROM group_capacity WHERE id > ? LIMIT ?", mapperResult.getSql());
|
||||
context.putWhereParameter(FieldConstant.GMT_CREATE, createTime);
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {id, pageSize});
|
||||
assertArrayEquals(new Object[] {id, pageSize}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
}
|
||||
|
@ -21,15 +21,15 @@ import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class HistoryConfigInfoMapperByMySqlTest {
|
||||
|
||||
private HistoryConfigInfoMapperByMySql historyConfigInfoMapperByMySql;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class HistoryConfigInfoMapperByMySqlTest {
|
||||
|
||||
int startRow = 0;
|
||||
|
||||
@ -45,8 +45,10 @@ public class HistoryConfigInfoMapperByMySqlTest {
|
||||
|
||||
MapperContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
private HistoryConfigInfoMapperByMySql historyConfigInfoMapperByMySql;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
historyConfigInfoMapperByMySql = new HistoryConfigInfoMapperByMySql();
|
||||
context = new MapperContext(startRow, pageSize);
|
||||
context.putWhereParameter(FieldConstant.START_TIME, startTime);
|
||||
@ -57,31 +59,30 @@ public class HistoryConfigInfoMapperByMySqlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveConfigHistory() {
|
||||
void testRemoveConfigHistory() {
|
||||
MapperResult mapperResult = historyConfigInfoMapperByMySql.removeConfigHistory(context);
|
||||
Assert.assertEquals(mapperResult.getSql(), "DELETE FROM his_config_info WHERE gmt_modified < ? LIMIT ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {startTime, limitSize});
|
||||
assertEquals("DELETE FROM his_config_info WHERE gmt_modified < ? LIMIT ?", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {startTime, limitSize}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigHistoryCountByTime() {
|
||||
void testFindConfigHistoryCountByTime() {
|
||||
MapperResult mapperResult = historyConfigInfoMapperByMySql.findConfigHistoryCountByTime(context);
|
||||
Assert.assertEquals(mapperResult.getSql(), "SELECT count(*) FROM his_config_info WHERE gmt_modified < ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {startTime});
|
||||
assertEquals("SELECT count(*) FROM his_config_info WHERE gmt_modified < ?", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {startTime}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindDeletedConfig() {
|
||||
void testFindDeletedConfig() {
|
||||
MapperResult mapperResult = historyConfigInfoMapperByMySql.findDeletedConfig(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT data_id, group_id, tenant_id,gmt_modified,nid FROM his_config_info "
|
||||
+ "WHERE op_type = 'D' AND gmt_modified >= ? and nid > ? order by nid limit ? ");
|
||||
assertEquals(mapperResult.getSql(), "SELECT data_id, group_id, tenant_id,gmt_modified,nid FROM his_config_info "
|
||||
+ "WHERE op_type = 'D' AND gmt_modified >= ? and nid > ? order by nid limit ? ");
|
||||
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {startTime, lastMaxId, pageSize});
|
||||
assertArrayEquals(new Object[] {startTime, lastMaxId, pageSize}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindConfigHistoryFetchRows() {
|
||||
void testFindConfigHistoryFetchRows() {
|
||||
Object dataId = "dataId";
|
||||
Object groupId = "groupId";
|
||||
Object tenantId = "tenantId";
|
||||
@ -91,32 +92,31 @@ public class HistoryConfigInfoMapperByMySqlTest {
|
||||
context.putWhereParameter(FieldConstant.TENANT_ID, tenantId);
|
||||
context.putWhereParameter(FieldConstant.DATA_ID, dataId);
|
||||
MapperResult mapperResult = historyConfigInfoMapperByMySql.findConfigHistoryFetchRows(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info "
|
||||
+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {dataId, groupId, tenantId});
|
||||
assertArrayEquals(new Object[] {dataId, groupId, tenantId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetailPreviousConfigHistory() {
|
||||
void testDetailPreviousConfigHistory() {
|
||||
Object id = "1";
|
||||
context.putWhereParameter(FieldConstant.ID, id);
|
||||
MapperResult mapperResult = historyConfigInfoMapperByMySql.detailPreviousConfigHistory(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"SELECT nid,data_id,group_id,tenant_id,app_name,content,md5,src_user,src_ip,op_type,gmt_create,"
|
||||
+ "gmt_modified,encrypted_data_key FROM his_config_info WHERE nid = (SELECT max(nid) FROM his_config_info WHERE id = ?)");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {id});
|
||||
assertEquals(mapperResult.getSql(), "SELECT nid,data_id,group_id,tenant_id,app_name,content,md5,src_user,src_ip,op_type,gmt_create,"
|
||||
+ "gmt_modified,encrypted_data_key FROM his_config_info WHERE nid = (SELECT max(nid) FROM his_config_info WHERE id = ?)");
|
||||
assertArrayEquals(new Object[] {id}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = historyConfigInfoMapperByMySql.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.HIS_CONFIG_INFO);
|
||||
assertEquals(TableConstant.HIS_CONFIG_INFO, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = historyConfigInfoMapperByMySql.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.MYSQL);
|
||||
assertEquals(DataSourceConstant.MYSQL, dataSource);
|
||||
}
|
||||
}
|
||||
|
@ -21,28 +21,30 @@ import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperContext;
|
||||
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class TenantCapacityMapperByMySqlTest {
|
||||
|
||||
private TenantCapacityMapperByMySql tenantCapacityMapperByMySql;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class TenantCapacityMapperByMySqlTest {
|
||||
|
||||
String tenantId = "tenantId";
|
||||
|
||||
MapperContext context;
|
||||
|
||||
private TenantCapacityMapperByMySql tenantCapacityMapperByMySql;
|
||||
|
||||
private Object modified = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
private Object oldModified = new Timestamp(System.currentTimeMillis());
|
||||
|
||||
private Object usage = 1;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
tenantCapacityMapperByMySql = new TenantCapacityMapperByMySql();
|
||||
context = new MapperContext();
|
||||
context.putUpdateParameter(FieldConstant.GMT_MODIFIED, modified);
|
||||
@ -53,74 +55,70 @@ public class TenantCapacityMapperByMySqlTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = tenantCapacityMapperByMySql.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.TENANT_CAPACITY);
|
||||
assertEquals(TableConstant.TENANT_CAPACITY, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = tenantCapacityMapperByMySql.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.MYSQL);
|
||||
assertEquals(DataSourceConstant.MYSQL, dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementUsageWithDefaultQuotaLimit() {
|
||||
void testIncrementUsageWithDefaultQuotaLimit() {
|
||||
MapperResult mapperResult = tenantCapacityMapperByMySql.incrementUsageWithDefaultQuotaLimit(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE tenant_capacity SET usage = usage + 1, gmt_modified = ? WHERE tenant_id = ? AND usage <"
|
||||
+ " ? AND quota = 0");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, tenantId, usage});
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"UPDATE tenant_capacity SET usage = usage + 1, gmt_modified = ? WHERE tenant_id = ? AND usage <" + " ? AND quota = 0");
|
||||
assertArrayEquals(new Object[] {modified, tenantId, usage}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementUsageWithQuotaLimit() {
|
||||
void testIncrementUsageWithQuotaLimit() {
|
||||
MapperResult mapperResult = tenantCapacityMapperByMySql.incrementUsageWithQuotaLimit(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE tenant_capacity SET usage = usage + 1, gmt_modified = ? WHERE tenant_id = ? AND usage < "
|
||||
+ "quota AND quota != 0");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, tenantId});
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"UPDATE tenant_capacity SET usage = usage + 1, gmt_modified = ? WHERE tenant_id = ? AND usage < " + "quota AND quota != 0");
|
||||
assertArrayEquals(new Object[] {modified, tenantId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrementUsage() {
|
||||
void testIncrementUsage() {
|
||||
MapperResult mapperResult = tenantCapacityMapperByMySql.incrementUsage(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE tenant_capacity SET usage = usage + 1, gmt_modified = ? WHERE tenant_id = ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, tenantId});
|
||||
assertEquals("UPDATE tenant_capacity SET usage = usage + 1, gmt_modified = ? WHERE tenant_id = ?", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {modified, tenantId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecrementUsage() {
|
||||
void testDecrementUsage() {
|
||||
MapperResult mapperResult = tenantCapacityMapperByMySql.decrementUsage(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE tenant_capacity SET usage = usage - 1, gmt_modified = ? WHERE tenant_id = ? AND usage > 0");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {modified, tenantId});
|
||||
assertEquals("UPDATE tenant_capacity SET usage = usage - 1, gmt_modified = ? WHERE tenant_id = ? AND usage > 0",
|
||||
mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {modified, tenantId}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCorrectUsage() {
|
||||
void testCorrectUsage() {
|
||||
MapperResult mapperResult = tenantCapacityMapperByMySql.correctUsage(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
"UPDATE tenant_capacity SET usage = (SELECT count(*) FROM config_info WHERE tenant_id = ?), "
|
||||
+ "gmt_modified = ? WHERE tenant_id = ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {tenantId, modified, tenantId});
|
||||
assertEquals(mapperResult.getSql(), "UPDATE tenant_capacity SET usage = (SELECT count(*) FROM config_info WHERE tenant_id = ?), "
|
||||
+ "gmt_modified = ? WHERE tenant_id = ?");
|
||||
assertArrayEquals(new Object[] {tenantId, modified, tenantId}, mapperResult.getParamList().toArray());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCapacityList4CorrectUsage() {
|
||||
void testGetCapacityList4CorrectUsage() {
|
||||
Object id = 1;
|
||||
Object limit = 10;
|
||||
context.putWhereParameter(FieldConstant.ID, id);
|
||||
context.putWhereParameter(FieldConstant.LIMIT_SIZE, limit);
|
||||
MapperResult mapperResult = tenantCapacityMapperByMySql.getCapacityList4CorrectUsage(context);
|
||||
Assert.assertEquals(mapperResult.getSql(), "SELECT id, tenant_id FROM tenant_capacity WHERE id>? LIMIT ?");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(), new Object[] {id, limit});
|
||||
assertEquals("SELECT id, tenant_id FROM tenant_capacity WHERE id>? LIMIT ?", mapperResult.getSql());
|
||||
assertArrayEquals(new Object[] {id, limit}, mapperResult.getParamList().toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsertTenantCapacity() {
|
||||
void testInsertTenantCapacity() {
|
||||
Object group = "group";
|
||||
Object quota = "quota";
|
||||
Object maxAggrSize = 10;
|
||||
@ -141,10 +139,10 @@ public class TenantCapacityMapperByMySqlTest {
|
||||
context.putWhereParameter(FieldConstant.TENANT_ID, tenantId);
|
||||
|
||||
MapperResult mapperResult = tenantCapacityMapperByMySql.insertTenantCapacity(context);
|
||||
Assert.assertEquals(mapperResult.getSql(),
|
||||
assertEquals(mapperResult.getSql(),
|
||||
"INSERT INTO tenant_capacity (tenant_id, quota, usage, max_size, max_aggr_count, max_aggr_size, "
|
||||
+ "gmt_create, gmt_modified) SELECT ?, ?, count(*), ?, ?, ?, ?, ? FROM config_info WHERE tenant_id=?;");
|
||||
Assert.assertArrayEquals(mapperResult.getParamList().toArray(),
|
||||
new Object[] {tenantId, quota, maxSize, maxAggrCount, maxAggrSize, createTime, modified, tenantId});
|
||||
assertArrayEquals(new Object[] {tenantId, quota, maxSize, maxAggrCount, maxAggrSize, createTime, modified, tenantId},
|
||||
mapperResult.getParamList().toArray());
|
||||
}
|
||||
}
|
||||
|
@ -18,28 +18,29 @@ package com.alibaba.nacos.plugin.datasource.impl.mysql;
|
||||
|
||||
import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant;
|
||||
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TenantInfoMapperByMySqlTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class TenantInfoMapperByMySqlTest {
|
||||
|
||||
private TenantInfoMapperByMySql tenantInfoMapperByMySql;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
tenantInfoMapperByMySql = new TenantInfoMapperByMySql();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTableName() {
|
||||
void testGetTableName() {
|
||||
String tableName = tenantInfoMapperByMySql.getTableName();
|
||||
Assert.assertEquals(tableName, TableConstant.TENANT_INFO);
|
||||
assertEquals(TableConstant.TENANT_INFO, tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataSource() {
|
||||
void testGetDataSource() {
|
||||
String dataSource = tenantInfoMapperByMySql.getDataSource();
|
||||
Assert.assertEquals(dataSource, DataSourceConstant.MYSQL);
|
||||
assertEquals(DataSourceConstant.MYSQL, dataSource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,66 +17,67 @@
|
||||
package com.alibaba.nacos.plugin.datasource.mapper;
|
||||
|
||||
import com.alibaba.nacos.plugin.datasource.impl.mysql.TenantInfoMapperByMySql;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class AbstractMapperTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class AbstractMapperTest {
|
||||
|
||||
private AbstractMapper abstractMapper;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
abstractMapper = new TenantInfoMapperByMySql();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelect() {
|
||||
void testSelect() {
|
||||
String sql = abstractMapper.select(Arrays.asList("id", "name"), Arrays.asList("id"));
|
||||
Assert.assertEquals(sql, "SELECT id,name FROM tenant_info WHERE id = ?");
|
||||
assertEquals("SELECT id,name FROM tenant_info WHERE id = ?", sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInsert() {
|
||||
void testInsert() {
|
||||
String sql = abstractMapper.insert(Arrays.asList("id", "name"));
|
||||
Assert.assertEquals(sql, "INSERT INTO tenant_info(id, name) VALUES(?,?)");
|
||||
assertEquals("INSERT INTO tenant_info(id, name) VALUES(?,?)", sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate() {
|
||||
void testUpdate() {
|
||||
String sql = abstractMapper.update(Arrays.asList("id", "name"), Arrays.asList("id"));
|
||||
Assert.assertEquals(sql, "UPDATE tenant_info SET id = ?,name = ? WHERE id = ?");
|
||||
assertEquals("UPDATE tenant_info SET id = ?,name = ? WHERE id = ?", sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelete() {
|
||||
void testDelete() {
|
||||
String sql = abstractMapper.delete(Arrays.asList("id"));
|
||||
Assert.assertEquals(sql, "DELETE FROM tenant_info WHERE id = ? ");
|
||||
assertEquals("DELETE FROM tenant_info WHERE id = ? ", sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCount() {
|
||||
void testCount() {
|
||||
String sql = abstractMapper.count(Arrays.asList("id"));
|
||||
Assert.assertEquals(sql, "SELECT COUNT(*) FROM tenant_info WHERE id = ?");
|
||||
assertEquals("SELECT COUNT(*) FROM tenant_info WHERE id = ?", sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPrimaryKeyGeneratedKeys() {
|
||||
void testGetPrimaryKeyGeneratedKeys() {
|
||||
String[] keys = abstractMapper.getPrimaryKeyGeneratedKeys();
|
||||
Assert.assertEquals(keys[0], "id");
|
||||
assertEquals("id", keys[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelectAll() {
|
||||
void testSelectAll() {
|
||||
String sql = abstractMapper.select(Arrays.asList("id", "name"), null);
|
||||
Assert.assertEquals(sql, "SELECT id,name FROM tenant_info ");
|
||||
assertEquals("SELECT id,name FROM tenant_info ", sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountAll() {
|
||||
void testCountAll() {
|
||||
String sql = abstractMapper.count(null);
|
||||
Assert.assertEquals(sql, "SELECT COUNT(*) FROM tenant_info ");
|
||||
assertEquals("SELECT COUNT(*) FROM tenant_info ", sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,18 +22,19 @@ import com.alibaba.nacos.plugin.datasource.impl.mysql.ConfigInfoAggrMapperByMySq
|
||||
|
||||
/**
|
||||
* Implement interfaces other than Mapper. just for test
|
||||
*
|
||||
* @author mikolls
|
||||
**/
|
||||
public class TestMapper extends ConfigInfoAggrMapperByMySql implements TestInterface {
|
||||
|
||||
|
||||
@Override
|
||||
public String getTableName() {
|
||||
return "enable_data_source_log_test";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getDataSource() {
|
||||
return DataSourceConstant.MYSQL;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -17,60 +17,61 @@
|
||||
package com.alibaba.nacos.plugin.datasource.proxy;
|
||||
|
||||
import com.alibaba.nacos.plugin.datasource.mapper.Mapper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
public class MapperProxyTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class MapperProxyTest {
|
||||
|
||||
private MapperProxy mapperProxy;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.mapperProxy = new MapperProxy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateProxy() {
|
||||
void testCreateProxy() {
|
||||
Mapper mapper = new Mapper() {
|
||||
@Override
|
||||
public String select(List<String> columns, List<String> where) {
|
||||
return "select-test";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String insert(List<String> columns) {
|
||||
return "insert-test";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String update(List<String> columns, List<String> where) {
|
||||
return "update-test";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String delete(List<String> params) {
|
||||
return "delete-test";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String count(List<String> where) {
|
||||
return "count-test";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getTableName() {
|
||||
return "test";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getDataSource() {
|
||||
return "test";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getPrimaryKeyGeneratedKeys() {
|
||||
return new String[0];
|
||||
@ -84,7 +85,7 @@ public class MapperProxyTest {
|
||||
Field mapperField = mapperProxy.getClass().getDeclaredField("mapper");
|
||||
mapperField.setAccessible(true);
|
||||
Class<?> clazz = mapperField.getDeclaringClass();
|
||||
Assert.assertEquals(MapperProxy.class, clazz);
|
||||
assertEquals(MapperProxy.class, clazz);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -17,26 +17,28 @@
|
||||
package com.alibaba.nacos.plugin.encryption;
|
||||
|
||||
import com.alibaba.nacos.plugin.encryption.spi.EncryptionPluginService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* EncryptionPluginManagerTest.
|
||||
*
|
||||
* @author lixiaoshuang
|
||||
*/
|
||||
public class EncryptionPluginManagerTest {
|
||||
class EncryptionPluginManagerTest {
|
||||
|
||||
@Test
|
||||
public void testInstance() {
|
||||
void testInstance() {
|
||||
EncryptionPluginManager instance = EncryptionPluginManager.instance();
|
||||
Assert.assertNotNull(instance);
|
||||
assertNotNull(instance);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoin() {
|
||||
void testJoin() {
|
||||
EncryptionPluginManager.join(new EncryptionPluginService() {
|
||||
@Override
|
||||
public String encrypt(String secretKey, String content) {
|
||||
@ -57,25 +59,25 @@ public class EncryptionPluginManagerTest {
|
||||
public String algorithmName() {
|
||||
return "aes";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String encryptSecretKey(String secretKey) {
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String decryptSecretKey(String secretKey) {
|
||||
return secretKey;
|
||||
}
|
||||
});
|
||||
Assert.assertNotNull(EncryptionPluginManager.instance().findEncryptionService("aes"));
|
||||
assertNotNull(EncryptionPluginManager.instance().findEncryptionService("aes"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindEncryptionService() {
|
||||
void testFindEncryptionService() {
|
||||
EncryptionPluginManager instance = EncryptionPluginManager.instance();
|
||||
Optional<EncryptionPluginService> optional = instance.findEncryptionService("aes");
|
||||
Assert.assertTrue(optional.isPresent());
|
||||
assertTrue(optional.isPresent());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -20,19 +20,20 @@ import com.alibaba.nacos.common.utils.Pair;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.alibaba.nacos.plugin.encryption.EncryptionPluginManager;
|
||||
import com.alibaba.nacos.plugin.encryption.spi.EncryptionPluginService;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* AES encryption algorithm testing dataId with prefix cipher.
|
||||
@ -41,12 +42,12 @@ import org.junit.Test;
|
||||
* @Date 2023/12/22 6:07 PM
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class EncryptionAesHandlerTest {
|
||||
class EncryptionAesHandlerTest {
|
||||
|
||||
private EncryptionPluginService mockEncryptionPluginService;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mockEncryptionPluginService = new EncryptionPluginService() {
|
||||
|
||||
private static final String ALGORITHM = "AES";
|
||||
@ -138,18 +139,18 @@ public class EncryptionAesHandlerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncrypt() {
|
||||
void testEncrypt() {
|
||||
String content = "content";
|
||||
String contentKey = mockEncryptionPluginService.generateSecretKey();
|
||||
Pair<String, String> pair = EncryptionHandler.encryptHandler("cipher-aes-dataId", content);
|
||||
Assert.assertEquals("should return the encryption secret key if algorithm defined.", mockEncryptionPluginService.encryptSecretKey(contentKey),
|
||||
pair.getFirst());
|
||||
Assert.assertEquals("should return the encryption content if algorithm defined.", mockEncryptionPluginService.encrypt(contentKey, content),
|
||||
pair.getSecond());
|
||||
assertEquals(mockEncryptionPluginService.encryptSecretKey(contentKey), pair.getFirst(),
|
||||
"should return the encryption secret key if algorithm defined.");
|
||||
assertEquals(mockEncryptionPluginService.encrypt(contentKey, content), pair.getSecond(),
|
||||
"should return the encryption content if algorithm defined.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecrypt() {
|
||||
void testDecrypt() {
|
||||
String content = "content";
|
||||
String contentKey = mockEncryptionPluginService.generateSecretKey();
|
||||
String encryptionSecretKey = mockEncryptionPluginService.encryptSecretKey(contentKey);
|
||||
@ -157,14 +158,14 @@ public class EncryptionAesHandlerTest {
|
||||
|
||||
Pair<String, String> pair = EncryptionHandler.decryptHandler("cipher-aes-dataId", encryptionSecretKey, encryptionContent);
|
||||
|
||||
Assert.assertEquals("should return the original secret key if algorithm defined.", mockEncryptionPluginService.generateSecretKey(),
|
||||
pair.getFirst());
|
||||
Assert.assertEquals("should return the original content if algorithm defined.", content, pair.getSecond());
|
||||
assertEquals(mockEncryptionPluginService.generateSecretKey(), pair.getFirst(),
|
||||
"should return the original secret key if algorithm defined.");
|
||||
assertEquals(content, pair.getSecond(), "should return the original content if algorithm defined.");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncryptAndDecrypt() {
|
||||
void testEncryptAndDecrypt() {
|
||||
String dataId = "cipher-aes-dataId";
|
||||
String content = "content";
|
||||
String contentKey = mockEncryptionPluginService.generateSecretKey();
|
||||
@ -172,64 +173,64 @@ public class EncryptionAesHandlerTest {
|
||||
Pair<String, String> encryptPair = EncryptionHandler.encryptHandler(dataId, content);
|
||||
String encryptionSecretKey = encryptPair.getFirst();
|
||||
String encryptionContent = encryptPair.getSecond();
|
||||
Assert.assertNotNull(encryptPair);
|
||||
Assert.assertEquals("should return the encryption secret key if algorithm defined.", mockEncryptionPluginService.encryptSecretKey(contentKey),
|
||||
encryptionSecretKey);
|
||||
Assert.assertEquals("should return the encryption content if algorithm defined.", mockEncryptionPluginService.encrypt(contentKey, content),
|
||||
encryptionContent);
|
||||
assertNotNull(encryptPair);
|
||||
assertEquals(mockEncryptionPluginService.encryptSecretKey(contentKey), encryptionSecretKey,
|
||||
"should return the encryption secret key if algorithm defined.");
|
||||
assertEquals(mockEncryptionPluginService.encrypt(contentKey, content), encryptionContent,
|
||||
"should return the encryption content if algorithm defined.");
|
||||
|
||||
Pair<String, String> decryptPair = EncryptionHandler.decryptHandler(dataId, encryptionSecretKey, encryptionContent);
|
||||
Assert.assertNotNull(decryptPair);
|
||||
Assert.assertEquals("should return the original secret key if algorithm defined.", mockEncryptionPluginService.generateSecretKey(),
|
||||
decryptPair.getFirst());
|
||||
Assert.assertEquals("should return the original content if algorithm defined.", content, decryptPair.getSecond());
|
||||
assertNotNull(decryptPair);
|
||||
assertEquals(mockEncryptionPluginService.generateSecretKey(), decryptPair.getFirst(),
|
||||
"should return the original secret key if algorithm defined.");
|
||||
assertEquals(content, decryptPair.getSecond(), "should return the original content if algorithm defined.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrefixNotCipherEncrypt() {
|
||||
void testPrefixNotCipherEncrypt() {
|
||||
String content = "content";
|
||||
Pair<String, String> pair = EncryptionHandler.encryptHandler("test-dataId", content);
|
||||
Assert.assertNotNull(pair);
|
||||
Assert.assertEquals(pair.getFirst(), "");
|
||||
Assert.assertEquals(pair.getSecond(), content);
|
||||
assertNotNull(pair);
|
||||
assertEquals("", pair.getFirst());
|
||||
assertEquals(pair.getSecond(), content);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPrefixNotCipherDecrypt() {
|
||||
void testPrefixNotCipherDecrypt() {
|
||||
String content = "content";
|
||||
Pair<String, String> pair = EncryptionHandler.decryptHandler("test-dataId", "", content);
|
||||
Assert.assertNotNull(pair);
|
||||
Assert.assertEquals(pair.getFirst(), "");
|
||||
Assert.assertEquals(pair.getSecond(), content);
|
||||
assertNotNull(pair);
|
||||
assertEquals("", pair.getFirst());
|
||||
assertEquals(pair.getSecond(), content);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlgorithmEmpty() {
|
||||
void testAlgorithmEmpty() {
|
||||
String dataId = "cipher-";
|
||||
String content = "content";
|
||||
Pair<String, String> pair = EncryptionHandler.encryptHandler(dataId, content);
|
||||
Assert.assertNotNull("should not throw exception when parsing enc algo for dataId '" + dataId + "'", pair);
|
||||
Assert.assertEquals(pair.getFirst(), "");
|
||||
Assert.assertEquals(pair.getSecond(), content);
|
||||
assertNotNull(pair, "should not throw exception when parsing enc algo for dataId '" + dataId + "'");
|
||||
assertEquals("", pair.getFirst());
|
||||
assertEquals(pair.getSecond(), content);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnknownAlgorithmNameEncrypt() {
|
||||
void testUnknownAlgorithmNameEncrypt() {
|
||||
String dataId = "cipher-mySM4-application";
|
||||
String content = "content";
|
||||
Pair<String, String> pair = EncryptionHandler.encryptHandler(dataId, content);
|
||||
Assert.assertNotNull(pair);
|
||||
Assert.assertEquals(pair.getFirst(), "");
|
||||
Assert.assertEquals("should return original content if algorithm is not defined.", content, pair.getSecond());
|
||||
assertNotNull(pair);
|
||||
assertEquals("", pair.getFirst());
|
||||
assertEquals(content, pair.getSecond(), "should return original content if algorithm is not defined.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnknownAlgorithmNameDecrypt() {
|
||||
void testUnknownAlgorithmNameDecrypt() {
|
||||
String dataId = "cipher-mySM4-application";
|
||||
String content = "content";
|
||||
Pair<String, String> pair = EncryptionHandler.decryptHandler(dataId, "", content);
|
||||
Assert.assertNotNull(pair);
|
||||
Assert.assertEquals(pair.getFirst(), "");
|
||||
Assert.assertEquals("should return original content if algorithm is not defined.", content, pair.getSecond());
|
||||
assertNotNull(pair);
|
||||
assertEquals("", pair.getFirst());
|
||||
assertEquals(content, pair.getSecond(), "should return original content if algorithm is not defined.");
|
||||
}
|
||||
}
|
||||
|
@ -19,21 +19,23 @@ package com.alibaba.nacos.plugin.encryption.handler;
|
||||
import com.alibaba.nacos.common.utils.Pair;
|
||||
import com.alibaba.nacos.plugin.encryption.EncryptionPluginManager;
|
||||
import com.alibaba.nacos.plugin.encryption.spi.EncryptionPluginService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* EncryptionHandlerTest.
|
||||
*
|
||||
* @author lixiaoshuang
|
||||
*/
|
||||
public class EncryptionHandlerTest {
|
||||
class EncryptionHandlerTest {
|
||||
|
||||
private EncryptionPluginService mockEncryptionPluginService;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
mockEncryptionPluginService = new EncryptionPluginService() {
|
||||
@Override
|
||||
public String encrypt(String secretKey, String content) {
|
||||
@ -69,65 +71,63 @@ public class EncryptionHandlerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncryptHandler() {
|
||||
void testEncryptHandler() {
|
||||
Pair<String, String> pair = EncryptionHandler.encryptHandler("test-dataId", "content");
|
||||
Assert.assertNotNull(pair);
|
||||
assertNotNull(pair);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecryptHandler() {
|
||||
void testDecryptHandler() {
|
||||
Pair<String, String> pair = EncryptionHandler.decryptHandler("test-dataId", "12345678", "content");
|
||||
Assert.assertNotNull(pair);
|
||||
assertNotNull(pair);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCornerCaseDataIdAlgoParse() {
|
||||
void testCornerCaseDataIdAlgoParse() {
|
||||
String dataId = "cipher-";
|
||||
Pair<String, String> pair = EncryptionHandler.encryptHandler(dataId, "content");
|
||||
Assert.assertNotNull("should not throw exception when parsing enc algo for dataId '" + dataId + "'", pair);
|
||||
assertNotNull(pair, "should not throw exception when parsing enc algo for dataId '" + dataId + "'");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnknownAlgorithmNameEnc() {
|
||||
void testUnknownAlgorithmNameEnc() {
|
||||
String dataId = "cipher-mySM4-application";
|
||||
String content = "content";
|
||||
Pair<String, String> pair = EncryptionHandler.encryptHandler(dataId, content);
|
||||
Assert.assertNotNull(pair);
|
||||
Assert.assertEquals("should return original content if algorithm is not defined.", content, pair.getSecond());
|
||||
assertNotNull(pair);
|
||||
assertEquals(content, pair.getSecond(), "should return original content if algorithm is not defined.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnknownAlgorithmNameDecrypt() {
|
||||
void testUnknownAlgorithmNameDecrypt() {
|
||||
String dataId = "cipher-mySM4-application";
|
||||
String content = "content";
|
||||
Pair<String, String> pair = EncryptionHandler.decryptHandler(dataId, "", content);
|
||||
Assert.assertNotNull(pair);
|
||||
Assert.assertEquals("should return original content if algorithm is not defined.", content, pair.getSecond());
|
||||
assertNotNull(pair);
|
||||
assertEquals(content, pair.getSecond(), "should return original content if algorithm is not defined.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEncrypt() {
|
||||
void testEncrypt() {
|
||||
String dataId = "cipher-mockAlgo-application";
|
||||
String content = "content";
|
||||
String sec = mockEncryptionPluginService.generateSecretKey();
|
||||
Pair<String, String> pair = EncryptionHandler.encryptHandler(dataId, content);
|
||||
Assert.assertNotNull(pair);
|
||||
Assert.assertEquals("should return encrypted content.",
|
||||
mockEncryptionPluginService.encrypt(sec, content), pair.getSecond());
|
||||
Assert.assertEquals("should return encrypted secret key.",
|
||||
mockEncryptionPluginService.encryptSecretKey(sec), pair.getFirst());
|
||||
assertNotNull(pair);
|
||||
assertEquals(mockEncryptionPluginService.encrypt(sec, content), pair.getSecond(), "should return encrypted content.");
|
||||
assertEquals(mockEncryptionPluginService.encryptSecretKey(sec), pair.getFirst(), "should return encrypted secret key.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDecrypt() {
|
||||
void testDecrypt() {
|
||||
String dataId = "cipher-mockAlgo-application";
|
||||
String oContent = "content";
|
||||
String oSec = mockEncryptionPluginService.generateSecretKey();
|
||||
String content = mockEncryptionPluginService.encrypt(oSec, oContent);
|
||||
String sec = mockEncryptionPluginService.encryptSecretKey(oSec);
|
||||
Pair<String, String> pair = EncryptionHandler.decryptHandler(dataId, sec, content);
|
||||
Assert.assertNotNull(pair);
|
||||
Assert.assertEquals("should return original content.", oContent, pair.getSecond());
|
||||
Assert.assertEquals("should return original secret key.", oSec, pair.getFirst());
|
||||
assertNotNull(pair);
|
||||
assertEquals(oContent, pair.getSecond(), "should return original content.");
|
||||
assertEquals(oSec, pair.getFirst(), "should return original secret key.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,28 +17,30 @@
|
||||
package com.alibaba.nacos.plugin.environment;
|
||||
|
||||
import com.alibaba.nacos.plugin.environment.spi.CustomEnvironmentPluginService;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* CustomEnvironment Plugin Test.
|
||||
*
|
||||
* @author : huangtianhui
|
||||
*/
|
||||
public class CustomEnvironmentPluginManagerTest {
|
||||
class CustomEnvironmentPluginManagerTest {
|
||||
|
||||
@Test
|
||||
public void testInstance() {
|
||||
void testInstance() {
|
||||
CustomEnvironmentPluginManager instance = CustomEnvironmentPluginManager.getInstance();
|
||||
Assert.assertNotNull(instance);
|
||||
assertNotNull(instance);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testJoin() {
|
||||
void testJoin() {
|
||||
CustomEnvironmentPluginManager.join(new CustomEnvironmentPluginService() {
|
||||
@Override
|
||||
public Map<String, Object> customValue(Map<String, Object> property) {
|
||||
@ -46,27 +48,27 @@ public class CustomEnvironmentPluginManagerTest {
|
||||
property.put("db.password.0", "test" + pwd);
|
||||
return property;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Set<String> propertyKey() {
|
||||
Set<String> propertyKey = new HashSet<>();
|
||||
propertyKey.add("db.password.0");
|
||||
return propertyKey;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Integer order() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String pluginName() {
|
||||
return "test";
|
||||
}
|
||||
});
|
||||
Assert.assertNotNull(CustomEnvironmentPluginManager.getInstance().getPropertyKeys());
|
||||
assertNotNull(CustomEnvironmentPluginManager.getInstance().getPropertyKeys());
|
||||
Map<String, Object> sourcePropertyMap = new HashMap<>();
|
||||
sourcePropertyMap.put("db.password.0", "nacos");
|
||||
Assert.assertNotNull(CustomEnvironmentPluginManager.getInstance().getCustomValues(sourcePropertyMap));
|
||||
assertNotNull(CustomEnvironmentPluginManager.getInstance().getCustomValues(sourcePropertyMap));
|
||||
}
|
||||
}
|
||||
|
@ -17,21 +17,21 @@
|
||||
package com.alibaba.nacos.plugin.trace;
|
||||
|
||||
import com.alibaba.nacos.plugin.trace.spi.NacosTraceSubscriber;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
public class NacosTracePluginManagerTest {
|
||||
class NacosTracePluginManagerTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
@BeforeAll
|
||||
static void setUp() {
|
||||
NacosTracePluginManager.getInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllTraceSubscribers() {
|
||||
void testGetAllTraceSubscribers() {
|
||||
assertFalse(NacosTracePluginManager.getInstance().getAllTraceSubscribers().isEmpty());
|
||||
assertContainsTestPlugin();
|
||||
}
|
||||
@ -42,6 +42,6 @@ public class NacosTracePluginManagerTest {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Assert.fail("No found plugin named 'trace-plugin-mock'");
|
||||
fail("No found plugin named 'trace-plugin-mock'");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user