summaryrefslogtreecommitdiffstats
path: root/tags/java/sca/1.5.1-RC3/vtest/assembly/component/src/test/java/org/apache/tuscany/sca/vtest/assembly/component/ComponentReferenceTestCase.java
blob: 5dd19690164f9227dabca3b69945689818fad6fa (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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
 */
package org.apache.tuscany.sca.vtest.assembly.component;

import junit.framework.Assert;

import org.apache.tuscany.sca.vtest.assembly.component.reference.MyClientA;
import org.apache.tuscany.sca.vtest.assembly.component.reference.MyClientB;
import org.apache.tuscany.sca.vtest.assembly.component.reference.MyClientC;
import org.apache.tuscany.sca.vtest.assembly.component.reference.MyClientD;
import org.apache.tuscany.sca.vtest.assembly.component.reference.MyClientE;
import org.apache.tuscany.sca.vtest.utilities.ServiceFinder;
import org.junit.Ignore;
import org.junit.Test;
import org.osoa.sca.ServiceRuntimeException;

/**
 * Test the reference name, wire, wireByImpl, autowire and so on.
 *
 */
public class ComponentReferenceTestCase {

	private void initDomain(String compositePath) {
        System.out.println("Setting up");        
        ServiceFinder.init(compositePath);
    }

    private void cleanupDomain() {
        System.out.println("Cleaning up");
        ServiceFinder.cleanup();
    }
	
	/**
     * Line 1325-1326:
     * <p>
     * OSOA:
     * the name of the reference. The name must be unique across all the 
     * composite references in the composite.
     * <p>
     * ASM50007
     * <p>
     * OASIS:
     * the name of the reference. Has to match a name of a reference defined by the implementation.
     * The @name attribute of a reference element of a <component/> MUST be unique amongst the 
     * reference elements of that <component/>
     */
    @Test
    public void testReferenceNameUnique() {
    	
    	initDomain("referencename_1.composite");
    	
    	MyClientA service = ServiceFinder.getService(MyClientA.class, "ClientComponent1/MyClientA");
    	Assert.assertEquals("MyService:::MyService" , service.callOtherServices()) ;
    	
        cleanupDomain();
    }
    
    /**
     * Line 1325-1326:
     * <p>
     * OSOA:
     * the name of the reference. The name must be unique across all the 
     * composite references in the composite.
     * <p>
     * ASM50007
     * <p>
     * OASIS:
     * the name of the reference. Has to match a name of a reference defined by the implementation.
     * The @name attribute of a reference element of a <component/> MUST be unique amongst the 
     * reference elements of that <component/>
     */
    @Test
    public void testReferenceNameDuplicated() {
    	//for this case, the reference of "b" in MyClientImpl is null.
        try {
        	initDomain("referencename_2.composite"); 
        } catch (ServiceRuntimeException ex){
            Assert.assertEquals("org.apache.tuscany.sca.monitor.MonitorRuntimeException: Duplicate component reference name: Component = ClientComponent2 Reference = b", ex.getMessage());
            return;
        }
        Assert.fail();         
        cleanupDomain();
    }
    
    /**
     * Line 192-193:
     * <p>
     * OSOA:
     * the name of the reference. Has to match a name of a reference
     *  defined by the implementation.
     * <p>
     * ASM50008
     * <p>
     * OASIS:
     * the name of the reference. Has to match a name of a reference defined by the implementation.
     * 
     */    
     @Test
     public void testComponentReferenceNameMatched() {     
         initDomain("referencename_3.composite");        
         MyClientA service = ServiceFinder.getService(MyClientA.class, "ClientComponent1/MyClientA");           
         Assert.assertEquals("MyService:::MyService" , service.callOtherServices()) ;    
         cleanupDomain();
    }
     
     /**
      * Line 192-193:
      * <p>
      * OSOA:
      * the name of the reference. Has to match a name of a reference
      *  defined by the implementation.
      * <p>
      * ASM50008
      * <p>
      * OASIS:
      * the name of the reference. Has to match a name of a reference defined by the implementation.
      * 
      */    
    @Test
    public void testComponentReferenceNameValid() {
    	
        try {
            initDomain("referencename_4.composite");   
        } catch (ServiceRuntimeException ex){
            Assert.assertEquals("org.apache.tuscany.sca.monitor.MonitorRuntimeException: Reference not found for component reference: Component = ClientComponent1 Reference = bb", ex.getMessage());
            return;
        }
    	   	
    	Assert.fail();    	
        cleanupDomain();
    	
    }
    
    /**
     * 
     * <p>
     * ASM50010
     * <p>
     * OASIS:
     * If @wiredByImpl="true" is set for a reference, then the reference MUST NOT be 
     * wired statically within a composite, but left unwired
     */
    @Test
    @Ignore("Not implemented in SCA 1.x codebase.")
    public void testWiredByImpl() {
    	initDomain("reference_wiredbyimpl.composite");    	
    	MyClientA service = ServiceFinder.getService(MyClientA.class, "ClientComponent/MyClientA");    	
    	Assert.assertEquals("MyService:::MyService" , service.callOtherServices()) ;    	
        cleanupDomain();
    }
    
    
    /**
     * Line 208:
     * <p>
     * OSOA:
     * zero or one wire can have the reference as a source
     * <p>
     * ASM50018
     * <p>
     * OASIS
     * A reference with multiplicity 0..1 or 0..n MAY have no target 
     * service defined.
     * 
     */
    @Test    
    public void testMultiplicity_1() {
    	
    	initDomain("reference_multiplicity_zerotarget.composite");    	
    	MyClientC service = ServiceFinder.getService(MyClientC.class, "ClientComponent/MyClientC");    	
    	Assert.assertEquals("MyService_MyService" , service.callOtherService()) ;    	
        cleanupDomain();
    }
    
    /**
     * Line 208:
     * OSOA:
     * zero or one wire can have the reference as a source
     * <p>
     * ASM50019
     * <p>
     * OASIS:
     * A reference with multiplicity 0..1 or 1..1 MUST NOT have more than one target service
     *  defined.
     */
    @Test
    @Ignore("TUSCANY-2720")
    public void testMultiplicity_2() {
    	
    	initDomain("reference_multiplicity_moretargets.composite");    	
    	MyClientB service = ServiceFinder.getService(MyClientB.class, "ClientComponent/MyClientB");    	
    	Assert.assertEquals("MyService_MyService2_MyService_MyService2" , service.callOtherServices()) ;    	
        cleanupDomain();
    }
    
    /**
     * Line 207,209
     * <p>
     * OSOA:
     * 1..1 � one wire can have the reference as a source
     * 1..n � one or more wires can have the reference as a source
     * <p>
     * ASM50020
     * <p>
     * OASIS:
     * A reference with multiplicity 1..1 or 1..n MUST have at least one target 
     * service defined.
     */
    @Test    
    public void testMultiplicity_3() {
    	
    	initDomain("reference_multiplicity_ntargets.composite");    	
    	MyClientD service = ServiceFinder.getService(MyClientD.class, "ClientComponent/MyClientD");    	
    	Assert.assertEquals("MyService_MyService" , service.callOtherService_1()) ;
    	Assert.assertEquals("MyService_MyService" , service.callOtherService_2()) ;
    	
        cleanupDomain();
    }
    
    /**
     * Line 209-210
     * <p>
     * OSOA
     * 1..n � one or more wires can have the reference as a source
     * 0..n - zero or more wires can have the reference as a source
     * <p>
     * ASM50020
     * <p>
     * OASIS:
     * A reference with multiplicity 0..n or 1..n MAY have one or more
     * target services defined.
     */
    @Test
    public void testMultiplicity_4() {
    	
    	initDomain("reference_multiplicity_multitargets.composite");    	
    	MyClientE service = ServiceFinder.getService(MyClientE.class, "ClientComponent/MyClientE");    	
    	Assert.assertEquals("MyService_MyService2_MyService" , service.callOtherServices()) ;    	
    	
        cleanupDomain();
    }
    
}