-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab5f7a8
commit d5d4719
Showing
6 changed files
with
120 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
cim-common/src/main/java/com/crossoverjie/cim/common/core/proxy/Request.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.crossoverjie.cim.common.core.proxy; | ||
|
||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
|
||
/** | ||
* @author crossoverJie | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Request { | ||
String method() default POST; | ||
|
||
String GET = "GET"; | ||
String POST = "POST"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
cim-common/src/test/java/com/crossoverjie/cim/common/core/proxy/ProxyManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.crossoverjie.cim.common.core.proxy; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import okhttp3.OkHttpClient; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ProxyManagerTest { | ||
|
||
@Test | ||
public void testGet() { | ||
OkHttpClient client = new OkHttpClient(); | ||
Github github = | ||
new ProxyManager<>(Github.class, "https://api.github.com/users/crossoverjie", | ||
client) | ||
.getInstance(); | ||
GithubResponse githubResponse = github.userInfo(); | ||
Assertions.assertEquals(githubResponse.getName(), "crossoverJie"); | ||
|
||
github.userInfo2(); | ||
} | ||
|
||
interface Github { | ||
@Request(method = Request.GET) | ||
GithubResponse userInfo(); | ||
@Request(method = Request.GET) | ||
void userInfo2(); | ||
} | ||
|
||
@NoArgsConstructor | ||
@Data | ||
public static class GithubResponse { | ||
@JsonProperty("name") | ||
private String name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters