Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #3249] Use new code style for nacos-config module/test. #3290

Merged
merged 1 commit into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>1.3.1-BETA</version>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>nacos-config</artifactId>
<packaging>jar</packaging>

<name>nacos-config ${project.version}</name>
<url>http://nacos.io</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -81,7 +81,7 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>

<!-- for aop -->
<dependency>
<groupId>org.aspectj</groupId>
Expand All @@ -95,13 +95,13 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
</dependency>

<!-- Provided -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.config.server.constant;

import org.junit.Assert;
Expand All @@ -26,17 +27,11 @@
import static com.alibaba.nacos.config.server.constant.Constants.LISTENER_CONTROLLER_PATH;
import static com.alibaba.nacos.config.server.constant.Constants.NAMESPACE_CONTROLLER_PATH;

/**
* {@link Constants} Test
*
* @author <a href="mailto:[email protected]">Mercy</a>
* @since 0.2.2
*/
public class ConstantsTest {

@Test
public void testControllerPathsDefaultValues() {

Assert.assertEquals("/v1/cs/capacity", CAPACITY_CONTROLLER_PATH);
Assert.assertEquals("/v1/cs/communication", COMMUNICATION_CONTROLLER_PATH);
Assert.assertEquals("/v1/cs/configs", CONFIG_CONTROLLER_PATH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.config.server.controller;

import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.service.datasource.DataSourceService;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -31,37 +34,31 @@
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.service.datasource.DataSourceService;

/**
* Created by qingliang on 2017/8/14.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = MockServletContext.class)
@WebAppConfiguration
public class HealthControllerUnitTest {

@InjectMocks
HealthController healthController;

@Mock
DataSourceService dataSourceService;

private MockMvc mockmvc;

@Before
public void setUp() throws Exception {
mockmvc = MockMvcBuilders.standaloneSetup(healthController).build();
}

@Test
public void testGetHealth() throws Exception {

Mockito.when(dataSourceService.getHealth()).thenReturn("UP");
MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(Constants.HEALTH_CONTROLLER_PATH);
String actualValue = mockmvc.perform(builder).andReturn().getResponse().getContentAsString();
Assert.assertEquals("UP", actualValue);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
import org.springframework.core.env.StandardEnvironment;

public class ConfigInfoTest {

@Test
public void test_precision_issue() throws Exception {
ApplicationUtils.injectEnvironment(new StandardEnvironment());
IdGenerator generator = new SnowFlowerIdGenerator();
long id = generator.nextId();
ConfigInfo configInfo = new ConfigInfo();
configInfo.setId(id);
String json = JacksonUtils.toJson(configInfo);
ConfigInfo _c = JacksonUtils.toObj(json, ConfigInfo.class);
Assert.assertEquals(id, _c.getId());

}

}
@Test
public void testPrecisionIssue() throws Exception {
ApplicationUtils.injectEnvironment(new StandardEnvironment());
IdGenerator generator = new SnowFlowerIdGenerator();
long expected = generator.nextId();
ConfigInfo configInfo = new ConfigInfo();
configInfo.setId(expected);
String json = JacksonUtils.toJson(configInfo);
ConfigInfo actual = JacksonUtils.toObj(json, ConfigInfo.class);
Assert.assertEquals(expected, actual.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.config.server.service;

import org.junit.Before;
Expand All @@ -30,27 +31,27 @@
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
public class AggrWhitelistTest {

AggrWhitelist service;

@Before
public void before() throws Exception {
service = new AggrWhitelist();
}

@Test
public void testIsAggrDataId() {
List<String> list = new ArrayList<String>();
list.add("com.taobao.jiuren.*");
list.add("NS_NACOS_SUBSCRIPTION_TOPIC_*");
list.add("com.taobao.tae.AppListOnGrid-*");
service.compile(list);

assertFalse(service.isAggrDataId("com.abc"));
assertFalse(service.isAggrDataId("com.taobao.jiuren"));
assertFalse(service.isAggrDataId("com.taobao.jiurenABC"));
assertTrue(service.isAggrDataId("com.taobao.jiuren.abc"));
assertTrue(service.isAggrDataId("NS_NACOS_SUBSCRIPTION_TOPIC_abc"));
assertTrue(service.isAggrDataId("com.taobao.tae.AppListOnGrid-abc"));
AggrWhitelist.compile(list);
assertFalse(AggrWhitelist.isAggrDataId("com.abc"));
assertFalse(AggrWhitelist.isAggrDataId("com.taobao.jiuren"));
assertFalse(AggrWhitelist.isAggrDataId("com.taobao.jiurenABC"));
assertTrue(AggrWhitelist.isAggrDataId("com.taobao.jiuren.abc"));
assertTrue(AggrWhitelist.isAggrDataId("NS_NACOS_SUBSCRIPTION_TOPIC_abc"));
assertTrue(AggrWhitelist.isAggrDataId("com.taobao.tae.AppListOnGrid-abc"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.config.server.service;

import com.alibaba.nacos.config.server.utils.GroupKey2;
Expand All @@ -26,32 +27,32 @@
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
public class ClientTrackServiceTest {

@Before
public void before() {
ClientTrackService.clientRecords.clear();
}

@Test
public void test_trackClientMd5() {
public void testTrackClientMd5() {
String clientIp = "1.1.1.1";
String dataId = "com.taobao.session.xml";
String group = "online";
String groupKey = GroupKey2.getKey(dataId, group);
String md5 = "xxxxxxxxxxxxx";

ConfigCacheService.updateMd5(groupKey, md5, System.currentTimeMillis());

ClientTrackService.trackClientMd5(clientIp, groupKey, md5);
ClientTrackService.trackClientMd5(clientIp, groupKey, md5);

Assert.assertEquals(true, ClientTrackService.isClientUptodate(clientIp).get(groupKey));
Assert.assertEquals(1, ClientTrackService.subscribeClientCount());
Assert.assertEquals(1, ClientTrackService.subscriberCount());

//服务端数据更新
ConfigCacheService.updateMd5(groupKey, md5 + "111", System.currentTimeMillis());
Assert.assertEquals(false, ClientTrackService.isClientUptodate(clientIp).get(groupKey));
}

}
Loading