forked from sunnykaka/mysteam
-
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.
add integration test for place order
- Loading branch information
Showing
21 changed files
with
225 additions
and
18 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
29 changes: 29 additions & 0 deletions
29
common/src/main/java/com/akkafun/common/spring/ServiceClientApplication.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,29 @@ | ||
package com.akkafun.common.spring; | ||
|
||
import com.netflix.appinfo.ApplicationInfoManager; | ||
import com.netflix.discovery.DiscoveryClient; | ||
import com.netflix.discovery.EurekaClient; | ||
import com.netflix.discovery.EurekaClientConfig; | ||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; | ||
import org.springframework.cloud.netflix.eureka.CloudEurekaClient; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
/** | ||
* Created by liubin on 2016/5/30. | ||
*/ | ||
@EnableDiscoveryClient | ||
public class ServiceClientApplication { | ||
|
||
@Bean(destroyMethod = "shutdown") | ||
@org.springframework.cloud.context.config.annotation.RefreshScope | ||
public EurekaClient eurekaClient(ApplicationInfoManager manager, | ||
EurekaClientConfig config, | ||
DiscoveryClient.DiscoveryClientOptionalArgs optionalArgs, | ||
ApplicationContext context) { | ||
manager.getInfo(); // force initialization | ||
return new CloudEurekaClient(manager, config, optionalArgs, context); | ||
} | ||
|
||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...ava/com/akkafun/common/spring/utils/InnerClassPathScanningCandidateComponentProvider.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,25 @@ | ||
package com.akkafun.common.spring.utils; | ||
|
||
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; | ||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; | ||
import org.springframework.core.env.Environment; | ||
|
||
/** | ||
* 内部类也能查询出来 | ||
* Created by liubin on 2016/5/31. | ||
*/ | ||
public class InnerClassPathScanningCandidateComponentProvider extends ClassPathScanningCandidateComponentProvider { | ||
|
||
public InnerClassPathScanningCandidateComponentProvider(boolean useDefaultFilters) { | ||
super(useDefaultFilters); | ||
} | ||
|
||
public InnerClassPathScanningCandidateComponentProvider(boolean useDefaultFilters, Environment environment) { | ||
super(useDefaultFilters, environment); | ||
} | ||
|
||
@Override | ||
protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) { | ||
return beanDefinition.getMetadata().isConcrete(); | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
26 changes: 26 additions & 0 deletions
26
user/core/src/test/java/com/akkafun/common/event/load/FakeAskCouponUse.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,26 @@ | ||
package com.akkafun.common.event.load; | ||
|
||
import org.apache.commons.lang.RandomStringUtils; | ||
|
||
/** | ||
* Created by liubin on 2016/5/30. | ||
*/ | ||
public class FakeAskCouponUse extends FakeAskEvent { | ||
|
||
private String id; | ||
|
||
public FakeAskCouponUse() { | ||
this.id = RandomStringUtils.randomAlphanumeric(8); | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "FakeAskCouponUse{" + | ||
"id='" + id + '\'' + | ||
"} " + super.toString(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
user/core/src/test/java/com/akkafun/common/event/load/FakeAskDeductBalance.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,26 @@ | ||
package com.akkafun.common.event.load; | ||
|
||
import org.apache.commons.lang.RandomStringUtils; | ||
|
||
/** | ||
* Created by liubin on 2016/5/30. | ||
*/ | ||
public class FakeAskDeductBalance extends FakeAskEvent { | ||
|
||
private String id; | ||
|
||
public FakeAskDeductBalance() { | ||
this.id = RandomStringUtils.randomAlphanumeric(8); | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "FakeAskDeductBalance{" + | ||
"id='" + id + '\'' + | ||
"} " + super.toString(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
user/core/src/test/java/com/akkafun/common/event/load/FakeAskEvent.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,7 @@ | ||
package com.akkafun.common.event.load; | ||
|
||
/** | ||
* Created by liubin on 2016/5/30. | ||
*/ | ||
public class FakeAskEvent { | ||
} |
13 changes: 13 additions & 0 deletions
13
user/core/src/test/java/com/akkafun/common/event/load/FakeEventBus.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,13 @@ | ||
package com.akkafun.common.event.load; | ||
|
||
/** | ||
* Created by liubin on 2016/5/30. | ||
*/ | ||
public class FakeEventBus { | ||
|
||
public void askUnited(FakeUnitedAskEventCallback callback, FakeAskEvent firstAskEvent, FakeAskEvent secondAskEvent, | ||
FakeAskEvent... remainAskEvents) { | ||
System.out.println(callback.getClass()); | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
user/core/src/test/java/com/akkafun/common/event/load/FakeUnitedAskEventCallback.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,12 @@ | ||
package com.akkafun.common.event.load; | ||
|
||
/** | ||
* Created by liubin on 2016/5/30. | ||
*/ | ||
public interface FakeUnitedAskEventCallback { | ||
|
||
void onSuccess(FakeAskEvent[] askEvents); | ||
|
||
void onFailure(FakeAskEvent[] askEvents); | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
user/core/src/test/java/com/akkafun/common/event/load/LoadEventClassTest.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,73 @@ | ||
package com.akkafun.common.event.load; | ||
|
||
import com.akkafun.common.spring.utils.InnerClassPathScanningCandidateComponentProvider; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.springframework.beans.factory.config.BeanDefinition; | ||
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; | ||
import org.springframework.core.type.filter.AssignableTypeFilter; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Set; | ||
|
||
import static org.hamcrest.Matchers.*; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* Created by liubin on 2016/5/30. | ||
*/ | ||
public class LoadEventClassTest { | ||
|
||
@Test | ||
@Ignore | ||
public void test() throws Exception { | ||
|
||
ClassPathScanningCandidateComponentProvider provider = new InnerClassPathScanningCandidateComponentProvider(false); | ||
provider.addIncludeFilter(new AssignableTypeFilter(FakeUnitedAskEventCallback.class)); | ||
|
||
Set<BeanDefinition> componentSet = provider.findCandidateComponents("com/akkafun"); | ||
|
||
assertThat(componentSet, not(empty())); | ||
System.out.println(String.format("FakeUnitedAskEventCallback subclass count: %d, content: %s", | ||
componentSet.size(), componentSet.toString())); | ||
|
||
ArrayList<BeanDefinition> components = new ArrayList<>(componentSet); | ||
BeanDefinition beanDefinition = components.get(0); | ||
Class<? extends FakeUnitedAskEventCallback> callbackClass = | ||
(Class<? extends FakeUnitedAskEventCallback>) Class.forName(beanDefinition.getBeanClassName()); | ||
Method onSuccessMethod = callbackClass.getMethod("onSuccess", FakeAskEvent[].class); | ||
assertThat(onSuccessMethod, notNullValue()); | ||
Constructor[] ctors = callbackClass.getDeclaredConstructors(); | ||
for (Constructor cc : ctors) | ||
{ | ||
System.out.println("my ctor is " + cc.toString()); | ||
} | ||
|
||
// onSuccessMethod.invoke(callbackClass.newInstance(), new FakeAskCouponUse(), new FakeAskDeductBalance()); | ||
|
||
|
||
FakeEventBus eventBus = new FakeEventBus(); | ||
|
||
final Integer a = new Integer(2); | ||
|
||
eventBus.askUnited(new FakeUnitedAskEventCallback() { | ||
|
||
@Override | ||
public void onSuccess(FakeAskEvent[] askEvents) { | ||
System.out.println(String.format("onSuccess, params: %s, a: %d", Arrays.toString(askEvents), a)); | ||
} | ||
|
||
@Override | ||
public void onFailure(FakeAskEvent[] askEvents) { | ||
System.out.println("onFailure: " + Arrays.toString(askEvents)); | ||
} | ||
|
||
}, new FakeAskCouponUse(), new FakeAskDeductBalance()); | ||
|
||
} | ||
|
||
|
||
} |