-
Notifications
You must be signed in to change notification settings - Fork 27
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
0988b10
commit 16ec936
Showing
35 changed files
with
480 additions
and
35 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* @author <a href="mailto:[email protected]">韩超</a> | ||
* @since 0.0.1 | ||
*/ | ||
@FeignClient(contextId = "my-client", name = "my-client") | ||
@FeignClient(contextId = "my-client", name = "my-client", configuration = {MockCapability.class}) | ||
public interface BaseClient { | ||
|
||
@GetMapping("echo") | ||
|
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
19 changes: 19 additions & 0 deletions
19
...d-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/FeignComponentAssert.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,19 @@ | ||
package io.microsphere.spring.cloud.openfeign; | ||
|
||
import feign.InvocationHandlerFactory; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">韩超</a> | ||
* @since 0.0.1 | ||
*/ | ||
public abstract class FeignComponentAssert<T> { | ||
|
||
|
||
protected abstract T loadCurrentComponent(InvocationHandlerFactory.MethodHandler methodHandler) throws Exception; | ||
|
||
public boolean expect(InvocationHandlerFactory.MethodHandler methodHandler, Class<T> expectedClass) throws Exception { | ||
T component = loadCurrentComponent(methodHandler); | ||
return expectedClass.equals(component.getClass()); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...g-cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/MockCapability.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,18 @@ | ||
package io.microsphere.spring.cloud.openfeign; | ||
|
||
import feign.Capability; | ||
import feign.InvocationHandlerFactory; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">韩超</a> | ||
* @since 0.0.1 | ||
*/ | ||
public class MockCapability implements Capability { | ||
|
||
@Override | ||
public InvocationHandlerFactory enrich(InvocationHandlerFactory invocationHandlerFactory) { | ||
return ObservableFeignInvocationHandler::new; | ||
} | ||
|
||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...src/test/java/io/microsphere/spring/cloud/openfeign/ObservableFeignInvocationHandler.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,78 @@ | ||
package io.microsphere.spring.cloud.openfeign; | ||
|
||
import feign.InvocationHandlerFactory; | ||
import feign.Target; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.util.Assert; | ||
|
||
import java.lang.reflect.InvocationHandler; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Proxy; | ||
import java.util.Map; | ||
|
||
import static feign.Util.checkNotNull; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">韩超</a> | ||
* @since 0.0.1 | ||
*/ | ||
public class ObservableFeignInvocationHandler implements InvocationHandler { | ||
|
||
|
||
private static final Logger log = LoggerFactory.getLogger(ObservableFeignInvocationHandler.class); | ||
public static FeignComponentAssert<?> componentAssert; | ||
public static Class expectComponentClass; | ||
|
||
private final Target target; | ||
private final Map<Method, InvocationHandlerFactory.MethodHandler> dispatch; | ||
|
||
ObservableFeignInvocationHandler(Target target, Map<Method, InvocationHandlerFactory.MethodHandler> dispatch) { | ||
this.target = checkNotNull(target, "target"); | ||
this.dispatch = checkNotNull(dispatch, "dispatch for %s", target); | ||
} | ||
|
||
@Override | ||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | ||
if ("equals".equals(method.getName())) { | ||
try { | ||
Object otherHandler = | ||
args.length > 0 && args[0] != null ? Proxy.getInvocationHandler(args[0]) : null; | ||
return equals(otherHandler); | ||
} catch (IllegalArgumentException e) { | ||
return false; | ||
} | ||
} else if ("hashCode".equals(method.getName())) { | ||
return hashCode(); | ||
} else if ("toString".equals(method.getName())) { | ||
return toString(); | ||
} else if (!dispatch.containsKey(method)) { | ||
throw new UnsupportedOperationException( | ||
String.format("Method \"%s\" should not be called", method.getName())); | ||
} | ||
|
||
InvocationHandlerFactory.MethodHandler methodHandler = dispatch.get(method); | ||
Assert.isTrue(componentAssert.expect(methodHandler, expectComponentClass), "unexpected component"); | ||
log.info("component validation is True"); | ||
return dispatch.get(method).invoke(args); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof ObservableFeignInvocationHandler) { | ||
ObservableFeignInvocationHandler other = (ObservableFeignInvocationHandler) obj; | ||
return target.equals(other.target); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return target.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return target.toString(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/ADecoder.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,21 @@ | ||
package io.microsphere.spring.cloud.openfeign.decoder; | ||
|
||
import feign.FeignException; | ||
import feign.Response; | ||
import feign.codec.DecodeException; | ||
import feign.codec.Decoder; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.Type; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">韩超</a> | ||
* @since 0.0.1 | ||
*/ | ||
public class ADecoder implements Decoder { | ||
|
||
@Override | ||
public Object decode(Response response, Type type) throws IOException, DecodeException, FeignException { | ||
return null; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...cloud-openfeign/src/test/java/io/microsphere/spring/cloud/openfeign/decoder/BDecoder.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,21 @@ | ||
package io.microsphere.spring.cloud.openfeign.decoder; | ||
|
||
import feign.FeignException; | ||
import feign.Response; | ||
import feign.codec.DecodeException; | ||
import feign.codec.Decoder; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.Type; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">韩超</a> | ||
* @since 0.0.1 | ||
*/ | ||
public class BDecoder implements Decoder { | ||
|
||
@Override | ||
public Object decode(Response response, Type type) throws IOException, DecodeException, FeignException { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.