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;
21 import org.oic.simulator.AttributeValue;
22 import org.oic.simulator.InvalidArgsException;
23 import org.oic.simulator.SimulatorResourceAttribute;
24 import org.oic.simulator.SimulatorResourceModel;
26 import junit.framework.TestCase;
29 * This class tests the APIs of SimulatorResourceModel class.
31 public class SimulatorResourceModelTest extends TestCase {
32 private static final String INT_KEY = "Interger";
33 private static final String DOUBLE_KEY = "Double";
34 private static final String BOOL_KEY = "Boolean";
35 private static final String STRING_KEY = "String";
38 protected void setUp() throws Exception {
43 protected void tearDown() throws Exception {
47 public void testSimulatorResourceModel_P01() {
48 SimulatorResourceModel resModel = new SimulatorResourceModel();
49 assertNotNull(resModel);
52 public void testSetInt_P01() {
56 SimulatorResourceModel resModel = new SimulatorResourceModel();
57 resModel.set(INT_KEY, new AttributeValue(10));
58 result = ((Integer) resModel.get(INT_KEY).get()).intValue();
59 } catch (InvalidArgsException e) {
63 assertEquals(10, result);
66 public void testSetInt_P02() {
70 SimulatorResourceModel resModel = new SimulatorResourceModel();
71 resModel.set(INT_KEY, new AttributeValue(-10));
72 result = ((Integer) resModel.get(INT_KEY).get()).intValue();
73 } catch (InvalidArgsException e) {
77 assertEquals(-10, result);
80 public void testSetDouble_P01() {
84 SimulatorResourceModel resModel = new SimulatorResourceModel();
85 resModel.set(DOUBLE_KEY, new AttributeValue(4.0));
86 result = ((Double) resModel.get(DOUBLE_KEY).get()).doubleValue();
87 } catch (InvalidArgsException e) {
91 assertEquals(4.0, result);
94 public void testSetDouble_P02() {
98 SimulatorResourceModel resModel = new SimulatorResourceModel();
99 resModel.set(DOUBLE_KEY, new AttributeValue(-4.0));
100 result = ((Double) resModel.get(DOUBLE_KEY).get()).doubleValue();
101 } catch (InvalidArgsException e) {
105 assertEquals(-4.0, result);
108 public void testSetBoolean_P01() {
109 boolean result = false;
112 SimulatorResourceModel resModel = new SimulatorResourceModel();
113 resModel.set(BOOL_KEY, new AttributeValue(true));
114 result = ((Boolean) resModel.get(BOOL_KEY).get()).booleanValue();
115 } catch (InvalidArgsException e) {
119 assertEquals(true, result);
122 public void testSetString_P01() {
123 String result = null;
126 SimulatorResourceModel resModel = new SimulatorResourceModel();
127 resModel.set(STRING_KEY, new AttributeValue("string-value"));
128 result = (String) resModel.get(STRING_KEY).get();
129 } catch (InvalidArgsException e) {
133 assertEquals("string-value", result);
136 public void testSetString_P02() {
137 String result = null;
140 SimulatorResourceModel resModel = new SimulatorResourceModel();
141 resModel.set(STRING_KEY, new AttributeValue(""));
142 result = (String) resModel.get(STRING_KEY).get();
143 } catch (InvalidArgsException e) {
147 assertEquals("", result);
150 public void testSetString_P03() {
151 String result = null;
154 SimulatorResourceModel resModel = new SimulatorResourceModel();
155 resModel.set(STRING_KEY, new AttributeValue("@#$$&^*^(*^&"));
156 result = (String) resModel.get(STRING_KEY).get();
157 } catch (InvalidArgsException e) {
161 assertEquals("@#$$&^*^(*^&", result);
164 public void testSize_P01() {
167 SimulatorResourceModel resModel = new SimulatorResourceModel();
168 result = resModel.size();
170 assertEquals(0, result);
173 public void testSize_P02() {
176 SimulatorResourceModel resModel = new SimulatorResourceModel();
178 resModel.set(INT_KEY, new AttributeValue(1234));
179 resModel.set(DOUBLE_KEY, new AttributeValue(1.234));
180 resModel.set(BOOL_KEY, new AttributeValue(true));
181 resModel.set(STRING_KEY, new AttributeValue("string-value"));
182 result = resModel.size();
183 } catch (InvalidArgsException e) {
187 assertEquals(4, result);
190 public void testGet_P01() {
191 AttributeValue result = null;
193 SimulatorResourceModel resModel = new SimulatorResourceModel();
195 resModel.set(INT_KEY, new AttributeValue(10));
196 result = resModel.get(INT_KEY);
197 } catch (InvalidArgsException e) {
201 assertNotNull(result);
204 public void testGet_P02() {
205 Map<String, AttributeValue> result = null;
207 SimulatorResourceModel resModel = new SimulatorResourceModel();
209 resModel.set(INT_KEY, new AttributeValue(1234));
210 resModel.set(DOUBLE_KEY, new AttributeValue(1.234));
211 resModel.set(BOOL_KEY, new AttributeValue(true));
212 resModel.set(STRING_KEY, new AttributeValue("string-value"));
213 result = resModel.get();
214 } catch (InvalidArgsException e) {
218 assertNotNull(result);
219 assertEquals(4, result.size());