aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/Client.java
blob: 312520dba74dd299a09159cf84fec40856835875 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import org.aspectj.testing.Tester;

aspect ClientFlow percflow(entries(Client)) {
    pointcut entries(Client c):
	this(c) && (call(void Server.doService1(Object)) ||
                    call(void Server.doService2()));

    Client client;
    before (Client c): entries(c) { client = c; }

    pointcut workPoints():
	(this(ServiceWorker1) && call(void doWorkItemA())) ||
	(this(ServiceWorker2) && call(void doWorkItemB())) ||
	(this(ServiceWorker3) && call(void doWorkItemC())) ||
	(this(ServiceWorker4) && call(void doWorkItemD()));

    Object around(): workPoints() {
	//System.out.println("at work: " + thisJoinPoint.methodName);
	client.count++;
	return proceed();
	//return;
    }

    void util(Client c) {
        c.count++;
        client.count++;
    }
}


public class Client {
    public static void main(String[] args) { test(); }
    public static void test() {
	Client c = new Client();
	Server s = new Server();

	c.requestServices(s);

	Tester.checkEqual(c.count, 5, "A+B+C+2*D");

	Tester.check("WorkA");
	Tester.check("WorkB");
	Tester.check("WorkC");
	Tester.check("WorkD");
    }

    int count;

    public void requestServices(Server s) {
	s.doService1("foo");
	s.doService2();
    }
}

class Server {

    ServiceWorker1 worker1 = new ServiceWorker1();
    ServiceWorker2 worker2 = new ServiceWorker2();

    public void doService1(Object data) {
	worker1.doYourPart();
    }

    public void doService2() {
	worker2.doYourPart();
    }
}

class ServiceWorker1 {
    void doYourPart() {
	doWorkItemA();
    }

    void doWorkItemA() { Tester.note("WorkA");}
}

class ServiceWorker2 {
    ServiceWorker3 worker3 = new ServiceWorker3();
    ServiceWorker4 worker4 = new ServiceWorker4();

    void doYourPart() {
	worker3.doYourPart();
	worker4.doYourPart();
	doWorkItemB();
    }

    void doWorkItemB() { Tester.note("WorkB");}

}

class ServiceWorker3 {
    void doYourPart() {
	doWorkItemC();
    }

    void doWorkItemC() { Tester.note("WorkC"); }
}

class ServiceWorker4 {
    void doYourPart() {
	doWorkItemD();
    }

    void doWorkItemD() {
        // charge extra for 'd' "by hand"
        ClientFlow.aspectOf().client.count++;
	Tester.note("WorkD");
    }
}