2 * Copyright 2015 Samsung Electronics All Rights Reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.oic.simulator.test;
19 import org.oic.simulator.AttributeValue;
20 import org.oic.simulator.InvalidArgsException;
21 import org.oic.simulator.SimulatorResourceModel;
23 import junit.framework.TestCase;
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";
31 protected void setUp() throws Exception {
35 protected void tearDown() throws Exception {
39 public void testAttributeValueInt_P01() {
40 AttributeValue value = new AttributeValue(5);
43 assertTrue(value.typeInfo() != null
44 && value.typeInfo().mType == AttributeValue.ValueType.INTEGER
45 && value.typeInfo().mBaseType == AttributeValue.ValueType.INTEGER
46 && value.typeInfo().mDepth == 0);
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);
58 public void testAttributeValueDouble_P01() {
59 AttributeValue value = new AttributeValue(5.00);
62 assertTrue(value.typeInfo() != null
63 && value.typeInfo().mType == AttributeValue.ValueType.DOUBLE
64 && value.typeInfo().mBaseType == AttributeValue.ValueType.DOUBLE
65 && value.typeInfo().mDepth == 0);
68 public void testAttributeValueDouble_P02() {
69 AttributeValue value = new AttributeValue(new Double(5.00));
72 assertTrue(value.typeInfo() != null
73 && value.typeInfo().mType == AttributeValue.ValueType.DOUBLE
74 && value.typeInfo().mBaseType == AttributeValue.ValueType.DOUBLE
75 && value.typeInfo().mDepth == 0);
78 public void testAttributeValueBoolean_P01() {
79 AttributeValue value = new AttributeValue(true);
82 assertTrue(value.typeInfo() != null
83 && value.typeInfo().mType == AttributeValue.ValueType.BOOLEAN
84 && value.typeInfo().mBaseType == AttributeValue.ValueType.BOOLEAN
85 && value.typeInfo().mDepth == 0);
88 public void testAttributeValueBoolean_P02() {
89 AttributeValue value = new AttributeValue(new Boolean(true));
92 assertTrue(value.typeInfo() != null
93 && value.typeInfo().mType == AttributeValue.ValueType.BOOLEAN
94 && value.typeInfo().mBaseType == AttributeValue.ValueType.BOOLEAN
95 && value.typeInfo().mDepth == 0);
98 public void testAttributeValueString_P01() {
99 AttributeValue value = new AttributeValue("String");
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);
108 public void testAttributeValueString_P02() {
109 AttributeValue value = new AttributeValue(new String("String"));
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);
118 public void testAttributeValueSimulatorResourceModel() {
119 SimulatorResourceModel model = new SimulatorResourceModel();
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) {
129 if (model.size() != 4)
130 fail("Failed to construct model for continuing test!");
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);
140 public void testAttributeValueIntArray_P01() {
141 int[] array = { 1, 2, 3 };
142 AttributeValue value = new AttributeValue(array);
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);
151 public void testAttributeValueIntArray_P02() {
152 Integer[] array = { new Integer(1), new Integer(2), new Integer(3) };
153 AttributeValue value = new AttributeValue(array);
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);
162 public void testAttributeValueDoubleArray_P01() {
163 double[] array = { 1.00, 2.00, 3.00 };
164 AttributeValue value = new AttributeValue(array);
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);
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);
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);
184 public void testAttributeValueBooleanArray_P01() {
185 boolean[] array = { true };
186 AttributeValue value = new AttributeValue(array);
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);
195 public void testAttributeValueBooleanArray_P02() {
196 boolean[] array = { new Boolean(true) };
197 AttributeValue value = new AttributeValue(array);
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);
206 public void testAttributeValueStringArray_P01() {
207 String[] array = { "string1", "string2" };
208 AttributeValue value = new AttributeValue(array);
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);
217 public void testAttributeValueStringArray_P02() {
218 String[] array = { new String("string1"), new String("string2") };
219 AttributeValue value = new AttributeValue(array);
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);
228 public void testAttributeValueSimulatorResourceModelArray() {
229 SimulatorResourceModel childModel = new SimulatorResourceModel();
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) {
239 if (childModel.size() != 4)
240 fail("Failed to construct model for continuing test!");
242 SimulatorResourceModel[] array = { childModel };
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);
252 public void testAttributeValueIntArrayArray_P01() {
253 int[][] array = { { 1, 2, 3 } };
254 AttributeValue value = new AttributeValue(array);
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);
263 public void testAttributeValueIntArrayArray_P02() {
264 Integer[][] array = { { new Integer(1), new Integer(2), new Integer(3) } };
265 AttributeValue value = new AttributeValue(array);
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);
274 public void testAttributeValueDoubleArrayArray_P01() {
275 double[][] array = { { 1.00, 2.00, 3.00 } };
276 AttributeValue value = new AttributeValue(array);
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);
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);
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);
297 public void testAttributeValueBooleanArrayArray_P01() {
298 boolean[][] array = { { true } };
299 AttributeValue value = new AttributeValue(array);
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);
308 public void testAttributeValueBooleanArrayArray_P02() {
309 Boolean[][] array = { { new Boolean(true) } };
310 AttributeValue value = new AttributeValue(array);
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);
319 public void testAttributeValueStringArrayArray_P01() {
320 String[][] array = { { "string" } };
321 AttributeValue value = new AttributeValue(array);
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);
330 public void testAttributeValueStringArrayArray_P02() {
331 String[][] array = { { new String("string") } };
332 AttributeValue value = new AttributeValue(array);
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);
341 public void testAttributeValueSimulatorResourceModelArrayArray() {
342 SimulatorResourceModel childModel = new SimulatorResourceModel();
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) {
352 if (childModel.size() != 4)
353 fail("Failed to construct model for continuing test!");
355 SimulatorResourceModel[][] array = { { childModel } };
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);
365 public void testAttributeValueIntArrayArrayArray_P01() {
366 int[][][] array = { { { 1, 2, 3 } } };
367 AttributeValue value = new AttributeValue(array);
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);
376 public void testAttributeValueIntArrayArrayArray_P02() {
377 Integer[][][] array = { { { new Integer(1), new Integer(2),
378 new Integer(3) } } };
379 AttributeValue value = new AttributeValue(array);
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);
388 public void testAttributeValueDoubleArrayArrayArray_P01() {
389 double[][][] array = { { { 1.00, 2.00, 3.00 } } };
390 AttributeValue value = new AttributeValue(array);
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);
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);
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);
411 public void testAttributeValueBooleanArrayArrayArray_P01() {
412 boolean[][][] array = { { { true } } };
413 AttributeValue value = new AttributeValue(array);
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);
422 public void testAttributeValueBooleanArrayArrayArray_P02() {
423 Boolean[][][] array = { { { new Boolean(true) } } };
424 AttributeValue value = new AttributeValue(array);
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);
433 public void testAttributeValueStringArrayArrayArray_P01() {
434 String[][][] array = { { { "string" } } };
435 AttributeValue value = new AttributeValue(array);
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);
444 public void testAttributeValueStringArrayArrayArray_P02() {
445 String[][][] array = { { { new String("string") } } };
446 AttributeValue value = new AttributeValue(array);
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);
455 public void testAttributeValueSimulatorResourceModelArrayArrayArray() {
456 SimulatorResourceModel childModel = new SimulatorResourceModel();
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) {
466 if (childModel.size() != 4)
467 fail("Failed to construct model for continuing test!");
469 SimulatorResourceModel[][][] array = { { { childModel } } };
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);