ClientTest.java 1.2 KB
Newer Older
L
lvxuhong 已提交
1 2
package github.javaguide.spring;

L
lvxuhong 已提交
3 4
import github.javaguide.api.Hello;
import github.javaguide.api.HelloService;
L
lvxuhong 已提交
5
import github.javaguide.spring.annotation.RpcServiceScan;
L
lvxuhong 已提交
6
import org.junit.Assert;
L
lvxuhong 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;

/**
 * @description:
 * @author:lvxuhong
 * @date:2020/6/19
 */
public class ClientTest {

    @Test
    public void test() {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(TestConfig.class);
        applicationContext.refresh();
        applicationContext.start();

L
lvxuhong 已提交
25 26 27 28 29
        HelloService helloService = applicationContext.getBean(HelloService.class);
        Hello hello = Hello.builder().message("test message").description("test description").build();
        String res = helloService.hello(hello);
        String expectedResult = "Hello description is " + hello.getDescription();
        Assert.assertEquals(expectedResult, res);
L
lvxuhong 已提交
30 31 32

    }

L
lvxuhong 已提交
33 34
    //@Configuration
    @RpcServiceScan("github.javaguide.api")
L
lvxuhong 已提交
35 36 37 38
    public static class TestConfig {

    }
}