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 junit.framework.TestCase;
23 import org.oic.simulator.AttributeValue;
24 import org.oic.simulator.InvalidArgsException;
25 import org.oic.simulator.SimulatorResourceModel;
28 * This class tests the APIs of SimulatorResourceModel class.
30 public class SimulatorResourceModelTest extends TestCase {
31 private static final String INT_KEY = "Interger";
32 private static final String DOUBLE_KEY = "Double";
33 private static final String BOOL_KEY = "Boolean";
34 private static final String STRING_KEY = "String";
37 protected void setUp() throws Exception {
42 protected void tearDown() throws Exception {
46 public void testSimulatorResourceModel_P01() {
47 SimulatorResourceModel resModel = new SimulatorResourceModel();
48 assertNotNull(resModel);
51 public void testSetInt_P01() {
55 SimulatorResourceModel resModel = new SimulatorResourceModel();
56 resModel.set(INT_KEY, new AttributeValue(10));
57 result = ((Integer) resModel.get(INT_KEY).get()).intValue();
58 } catch (InvalidArgsException e) {
62 assertEquals(10, result);
65 public void testSetInt_P02() {
69 SimulatorResourceModel resModel = new SimulatorResourceModel();
70 resModel.set(INT_KEY, new AttributeValue(-10));
71 result = ((Integer) resModel.get(INT_KEY).get()).intValue();
72 } catch (InvalidArgsException e) {
76 assertEquals(-10, result);
79 public void testSetDouble_P01() {
83 SimulatorResourceModel resModel = new SimulatorResourceModel();
84 resModel.set(DOUBLE_KEY, new AttributeValue(4.0));
85 result = ((Double) resModel.get(DOUBLE_KEY).get()).doubleValue();
86 } catch (InvalidArgsException e) {
90 assertEquals(4.0, result);
93 public void testSetDouble_P02() {
97 SimulatorResourceModel resModel = new SimulatorResourceModel();
98 resModel.set(DOUBLE_KEY, new AttributeValue(-4.0));
99 result = ((Double) resModel.get(DOUBLE_KEY).get()).doubleValue();
100 } catch (InvalidArgsException e) {
104 assertEquals(-4.0, result);
107 public void testSetBoolean_P01() {
108 boolean result = false;
111 SimulatorResourceModel resModel = new SimulatorResourceModel();
112 resModel.set(BOOL_KEY, new AttributeValue(true));
113 result = ((Boolean) resModel.get(BOOL_KEY).get()).booleanValue();
114 } catch (InvalidArgsException e) {
118 assertEquals(true, result);
121 public void testSetString_P01() {
122 String result = null;
125 SimulatorResourceModel resModel = new SimulatorResourceModel();
126 resModel.set(STRING_KEY, new AttributeValue("string-value"));
127 result = (String) resModel.get(STRING_KEY).get();
128 } catch (InvalidArgsException e) {
132 assertEquals("string-value", result);
135 public void testSetString_P02() {
136 String result = null;
139 SimulatorResourceModel resModel = new SimulatorResourceModel();
140 resModel.set(STRING_KEY, new AttributeValue(""));
141 result = (String) resModel.get(STRING_KEY).get();
142 } catch (InvalidArgsException e) {
146 assertEquals("", result);
149 public void testSetString_P03() {
150 String result = null;
153 SimulatorResourceModel resModel = new SimulatorResourceModel();
154 resModel.set(STRING_KEY, new AttributeValue("@#$$&^*^(*^&"));
155 result = (String) resModel.get(STRING_KEY).get();
156 } catch (InvalidArgsException e) {
160 assertEquals("@#$$&^*^(*^&", result);
163 public void testSize_P01() {
166 SimulatorResourceModel resModel = new SimulatorResourceModel();
167 result = resModel.size();
169 assertEquals(0, result);
172 public void testSize_P02() {
175 SimulatorResourceModel resModel = new SimulatorResourceModel();
177 resModel.set(INT_KEY, new AttributeValue(1234));
178 resModel.set(DOUBLE_KEY, new AttributeValue(1.234));
179 resModel.set(BOOL_KEY, new AttributeValue(true));
180 resModel.set(STRING_KEY, new AttributeValue("string-value"));
181 result = resModel.size();
182 } catch (InvalidArgsException e) {
186 assertEquals(4, result);
189 public void testGet_P01() {
190 AttributeValue result = null;
192 SimulatorResourceModel resModel = new SimulatorResourceModel();
194 resModel.set(INT_KEY, new AttributeValue(10));
195 result = resModel.get(INT_KEY);
196 } catch (InvalidArgsException e) {
200 assertNotNull(result);
203 public void testGet_P02() {
204 Map<String, AttributeValue> result = null;
206 SimulatorResourceModel resModel = new SimulatorResourceModel();
208 resModel.set(INT_KEY, new AttributeValue(1234));
209 resModel.set(DOUBLE_KEY, new AttributeValue(1.234));
210 resModel.set(BOOL_KEY, new AttributeValue(true));
211 resModel.set(STRING_KEY, new AttributeValue("string-value"));
212 result = resModel.get();
213 } catch (InvalidArgsException e) {
217 assertNotNull(result);
218 assertEquals(4, result.size());