* refact(api): remove junit4 to junit5 * format with code style
This commit is contained in:
parent
9363a088f0
commit
366c88e4d6
@ -20,25 +20,25 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ClientAbilitiesTest {
|
class ClientAbilitiesTest {
|
||||||
|
|
||||||
private static ObjectMapper mapper;
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
ClientAbilities abilities = new ClientAbilities();
|
ClientAbilities abilities = new ClientAbilities();
|
||||||
String json = mapper.writeValueAsString(abilities);
|
String json = mapper.writeValueAsString(abilities);
|
||||||
assertTrue(json.contains("\"remoteAbility\":{"));
|
assertTrue(json.contains("\"remoteAbility\":{"));
|
||||||
@ -47,7 +47,7 @@ public class ClientAbilitiesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false},"
|
String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false},"
|
||||||
+ "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false,"
|
+ "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false,"
|
||||||
+ "\"supportRemoteMetric\":false}}";
|
+ "\"supportRemoteMetric\":false}}";
|
||||||
|
@ -20,35 +20,35 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServerAbilitiesTest {
|
class ServerAbilitiesTest {
|
||||||
|
|
||||||
private static ObjectMapper mapper;
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
private ServerAbilities serverAbilities;
|
private ServerAbilities serverAbilities;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpBeforeClass() throws Exception {
|
static void setUpBeforeClass() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
serverAbilities = new ServerAbilities();
|
serverAbilities = new ServerAbilities();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
serverAbilities = new ServerAbilities();
|
serverAbilities = new ServerAbilities();
|
||||||
String json = mapper.writeValueAsString(serverAbilities);
|
String json = mapper.writeValueAsString(serverAbilities);
|
||||||
assertTrue(json.contains("\"remoteAbility\":{"));
|
assertTrue(json.contains("\"remoteAbility\":{"));
|
||||||
@ -57,7 +57,7 @@ public class ServerAbilitiesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false},"
|
String json = "{\"remoteAbility\":{\"supportRemoteConnection\":false},"
|
||||||
+ "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false,"
|
+ "\"configAbility\":{\"supportRemoteMetrics\":false},\"namingAbility\":{\"supportDeltaPush\":false,"
|
||||||
+ "\"supportRemoteMetric\":false}}";
|
+ "\"supportRemoteMetric\":false}}";
|
||||||
@ -68,10 +68,10 @@ public class ServerAbilitiesTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualsAndHashCode() {
|
void testEqualsAndHashCode() {
|
||||||
assertEquals(serverAbilities, serverAbilities);
|
assertEquals(serverAbilities, serverAbilities);
|
||||||
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
|
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
|
||||||
assertNotEquals(serverAbilities, null);
|
assertNotEquals(null, serverAbilities);
|
||||||
assertNotEquals(serverAbilities, new ClientAbilities());
|
assertNotEquals(serverAbilities, new ClientAbilities());
|
||||||
ServerAbilities test = new ServerAbilities();
|
ServerAbilities test = new ServerAbilities();
|
||||||
assertEquals(serverAbilities, test);
|
assertEquals(serverAbilities, test);
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.ability.register.impl;
|
package com.alibaba.nacos.api.ability.register.impl;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ClusterClientAbilitiesTest {
|
class ClusterClientAbilitiesTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetStaticAbilities() {
|
void testGetStaticAbilities() {
|
||||||
// TODO add the cluster client abilities.
|
// TODO add the cluster client abilities.
|
||||||
assertTrue(ClusterClientAbilities.getStaticAbilities().isEmpty());
|
assertTrue(ClusterClientAbilities.getStaticAbilities().isEmpty());
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.ability.register.impl;
|
package com.alibaba.nacos.api.ability.register.impl;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class SdkClientAbilitiesTest {
|
class SdkClientAbilitiesTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetStaticAbilities() {
|
void testGetStaticAbilities() {
|
||||||
// TODO add the sdk client abilities.
|
// TODO add the sdk client abilities.
|
||||||
assertTrue(SdkClientAbilities.getStaticAbilities().isEmpty());
|
assertTrue(SdkClientAbilities.getStaticAbilities().isEmpty());
|
||||||
}
|
}
|
||||||
|
@ -17,20 +17,20 @@
|
|||||||
package com.alibaba.nacos.api.ability.register.impl;
|
package com.alibaba.nacos.api.ability.register.impl;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServerAbilitiesTest {
|
class ServerAbilitiesTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetStaticAbilities() {
|
void testGetStaticAbilities() {
|
||||||
assertFalse(ServerAbilities.getStaticAbilities().isEmpty());
|
assertFalse(ServerAbilities.getStaticAbilities().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSupportPersistentInstanceByGrpcAbilities() {
|
void testSupportPersistentInstanceByGrpcAbilities() {
|
||||||
assertTrue(ServerAbilities.getStaticAbilities().get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC));
|
assertTrue(ServerAbilities.getStaticAbilities().get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,8 +16,7 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.annotation;
|
package com.alibaba.nacos.api.annotation;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.mock.env.MockEnvironment;
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
|
|
||||||
import static com.alibaba.nacos.api.annotation.NacosProperties.ACCESS_KEY_PLACEHOLDER;
|
import static com.alibaba.nacos.api.annotation.NacosProperties.ACCESS_KEY_PLACEHOLDER;
|
||||||
@ -28,23 +27,24 @@ import static com.alibaba.nacos.api.annotation.NacosProperties.ENDPOINT_PLACEHOL
|
|||||||
import static com.alibaba.nacos.api.annotation.NacosProperties.NAMESPACE_PLACEHOLDER;
|
import static com.alibaba.nacos.api.annotation.NacosProperties.NAMESPACE_PLACEHOLDER;
|
||||||
import static com.alibaba.nacos.api.annotation.NacosProperties.SECRET_KEY_PLACEHOLDER;
|
import static com.alibaba.nacos.api.annotation.NacosProperties.SECRET_KEY_PLACEHOLDER;
|
||||||
import static com.alibaba.nacos.api.annotation.NacosProperties.SERVER_ADDR_PLACEHOLDER;
|
import static com.alibaba.nacos.api.annotation.NacosProperties.SERVER_ADDR_PLACEHOLDER;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class NacosPropertiesTest {
|
class NacosPropertiesTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPlaceholders() {
|
void testPlaceholders() {
|
||||||
Assert.assertEquals("${nacos.endpoint:}", ENDPOINT_PLACEHOLDER);
|
assertEquals("${nacos.endpoint:}", ENDPOINT_PLACEHOLDER);
|
||||||
Assert.assertEquals("${nacos.namespace:}", NAMESPACE_PLACEHOLDER);
|
assertEquals("${nacos.namespace:}", NAMESPACE_PLACEHOLDER);
|
||||||
Assert.assertEquals("${nacos.access-key:}", ACCESS_KEY_PLACEHOLDER);
|
assertEquals("${nacos.access-key:}", ACCESS_KEY_PLACEHOLDER);
|
||||||
Assert.assertEquals("${nacos.secret-key:}", SECRET_KEY_PLACEHOLDER);
|
assertEquals("${nacos.secret-key:}", SECRET_KEY_PLACEHOLDER);
|
||||||
Assert.assertEquals("${nacos.server-addr:}", SERVER_ADDR_PLACEHOLDER);
|
assertEquals("${nacos.server-addr:}", SERVER_ADDR_PLACEHOLDER);
|
||||||
Assert.assertEquals("${nacos.context-path:}", CONTEXT_PATH_PLACEHOLDER);
|
assertEquals("${nacos.context-path:}", CONTEXT_PATH_PLACEHOLDER);
|
||||||
Assert.assertEquals("${nacos.cluster-name:}", CLUSTER_NAME_PLACEHOLDER);
|
assertEquals("${nacos.cluster-name:}", CLUSTER_NAME_PLACEHOLDER);
|
||||||
Assert.assertEquals("${nacos.encode:UTF-8}", ENCODE_PLACEHOLDER);
|
assertEquals("${nacos.encode:UTF-8}", ENCODE_PLACEHOLDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testResolvePlaceholders() {
|
void testResolvePlaceholders() {
|
||||||
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "nacos.endpoint", "test-value", "test-value");
|
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "nacos.endpoint", "test-value", "test-value");
|
||||||
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "", "test-value", "");
|
testResolvePlaceholder(ENDPOINT_PLACEHOLDER, "", "test-value", "");
|
||||||
|
|
||||||
@ -75,11 +75,11 @@ public class NacosPropertiesTest {
|
|||||||
MockEnvironment environment = new MockEnvironment();
|
MockEnvironment environment = new MockEnvironment();
|
||||||
environment.setProperty(propertyName, propertyValue);
|
environment.setProperty(propertyName, propertyValue);
|
||||||
String resolvedValue = environment.resolvePlaceholders(placeholder);
|
String resolvedValue = environment.resolvePlaceholders(placeholder);
|
||||||
Assert.assertEquals(expectValue, resolvedValue);
|
assertEquals(expectValue, resolvedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSort() {
|
void testSort() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,24 +20,24 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class EntityEventTest {
|
class EntityEventTest {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialization() throws JsonProcessingException {
|
void testSerialization() throws JsonProcessingException {
|
||||||
EntityEvent entity = new EntityEvent();
|
EntityEvent entity = new EntityEvent();
|
||||||
entity.setEntityName("test-entity");
|
entity.setEntityName("test-entity");
|
||||||
entity.setEntityType("CMDB");
|
entity.setEntityType("CMDB");
|
||||||
@ -50,7 +50,7 @@ public class EntityEventTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialization() throws JsonProcessingException {
|
void testDeserialization() throws JsonProcessingException {
|
||||||
String json = "{\"type\":\"ENTITY_REMOVE\",\"entityName\":\"test-entity\",\"entityType\":\"CMDB\"}";
|
String json = "{\"type\":\"ENTITY_REMOVE\",\"entityName\":\"test-entity\",\"entityType\":\"CMDB\"}";
|
||||||
EntityEvent entity = mapper.readValue(json, EntityEvent.class);
|
EntityEvent entity = mapper.readValue(json, EntityEvent.class);
|
||||||
assertEquals("test-entity", entity.getEntityName());
|
assertEquals("test-entity", entity.getEntityName());
|
||||||
|
@ -20,26 +20,26 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class EntityTest {
|
class EntityTest {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialization() throws JsonProcessingException {
|
void testSerialization() throws JsonProcessingException {
|
||||||
Entity entity = new Entity();
|
Entity entity = new Entity();
|
||||||
entity.setName("test-entity");
|
entity.setName("test-entity");
|
||||||
entity.setType(PreservedEntityTypes.ip.name());
|
entity.setType(PreservedEntityTypes.ip.name());
|
||||||
@ -51,7 +51,7 @@ public class EntityTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialization() throws JsonProcessingException {
|
void testDeserialization() throws JsonProcessingException {
|
||||||
String json = "{\"type\":\"service\",\"name\":\"test-entity\",\"labels\":{\"test-label-key\":\"test-label-value\"}}";
|
String json = "{\"type\":\"service\",\"name\":\"test-entity\",\"labels\":{\"test-label-key\":\"test-label-value\"}}";
|
||||||
Entity entity = mapper.readValue(json, Entity.class);
|
Entity entity = mapper.readValue(json, Entity.class);
|
||||||
assertEquals("test-entity", entity.getName());
|
assertEquals("test-entity", entity.getName());
|
||||||
|
@ -20,26 +20,26 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class LabelTest {
|
class LabelTest {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialization() throws JsonProcessingException {
|
void testSerialization() throws JsonProcessingException {
|
||||||
Label label = new Label();
|
Label label = new Label();
|
||||||
label.setName("test-label");
|
label.setName("test-label");
|
||||||
label.setDescription("CMDB description");
|
label.setDescription("CMDB description");
|
||||||
@ -52,7 +52,7 @@ public class LabelTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialization() throws JsonProcessingException {
|
void testDeserialization() throws JsonProcessingException {
|
||||||
String json = "{\"values\":[\"test-value\"],\"name\":\"test-label\",\"description\":\"CMDB description\"}";
|
String json = "{\"values\":[\"test-value\"],\"name\":\"test-label\",\"description\":\"CMDB description\"}";
|
||||||
Label label = mapper.readValue(json, Label.class);
|
Label label = mapper.readValue(json, Label.class);
|
||||||
assertEquals("test-label", label.getName());
|
assertEquals("test-label", label.getName());
|
||||||
|
@ -16,18 +16,18 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.config;
|
package com.alibaba.nacos.api.config;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class ConfigChangeEventTest {
|
class ConfigChangeEventTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor() {
|
void testConstructor() {
|
||||||
Map<String, ConfigChangeItem> mockData = new HashMap<>();
|
Map<String, ConfigChangeItem> mockData = new HashMap<>();
|
||||||
mockData.put("test", new ConfigChangeItem("testKey", null, "testValue"));
|
mockData.put("test", new ConfigChangeItem("testKey", null, "testValue"));
|
||||||
ConfigChangeEvent event = new ConfigChangeEvent(mockData);
|
ConfigChangeEvent event = new ConfigChangeEvent(mockData);
|
||||||
|
@ -16,15 +16,15 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.config;
|
package com.alibaba.nacos.api.config;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class ConfigChangeItemTest {
|
class ConfigChangeItemTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetNewValue() {
|
void testSetNewValue() {
|
||||||
ConfigChangeItem item = new ConfigChangeItem("testKey", null, "testValue");
|
ConfigChangeItem item = new ConfigChangeItem("testKey", null, "testValue");
|
||||||
item.setType(PropertyChangeType.ADDED);
|
item.setType(PropertyChangeType.ADDED);
|
||||||
assertEquals("testKey", item.getKey());
|
assertEquals("testKey", item.getKey());
|
||||||
@ -46,7 +46,7 @@ public class ConfigChangeItemTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString() {
|
void testToString() {
|
||||||
ConfigChangeItem item = new ConfigChangeItem("testKey", null, "testValue");
|
ConfigChangeItem item = new ConfigChangeItem("testKey", null, "testValue");
|
||||||
item.setType(PropertyChangeType.ADDED);
|
item.setType(PropertyChangeType.ADDED);
|
||||||
assertEquals("ConfigChangeItem{key='testKey', oldValue='null', newValue='testValue', type=ADDED}",
|
assertEquals("ConfigChangeItem{key='testKey', oldValue='null', newValue='testValue', type=ADDED}",
|
||||||
|
@ -16,16 +16,16 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.config;
|
package com.alibaba.nacos.api.config;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigTypeTest {
|
class ConfigTypeTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isValidType() {
|
void isValidType() {
|
||||||
assertTrue(ConfigType.isValidType("xml"));
|
assertTrue(ConfigType.isValidType("xml"));
|
||||||
assertTrue(ConfigType.isValidType("properties"));
|
assertTrue(ConfigType.isValidType("properties"));
|
||||||
assertTrue(ConfigType.isValidType("json"));
|
assertTrue(ConfigType.isValidType("json"));
|
||||||
@ -38,7 +38,7 @@ public class ConfigTypeTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDefaultType() {
|
void testGetDefaultType() {
|
||||||
assertEquals("text", ConfigType.getDefaultType().getType());
|
assertEquals("text", ConfigType.getDefaultType().getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,32 +21,32 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ClientRemoteAbilityTest {
|
class ClientRemoteAbilityTest {
|
||||||
|
|
||||||
private static ObjectMapper mapper;
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
ClientRemoteAbility abilities = new ClientRemoteAbility();
|
ClientRemoteAbility abilities = new ClientRemoteAbility();
|
||||||
String json = mapper.writeValueAsString(abilities);
|
String json = mapper.writeValueAsString(abilities);
|
||||||
assertEquals("{\"supportRemoteConnection\":false}", json);
|
assertEquals("{\"supportRemoteConnection\":false}", json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"supportRemoteConnection\":true}";
|
String json = "{\"supportRemoteConnection\":true}";
|
||||||
ClientRemoteAbility abilities = mapper.readValue(json, ClientRemoteAbility.class);
|
ClientRemoteAbility abilities = mapper.readValue(json, ClientRemoteAbility.class);
|
||||||
assertTrue(abilities.isSupportRemoteConnection());
|
assertTrue(abilities.isSupportRemoteConnection());
|
||||||
|
@ -16,21 +16,20 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.config.ability;
|
package com.alibaba.nacos.api.config.ability;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
|
||||||
|
|
||||||
public class ServerConfigAbilityTest {
|
class ServerConfigAbilityTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquals() {
|
void testEquals() {
|
||||||
ServerConfigAbility ability = new ServerConfigAbility();
|
ServerConfigAbility ability = new ServerConfigAbility();
|
||||||
ability.setSupportRemoteMetrics(true);
|
ability.setSupportRemoteMetrics(true);
|
||||||
assertEquals(ability, ability);
|
assertEquals(ability, ability);
|
||||||
assertFalse(ability.equals(null));
|
assertNotEquals(null, ability);
|
||||||
assertFalse(ability.equals(new ClientConfigAbility()));
|
assertNotEquals(ability, new ClientConfigAbility());
|
||||||
ServerConfigAbility newOne = new ServerConfigAbility();
|
ServerConfigAbility newOne = new ServerConfigAbility();
|
||||||
assertNotEquals(ability, newOne);
|
assertNotEquals(ability, newOne);
|
||||||
newOne.setSupportRemoteMetrics(true);
|
newOne.setSupportRemoteMetrics(true);
|
||||||
|
@ -23,35 +23,35 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.MapperFeature;
|
import com.fasterxml.jackson.databind.MapperFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServerRemoteAbilityTest {
|
class ServerRemoteAbilityTest {
|
||||||
|
|
||||||
private static ObjectMapper mapper;
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
private ServerRemoteAbility serverAbilities;
|
private ServerRemoteAbility serverAbilities;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpBeforeClass() throws Exception {
|
static void setUpBeforeClass() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
|
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
serverAbilities = new ServerRemoteAbility();
|
serverAbilities = new ServerRemoteAbility();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
serverAbilities = new ServerRemoteAbility();
|
serverAbilities = new ServerRemoteAbility();
|
||||||
String json = mapper.writeValueAsString(serverAbilities);
|
String json = mapper.writeValueAsString(serverAbilities);
|
||||||
assertTrue(json.contains("\"supportRemoteConnection\":false"));
|
assertTrue(json.contains("\"supportRemoteConnection\":false"));
|
||||||
@ -59,7 +59,7 @@ public class ServerRemoteAbilityTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"supportRemoteConnection\":true,\"grpcReportEnabled\":true}";
|
String json = "{\"supportRemoteConnection\":true,\"grpcReportEnabled\":true}";
|
||||||
ServerRemoteAbility abilities = mapper.readValue(json, ServerRemoteAbility.class);
|
ServerRemoteAbility abilities = mapper.readValue(json, ServerRemoteAbility.class);
|
||||||
assertTrue(abilities.isSupportRemoteConnection());
|
assertTrue(abilities.isSupportRemoteConnection());
|
||||||
@ -67,10 +67,10 @@ public class ServerRemoteAbilityTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualsAndHashCode() {
|
void testEqualsAndHashCode() {
|
||||||
assertEquals(serverAbilities, serverAbilities);
|
assertEquals(serverAbilities, serverAbilities);
|
||||||
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
|
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
|
||||||
assertNotEquals(serverAbilities, null);
|
assertNotEquals(null, serverAbilities);
|
||||||
assertNotEquals(serverAbilities, new ClientAbilities());
|
assertNotEquals(serverAbilities, new ClientAbilities());
|
||||||
ServerRemoteAbility test = new ServerRemoteAbility();
|
ServerRemoteAbility test = new ServerRemoteAbility();
|
||||||
assertEquals(serverAbilities, test);
|
assertEquals(serverAbilities, test);
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.config.listener;
|
package com.alibaba.nacos.api.config.listener;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class AbstractListenerTest {
|
class AbstractListenerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetExecutor() {
|
void testGetExecutor() {
|
||||||
// Default listener executor is null.
|
// Default listener executor is null.
|
||||||
assertNull(new AbstractListener() {
|
assertNull(new AbstractListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,28 +16,28 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.config.listener;
|
package com.alibaba.nacos.api.config.listener;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class AbstractSharedListenerTest {
|
class AbstractSharedListenerTest {
|
||||||
|
|
||||||
private static final String CONFIG_CONTENT = "test";
|
private static final String CONFIG_CONTENT = "test";
|
||||||
|
|
||||||
private static Map<String, String> receivedMap;
|
private static Map<String, String> receivedMap;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
receivedMap = new HashMap<>();
|
receivedMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFillContext() {
|
void testFillContext() {
|
||||||
assertEquals(0, receivedMap.size());
|
assertEquals(0, receivedMap.size());
|
||||||
MockShardListener listener = new MockShardListener();
|
MockShardListener listener = new MockShardListener();
|
||||||
listener.receiveConfigInfo(CONFIG_CONTENT);
|
listener.receiveConfigInfo(CONFIG_CONTENT);
|
||||||
@ -52,7 +52,7 @@ public class AbstractSharedListenerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getExecutor() {
|
void getExecutor() {
|
||||||
// Default listener executor is null.
|
// Default listener executor is null.
|
||||||
assertNull(new MockShardListener().getExecutor());
|
assertNull(new MockShardListener().getExecutor());
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.MapperFeature;
|
import com.fasterxml.jackson.databind.MapperFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -30,8 +30,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public abstract class BasedConfigRequestTest {
|
public abstract class BasedConfigRequestTest {
|
||||||
|
|
||||||
protected static ObjectMapper mapper;
|
|
||||||
|
|
||||||
protected static final String DATA_ID = "test_data";
|
protected static final String DATA_ID = "test_data";
|
||||||
|
|
||||||
protected static final String GROUP = "group";
|
protected static final String GROUP = "group";
|
||||||
@ -52,11 +50,13 @@ public abstract class BasedConfigRequestTest {
|
|||||||
|
|
||||||
protected static final String CONTENT = "content";
|
protected static final String CONTENT = "content";
|
||||||
|
|
||||||
|
protected static ObjectMapper mapper;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
HEADERS.put(HEADER_KEY, HEADER_VALUE);
|
HEADERS.put(HEADER_KEY, HEADER_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
|
@ -18,18 +18,17 @@ package com.alibaba.nacos.api.config.remote.request;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import static com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest.MetricsKey.CACHE_DATA;
|
import static com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest.MetricsKey.CACHE_DATA;
|
||||||
import static com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest.MetricsKey.SNAPSHOT_DATA;
|
import static com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest.MetricsKey.SNAPSHOT_DATA;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
public class ClientConfigMetricRequestTest extends BasedConfigRequestTest {
|
class ClientConfigMetricRequestTest extends BasedConfigRequestTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test
|
@Test
|
||||||
@ -57,35 +56,36 @@ public class ClientConfigMetricRequestTest extends BasedConfigRequestTest {
|
|||||||
+ "\"test_data+group+test_tenant\"},{\"type\":\"snapshotData\","
|
+ "\"test_data+group+test_tenant\"},{\"type\":\"snapshotData\","
|
||||||
+ "\"key\":\"test_data+group+test_tenant\"}],\"module\":\"config\"}";
|
+ "\"key\":\"test_data+group+test_tenant\"}],\"module\":\"config\"}";
|
||||||
ClientConfigMetricRequest actual = mapper.readValue(json, ClientConfigMetricRequest.class);
|
ClientConfigMetricRequest actual = mapper.readValue(json, ClientConfigMetricRequest.class);
|
||||||
assertEquals(actual.getMetricsKeys().size(), 2);
|
assertEquals(2, actual.getMetricsKeys().size());
|
||||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||||
assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE);
|
assertEquals(HEADER_VALUE, actual.getHeader(HEADER_KEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMetricsKeysEquals() {
|
void testMetricsKeysEquals() {
|
||||||
String dataKey = String.join("+", KEY);
|
String dataKey = String.join("+", KEY);
|
||||||
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, dataKey);
|
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, dataKey);
|
||||||
assertEquals(key, key);
|
assertEquals(key, key);
|
||||||
assertFalse(key.equals(null));
|
assertNotEquals(null, key);
|
||||||
assertFalse(key.equals(new ClientConfigMetricRequest()));
|
assertNotEquals(key, new ClientConfigMetricRequest());
|
||||||
ClientConfigMetricRequest.MetricsKey newOne = ClientConfigMetricRequest.MetricsKey
|
ClientConfigMetricRequest.MetricsKey newOne = ClientConfigMetricRequest.MetricsKey.build(SNAPSHOT_DATA,
|
||||||
.build(SNAPSHOT_DATA, dataKey);
|
dataKey);
|
||||||
assertNotEquals(key, newOne);
|
assertNotEquals(key, newOne);
|
||||||
newOne.setType(CACHE_DATA);
|
newOne.setType(CACHE_DATA);
|
||||||
assertEquals(key, newOne);
|
assertEquals(key, newOne);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMetricsHashCode() {
|
void testMetricsHashCode() {
|
||||||
String dataKey = String.join("+", KEY);
|
String dataKey = String.join("+", KEY);
|
||||||
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, dataKey);
|
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, dataKey);
|
||||||
assertEquals(Objects.hash(CACHE_DATA, dataKey), key.hashCode());
|
assertEquals(Objects.hash(CACHE_DATA, dataKey), key.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMetricsToString() {
|
void testMetricsToString() {
|
||||||
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, String.join("+", KEY));
|
ClientConfigMetricRequest.MetricsKey key = ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA,
|
||||||
|
String.join("+", KEY));
|
||||||
assertEquals("MetricsKey{type='cacheData', key='test_data+group+test_tenant'}", key.toString());
|
assertEquals("MetricsKey{type='cacheData', key='test_data+group+test_tenant'}", key.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,12 @@ package com.alibaba.nacos.api.config.remote.request;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigBatchListenRequestTest extends BasedConfigRequestTest {
|
class ConfigBatchListenRequestTest extends BasedConfigRequestTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test
|
@Test
|
||||||
@ -47,14 +47,14 @@ public class ConfigBatchListenRequestTest extends BasedConfigRequestTest {
|
|||||||
+ "\"configListenContexts\":[{\"group\":\"group\",\"md5\":\"test_MD5\","
|
+ "\"configListenContexts\":[{\"group\":\"group\",\"md5\":\"test_MD5\","
|
||||||
+ "\"dataId\":\"test_data\",\"tenant\":\"test_tenant\"}],\"module\":\"config\"}";
|
+ "\"dataId\":\"test_data\",\"tenant\":\"test_tenant\"}],\"module\":\"config\"}";
|
||||||
ConfigBatchListenRequest actual = mapper.readValue(json, ConfigBatchListenRequest.class);
|
ConfigBatchListenRequest actual = mapper.readValue(json, ConfigBatchListenRequest.class);
|
||||||
assertEquals(actual.isListen(), true);
|
assertEquals(true, actual.isListen());
|
||||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||||
assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE);
|
assertEquals(HEADER_VALUE, actual.getHeader(HEADER_KEY));
|
||||||
assertEquals(actual.getConfigListenContexts().size(), 1);
|
assertEquals(1, actual.getConfigListenContexts().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConfigListenContextToString() {
|
void testConfigListenContextToString() {
|
||||||
ConfigBatchListenRequest configBatchListenRequest = new ConfigBatchListenRequest();
|
ConfigBatchListenRequest configBatchListenRequest = new ConfigBatchListenRequest();
|
||||||
configBatchListenRequest.addConfigListenContext(GROUP, DATA_ID, TENANT, MD5);
|
configBatchListenRequest.addConfigListenContext(GROUP, DATA_ID, TENANT, MD5);
|
||||||
assertEquals("ConfigListenContext{group='group', md5='test_MD5', dataId='test_data', tenant='test_tenant'}",
|
assertEquals("ConfigListenContext{group='group', md5='test_MD5', dataId='test_data', tenant='test_tenant'}",
|
||||||
|
@ -18,20 +18,20 @@ package com.alibaba.nacos.api.config.remote.request;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigChangeNotifyRequestTest extends BasedConfigRequestTest {
|
class ConfigChangeNotifyRequestTest extends BasedConfigRequestTest {
|
||||||
|
|
||||||
ConfigChangeNotifyRequest configChangeNotifyRequest;
|
ConfigChangeNotifyRequest configChangeNotifyRequest;
|
||||||
|
|
||||||
String requestId;
|
String requestId;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configChangeNotifyRequest = ConfigChangeNotifyRequest.build(DATA_ID, GROUP, TENANT);
|
configChangeNotifyRequest = ConfigChangeNotifyRequest.build(DATA_ID, GROUP, TENANT);
|
||||||
configChangeNotifyRequest.putAllHeader(HEADERS);
|
configChangeNotifyRequest.putAllHeader(HEADERS);
|
||||||
requestId = injectRequestUuId(configChangeNotifyRequest);
|
requestId = injectRequestUuId(configChangeNotifyRequest);
|
||||||
@ -54,10 +54,10 @@ public class ConfigChangeNotifyRequestTest extends BasedConfigRequestTest {
|
|||||||
String json = "{\"headers\":{\"header1\":\"test_header1\"},\"dataId\":\"test_data\",\"group\":"
|
String json = "{\"headers\":{\"header1\":\"test_header1\"},\"dataId\":\"test_data\",\"group\":"
|
||||||
+ "\"group\",\"tenant\":\"test_tenant\",\"module\":\"config\"}";
|
+ "\"group\",\"tenant\":\"test_tenant\",\"module\":\"config\"}";
|
||||||
ConfigChangeNotifyRequest actual = mapper.readValue(json, ConfigChangeNotifyRequest.class);
|
ConfigChangeNotifyRequest actual = mapper.readValue(json, ConfigChangeNotifyRequest.class);
|
||||||
assertEquals(actual.getDataId(), DATA_ID);
|
assertEquals(DATA_ID, actual.getDataId());
|
||||||
assertEquals(actual.getGroup(), GROUP);
|
assertEquals(GROUP, actual.getGroup());
|
||||||
assertEquals(actual.getTenant(), TENANT);
|
assertEquals(TENANT, actual.getTenant());
|
||||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||||
assertEquals(actual.getHeader(HEADER_KEY), HEADER_VALUE);
|
assertEquals(HEADER_VALUE, actual.getHeader(HEADER_KEY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,24 +18,24 @@ package com.alibaba.nacos.api.config.remote.request;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigPublishRequestTest extends BasedConfigRequestTest {
|
class ConfigPublishRequestTest extends BasedConfigRequestTest {
|
||||||
|
|
||||||
ConfigPublishRequest configPublishRequest;
|
|
||||||
|
|
||||||
private static final String TAG_PARAM = "tag";
|
private static final String TAG_PARAM = "tag";
|
||||||
|
|
||||||
private static final String APP_NAME_PARAM = "appName";
|
private static final String APP_NAME_PARAM = "appName";
|
||||||
|
|
||||||
|
ConfigPublishRequest configPublishRequest;
|
||||||
|
|
||||||
String requestId;
|
String requestId;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configPublishRequest = new ConfigPublishRequest(DATA_ID, GROUP, TENANT, CONTENT);
|
configPublishRequest = new ConfigPublishRequest(DATA_ID, GROUP, TENANT, CONTENT);
|
||||||
configPublishRequest.putAdditionalParam(TAG_PARAM, TAG_PARAM);
|
configPublishRequest.putAdditionalParam(TAG_PARAM, TAG_PARAM);
|
||||||
configPublishRequest.putAdditionalParam(APP_NAME_PARAM, APP_NAME_PARAM);
|
configPublishRequest.putAdditionalParam(APP_NAME_PARAM, APP_NAME_PARAM);
|
||||||
@ -64,13 +64,13 @@ public class ConfigPublishRequestTest extends BasedConfigRequestTest {
|
|||||||
+ "\"tenant\":\"test_tenant\",\"content\":\"content\",\"casMd5\":\"test_MD5\","
|
+ "\"tenant\":\"test_tenant\",\"content\":\"content\",\"casMd5\":\"test_MD5\","
|
||||||
+ "\"additionMap\":{\"appName\":\"appName\",\"tag\":\"tag\"},\"module\":\"config\"}";
|
+ "\"additionMap\":{\"appName\":\"appName\",\"tag\":\"tag\"},\"module\":\"config\"}";
|
||||||
ConfigPublishRequest actual = mapper.readValue(json, ConfigPublishRequest.class);
|
ConfigPublishRequest actual = mapper.readValue(json, ConfigPublishRequest.class);
|
||||||
assertEquals(actual.getDataId(), DATA_ID);
|
assertEquals(DATA_ID, actual.getDataId());
|
||||||
assertEquals(actual.getGroup(), GROUP);
|
assertEquals(GROUP, actual.getGroup());
|
||||||
assertEquals(actual.getTenant(), TENANT);
|
assertEquals(TENANT, actual.getTenant());
|
||||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||||
assertEquals(actual.getContent(), CONTENT);
|
assertEquals(CONTENT, actual.getContent());
|
||||||
assertEquals(actual.getCasMd5(), MD5);
|
assertEquals(MD5, actual.getCasMd5());
|
||||||
assertEquals(actual.getAdditionParam(TAG_PARAM), TAG_PARAM);
|
assertEquals(TAG_PARAM, actual.getAdditionParam(TAG_PARAM));
|
||||||
assertEquals(actual.getAdditionParam(APP_NAME_PARAM), APP_NAME_PARAM);
|
assertEquals(APP_NAME_PARAM, actual.getAdditionParam(APP_NAME_PARAM));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,16 @@ package com.alibaba.nacos.api.config.remote.request;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
||||||
|
|
||||||
ConfigQueryRequest configQueryRequest;
|
ConfigQueryRequest configQueryRequest;
|
||||||
|
|
||||||
@ -35,8 +35,8 @@ public class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
|||||||
|
|
||||||
String requestId;
|
String requestId;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
headers.put(Constants.Config.NOTIFY_HEADER, Boolean.TRUE.toString());
|
headers.put(Constants.Config.NOTIFY_HEADER, Boolean.TRUE.toString());
|
||||||
configQueryRequest = ConfigQueryRequest.build(DATA_ID, GROUP, TENANT);
|
configQueryRequest = ConfigQueryRequest.build(DATA_ID, GROUP, TENANT);
|
||||||
configQueryRequest.putAllHeader(headers);
|
configQueryRequest.putAllHeader(headers);
|
||||||
@ -45,7 +45,7 @@ public class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsNotify() {
|
void testIsNotify() {
|
||||||
assertTrue(configQueryRequest.isNotify());
|
assertTrue(configQueryRequest.isNotify());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,10 +67,10 @@ public class ConfigQueryRequestTest extends BasedConfigRequestTest {
|
|||||||
String json = "{\"headers\":{\"notify\":\"true\"},\"dataId\":\"test_data\",\"group\":\"group\","
|
String json = "{\"headers\":{\"notify\":\"true\"},\"dataId\":\"test_data\",\"group\":\"group\","
|
||||||
+ "\"tenant\":\"test_tenant\",\"notify\":true,\"module\":\"config\",\"tag\":\"tag\"}";
|
+ "\"tenant\":\"test_tenant\",\"notify\":true,\"module\":\"config\",\"tag\":\"tag\"}";
|
||||||
ConfigQueryRequest actual = mapper.readValue(json, ConfigQueryRequest.class);
|
ConfigQueryRequest actual = mapper.readValue(json, ConfigQueryRequest.class);
|
||||||
assertEquals(actual.getDataId(), DATA_ID);
|
assertEquals(DATA_ID, actual.getDataId());
|
||||||
assertEquals(actual.getGroup(), GROUP);
|
assertEquals(GROUP, actual.getGroup());
|
||||||
assertEquals(actual.getTenant(), TENANT);
|
assertEquals(TENANT, actual.getTenant());
|
||||||
assertEquals(actual.getTag(), TAG);
|
assertEquals(TAG, actual.getTag());
|
||||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,20 +18,20 @@ package com.alibaba.nacos.api.config.remote.request;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigRemoveRequestTest extends BasedConfigRequestTest {
|
class ConfigRemoveRequestTest extends BasedConfigRequestTest {
|
||||||
|
|
||||||
ConfigRemoveRequest configRemoveRequest;
|
ConfigRemoveRequest configRemoveRequest;
|
||||||
|
|
||||||
String requestId;
|
String requestId;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configRemoveRequest = new ConfigRemoveRequest(DATA_ID, GROUP, TENANT, TAG);
|
configRemoveRequest = new ConfigRemoveRequest(DATA_ID, GROUP, TENANT, TAG);
|
||||||
requestId = injectRequestUuId(configRemoveRequest);
|
requestId = injectRequestUuId(configRemoveRequest);
|
||||||
|
|
||||||
@ -56,10 +56,10 @@ public class ConfigRemoveRequestTest extends BasedConfigRequestTest {
|
|||||||
String json = "{\"headers\":{},\"dataId\":\"test_data\",\"group\":\"group\",\"tenant\":\"test_tenant\""
|
String json = "{\"headers\":{},\"dataId\":\"test_data\",\"group\":\"group\",\"tenant\":\"test_tenant\""
|
||||||
+ ",\"tag\":\"tag\",\"module\":\"config\"}";
|
+ ",\"tag\":\"tag\",\"module\":\"config\"}";
|
||||||
ConfigRemoveRequest actual = mapper.readValue(json, ConfigRemoveRequest.class);
|
ConfigRemoveRequest actual = mapper.readValue(json, ConfigRemoveRequest.class);
|
||||||
assertEquals(actual.getDataId(), DATA_ID);
|
assertEquals(DATA_ID, actual.getDataId());
|
||||||
assertEquals(actual.getGroup(), GROUP);
|
assertEquals(GROUP, actual.getGroup());
|
||||||
assertEquals(actual.getTenant(), TENANT);
|
assertEquals(TENANT, actual.getTenant());
|
||||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||||
assertEquals(actual.getTag(), TAG);
|
assertEquals(TAG, actual.getTag());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,20 +19,20 @@ package com.alibaba.nacos.api.config.remote.request.cluster;
|
|||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.alibaba.nacos.api.config.remote.request.BasedConfigRequestTest;
|
import com.alibaba.nacos.api.config.remote.request.BasedConfigRequestTest;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest {
|
class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest {
|
||||||
|
|
||||||
ConfigChangeClusterSyncRequest configChangeClusterSyncRequest;
|
ConfigChangeClusterSyncRequest configChangeClusterSyncRequest;
|
||||||
|
|
||||||
String requestId;
|
String requestId;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configChangeClusterSyncRequest = new ConfigChangeClusterSyncRequest();
|
configChangeClusterSyncRequest = new ConfigChangeClusterSyncRequest();
|
||||||
configChangeClusterSyncRequest.setDataId(DATA_ID);
|
configChangeClusterSyncRequest.setDataId(DATA_ID);
|
||||||
configChangeClusterSyncRequest.setGroup(GROUP);
|
configChangeClusterSyncRequest.setGroup(GROUP);
|
||||||
@ -64,15 +64,16 @@ public class ConfigChangeClusterSyncRequestTest extends BasedConfigRequestTest {
|
|||||||
@Override
|
@Override
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
public void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"headers\":{\"header1\":\"test_header1\"},\"requestId\":\"ece89111-3c42-4055-aca4-c95e16ec564b\",\"dataId\":\"test_data\","
|
String json =
|
||||||
+ "\"group\":\"group\",\"tenant\":\"test_tenant\","
|
"{\"headers\":{\"header1\":\"test_header1\"},\"requestId\":\"ece89111-3c42-4055-aca4-c95e16ec564b\",\"dataId\":\"test_data\","
|
||||||
+ "\"tag\":\"tag\",\"lastModified\":0,\"beta\":true,\"module\":\"config\"}";
|
+ "\"group\":\"group\",\"tenant\":\"test_tenant\","
|
||||||
|
+ "\"tag\":\"tag\",\"lastModified\":0,\"beta\":true,\"module\":\"config\"}";
|
||||||
ConfigChangeClusterSyncRequest actual = mapper.readValue(json, ConfigChangeClusterSyncRequest.class);
|
ConfigChangeClusterSyncRequest actual = mapper.readValue(json, ConfigChangeClusterSyncRequest.class);
|
||||||
assertEquals(actual.getDataId(), DATA_ID);
|
assertEquals(DATA_ID, actual.getDataId());
|
||||||
assertEquals(actual.getGroup(), GROUP);
|
assertEquals(GROUP, actual.getGroup());
|
||||||
assertEquals(actual.getTenant(), TENANT);
|
assertEquals(TENANT, actual.getTenant());
|
||||||
assertEquals(actual.getModule(), Constants.Config.CONFIG_MODULE);
|
assertEquals(Constants.Config.CONFIG_MODULE, actual.getModule());
|
||||||
assertEquals(actual.getLastModified(), 0L);
|
assertEquals(0L, actual.getLastModified());
|
||||||
assertTrue(actual.isBeta());
|
assertTrue(actual.isBeta());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,14 +18,14 @@ package com.alibaba.nacos.api.config.remote.response;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ClientConfigMetricResponseTest extends BasedConfigResponseTest {
|
public class ClientConfigMetricResponseTest extends BasedConfigResponseTest {
|
||||||
|
|
||||||
@ -33,8 +33,8 @@ public class ClientConfigMetricResponseTest extends BasedConfigResponseTest {
|
|||||||
|
|
||||||
Map<String, Object> metric = new HashMap<>(16);
|
Map<String, Object> metric = new HashMap<>(16);
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
metric.put("m1", "v1");
|
metric.put("m1", "v1");
|
||||||
clientConfigMetricResponse = new ClientConfigMetricResponse();
|
clientConfigMetricResponse = new ClientConfigMetricResponse();
|
||||||
clientConfigMetricResponse.setMetrics(metric);
|
clientConfigMetricResponse.setMetrics(metric);
|
||||||
|
@ -18,18 +18,18 @@ package com.alibaba.nacos.api.config.remote.response;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigChangeBatchListenResponseTest extends BasedConfigResponseTest {
|
class ConfigChangeBatchListenResponseTest extends BasedConfigResponseTest {
|
||||||
|
|
||||||
ConfigChangeBatchListenResponse configChangeBatchListenResponse;
|
ConfigChangeBatchListenResponse configChangeBatchListenResponse;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configChangeBatchListenResponse = new ConfigChangeBatchListenResponse();
|
configChangeBatchListenResponse = new ConfigChangeBatchListenResponse();
|
||||||
requestId = injectResponseUuId(configChangeBatchListenResponse);
|
requestId = injectResponseUuId(configChangeBatchListenResponse);
|
||||||
configChangeBatchListenResponse.addChangeConfig(DATA_ID, GROUP, TENANT);
|
configChangeBatchListenResponse.addChangeConfig(DATA_ID, GROUP, TENANT);
|
||||||
@ -50,8 +50,8 @@ public class ConfigChangeBatchListenResponseTest extends BasedConfigResponseTest
|
|||||||
@Override
|
@Override
|
||||||
@Test
|
@Test
|
||||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
public void testSerializeFailResponse() throws JsonProcessingException {
|
||||||
ConfigChangeBatchListenResponse configChangeBatchListenResponse = ConfigChangeBatchListenResponse
|
ConfigChangeBatchListenResponse configChangeBatchListenResponse = ConfigChangeBatchListenResponse.buildFailResponse(
|
||||||
.buildFailResponse("Fail");
|
"Fail");
|
||||||
String json = mapper.writeValueAsString(configChangeBatchListenResponse);
|
String json = mapper.writeValueAsString(configChangeBatchListenResponse);
|
||||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.FAIL.getCode()));
|
assertTrue(json.contains("\"resultCode\":" + ResponseCode.FAIL.getCode()));
|
||||||
assertTrue(json.contains("\"errorCode\":0"));
|
assertTrue(json.contains("\"errorCode\":0"));
|
||||||
|
@ -18,17 +18,17 @@ package com.alibaba.nacos.api.config.remote.response;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigChangeNotifyResponseTest extends BasedConfigResponseTest {
|
public class ConfigChangeNotifyResponseTest extends BasedConfigResponseTest {
|
||||||
|
|
||||||
ConfigChangeNotifyResponse configChangeNotifyResponse;
|
ConfigChangeNotifyResponse configChangeNotifyResponse;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configChangeNotifyResponse = new ConfigChangeNotifyResponse();
|
configChangeNotifyResponse = new ConfigChangeNotifyResponse();
|
||||||
requestId = injectResponseUuId(configChangeNotifyResponse);
|
requestId = injectResponseUuId(configChangeNotifyResponse);
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ public class ConfigChangeNotifyResponseTest extends BasedConfigResponseTest {
|
|||||||
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
assertTrue(json.contains("\"requestId\":\"" + requestId));
|
||||||
assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode()));
|
assertTrue(json.contains("\"resultCode\":" + ResponseCode.SUCCESS.getCode()));
|
||||||
assertTrue(json.contains("\"errorCode\":0"));
|
assertTrue(json.contains("\"errorCode\":0"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,17 +18,17 @@ package com.alibaba.nacos.api.config.remote.response;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigPublishResponseTest extends BasedConfigResponseTest {
|
class ConfigPublishResponseTest extends BasedConfigResponseTest {
|
||||||
|
|
||||||
ConfigPublishResponse configPublishResponse;
|
ConfigPublishResponse configPublishResponse;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configPublishResponse = ConfigPublishResponse.buildSuccessResponse();
|
configPublishResponse = ConfigPublishResponse.buildSuccessResponse();
|
||||||
requestId = injectResponseUuId(configPublishResponse);
|
requestId = injectResponseUuId(configPublishResponse);
|
||||||
}
|
}
|
||||||
|
@ -18,18 +18,18 @@ package com.alibaba.nacos.api.config.remote.response;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigQueryResponseTest extends BasedConfigResponseTest {
|
class ConfigQueryResponseTest extends BasedConfigResponseTest {
|
||||||
|
|
||||||
ConfigQueryResponse configQueryResponse;
|
ConfigQueryResponse configQueryResponse;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configQueryResponse = ConfigQueryResponse.buildSuccessResponse("success");
|
configQueryResponse = ConfigQueryResponse.buildSuccessResponse("success");
|
||||||
configQueryResponse.setContentType("text");
|
configQueryResponse.setContentType("text");
|
||||||
configQueryResponse.setEncryptedDataKey("encryptedKey");
|
configQueryResponse.setEncryptedDataKey("encryptedKey");
|
||||||
|
@ -18,17 +18,17 @@ package com.alibaba.nacos.api.config.remote.response;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigRemoveResponseTest extends BasedConfigResponseTest {
|
class ConfigRemoveResponseTest extends BasedConfigResponseTest {
|
||||||
|
|
||||||
ConfigRemoveResponse configRemoveResponse;
|
ConfigRemoveResponse configRemoveResponse;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configRemoveResponse = ConfigRemoveResponse.buildSuccessResponse();
|
configRemoveResponse = ConfigRemoveResponse.buildSuccessResponse();
|
||||||
requestId = injectResponseUuId(configRemoveResponse);
|
requestId = injectResponseUuId(configRemoveResponse);
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,17 @@ package com.alibaba.nacos.api.config.remote.response.cluster;
|
|||||||
import com.alibaba.nacos.api.config.remote.response.BasedConfigResponseTest;
|
import com.alibaba.nacos.api.config.remote.response.BasedConfigResponseTest;
|
||||||
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
import com.alibaba.nacos.api.remote.response.ResponseCode;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ConfigChangeClusterSyncResponseTest extends BasedConfigResponseTest {
|
public class ConfigChangeClusterSyncResponseTest extends BasedConfigResponseTest {
|
||||||
|
|
||||||
ConfigChangeClusterSyncResponse configChangeClusterSyncResponse;
|
ConfigChangeClusterSyncResponse configChangeClusterSyncResponse;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
void before() {
|
||||||
configChangeClusterSyncResponse = new ConfigChangeClusterSyncResponse();
|
configChangeClusterSyncResponse = new ConfigChangeClusterSyncResponse();
|
||||||
requestId = injectResponseUuId(configChangeClusterSyncResponse);
|
requestId = injectResponseUuId(configChangeClusterSyncResponse);
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,14 @@
|
|||||||
package com.alibaba.nacos.api.exception;
|
package com.alibaba.nacos.api.exception;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
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 NacosExceptionTest {
|
class NacosExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyConstructor() {
|
void testEmptyConstructor() {
|
||||||
NacosException exception = new NacosException();
|
NacosException exception = new NacosException();
|
||||||
assertEquals(0, exception.getErrCode());
|
assertEquals(0, exception.getErrCode());
|
||||||
assertEquals(Constants.NULL, exception.getErrMsg());
|
assertEquals(Constants.NULL, exception.getErrMsg());
|
||||||
@ -35,7 +35,7 @@ public class NacosExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithErrMsg() {
|
void testConstructorWithErrMsg() {
|
||||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR, "test");
|
NacosException exception = new NacosException(NacosException.SERVER_ERROR, "test");
|
||||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||||
assertEquals("test", exception.getErrMsg());
|
assertEquals("test", exception.getErrMsg());
|
||||||
@ -43,7 +43,7 @@ public class NacosExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithCause() {
|
void testConstructorWithCause() {
|
||||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR, new RuntimeException("cause test"));
|
NacosException exception = new NacosException(NacosException.SERVER_ERROR, new RuntimeException("cause test"));
|
||||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||||
assertEquals("cause test", exception.getErrMsg());
|
assertEquals("cause test", exception.getErrMsg());
|
||||||
@ -51,7 +51,7 @@ public class NacosExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithMultiCauses() {
|
void testConstructorWithMultiCauses() {
|
||||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR,
|
NacosException exception = new NacosException(NacosException.SERVER_ERROR,
|
||||||
new RuntimeException("cause test", new RuntimeException("multi")));
|
new RuntimeException("cause test", new RuntimeException("multi")));
|
||||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||||
@ -60,7 +60,7 @@ public class NacosExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithFull() {
|
void testConstructorWithFull() {
|
||||||
NacosException exception = new NacosException(NacosException.SERVER_ERROR, "test",
|
NacosException exception = new NacosException(NacosException.SERVER_ERROR, "test",
|
||||||
new RuntimeException("cause test"));
|
new RuntimeException("cause test"));
|
||||||
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
assertEquals(NacosException.SERVER_ERROR, exception.getErrCode());
|
||||||
|
@ -18,14 +18,14 @@ package com.alibaba.nacos.api.exception.api;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.alibaba.nacos.api.model.v2.ErrorCode;
|
import com.alibaba.nacos.api.model.v2.ErrorCode;
|
||||||
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 NacosApiExceptionTest {
|
class NacosApiExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyConstructor() {
|
void testEmptyConstructor() {
|
||||||
NacosApiException exception = new NacosApiException();
|
NacosApiException exception = new NacosApiException();
|
||||||
assertEquals(0, exception.getErrCode());
|
assertEquals(0, exception.getErrCode());
|
||||||
assertEquals(0, exception.getDetailErrCode());
|
assertEquals(0, exception.getDetailErrCode());
|
||||||
@ -34,7 +34,7 @@ public class NacosApiExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithoutCause() {
|
void testConstructorWithoutCause() {
|
||||||
NacosApiException exception = new NacosApiException(500, ErrorCode.SERVER_ERROR, "test");
|
NacosApiException exception = new NacosApiException(500, ErrorCode.SERVER_ERROR, "test");
|
||||||
assertEquals(500, exception.getErrCode());
|
assertEquals(500, exception.getErrCode());
|
||||||
assertEquals(ErrorCode.SERVER_ERROR.getCode().intValue(), exception.getDetailErrCode());
|
assertEquals(ErrorCode.SERVER_ERROR.getCode().intValue(), exception.getDetailErrCode());
|
||||||
@ -43,7 +43,7 @@ public class NacosApiExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithCause() {
|
void testConstructorWithCause() {
|
||||||
NacosApiException exception = new NacosApiException(500, ErrorCode.SERVER_ERROR,
|
NacosApiException exception = new NacosApiException(500, ErrorCode.SERVER_ERROR,
|
||||||
new RuntimeException("cause test"), "test");
|
new RuntimeException("cause test"), "test");
|
||||||
assertEquals(500, exception.getErrCode());
|
assertEquals(500, exception.getErrCode());
|
||||||
|
@ -18,17 +18,17 @@ package com.alibaba.nacos.api.exception.runtime;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.fasterxml.jackson.databind.type.SimpleType;
|
import com.fasterxml.jackson.databind.type.SimpleType;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class NacosDeserializationExceptionTest {
|
class NacosDeserializationExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyConstructor() {
|
void testEmptyConstructor() {
|
||||||
NacosDeserializationException exception = new NacosDeserializationException();
|
NacosDeserializationException exception = new NacosDeserializationException();
|
||||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
assertNull(exception.getMessage());
|
assertNull(exception.getMessage());
|
||||||
@ -36,7 +36,7 @@ public class NacosDeserializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithTargetClass() {
|
void testConstructorWithTargetClass() {
|
||||||
NacosDeserializationException exception = new NacosDeserializationException(
|
NacosDeserializationException exception = new NacosDeserializationException(
|
||||||
NacosDeserializationExceptionTest.class);
|
NacosDeserializationExceptionTest.class);
|
||||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
@ -46,7 +46,7 @@ public class NacosDeserializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithTargetType() {
|
void testConstructorWithTargetType() {
|
||||||
Type type = SimpleType.constructUnsafe(NacosDeserializationExceptionTest.class);
|
Type type = SimpleType.constructUnsafe(NacosDeserializationExceptionTest.class);
|
||||||
NacosDeserializationException exception = new NacosDeserializationException(type);
|
NacosDeserializationException exception = new NacosDeserializationException(type);
|
||||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
@ -57,7 +57,7 @@ public class NacosDeserializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithCause() {
|
void testConstructorWithCause() {
|
||||||
NacosDeserializationException exception = new NacosDeserializationException(new RuntimeException("test"));
|
NacosDeserializationException exception = new NacosDeserializationException(new RuntimeException("test"));
|
||||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
assertEquals("errCode: 101, errMsg: Nacos deserialize failed. ", exception.getMessage());
|
assertEquals("errCode: 101, errMsg: Nacos deserialize failed. ", exception.getMessage());
|
||||||
@ -65,7 +65,7 @@ public class NacosDeserializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithTargetClassAndCause() {
|
void testConstructorWithTargetClassAndCause() {
|
||||||
NacosDeserializationException exception = new NacosDeserializationException(
|
NacosDeserializationException exception = new NacosDeserializationException(
|
||||||
NacosDeserializationExceptionTest.class, new RuntimeException("test"));
|
NacosDeserializationExceptionTest.class, new RuntimeException("test"));
|
||||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
@ -75,7 +75,7 @@ public class NacosDeserializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithTargetTypeAndCause() {
|
void testConstructorWithTargetTypeAndCause() {
|
||||||
Type type = SimpleType.constructUnsafe(NacosDeserializationExceptionTest.class);
|
Type type = SimpleType.constructUnsafe(NacosDeserializationExceptionTest.class);
|
||||||
NacosDeserializationException exception = new NacosDeserializationException(type, new RuntimeException("test"));
|
NacosDeserializationException exception = new NacosDeserializationException(type, new RuntimeException("test"));
|
||||||
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.DESERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
|
@ -16,15 +16,15 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.exception.runtime;
|
package com.alibaba.nacos.api.exception.runtime;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class NacosLoadExceptionTest {
|
class NacosLoadExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor() {
|
void testConstructor() {
|
||||||
NacosLoadException exception = new NacosLoadException("test");
|
NacosLoadException exception = new NacosLoadException("test");
|
||||||
assertEquals("test", exception.getMessage());
|
assertEquals("test", exception.getMessage());
|
||||||
assertNull(exception.getCause());
|
assertNull(exception.getCause());
|
||||||
|
@ -17,16 +17,16 @@
|
|||||||
package com.alibaba.nacos.api.exception.runtime;
|
package com.alibaba.nacos.api.exception.runtime;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class NacosRuntimeExceptionTest {
|
class NacosRuntimeExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithErrorCode() {
|
void testConstructorWithErrorCode() {
|
||||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM);
|
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM);
|
||||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||||
assertNull(exception.getMessage());
|
assertNull(exception.getMessage());
|
||||||
@ -34,7 +34,7 @@ public class NacosRuntimeExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithErrorCodeAndMsg() {
|
void testConstructorWithErrorCodeAndMsg() {
|
||||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM, "test");
|
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM, "test");
|
||||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||||
assertEquals("errCode: 400, errMsg: test ", exception.getMessage());
|
assertEquals("errCode: 400, errMsg: test ", exception.getMessage());
|
||||||
@ -42,7 +42,7 @@ public class NacosRuntimeExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithErrorCodeAndCause() {
|
void testConstructorWithErrorCodeAndCause() {
|
||||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM,
|
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM,
|
||||||
new RuntimeException("test"));
|
new RuntimeException("test"));
|
||||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||||
@ -51,9 +51,9 @@ public class NacosRuntimeExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithFull() {
|
void testConstructorWithFull() {
|
||||||
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM,
|
NacosRuntimeException exception = new NacosRuntimeException(NacosException.INVALID_PARAM, "test",
|
||||||
"test", new RuntimeException("cause test"));
|
new RuntimeException("cause test"));
|
||||||
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
assertEquals(NacosException.INVALID_PARAM, exception.getErrCode());
|
||||||
assertEquals("errCode: 400, errMsg: test ", exception.getMessage());
|
assertEquals("errCode: 400, errMsg: test ", exception.getMessage());
|
||||||
assertTrue(exception.getCause() instanceof RuntimeException);
|
assertTrue(exception.getCause() instanceof RuntimeException);
|
||||||
|
@ -17,15 +17,15 @@
|
|||||||
package com.alibaba.nacos.api.exception.runtime;
|
package com.alibaba.nacos.api.exception.runtime;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
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;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class NacosSerializationExceptionTest {
|
class NacosSerializationExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyConstructor() {
|
void testEmptyConstructor() {
|
||||||
NacosSerializationException exception = new NacosSerializationException();
|
NacosSerializationException exception = new NacosSerializationException();
|
||||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
assertNull(exception.getMessage());
|
assertNull(exception.getMessage());
|
||||||
@ -33,7 +33,7 @@ public class NacosSerializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithSerializedClass() {
|
void testConstructorWithSerializedClass() {
|
||||||
NacosSerializationException exception = new NacosSerializationException(NacosSerializationExceptionTest.class);
|
NacosSerializationException exception = new NacosSerializationException(NacosSerializationExceptionTest.class);
|
||||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
assertEquals(String.format("errCode: 100, errMsg: Nacos serialize for class [%s] failed. ",
|
assertEquals(String.format("errCode: 100, errMsg: Nacos serialize for class [%s] failed. ",
|
||||||
@ -42,7 +42,7 @@ public class NacosSerializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithCause() {
|
void testConstructorWithCause() {
|
||||||
NacosSerializationException exception = new NacosSerializationException(new RuntimeException("test"));
|
NacosSerializationException exception = new NacosSerializationException(new RuntimeException("test"));
|
||||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
assertEquals("errCode: 100, errMsg: Nacos serialize failed. ", exception.getMessage());
|
assertEquals("errCode: 100, errMsg: Nacos serialize failed. ", exception.getMessage());
|
||||||
@ -50,7 +50,7 @@ public class NacosSerializationExceptionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithSerializedClassAndCause() {
|
void testConstructorWithSerializedClassAndCause() {
|
||||||
NacosSerializationException exception = new NacosSerializationException(NacosSerializationExceptionTest.class,
|
NacosSerializationException exception = new NacosSerializationException(NacosSerializationExceptionTest.class,
|
||||||
new RuntimeException("test"));
|
new RuntimeException("test"));
|
||||||
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
assertEquals(Constants.Exception.SERIALIZE_ERROR_CODE, exception.getErrCode());
|
||||||
|
@ -16,16 +16,17 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.model.v2;
|
package com.alibaba.nacos.api.model.v2;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class ErrorCodeTest {
|
class ErrorCodeTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCodeNotSame() {
|
void testCodeNotSame() {
|
||||||
Class<ErrorCode> errorCodeClass = ErrorCode.class;
|
Class<ErrorCode> errorCodeClass = ErrorCode.class;
|
||||||
|
|
||||||
ErrorCode[] errorCodes = errorCodeClass.getEnumConstants();
|
ErrorCode[] errorCodes = errorCodeClass.getEnumConstants();
|
||||||
|
@ -16,15 +16,15 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.model.v2;
|
package com.alibaba.nacos.api.model.v2;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class ResultTest {
|
class ResultTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccessEmptyResult() {
|
void testSuccessEmptyResult() {
|
||||||
Result<String> result = Result.success();
|
Result<String> result = Result.success();
|
||||||
assertNull(result.getData());
|
assertNull(result.getData());
|
||||||
assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode());
|
assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode());
|
||||||
@ -32,7 +32,7 @@ public class ResultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccessWithData() {
|
void testSuccessWithData() {
|
||||||
Result<String> result = Result.success("test");
|
Result<String> result = Result.success("test");
|
||||||
assertEquals("test", result.getData());
|
assertEquals("test", result.getData());
|
||||||
assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode());
|
assertEquals(ErrorCode.SUCCESS.getCode(), result.getCode());
|
||||||
@ -40,7 +40,7 @@ public class ResultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailureMessageResult() {
|
void testFailureMessageResult() {
|
||||||
Result<String> result = Result.failure("test");
|
Result<String> result = Result.failure("test");
|
||||||
assertNull(result.getData());
|
assertNull(result.getData());
|
||||||
assertEquals(ErrorCode.SERVER_ERROR.getCode(), result.getCode());
|
assertEquals(ErrorCode.SERVER_ERROR.getCode(), result.getCode());
|
||||||
@ -48,7 +48,7 @@ public class ResultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailureWithoutData() {
|
void testFailureWithoutData() {
|
||||||
Result<String> result = Result.failure(ErrorCode.DATA_ACCESS_ERROR);
|
Result<String> result = Result.failure(ErrorCode.DATA_ACCESS_ERROR);
|
||||||
assertNull(result.getData());
|
assertNull(result.getData());
|
||||||
assertEquals(ErrorCode.DATA_ACCESS_ERROR.getCode(), result.getCode());
|
assertEquals(ErrorCode.DATA_ACCESS_ERROR.getCode(), result.getCode());
|
||||||
@ -56,7 +56,7 @@ public class ResultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailureWithData() {
|
void testFailureWithData() {
|
||||||
Result<String> result = Result.failure(ErrorCode.DATA_ACCESS_ERROR, "error");
|
Result<String> result = Result.failure(ErrorCode.DATA_ACCESS_ERROR, "error");
|
||||||
assertEquals("error", result.getData());
|
assertEquals("error", result.getData());
|
||||||
assertEquals(ErrorCode.DATA_ACCESS_ERROR.getCode(), result.getCode());
|
assertEquals(ErrorCode.DATA_ACCESS_ERROR.getCode(), result.getCode());
|
||||||
@ -64,7 +64,7 @@ public class ResultTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString() {
|
void testToString() {
|
||||||
Result<String> result = Result.success("test");
|
Result<String> result = Result.success("test");
|
||||||
assertEquals("Result{errorCode=0, message='success', data=test}", result.toString());
|
assertEquals("Result{errorCode=0, message='success', data=test}", result.toString());
|
||||||
}
|
}
|
||||||
|
@ -16,15 +16,15 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.naming.ability;
|
package com.alibaba.nacos.api.naming.ability;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ClientNamingAbilityTest {
|
class ClientNamingAbilityTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAndSet() {
|
void testGetAndSet() {
|
||||||
ClientNamingAbility ability = new ClientNamingAbility();
|
ClientNamingAbility ability = new ClientNamingAbility();
|
||||||
assertFalse(ability.isSupportDeltaPush());
|
assertFalse(ability.isSupportDeltaPush());
|
||||||
assertFalse(ability.isSupportRemoteMetric());
|
assertFalse(ability.isSupportRemoteMetric());
|
||||||
|
@ -20,34 +20,33 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
public class ServerNamingAbilityTest {
|
class ServerNamingAbilityTest {
|
||||||
|
|
||||||
private static ObjectMapper jacksonMapper;
|
private static ObjectMapper jacksonMapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpClass() throws Exception {
|
static void setUpClass() throws Exception {
|
||||||
jacksonMapper = new ObjectMapper();
|
jacksonMapper = new ObjectMapper();
|
||||||
jacksonMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
jacksonMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
jacksonMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
jacksonMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserializeServerNamingAbilityForNonExistItem() throws JsonProcessingException {
|
void testDeserializeServerNamingAbilityForNonExistItem() throws JsonProcessingException {
|
||||||
String nonExistItemJson = "{\"exampleAbility\":false}";
|
String nonExistItemJson = "{\"exampleAbility\":false}";
|
||||||
ServerNamingAbility actual = jacksonMapper.readValue(nonExistItemJson, ServerNamingAbility.class);
|
ServerNamingAbility actual = jacksonMapper.readValue(nonExistItemJson, ServerNamingAbility.class);
|
||||||
assertFalse(actual.isSupportJraft());
|
assertFalse(actual.isSupportJraft());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquals() throws JsonProcessingException {
|
void testEquals() throws JsonProcessingException {
|
||||||
ServerNamingAbility expected = new ServerNamingAbility();
|
ServerNamingAbility expected = new ServerNamingAbility();
|
||||||
expected.setSupportJraft(true);
|
expected.setSupportJraft(true);
|
||||||
String serializeJson = jacksonMapper.writeValueAsString(expected);
|
String serializeJson = jacksonMapper.writeValueAsString(expected);
|
||||||
@ -60,19 +59,19 @@ public class ServerNamingAbilityTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualsForOneObject() {
|
void testEqualsForOneObject() {
|
||||||
ServerNamingAbility ability = new ServerNamingAbility();
|
ServerNamingAbility ability = new ServerNamingAbility();
|
||||||
assertTrue(ability.equals(ability));
|
assertEquals(ability, ability);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualsForOtherAbility() {
|
void testEqualsForOtherAbility() {
|
||||||
ServerNamingAbility ability = new ServerNamingAbility();
|
ServerNamingAbility ability = new ServerNamingAbility();
|
||||||
assertFalse(ability.equals(new ClientNamingAbility()));
|
assertNotEquals(ability, new ClientNamingAbility());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHashCode() throws JsonProcessingException {
|
void testHashCode() throws JsonProcessingException {
|
||||||
ServerNamingAbility expected = new ServerNamingAbility();
|
ServerNamingAbility expected = new ServerNamingAbility();
|
||||||
expected.setSupportJraft(true);
|
expected.setSupportJraft(true);
|
||||||
String serializeJson = jacksonMapper.writeValueAsString(expected);
|
String serializeJson = jacksonMapper.writeValueAsString(expected);
|
||||||
|
@ -16,26 +16,26 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.naming.listener;
|
package com.alibaba.nacos.api.naming.listener;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class NamingEventTest {
|
class NamingEventTest {
|
||||||
|
|
||||||
private MockNamingEventListener eventListener;
|
private MockNamingEventListener eventListener;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
eventListener = new MockNamingEventListener();
|
eventListener = new MockNamingEventListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNamingEventWithSimpleConstructor() {
|
void testNamingEventWithSimpleConstructor() {
|
||||||
NamingEvent event = new NamingEvent("serviceName", Collections.EMPTY_LIST);
|
NamingEvent event = new NamingEvent("serviceName", Collections.EMPTY_LIST);
|
||||||
assertEquals("serviceName", event.getServiceName());
|
assertEquals("serviceName", event.getServiceName());
|
||||||
assertNull(event.getGroupName());
|
assertNull(event.getGroupName());
|
||||||
@ -49,7 +49,7 @@ public class NamingEventTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNamingEventWithFullConstructor() {
|
void testNamingEventWithFullConstructor() {
|
||||||
NamingEvent event = new NamingEvent("serviceName", "group", "clusters", Collections.EMPTY_LIST);
|
NamingEvent event = new NamingEvent("serviceName", "group", "clusters", Collections.EMPTY_LIST);
|
||||||
assertEquals("serviceName", event.getServiceName());
|
assertEquals("serviceName", event.getServiceName());
|
||||||
assertEquals("group", event.getGroupName());
|
assertEquals("group", event.getGroupName());
|
||||||
|
@ -22,29 +22,29 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ClusterTest {
|
class ClusterTest {
|
||||||
|
|
||||||
private static ObjectMapper mapper;
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetAndGet() {
|
void testSetAndGet() {
|
||||||
Cluster actual = new Cluster();
|
Cluster actual = new Cluster();
|
||||||
assertNull(actual.getName());
|
assertNull(actual.getName());
|
||||||
assertNull(actual.getServiceName());
|
assertNull(actual.getServiceName());
|
||||||
@ -72,7 +72,7 @@ public class ClusterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJsonSerialize() throws JsonProcessingException {
|
void testJsonSerialize() throws JsonProcessingException {
|
||||||
Cluster actual = new Cluster("cluster");
|
Cluster actual = new Cluster("cluster");
|
||||||
actual.setServiceName("group@@service");
|
actual.setServiceName("group@@service");
|
||||||
actual.setHealthChecker(new Http());
|
actual.setHealthChecker(new Http());
|
||||||
@ -91,7 +91,7 @@ public class ClusterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJsonDeserialize() throws JsonProcessingException {
|
void testJsonDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"serviceName\":\"group@@service\",\"name\":\"cluster\","
|
String json = "{\"serviceName\":\"group@@service\",\"name\":\"cluster\","
|
||||||
+ "\"healthChecker\":{\"type\":\"HTTP\",\"path\":\"\",\"headers\":\"\",\"expectedResponseCode\":200},"
|
+ "\"healthChecker\":{\"type\":\"HTTP\",\"path\":\"\",\"headers\":\"\",\"expectedResponseCode\":200},"
|
||||||
+ "\"defaultPort\":81,\"defaultCheckPort\":82,\"useIPPort4Check\":false,\"metadata\":{\"a\":\"a\"}}";
|
+ "\"defaultPort\":81,\"defaultCheckPort\":82,\"useIPPort4Check\":false,\"metadata\":{\"a\":\"a\"}}";
|
||||||
|
@ -22,30 +22,31 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class InstanceTest {
|
class InstanceTest {
|
||||||
|
|
||||||
private static ObjectMapper mapper;
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetAndGet() {
|
void testSetAndGet() {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
assertNull(instance.getInstanceId());
|
assertNull(instance.getInstanceId());
|
||||||
assertNull(instance.getIp());
|
assertNull(instance.getIp());
|
||||||
@ -62,7 +63,7 @@ public class InstanceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJsonSerialize() throws JsonProcessingException {
|
void testJsonSerialize() throws JsonProcessingException {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
setInstance(instance);
|
setInstance(instance);
|
||||||
String actual = mapper.writeValueAsString(instance);
|
String actual = mapper.writeValueAsString(instance);
|
||||||
@ -82,7 +83,7 @@ public class InstanceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJsonDeserialize() throws JsonProcessingException {
|
void testJsonDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"instanceId\":\"id\",\"ip\":\"1.1.1.1\",\"port\":1000,\"weight\":100.0,\"healthy\":false,"
|
String json = "{\"instanceId\":\"id\",\"ip\":\"1.1.1.1\",\"port\":1000,\"weight\":100.0,\"healthy\":false,"
|
||||||
+ "\"enabled\":false,\"ephemeral\":false,\"clusterName\":\"cluster\","
|
+ "\"enabled\":false,\"ephemeral\":false,\"clusterName\":\"cluster\","
|
||||||
+ "\"serviceName\":\"group@@serviceName\",\"metadata\":{\"a\":\"b\"},\"instanceHeartBeatInterval\":5000,"
|
+ "\"serviceName\":\"group@@serviceName\",\"metadata\":{\"a\":\"b\"},\"instanceHeartBeatInterval\":5000,"
|
||||||
@ -92,21 +93,21 @@ public class InstanceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckClusterNameFormat() {
|
void testCheckClusterNameFormat() {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
instance.setClusterName("demo");
|
instance.setClusterName("demo");
|
||||||
assertEquals("demo", instance.getClusterName());
|
assertEquals("demo", instance.getClusterName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToInetAddr() {
|
void testToInetAddr() {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
setInstance(instance);
|
setInstance(instance);
|
||||||
assertEquals("1.1.1.1:1000", instance.toInetAddr());
|
assertEquals("1.1.1.1:1000", instance.toInetAddr());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testContainsMetadata() {
|
void testContainsMetadata() {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
assertFalse(instance.containsMetadata("a"));
|
assertFalse(instance.containsMetadata("a"));
|
||||||
instance.setMetadata(null);
|
instance.setMetadata(null);
|
||||||
@ -116,7 +117,7 @@ public class InstanceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetInstanceIdGenerator() {
|
void testGetInstanceIdGenerator() {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
assertEquals(Constants.DEFAULT_INSTANCE_ID_GENERATOR, instance.getInstanceIdGenerator());
|
assertEquals(Constants.DEFAULT_INSTANCE_ID_GENERATOR, instance.getInstanceIdGenerator());
|
||||||
instance.addMetadata(PreservedMetadataKeys.INSTANCE_ID_GENERATOR, "test");
|
instance.addMetadata(PreservedMetadataKeys.INSTANCE_ID_GENERATOR, "test");
|
||||||
@ -124,19 +125,19 @@ public class InstanceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquals() {
|
void testEquals() {
|
||||||
Instance actual = new Instance();
|
Instance actual = new Instance();
|
||||||
setInstance(actual);
|
setInstance(actual);
|
||||||
actual.setMetadata(new HashMap<>());
|
actual.setMetadata(new HashMap<>());
|
||||||
actual.addMetadata("a", "b");
|
actual.addMetadata("a", "b");
|
||||||
assertFalse(actual.equals(new Object()));
|
assertNotEquals(actual, new Object());
|
||||||
Instance expected = new Instance();
|
Instance expected = new Instance();
|
||||||
setInstance(expected);
|
setInstance(expected);
|
||||||
expected.setMetadata(new HashMap<>());
|
expected.setMetadata(new HashMap<>());
|
||||||
expected.addMetadata("a", "b");
|
expected.addMetadata("a", "b");
|
||||||
assertTrue(actual.equals(expected));
|
assertEquals(actual, expected);
|
||||||
expected.addMetadata("a", "c");
|
expected.addMetadata("a", "c");
|
||||||
assertFalse(actual.equals(expected));
|
assertNotEquals(actual, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setInstance(Instance instance) {
|
private void setInstance(Instance instance) {
|
||||||
|
@ -16,19 +16,19 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.naming.pojo;
|
package com.alibaba.nacos.api.naming.pojo;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class ListViewTest {
|
class ListViewTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString() {
|
void testToString() {
|
||||||
List<String> data = new LinkedList<>();
|
List<String> data = new LinkedList<>();
|
||||||
data.add("1");
|
data.add("1");
|
||||||
data.add("2");
|
data.add("2");
|
||||||
@ -41,7 +41,7 @@ public class ListViewTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetAndGet() {
|
void testSetAndGet() {
|
||||||
ListView<String> listView = new ListView<>();
|
ListView<String> listView = new ListView<>();
|
||||||
assertEquals(0, listView.getCount());
|
assertEquals(0, listView.getCount());
|
||||||
assertNull(listView.getData());
|
assertNull(listView.getData());
|
||||||
|
@ -20,8 +20,8 @@ import com.alibaba.nacos.api.utils.StringUtils;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
@ -30,25 +30,26 @@ import java.util.Collections;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServiceInfoTest {
|
class ServiceInfoTest {
|
||||||
|
|
||||||
private ObjectMapper mapper;
|
private ObjectMapper mapper;
|
||||||
|
|
||||||
private ServiceInfo serviceInfo;
|
private ServiceInfo serviceInfo;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
serviceInfo = new ServiceInfo("G@@testName", "testClusters");
|
serviceInfo = new ServiceInfo("G@@testName", "testClusters");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
String actual = mapper.writeValueAsString(serviceInfo);
|
String actual = mapper.writeValueAsString(serviceInfo);
|
||||||
assertTrue(actual.contains("\"name\":\"G@@testName\""));
|
assertTrue(actual.contains("\"name\":\"G@@testName\""));
|
||||||
assertTrue(actual.contains("\"clusters\":\"testClusters\""));
|
assertTrue(actual.contains("\"clusters\":\"testClusters\""));
|
||||||
@ -64,7 +65,7 @@ public class ServiceInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws IOException {
|
void testDeserialize() throws IOException {
|
||||||
String example = "{\"name\":\"G@@testName\",\"clusters\":\"testClusters\",\"cacheMillis\":1000,\"hosts\":[],"
|
String example = "{\"name\":\"G@@testName\",\"clusters\":\"testClusters\",\"cacheMillis\":1000,\"hosts\":[],"
|
||||||
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"valid\":true,\"groupName\":\"\"}";
|
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"valid\":true,\"groupName\":\"\"}";
|
||||||
ServiceInfo actual = mapper.readValue(example, ServiceInfo.class);
|
ServiceInfo actual = mapper.readValue(example, ServiceInfo.class);
|
||||||
@ -82,14 +83,14 @@ public class ServiceInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetKey() {
|
void testGetKey() {
|
||||||
String key = serviceInfo.getKey();
|
String key = serviceInfo.getKey();
|
||||||
assertEquals("G@@testName@@testClusters", key);
|
assertEquals("G@@testName@@testClusters", key);
|
||||||
assertEquals("G@@testName@@testClusters", serviceInfo.toString());
|
assertEquals("G@@testName@@testClusters", serviceInfo.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetKeyEncode() {
|
void testGetKeyEncode() {
|
||||||
String key = serviceInfo.getKeyEncoded();
|
String key = serviceInfo.getKeyEncoded();
|
||||||
String encodeName = null;
|
String encodeName = null;
|
||||||
try {
|
try {
|
||||||
@ -101,7 +102,7 @@ public class ServiceInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testServiceInfoConstructor() {
|
void testServiceInfoConstructor() {
|
||||||
String key1 = "group@@name";
|
String key1 = "group@@name";
|
||||||
String key2 = "group@@name@@c2";
|
String key2 = "group@@name@@c2";
|
||||||
ServiceInfo s1 = new ServiceInfo(key1);
|
ServiceInfo s1 = new ServiceInfo(key1);
|
||||||
@ -110,32 +111,34 @@ public class ServiceInfoTest {
|
|||||||
assertEquals(key2, s2.getKey());
|
assertEquals(key2, s2.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testServiceInfoConstructorWithError() {
|
void testServiceInfoConstructorWithError() {
|
||||||
String key1 = "name";
|
assertThrows(IllegalArgumentException.class, () -> {
|
||||||
ServiceInfo s1 = new ServiceInfo(key1);
|
String key1 = "name";
|
||||||
|
ServiceInfo s1 = new ServiceInfo(key1);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateForAllIps() {
|
void testValidateForAllIps() {
|
||||||
serviceInfo.setAllIPs(true);
|
serviceInfo.setAllIPs(true);
|
||||||
assertTrue(serviceInfo.validate());
|
assertTrue(serviceInfo.validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateForNullHosts() {
|
void testValidateForNullHosts() {
|
||||||
serviceInfo.setHosts(null);
|
serviceInfo.setHosts(null);
|
||||||
assertFalse(serviceInfo.validate());
|
assertFalse(serviceInfo.validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateForEmptyHosts() {
|
void testValidateForEmptyHosts() {
|
||||||
serviceInfo.setHosts(Collections.EMPTY_LIST);
|
serviceInfo.setHosts(Collections.EMPTY_LIST);
|
||||||
assertFalse(serviceInfo.validate());
|
assertFalse(serviceInfo.validate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateForUnhealthyHosts() {
|
void testValidateForUnhealthyHosts() {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
instance.setHealthy(false);
|
instance.setHealthy(false);
|
||||||
serviceInfo.addHost(instance);
|
serviceInfo.addHost(instance);
|
||||||
@ -143,7 +146,7 @@ public class ServiceInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testValidateForBothUnhealthyAndHealthyHosts() {
|
void testValidateForBothUnhealthyAndHealthyHosts() {
|
||||||
List<Instance> instanceList = new LinkedList<>();
|
List<Instance> instanceList = new LinkedList<>();
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
instanceList.add(instance);
|
instanceList.add(instance);
|
||||||
@ -155,7 +158,7 @@ public class ServiceInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFromKey() {
|
void testFromKey() {
|
||||||
String key1 = "group@@name";
|
String key1 = "group@@name";
|
||||||
String key2 = "group@@name@@c2";
|
String key2 = "group@@name@@c2";
|
||||||
ServiceInfo s1 = ServiceInfo.fromKey(key1);
|
ServiceInfo s1 = ServiceInfo.fromKey(key1);
|
||||||
@ -165,7 +168,7 @@ public class ServiceInfoTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetAndGet() throws JsonProcessingException {
|
void testSetAndGet() throws JsonProcessingException {
|
||||||
serviceInfo.setReachProtectionThreshold(true);
|
serviceInfo.setReachProtectionThreshold(true);
|
||||||
serviceInfo.setJsonFromServer(mapper.writeValueAsString(serviceInfo));
|
serviceInfo.setJsonFromServer(mapper.writeValueAsString(serviceInfo));
|
||||||
ServiceInfo actual = mapper.readValue(serviceInfo.getJsonFromServer(), ServiceInfo.class);
|
ServiceInfo actual = mapper.readValue(serviceInfo.getJsonFromServer(), ServiceInfo.class);
|
||||||
|
@ -16,19 +16,19 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.naming.pojo;
|
package com.alibaba.nacos.api.naming.pojo;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServiceTest {
|
class ServiceTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetAndGet() {
|
void testSetAndGet() {
|
||||||
Service service = new Service();
|
Service service = new Service();
|
||||||
assertNull(service.getName());
|
assertNull(service.getName());
|
||||||
assertNull(service.getAppName());
|
assertNull(service.getAppName());
|
||||||
@ -51,12 +51,13 @@ public class ServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString() {
|
void testToString() {
|
||||||
Service service = new Service("service");
|
Service service = new Service("service");
|
||||||
service.setGroupName("group");
|
service.setGroupName("group");
|
||||||
service.setAppName("app");
|
service.setAppName("app");
|
||||||
service.setProtectThreshold(1.0f);
|
service.setProtectThreshold(1.0f);
|
||||||
service.setMetadata(Collections.singletonMap("a", "b"));
|
service.setMetadata(Collections.singletonMap("a", "b"));
|
||||||
assertEquals("Service{name='service', protectThreshold=1.0, appName='app', groupName='group', metadata={a=b}}", service.toString());
|
assertEquals("Service{name='service', protectThreshold=1.0, appName='app', groupName='group', metadata={a=b}}",
|
||||||
|
service.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,18 +17,18 @@
|
|||||||
package com.alibaba.nacos.api.naming.pojo.builder;
|
package com.alibaba.nacos.api.naming.pojo.builder;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class InstanceBuilderTest {
|
class InstanceBuilderTest {
|
||||||
|
|
||||||
private static final String SERVICE_NAME = "testService";
|
private static final String SERVICE_NAME = "testService";
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ public class InstanceBuilderTest {
|
|||||||
private static final String META_VALUE = "value";
|
private static final String META_VALUE = "value";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildFullInstance() {
|
void testBuildFullInstance() {
|
||||||
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
||||||
Instance actual = builder.setServiceName(SERVICE_NAME).setClusterName(CLUSTER_NAME).setInstanceId(INSTANCE_ID)
|
Instance actual = builder.setServiceName(SERVICE_NAME).setClusterName(CLUSTER_NAME).setInstanceId(INSTANCE_ID)
|
||||||
.setIp(IP).setPort(PORT).setWeight(WEIGHT).setHealthy(HEALTHY).setEnabled(ENABLED)
|
.setIp(IP).setPort(PORT).setWeight(WEIGHT).setHealthy(HEALTHY).setEnabled(ENABLED)
|
||||||
@ -72,7 +72,7 @@ public class InstanceBuilderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildInstanceWithoutNewMetadata() {
|
void testBuildInstanceWithoutNewMetadata() {
|
||||||
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
||||||
Map<String, String> metadata = new HashMap<>();
|
Map<String, String> metadata = new HashMap<>();
|
||||||
metadata.put("test", "test");
|
metadata.put("test", "test");
|
||||||
@ -90,7 +90,7 @@ public class InstanceBuilderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildEmptyInstance() {
|
void testBuildEmptyInstance() {
|
||||||
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
InstanceBuilder builder = InstanceBuilder.newBuilder();
|
||||||
Instance actual = builder.build();
|
Instance actual = builder.build();
|
||||||
assertNull(actual.getServiceName());
|
assertNull(actual.getServiceName());
|
||||||
|
@ -20,26 +20,26 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.jsontype.NamedType;
|
import com.fasterxml.jackson.databind.jsontype.NamedType;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class AbstractHealthCheckerTest {
|
class AbstractHealthCheckerTest {
|
||||||
|
|
||||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
objectMapper.registerSubtypes(new NamedType(TestChecker.class, TestChecker.TYPE));
|
objectMapper.registerSubtypes(new NamedType(TestChecker.class, TestChecker.TYPE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
TestChecker testChecker = new TestChecker();
|
TestChecker testChecker = new TestChecker();
|
||||||
testChecker.setTestValue("");
|
testChecker.setTestValue("");
|
||||||
String actual = objectMapper.writeValueAsString(testChecker);
|
String actual = objectMapper.writeValueAsString(testChecker);
|
||||||
@ -48,7 +48,7 @@ public class AbstractHealthCheckerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws IOException {
|
void testDeserialize() throws IOException {
|
||||||
String testChecker = "{\"type\":\"TEST\",\"testValue\":\"\"}";
|
String testChecker = "{\"type\":\"TEST\",\"testValue\":\"\"}";
|
||||||
TestChecker actual = objectMapper.readValue(testChecker, TestChecker.class);
|
TestChecker actual = objectMapper.readValue(testChecker, TestChecker.class);
|
||||||
assertEquals("", actual.getTestValue());
|
assertEquals("", actual.getTestValue());
|
||||||
@ -56,7 +56,7 @@ public class AbstractHealthCheckerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClone() throws CloneNotSupportedException {
|
void testClone() throws CloneNotSupportedException {
|
||||||
AbstractHealthChecker none = new AbstractHealthChecker.None().clone();
|
AbstractHealthChecker none = new AbstractHealthChecker.None().clone();
|
||||||
assertEquals(AbstractHealthChecker.None.class, none.getClass());
|
assertEquals(AbstractHealthChecker.None.class, none.getClass());
|
||||||
}
|
}
|
||||||
|
@ -19,17 +19,17 @@ package com.alibaba.nacos.api.naming.pojo.healthcheck;
|
|||||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http;
|
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Http;
|
||||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Mysql;
|
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Mysql;
|
||||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
|
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
public class HealthCheckTypeTest {
|
class HealthCheckTypeTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOfHealthCheckerClassForBuildInType() {
|
void testOfHealthCheckerClassForBuildInType() {
|
||||||
assertEquals(Tcp.class, HealthCheckType.ofHealthCheckerClass("TCP"));
|
assertEquals(Tcp.class, HealthCheckType.ofHealthCheckerClass("TCP"));
|
||||||
assertEquals(Http.class, HealthCheckType.ofHealthCheckerClass("HTTP"));
|
assertEquals(Http.class, HealthCheckType.ofHealthCheckerClass("HTTP"));
|
||||||
assertEquals(Mysql.class, HealthCheckType.ofHealthCheckerClass("MYSQL"));
|
assertEquals(Mysql.class, HealthCheckType.ofHealthCheckerClass("MYSQL"));
|
||||||
@ -37,18 +37,18 @@ public class HealthCheckTypeTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOfHealthCheckerClassForExtendType() {
|
void testOfHealthCheckerClassForExtendType() {
|
||||||
HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class);
|
HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class);
|
||||||
assertEquals(TestChecker.class, HealthCheckType.ofHealthCheckerClass(TestChecker.TYPE));
|
assertEquals(TestChecker.class, HealthCheckType.ofHealthCheckerClass(TestChecker.TYPE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOfHealthCheckerClassForNonExistType() {
|
void testOfHealthCheckerClassForNonExistType() {
|
||||||
assertNull(HealthCheckType.ofHealthCheckerClass("non-exist"));
|
assertNull(HealthCheckType.ofHealthCheckerClass("non-exist"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetLoadedHealthCheckerClasses() {
|
void testGetLoadedHealthCheckerClasses() {
|
||||||
HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class);
|
HealthCheckType.registerHealthChecker(TestChecker.TYPE, TestChecker.class);
|
||||||
List<Class<? extends AbstractHealthChecker>> actual = HealthCheckType.getLoadedHealthCheckerClasses();
|
List<Class<? extends AbstractHealthChecker>> actual = HealthCheckType.getLoadedHealthCheckerClasses();
|
||||||
assertEquals(5, actual.size());
|
assertEquals(5, actual.size());
|
||||||
|
@ -19,75 +19,80 @@ package com.alibaba.nacos.api.naming.pojo.healthcheck;
|
|||||||
import com.alibaba.nacos.api.exception.runtime.NacosDeserializationException;
|
import com.alibaba.nacos.api.exception.runtime.NacosDeserializationException;
|
||||||
import com.alibaba.nacos.api.exception.runtime.NacosSerializationException;
|
import com.alibaba.nacos.api.exception.runtime.NacosSerializationException;
|
||||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
|
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class HealthCheckerFactoryTest {
|
class HealthCheckerFactoryTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void beforeClass() {
|
static void beforeClass() {
|
||||||
HealthCheckerFactory.registerSubType(new TestChecker());
|
HealthCheckerFactory.registerSubType(new TestChecker());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() {
|
void testSerialize() {
|
||||||
Tcp tcp = new Tcp();
|
Tcp tcp = new Tcp();
|
||||||
String actual = HealthCheckerFactory.serialize(tcp);
|
String actual = HealthCheckerFactory.serialize(tcp);
|
||||||
assertTrue(actual.contains("\"type\":\"TCP\""));
|
assertTrue(actual.contains("\"type\":\"TCP\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerializeExtend() {
|
void testSerializeExtend() {
|
||||||
TestChecker testChecker = new TestChecker();
|
TestChecker testChecker = new TestChecker();
|
||||||
String actual = HealthCheckerFactory.serialize(testChecker);
|
String actual = HealthCheckerFactory.serialize(testChecker);
|
||||||
assertTrue(actual.contains("\"type\":\"TEST\""));
|
assertTrue(actual.contains("\"type\":\"TEST\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() {
|
void testDeserialize() {
|
||||||
String tcpString = "{\"type\":\"TCP\"}";
|
String tcpString = "{\"type\":\"TCP\"}";
|
||||||
AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString);
|
AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString);
|
||||||
assertEquals(Tcp.class, actual.getClass());
|
assertEquals(Tcp.class, actual.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserializeExtend() {
|
void testDeserializeExtend() {
|
||||||
String tcpString = "{\"type\":\"TEST\",\"testValue\":null}";
|
String tcpString = "{\"type\":\"TEST\",\"testValue\":null}";
|
||||||
AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString);
|
AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString);
|
||||||
assertEquals(TestChecker.class, actual.getClass());
|
assertEquals(TestChecker.class, actual.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerializeNoRegister() {
|
void testSerializeNoRegister() {
|
||||||
NoRegisterHealthChecker noRegister = new NoRegisterHealthChecker();
|
NoRegisterHealthChecker noRegister = new NoRegisterHealthChecker();
|
||||||
assertFalse(HealthCheckerFactory.serialize(noRegister).contains("no register"));
|
assertFalse(HealthCheckerFactory.serialize(noRegister).contains("no register"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserializeNoRegister() {
|
void testDeserializeNoRegister() {
|
||||||
String tcpString = "{\"type\":\"no register\",\"testValue\":null}";
|
String tcpString = "{\"type\":\"no register\",\"testValue\":null}";
|
||||||
AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString);
|
AbstractHealthChecker actual = HealthCheckerFactory.deserialize(tcpString);
|
||||||
assertEquals(AbstractHealthChecker.None.class, actual.getClass());
|
assertEquals(AbstractHealthChecker.None.class, actual.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NacosSerializationException.class)
|
@Test
|
||||||
public void testSerializeFailure() {
|
void testSerializeFailure() {
|
||||||
SelfDependHealthChecker selfDependHealthChecker = new SelfDependHealthChecker();
|
assertThrows(NacosSerializationException.class, () -> {
|
||||||
System.out.println(HealthCheckerFactory.serialize(selfDependHealthChecker));
|
SelfDependHealthChecker selfDependHealthChecker = new SelfDependHealthChecker();
|
||||||
}
|
System.out.println(HealthCheckerFactory.serialize(selfDependHealthChecker));
|
||||||
|
});
|
||||||
@Test(expected = NacosDeserializationException.class)
|
|
||||||
public void testDeserializeFailure() {
|
|
||||||
String errorString = "{\"type\"=\"TCP\"}";
|
|
||||||
System.out.println(HealthCheckerFactory.deserialize(errorString));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateNoneHealthChecker() {
|
void testDeserializeFailure() {
|
||||||
|
assertThrows(NacosDeserializationException.class, () -> {
|
||||||
|
String errorString = "{\"type\"=\"TCP\"}";
|
||||||
|
System.out.println(HealthCheckerFactory.deserialize(errorString));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testCreateNoneHealthChecker() {
|
||||||
assertEquals(AbstractHealthChecker.None.class, HealthCheckerFactory.createNoneHealthChecker().getClass());
|
assertEquals(AbstractHealthChecker.None.class, HealthCheckerFactory.createNoneHealthChecker().getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,10 @@ public class TestChecker extends AbstractHealthChecker {
|
|||||||
|
|
||||||
private String testValue;
|
private String testValue;
|
||||||
|
|
||||||
|
public TestChecker() {
|
||||||
|
super(TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
public String getTestValue() {
|
public String getTestValue() {
|
||||||
return testValue;
|
return testValue;
|
||||||
}
|
}
|
||||||
@ -36,10 +40,6 @@ public class TestChecker extends AbstractHealthChecker {
|
|||||||
this.testValue = testValue;
|
this.testValue = testValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestChecker() {
|
|
||||||
super(TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AbstractHealthChecker clone() throws CloneNotSupportedException {
|
public AbstractHealthChecker clone() throws CloneNotSupportedException {
|
||||||
return null;
|
return null;
|
||||||
|
@ -18,36 +18,37 @@ package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class HttpTest {
|
class HttpTest {
|
||||||
|
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
private Http http;
|
private Http http;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
objectMapper = new ObjectMapper();
|
objectMapper = new ObjectMapper();
|
||||||
http = new Http();
|
http = new Http();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetExpectedResponseCodeWithEmpty() {
|
void testGetExpectedResponseCodeWithEmpty() {
|
||||||
http.setHeaders("");
|
http.setHeaders("");
|
||||||
assertTrue(http.getCustomHeaders().isEmpty());
|
assertTrue(http.getCustomHeaders().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetExpectedResponseCodeWithoutEmpty() {
|
void testGetExpectedResponseCodeWithoutEmpty() {
|
||||||
http.setHeaders("x:a|y:");
|
http.setHeaders("x:a|y:");
|
||||||
Map<String, String> actual = http.getCustomHeaders();
|
Map<String, String> actual = http.getCustomHeaders();
|
||||||
assertFalse(actual.isEmpty());
|
assertFalse(actual.isEmpty());
|
||||||
@ -56,7 +57,7 @@ public class HttpTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
http.setHeaders("x:a|y:");
|
http.setHeaders("x:a|y:");
|
||||||
http.setPath("/x");
|
http.setPath("/x");
|
||||||
String actual = objectMapper.writeValueAsString(http);
|
String actual = objectMapper.writeValueAsString(http);
|
||||||
@ -67,7 +68,7 @@ public class HttpTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws IOException {
|
void testDeserialize() throws IOException {
|
||||||
String testChecker = "{\"type\":\"HTTP\",\"path\":\"/x\",\"headers\":\"x:a|y:\",\"expectedResponseCode\":200}";
|
String testChecker = "{\"type\":\"HTTP\",\"path\":\"/x\",\"headers\":\"x:a|y:\",\"expectedResponseCode\":200}";
|
||||||
Http actual = objectMapper.readValue(testChecker, Http.class);
|
Http actual = objectMapper.readValue(testChecker, Http.class);
|
||||||
assertEquals("x:a|y:", actual.getHeaders());
|
assertEquals("x:a|y:", actual.getHeaders());
|
||||||
@ -78,23 +79,23 @@ public class HttpTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClone() throws CloneNotSupportedException {
|
void testClone() throws CloneNotSupportedException {
|
||||||
Http cloned = http.clone();
|
Http cloned = http.clone();
|
||||||
assertEquals(http.hashCode(), cloned.hashCode());
|
assertEquals(http.hashCode(), cloned.hashCode());
|
||||||
assertTrue(http.equals(cloned));
|
assertEquals(http, cloned);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotEquals() throws CloneNotSupportedException {
|
void testNotEquals() throws CloneNotSupportedException {
|
||||||
assertFalse(http.equals(new Tcp()));
|
assertNotEquals(http, new Tcp());
|
||||||
Http cloned = http.clone();
|
Http cloned = http.clone();
|
||||||
cloned.setPath("aaa");
|
cloned.setPath("aaa");
|
||||||
assertFalse(http.equals(cloned));
|
assertNotEquals(http, cloned);
|
||||||
cloned = http.clone();
|
cloned = http.clone();
|
||||||
cloned.setHeaders("aaa");
|
cloned.setHeaders("aaa");
|
||||||
assertFalse(http.equals(cloned));
|
assertNotEquals(http, cloned);
|
||||||
cloned = http.clone();
|
cloned = http.clone();
|
||||||
cloned.setExpectedResponseCode(500);
|
cloned.setExpectedResponseCode(500);
|
||||||
assertFalse(http.equals(cloned));
|
assertNotEquals(http, cloned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,23 +18,23 @@ package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class MysqlTest {
|
class MysqlTest {
|
||||||
|
|
||||||
private ObjectMapper objectMapper;
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
private Mysql mysql;
|
private Mysql mysql;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
mysql = new Mysql();
|
mysql = new Mysql();
|
||||||
mysql.setUser("user");
|
mysql.setUser("user");
|
||||||
mysql.setPwd("pwd");
|
mysql.setPwd("pwd");
|
||||||
@ -43,7 +43,7 @@ public class MysqlTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
String actual = objectMapper.writeValueAsString(mysql);
|
String actual = objectMapper.writeValueAsString(mysql);
|
||||||
assertTrue(actual.contains("\"user\":\"user\""));
|
assertTrue(actual.contains("\"user\":\"user\""));
|
||||||
assertTrue(actual.contains("\"type\":\"MYSQL\""));
|
assertTrue(actual.contains("\"type\":\"MYSQL\""));
|
||||||
@ -52,7 +52,7 @@ public class MysqlTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws IOException {
|
void testDeserialize() throws IOException {
|
||||||
String testChecker = "{\"type\":\"MYSQL\",\"user\":\"user\",\"pwd\":\"pwd\",\"cmd\":\"cmd\"}";
|
String testChecker = "{\"type\":\"MYSQL\",\"user\":\"user\",\"pwd\":\"pwd\",\"cmd\":\"cmd\"}";
|
||||||
Mysql actual = objectMapper.readValue(testChecker, Mysql.class);
|
Mysql actual = objectMapper.readValue(testChecker, Mysql.class);
|
||||||
assertEquals("cmd", actual.getCmd());
|
assertEquals("cmd", actual.getCmd());
|
||||||
@ -62,23 +62,23 @@ public class MysqlTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClone() throws CloneNotSupportedException {
|
void testClone() throws CloneNotSupportedException {
|
||||||
Mysql cloned = mysql.clone();
|
Mysql cloned = mysql.clone();
|
||||||
assertEquals(mysql.hashCode(), cloned.hashCode());
|
assertEquals(mysql.hashCode(), cloned.hashCode());
|
||||||
assertTrue(mysql.equals(cloned));
|
assertEquals(mysql, cloned);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotEquals() throws CloneNotSupportedException {
|
void testNotEquals() throws CloneNotSupportedException {
|
||||||
assertFalse(mysql.equals(new Tcp()));
|
assertNotEquals(mysql, new Tcp());
|
||||||
Mysql cloned = mysql.clone();
|
Mysql cloned = mysql.clone();
|
||||||
cloned.setUser("aaa");
|
cloned.setUser("aaa");
|
||||||
assertFalse(mysql.equals(cloned));
|
assertNotEquals(mysql, cloned);
|
||||||
cloned = mysql.clone();
|
cloned = mysql.clone();
|
||||||
cloned.setPwd("aaa");
|
cloned.setPwd("aaa");
|
||||||
assertFalse(mysql.equals(cloned));
|
assertNotEquals(mysql, cloned);
|
||||||
cloned = mysql.clone();
|
cloned = mysql.clone();
|
||||||
cloned.setCmd("aaa");
|
cloned.setCmd("aaa");
|
||||||
assertFalse(mysql.equals(cloned));
|
assertNotEquals(mysql, cloned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,18 +16,17 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
|
package com.alibaba.nacos.api.naming.pojo.healthcheck.impl;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
public class TcpTest {
|
class TcpTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClone() throws CloneNotSupportedException {
|
void testClone() throws CloneNotSupportedException {
|
||||||
Tcp original = new Tcp();
|
Tcp original = new Tcp();
|
||||||
Tcp cloned = original.clone();
|
Tcp cloned = original.clone();
|
||||||
assertEquals(original.hashCode(), cloned.hashCode());
|
assertEquals(original.hashCode(), cloned.hashCode());
|
||||||
assertTrue(original.equals(cloned));
|
assertEquals(original, cloned);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,11 +19,11 @@ package com.alibaba.nacos.api.naming.remote.request;
|
|||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
|
||||||
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
|
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public abstract class BasedNamingRequestTest {
|
public abstract class BasedNamingRequestTest {
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ public abstract class BasedNamingRequestTest {
|
|||||||
|
|
||||||
protected static ObjectMapper mapper;
|
protected static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
|
@ -19,17 +19,17 @@ package com.alibaba.nacos.api.naming.remote.request;
|
|||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
|
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class BatchInstanceRequestTest extends BasedNamingRequestTest {
|
class BatchInstanceRequestTest extends BasedNamingRequestTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
BatchInstanceRequest request = new BatchInstanceRequest(NAMESPACE, SERVICE, GROUP,
|
BatchInstanceRequest request = new BatchInstanceRequest(NAMESPACE, SERVICE, GROUP,
|
||||||
NamingRemoteConstants.BATCH_REGISTER_INSTANCE, Collections.singletonList(new Instance()));
|
NamingRemoteConstants.BATCH_REGISTER_INSTANCE, Collections.singletonList(new Instance()));
|
||||||
String json = mapper.writeValueAsString(request);
|
String json = mapper.writeValueAsString(request);
|
||||||
@ -39,7 +39,7 @@ public class BatchInstanceRequestTest extends BasedNamingRequestTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
||||||
+ "\"type\":\"batchRegisterInstance\",\"instances\":[{\"port\":0,\"weight\":1.0,\"healthy\":true,"
|
+ "\"type\":\"batchRegisterInstance\",\"instances\":[{\"port\":0,\"weight\":1.0,\"healthy\":true,"
|
||||||
+ "\"enabled\":true,\"ephemeral\":true,\"metadata\":{},\"instanceIdGenerator\":\"simple\","
|
+ "\"enabled\":true,\"ephemeral\":true,\"metadata\":{},\"instanceIdGenerator\":\"simple\","
|
||||||
|
@ -19,15 +19,15 @@ package com.alibaba.nacos.api.naming.remote.request;
|
|||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
|
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class InstanceRequestTest extends BasedNamingRequestTest {
|
class InstanceRequestTest extends BasedNamingRequestTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
InstanceRequest request = new InstanceRequest(NAMESPACE, SERVICE, GROUP,
|
InstanceRequest request = new InstanceRequest(NAMESPACE, SERVICE, GROUP,
|
||||||
NamingRemoteConstants.REGISTER_INSTANCE, new Instance());
|
NamingRemoteConstants.REGISTER_INSTANCE, new Instance());
|
||||||
String json = mapper.writeValueAsString(request);
|
String json = mapper.writeValueAsString(request);
|
||||||
@ -37,7 +37,7 @@ public class InstanceRequestTest extends BasedNamingRequestTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
||||||
+ "\"type\":\"deregisterInstance\",\"instance\":{\"port\":0,\"weight\":1.0,\"healthy\":true,"
|
+ "\"type\":\"deregisterInstance\",\"instance\":{\"port\":0,\"weight\":1.0,\"healthy\":true,"
|
||||||
+ "\"enabled\":true,\"ephemeral\":true,\"metadata\":{},\"instanceIdGenerator\":\"simple\","
|
+ "\"enabled\":true,\"ephemeral\":true,\"metadata\":{},\"instanceIdGenerator\":\"simple\","
|
||||||
|
@ -21,14 +21,14 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
|
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class NotifySubscriberRequestTest {
|
class NotifySubscriberRequestTest {
|
||||||
|
|
||||||
private static final String SERVICE = "service";
|
private static final String SERVICE = "service";
|
||||||
|
|
||||||
@ -38,15 +38,15 @@ public class NotifySubscriberRequestTest {
|
|||||||
|
|
||||||
private static ObjectMapper mapper;
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
ServiceInfo serviceInfo = new ServiceInfo(GROUP + "@@" + SERVICE);
|
ServiceInfo serviceInfo = new ServiceInfo(GROUP + "@@" + SERVICE);
|
||||||
NotifySubscriberRequest request = NotifySubscriberRequest.buildNotifySubscriberRequest(serviceInfo);
|
NotifySubscriberRequest request = NotifySubscriberRequest.buildNotifySubscriberRequest(serviceInfo);
|
||||||
request.setServiceName(SERVICE);
|
request.setServiceName(SERVICE);
|
||||||
@ -58,7 +58,7 @@ public class NotifySubscriberRequestTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
||||||
+ "\"serviceInfo\":{\"name\":\"service\",\"groupName\":\"group\",\"cacheMillis\":1000,\"hosts\":[],"
|
+ "\"serviceInfo\":{\"name\":\"service\",\"groupName\":\"group\",\"cacheMillis\":1000,\"hosts\":[],"
|
||||||
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"reachProtectionThreshold\":false,"
|
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"reachProtectionThreshold\":false,"
|
||||||
|
@ -19,15 +19,15 @@ package com.alibaba.nacos.api.naming.remote.request;
|
|||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
|
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class PersistentInstanceRequestTest extends BasedNamingRequestTest {
|
class PersistentInstanceRequestTest extends BasedNamingRequestTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
PersistentInstanceRequest request = new PersistentInstanceRequest(NAMESPACE, SERVICE, GROUP,
|
PersistentInstanceRequest request = new PersistentInstanceRequest(NAMESPACE, SERVICE, GROUP,
|
||||||
NamingRemoteConstants.REGISTER_INSTANCE, new Instance());
|
NamingRemoteConstants.REGISTER_INSTANCE, new Instance());
|
||||||
String json = mapper.writeValueAsString(request);
|
String json = mapper.writeValueAsString(request);
|
||||||
@ -37,7 +37,7 @@ public class PersistentInstanceRequestTest extends BasedNamingRequestTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
||||||
+ "\"type\":\"deregisterInstance\",\"instance\":{\"port\":0,\"weight\":1.0,\"healthy\":true,"
|
+ "\"type\":\"deregisterInstance\",\"instance\":{\"port\":0,\"weight\":1.0,\"healthy\":true,"
|
||||||
+ "\"enabled\":true,\"ephemeral\":true,\"metadata\":{},\"instanceIdGenerator\":\"simple\","
|
+ "\"enabled\":true,\"ephemeral\":true,\"metadata\":{},\"instanceIdGenerator\":\"simple\","
|
||||||
|
@ -17,16 +17,16 @@
|
|||||||
package com.alibaba.nacos.api.naming.remote.request;
|
package com.alibaba.nacos.api.naming.remote.request;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
|
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServiceListRequestTest extends BasedNamingRequestTest {
|
class ServiceListRequestTest extends BasedNamingRequestTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
ServiceListRequest request = new ServiceListRequest(NAMESPACE, GROUP, 1, 10);
|
ServiceListRequest request = new ServiceListRequest(NAMESPACE, GROUP, 1, 10);
|
||||||
request.setSelector("label");
|
request.setSelector("label");
|
||||||
String json = mapper.writeValueAsString(request);
|
String json = mapper.writeValueAsString(request);
|
||||||
@ -39,7 +39,7 @@ public class ServiceListRequestTest extends BasedNamingRequestTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"\",\"groupName\":\"group\","
|
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"\",\"groupName\":\"group\","
|
||||||
+ "\"pageNo\":1,\"pageSize\":10,\"selector\":\"label\",\"module\":\"naming\"}";
|
+ "\"pageNo\":1,\"pageSize\":10,\"selector\":\"label\",\"module\":\"naming\"}";
|
||||||
ServiceListRequest actual = mapper.readValue(json, ServiceListRequest.class);
|
ServiceListRequest actual = mapper.readValue(json, ServiceListRequest.class);
|
||||||
|
@ -18,15 +18,15 @@ package com.alibaba.nacos.api.naming.remote.request;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.common.Constants;
|
import com.alibaba.nacos.api.common.Constants;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServiceQueryRequestTest extends BasedNamingRequestTest {
|
class ServiceQueryRequestTest extends BasedNamingRequestTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
ServiceQueryRequest request = new ServiceQueryRequest(NAMESPACE, SERVICE, GROUP);
|
ServiceQueryRequest request = new ServiceQueryRequest(NAMESPACE, SERVICE, GROUP);
|
||||||
request.setCluster(Constants.DEFAULT_CLUSTER_NAME);
|
request.setCluster(Constants.DEFAULT_CLUSTER_NAME);
|
||||||
String json = mapper.writeValueAsString(request);
|
String json = mapper.writeValueAsString(request);
|
||||||
@ -37,7 +37,7 @@ public class ServiceQueryRequestTest extends BasedNamingRequestTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
||||||
+ "\"cluster\":\"DEFAULT\",\"healthyOnly\":true,\"udpPort\":0,\"module\":\"naming\"}";
|
+ "\"cluster\":\"DEFAULT\",\"healthyOnly\":true,\"udpPort\":0,\"module\":\"naming\"}";
|
||||||
ServiceQueryRequest actual = mapper.readValue(json, ServiceQueryRequest.class);
|
ServiceQueryRequest actual = mapper.readValue(json, ServiceQueryRequest.class);
|
||||||
|
@ -17,16 +17,16 @@
|
|||||||
package com.alibaba.nacos.api.naming.remote.request;
|
package com.alibaba.nacos.api.naming.remote.request;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class SubscribeServiceRequestTest extends BasedNamingRequestTest {
|
class SubscribeServiceRequestTest extends BasedNamingRequestTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
SubscribeServiceRequest request = new SubscribeServiceRequest(NAMESPACE, GROUP, SERVICE, "", true);
|
SubscribeServiceRequest request = new SubscribeServiceRequest(NAMESPACE, GROUP, SERVICE, "", true);
|
||||||
String json = mapper.writeValueAsString(request);
|
String json = mapper.writeValueAsString(request);
|
||||||
checkSerializeBasedInfo(json);
|
checkSerializeBasedInfo(json);
|
||||||
@ -35,7 +35,7 @@ public class SubscribeServiceRequestTest extends BasedNamingRequestTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
String json = "{\"headers\":{},\"namespace\":\"namespace\",\"serviceName\":\"service\",\"groupName\":\"group\","
|
||||||
+ "\"subscribe\":false,\"clusters\":\"aa,bb\",\"module\":\"naming\"}";
|
+ "\"subscribe\":false,\"clusters\":\"aa,bb\",\"module\":\"naming\"}";
|
||||||
SubscribeServiceRequest actual = mapper.readValue(json, SubscribeServiceRequest.class);
|
SubscribeServiceRequest actual = mapper.readValue(json, SubscribeServiceRequest.class);
|
||||||
|
@ -21,32 +21,32 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class BatchInstanceResponseTest {
|
class BatchInstanceResponseTest {
|
||||||
|
|
||||||
protected static ObjectMapper mapper;
|
protected static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
BatchInstanceResponse response = new BatchInstanceResponse(NamingRemoteConstants.REGISTER_INSTANCE);
|
BatchInstanceResponse response = new BatchInstanceResponse(NamingRemoteConstants.REGISTER_INSTANCE);
|
||||||
String json = mapper.writeValueAsString(response);
|
String json = mapper.writeValueAsString(response);
|
||||||
assertTrue(json.contains("\"type\":\"" + NamingRemoteConstants.REGISTER_INSTANCE + "\""));
|
assertTrue(json.contains("\"type\":\"" + NamingRemoteConstants.REGISTER_INSTANCE + "\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"type\":\"registerInstance\",\"success\":true}";
|
String json = "{\"resultCode\":200,\"errorCode\":0,\"type\":\"registerInstance\",\"success\":true}";
|
||||||
BatchInstanceResponse response = mapper.readValue(json, BatchInstanceResponse.class);
|
BatchInstanceResponse response = mapper.readValue(json, BatchInstanceResponse.class);
|
||||||
assertEquals(NamingRemoteConstants.REGISTER_INSTANCE, response.getType());
|
assertEquals(NamingRemoteConstants.REGISTER_INSTANCE, response.getType());
|
||||||
|
@ -21,32 +21,32 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class InstanceResponseTest {
|
class InstanceResponseTest {
|
||||||
|
|
||||||
protected static ObjectMapper mapper;
|
protected static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
InstanceResponse response = new InstanceResponse(NamingRemoteConstants.REGISTER_INSTANCE);
|
InstanceResponse response = new InstanceResponse(NamingRemoteConstants.REGISTER_INSTANCE);
|
||||||
String json = mapper.writeValueAsString(response);
|
String json = mapper.writeValueAsString(response);
|
||||||
assertTrue(json.contains("\"type\":\"" + NamingRemoteConstants.REGISTER_INSTANCE + "\""));
|
assertTrue(json.contains("\"type\":\"" + NamingRemoteConstants.REGISTER_INSTANCE + "\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"type\":\"deregisterInstance\",\"success\":true}";
|
String json = "{\"resultCode\":200,\"errorCode\":0,\"type\":\"deregisterInstance\",\"success\":true}";
|
||||||
InstanceResponse response = mapper.readValue(json, InstanceResponse.class);
|
InstanceResponse response = mapper.readValue(json, InstanceResponse.class);
|
||||||
assertEquals(NamingRemoteConstants.DE_REGISTER_INSTANCE, response.getType());
|
assertEquals(NamingRemoteConstants.DE_REGISTER_INSTANCE, response.getType());
|
||||||
|
@ -21,25 +21,25 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class QueryServiceResponseTest {
|
class QueryServiceResponseTest {
|
||||||
|
|
||||||
protected static ObjectMapper mapper;
|
protected static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerializeSuccessResponse() throws JsonProcessingException {
|
void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||||
QueryServiceResponse response = QueryServiceResponse.buildSuccessResponse(new ServiceInfo());
|
QueryServiceResponse response = QueryServiceResponse.buildSuccessResponse(new ServiceInfo());
|
||||||
String json = mapper.writeValueAsString(response);
|
String json = mapper.writeValueAsString(response);
|
||||||
assertTrue(json.contains("\"serviceInfo\":{"));
|
assertTrue(json.contains("\"serviceInfo\":{"));
|
||||||
@ -49,7 +49,7 @@ public class QueryServiceResponseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
void testSerializeFailResponse() throws JsonProcessingException {
|
||||||
QueryServiceResponse response = QueryServiceResponse.buildFailResponse("test");
|
QueryServiceResponse response = QueryServiceResponse.buildFailResponse("test");
|
||||||
String json = mapper.writeValueAsString(response);
|
String json = mapper.writeValueAsString(response);
|
||||||
assertTrue(json.contains("\"resultCode\":500"));
|
assertTrue(json.contains("\"resultCode\":500"));
|
||||||
@ -59,7 +59,7 @@ public class QueryServiceResponseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"serviceInfo\":{\"cacheMillis\":1000,\"hosts\":[],"
|
String json = "{\"resultCode\":200,\"errorCode\":0,\"serviceInfo\":{\"cacheMillis\":1000,\"hosts\":[],"
|
||||||
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"reachProtectionThreshold\":false,"
|
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"reachProtectionThreshold\":false,"
|
||||||
+ "\"valid\":true},\"success\":true}";
|
+ "\"valid\":true},\"success\":true}";
|
||||||
|
@ -20,27 +20,27 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServiceListResponseTest {
|
class ServiceListResponseTest {
|
||||||
|
|
||||||
protected static ObjectMapper mapper;
|
protected static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerializeSuccessResponse() throws JsonProcessingException {
|
void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||||
ServiceListResponse response = ServiceListResponse.buildSuccessResponse(10, Collections.singletonList("a"));
|
ServiceListResponse response = ServiceListResponse.buildSuccessResponse(10, Collections.singletonList("a"));
|
||||||
String json = mapper.writeValueAsString(response);
|
String json = mapper.writeValueAsString(response);
|
||||||
assertTrue(json.contains("\"count\":10"));
|
assertTrue(json.contains("\"count\":10"));
|
||||||
@ -51,7 +51,7 @@ public class ServiceListResponseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
void testSerializeFailResponse() throws JsonProcessingException {
|
||||||
ServiceListResponse response = ServiceListResponse.buildFailResponse("test");
|
ServiceListResponse response = ServiceListResponse.buildFailResponse("test");
|
||||||
String json = mapper.writeValueAsString(response);
|
String json = mapper.writeValueAsString(response);
|
||||||
assertTrue(json.contains("\"resultCode\":500"));
|
assertTrue(json.contains("\"resultCode\":500"));
|
||||||
@ -61,7 +61,7 @@ public class ServiceListResponseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"count\":10,\"serviceNames\":[\"a\"],\"success\":true}";
|
String json = "{\"resultCode\":200,\"errorCode\":0,\"count\":10,\"serviceNames\":[\"a\"],\"success\":true}";
|
||||||
ServiceListResponse response = mapper.readValue(json, ServiceListResponse.class);
|
ServiceListResponse response = mapper.readValue(json, ServiceListResponse.class);
|
||||||
assertEquals(10, response.getCount());
|
assertEquals(10, response.getCount());
|
||||||
|
@ -21,25 +21,25 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class SubscribeServiceResponseTest {
|
class SubscribeServiceResponseTest {
|
||||||
|
|
||||||
protected static ObjectMapper mapper;
|
protected static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerializeSuccessResponse() throws JsonProcessingException {
|
void testSerializeSuccessResponse() throws JsonProcessingException {
|
||||||
SubscribeServiceResponse response = new SubscribeServiceResponse(200, null, new ServiceInfo());
|
SubscribeServiceResponse response = new SubscribeServiceResponse(200, null, new ServiceInfo());
|
||||||
String json = mapper.writeValueAsString(response);
|
String json = mapper.writeValueAsString(response);
|
||||||
assertTrue(json.contains("\"serviceInfo\":{"));
|
assertTrue(json.contains("\"serviceInfo\":{"));
|
||||||
@ -49,7 +49,7 @@ public class SubscribeServiceResponseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerializeFailResponse() throws JsonProcessingException {
|
void testSerializeFailResponse() throws JsonProcessingException {
|
||||||
SubscribeServiceResponse response = new SubscribeServiceResponse(500, "test", null);
|
SubscribeServiceResponse response = new SubscribeServiceResponse(500, "test", null);
|
||||||
String json = mapper.writeValueAsString(response);
|
String json = mapper.writeValueAsString(response);
|
||||||
assertTrue(json.contains("\"resultCode\":500"));
|
assertTrue(json.contains("\"resultCode\":500"));
|
||||||
@ -59,7 +59,7 @@ public class SubscribeServiceResponseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"serviceInfo\":{\"cacheMillis\":1000,\"hosts\":[],"
|
String json = "{\"resultCode\":200,\"errorCode\":0,\"serviceInfo\":{\"cacheMillis\":1000,\"hosts\":[],"
|
||||||
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"reachProtectionThreshold\":false,"
|
+ "\"lastRefTime\":0,\"checksum\":\"\",\"allIPs\":false,\"reachProtectionThreshold\":false,"
|
||||||
+ "\"valid\":true},\"success\":true}";
|
+ "\"valid\":true},\"success\":true}";
|
||||||
|
@ -21,107 +21,117 @@ import com.alibaba.nacos.api.exception.NacosException;
|
|||||||
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
|
import com.alibaba.nacos.api.naming.PreservedMetadataKeys;
|
||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import com.alibaba.nacos.api.utils.StringUtils;
|
import com.alibaba.nacos.api.utils.StringUtils;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class NamingUtilsTest {
|
class NamingUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetGroupedName() {
|
void testGetGroupedName() {
|
||||||
assertEquals("group@@serviceName", NamingUtils.getGroupedName("serviceName", "group"));
|
assertEquals("group@@serviceName", NamingUtils.getGroupedName("serviceName", "group"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testGetGroupedNameWithoutGroup() {
|
void testGetGroupedNameWithoutGroup() {
|
||||||
NamingUtils.getGroupedName("serviceName", "");
|
assertThrows(IllegalArgumentException.class, () -> {
|
||||||
}
|
NamingUtils.getGroupedName("serviceName", "");
|
||||||
|
});
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void testGetGroupedNameWithoutServiceName() {
|
|
||||||
NamingUtils.getGroupedName("", "group");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetServiceName() {
|
void testGetGroupedNameWithoutServiceName() {
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> {
|
||||||
|
NamingUtils.getGroupedName("", "group");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetServiceName() {
|
||||||
String validServiceName = "group@@serviceName";
|
String validServiceName = "group@@serviceName";
|
||||||
assertEquals("serviceName", NamingUtils.getServiceName(validServiceName));
|
assertEquals("serviceName", NamingUtils.getServiceName(validServiceName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetServiceNameWithoutGroup() {
|
void testGetServiceNameWithoutGroup() {
|
||||||
String serviceName = "serviceName";
|
String serviceName = "serviceName";
|
||||||
assertEquals(serviceName, NamingUtils.getServiceName(serviceName));
|
assertEquals(serviceName, NamingUtils.getServiceName(serviceName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetServiceNameWithEmpty() {
|
void testGetServiceNameWithEmpty() {
|
||||||
assertEquals(StringUtils.EMPTY, NamingUtils.getServiceName(null));
|
assertEquals(StringUtils.EMPTY, NamingUtils.getServiceName(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetGroupName() {
|
void testGetGroupName() {
|
||||||
String validServiceName = "group@@serviceName";
|
String validServiceName = "group@@serviceName";
|
||||||
assertEquals("group", NamingUtils.getGroupName(validServiceName));
|
assertEquals("group", NamingUtils.getGroupName(validServiceName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetGroupNameWithoutGroup() {
|
void testGetGroupNameWithoutGroup() {
|
||||||
String serviceName = "serviceName";
|
String serviceName = "serviceName";
|
||||||
assertEquals(Constants.DEFAULT_GROUP, NamingUtils.getGroupName(serviceName));
|
assertEquals(Constants.DEFAULT_GROUP, NamingUtils.getGroupName(serviceName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetGroupNameWithEmpty() {
|
void testGetGroupNameWithEmpty() {
|
||||||
assertEquals(StringUtils.EMPTY, NamingUtils.getGroupName(null));
|
assertEquals(StringUtils.EMPTY, NamingUtils.getGroupName(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsServiceNameCompatibilityMode() {
|
void testIsServiceNameCompatibilityMode() {
|
||||||
String serviceName1 = "group@@serviceName";
|
String serviceName1 = "group@@serviceName";
|
||||||
assertTrue(NamingUtils.isServiceNameCompatibilityMode(serviceName1));
|
assertTrue(NamingUtils.isServiceNameCompatibilityMode(serviceName1));
|
||||||
|
|
||||||
String serviceName2 = "serviceName";
|
String serviceName2 = "serviceName";
|
||||||
assertFalse(NamingUtils.isServiceNameCompatibilityMode(serviceName2));
|
assertFalse(NamingUtils.isServiceNameCompatibilityMode(serviceName2));
|
||||||
|
|
||||||
String serviceName3 = null;
|
String serviceName3 = null;
|
||||||
assertFalse(NamingUtils.isServiceNameCompatibilityMode(serviceName3));
|
assertFalse(NamingUtils.isServiceNameCompatibilityMode(serviceName3));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckServiceNameFormat() {
|
void testCheckServiceNameFormat() {
|
||||||
String validServiceName = "group@@serviceName";
|
String validServiceName = "group@@serviceName";
|
||||||
NamingUtils.checkServiceNameFormat(validServiceName);
|
NamingUtils.checkServiceNameFormat(validServiceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testCheckServiceNameFormatWithoutGroupAndService() {
|
void testCheckServiceNameFormatWithoutGroupAndService() {
|
||||||
String validServiceName = "@@";
|
assertThrows(IllegalArgumentException.class, () -> {
|
||||||
NamingUtils.checkServiceNameFormat(validServiceName);
|
String validServiceName = "@@";
|
||||||
}
|
NamingUtils.checkServiceNameFormat(validServiceName);
|
||||||
|
});
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void testCheckServiceNameFormatWithoutGroup() {
|
|
||||||
String validServiceName = "@@service";
|
|
||||||
NamingUtils.checkServiceNameFormat(validServiceName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
|
||||||
public void testCheckServiceNameFormatWithoutService() {
|
|
||||||
String validServiceName = "group@@";
|
|
||||||
NamingUtils.checkServiceNameFormat(validServiceName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetGroupedNameOptional() {
|
void testCheckServiceNameFormatWithoutGroup() {
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> {
|
||||||
|
String validServiceName = "@@service";
|
||||||
|
NamingUtils.checkServiceNameFormat(validServiceName);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testCheckServiceNameFormatWithoutService() {
|
||||||
|
assertThrows(IllegalArgumentException.class, () -> {
|
||||||
|
String validServiceName = "group@@";
|
||||||
|
NamingUtils.checkServiceNameFormat(validServiceName);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetGroupedNameOptional() {
|
||||||
String onlyGroupName = NamingUtils.getGroupedNameOptional(StringUtils.EMPTY, "groupA");
|
String onlyGroupName = NamingUtils.getGroupedNameOptional(StringUtils.EMPTY, "groupA");
|
||||||
assertEquals("groupA@@", onlyGroupName);
|
assertEquals("groupA@@", onlyGroupName);
|
||||||
|
|
||||||
@ -133,7 +143,7 @@ public class NamingUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckInstanceIsLegal() throws NacosException {
|
void testCheckInstanceIsLegal() throws NacosException {
|
||||||
// check invalid clusterName
|
// check invalid clusterName
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
instance.setClusterName("cluster1,cluster2");
|
instance.setClusterName("cluster1,cluster2");
|
||||||
@ -151,7 +161,7 @@ public class NamingUtilsTest {
|
|||||||
instance.setClusterName("cluster1");
|
instance.setClusterName("cluster1");
|
||||||
NamingUtils.checkInstanceIsLegal(instance);
|
NamingUtils.checkInstanceIsLegal(instance);
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
|
|
||||||
// check heartBeatTimeout, heartBeatInterval, ipDeleteTimeout
|
// check heartBeatTimeout, heartBeatInterval, ipDeleteTimeout
|
||||||
Map<String, String> meta = new HashMap<>();
|
Map<String, String> meta = new HashMap<>();
|
||||||
meta.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, "1");
|
meta.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, "1");
|
||||||
@ -163,8 +173,7 @@ public class NamingUtilsTest {
|
|||||||
assertTrue(false);
|
assertTrue(false);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
assertTrue(e instanceof NacosException);
|
assertTrue(e instanceof NacosException);
|
||||||
assertEquals(
|
assertEquals("Instance 'heart beat interval' must less than 'heart beat timeout' and 'ip delete timeout'.",
|
||||||
"Instance 'heart beat interval' must less than 'heart beat timeout' and 'ip delete timeout'.",
|
|
||||||
e.getMessage());
|
e.getMessage());
|
||||||
}
|
}
|
||||||
meta.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, "3");
|
meta.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT, "3");
|
||||||
@ -175,7 +184,7 @@ public class NamingUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBatchCheckInstanceIsLegal() throws NacosException {
|
void testBatchCheckInstanceIsLegal() throws NacosException {
|
||||||
// check invalid clusterName
|
// check invalid clusterName
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
instance.setClusterName("cluster1,cluster2");
|
instance.setClusterName("cluster1,cluster2");
|
||||||
@ -212,8 +221,7 @@ public class NamingUtilsTest {
|
|||||||
assertTrue(false);
|
assertTrue(false);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
assertTrue(e instanceof NacosException);
|
assertTrue(e instanceof NacosException);
|
||||||
assertEquals(
|
assertEquals("Instance 'heart beat interval' must less than 'heart beat timeout' and 'ip delete timeout'.",
|
||||||
"Instance 'heart beat interval' must less than 'heart beat timeout' and 'ip delete timeout'.",
|
|
||||||
e.getMessage());
|
e.getMessage());
|
||||||
}
|
}
|
||||||
instanceList.remove(instance);
|
instanceList.remove(instance);
|
||||||
@ -228,7 +236,7 @@ public class NamingUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckInstanceIsEphemeral() throws NacosException {
|
void testCheckInstanceIsEphemeral() throws NacosException {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
instance.setIp("127.0.0.1");
|
instance.setIp("127.0.0.1");
|
||||||
instance.setPort(9089);
|
instance.setPort(9089);
|
||||||
@ -241,12 +249,12 @@ public class NamingUtilsTest {
|
|||||||
instance.setEphemeral(false);
|
instance.setEphemeral(false);
|
||||||
NamingUtils.checkInstanceIsEphemeral(instance);
|
NamingUtils.checkInstanceIsEphemeral(instance);
|
||||||
} catch (NacosException e) {
|
} catch (NacosException e) {
|
||||||
Assert.assertEquals(e.getErrCode(), NacosException.INVALID_PARAM);
|
assertEquals(NacosException.INVALID_PARAM, e.getErrCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckInstanceIsNull() throws NacosException {
|
void testCheckInstanceIsNull() throws NacosException {
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
instance.setIp("127.0.0.1");
|
instance.setIp("127.0.0.1");
|
||||||
instance.setPort(9089);
|
instance.setPort(9089);
|
||||||
@ -254,15 +262,15 @@ public class NamingUtilsTest {
|
|||||||
try {
|
try {
|
||||||
NamingUtils.checkInstanceIsLegal(null);
|
NamingUtils.checkInstanceIsLegal(null);
|
||||||
} catch (NacosException e) {
|
} catch (NacosException e) {
|
||||||
Assert.assertEquals(e.getErrCode(), NacosException.INVALID_PARAM);
|
assertEquals(NacosException.INVALID_PARAM, e.getErrCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsNumber() {
|
void testIsNumber() {
|
||||||
String str1 = "abc";
|
String str1 = "abc";
|
||||||
assertTrue(!NamingUtils.isNumber(str1));
|
assertFalse(NamingUtils.isNumber(str1));
|
||||||
|
|
||||||
String str2 = "123456";
|
String str2 = "123456";
|
||||||
assertTrue(NamingUtils.isNumber(str2));
|
assertTrue(NamingUtils.isNumber(str2));
|
||||||
}
|
}
|
||||||
|
@ -16,18 +16,18 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.remote;
|
package com.alibaba.nacos.api.remote;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class AbstractPushCallBackTest {
|
class AbstractPushCallBackTest {
|
||||||
|
|
||||||
boolean testValue;
|
boolean testValue;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAbstractPushCallBack() {
|
void testAbstractPushCallBack() {
|
||||||
AbstractPushCallBack callBack = new AbstractPushCallBack(2000) {
|
AbstractPushCallBack callBack = new AbstractPushCallBack(2000) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -18,20 +18,20 @@ package com.alibaba.nacos.api.remote;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.remote.response.ErrorResponse;
|
import com.alibaba.nacos.api.remote.response.ErrorResponse;
|
||||||
import com.alibaba.nacos.api.remote.response.Response;
|
import com.alibaba.nacos.api.remote.response.Response;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class AbstractRequestCallBackTest {
|
class AbstractRequestCallBackTest {
|
||||||
|
|
||||||
boolean testValue;
|
boolean testValue;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAbstractPushCallBack() {
|
void testAbstractPushCallBack() {
|
||||||
AbstractRequestCallBack callBack = new AbstractRequestCallBack() {
|
AbstractRequestCallBack callBack = new AbstractRequestCallBack() {
|
||||||
@Override
|
@Override
|
||||||
public Executor getExecutor() {
|
public Executor getExecutor() {
|
||||||
|
@ -17,27 +17,28 @@
|
|||||||
package com.alibaba.nacos.api.remote;
|
package com.alibaba.nacos.api.remote;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.remote.response.Response;
|
import com.alibaba.nacos.api.remote.response.Response;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class DefaultRequestFutureTest {
|
class DefaultRequestFutureTest {
|
||||||
|
|
||||||
private static final String CONNECTION_ID = "1233_1.1.1.1_3306";
|
private static final String CONNECTION_ID = "1233_1.1.1.1_3306";
|
||||||
|
|
||||||
@ -51,17 +52,17 @@ public class DefaultRequestFutureTest {
|
|||||||
|
|
||||||
private long timestamp;
|
private long timestamp;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
timestamp = System.currentTimeMillis();
|
timestamp = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void tearDown() throws Exception {
|
void tearDown() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSyncGetResponseSuccessWithoutTimeout() throws InterruptedException {
|
void testSyncGetResponseSuccessWithoutTimeout() throws InterruptedException {
|
||||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
@ -79,7 +80,7 @@ public class DefaultRequestFutureTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSyncGetResponseFailureWithoutTimeout() throws InterruptedException {
|
void testSyncGetResponseFailureWithoutTimeout() throws InterruptedException {
|
||||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
@ -97,7 +98,7 @@ public class DefaultRequestFutureTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSyncGetResponseSuccessWithTimeout() throws InterruptedException, TimeoutException {
|
void testSyncGetResponseSuccessWithTimeout() throws InterruptedException, TimeoutException {
|
||||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
@ -115,7 +116,7 @@ public class DefaultRequestFutureTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSyncGetResponseSuccessWithInvalidTimeout() throws InterruptedException, TimeoutException {
|
void testSyncGetResponseSuccessWithInvalidTimeout() throws InterruptedException, TimeoutException {
|
||||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
@ -132,14 +133,16 @@ public class DefaultRequestFutureTest {
|
|||||||
assertTrue(requestFuture.getTimeStamp() >= timestamp);
|
assertTrue(requestFuture.getTimeStamp() >= timestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = TimeoutException.class)
|
@Test
|
||||||
public void testSyncGetResponseFailureWithTimeout() throws InterruptedException, TimeoutException {
|
void testSyncGetResponseFailureWithTimeout() throws InterruptedException, TimeoutException {
|
||||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
assertThrows(TimeoutException.class, () -> {
|
||||||
requestFuture.get(100L);
|
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID);
|
||||||
|
requestFuture.get(100L);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSyncGetResponseSuccessByTriggerWithoutTimeout() throws InterruptedException {
|
void testSyncGetResponseSuccessByTriggerWithoutTimeout() throws InterruptedException {
|
||||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
@ -159,7 +162,7 @@ public class DefaultRequestFutureTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSyncGetResponseFailureByTriggerWithoutTimeout() throws InterruptedException {
|
void testSyncGetResponseFailureByTriggerWithoutTimeout() throws InterruptedException {
|
||||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
@ -179,7 +182,7 @@ public class DefaultRequestFutureTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSyncGetResponseSuccessByTriggerWithTimeout() throws InterruptedException, TimeoutException {
|
void testSyncGetResponseSuccessByTriggerWithTimeout() throws InterruptedException, TimeoutException {
|
||||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
@ -198,19 +201,21 @@ public class DefaultRequestFutureTest {
|
|||||||
assertFalse(trigger.isTimeout);
|
assertFalse(trigger.isTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = TimeoutException.class)
|
@Test
|
||||||
public void testSyncGetResponseFailureByTriggerWithTimeout() throws InterruptedException, TimeoutException {
|
void testSyncGetResponseFailureByTriggerWithTimeout() throws InterruptedException, TimeoutException {
|
||||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
assertThrows(TimeoutException.class, () -> {
|
||||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||||
try {
|
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, null, trigger);
|
||||||
requestFuture.get(100L);
|
try {
|
||||||
} finally {
|
requestFuture.get(100L);
|
||||||
assertTrue(trigger.isTimeout);
|
} finally {
|
||||||
}
|
assertTrue(trigger.isTimeout);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testASyncGetResponseSuccessWithoutTimeout() throws InterruptedException {
|
void testASyncGetResponseSuccessWithoutTimeout() throws InterruptedException {
|
||||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||||
MockRequestCallback callback = new MockRequestCallback(200L);
|
MockRequestCallback callback = new MockRequestCallback(200L);
|
||||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger);
|
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger);
|
||||||
@ -229,7 +234,7 @@ public class DefaultRequestFutureTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testASyncGetResponseSuccessWithoutTimeoutByExecutor() throws InterruptedException {
|
void testASyncGetResponseSuccessWithoutTimeoutByExecutor() throws InterruptedException {
|
||||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||||
MockRequestCallback callback = new MockRequestCallback(executor, 200L);
|
MockRequestCallback callback = new MockRequestCallback(executor, 200L);
|
||||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger);
|
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger);
|
||||||
@ -246,7 +251,7 @@ public class DefaultRequestFutureTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testASyncGetResponseFailureWithoutTimeout() throws InterruptedException {
|
void testASyncGetResponseFailureWithoutTimeout() throws InterruptedException {
|
||||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||||
MockRequestCallback callback = new MockRequestCallback(1000L);
|
MockRequestCallback callback = new MockRequestCallback(1000L);
|
||||||
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger);
|
DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger);
|
||||||
@ -265,10 +270,11 @@ public class DefaultRequestFutureTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testASyncGetResponseFailureWithTimeout() throws InterruptedException {
|
void testASyncGetResponseFailureWithTimeout() throws InterruptedException {
|
||||||
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
MockTimeoutInnerTrigger trigger = new MockTimeoutInnerTrigger();
|
||||||
MockRequestCallback callback = new MockRequestCallback(100L);
|
MockRequestCallback callback = new MockRequestCallback(100L);
|
||||||
final DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback, trigger);
|
final DefaultRequestFuture requestFuture = new DefaultRequestFuture(CONNECTION_ID, REQUEST_ID, callback,
|
||||||
|
trigger);
|
||||||
TimeUnit.MILLISECONDS.sleep(500);
|
TimeUnit.MILLISECONDS.sleep(500);
|
||||||
assertNull(callback.response);
|
assertNull(callback.response);
|
||||||
assertTrue(callback.exception instanceof TimeoutException);
|
assertTrue(callback.exception instanceof TimeoutException);
|
||||||
|
@ -16,24 +16,24 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.remote;
|
package com.alibaba.nacos.api.remote;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class RpcScheduledExecutorTest {
|
class RpcScheduledExecutorTest {
|
||||||
|
|
||||||
private static final String NAME = "test.rpc.thread";
|
private static final String NAME = "test.rpc.thread";
|
||||||
|
|
||||||
Map<String, String> threadNameMap = new ConcurrentHashMap<>();
|
Map<String, String> threadNameMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRpcScheduledExecutor() throws InterruptedException {
|
void testRpcScheduledExecutor() throws InterruptedException {
|
||||||
RpcScheduledExecutor executor = new RpcScheduledExecutor(2, NAME);
|
RpcScheduledExecutor executor = new RpcScheduledExecutor(2, NAME);
|
||||||
CountDownLatch latch = new CountDownLatch(2);
|
CountDownLatch latch = new CountDownLatch(2);
|
||||||
executor.submit(new TestRunner(1, latch));
|
executor.submit(new TestRunner(1, latch));
|
||||||
|
@ -20,32 +20,32 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ClientRemoteAbilityTest {
|
class ClientRemoteAbilityTest {
|
||||||
|
|
||||||
private static ObjectMapper mapper;
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUp() throws Exception {
|
static void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
ClientRemoteAbility abilities = new ClientRemoteAbility();
|
ClientRemoteAbility abilities = new ClientRemoteAbility();
|
||||||
String json = mapper.writeValueAsString(abilities);
|
String json = mapper.writeValueAsString(abilities);
|
||||||
assertEquals("{\"supportRemoteConnection\":false}", json);
|
assertEquals("{\"supportRemoteConnection\":false}", json);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"supportRemoteConnection\":true}";
|
String json = "{\"supportRemoteConnection\":true}";
|
||||||
ClientRemoteAbility abilities = mapper.readValue(json, ClientRemoteAbility.class);
|
ClientRemoteAbility abilities = mapper.readValue(json, ClientRemoteAbility.class);
|
||||||
assertTrue(abilities.isSupportRemoteConnection());
|
assertTrue(abilities.isSupportRemoteConnection());
|
||||||
|
@ -20,37 +20,37 @@ import com.alibaba.nacos.api.ability.ClientAbilities;
|
|||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.MapperFeature;
|
import com.fasterxml.jackson.databind.MapperFeature;
|
||||||
import org.junit.Before;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
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;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServerRemoteAbilityTest {
|
class ServerRemoteAbilityTest {
|
||||||
|
|
||||||
private static ObjectMapper mapper;
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
private ServerRemoteAbility serverAbilities;
|
private ServerRemoteAbility serverAbilities;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void setUpBeforeClass() throws Exception {
|
static void setUpBeforeClass() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
|
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
serverAbilities = new ServerRemoteAbility();
|
serverAbilities = new ServerRemoteAbility();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws JsonProcessingException {
|
void testSerialize() throws JsonProcessingException {
|
||||||
serverAbilities = new ServerRemoteAbility();
|
serverAbilities = new ServerRemoteAbility();
|
||||||
String json = mapper.writeValueAsString(serverAbilities);
|
String json = mapper.writeValueAsString(serverAbilities);
|
||||||
assertTrue(json.contains("\"supportRemoteConnection\":false"));
|
assertTrue(json.contains("\"supportRemoteConnection\":false"));
|
||||||
@ -58,7 +58,7 @@ public class ServerRemoteAbilityTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws JsonProcessingException {
|
void testDeserialize() throws JsonProcessingException {
|
||||||
String json = "{\"supportRemoteConnection\":true,\"grpcReportEnabled\":true}";
|
String json = "{\"supportRemoteConnection\":true,\"grpcReportEnabled\":true}";
|
||||||
ServerRemoteAbility abilities = mapper.readValue(json, ServerRemoteAbility.class);
|
ServerRemoteAbility abilities = mapper.readValue(json, ServerRemoteAbility.class);
|
||||||
assertTrue(abilities.isSupportRemoteConnection());
|
assertTrue(abilities.isSupportRemoteConnection());
|
||||||
@ -66,10 +66,10 @@ public class ServerRemoteAbilityTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualsAndHashCode() {
|
void testEqualsAndHashCode() {
|
||||||
assertEquals(serverAbilities, serverAbilities);
|
assertEquals(serverAbilities, serverAbilities);
|
||||||
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
|
assertEquals(serverAbilities.hashCode(), serverAbilities.hashCode());
|
||||||
assertNotEquals(serverAbilities, null);
|
assertNotEquals(null, serverAbilities);
|
||||||
assertNotEquals(serverAbilities, new ClientAbilities());
|
assertNotEquals(serverAbilities, new ClientAbilities());
|
||||||
ServerRemoteAbility test = new ServerRemoteAbility();
|
ServerRemoteAbility test = new ServerRemoteAbility();
|
||||||
assertEquals(serverAbilities, test);
|
assertEquals(serverAbilities, test);
|
||||||
|
@ -19,13 +19,13 @@ package com.alibaba.nacos.api.remote.request;
|
|||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
|
||||||
public abstract class BasicRequestTest {
|
public abstract class BasicRequestTest {
|
||||||
|
|
||||||
protected ObjectMapper mapper;
|
protected ObjectMapper mapper;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
mapper = new ObjectMapper();
|
mapper = new ObjectMapper();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
|
@ -16,35 +16,38 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.remote.request;
|
package com.alibaba.nacos.api.remote.request;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class ConnectResetRequestTest extends BasicRequestTest {
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
class ConnectResetRequestTest extends BasicRequestTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws Exception {
|
void testSerialize() throws Exception {
|
||||||
ConnectResetRequest request = new ConnectResetRequest();
|
ConnectResetRequest request = new ConnectResetRequest();
|
||||||
request.setServerIp("127.0.0.1");
|
request.setServerIp("127.0.0.1");
|
||||||
request.setServerPort("8888");
|
request.setServerPort("8888");
|
||||||
request.setRequestId("1");
|
request.setRequestId("1");
|
||||||
request.setConnectionId("11111_127.0.0.1_8888");
|
request.setConnectionId("11111_127.0.0.1_8888");
|
||||||
String json = mapper.writeValueAsString(request);
|
String json = mapper.writeValueAsString(request);
|
||||||
Assert.assertNotNull(json);
|
assertNotNull(json);
|
||||||
Assert.assertTrue(json.contains("\"serverIp\":\"127.0.0.1\""));
|
assertTrue(json.contains("\"serverIp\":\"127.0.0.1\""));
|
||||||
Assert.assertTrue(json.contains("\"serverPort\":\"8888\""));
|
assertTrue(json.contains("\"serverPort\":\"8888\""));
|
||||||
Assert.assertTrue(json.contains("\"module\":\"internal\""));
|
assertTrue(json.contains("\"module\":\"internal\""));
|
||||||
Assert.assertTrue(json.contains("\"requestId\":\"1\""));
|
assertTrue(json.contains("\"requestId\":\"1\""));
|
||||||
Assert.assertTrue(json.contains("\"connectionId\":\"11111_127.0.0.1_8888\""));
|
assertTrue(json.contains("\"connectionId\":\"11111_127.0.0.1_8888\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws Exception {
|
void testDeserialize() throws Exception {
|
||||||
String json = "{\"headers\":{},\"requestId\":\"1\",\"serverIp\":\"127.0.0.1\",\"serverPort\":\"8888\","
|
String json = "{\"headers\":{},\"requestId\":\"1\",\"serverIp\":\"127.0.0.1\",\"serverPort\":\"8888\","
|
||||||
+ "\"module\":\"internal\",\"connectionId\":\"11111_127.0.0.1_8888\"}";
|
+ "\"module\":\"internal\",\"connectionId\":\"11111_127.0.0.1_8888\"}";
|
||||||
ConnectResetRequest result = mapper.readValue(json, ConnectResetRequest.class);
|
ConnectResetRequest result = mapper.readValue(json, ConnectResetRequest.class);
|
||||||
Assert.assertNotNull(result);
|
assertNotNull(result);
|
||||||
Assert.assertEquals("127.0.0.1", result.getServerIp());
|
assertEquals("127.0.0.1", result.getServerIp());
|
||||||
Assert.assertEquals("8888", result.getServerPort());
|
assertEquals("8888", result.getServerPort());
|
||||||
Assert.assertEquals("11111_127.0.0.1_8888", result.getConnectionId());
|
assertEquals("11111_127.0.0.1_8888", result.getConnectionId());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,16 +16,19 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.remote.request;
|
package com.alibaba.nacos.api.remote.request;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class ConnectionSetupRequestTest extends BasicRequestTest {
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
class ConnectionSetupRequestTest extends BasicRequestTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws Exception {
|
void testSerialize() throws Exception {
|
||||||
ConnectionSetupRequest request = new ConnectionSetupRequest();
|
ConnectionSetupRequest request = new ConnectionSetupRequest();
|
||||||
request.setClientVersion("2.2.2");
|
request.setClientVersion("2.2.2");
|
||||||
request.setAbilityTable(new HashMap<>());
|
request.setAbilityTable(new HashMap<>());
|
||||||
@ -33,27 +36,28 @@ public class ConnectionSetupRequestTest extends BasicRequestTest {
|
|||||||
request.setLabels(Collections.singletonMap("labelKey", "labelValue"));
|
request.setLabels(Collections.singletonMap("labelKey", "labelValue"));
|
||||||
request.setRequestId("1");
|
request.setRequestId("1");
|
||||||
String json = mapper.writeValueAsString(request);
|
String json = mapper.writeValueAsString(request);
|
||||||
Assert.assertNotNull(json);
|
assertNotNull(json);
|
||||||
Assert.assertTrue(json.contains("\"clientVersion\":\"2.2.2\""));
|
assertTrue(json.contains("\"clientVersion\":\"2.2.2\""));
|
||||||
Assert.assertTrue(json.contains("\"tenant\":\"testNamespaceId\""));
|
assertTrue(json.contains("\"tenant\":\"testNamespaceId\""));
|
||||||
Assert.assertTrue(json.contains("\"labels\":{\"labelKey\":\"labelValue\"}"));
|
assertTrue(json.contains("\"labels\":{\"labelKey\":\"labelValue\"}"));
|
||||||
Assert.assertTrue(json.contains("\"abilityTable\":{"));
|
assertTrue(json.contains("\"abilityTable\":{"));
|
||||||
Assert.assertTrue(json.contains("\"module\":\"internal\""));
|
assertTrue(json.contains("\"module\":\"internal\""));
|
||||||
Assert.assertTrue(json.contains("\"requestId\":\"1\""));
|
assertTrue(json.contains("\"requestId\":\"1\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws Exception {
|
void testDeserialize() throws Exception {
|
||||||
String json = "{\"headers\":{},\"requestId\":\"1\",\"clientVersion\":\"2.2.2\",\"abilities\":{\"remoteAbility\":"
|
String json =
|
||||||
+ "{\"supportRemoteConnection\":false},\"configAbility\":{\"supportRemoteMetrics\":false},"
|
"{\"headers\":{},\"requestId\":\"1\",\"clientVersion\":\"2.2.2\",\"abilities\":{\"remoteAbility\":"
|
||||||
+ "\"namingAbility\":{\"supportDeltaPush\":false,\"supportRemoteMetric\":false}},\"tenant\":\"testNamespaceId\","
|
+ "{\"supportRemoteConnection\":false},\"configAbility\":{\"supportRemoteMetrics\":false},"
|
||||||
+ "\"labels\":{\"labelKey\":\"labelValue\"},\"module\":\"internal\"}";
|
+ "\"namingAbility\":{\"supportDeltaPush\":false,\"supportRemoteMetric\":false}},\"tenant\":\"testNamespaceId\","
|
||||||
|
+ "\"labels\":{\"labelKey\":\"labelValue\"},\"module\":\"internal\"}";
|
||||||
ConnectionSetupRequest result = mapper.readValue(json, ConnectionSetupRequest.class);
|
ConnectionSetupRequest result = mapper.readValue(json, ConnectionSetupRequest.class);
|
||||||
Assert.assertNotNull(result);
|
assertNotNull(result);
|
||||||
Assert.assertEquals("2.2.2", result.getClientVersion());
|
assertEquals("2.2.2", result.getClientVersion());
|
||||||
Assert.assertEquals("testNamespaceId", result.getTenant());
|
assertEquals("testNamespaceId", result.getTenant());
|
||||||
Assert.assertEquals(1, result.getLabels().size());
|
assertEquals(1, result.getLabels().size());
|
||||||
Assert.assertEquals("labelValue", result.getLabels().get("labelKey"));
|
assertEquals("labelValue", result.getLabels().get("labelKey"));
|
||||||
Assert.assertEquals("1", result.getRequestId());
|
assertEquals("1", result.getRequestId());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,19 +19,19 @@ package com.alibaba.nacos.api.remote.request;
|
|||||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class EmptyContentRequestTest extends BasicRequestTest {
|
class EmptyContentRequestTest extends BasicRequestTest {
|
||||||
|
|
||||||
private static final String COMMON_JSON = "{\"headers\":{\"clientIp\":\"1.1.1.1\"},\"requestId\":\"1\",\"module\":\"internal\"}";
|
private static final String COMMON_JSON = "{\"headers\":{\"clientIp\":\"1.1.1.1\"},\"requestId\":\"1\",\"module\":\"internal\"}";
|
||||||
|
|
||||||
private static final String TO_STRING = "%s{headers={clientIp=1.1.1.1}, requestId='1'}";
|
private static final String TO_STRING = "%s{headers={clientIp=1.1.1.1}, requestId='1'}";
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
@ -39,26 +39,22 @@ public class EmptyContentRequestTest extends BasicRequestTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClientDetectionRequest()
|
void testClientDetectionRequest() throws JsonProcessingException, InstantiationException, IllegalAccessException {
|
||||||
throws JsonProcessingException, InstantiationException, IllegalAccessException {
|
|
||||||
doTest(ClientDetectionRequest.class);
|
doTest(ClientDetectionRequest.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHealthCheckRequest()
|
void testHealthCheckRequest() throws JsonProcessingException, InstantiationException, IllegalAccessException {
|
||||||
throws JsonProcessingException, InstantiationException, IllegalAccessException {
|
|
||||||
doTest(HealthCheckRequest.class);
|
doTest(HealthCheckRequest.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testServerCheckRequest()
|
void testServerCheckRequest() throws JsonProcessingException, InstantiationException, IllegalAccessException {
|
||||||
throws JsonProcessingException, InstantiationException, IllegalAccessException {
|
|
||||||
doTest(ServerCheckRequest.class);
|
doTest(ServerCheckRequest.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testServerLoaderInfoRequest()
|
void testServerLoaderInfoRequest() throws JsonProcessingException, InstantiationException, IllegalAccessException {
|
||||||
throws JsonProcessingException, InstantiationException, IllegalAccessException {
|
|
||||||
doTest(ServerLoaderInfoRequest.class);
|
doTest(ServerLoaderInfoRequest.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,31 +17,35 @@
|
|||||||
package com.alibaba.nacos.api.remote.request;
|
package com.alibaba.nacos.api.remote.request;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.exception.runtime.NacosRuntimeException;
|
import com.alibaba.nacos.api.exception.runtime.NacosRuntimeException;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class PushAckRequestTest extends BasicRequestTest {
|
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 PushAckRequestTest extends BasicRequestTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws Exception {
|
void testSerialize() throws Exception {
|
||||||
PushAckRequest request = PushAckRequest.build("1", false);
|
PushAckRequest request = PushAckRequest.build("1", false);
|
||||||
request.setException(new NacosRuntimeException(500, "test"));
|
request.setException(new NacosRuntimeException(500, "test"));
|
||||||
String json = mapper.writeValueAsString(request);
|
String json = mapper.writeValueAsString(request);
|
||||||
Assert.assertNotNull(json);
|
assertNotNull(json);
|
||||||
Assert.assertTrue(json.contains("\"success\":false"));
|
assertTrue(json.contains("\"success\":false"));
|
||||||
Assert.assertTrue(json.contains("\"exception\":{"));
|
assertTrue(json.contains("\"exception\":{"));
|
||||||
Assert.assertTrue(json.contains("\"module\":\"internal\""));
|
assertTrue(json.contains("\"module\":\"internal\""));
|
||||||
Assert.assertTrue(json.contains("\"requestId\":\"1\""));
|
assertTrue(json.contains("\"requestId\":\"1\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws Exception {
|
void testDeserialize() throws Exception {
|
||||||
String json = "{\"headers\":{},\"requestId\":\"1\",\"success\":false,"
|
String json = "{\"headers\":{},\"requestId\":\"1\",\"success\":false,"
|
||||||
+ "\"exception\":{\"stackTrace\":[],\"errCode\":500,\"message\":\"errCode: 500, errMsg: test \","
|
+ "\"exception\":{\"stackTrace\":[],\"errCode\":500,\"message\":\"errCode: 500, errMsg: test \","
|
||||||
+ "\"localizedMessage\":\"errCode: 500, errMsg: test \",\"suppressed\":[]},\"module\":\"internal\"}";
|
+ "\"localizedMessage\":\"errCode: 500, errMsg: test \",\"suppressed\":[]},\"module\":\"internal\"}";
|
||||||
PushAckRequest result = mapper.readValue(json, PushAckRequest.class);
|
PushAckRequest result = mapper.readValue(json, PushAckRequest.class);
|
||||||
Assert.assertNotNull(result);
|
assertNotNull(result);
|
||||||
Assert.assertFalse(result.isSuccess());
|
assertFalse(result.isSuccess());
|
||||||
Assert.assertEquals("1", result.getRequestId());
|
assertEquals("1", result.getRequestId());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,22 +18,22 @@ package com.alibaba.nacos.api.remote.request;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||||
import com.alibaba.nacos.api.ability.constant.AbilityStatus;
|
import com.alibaba.nacos.api.ability.constant.AbilityStatus;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
public class RequestMetaTest {
|
class RequestMetaTest {
|
||||||
|
|
||||||
private RequestMeta requestMeta;
|
private RequestMeta requestMeta;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
requestMeta = new RequestMeta();
|
requestMeta = new RequestMeta();
|
||||||
requestMeta.setClientIp("127.0.0.1");
|
requestMeta.setClientIp("127.0.0.1");
|
||||||
requestMeta.setClientVersion("1.0.0");
|
requestMeta.setClientVersion("1.0.0");
|
||||||
@ -44,22 +44,22 @@ public class RequestMetaTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetClientIp() {
|
void testGetClientIp() {
|
||||||
assertEquals("127.0.0.1", requestMeta.getClientIp());
|
assertEquals("127.0.0.1", requestMeta.getClientIp());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetClientVersion() {
|
void testGetClientVersion() {
|
||||||
assertEquals("1.0.0", requestMeta.getClientVersion());
|
assertEquals("1.0.0", requestMeta.getClientVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetConnectionId() {
|
void testGetConnectionId() {
|
||||||
assertEquals("test-connection-id", requestMeta.getConnectionId());
|
assertEquals("test-connection-id", requestMeta.getConnectionId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetLabels() {
|
void testGetLabels() {
|
||||||
Map<String, String> labels = requestMeta.getLabels();
|
Map<String, String> labels = requestMeta.getLabels();
|
||||||
assertNotNull(labels);
|
assertNotNull(labels);
|
||||||
assertEquals(1, labels.size());
|
assertEquals(1, labels.size());
|
||||||
@ -67,20 +67,20 @@ public class RequestMetaTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString() {
|
void testToString() {
|
||||||
String expected = "RequestMeta{connectionId='test-connection-id', clientIp='127.0.0.1', clientVersion='1.0.0', labels={env=dev}}";
|
String expected = "RequestMeta{connectionId='test-connection-id', clientIp='127.0.0.1', clientVersion='1.0.0', labels={env=dev}}";
|
||||||
assertEquals(expected, requestMeta.toString());
|
assertEquals(expected, requestMeta.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetConnectionAbilityForNonExist() {
|
void testGetConnectionAbilityForNonExist() {
|
||||||
assertEquals(AbilityStatus.UNKNOWN, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1));
|
assertEquals(AbilityStatus.UNKNOWN, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1));
|
||||||
requestMeta.setAbilityTable(Collections.emptyMap());
|
requestMeta.setAbilityTable(Collections.emptyMap());
|
||||||
assertEquals(AbilityStatus.UNKNOWN, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1));
|
assertEquals(AbilityStatus.UNKNOWN, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetConnectionAbilityForExist() {
|
void testGetConnectionAbilityForExist() {
|
||||||
requestMeta.setAbilityTable(Collections.singletonMap(AbilityKey.SERVER_TEST_1.getName(), Boolean.FALSE));
|
requestMeta.setAbilityTable(Collections.singletonMap(AbilityKey.SERVER_TEST_1.getName(), Boolean.FALSE));
|
||||||
assertEquals(AbilityStatus.NOT_SUPPORTED, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1));
|
assertEquals(AbilityStatus.NOT_SUPPORTED, requestMeta.getConnectionAbility(AbilityKey.SERVER_TEST_1));
|
||||||
requestMeta.setAbilityTable(Collections.singletonMap(AbilityKey.SERVER_TEST_1.getName(), Boolean.TRUE));
|
requestMeta.setAbilityTable(Collections.singletonMap(AbilityKey.SERVER_TEST_1.getName(), Boolean.TRUE));
|
||||||
|
@ -16,23 +16,23 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.remote.request;
|
package com.alibaba.nacos.api.remote.request;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class RequestTest {
|
class RequestTest {
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHeader() {
|
void testHeader() {
|
||||||
MockRequest request = new MockRequest();
|
MockRequest request = new MockRequest();
|
||||||
assertTrue(request.getHeaders().isEmpty());
|
assertTrue(request.getHeaders().isEmpty());
|
||||||
assertNull(request.getHeader("clientIp"));
|
assertNull(request.getHeader("clientIp"));
|
||||||
|
@ -16,35 +16,38 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.remote.request;
|
package com.alibaba.nacos.api.remote.request;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class ServerReloadRequestTest extends BasicRequestTest {
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
class ServerReloadRequestTest extends BasicRequestTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws Exception {
|
void testSerialize() throws Exception {
|
||||||
ServerReloadRequest request = new ServerReloadRequest();
|
ServerReloadRequest request = new ServerReloadRequest();
|
||||||
request.setReloadCount(10);
|
request.setReloadCount(10);
|
||||||
request.setReloadServer("1.1.1.1");
|
request.setReloadServer("1.1.1.1");
|
||||||
request.setRequestId("1");
|
request.setRequestId("1");
|
||||||
String json = mapper.writeValueAsString(request);
|
String json = mapper.writeValueAsString(request);
|
||||||
System.out.println(json);
|
System.out.println(json);
|
||||||
Assert.assertNotNull(json);
|
assertNotNull(json);
|
||||||
Assert.assertTrue(json.contains("\"reloadCount\":10"));
|
assertTrue(json.contains("\"reloadCount\":10"));
|
||||||
Assert.assertTrue(json.contains("\"reloadServer\":\"1.1.1.1\""));
|
assertTrue(json.contains("\"reloadServer\":\"1.1.1.1\""));
|
||||||
Assert.assertTrue(json.contains("\"module\":\"internal\""));
|
assertTrue(json.contains("\"module\":\"internal\""));
|
||||||
Assert.assertTrue(json.contains("\"requestId\":\"1\""));
|
assertTrue(json.contains("\"requestId\":\"1\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws Exception {
|
void testDeserialize() throws Exception {
|
||||||
String json = "{\"headers\":{},\"requestId\":\"1\",\"reloadCount\":10,\"reloadServer\":\"1.1.1.1\","
|
String json = "{\"headers\":{},\"requestId\":\"1\",\"reloadCount\":10,\"reloadServer\":\"1.1.1.1\","
|
||||||
+ "\"module\":\"internal\"}";
|
+ "\"module\":\"internal\"}";
|
||||||
ServerReloadRequest result = mapper.readValue(json, ServerReloadRequest.class);
|
ServerReloadRequest result = mapper.readValue(json, ServerReloadRequest.class);
|
||||||
Assert.assertNotNull(result);
|
assertNotNull(result);
|
||||||
Assert.assertEquals(10, result.getReloadCount());
|
assertEquals(10, result.getReloadCount());
|
||||||
Assert.assertEquals("1.1.1.1", result.getReloadServer());
|
assertEquals("1.1.1.1", result.getReloadServer());
|
||||||
Assert.assertEquals("1", result.getRequestId());
|
assertEquals("1", result.getRequestId());
|
||||||
Assert.assertEquals("internal", result.getModule());
|
assertEquals("internal", result.getModule());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,34 +17,37 @@
|
|||||||
package com.alibaba.nacos.api.remote.request;
|
package com.alibaba.nacos.api.remote.request;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
public class SetupAckRequestTest extends BasicRequestTest {
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
class SetupAckRequestTest extends BasicRequestTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() throws Exception {
|
void testSerialize() throws Exception {
|
||||||
SetupAckRequest request = new SetupAckRequest(
|
SetupAckRequest request = new SetupAckRequest(
|
||||||
Collections.singletonMap(AbilityKey.SERVER_TEST_1.getName(), Boolean.TRUE));
|
Collections.singletonMap(AbilityKey.SERVER_TEST_1.getName(), Boolean.TRUE));
|
||||||
request.setRequestId("1");
|
request.setRequestId("1");
|
||||||
String json = mapper.writeValueAsString(request);
|
String json = mapper.writeValueAsString(request);
|
||||||
System.out.println(json);
|
System.out.println(json);
|
||||||
Assert.assertNotNull(json);
|
assertNotNull(json);
|
||||||
Assert.assertTrue(json.contains("\"abilityTable\":{\"test_1\":true}"));
|
assertTrue(json.contains("\"abilityTable\":{\"test_1\":true}"));
|
||||||
Assert.assertTrue(json.contains("\"module\":\"internal\""));
|
assertTrue(json.contains("\"module\":\"internal\""));
|
||||||
Assert.assertTrue(json.contains("\"requestId\":\"1\""));
|
assertTrue(json.contains("\"requestId\":\"1\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialize() throws Exception {
|
void testDeserialize() throws Exception {
|
||||||
String json =
|
String json =
|
||||||
"{\"headers\":{},\"requestId\":\"1\",\"abilityTable\":{\"test_1\":true}," + "\"module\":\"internal\"}";
|
"{\"headers\":{},\"requestId\":\"1\",\"abilityTable\":{\"test_1\":true}," + "\"module\":\"internal\"}";
|
||||||
SetupAckRequest result = mapper.readValue(json, SetupAckRequest.class);
|
SetupAckRequest result = mapper.readValue(json, SetupAckRequest.class);
|
||||||
Assert.assertNotNull(result);
|
assertNotNull(result);
|
||||||
Assert.assertTrue(result.getAbilityTable().get("test_1"));
|
assertTrue(result.getAbilityTable().get("test_1"));
|
||||||
Assert.assertEquals("1", result.getRequestId());
|
assertEquals("1", result.getRequestId());
|
||||||
Assert.assertEquals("internal", result.getModule());
|
assertEquals("internal", result.getModule());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,15 +20,15 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class EmptyContentResponseTest {
|
class EmptyContentResponseTest {
|
||||||
|
|
||||||
private static final String COMMON_JSON = "{\"resultCode\":200,\"errorCode\":0,\"requestId\":\"1\",\"success\":true}";
|
private static final String COMMON_JSON = "{\"resultCode\":200,\"errorCode\":0,\"requestId\":\"1\",\"success\":true}";
|
||||||
|
|
||||||
@ -36,14 +36,14 @@ public class EmptyContentResponseTest {
|
|||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetErrorInfo() {
|
void testSetErrorInfo() {
|
||||||
Response response = new Response() {
|
Response response = new Response() {
|
||||||
};
|
};
|
||||||
response.setErrorInfo(ResponseCode.FAIL.getCode(), ResponseCode.FAIL.getDesc());
|
response.setErrorInfo(ResponseCode.FAIL.getCode(), ResponseCode.FAIL.getDesc());
|
||||||
@ -53,7 +53,7 @@ public class EmptyContentResponseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testClientDetectionResponse() throws JsonProcessingException {
|
void testClientDetectionResponse() throws JsonProcessingException {
|
||||||
ClientDetectionResponse response = new ClientDetectionResponse();
|
ClientDetectionResponse response = new ClientDetectionResponse();
|
||||||
response.setRequestId("1");
|
response.setRequestId("1");
|
||||||
String actual = mapper.writeValueAsString(response);
|
String actual = mapper.writeValueAsString(response);
|
||||||
@ -63,7 +63,7 @@ public class EmptyContentResponseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectResetResponse() throws JsonProcessingException {
|
void testConnectResetResponse() throws JsonProcessingException {
|
||||||
ConnectResetResponse response = new ConnectResetResponse();
|
ConnectResetResponse response = new ConnectResetResponse();
|
||||||
response.setRequestId("1");
|
response.setRequestId("1");
|
||||||
String actual = mapper.writeValueAsString(response);
|
String actual = mapper.writeValueAsString(response);
|
||||||
@ -73,7 +73,7 @@ public class EmptyContentResponseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHealthCheckResponse() throws JsonProcessingException {
|
void testHealthCheckResponse() throws JsonProcessingException {
|
||||||
HealthCheckResponse response = new HealthCheckResponse();
|
HealthCheckResponse response = new HealthCheckResponse();
|
||||||
response.setRequestId("1");
|
response.setRequestId("1");
|
||||||
String actual = mapper.writeValueAsString(response);
|
String actual = mapper.writeValueAsString(response);
|
||||||
@ -83,7 +83,7 @@ public class EmptyContentResponseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testServerReloadResponse() throws JsonProcessingException {
|
void testServerReloadResponse() throws JsonProcessingException {
|
||||||
ServerReloadResponse response = new ServerReloadResponse();
|
ServerReloadResponse response = new ServerReloadResponse();
|
||||||
response.setRequestId("1");
|
response.setRequestId("1");
|
||||||
String actual = mapper.writeValueAsString(response);
|
String actual = mapper.writeValueAsString(response);
|
||||||
@ -93,7 +93,7 @@ public class EmptyContentResponseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetupAckResponse() throws JsonProcessingException {
|
void testSetupAckResponse() throws JsonProcessingException {
|
||||||
SetupAckResponse response = new SetupAckResponse();
|
SetupAckResponse response = new SetupAckResponse();
|
||||||
response.setRequestId("1");
|
response.setRequestId("1");
|
||||||
String actual = mapper.writeValueAsString(response);
|
String actual = mapper.writeValueAsString(response);
|
||||||
|
@ -18,59 +18,60 @@ package com.alibaba.nacos.api.remote.response;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import com.alibaba.nacos.api.exception.runtime.NacosRuntimeException;
|
import com.alibaba.nacos.api.exception.runtime.NacosRuntimeException;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class ErrorResponseTest {
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class ErrorResponseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildWithErrorCode() {
|
void testBuildWithErrorCode() {
|
||||||
int errorCode = 500;
|
int errorCode = 500;
|
||||||
String msg = "err msg";
|
String msg = "err msg";
|
||||||
|
|
||||||
Response response = ErrorResponse.build(errorCode, msg);
|
Response response = ErrorResponse.build(errorCode, msg);
|
||||||
|
|
||||||
Assert.assertEquals(errorCode, response.getErrorCode());
|
assertEquals(errorCode, response.getErrorCode());
|
||||||
Assert.assertEquals(errorCode, response.getResultCode());
|
assertEquals(errorCode, response.getResultCode());
|
||||||
Assert.assertEquals(msg, response.getMessage());
|
assertEquals(msg, response.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildWithThrowable() {
|
void testBuildWithThrowable() {
|
||||||
String errMsg = "exception msg";
|
String errMsg = "exception msg";
|
||||||
RuntimeException runtimeException = new RuntimeException(errMsg);
|
RuntimeException runtimeException = new RuntimeException(errMsg);
|
||||||
|
|
||||||
Response response = ErrorResponse.build(runtimeException);
|
Response response = ErrorResponse.build(runtimeException);
|
||||||
|
|
||||||
Assert.assertEquals(ResponseCode.FAIL.getCode(), response.getErrorCode());
|
assertEquals(ResponseCode.FAIL.getCode(), response.getErrorCode());
|
||||||
Assert.assertEquals(ResponseCode.FAIL.getCode(), response.getResultCode());
|
assertEquals(ResponseCode.FAIL.getCode(), response.getResultCode());
|
||||||
Assert.assertEquals(errMsg, response.getMessage());
|
assertEquals(errMsg, response.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildWithNacosException() {
|
void testBuildWithNacosException() {
|
||||||
int errCode = 500;
|
int errCode = 500;
|
||||||
String errMsg = "nacos exception msg";
|
String errMsg = "nacos exception msg";
|
||||||
NacosException nacosException = new NacosException(errCode, errMsg);
|
NacosException nacosException = new NacosException(errCode, errMsg);
|
||||||
|
|
||||||
Response response = ErrorResponse.build(nacosException);
|
Response response = ErrorResponse.build(nacosException);
|
||||||
|
|
||||||
Assert.assertEquals(errCode, response.getErrorCode());
|
assertEquals(errCode, response.getErrorCode());
|
||||||
Assert.assertEquals(errCode, response.getResultCode());
|
assertEquals(errCode, response.getResultCode());
|
||||||
Assert.assertEquals(errMsg, response.getMessage());
|
assertEquals(errMsg, response.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildWithNacosRuntimeException() {
|
void testBuildWithNacosRuntimeException() {
|
||||||
int errCode = 500;
|
int errCode = 500;
|
||||||
String errMsg = "nacos runtime exception msg";
|
String errMsg = "nacos runtime exception msg";
|
||||||
NacosRuntimeException nacosRuntimeException = new NacosRuntimeException(errCode, errMsg);
|
NacosRuntimeException nacosRuntimeException = new NacosRuntimeException(errCode, errMsg);
|
||||||
|
|
||||||
Response response = ErrorResponse.build(nacosRuntimeException);
|
Response response = ErrorResponse.build(nacosRuntimeException);
|
||||||
|
|
||||||
Assert.assertEquals(errCode, response.getErrorCode());
|
assertEquals(errCode, response.getErrorCode());
|
||||||
Assert.assertEquals(errCode, response.getResultCode());
|
assertEquals(errCode, response.getResultCode());
|
||||||
Assert.assertEquals("errCode: " + errCode + ", errMsg: " + errMsg + " ", response.getMessage());
|
assertEquals("errCode: " + errCode + ", errMsg: " + errMsg + " ", response.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,24 +20,24 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServerCheckResponseTest {
|
class ServerCheckResponseTest {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialization() throws JsonProcessingException {
|
void testSerialization() throws JsonProcessingException {
|
||||||
ServerCheckResponse response = new ServerCheckResponse("35643245_1.1.1.1_3306", false);
|
ServerCheckResponse response = new ServerCheckResponse("35643245_1.1.1.1_3306", false);
|
||||||
String actual = mapper.writeValueAsString(response);
|
String actual = mapper.writeValueAsString(response);
|
||||||
assertTrue(actual.contains("\"connectionId\":\"35643245_1.1.1.1_3306\""));
|
assertTrue(actual.contains("\"connectionId\":\"35643245_1.1.1.1_3306\""));
|
||||||
@ -45,7 +45,7 @@ public class ServerCheckResponseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialization() throws JsonProcessingException {
|
void testDeserialization() throws JsonProcessingException {
|
||||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"connectionId\":\"35643245_1.1.1.1_3306\",\"success\":true,"
|
String json = "{\"resultCode\":200,\"errorCode\":0,\"connectionId\":\"35643245_1.1.1.1_3306\",\"success\":true,"
|
||||||
+ "\"supportAbilityNegotiation\":true}";
|
+ "\"supportAbilityNegotiation\":true}";
|
||||||
ServerCheckResponse response = mapper.readValue(json, ServerCheckResponse.class);
|
ServerCheckResponse response = mapper.readValue(json, ServerCheckResponse.class);
|
||||||
|
@ -20,24 +20,24 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ServerLoaderInfoResponseTest {
|
class ServerLoaderInfoResponseTest {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialization() throws JsonProcessingException {
|
void testSerialization() throws JsonProcessingException {
|
||||||
ServerLoaderInfoResponse response = new ServerLoaderInfoResponse();
|
ServerLoaderInfoResponse response = new ServerLoaderInfoResponse();
|
||||||
response.putMetricsValue("test", "testValue");
|
response.putMetricsValue("test", "testValue");
|
||||||
String actual = mapper.writeValueAsString(response);
|
String actual = mapper.writeValueAsString(response);
|
||||||
@ -46,7 +46,7 @@ public class ServerLoaderInfoResponseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialization() throws JsonProcessingException {
|
void testDeserialization() throws JsonProcessingException {
|
||||||
String json = "{\"resultCode\":200,\"errorCode\":0,\"loaderMetrics\":{\"test\":\"testValue\"},\"success\":true}";
|
String json = "{\"resultCode\":200,\"errorCode\":0,\"loaderMetrics\":{\"test\":\"testValue\"},\"success\":true}";
|
||||||
ServerLoaderInfoResponse response = mapper.readValue(json, ServerLoaderInfoResponse.class);
|
ServerLoaderInfoResponse response = mapper.readValue(json, ServerLoaderInfoResponse.class);
|
||||||
assertEquals(1, response.getLoaderMetrics().size());
|
assertEquals(1, response.getLoaderMetrics().size());
|
||||||
|
@ -20,29 +20,29 @@ import com.alibaba.nacos.api.cmdb.pojo.Entity;
|
|||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import com.alibaba.nacos.api.selector.context.CmdbContext;
|
import com.alibaba.nacos.api.selector.context.CmdbContext;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static com.alibaba.nacos.api.common.Constants.Naming.CMDB_CONTEXT_TYPE;
|
import static com.alibaba.nacos.api.common.Constants.Naming.CMDB_CONTEXT_TYPE;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class AbstractCmdbSelectorTest {
|
class AbstractCmdbSelectorTest {
|
||||||
|
|
||||||
private AtomicInteger counter;
|
private AtomicInteger counter;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
void setUp() {
|
||||||
counter = new AtomicInteger();
|
counter = new AtomicInteger();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetExpression() {
|
void testSetExpression() {
|
||||||
MockCmdbSelector cmdbSelector = new MockCmdbSelector();
|
MockCmdbSelector cmdbSelector = new MockCmdbSelector();
|
||||||
assertNull(cmdbSelector.getExpression());
|
assertNull(cmdbSelector.getExpression());
|
||||||
cmdbSelector.setExpression("test");
|
cmdbSelector.setExpression("test");
|
||||||
@ -50,7 +50,7 @@ public class AbstractCmdbSelectorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParse() throws NacosException {
|
void testParse() throws NacosException {
|
||||||
MockCmdbSelector cmdbSelector = new MockCmdbSelector();
|
MockCmdbSelector cmdbSelector = new MockCmdbSelector();
|
||||||
cmdbSelector.parse("test");
|
cmdbSelector.parse("test");
|
||||||
assertEquals("test", cmdbSelector.getExpression());
|
assertEquals("test", cmdbSelector.getExpression());
|
||||||
@ -58,7 +58,7 @@ public class AbstractCmdbSelectorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSelect() {
|
void testSelect() {
|
||||||
CmdbContext<Instance> context = new CmdbContext<>();
|
CmdbContext<Instance> context = new CmdbContext<>();
|
||||||
CmdbContext.CmdbInstance<Instance> provider = new CmdbContext.CmdbInstance<>();
|
CmdbContext.CmdbInstance<Instance> provider = new CmdbContext.CmdbInstance<>();
|
||||||
provider.setInstance(new Instance());
|
provider.setInstance(new Instance());
|
||||||
@ -78,12 +78,12 @@ public class AbstractCmdbSelectorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetContextType() {
|
void testGetContextType() {
|
||||||
assertEquals(CMDB_CONTEXT_TYPE, new MockCmdbSelector().getContextType());
|
assertEquals(CMDB_CONTEXT_TYPE, new MockCmdbSelector().getContextType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetType() {
|
void testGetType() {
|
||||||
assertEquals("mock", new MockCmdbSelector().getType());
|
assertEquals("mock", new MockCmdbSelector().getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,25 +21,25 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.jsontype.NamedType;
|
import com.fasterxml.jackson.databind.jsontype.NamedType;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ExpressionSelectorTest {
|
class ExpressionSelectorTest {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
mapper.registerSubtypes(new NamedType(ExpressionSelector.class, SelectorType.label.name()));
|
mapper.registerSubtypes(new NamedType(ExpressionSelector.class, SelectorType.label.name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialization() throws JsonProcessingException {
|
void testSerialization() throws JsonProcessingException {
|
||||||
ExpressionSelector selector = new ExpressionSelector();
|
ExpressionSelector selector = new ExpressionSelector();
|
||||||
selector.setExpression("test expression");
|
selector.setExpression("test expression");
|
||||||
String actual = mapper.writeValueAsString(selector);
|
String actual = mapper.writeValueAsString(selector);
|
||||||
@ -48,7 +48,7 @@ public class ExpressionSelectorTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialization() throws JsonProcessingException {
|
void testDeserialization() throws JsonProcessingException {
|
||||||
String json = "{\"type\":\"label\",\"expression\":\"test expression\"}";
|
String json = "{\"type\":\"label\",\"expression\":\"test expression\"}";
|
||||||
AbstractSelector actual = mapper.readValue(json, AbstractSelector.class);
|
AbstractSelector actual = mapper.readValue(json, AbstractSelector.class);
|
||||||
assertEquals(SelectorType.label.name(), actual.getType());
|
assertEquals(SelectorType.label.name(), actual.getType());
|
||||||
|
@ -21,32 +21,32 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.databind.jsontype.NamedType;
|
import com.fasterxml.jackson.databind.jsontype.NamedType;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class NoneSelectorTest {
|
class NoneSelectorTest {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||||
mapper.registerSubtypes(new NamedType(NoneSelector.class, SelectorType.none.name()));
|
mapper.registerSubtypes(new NamedType(NoneSelector.class, SelectorType.none.name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialization() throws JsonProcessingException {
|
void testSerialization() throws JsonProcessingException {
|
||||||
NoneSelector selector = new NoneSelector();
|
NoneSelector selector = new NoneSelector();
|
||||||
String actual = mapper.writeValueAsString(selector);
|
String actual = mapper.writeValueAsString(selector);
|
||||||
assertTrue(actual.contains("\"type\":\"" + SelectorType.none.name() + "\""));
|
assertTrue(actual.contains("\"type\":\"" + SelectorType.none.name() + "\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeserialization() throws JsonProcessingException {
|
void testDeserialization() throws JsonProcessingException {
|
||||||
String json = "{\"type\":\"none\"}";
|
String json = "{\"type\":\"none\"}";
|
||||||
AbstractSelector actual = mapper.readValue(json, AbstractSelector.class);
|
AbstractSelector actual = mapper.readValue(json, AbstractSelector.class);
|
||||||
assertEquals(SelectorType.none.name(), actual.getType());
|
assertEquals(SelectorType.none.name(), actual.getType());
|
||||||
|
@ -17,16 +17,16 @@
|
|||||||
package com.alibaba.nacos.api.selector.context;
|
package com.alibaba.nacos.api.selector.context;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class CmdbContextTest {
|
class CmdbContextTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString() {
|
void testToString() {
|
||||||
CmdbContext<Instance> cmdbContext = new CmdbContext<>();
|
CmdbContext<Instance> cmdbContext = new CmdbContext<>();
|
||||||
cmdbContext.setProviders(Collections.singletonList(new CmdbContext.CmdbInstance<>()));
|
cmdbContext.setProviders(Collections.singletonList(new CmdbContext.CmdbInstance<>()));
|
||||||
cmdbContext.setConsumer(new CmdbContext.CmdbInstance<>());
|
cmdbContext.setConsumer(new CmdbContext.CmdbInstance<>());
|
||||||
|
@ -18,26 +18,28 @@ package com.alibaba.nacos.api.utils;
|
|||||||
|
|
||||||
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
import com.alibaba.nacos.api.ability.constant.AbilityKey;
|
||||||
import com.alibaba.nacos.api.ability.constant.AbilityMode;
|
import com.alibaba.nacos.api.ability.constant.AbilityMode;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
/**.
|
/**
|
||||||
|
* .
|
||||||
|
*
|
||||||
* @author Daydreamer
|
* @author Daydreamer
|
||||||
* @description Ability key test
|
* @description Ability key test
|
||||||
* @date 2022/9/8 12:27
|
* @date 2022/9/8 12:27
|
||||||
**/
|
**/
|
||||||
public class AbilityKeyTest {
|
class AbilityKeyTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMapStr() {
|
void testMapStr() {
|
||||||
Map<AbilityKey, Boolean> enumMap = new HashMap<>();
|
Map<AbilityKey, Boolean> enumMap = new HashMap<>();
|
||||||
Map<String, Boolean> stringBooleanMap = AbilityKey.mapStr(enumMap);
|
Map<String, Boolean> stringBooleanMap = AbilityKey.mapStr(enumMap);
|
||||||
assertEquals(0, stringBooleanMap.size());
|
assertEquals(0, stringBooleanMap.size());
|
||||||
@ -47,27 +49,27 @@ public class AbilityKeyTest {
|
|||||||
enumMap.put(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC, false);
|
enumMap.put(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC, false);
|
||||||
stringBooleanMap = AbilityKey.mapStr(enumMap);
|
stringBooleanMap = AbilityKey.mapStr(enumMap);
|
||||||
assertEquals(3, stringBooleanMap.size());
|
assertEquals(3, stringBooleanMap.size());
|
||||||
Assert.assertTrue(stringBooleanMap.get(AbilityKey.SERVER_TEST_1.getName()));
|
assertTrue(stringBooleanMap.get(AbilityKey.SERVER_TEST_1.getName()));
|
||||||
Assert.assertFalse(stringBooleanMap.get(AbilityKey.SERVER_TEST_2.getName()));
|
assertFalse(stringBooleanMap.get(AbilityKey.SERVER_TEST_2.getName()));
|
||||||
Assert.assertFalse(stringBooleanMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC.getName()));
|
assertFalse(stringBooleanMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC.getName()));
|
||||||
|
|
||||||
enumMap.put(AbilityKey.SERVER_TEST_2, true);
|
enumMap.put(AbilityKey.SERVER_TEST_2, true);
|
||||||
enumMap.put(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC, true);
|
enumMap.put(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC, true);
|
||||||
stringBooleanMap = AbilityKey.mapStr(enumMap);
|
stringBooleanMap = AbilityKey.mapStr(enumMap);
|
||||||
assertEquals(3, stringBooleanMap.size());
|
assertEquals(3, stringBooleanMap.size());
|
||||||
Assert.assertTrue(stringBooleanMap.get(AbilityKey.SERVER_TEST_1.getName()));
|
assertTrue(stringBooleanMap.get(AbilityKey.SERVER_TEST_1.getName()));
|
||||||
Assert.assertTrue(stringBooleanMap.get(AbilityKey.SERVER_TEST_2.getName()));
|
assertTrue(stringBooleanMap.get(AbilityKey.SERVER_TEST_2.getName()));
|
||||||
Assert.assertTrue(stringBooleanMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC.getName()));
|
assertTrue(stringBooleanMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMapEnumForEmpty() {
|
void testMapEnumForEmpty() {
|
||||||
Map<AbilityKey, Boolean> actual = AbilityKey.mapEnum(AbilityMode.SERVER, Collections.emptyMap());
|
Map<AbilityKey, Boolean> actual = AbilityKey.mapEnum(AbilityMode.SERVER, Collections.emptyMap());
|
||||||
assertTrue(actual.isEmpty());
|
assertTrue(actual.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMapEnum() {
|
void testMapEnum() {
|
||||||
Map<String, Boolean> mapStr = new HashMap<>();
|
Map<String, Boolean> mapStr = new HashMap<>();
|
||||||
mapStr.put("test-no-existed", true);
|
mapStr.put("test-no-existed", true);
|
||||||
Map<AbilityKey, Boolean> enumMap = AbilityKey.mapEnum(AbilityMode.SERVER, mapStr);
|
Map<AbilityKey, Boolean> enumMap = AbilityKey.mapEnum(AbilityMode.SERVER, mapStr);
|
||||||
@ -77,23 +79,23 @@ public class AbilityKeyTest {
|
|||||||
mapStr.put(AbilityKey.SERVER_TEST_1.getName(), true);
|
mapStr.put(AbilityKey.SERVER_TEST_1.getName(), true);
|
||||||
mapStr.put(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC.getName(), true);
|
mapStr.put(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC.getName(), true);
|
||||||
enumMap = AbilityKey.mapEnum(AbilityMode.SERVER, mapStr);
|
enumMap = AbilityKey.mapEnum(AbilityMode.SERVER, mapStr);
|
||||||
Assert.assertFalse(enumMap.get(AbilityKey.SERVER_TEST_2));
|
assertFalse(enumMap.get(AbilityKey.SERVER_TEST_2));
|
||||||
Assert.assertTrue(enumMap.get(AbilityKey.SERVER_TEST_1));
|
assertTrue(enumMap.get(AbilityKey.SERVER_TEST_1));
|
||||||
Assert.assertTrue(enumMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC));
|
assertTrue(enumMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC));
|
||||||
|
|
||||||
mapStr.clear();
|
mapStr.clear();
|
||||||
mapStr.put(AbilityKey.SERVER_TEST_2.getName(), true);
|
mapStr.put(AbilityKey.SERVER_TEST_2.getName(), true);
|
||||||
mapStr.put(AbilityKey.SERVER_TEST_1.getName(), true);
|
mapStr.put(AbilityKey.SERVER_TEST_1.getName(), true);
|
||||||
mapStr.put(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC.getName(), true);
|
mapStr.put(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC.getName(), true);
|
||||||
enumMap = AbilityKey.mapEnum(AbilityMode.SERVER, mapStr);
|
enumMap = AbilityKey.mapEnum(AbilityMode.SERVER, mapStr);
|
||||||
Assert.assertTrue(enumMap.get(AbilityKey.SERVER_TEST_2));
|
assertTrue(enumMap.get(AbilityKey.SERVER_TEST_2));
|
||||||
Assert.assertTrue(enumMap.get(AbilityKey.SERVER_TEST_1));
|
assertTrue(enumMap.get(AbilityKey.SERVER_TEST_1));
|
||||||
Assert.assertTrue(enumMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC));
|
assertTrue(enumMap.get(AbilityKey.SERVER_SUPPORT_PERSISTENT_INSTANCE_BY_GRPC));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAllValues() {
|
void testGetAllValues() {
|
||||||
Collection<AbilityKey> actual = AbilityKey.getAllValues(AbilityMode.SERVER);
|
Collection<AbilityKey> actual = AbilityKey.getAllValues(AbilityMode.SERVER);
|
||||||
assertEquals(3, actual.size());
|
assertEquals(3, actual.size());
|
||||||
actual = AbilityKey.getAllValues(AbilityMode.SDK_CLIENT);
|
actual = AbilityKey.getAllValues(AbilityMode.SDK_CLIENT);
|
||||||
@ -103,7 +105,7 @@ public class AbilityKeyTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAllNames() {
|
void testGetAllNames() {
|
||||||
Collection<String> actual = AbilityKey.getAllNames(AbilityMode.SERVER);
|
Collection<String> actual = AbilityKey.getAllNames(AbilityMode.SERVER);
|
||||||
assertEquals(3, actual.size());
|
assertEquals(3, actual.size());
|
||||||
actual = AbilityKey.getAllNames(AbilityMode.SDK_CLIENT);
|
actual = AbilityKey.getAllNames(AbilityMode.SDK_CLIENT);
|
||||||
@ -113,7 +115,7 @@ public class AbilityKeyTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDescription() {
|
void testGetDescription() {
|
||||||
assertEquals("just for junit test", AbilityKey.SERVER_TEST_1.getDescription());
|
assertEquals("just for junit test", AbilityKey.SERVER_TEST_1.getDescription());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,22 +16,22 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.utils;
|
package com.alibaba.nacos.api.utils;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class NetUtilsTest {
|
class NetUtilsTest {
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void tearDown() throws Exception {
|
void tearDown() throws Exception {
|
||||||
Class<?> clazz = Class.forName("com.alibaba.nacos.api.utils.NetUtils");
|
Class<?> clazz = Class.forName("com.alibaba.nacos.api.utils.NetUtils");
|
||||||
Field field = clazz.getDeclaredField("localIp");
|
Field field = clazz.getDeclaredField("localIp");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
@ -42,7 +42,7 @@ public class NetUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocalIpWithSpecifiedIp() {
|
void testLocalIpWithSpecifiedIp() {
|
||||||
System.setProperty("com.alibaba.nacos.client.local.ip", "10.2.8.8");
|
System.setProperty("com.alibaba.nacos.client.local.ip", "10.2.8.8");
|
||||||
assertEquals("10.2.8.8", NetUtils.localIP());
|
assertEquals("10.2.8.8", NetUtils.localIP());
|
||||||
System.setProperty("com.alibaba.nacos.client.local.ip", "10.2.8.9");
|
System.setProperty("com.alibaba.nacos.client.local.ip", "10.2.8.9");
|
||||||
@ -50,7 +50,7 @@ public class NetUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocalIpWithPreferHostname() throws Exception {
|
void testLocalIpWithPreferHostname() throws Exception {
|
||||||
InetAddress inetAddress = invokeGetInetAddress();
|
InetAddress inetAddress = invokeGetInetAddress();
|
||||||
String hostname = inetAddress.getHostName();
|
String hostname = inetAddress.getHostName();
|
||||||
System.setProperty("com.alibaba.nacos.client.local.preferHostname", "true");
|
System.setProperty("com.alibaba.nacos.client.local.preferHostname", "true");
|
||||||
@ -58,14 +58,14 @@ public class NetUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocalIpWithoutPreferHostname() throws Exception {
|
void testLocalIpWithoutPreferHostname() throws Exception {
|
||||||
InetAddress inetAddress = invokeGetInetAddress();
|
InetAddress inetAddress = invokeGetInetAddress();
|
||||||
String ip = inetAddress.getHostAddress();
|
String ip = inetAddress.getHostAddress();
|
||||||
assertEquals(ip, NetUtils.localIP());
|
assertEquals(ip, NetUtils.localIP());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocalIpWithException() throws Exception {
|
void testLocalIpWithException() throws Exception {
|
||||||
Field field = System.class.getDeclaredField("props");
|
Field field = System.class.getDeclaredField("props");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
Properties properties = (Properties) field.get(null);
|
Properties properties = (Properties) field.get(null);
|
||||||
|
@ -16,94 +16,98 @@
|
|||||||
|
|
||||||
package com.alibaba.nacos.api.utils;
|
package com.alibaba.nacos.api.utils;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class StringUtilsTest {
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
class StringUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsEmpty() {
|
void testIsEmpty() {
|
||||||
Assert.assertTrue(StringUtils.isEmpty(null));
|
assertTrue(StringUtils.isEmpty(null));
|
||||||
Assert.assertTrue(StringUtils.isEmpty(""));
|
assertTrue(StringUtils.isEmpty(""));
|
||||||
Assert.assertFalse(StringUtils.isEmpty(" "));
|
assertFalse(StringUtils.isEmpty(" "));
|
||||||
Assert.assertFalse(StringUtils.isEmpty("bob"));
|
assertFalse(StringUtils.isEmpty("bob"));
|
||||||
Assert.assertFalse(StringUtils.isEmpty(" bob "));
|
assertFalse(StringUtils.isEmpty(" bob "));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsBlank() {
|
void testIsBlank() {
|
||||||
Assert.assertTrue(StringUtils.isBlank(null));
|
assertTrue(StringUtils.isBlank(null));
|
||||||
Assert.assertTrue(StringUtils.isBlank(""));
|
assertTrue(StringUtils.isBlank(""));
|
||||||
Assert.assertTrue(StringUtils.isBlank(" "));
|
assertTrue(StringUtils.isBlank(" "));
|
||||||
Assert.assertFalse(StringUtils.isBlank("bob"));
|
assertFalse(StringUtils.isBlank("bob"));
|
||||||
Assert.assertFalse(StringUtils.isBlank(" bob "));
|
assertFalse(StringUtils.isBlank(" bob "));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTrim() {
|
void testTrim() {
|
||||||
Assert.assertNull(StringUtils.trim(null));
|
assertNull(StringUtils.trim(null));
|
||||||
Assert.assertEquals(StringUtils.EMPTY, StringUtils.trim(""));
|
assertEquals(StringUtils.EMPTY, StringUtils.trim(""));
|
||||||
Assert.assertEquals(StringUtils.EMPTY, StringUtils.trim(" "));
|
assertEquals(StringUtils.EMPTY, StringUtils.trim(" "));
|
||||||
Assert.assertEquals("abc", StringUtils.trim("abc"));
|
assertEquals("abc", StringUtils.trim("abc"));
|
||||||
Assert.assertEquals("abc", StringUtils.trim(" abc "));
|
assertEquals("abc", StringUtils.trim(" abc "));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquals() {
|
void testEquals() {
|
||||||
Assert.assertTrue(StringUtils.equals(null, null));
|
assertTrue(StringUtils.equals(null, null));
|
||||||
Assert.assertFalse(StringUtils.equals(null, "abc"));
|
assertFalse(StringUtils.equals(null, "abc"));
|
||||||
Assert.assertFalse(StringUtils.equals("abc", null));
|
assertFalse(StringUtils.equals("abc", null));
|
||||||
Assert.assertTrue(StringUtils.equals("abc", "abc"));
|
assertTrue(StringUtils.equals("abc", "abc"));
|
||||||
Assert.assertFalse(StringUtils.equals("abc", "ABC"));
|
assertFalse(StringUtils.equals("abc", "ABC"));
|
||||||
Assert.assertTrue(StringUtils.equals(new StringBuilder("abc"), "abc"));
|
assertTrue(StringUtils.equals(new StringBuilder("abc"), "abc"));
|
||||||
Assert.assertFalse(StringUtils.equals(new StringBuilder("ABC"), "abc"));
|
assertFalse(StringUtils.equals(new StringBuilder("ABC"), "abc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegionMatchesEqualsCaseSensitive() {
|
void testRegionMatchesEqualsCaseSensitive() {
|
||||||
Assert.assertTrue(StringUtils.regionMatches("abc", false, 0, "xabc", 1, 3));
|
assertTrue(StringUtils.regionMatches("abc", false, 0, "xabc", 1, 3));
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRegionMatchesEqualsCaseInsensitive() {
|
|
||||||
Assert.assertTrue(StringUtils.regionMatches("abc", true, 0, "xabc", 1, 3));
|
|
||||||
Assert.assertTrue(StringUtils.regionMatches("abc", true, 0, "xAbc", 1, 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRegionMatchesNotEqualsCaseSensitive() {
|
|
||||||
Assert.assertFalse(StringUtils.regionMatches("abc", false, 0, "xAbc", 1, 3));
|
|
||||||
Assert.assertFalse(StringUtils.regionMatches("abc", false, 0, "xCbc", 1, 3));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegionMatchesNotEqualsCaseInsensitive() {
|
void testRegionMatchesEqualsCaseInsensitive() {
|
||||||
Assert.assertFalse(StringUtils.regionMatches("abc", true, 0, "xCab", 1, 3));
|
assertTrue(StringUtils.regionMatches("abc", true, 0, "xabc", 1, 3));
|
||||||
|
assertTrue(StringUtils.regionMatches("abc", true, 0, "xAbc", 1, 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegionMatchesEqualsCaseSensitiveForNonString() {
|
void testRegionMatchesNotEqualsCaseSensitive() {
|
||||||
Assert.assertTrue(StringUtils.regionMatches(new StringBuilder("abc"), false, 0, "xabc", 1, 3));
|
assertFalse(StringUtils.regionMatches("abc", false, 0, "xAbc", 1, 3));
|
||||||
|
assertFalse(StringUtils.regionMatches("abc", false, 0, "xCbc", 1, 3));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegionMatchesEqualsCaseInsensitiveForNonString() {
|
void testRegionMatchesNotEqualsCaseInsensitive() {
|
||||||
Assert.assertTrue(StringUtils.regionMatches(new StringBuilder("abc"), true, 0, "xabc", 1, 3));
|
assertFalse(StringUtils.regionMatches("abc", true, 0, "xCab", 1, 3));
|
||||||
Assert.assertTrue(StringUtils.regionMatches(new StringBuilder("abc"), true, 0, "xAbc", 1, 3));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegionMatchesNotEqualsCaseSensitiveForNonString() {
|
void testRegionMatchesEqualsCaseSensitiveForNonString() {
|
||||||
Assert.assertFalse(StringUtils.regionMatches(new StringBuilder("abc"), false, 0, "xAbc", 1, 3));
|
assertTrue(StringUtils.regionMatches(new StringBuilder("abc"), false, 0, "xabc", 1, 3));
|
||||||
Assert.assertFalse(StringUtils.regionMatches(new StringBuilder("abc"), false, 0, "xCbc", 1, 3));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRegionMatchesNotEqualsCaseInsensitiveForNonString() {
|
void testRegionMatchesEqualsCaseInsensitiveForNonString() {
|
||||||
Assert.assertFalse(StringUtils.regionMatches(new StringBuilder("abc"), true, 0, "xCab", 1, 3));
|
assertTrue(StringUtils.regionMatches(new StringBuilder("abc"), true, 0, "xabc", 1, 3));
|
||||||
|
assertTrue(StringUtils.regionMatches(new StringBuilder("abc"), true, 0, "xAbc", 1, 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testRegionMatchesNotEqualsCaseSensitiveForNonString() {
|
||||||
|
assertFalse(StringUtils.regionMatches(new StringBuilder("abc"), false, 0, "xAbc", 1, 3));
|
||||||
|
assertFalse(StringUtils.regionMatches(new StringBuilder("abc"), false, 0, "xCbc", 1, 3));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testRegionMatchesNotEqualsCaseInsensitiveForNonString() {
|
||||||
|
assertFalse(StringUtils.regionMatches(new StringBuilder("abc"), true, 0, "xCab", 1, 3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user