2 * //******************************************************************
4 * // Copyright 2016 Samsung Electronics All Rights Reserved.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 * // Licensed under the Apache License, Version 2.0 (the "License");
9 * // you may not use this file except in compliance with the License.
10 * // You may obtain a copy of the License at
12 * // http://www.apache.org/licenses/LICENSE-2.0
14 * // Unless required by applicable law or agreed to in writing, software
15 * // distributed under the License is distributed on an "AS IS" BASIS,
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * // See the License for the specific language governing permissions and
18 * // limitations under the License.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 package org.iotivity.cloud.ciserver.resources.proxy.account;
25 import static java.util.concurrent.TimeUnit.SECONDS;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertTrue;
28 import static org.mockito.Mockito.mock;
30 import java.util.concurrent.CountDownLatch;
32 import org.iotivity.cloud.base.OICConstants;
33 import org.iotivity.cloud.base.device.CoapDevice;
34 import org.iotivity.cloud.base.device.IRequestChannel;
35 import org.iotivity.cloud.base.protocols.IRequest;
36 import org.iotivity.cloud.base.protocols.MessageBuilder;
37 import org.iotivity.cloud.base.protocols.coap.CoapRequest;
38 import org.iotivity.cloud.base.protocols.enums.RequestMethod;
39 import org.iotivity.cloud.ciserver.DeviceServerSystem;
40 import org.junit.Before;
41 import org.junit.Test;
42 import org.mockito.InjectMocks;
43 import org.mockito.Mock;
44 import org.mockito.Mockito;
45 import org.mockito.MockitoAnnotations;
46 import org.mockito.invocation.InvocationOnMock;
47 import org.mockito.stubbing.Answer;
49 public class CertificateTest {
50 private static final String TEST_RESOURCE_CERTI_URI = "/"
51 + OICConstants.PREFIX_OIC + "/" + OICConstants.CREDPROV_URI + "/"
52 + OICConstants.CERT_URI;
53 private CoapDevice mMockDevice = mock(
55 private IRequest mReq = null;
56 private DeviceServerSystem mDeviceServerSystem = new DeviceServerSystem();
57 final CountDownLatch mLatch = new CountDownLatch(1);
60 private IRequestChannel mRequestChannel;
63 private Certificate mCertHandler = new Certificate();
66 public void setUp() throws Exception {
68 MockitoAnnotations.initMocks(this);
69 mDeviceServerSystem.addResource(mCertHandler);
71 Mockito.doAnswer(new Answer<Object>() {
73 public CoapRequest answer(InvocationOnMock invocation)
75 Object[] args = invocation.getArguments();
76 CoapRequest request = (CoapRequest) args[0];
78 "\t----------payload : " + request.getPayloadString());
80 "\t----------uripath : " + request.getUriPath());
82 "\t---------uriquery : " + request.getUriQuery());
87 }).when(mRequestChannel).sendRequest(Mockito.any(IRequest.class),
88 Mockito.any(CoapDevice.class));
92 public void testOnDefaultRequestReceived() throws Exception {
94 "\t--------------OnRequestReceived(AS) Test------------");
96 IRequest request = MessageBuilder.createRequest(RequestMethod.POST,
97 TEST_RESOURCE_CERTI_URI, null, null, null);
98 mCertHandler.onRequestReceived(mMockDevice, request);
100 assertTrue(mLatch.await(1L, SECONDS));
101 assertEquals(mReq.getUriPath(), TEST_RESOURCE_CERTI_URI);