summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/tags/2.0.1-RC1/testing/itest/properties/src/test/java/org/apache/tuscany/sca/itest/PropertyTestCase.java
blob: 0106d8a665f69e94c4b7257c5229aa913559d7c5 (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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
/*
 * 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.itest;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Iterator;

import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.ContributionLocationHelper;
import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import test.jaxb.props.ReturnCodeProperties;

/**
 * This is a class which makes user of JUnit Framework, all tests are written using JUnit notation. These tests are used
 * to test different property values returned from the SCA Runtime Environment which is initialized with the composite
 * 'PropertyTest.composite'. It basically tests all types of property values returned from SCA runtime environment.
 */
public class PropertyTestCase {
    private static Node node;
    private static ABComponent abService;
    private static CDComponent cdService;
    private static ABCDComponent abcdService;
    private static PropertyComponent propertyService;

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property value obtained using a service from the SCA runtime environment with the expected value 'a'
     */
    @Test
    public void testA() {
        assertEquals("a", abService.getA());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property value obtained using a service from the SCA runtime environment with the expected value 'b'
     */
    @Test
    public void testB() {
        assertEquals("b", abService.getB());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property value obtained using a service from the SCA runtime environment with the expected value 'c'
     */
    @Test
    public void testC() {
        assertEquals("c", cdService.getC());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property value obtained using a service from the SCA runtime environment with the expected value 'c'
     */
    @Test
    public void testC2() {
        assertEquals("c", cdService.getC2());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property value obtained using a service from the SCA runtime environment with the expected value 'd'
     */
    @Test
    public void testD() {
        assertEquals("d", cdService.getD());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property value obtained using a service from the SCA runtime environment with the expected value 'a'
     */
    @Test
    public void testF() {
        assertEquals("a", abService.getF());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property value obtained using a service from the SCA runtime environment with the expected value 'z'
     */
    @Test
    public void testZ() {
        assertEquals("z", abService.getZ());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property value obtained using a service from the SCA runtime environment with the expected value 1.
     */
    @Test
    public void testIntValue() {
        assertEquals(1, abService.getIntValue());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property value obtained using a service from the SCA runtime environment with the expected value 1.
     */
    @Test
    public void testDefaultValue() {
        assertEquals(1, abService.getIntValue());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property value obtained using a service from the SCA runtime environment with the expected value 1.
     */
    @Test
    public void testDefaultValueOverride() {
        assertEquals(1, cdService.getOverrideValue());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property value obtained using a service from the SCA runtime environment with the expected value 'aValue'
     */
    @Test
    public void testNoSource() {
        assertEquals("aValue", cdService.getNoSource());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property value obtained using a service from the SCA runtime environment with the expected value
     *       'fileValue'
     */
    @Test
    public void testFileProperty() {
        assertEquals("fileValue", cdService.getFileProperty());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property values obtained using a service from the SCA runtime environment with the expected values 4 and
     *       'fileValueTwo' respectively.
     */
    @Test
    public void testManyValuesFileProperty() {
        Iterator<String> iterator = cdService.getManyValuesFileProperty().iterator();
        iterator.next();
        String secondValue = iterator.next();
        assertEquals(4, cdService.getManyValuesFileProperty().size());
        assertEquals("fileValueTwo", secondValue);
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property values obtained using a service from the SCA runtime environment with the expected values 'a' ,
     *       'b', 'c' and 'd' respectively.
     */
    @Test
    public void testABCD() {
        assertEquals("a", abcdService.getA());
        assertEquals("b", abcdService.getB());
        assertEquals("c", abcdService.getC());
        assertEquals("d", abcdService.getD());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property values obtained using a service from the SCA runtime environment with the expected values 'RTP'
     *       and '2006' respectively
     */
    @Test
    public void testDefaultProperty() {
        assertEquals("RTP", propertyService.getLocation());
        assertEquals("2006", propertyService.getYear());

    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property values obtained using a service from the SCA runtime environment with the expected values 'Apache' ,
     *       'Tuscany' and 'Java SCA' respectively .
     */
    @Test
    public void testManySimpleStringValues() {
        Iterator<String> iterator = abService.getManyStringValues().iterator();
        assertEquals("Apache", iterator.next());
        assertEquals("Tuscany", iterator.next());
        assertEquals("Java SCA", iterator.next());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property values obtained using a service from the SCA runtime environment with the expected values 123, 456
     *       and 789 respectively.
     */
    @Test
    public void testManySimpleIntegerValues() {
        Iterator<Integer> iterator = abService.getManyIntegers().iterator();
        assertEquals(123, iterator.next().intValue());
        assertEquals(456, iterator.next().intValue());
        assertEquals(789, iterator.next().intValue());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property values obtained using a service from the SCA runtime environment with the expected values
     *       'TestString_1' and 2 respectively.
     */
    @Test
    public void testComplexPropertyOne() {
        ComplexPropertyBean propBean = propertyService.getComplexPropertyOne();
        assertNotNull(propBean);
        assertEquals("TestString_1", propBean.getStringArray()[0]);
        assertEquals(2, propBean.numberSetArray[1].integerNumber);
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property values obtained using a service from the SCA runtime environment with the expected integer number
     *       and a float number
     */
    @Test
    public void testComplexPropertyTwo() {
        ComplexPropertyBean propBean = propertyService.getComplexPropertyTwo();
        assertNotNull(propBean);
        assertEquals(10, propBean.intArray[0]);
        assertEquals((float)22, propBean.numberSetArray[1].floatNumber, 0.1);
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property values obtained using a service from the SCA runtime environment with the expected value first
     *       element in the string array and the float number
     */
    @Test
    public void testComplexPropertyThree() {
        ComplexPropertyBean propBean = propertyService.getComplexPropertyThree();
        assertNotNull(propBean);
        assertEquals("TestElementString_1", propBean.stringArray[0]);
        assertEquals((float)22, propBean.numberSetArray[1].floatNumber, 0.1);
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       complex property value obtained using a service from the SCA runtime environment with the expected values
     *       1, 222.222 and 33 respectively.
     */
    @Test
    public void testComplexPropertyFour() {
        Object[] propBeanCollection = propertyService.getComplexPropertyFour().toArray();
        assertNotNull(propBeanCollection);
        assertEquals(1, ((ComplexPropertyBean)propBeanCollection[0]).getIntegerNumber());
        assertEquals(222.222, ((ComplexPropertyBean)propBeanCollection[1]).getDoubleNumber(), 0.1);
        assertEquals(33, ((ComplexPropertyBean)propBeanCollection[2]).getNumberSet().getIntegerNumber());
    }

    /**
     * Method annotated with
     * 
     * @Test is a test method where testing logic is written using various assert methods. This test verifies the
     *       property values obtained using a service from the SCA runtime environment with the expected values
     *       'TestString_3', 'TestString_4', 100 and 200.
     */
    @Test
    public void testComplexPropertyFive() {
        ComplexPropertyBean propBean = propertyService.getComplexPropertyFive();
        assertNotNull(propBean);
        assertEquals("TestString_3", propBean.getStringArray()[0]);
        assertEquals("TestString_4", propBean.getStringArray()[1]);
        assertEquals(100, propBean.getIntArray()[0]);
        assertEquals(200, propBean.getIntArray()[1]);
    }

    @Test
    public void testGetLocationFromComponentContext() {
        String location = propertyService.getLocation();
        assertNotNull(location);
        String locationFromCC = propertyService.getLocationFromComponentContext();
        assertNotNull(locationFromCC);
        assertEquals(location, locationFromCC);
    }

    @Test
    public void testGetInjectedStringArrayProperty() {
        String[] daysOfWeek = propertyService.getDaysOfTheWeek();
        assertNotNull(daysOfWeek);

        String[] expected = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
        Assert.assertTrue(Arrays.equals(expected, daysOfWeek));
    }

    @Test
    public void testGetInjectedIntegerArrayProperty() {
        Integer[] numbers = propertyService.getIntegerNumbers();
        assertNotNull(numbers);

        Integer[] expected = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        Assert.assertTrue(Arrays.equals(expected, numbers));
    }

    @Test
    public void testGetInjectedIntArrayProperty() {
        int[] numbers = propertyService.getIntNumbers();
        assertNotNull(numbers);

        int[] expected = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
        Assert.assertTrue(Arrays.equals(expected, numbers));
    }

    @Test
    public void testComplexJAXBProperty() {
        ReturnCodeProperties rc = propertyService.getComplexJAXBPropertyOne();
        assertEquals(10, rc.getA());
        assertEquals(new BigInteger("10"), rc.getB());
    }

    @Test
    public void testComplexJAXBPropertyFromFile() {
        ReturnCodeProperties rc = propertyService.getComplexJAXBPropertyTwo();
        System.out.println("SKSK: a =" + rc.getA());
        System.out.println("SKSK: b =" + rc.getB());
        assertEquals(20, rc.getA());
        assertEquals(new BigInteger("20"), rc.getB());
    }

    /**
     * Method annotated with
     * 
     * @BeforeClass is used for one time set Up, it executes before every tests. This method is used to create a test
     *              Embedded SCA node, to start the SCA node and to get a reference to 4 services namely 'abService'
     *              service, 'cdService' service, 'abcdService' service and 'propertyService' service
     */
    @BeforeClass
    public static void init() throws Exception {
        try {
            String location = ContributionLocationHelper.getContributionLocation("PropertyTest.composite");
            node = NodeFactory.newInstance().createNode("PropertyTest.composite", new Contribution("c1", location));
            node.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
        abService = node.getService(ABComponent.class, "ABComponent");
        cdService = node.getService(CDComponent.class, "CDComponent");
        abcdService = node.getService(ABCDComponent.class, "ABCDComponent");
        propertyService = node.getService(PropertyComponent.class, "PropertyComponent");
    }

    /**
     * Method annotated with
     * 
     * @AfterClass is used for one time Tear Down, it executes after every tests. This method is used to close the
     *             node, close any previously opened connections etc
     */
    @AfterClass
    public static void destroy() throws Exception {
        node.stop();
    }
}