diff --git a/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java b/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java index 351454fabf8..7abd023c5b8 100644 --- a/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java +++ b/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/CPInstancesAPI_ITCase.java @@ -24,12 +24,14 @@ import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.ListView; import com.alibaba.nacos.common.utils.JacksonUtils; +import com.alibaba.nacos.core.namespace.repository.NamespacePersistService; import com.alibaba.nacos.test.base.Params; import com.fasterxml.jackson.databind.JsonNode; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; @@ -41,6 +43,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; /** * @author nkorange @@ -55,6 +58,9 @@ class CPInstancesAPI_ITCase extends NamingBase { private NamingService naming2; + @MockBean + private NamespacePersistService namespacePersistService; + @LocalServerPort private int port; @@ -75,6 +81,8 @@ void setUp() throws Exception { properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1" + ":" + port); naming2 = NamingFactory.createNamingService(properties); isNamingServerReady(); + when(namespacePersistService.tenantInfoCountByTenantId(TEST_NAMESPACE_1)).thenReturn(1); + when(namespacePersistService.tenantInfoCountByTenantId(TEST_NAMESPACE_2)).thenReturn(1); } @AfterEach diff --git a/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_ITCase.java b/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_ITCase.java index 9f9b2d8a89a..8aa1208eae5 100644 --- a/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_ITCase.java +++ b/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_ITCase.java @@ -26,10 +26,12 @@ import com.alibaba.nacos.api.naming.listener.NamingEvent; import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.ListView; +import com.alibaba.nacos.core.namespace.repository.NamespacePersistService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.web.server.LocalServerPort; import java.util.Arrays; @@ -50,6 +52,7 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; /** * @author nkorange @@ -64,6 +67,9 @@ class MultiTenant_ITCase { private NamingService naming2; + @MockBean + private NamespacePersistService namespacePersistService; + @LocalServerPort private int port; @@ -93,6 +99,10 @@ void init() throws Exception { properties.put(PropertyKeyConst.NAMESPACE, "namespace-2"); properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1" + ":" + port); naming2 = NamingFactory.createNamingService(properties); + + + when(namespacePersistService.tenantInfoCountByTenantId("namespace-1")).thenReturn(1); + when(namespacePersistService.tenantInfoCountByTenantId("namespace-2")).thenReturn(1); } /** diff --git a/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_InstanceAPI_ITCase.java b/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_InstanceAPI_ITCase.java index 7336f0f5b48..0d8ba5bca1e 100644 --- a/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_InstanceAPI_ITCase.java +++ b/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/MultiTenant_InstanceAPI_ITCase.java @@ -22,12 +22,15 @@ import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.common.utils.JacksonUtils; +import com.alibaba.nacos.core.namespace.repository.NamespacePersistService; import com.alibaba.nacos.test.base.Params; import com.fasterxml.jackson.databind.JsonNode; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpEntity; @@ -49,6 +52,7 @@ import static com.alibaba.nacos.test.naming.NamingBase.randomDomainName; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.when; /** * @author nkorange @@ -71,6 +75,9 @@ class MultiTenant_InstanceAPI_ITCase { @Autowired private TestRestTemplate restTemplate; + @MockBean + private NamespacePersistService namespacePersistService; + private URL base; @BeforeEach @@ -100,6 +107,9 @@ void init() throws Exception { properties.put(PropertyKeyConst.NAMESPACE, "namespace-2"); properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1" + ":" + port); naming2 = NamingFactory.createNamingService(properties); + + when(namespacePersistService.tenantInfoCountByTenantId("namespace-1")).thenReturn(1); + when(namespacePersistService.tenantInfoCountByTenantId("namespace-2")).thenReturn(1); } /** diff --git a/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/Subscribe_ITCase.java b/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/Subscribe_ITCase.java index f88334411dc..e7008adc390 100644 --- a/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/Subscribe_ITCase.java +++ b/test/naming-test/src/test/java/com/alibaba/nacos/test/naming/Subscribe_ITCase.java @@ -27,12 +27,14 @@ import com.alibaba.nacos.client.naming.listener.NamingChangeEvent; import com.alibaba.nacos.common.utils.ConcurrentHashSet; import com.alibaba.nacos.common.utils.JacksonUtils; +import com.alibaba.nacos.core.namespace.repository.NamespacePersistService; import com.alibaba.nacos.test.base.Params; import com.fasterxml.jackson.databind.JsonNode; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; @@ -47,6 +49,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.Mockito.when; /** * Created by wangtong.wt on 2018/6/20. @@ -65,6 +68,9 @@ class Subscribe_ITCase extends NamingBase { private volatile List instances = Collections.emptyList(); + @MockBean + private NamespacePersistService namespacePersistService; + @BeforeEach void init() throws Exception { instances.clear(); @@ -272,6 +278,8 @@ void subscribeSameServiceForTwoNamingService() throws Exception { Properties properties2 = new Properties(); properties2.setProperty("serverAddr", "127.0.0.1" + ":" + port); properties2.setProperty("namespace", "ns-002"); + when(namespacePersistService.tenantInfoCountByTenantId("ns-001")).thenReturn(1); + when(namespacePersistService.tenantInfoCountByTenantId("ns-002")).thenReturn(1); final NamingService naming2 = NamingFactory.createNamingService(properties2); final ConcurrentHashSet concurrentHashSet1 = new ConcurrentHashSet();