Skip to content

Commit b93ff68

Browse files
committed
添加 nami 新单测
1 parent 2510911 commit b93ff68

File tree

6 files changed

+137
-6
lines changed

6 files changed

+137
-6
lines changed

__test/src/main/java/webapp/demo5_rpc/HelloService.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package webapp.demo5_rpc;
22

3-
import org.noear.nami.annotation.NamiClient;
43
import org.noear.solon.annotation.*;
54
import org.noear.solon.core.handle.UploadedFile;
65

76
import java.util.List;
87

98
//@NamiClient
109
public interface HelloService {
11-
@Post
1210
@Mapping("hello")
11+
@Post
1312
String hello(String name, @Header("H1") String h1, @Cookie("C1") String c1);
1413

1514
@Mapping("/test01")
@@ -23,4 +22,12 @@ public interface HelloService {
2322
@Mapping("/test03")
2423
@Post
2524
String test03();
25+
26+
@Mapping("/test04/{name}")
27+
@Get
28+
String test04(String name);
29+
30+
@Mapping("/test05?type={type}")
31+
@Post
32+
String test05(int type, @Body String body);
2633
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package webapp.demo5_rpc;
2+
3+
import org.noear.solon.annotation.*;
4+
import org.noear.solon.core.handle.UploadedFile;
5+
6+
import java.util.List;
7+
8+
/**
9+
* 简化模式
10+
* */
11+
//@NamiClient
12+
public interface HelloService2 {
13+
@Mapping("hello")
14+
// @Post
15+
String hello(String name, @Header("H1") String h1, @Cookie("C1") String c1);
16+
17+
@Mapping("/test01")
18+
// @Post
19+
String test01(@Param("ids") List<String> ids);
20+
21+
@Mapping("/test02")
22+
// @Post
23+
String test02(@Param("file") UploadedFile file);
24+
25+
@Mapping("/test03")
26+
@Post
27+
String test03();
28+
29+
@Mapping("/test04/{name}")
30+
// @Get
31+
String test04(String name);
32+
33+
@Mapping("/test05?type={type}")
34+
// @Post
35+
String test05(int type, @Body String body);
36+
}

__test/src/main/java/webapp/demo5_rpc/HelloServiceImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,18 @@ public String test02(@Param("file") UploadedFile file) {
3838
public String test03() {
3939
return "test03";
4040
}
41+
42+
@Mapping("/test04/{name}")
43+
@Get
44+
@Override
45+
public String test04(@Path String name) {
46+
return name;
47+
}
48+
49+
@Mapping("/test05")
50+
@Post
51+
@Override
52+
public String test05(int type, @Body String body) {
53+
return type + ":" + body;
54+
}
4155
}

__test/src/test/java/features/HeaderTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package features;
1717

18+
import org.junit.jupiter.api.Assertions;
1819
import org.junit.jupiter.api.Test;
1920
import org.noear.snack.ONode;
2021
import org.noear.solon.server.handle.HeaderNames;
@@ -130,15 +131,15 @@ public void testContentType_post_multipart() throws Exception {
130131
@Test
131132
public void testContentType_get() throws Exception {
132133
String rst = path("/demo2/header/ct?name=solon").get();
133-
assert rst.equals("GET::null::solon");
134+
Assertions.assertEquals("GET::null::solon", rst);
134135
}
135136

136137
@Test
137138
public void testServer_get() throws Exception {
138139
String rst = path("/demo2/header/server").exec("GET").header("Server");
139-
assert rst == null;
140+
Assertions.assertNull(rst);
140141

141142
rst = path("/demo2/header/server?out=1").exec("GET").header("Server");
142-
assert "solon".equals(rst);
143+
Assertions.assertEquals("solon", rst);
143144
}
144-
}
145+
}

__test/src/test/java/features/NamiAndHttpTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,14 @@ public void test02() throws IOException {
4949
public void test03() throws IOException {
5050
assert helloService.test03().equals("test03");
5151
}
52+
53+
@Test
54+
public void test04() throws IOException {
55+
assert helloService.test04("test04").equals("test04");
56+
}
57+
58+
@Test
59+
public void test05() throws IOException {
60+
assert helloService.test05(1, "test05").equals("1:\"test05\"");
61+
}
5262
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package features;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.noear.nami.annotation.NamiClient;
5+
import org.noear.solon.core.handle.UploadedFile;
6+
import org.noear.solon.core.util.MimeType;
7+
import org.noear.solon.test.SolonTest;
8+
import webapp.App;
9+
import webapp.demo5_rpc.HelloService;
10+
import webapp.demo5_rpc.HelloService2;
11+
12+
import java.io.ByteArrayInputStream;
13+
import java.io.IOException;
14+
import java.util.ArrayList;
15+
import java.util.List;
16+
17+
/**
18+
* @author noear 2025/5/7 created
19+
*/
20+
@SolonTest(App.class)
21+
public class NamiAndHttpTest2 {
22+
//直接指定服务端地址
23+
@NamiClient(url = "http://localhost:8080/demo5/hello/")
24+
HelloService2 helloService;
25+
26+
@Test
27+
public void hello() {
28+
assert helloService.hello("world", "1", "a").contains("world:1:a");
29+
assert helloService.hello("solon", "2", "b").contains("solon:2:b");
30+
}
31+
32+
@Test
33+
public void test01() {
34+
List<String> ids = new ArrayList<>();
35+
ids.add("a");
36+
ids.add("b");
37+
assert helloService.test01(ids).equals("a,b");
38+
}
39+
40+
@Test
41+
public void test02() throws IOException {
42+
UploadedFile file = new UploadedFile(MimeType.TEXT_PLAIN_VALUE,
43+
new ByteArrayInputStream("hello".getBytes()),
44+
"demo1.txt");
45+
46+
assert helloService.test02(file).equals("demo1.txt");
47+
}
48+
49+
@Test
50+
public void test03() throws IOException {
51+
assert helloService.test03().equals("test03");
52+
}
53+
54+
@Test
55+
public void test04() throws IOException {
56+
assert helloService.test04("test04").equals("test04");
57+
}
58+
59+
@Test
60+
public void test05() throws IOException {
61+
assert helloService.test05(1, "test05").equals("1:\"test05\"");
62+
}
63+
}

0 commit comments

Comments
 (0)