JUnit test cases for updated APIs.
[platform/upstream/iotivity.git] / service / simulator / unittests / SimulatorTest / src / org / oic / simulator / test / AttributeValueTest.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.oic.simulator.test;
18
19 import org.oic.simulator.AttributeValue;
20 import org.oic.simulator.InvalidArgsException;
21 import org.oic.simulator.SimulatorResourceModel;
22
23 import junit.framework.TestCase;
24
25 public class AttributeValueTest extends TestCase {
26     private static final String INT_KEY    = "Interger";
27     private static final String DOUBLE_KEY = "Double";
28     private static final String BOOL_KEY   = "Boolean";
29     private static final String STRING_KEY = "String";
30
31     protected void setUp() throws Exception {
32         super.setUp();
33     }
34
35     protected void tearDown() throws Exception {
36         super.tearDown();
37     }
38
39     public void testAttributeValueInt_P01() {
40         AttributeValue value = new AttributeValue(5);
41
42         assertNotNull(value);
43         assertTrue(value.typeInfo() != null
44                 && value.typeInfo().mType == AttributeValue.ValueType.INTEGER
45                 && value.typeInfo().mBaseType == AttributeValue.ValueType.INTEGER
46                 && value.typeInfo().mDepth == 0);
47     }
48
49     public void testAttributeValueInt_P02() {
50         AttributeValue attribute = new AttributeValue(new Integer(5));
51         assertNotNull(attribute);
52         assertTrue(attribute.typeInfo() != null
53                 && attribute.typeInfo().mType == AttributeValue.ValueType.INTEGER
54                 && attribute.typeInfo().mBaseType == AttributeValue.ValueType.INTEGER
55                 && attribute.typeInfo().mDepth == 0);
56     }
57
58     public void testAttributeValueDouble_P01() {
59         AttributeValue value = new AttributeValue(5.00);
60
61         assertNotNull(value);
62         assertTrue(value.typeInfo() != null
63                 && value.typeInfo().mType == AttributeValue.ValueType.DOUBLE
64                 && value.typeInfo().mBaseType == AttributeValue.ValueType.DOUBLE
65                 && value.typeInfo().mDepth == 0);
66     }
67
68     public void testAttributeValueDouble_P02() {
69         AttributeValue value = new AttributeValue(new Double(5.00));
70
71         assertNotNull(value);
72         assertTrue(value.typeInfo() != null
73                 && value.typeInfo().mType == AttributeValue.ValueType.DOUBLE
74                 && value.typeInfo().mBaseType == AttributeValue.ValueType.DOUBLE
75                 && value.typeInfo().mDepth == 0);
76     }
77
78     public void testAttributeValueBoolean_P01() {
79         AttributeValue value = new AttributeValue(true);
80
81         assertNotNull(value);
82         assertTrue(value.typeInfo() != null
83                 && value.typeInfo().mType == AttributeValue.ValueType.BOOLEAN
84                 && value.typeInfo().mBaseType == AttributeValue.ValueType.BOOLEAN
85                 && value.typeInfo().mDepth == 0);
86     }
87
88     public void testAttributeValueBoolean_P02() {
89         AttributeValue value = new AttributeValue(new Boolean(true));
90
91         assertNotNull(value);
92         assertTrue(value.typeInfo() != null
93                 && value.typeInfo().mType == AttributeValue.ValueType.BOOLEAN
94                 && value.typeInfo().mBaseType == AttributeValue.ValueType.BOOLEAN
95                 && value.typeInfo().mDepth == 0);
96     }
97
98     public void testAttributeValueString_P01() {
99         AttributeValue value = new AttributeValue("String");
100
101         assertNotNull(value);
102         assertTrue(value.typeInfo() != null
103                 && value.typeInfo().mType == AttributeValue.ValueType.STRING
104                 && value.typeInfo().mBaseType == AttributeValue.ValueType.STRING
105                 && value.typeInfo().mDepth == 0);
106     }
107
108     public void testAttributeValueString_P02() {
109         AttributeValue value = new AttributeValue(new String("String"));
110
111         assertNotNull(value);
112         assertTrue(value.typeInfo() != null
113                 && value.typeInfo().mType == AttributeValue.ValueType.STRING
114                 && value.typeInfo().mBaseType == AttributeValue.ValueType.STRING
115                 && value.typeInfo().mDepth == 0);
116     }
117
118     public void testAttributeValueSimulatorResourceModel() {
119         SimulatorResourceModel model = new SimulatorResourceModel();
120         try {
121             model.addAttribute(INT_KEY, new AttributeValue(1));
122             model.addAttribute(DOUBLE_KEY, new AttributeValue(1.00));
123             model.addAttribute(BOOL_KEY, new AttributeValue(true));
124             model.addAttribute(STRING_KEY, new AttributeValue("string"));
125         } catch (InvalidArgsException e) {
126             e.printStackTrace();
127         }
128
129         if (model.size() != 4)
130             fail("Failed to construct model for continuing test!");
131
132         AttributeValue value = new AttributeValue(model);
133         assertNotNull(value);
134         assertTrue(value.typeInfo() != null
135                 && value.typeInfo().mType == AttributeValue.ValueType.RESOURCEMODEL
136                 && value.typeInfo().mBaseType == AttributeValue.ValueType.RESOURCEMODEL
137                 && value.typeInfo().mDepth == 0);
138     }
139
140     public void testAttributeValueIntArray_P01() {
141         int[] array = { 1, 2, 3 };
142         AttributeValue value = new AttributeValue(array);
143
144         assertNotNull(value);
145         assertTrue(value.typeInfo() != null
146                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
147                 && value.typeInfo().mBaseType == AttributeValue.ValueType.INTEGER
148                 && value.typeInfo().mDepth == 1);
149     }
150
151     public void testAttributeValueIntArray_P02() {
152         Integer[] array = { new Integer(1), new Integer(2), new Integer(3) };
153         AttributeValue value = new AttributeValue(array);
154
155         assertNotNull(value);
156         assertTrue(value.typeInfo() != null
157                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
158                 && value.typeInfo().mBaseType == AttributeValue.ValueType.INTEGER
159                 && value.typeInfo().mDepth == 1);
160     }
161
162     public void testAttributeValueDoubleArray_P01() {
163         double[] array = { 1.00, 2.00, 3.00 };
164         AttributeValue value = new AttributeValue(array);
165
166         assertNotNull(value);
167         assertTrue(value.typeInfo() != null
168                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
169                 && value.typeInfo().mBaseType == AttributeValue.ValueType.DOUBLE
170                 && value.typeInfo().mDepth == 1);
171     }
172
173     public void testAttributeValueDoubleArray_P02() {
174         Double[] array = { new Double(1.00), new Double(2.00), new Double(3.00) };
175         AttributeValue value = new AttributeValue(array);
176
177         assertNotNull(value);
178         assertTrue(value.typeInfo() != null
179                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
180                 && value.typeInfo().mBaseType == AttributeValue.ValueType.DOUBLE
181                 && value.typeInfo().mDepth == 1);
182     }
183
184     public void testAttributeValueBooleanArray_P01() {
185         boolean[] array = { true };
186         AttributeValue value = new AttributeValue(array);
187
188         assertNotNull(value);
189         assertTrue(value.typeInfo() != null
190                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
191                 && value.typeInfo().mBaseType == AttributeValue.ValueType.BOOLEAN
192                 && value.typeInfo().mDepth == 1);
193     }
194
195     public void testAttributeValueBooleanArray_P02() {
196         boolean[] array = { new Boolean(true) };
197         AttributeValue value = new AttributeValue(array);
198
199         assertNotNull(value);
200         assertTrue(value.typeInfo() != null
201                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
202                 && value.typeInfo().mBaseType == AttributeValue.ValueType.BOOLEAN
203                 && value.typeInfo().mDepth == 1);
204     }
205
206     public void testAttributeValueStringArray_P01() {
207         String[] array = { "string1", "string2" };
208         AttributeValue value = new AttributeValue(array);
209
210         assertNotNull(value);
211         assertTrue(value.typeInfo() != null
212                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
213                 && value.typeInfo().mBaseType == AttributeValue.ValueType.STRING
214                 && value.typeInfo().mDepth == 1);
215     }
216
217     public void testAttributeValueStringArray_P02() {
218         String[] array = { new String("string1"), new String("string2") };
219         AttributeValue value = new AttributeValue(array);
220
221         assertNotNull(value);
222         assertTrue(value.typeInfo() != null
223                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
224                 && value.typeInfo().mBaseType == AttributeValue.ValueType.STRING
225                 && value.typeInfo().mDepth == 1);
226     }
227
228     public void testAttributeValueSimulatorResourceModelArray() {
229         SimulatorResourceModel childModel = new SimulatorResourceModel();
230         try {
231             childModel.addAttribute(INT_KEY, new AttributeValue(1));
232             childModel.addAttribute(DOUBLE_KEY, new AttributeValue(1.00));
233             childModel.addAttribute(BOOL_KEY, new AttributeValue(true));
234             childModel.addAttribute(STRING_KEY, new AttributeValue("string"));
235         } catch (InvalidArgsException e) {
236             e.printStackTrace();
237         }
238
239         if (childModel.size() != 4)
240             fail("Failed to construct model for continuing test!");
241
242         SimulatorResourceModel[] array = { childModel };
243
244         AttributeValue value = new AttributeValue(array);
245         assertNotNull(value);
246         assertTrue(value.typeInfo() != null
247                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
248                 && value.typeInfo().mBaseType == AttributeValue.ValueType.RESOURCEMODEL
249                 && value.typeInfo().mDepth == 1);
250     }
251
252     public void testAttributeValueIntArrayArray_P01() {
253         int[][] array = { { 1, 2, 3 } };
254         AttributeValue value = new AttributeValue(array);
255
256         assertNotNull(value);
257         assertTrue(value.typeInfo() != null
258                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
259                 && value.typeInfo().mBaseType == AttributeValue.ValueType.INTEGER
260                 && value.typeInfo().mDepth == 2);
261     }
262
263     public void testAttributeValueIntArrayArray_P02() {
264         Integer[][] array = { { new Integer(1), new Integer(2), new Integer(3) } };
265         AttributeValue value = new AttributeValue(array);
266
267         assertNotNull(value);
268         assertTrue(value.typeInfo() != null
269                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
270                 && value.typeInfo().mBaseType == AttributeValue.ValueType.INTEGER
271                 && value.typeInfo().mDepth == 2);
272     }
273
274     public void testAttributeValueDoubleArrayArray_P01() {
275         double[][] array = { { 1.00, 2.00, 3.00 } };
276         AttributeValue value = new AttributeValue(array);
277
278         assertNotNull(value);
279         assertTrue(value.typeInfo() != null
280                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
281                 && value.typeInfo().mBaseType == AttributeValue.ValueType.DOUBLE
282                 && value.typeInfo().mDepth == 2);
283     }
284
285     public void testAttributeValueDoubleArrayArray_P02() {
286         Double[][] array = { { new Double(1.00), new Double(2.00),
287                 new Double(3.00) } };
288         AttributeValue value = new AttributeValue(array);
289
290         assertNotNull(value);
291         assertTrue(value.typeInfo() != null
292                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
293                 && value.typeInfo().mBaseType == AttributeValue.ValueType.DOUBLE
294                 && value.typeInfo().mDepth == 2);
295     }
296
297     public void testAttributeValueBooleanArrayArray_P01() {
298         boolean[][] array = { { true } };
299         AttributeValue value = new AttributeValue(array);
300
301         assertNotNull(value);
302         assertTrue(value.typeInfo() != null
303                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
304                 && value.typeInfo().mBaseType == AttributeValue.ValueType.BOOLEAN
305                 && value.typeInfo().mDepth == 2);
306     }
307
308     public void testAttributeValueBooleanArrayArray_P02() {
309         Boolean[][] array = { { new Boolean(true) } };
310         AttributeValue value = new AttributeValue(array);
311
312         assertNotNull(value);
313         assertTrue(value.typeInfo() != null
314                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
315                 && value.typeInfo().mBaseType == AttributeValue.ValueType.BOOLEAN
316                 && value.typeInfo().mDepth == 2);
317     }
318
319     public void testAttributeValueStringArrayArray_P01() {
320         String[][] array = { { "string" } };
321         AttributeValue value = new AttributeValue(array);
322
323         assertNotNull(value);
324         assertTrue(value.typeInfo() != null
325                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
326                 && value.typeInfo().mBaseType == AttributeValue.ValueType.STRING
327                 && value.typeInfo().mDepth == 2);
328     }
329
330     public void testAttributeValueStringArrayArray_P02() {
331         String[][] array = { { new String("string") } };
332         AttributeValue value = new AttributeValue(array);
333
334         assertNotNull(value);
335         assertTrue(value.typeInfo() != null
336                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
337                 && value.typeInfo().mBaseType == AttributeValue.ValueType.STRING
338                 && value.typeInfo().mDepth == 2);
339     }
340
341     public void testAttributeValueSimulatorResourceModelArrayArray() {
342         SimulatorResourceModel childModel = new SimulatorResourceModel();
343         try {
344             childModel.addAttribute(INT_KEY, new AttributeValue(1));
345             childModel.addAttribute(DOUBLE_KEY, new AttributeValue(1.00));
346             childModel.addAttribute(BOOL_KEY, new AttributeValue(true));
347             childModel.addAttribute(STRING_KEY, new AttributeValue("string"));
348         } catch (InvalidArgsException e) {
349             e.printStackTrace();
350         }
351
352         if (childModel.size() != 4)
353             fail("Failed to construct model for continuing test!");
354
355         SimulatorResourceModel[][] array = { { childModel } };
356
357         AttributeValue value = new AttributeValue(array);
358         assertNotNull(value);
359         assertTrue(value.typeInfo() != null
360                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
361                 && value.typeInfo().mBaseType == AttributeValue.ValueType.RESOURCEMODEL
362                 && value.typeInfo().mDepth == 2);
363     }
364
365     public void testAttributeValueIntArrayArrayArray_P01() {
366         int[][][] array = { { { 1, 2, 3 } } };
367         AttributeValue value = new AttributeValue(array);
368
369         assertNotNull(value);
370         assertTrue(value.typeInfo() != null
371                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
372                 && value.typeInfo().mBaseType == AttributeValue.ValueType.INTEGER
373                 && value.typeInfo().mDepth == 3);
374     }
375
376     public void testAttributeValueIntArrayArrayArray_P02() {
377         Integer[][][] array = { { { new Integer(1), new Integer(2),
378                 new Integer(3) } } };
379         AttributeValue value = new AttributeValue(array);
380
381         assertNotNull(value);
382         assertTrue(value.typeInfo() != null
383                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
384                 && value.typeInfo().mBaseType == AttributeValue.ValueType.INTEGER
385                 && value.typeInfo().mDepth == 3);
386     }
387
388     public void testAttributeValueDoubleArrayArrayArray_P01() {
389         double[][][] array = { { { 1.00, 2.00, 3.00 } } };
390         AttributeValue value = new AttributeValue(array);
391
392         assertNotNull(value);
393         assertTrue(value.typeInfo() != null
394                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
395                 && value.typeInfo().mBaseType == AttributeValue.ValueType.DOUBLE
396                 && value.typeInfo().mDepth == 3);
397     }
398
399     public void testAttributeValueDoubleArrayArrayArray_P02() {
400         Double[][][] array = { { { new Double(1.00), new Double(2.00),
401                 new Double(3.00) } } };
402         AttributeValue value = new AttributeValue(array);
403
404         assertNotNull(value);
405         assertTrue(value.typeInfo() != null
406                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
407                 && value.typeInfo().mBaseType == AttributeValue.ValueType.DOUBLE
408                 && value.typeInfo().mDepth == 3);
409     }
410
411     public void testAttributeValueBooleanArrayArrayArray_P01() {
412         boolean[][][] array = { { { true } } };
413         AttributeValue value = new AttributeValue(array);
414
415         assertNotNull(value);
416         assertTrue(value.typeInfo() != null
417                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
418                 && value.typeInfo().mBaseType == AttributeValue.ValueType.BOOLEAN
419                 && value.typeInfo().mDepth == 3);
420     }
421
422     public void testAttributeValueBooleanArrayArrayArray_P02() {
423         Boolean[][][] array = { { { new Boolean(true) } } };
424         AttributeValue value = new AttributeValue(array);
425
426         assertNotNull(value);
427         assertTrue(value.typeInfo() != null
428                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
429                 && value.typeInfo().mBaseType == AttributeValue.ValueType.BOOLEAN
430                 && value.typeInfo().mDepth == 3);
431     }
432
433     public void testAttributeValueStringArrayArrayArray_P01() {
434         String[][][] array = { { { "string" } } };
435         AttributeValue value = new AttributeValue(array);
436
437         assertNotNull(value);
438         assertTrue(value.typeInfo() != null
439                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
440                 && value.typeInfo().mBaseType == AttributeValue.ValueType.STRING
441                 && value.typeInfo().mDepth == 3);
442     }
443
444     public void testAttributeValueStringArrayArrayArray_P02() {
445         String[][][] array = { { { new String("string") } } };
446         AttributeValue value = new AttributeValue(array);
447
448         assertNotNull(value);
449         assertTrue(value.typeInfo() != null
450                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
451                 && value.typeInfo().mBaseType == AttributeValue.ValueType.STRING
452                 && value.typeInfo().mDepth == 3);
453     }
454
455     public void testAttributeValueSimulatorResourceModelArrayArrayArray() {
456         SimulatorResourceModel childModel = new SimulatorResourceModel();
457         try {
458             childModel.addAttribute(INT_KEY, new AttributeValue(1));
459             childModel.addAttribute(DOUBLE_KEY, new AttributeValue(1.00));
460             childModel.addAttribute(BOOL_KEY, new AttributeValue(true));
461             childModel.addAttribute(STRING_KEY, new AttributeValue("string"));
462         } catch (InvalidArgsException e) {
463             e.printStackTrace();
464         }
465
466         if (childModel.size() != 4)
467             fail("Failed to construct model for continuing test!");
468
469         SimulatorResourceModel[][][] array = { { { childModel } } };
470
471         AttributeValue value = new AttributeValue(array);
472         assertNotNull(value);
473         assertTrue(value.typeInfo() != null
474                 && value.typeInfo().mType == AttributeValue.ValueType.ARRAY
475                 && value.typeInfo().mBaseType == AttributeValue.ValueType.RESOURCEMODEL
476                 && value.typeInfo().mDepth == 3);
477     }
478 }