Merge test folder of test branch
[iotivity.git] / test / src / tc / es / junit / src / org / iotivity / test / es / tc / stc / ESProvisionCloudPropertiesTest.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
21 package org.iotivity.test.es.tc.stc;
22
23 import org.iotivity.base.OcResource;
24 import org.iotivity.service.easysetup.mediator.CloudProp;
25 import org.iotivity.service.easysetup.mediator.ESException;
26 import org.iotivity.service.easysetup.mediator.EasySetup;
27 import org.iotivity.service.easysetup.mediator.RemoteEnrollee;
28 import org.iotivity.test.es.tc.helper.ESCloudPropProvCallback;
29 import org.iotivity.test.es.tc.helper.ESEnrolleeHelper;
30 import org.iotivity.test.es.tc.helper.ESPropertiesHelper;
31 import org.iotivity.test.es.tc.helper.ESUtility;
32 import static org.iotivity.test.es.tc.helper.ESUtility.*;
33
34 import android.test.AndroidTestCase;
35
36 public class ESProvisionCloudPropertiesTest extends AndroidTestCase {
37     private ESEnrolleeHelper eSEnrolleeHelper;
38
39     protected void setUp() throws Exception {
40         super.setUp();
41         eSEnrolleeHelper = new ESEnrolleeHelper();
42         ESCloudPropProvCallback.initialCallbackValuse();
43     }
44
45     protected void tearDown() throws Exception {
46         super.tearDown();
47         eSEnrolleeHelper = null;
48         ESCloudPropProvCallback.initialCallbackValuse();
49     }
50
51     /**
52      * @throws ESException
53      * @since 2016-08-14
54      * @see public void setCloudProp(String authCode, String authProvider,
55      *      String ciServer)
56      * @see public synchronized static EasySetup getInstance(Context context)
57      * @see public synchronized RemoteEnrollee createRemoteEnrollee(OcResource
58      *      enrolleeResource)
59      * @objective test provisionDeviceProperties positively
60      * @target public void provisionDeviceProperties(DeviceProp deviceProp,
61      *         DevicePropProvisioningCallback callback) throws ESException
62      * @test_data deviceProp DevicePropProvisioningCallback
63      * @pre_condition 1.create remote enrollee 2.cretae deviceprop
64      * @procedure 1. Call provisionDeviceProperties API.
65      * @post_condition none
66      * @expected provisionDeviceProperties call without exception
67      * 
68      */
69     public void testESCloudProvision_P_RSV() {
70
71         OcResource remoteEnrolleeResource = eSEnrolleeHelper
72                 .findEnrolleeResource(getContext());
73         assertNotNull("Got null remote enrollee resource",
74                 remoteEnrolleeResource);
75         RemoteEnrollee remoteEnrollee = EasySetup.getInstance(getContext())
76                 .createRemoteEnrollee(remoteEnrolleeResource);
77         assertNotNull("Got null remote enrollee", remoteEnrollee);
78         CloudProp cloudProp = ESPropertiesHelper.createCloudProperties();
79         assertNotNull("Got null deviceProp", cloudProp);
80
81         try {
82             remoteEnrollee.provisionCloudProperties(cloudProp,
83                     new ESCloudPropProvCallback());
84             ESUtility.waitUntilEnrolleeResponse(
85                     ESCloudPropProvCallback.isCloudPropProvCallbackCalled);
86
87         } catch (Exception ex) {
88             fail(EXCEPTION_SHOULD_NOT_BE_THROWN);
89         }
90         assertTrue("CloudPropProvCallback not called",
91                 ESCloudPropProvCallback.isCloudPropProvCallbackCalled);
92         assertTrue("Fail to find enrollee",
93                 ESCloudPropProvCallback.isEnrolleeFound);
94         ESCloudPropProvCallback.waitUntilProvSuccess(
95                 ESCloudPropProvCallback.isCloudPropSuccess);
96         assertTrue("Cloud provisioning fail : ",
97                 ESCloudPropProvCallback.isCloudPropSuccess);
98     }
99
100     /**
101      * @since 2016-08-19
102      * @see public synchronized static EasySetup getInstance(Context context)
103      * @see public synchronized RemoteEnrollee createRemoteEnrollee(OcResource
104      *      enrolleeResource)
105      * @objective test provisionDeviceProperties negatively
106      * @target public void provisionCloudProperties(CloudProp cloudProp,
107      *         CloudPropProvisioningCallback callback) throws ESException
108      * @test_data null cloudProp CloudPropProvisioningCallback
109      * @pre_condition create remote enrollee
110      * @procedure Call provisionCloudProperties API with null cloudProp
111      * @post_condition none
112      * @expected ES Exception should be thrown
113      */
114     public void testESProvisionCloudPropertiesWithNullCloudProp_ETC_N() {
115         OcResource remoteEnrolleeResource = eSEnrolleeHelper
116                 .findEnrolleeResource(getContext());
117         assertNotNull("Got null remote enrollee resource",
118                 remoteEnrolleeResource);
119         RemoteEnrollee remoteEnrollee = EasySetup.getInstance(getContext())
120                 .createRemoteEnrollee(remoteEnrolleeResource);
121         assertNotNull("Got null remote enrollee", remoteEnrollee);
122         CloudProp cloudProp = ESPropertiesHelper.createCloudProperties();
123         assertNotNull("Got null deviceProp", cloudProp);
124
125         try {
126             remoteEnrollee.provisionCloudProperties(null,
127                     new ESCloudPropProvCallback());
128             fail(EXCEPTION_SHOULD_BE_THROWN);
129         } catch (Exception e) {
130             assertTrue(true);
131         }
132     }
133
134 }