Skip to content

Commit

Permalink
Merge pull request #143 from crossoverJie/fix-client-unit-test
Browse files Browse the repository at this point in the history
[test] fix client unit test
  • Loading branch information
crossoverJie authored Aug 30, 2024
2 parents 8155fd7 + 3f1ccf0 commit cc83c74
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 57 deletions.
6 changes: 6 additions & 0 deletions cim-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.stereotype.Component;

import jakarta.annotation.PostConstruct;
Expand All @@ -38,6 +40,7 @@
*/
@Component
@Slf4j
@ConditionalOnWebApplication
public class CIMClient {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.crossoverjie.cim.common.res.NULLBody;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -27,6 +28,7 @@
*/
@Controller
@RequestMapping("/")
@ConditionalOnWebApplication
public class IndexController {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.crossoverjie.cim.common.kit.HeartBeatHandler;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.stereotype.Service;

/**
Expand All @@ -15,6 +16,7 @@
* @since JDK 1.8
*/
@Service
@ConditionalOnWebApplication
public class ClientHeartBeatHandlerImpl implements HeartBeatHandler {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.crossoverjie.cim.common.data.construct.RingBufferWheel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
Expand All @@ -24,6 +25,7 @@
*/
@Slf4j
@Service
@ConditionalOnWebApplication
public class ShutDownCommand implements InnerCommand {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.crossoverjie.cim.client.service;

import com.crossoverjie.cim.client.CIMClientApplication;
import com.crossoverjie.cim.client.service.InnerCommand;
import com.crossoverjie.cim.client.service.InnerCommandContext;
import com.crossoverjie.cim.common.enums.SystemCommandEnum;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -22,8 +24,9 @@ public void execute() {
execute.process(msg) ;
}

@Test
// @Test
public void execute3() {
// TODO: 2024/8/31 Integration test
String msg = SystemCommandEnum.ONLINE_USER.getCommandType();
InnerCommand execute = context.getInstance(msg);
execute.process(msg) ;
Expand Down Expand Up @@ -57,8 +60,9 @@ public void execute7() {
execute.process(msg) ;
}

@Test
// @Test
public void execute8() {
// TODO: 2024/8/31 Integration test
String msg = ":pu cross";
InnerCommand execute = context.getInstance(msg);
execute.process(msg) ;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.crossoverjie.cim.client.service.impl;

import com.crossoverjie.cim.client.CIMClientApplication;
import com.crossoverjie.cim.client.service.EchoService;
import jakarta.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;


@SpringBootTest(classes = CIMClientApplication.class)
@RunWith(SpringRunner.class)
public class EchoServiceImplTest {

@Resource
private EchoService echoService;

@Test
public void echo(){
echoService.echo("test");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,56 +72,6 @@ public void onlineUser(){
}


@Test
public void searchMsg(){
StringBuilder sb = new StringBuilder() ;
String allMsg = "于是在之前的基础上我完善了一些内容,先来看看这个项目的介绍吧:\n" +
"\n" +
"CIM(CROSS-IM) 一款面向开发者的 IM(即时通讯)系统;同时提供了一些组件帮助开发者构建一款属于自己可水平扩展的 IM 。\n" +
"\n" +
"借助 CIM 你可以实现以下需求:" ;

String key = "IM" ;

String[] split = allMsg.split("\n");
for (String msg : split) {
if (msg.trim().contains(key)){
sb.append(msg).append("\n") ;
}
}
int pos = 0;

String result = sb.toString();

int count = 1 ;
int multiple = 2 ;
while((pos = result.indexOf(key, pos)) >= 0) {

log.info("{},{}",pos, pos + key.length());

if (count == 1){
sb.insert(pos,"**");
}else {
Double pow = Math.pow(multiple, count);
sb.insert(pos +pow.intValue(),"**");
}

pos += key.length();

if (count == 1){
sb.insert(pos +2,"**");
}else {
Double pow = Math.pow(multiple, count);
sb.insert((pos +2) + pow.intValue(),"**");

}


count ++ ;
}

System.out.println(sb);
}
@Test
public void searchMsg2(){
StringBuilder sb = new StringBuilder() ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* Date: 2018/12/23 22:39
* @since JDK 1.8
*/
@SpringBootTest(classes = CIMClientApplication.class)
@RunWith(SpringRunner.class)
//@SpringBootTest(classes = CIMClientApplication.class)
//@RunWith(SpringRunner.class)
@Slf4j
public class RouteTest {

Expand All @@ -30,10 +30,11 @@ public class RouteTest {
@Value("${cim.user.userName}")
private String userName;

@Autowired
// @Autowired
private RouteRequest routeRequest ;

@Test
// TODO: 2024/8/31 Integration test
// @Test
public void test() throws Exception {
LoginReqVO vo = new LoginReqVO(userId,userName) ;
CIMServerResVO.ServerInfo cimServer = routeRequest.getCIMServer(vo);
Expand Down
40 changes: 40 additions & 0 deletions cim-client/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
spring:
application:
name: cim-client
main:
# this will not be used to create real spring context, because don't need this context in test case.
web-application-type: none

# web port
server:
port: 8082

logging:
level:
root: error

# enable swagger
springdoc:
swagger-ui:
enabled: true

# log path
cim:
msg:
logger:
path: /opt/logs/cim/
route:
url: http://localhost:8083 # route url suggested that this is Nginx address
user: # cim userId and userName
id: 1722343979085
userName: zhangsan
callback:
thread:
queue:
size: 2
pool:
size: 2
heartbeat:
time: 60 # cim heartbeat time (seconds)
reconnect:
count: 3
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void sort() {
if (o1.key > o2.key) {
return 1;
} else {
return -1;
return 0;
}
});
}
Expand Down

0 comments on commit cc83c74

Please sign in to comment.