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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
package org.eclipse.papyrus.infra.core.services;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
import org.eclipse.papyrus.infra.core.services.ServiceDescriptor;
import org.eclipse.papyrus.infra.core.services.ServiceStartKind;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class ComposedServiceTest {
private FakeComposedService masterService;
@Before
public void setUp() throws Exception {
masterService = new FakeComposedService();
}
@After
public void tearDown() throws Exception {
}
@Test
public void testAddServicePart() {
FakeComposedServicePartA partA = new FakeComposedServicePartA();
FakeComposedServicePartB partB = new FakeComposedServicePartB();
masterService.addServicePart(partA);
masterService.addServicePart(partB);
List<?> addedParts = masterService.getRegisteredServices();
assertTrue("service contains partA", addedParts.contains(partA));
assertTrue("service contains partB", addedParts.contains(partB));
}
@Test
public void testRemoveServicePart() {
FakeComposedServicePartA partA = new FakeComposedServicePartA();
FakeComposedServicePartB partB = new FakeComposedServicePartB();
masterService.addServicePart(partA);
masterService.addServicePart(partB);
List<?> addedParts = masterService.getRegisteredServices();
assertTrue("service contains partA", addedParts.contains(partA));
assertTrue("service contains partB", addedParts.contains(partB));
masterService.removeServicePart(partA);
assertFalse("service contains partA", addedParts.contains(partA));
assertTrue("service contains partB", addedParts.contains(partB));
}
/**
* Test that the parts registered to the ServiceRegistry are automaticly
* registered to there associated main service when registry is started.
* @throws ServiceException
*/
@Test
public void testPartAutomaticRegistration() throws ServiceException {
ServicesRegistry serviceRegistry = new ServicesRegistry();
// Register services
serviceRegistry.add(new ComposedServiceDescriptor());
serviceRegistry.add(new ServicePartADescriptor());
serviceRegistry.add(new ServicePartBDescriptor());
// start registry
serviceRegistry.startRegistry();
// Check if connected
FakeComposedService masterService = serviceRegistry.getService(FakeComposedService.class);
FakeComposedServicePartA partA = serviceRegistry.getService( FakeComposedServicePartA.class);
FakeComposedServicePartB partB = serviceRegistry.getService( FakeComposedServicePartB.class);
List<?> addedParts = masterService.getRegisteredServices();
assertNotNull("master service found", masterService);
assertTrue("service contains partA", addedParts.contains(partA));
assertTrue("service contains partB", addedParts.contains(partB));
}
/* ***************************** */
/**
* A descriptor
* @author dumoulin
*
*/
public class ServicePartADescriptor extends ServiceDescriptor {
public ServicePartADescriptor() {
super(FakeComposedServicePartA.class, FakeComposedServicePartA.class.getName(), ServiceStartKind.STARTUP, 1);
}
}
/**
* A descriptor
* @author dumoulin
*
*/
public class ServicePartBDescriptor extends ServiceDescriptor {
public ServicePartBDescriptor() {
super(FakeComposedServicePartB.class, FakeComposedServicePartB.class.getName(), ServiceStartKind.STARTUP, 1);
}
}
/**
* A descriptor
* @author dumoulin
*
*/
public class ComposedServiceDescriptor extends ServiceDescriptor {
public ComposedServiceDescriptor() {
super(FakeComposedService.class, FakeComposedService.class.getName(), ServiceStartKind.STARTUP, 1);
}
}
}
|