forked from apache/incubator-seata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: fix the failure of @BusinessActionContextParamete annotation …
…to set parameters into io.seata.rm.tcc.api.BusinessActionContext. A interface instead of its implementation class should be passed to io.seata.integration.tx.api.interceptor.ActionInterceptorHandler#fetchActionRequestContext to get parameters noted by "BusinessActionContextParameter". apache#6473
- Loading branch information
1 parent
d318409
commit 75f612d
Showing
2 changed files
with
88 additions
and
12 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
spring/src/test/java/org/apache/seata/spring/tcc/TccActionInterceptorHandlerTest.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,59 @@ | ||
package org.apache.seata.spring.tcc; | ||
|
||
import org.aopalliance.intercept.MethodInvocation; | ||
import org.apache.seata.integration.tx.api.interceptor.InvocationWrapper; | ||
import org.apache.seata.rm.tcc.api.BusinessActionContext; | ||
import org.apache.seata.rm.tcc.api.TwoPhaseBusinessAction; | ||
import org.apache.seata.rm.tcc.interceptor.TccActionInterceptorHandler; | ||
import org.apache.seata.spring.annotation.AdapterInvocationWrapper; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.HashSet; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
|
||
class TccActionInterceptorHandlerTest { | ||
|
||
protected TccActionInterceptorHandler tccActionInterceptorHandler = new TccActionInterceptorHandler( | ||
null, | ||
new HashSet<String>() {{ | ||
add("prepare"); | ||
}} | ||
); | ||
|
||
/** | ||
* Test method "parseAnnotation" of TccActionInterceptorHandler | ||
* | ||
* @throws Throwable | ||
*/ | ||
@Test | ||
void testParseAnnotation() throws Throwable { | ||
// mock MethodInvocation | ||
NormalTccActionImpl tccAction = new NormalTccActionImpl(); | ||
Method classMethod = NormalTccActionImpl.class.getMethod("prepare", BusinessActionContext.class); | ||
MethodInvocation mockInvocation = mock(MethodInvocation.class); | ||
when(mockInvocation.getMethod()).thenReturn(classMethod); | ||
when(mockInvocation.getArguments()).thenReturn(new Object[]{new BusinessActionContext()}); | ||
when(mockInvocation.proceed()).thenAnswer(invocation -> classMethod.invoke(tccAction, mockInvocation.getArguments())); | ||
|
||
// mock AdapterInvocationWrapper | ||
AdapterInvocationWrapper invocationWrapper = new AdapterInvocationWrapper(mockInvocation); | ||
when(invocationWrapper.getTarget()).thenReturn(tccAction); | ||
|
||
// invoke private method "parseAnnotation" of TccActionInterceptorHandler | ||
Method method = TccActionInterceptorHandler.class.getDeclaredMethod("parseAnnotation", InvocationWrapper.class); | ||
method.setAccessible(true); | ||
Object[] results = (Object[]) method.invoke(tccActionInterceptorHandler, invocationWrapper); | ||
System.out.println(results); | ||
|
||
// test results | ||
Method interfaceMethod = NormalTccAction.class.getMethod("prepare", BusinessActionContext.class); | ||
Assertions.assertEquals(interfaceMethod, results[0]); | ||
Assertions.assertEquals(true, results[1] instanceof TwoPhaseBusinessAction); | ||
|
||
} | ||
} |
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