Skip to content

Commit

Permalink
comment unless code
Browse files Browse the repository at this point in the history
  • Loading branch information
crossoverJie committed Sep 8, 2024
1 parent 88bdea9 commit 2dffa42
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
serverUrl = serverUri.normalize().toString();

if (args != null && args.length > 1) {
throw new CIMException(VALIDATION_FAIL);
throw new IllegalArgumentException(VALIDATION_FAIL.message());
}

if (method.getParameterTypes().length > 0) {
Expand All @@ -131,7 +131,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
return objectMapper.readValue(json, method.getReturnType());
} else {
return objectMapper.readValue(json, objectMapper.getTypeFactory()
.constructParametricType(BaseResponse.class, objectMapper.getTypeFactory().constructType(genericTypeOfBaseResponse)));
.constructParametricType(method.getReturnType(), objectMapper.getTypeFactory().constructType(genericTypeOfBaseResponse)));
}
} finally {
if (result != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import okhttp3.OkHttpClient;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class RpcProxyManagerTest {

@Test
Expand Down Expand Up @@ -35,9 +40,40 @@ public void testPost() {
Assertions.assertEquals(response.getParsedBody().getCity(), "shenzhen");
}

@Test
public void testFail() {
OkHttpClient client = new OkHttpClient();
String url = "http://echo.free.beeceptor.com";
Echo echo = RpcProxyManager.create(Echo.class, url, client);
EchoRequest request = new EchoRequest();
request.setName("crossoverJie");
request.setAge(18);
request.setCity("shenzhen");
Assertions.assertThrows(IllegalArgumentException.class, () -> echo.fail(request, "test"));
}


@Test
public void testGeneric() {
OkHttpClient client = new OkHttpClient();
String url = "http://echo.free.beeceptor.com";
Echo echo = RpcProxyManager.create(Echo.class, url, client);
EchoRequest request = new EchoRequest();
request.setName("crossoverJie");
request.setAge(18);
request.setCity("shenzhen");
EchoGeneric<EchoResponse.HeadersDTO> response = echo.echoGeneric(request);
Assertions.assertEquals(response.getHeaders().getHost(), "echo.free.beeceptor.com");
}

interface Echo {
@Request(url = "sample-request?author=beeceptor")
EchoResponse echo(EchoRequest message);
@Request(url = "sample-request?author=beeceptor")
EchoResponse fail(EchoRequest message, String s);

@Request(url = "sample-request?author=beeceptor")
EchoGeneric<EchoResponse.HeadersDTO> echoGeneric(EchoRequest message);
}

@Data
Expand All @@ -47,6 +83,29 @@ public static class EchoRequest{
private String city;
}

@Data
@AllArgsConstructor
@NoArgsConstructor
public static class CIMServerResVO implements Serializable {

private String ip ;
private Integer cimServerPort;
private Integer httpPort;

}

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@AllArgsConstructor
@NoArgsConstructor
public static class EchoGeneric<T> {
private String method;
private String protocol;
private String host;

private T headers;
}

@NoArgsConstructor
@Data
public static class EchoResponse{
Expand Down

0 comments on commit 2dffa42

Please sign in to comment.