|
1 |
| package com.agical.rmock.extension.junit; |
|
2 |
| |
|
3 |
| import com.agical.rmock.core.ProxyFactory; |
|
4 |
| import com.agical.rmock.core.configuration.ConfiguratorImpl; |
|
5 |
| import com.agical.rmock.core.hub.Hub; |
|
6 |
| import com.agical.rmock.core.strategy.TestStep; |
|
7 |
| import com.agical.rmock.core.strategy.impl.BeginVerifyStep; |
|
8 |
| import com.agical.rmock.core.strategy.impl.CompositeStep; |
|
9 |
| import com.agical.rmock.core.strategy.impl.EndVerifyStep; |
|
10 |
| import com.agical.rmock.core.strategy.impl.ExceptionVerifierTestStepDecorator; |
|
11 |
| import com.agical.rmock.core.strategy.impl.FinallyStep; |
|
12 |
| |
|
13 |
| public abstract class AbstractMockStrategyTestCase extends BasicJUnitStrategyTestCase{ |
|
14 |
| |
|
15 |
| private ProxyFactory proxyFactory; |
|
16 |
| |
|
17 |
1
| public AbstractMockStrategyTestCase(String testName) {
|
|
18 |
1
| this(testName, ConfiguratorImpl.getInstance().getHub());
|
|
19 |
| } |
|
20 |
| |
|
21 |
1108
| public AbstractMockStrategyTestCase(String testName, Hub hub) {
|
|
22 |
1108
| super(testName, hub);
|
|
23 |
| } |
|
24 |
| |
|
25 |
512
| protected void verify() throws Exception {
|
|
26 |
| } |
|
27 |
| |
|
28 |
543
| public TestStep createVerifyStep(String name) {
|
|
29 |
543
| return new TestStep() {
|
|
30 |
521
| public void run() throws Throwable {
|
|
31 |
521
| verify();
|
|
32 |
| } |
|
33 |
| }; |
|
34 |
| } |
|
35 |
| |
|
36 |
| |
|
37 |
544
| protected TestStep createStrategy(String test) {
|
|
38 |
544
| BeginVerifyStep beginVerifyStep = new BeginVerifyStep();
|
|
39 |
544
| EndVerifyStep endVerifyStep = new EndVerifyStep();
|
|
40 |
| |
|
41 |
544
| getHub().connect(beginVerifyStep);
|
|
42 |
544
| getHub().connect(endVerifyStep);
|
|
43 |
| |
|
44 |
| |
|
45 |
544
| FinallyStep strategy = new FinallyStep();
|
|
46 |
544
| CompositeStep mainStep = new CompositeStep();
|
|
47 |
544
| mainStep.addStep(createSetupStep(test));
|
|
48 |
544
| mainStep.addStep(exceptionVerifierDecorator( createTestStep(test) ));
|
|
49 |
544
| mainStep.addStep(beginVerifyStep);
|
|
50 |
544
| mainStep.addStep(exceptionVerifierDecorator( createVerifyStep(test) ));
|
|
51 |
544
| mainStep.addStep( endVerifyStep );
|
|
52 |
| |
|
53 |
544
| strategy.setMainStep(mainStep);
|
|
54 |
544
| strategy.setFinallyStep(createTearDownStep(test));
|
|
55 |
| |
|
56 |
544
| return strategy;
|
|
57 |
| } |
|
58 |
| |
|
59 |
1086
| protected TestStep exceptionVerifierDecorator( TestStep testStep ) {
|
|
60 |
1086
| TestStep step = new ExceptionVerifierTestStepDecorator( testStep );
|
|
61 |
1086
| getHub().connect( step );
|
|
62 |
1086
| return step;
|
|
63 |
| } |
|
64 |
| |
|
65 |
| |
|
66 |
1089
| public void setProxyFactory(ProxyFactory proxyFactory) {
|
|
67 |
1089
| this.proxyFactory = proxyFactory;
|
|
68 |
| } |
|
69 |
| |
|
70 |
749
| public ProxyFactory getProxyFactory() {
|
|
71 |
749
| return proxyFactory;
|
|
72 |
| } |
|
73 |
| } |