Skip to content

Commit a89b69f

Browse files
committed
#62 - ENH: [Client generator] Add Map<String,?> option for header() queryParam() and formParam()
1 parent 1d9f5ed commit a89b69f

File tree

8 files changed

+176
-8
lines changed

8 files changed

+176
-8
lines changed

http-generator-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<relativePath>..</relativePath>
1010
</parent>
1111

12-
<artifactId>avaje-http-generator-client</artifactId>
12+
<artifactId>avaje-http-client-generator</artifactId>
1313

1414
<properties>
1515
<java.version>11</java.version>

tests/test-client/pom.xml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
<artifactId>test-client</artifactId>
1515
<version>1</version>
1616

17+
<properties>
18+
<jex.version>1.6</jex.version>
19+
<avaje-inject.version>6.0</avaje-inject.version>
20+
</properties>
21+
1722
<dependencies>
1823

1924
<dependency>
@@ -28,18 +33,18 @@
2833
<version>1.8</version>
2934
</dependency>
3035

31-
<dependency>
32-
<groupId>com.fasterxml.jackson.core</groupId>
33-
<artifactId>jackson-databind</artifactId>
34-
<version>2.12.3</version>
35-
</dependency>
36-
3736
<dependency>
3837
<groupId>io.avaje</groupId>
3938
<artifactId>avaje-http-api</artifactId>
4039
<version>1.7-SNAPSHOT</version>
4140
</dependency>
4241

42+
<dependency>
43+
<groupId>com.fasterxml.jackson.core</groupId>
44+
<artifactId>jackson-databind</artifactId>
45+
<version>2.12.3</version>
46+
</dependency>
47+
4348
<dependency>
4449
<groupId>com.squareup.retrofit2</groupId>
4550
<artifactId>retrofit</artifactId>
@@ -58,6 +63,16 @@
5863
<version>2.9.0</version>
5964
</dependency>
6065

66+
<dependency>
67+
<groupId>io.avaje</groupId>
68+
<artifactId>avaje-jex</artifactId>
69+
<version>${jex.version}</version>
70+
</dependency>
71+
<dependency>
72+
<groupId>io.avaje</groupId>
73+
<artifactId>avaje-inject</artifactId>
74+
<version>${avaje-inject.version}</version>
75+
</dependency>
6176

6277
<dependency>
6378
<groupId>org.junit.jupiter</groupId>
@@ -92,9 +107,19 @@
92107
<annotationProcessorPaths>
93108
<path>
94109
<groupId>io.avaje</groupId>
95-
<artifactId>avaje-http-generator-client</artifactId>
110+
<artifactId>avaje-http-client-generator</artifactId>
96111
<version>1.7-SNAPSHOT</version>
97112
</path>
113+
<path>
114+
<groupId>io.avaje</groupId>
115+
<artifactId>avaje-http-jex-generator</artifactId>
116+
<version>1.7-SNAPSHOT</version>
117+
</path>
118+
<path>
119+
<groupId>io.avaje</groupId>
120+
<artifactId>avaje-inject-generator</artifactId>
121+
<version>${avaje-inject.version}</version>
122+
</path>
98123
</annotationProcessorPaths>
99124
</configuration>
100125
</plugin>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.example;
2+
3+
import io.avaje.http.api.Get;
4+
import io.avaje.http.api.Path;
5+
import io.avaje.http.api.Produces;
6+
7+
import java.time.LocalDate;
8+
9+
@Path("/common")
10+
public interface CommonApi {
11+
12+
@Produces("text/plain")
13+
@Get("plain")
14+
String hello();
15+
16+
@Produces("text/plain")
17+
@Get("name/{name}")
18+
String name(String name);
19+
20+
@Produces("text/plain")
21+
@Get("{id}/{name}")
22+
String p2(long id, String name, LocalDate after, Boolean more);
23+
24+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@Client.Import(types = CommonApi.class)
2+
package org.example.client;
3+
4+
import io.avaje.http.api.Client;
5+
import org.example.CommonApi;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.example.server;
2+
3+
import io.avaje.http.api.Controller;
4+
import org.example.CommonApi;
5+
6+
import java.time.LocalDate;
7+
8+
@Controller
9+
public class CommonController implements CommonApi {
10+
11+
@Override
12+
public String hello() {
13+
return "hello world";
14+
}
15+
16+
@Override
17+
public String name(String name) {
18+
return "name[" + name + "]";
19+
}
20+
21+
@Override
22+
public String p2(long id, String name, LocalDate after, Boolean more) {
23+
return "p2[" + id + ";" + name + "; after:" + after + " more:" + more + "]";
24+
}
25+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.example.server;
2+
3+
import io.avaje.inject.ApplicationScope;
4+
import io.avaje.inject.BeanScope;
5+
import io.avaje.jex.Jex;
6+
import io.avaje.jex.Routing;
7+
8+
import java.util.List;
9+
10+
public class Main {
11+
12+
public static void main(String[] args) {
13+
start(8090);
14+
}
15+
16+
public static Jex.Server start(int port) {
17+
return start(port, ApplicationScope.scope());
18+
}
19+
20+
public static Jex.Server start(int port, BeanScope context) {
21+
22+
final List<Routing.Service> services = context.list(Routing.Service.class);
23+
24+
final Jex jex = Jex.create();
25+
jex.routing().addAll(services);
26+
return jex.port(port).start();
27+
}
28+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package org.example;
2+
3+
import com.fasterxml.jackson.databind.DeserializationFeature;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import io.avaje.http.client.HttpClientContext;
6+
import io.avaje.http.client.JacksonBodyAdapter;
7+
import io.avaje.http.client.RequestLogger;
8+
import org.example.server.Main;
9+
import org.junit.jupiter.api.BeforeAll;
10+
import org.junit.jupiter.api.Test;
11+
12+
import java.time.LocalDate;
13+
import java.util.Random;
14+
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
17+
class CommonApiTest {
18+
19+
static CommonApi client;
20+
21+
@BeforeAll
22+
static void start() {
23+
24+
final int port = new Random().nextInt(1000) + 10_000;
25+
Main.start(port);
26+
27+
ObjectMapper objectMapper = new ObjectMapper()
28+
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
29+
30+
final HttpClientContext clientContext = HttpClientContext.newBuilder()
31+
.withBaseUrl("http://localhost:" + port)
32+
.withRequestListener(new RequestLogger())
33+
.withBodyAdapter(new JacksonBodyAdapter(objectMapper))
34+
.build();
35+
36+
client = clientContext.create(CommonApi.class);
37+
}
38+
39+
@Test
40+
void hello() {
41+
assertThat(client.hello()).isEqualTo("hello world");
42+
}
43+
44+
@Test
45+
void name() {
46+
assertThat(client.name("foo")).isEqualTo("name[foo]");
47+
assertThat(client.name("bar")).isEqualTo("name[bar]");
48+
}
49+
50+
@Test
51+
void p2() {
52+
final LocalDate date = LocalDate.of(2021, 6, 24);
53+
final String result = client.p2(42, "foo", date, false);
54+
assertThat(result).isEqualTo("p2[42;foo; after:2021-06-24 more:false]");
55+
56+
final String result2 = client.p2(44, "bar", null, true);
57+
assertThat(result2).isEqualTo("p2[44;bar; after:null more:true]");
58+
}
59+
}

tests/test-client/src/test/java/org/example/SimpleTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.avaje.http.client.JacksonBodyAdapter;
88
import io.avaje.http.client.RequestLogger;
99
import org.example.httpclient.GitHubUsers$HttpClient;
10+
import org.junit.jupiter.api.Disabled;
1011
import org.junit.jupiter.api.Test;
1112

1213
import java.util.List;
@@ -15,6 +16,7 @@
1516

1617
public class SimpleTest {
1718

19+
@Disabled
1820
@Test
1921
void listRepos() {
2022

0 commit comments

Comments
 (0)