Merge test folder of test branch
[iotivity.git] / test / src / tc / rc / junit / src / org / iotivity / test / rc / tc / stc / RCResourceConfigTest.java
1 /******************************************************************
2 *
3 * Copyright 2016 Samsung Electronics All Rights Reserved.
4 *
5 *
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ******************************************************************/
20 package org.iotivity.test.rc.tc.stc;
21
22 import java.util.List;
23
24 import org.iotivity.test.rc.tc.helper.RCHelper;
25
26 import static org.iotivity.test.rc.tc.helper.RCCommonUtil.*;
27
28 import org.iotivity.service.resourcecontainer.RcsResourceContainer;
29 import org.iotivity.service.resourcecontainer.ResourceConfig;
30
31 import android.content.Context;
32 import android.test.InstrumentationTestCase;
33 import android.util.Log;
34
35 public class RCResourceConfigTest extends InstrumentationTestCase {
36
37         private RcsResourceContainer m_ResourceContainer;
38         private Context m_Context = null;
39         private RCHelper m_RCHelper;
40         private static boolean isCopied = false;
41         private String configFile;
42         private String sdCardPath;
43
44         protected void setUp() throws Exception {
45                 super.setUp();
46
47                 m_Context = getInstrumentation().getTargetContext();
48
49                 m_RCHelper = RCHelper.getInstance();
50
51                 isCopied = m_RCHelper.copyFilesToDevice(m_Context);
52
53                 sdCardPath = m_RCHelper.getFilesPath(getInstrumentation()
54                                 .getTargetContext()) + PATH_INDICATOR;
55
56                 configFile = sdCardPath + RESOURCE_CONTAINER_CONFIG_XML;
57
58                 if (!isCopied) {
59                         Log.d(TAG, "Can't copy the files from assets/lib folder");
60                 } else {
61                         Log.d(TAG, "Successfully copied files from assets/lib folder");
62                 }
63
64                 m_ResourceContainer = new RcsResourceContainer(m_Context);
65         }
66
67         /**
68          * @since 2016-03-10
69          * @see StartContainer
70          * @objective Test 'setName' function with DI Bundle Resource Name
71          * @target public void setName()
72          * @test_data configFile
73          * @pre_condition Start Container
74          * @procedure Perform setName()
75          * @post_condition Stop Container
76          * @expected Set the name of a resource
77          **/
78         public void testSetGetName_GSRV_P() {
79
80                 try {
81
82                         m_ResourceContainer.startContainer(configFile);
83
84                         List<ResourceConfig> resourceConfigList = m_ResourceContainer
85                                         .getConfiguredBundleResources(DI_BUNDLE_ID);
86
87                         resourceConfigList.get(0).setName(DI_BUNDLE_RESOURCE1_NAME_SET);
88
89                         String name = resourceConfigList.get(0).getName();
90
91                         assertEquals(name, DI_BUNDLE_RESOURCE1_NAME_SET);
92
93                         m_ResourceContainer.stopContainer();
94
95                 } catch (Exception e) {
96                         fail("Can't set name because of the exception: "
97                                         + e.getLocalizedMessage());
98                 }
99         }
100
101         /**
102          * @since 2016-03-10
103          * @see StartContainer
104          * @objective Test 'setURI' function with DI Bundle Resource URI
105          * @target public void setURI()
106          * @test_data configFile
107          * @pre_condition Start Container
108          * @procedure Perform setURI()
109          * @post_condition Stop Container
110          * @expected Set the URI of a resource
111          **/
112         public void testSetGetURI_GSRV_P() {
113
114                 try {
115
116                         m_ResourceContainer.startContainer(configFile);
117
118                         List<ResourceConfig> resourceConfigList = m_ResourceContainer
119                                         .getConfiguredBundleResources(DI_BUNDLE_ID);
120
121                         resourceConfigList.get(0).setURI(DI_BUNDLE_RESOURCE1_URI_SET);
122
123                         String resURI = resourceConfigList.get(0).getURI();
124
125                         assertEquals(resURI, DI_BUNDLE_RESOURCE1_URI_SET);
126
127                         m_ResourceContainer.stopContainer();
128
129                 } catch (Exception e) {
130                         fail("Can't  get URI because of the exception: "
131                                         + e.getLocalizedMessage());
132                 }
133         }
134
135         /**
136          * @since 2016-03-10
137          * @see StartContainer
138          * @objective Test 'getResourceType' function with DI Bundle Resource Type
139          * @target public void getResourceType()
140          * @test_data configFile
141          * @pre_condition Start Container
142          * @procedure Perform getResourceType()
143          * @post_condition Stop Container
144          * @expected Set the Resource Type of a resource
145          **/
146         public void testSetGetResourceType_GSRV_P() {
147
148                 try {
149
150                         m_ResourceContainer.startContainer(configFile);
151
152                         List<ResourceConfig> resourceConfigList = m_ResourceContainer
153                                         .getConfiguredBundleResources(DI_BUNDLE_ID);
154
155                         resourceConfigList.get(0).setResourceType(
156                                         DI_SENSOR_RESOURCE_TYPE_SET);
157
158                         String resType = resourceConfigList.get(0).getResourceType();
159
160                         assertEquals(resType, DI_SENSOR_RESOURCE_TYPE_SET);
161
162                         m_ResourceContainer.stopContainer();
163
164                 } catch (Exception e) {
165                         fail("Can't  get URI because of the exception: "
166                                         + e.getLocalizedMessage());
167                 }
168         }
169
170         /**
171          * @since 2016-03-10
172          * @see StartContainer
173          * @objective Test 'setAddress' function with DI Bundle Resource Address
174          * @target public void setAddress()
175          * @test_data configFile
176          * @pre_condition Start Container
177          * @procedure Perform setAddress()
178          * @post_condition Stop Container
179          * @expected Set the Address Type of a resource
180          **/
181         public void testSetGetAddress_GSRV_P() {
182
183                 try {
184
185                         m_ResourceContainer.startContainer(configFile);
186
187                         List<ResourceConfig> resourceConfigList = m_ResourceContainer
188                                         .getConfiguredBundleResources(DI_BUNDLE_ID);
189
190                         resourceConfigList.get(0)
191                                         .setAddress(DI_SENSOR_RESOURCE_ADDRESS_SET);
192
193                         String address = resourceConfigList.get(0).getAddress();
194
195                         assertEquals(address, DI_SENSOR_RESOURCE_ADDRESS_SET);
196
197                         m_ResourceContainer.stopContainer();
198
199                 } catch (Exception e) {
200                         fail("Can't  get URI because of the exception: "
201                                         + e.getLocalizedMessage());
202                 }
203         }
204
205 }