remove prefix .well-known uri & change from 'ocf' to 'oic' uri
[iotivity.git] / cloud / interface / src / test / java / org / iotivity / cloud / ciserver / resources / proxy / account / AclTest.java
1 package org.iotivity.cloud.ciserver.resources.proxy.account;
2
3 import static java.util.concurrent.TimeUnit.SECONDS;
4 import static org.junit.Assert.assertEquals;
5 import static org.junit.Assert.assertTrue;
6 import static org.mockito.Mockito.mock;
7
8 import java.util.concurrent.CountDownLatch;
9
10 import org.iotivity.cloud.base.OICConstants;
11 import org.iotivity.cloud.base.connector.ConnectorPool;
12 import org.iotivity.cloud.base.device.CoapDevice;
13 import org.iotivity.cloud.base.device.IRequestChannel;
14 import org.iotivity.cloud.base.protocols.IRequest;
15 import org.iotivity.cloud.base.protocols.MessageBuilder;
16 import org.iotivity.cloud.base.protocols.coap.CoapRequest;
17 import org.iotivity.cloud.base.protocols.enums.RequestMethod;
18 import org.iotivity.cloud.ciserver.DeviceServerSystem;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.InjectMocks;
22 import org.mockito.Mock;
23 import org.mockito.Mockito;
24 import org.mockito.MockitoAnnotations;
25 import org.mockito.invocation.InvocationOnMock;
26 import org.mockito.stubbing.Answer;
27
28 public class AclTest {
29     private static final String TEST_RESOURCE_ACI_URI = "/"
30             + OICConstants.PREFIX_OIC + "/" + OICConstants.ACL_URI;
31     private CoapDevice          mockDevice            = mock(CoapDevice.class);
32     IRequest                    req                   = null;
33     ConnectorPool               connectorPool         = null;
34     DeviceServerSystem          deviceServerSystem    = new DeviceServerSystem();
35     final CountDownLatch        latch                 = new CountDownLatch(1);
36
37     @Mock
38     IRequestChannel             requestChannel;
39
40     @InjectMocks
41     Acl                         aclHandler            = new Acl();
42
43     @Before
44     public void setUp() throws Exception {
45         req = null;
46         MockitoAnnotations.initMocks(this);
47         deviceServerSystem.addResource(aclHandler);
48         // callback mock
49         Mockito.doAnswer(new Answer<Object>() {
50             @Override
51             public CoapRequest answer(InvocationOnMock invocation)
52                     throws Throwable {
53                 Object[] args = invocation.getArguments();
54                 CoapRequest request = (CoapRequest) args[0];
55                 System.out.println(
56                         "\t----------payload : " + request.getPayloadString());
57                 System.out.println(
58                         "\t----------uripath : " + request.getUriPath());
59                 System.out.println(
60                         "\t---------uriquery : " + request.getUriQuery());
61                 req = request;
62                 latch.countDown();
63                 return null;
64             }
65         }).when(requestChannel).sendRequest(Mockito.any(IRequest.class),
66                 Mockito.any(CoapDevice.class));
67     }
68
69     @Test
70     public void testOnDefaultRequestReceived() throws Exception {
71         System.out.println(
72                 "\t--------------OnRequestReceived(AS)Test------------");
73
74         IRequest request = MessageBuilder.createRequest(RequestMethod.POST,
75                 TEST_RESOURCE_ACI_URI, null, null, null);
76         aclHandler.onRequestReceived(mockDevice, request);
77
78         assertTrue(latch.await(1L, SECONDS));
79         assertEquals(req.getUriPath(), TEST_RESOURCE_ACI_URI);
80     }
81 }