[IOT-1556] Changes in cloud according to the stateless in CloudInterface and AccountS... 79/16079/4
authorJung Seungho <shonest.jung@samsung.com>
Tue, 15 Nov 2016 07:26:51 +0000 (16:26 +0900)
committerJee Hyeok Kim <jihyeok13.kim@samsung.com>
Tue, 17 Jan 2017 08:30:51 +0000 (08:30 +0000)
- appended uid in AclInvite, Account and AccoutSession in CI
- apppeded uid, members in AclGroup, ResourceFind, ResourcePresence and DevicePresence
- added logic for verifying accesstoken in AccountManger in AS
- fixed testcase

Change-Id: I468c13127452edaee7301b9cafd0ab9f28bbf65d
Signed-off-by: Jung Seungho <shonest.jung@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/14341
Reviewed-by: Yeonghun Nam <yeonghun.nam@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jee Hyeok Kim <jihyeok13.kim@samsung.com>
(cherry picked from commit 186bc52a19653b48a154d8dfb1815e1cabce2efc)
Reviewed-on: https://gerrit.iotivity.org/gerrit/14583
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/16079

25 files changed:
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/account/AccountManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/account/AccountResource.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/account/session/SessionResource.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/invite/InviteManager.java
cloud/account/src/main/java/org/iotivity/cloud/accountserver/resources/acl/invite/InviteResource.java
cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/account/AccountResourceTest.java
cloud/account/src/test/java/org/iotivity/cloud/accountserver/resources/account/session/SessionResourceTest.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/Constants.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/DeviceServerSystem.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/Account.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/AccountSession.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/AclGroup.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/account/AclInvite.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/rd/DevicePresence.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/rd/ResourceDirectory.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/rd/ResourceFind.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/proxy/rd/ResourcePresence.java
cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/KeepAliveResourceTest.java
cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/account/AccountSessionTest.java
cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/account/AclGroupTest.java
cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/account/AclInviteTest.java
cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/account/CrlTest.java [new file with mode: 0644]
cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/rd/DevicePresenceTest.java
cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/rd/ResourceFindTest.java
cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/rd/ResourcePresenceTest.java

index 296669a..eba4b26 100644 (file)
@@ -135,19 +135,16 @@ public class AccountManager {
         // find token information corresponding to the uuid and did
         HashMap<String, Object> condition = new HashMap<>();
         condition.put(Constants.KEYFIELD_UUID, uuid);
+        condition.put(Constants.KEYFIELD_DID, did);
 
-        ArrayList<HashMap<String, Object>> recordList = findRecord(
-                AccountDBManager.getInstance()
-                        .selectRecord(Constants.TOKEN_TABLE, condition),
-                Constants.KEYFIELD_DID, did);
+        ArrayList<HashMap<String, Object>> recordList = AccountDBManager
+                .getInstance().selectRecord(Constants.TOKEN_TABLE, condition);
 
         if (recordList.isEmpty()) {
             throw new UnAuthorizedException("access token doesn't exist");
         }
 
-        HashMap<String, Object> record = recordList.get(0);
-
-        TokenTable tokenInfo = castMapToTokenTable(record);
+        TokenTable tokenInfo = castMapToTokenTable(recordList.get(0));
 
         // token verification to check if the accesstoken is expired
         if (verifyToken(tokenInfo, accessToken)) {
@@ -558,7 +555,7 @@ public class AccountManager {
         return searchType;
     }
 
-    public void deleteDevice(String uid, String di) {
+    public boolean deleteDevice(String uid, String di, String accetoken) {
 
         HashSet<String> diSet = new HashSet<String>();
         diSet.add(di);
@@ -568,11 +565,25 @@ public class AccountManager {
         condition.put(Constants.KEYFIELD_UUID, uid);
         condition.put(Constants.KEYFIELD_DID, di);
 
+        ArrayList<HashMap<String, Object>> recordList = AccountDBManager
+                .getInstance().selectRecord(Constants.TOKEN_TABLE, condition);
+
+        if (recordList.isEmpty()) {
+            throw new UnAuthorizedException("access token doesn't exist");
+        }
+
+        TokenTable tokenInfo = castMapToTokenTable(recordList.get(0));
+
+        if (!verifyToken(tokenInfo, accetoken)) {
+            return false;
+        }
+
         // delete Token information from the DB
         AccountDBManager.getInstance().deleteRecord(Constants.TOKEN_TABLE,
                 condition);
         // delete device ID from all groups in the DB
         GroupManager.getInstance().deleteDevicesFromAllGroup(di);
-    }
 
+        return true;
+    }
 }
index 30b0a48..4e7cfb7 100644 (file)
@@ -26,10 +26,10 @@ import java.util.HashMap;
 import java.util.List;
 
 import org.iotivity.cloud.accountserver.Constants;
-import org.iotivity.cloud.accountserver.resources.acl.id.AclManager;
 import org.iotivity.cloud.base.device.Device;
 import org.iotivity.cloud.base.exception.ServerException;
 import org.iotivity.cloud.base.exception.ServerException.BadRequestException;
+import org.iotivity.cloud.base.exception.ServerException.UnAuthorizedException;
 import org.iotivity.cloud.base.protocols.IRequest;
 import org.iotivity.cloud.base.protocols.IResponse;
 import org.iotivity.cloud.base.protocols.MessageBuilder;
@@ -153,13 +153,16 @@ public class AccountResource extends Resource {
 
         HashMap<String, List<String>> queryMap = request.getUriQueryMap();
 
-        if (checkQueryException(
-                Arrays.asList(Constants.REQ_UUID_ID, Constants.REQ_DEVICE_ID),
+        if (checkQueryException(Arrays.asList(Constants.REQ_UUID_ID,
+                Constants.REQ_DEVICE_ID, Constants.REQ_ACCESS_TOKEN),
                 queryMap)) {
 
             String uid = queryMap.get(Constants.REQ_UUID_ID).get(0);
             String did = queryMap.get(Constants.REQ_DEVICE_ID).get(0);
-            mAsManager.deleteDevice(uid, did);
+            String accesstoken = queryMap.get(Constants.REQ_ACCESS_TOKEN)
+                    .get(0);
+            if (!mAsManager.deleteDevice(uid, did, accesstoken))
+                throw new UnAuthorizedException("accesstoken is not valid");
         }
 
         return MessageBuilder.createResponse(request, ResponseStatus.DELETED);
index f05c900..f2d6763 100644 (file)
@@ -86,31 +86,31 @@ public class SessionResource extends Resource {
 
         HashMap<String, Object> responsePayload = null;
 
-        if (checkPayloadException(
-                Arrays.asList(Constants.REQ_UUID_ID, Constants.REQ_DEVICE_ID,
-                        Constants.REQ_ACCESS_TOKEN, Constants.REQ_LOGIN),
-                payloadData)) {
+        checkPayloadException(Arrays.asList(Constants.REQ_DEVICE_ID,
+                Constants.REQ_ACCESS_TOKEN), payloadData);
 
+        String deviceId = payloadData.get(Constants.REQ_DEVICE_ID).toString();
+        String accessToken = payloadData.get(Constants.REQ_ACCESS_TOKEN)
+                .toString();
+
+        checkPayloadException(Constants.REQ_LOGIN, payloadData);
+
+        boolean signinRequest = (boolean) payloadData.get(Constants.REQ_LOGIN);
+
+        if (signinRequest) {
+            // sign-in response payload
+            checkPayloadException(Constants.REQ_UUID_ID, payloadData);
             String uuid = payloadData.get(Constants.REQ_UUID_ID).toString();
-            String deviceId = payloadData.get(Constants.REQ_DEVICE_ID)
-                    .toString();
-            String accessToken = payloadData.get(Constants.REQ_ACCESS_TOKEN)
-                    .toString();
-
-            // identify if the request is sign-in or sign-out
-            boolean signinRequest = (boolean) payloadData
-                    .get(Constants.REQ_LOGIN);
-
-            if (signinRequest) {
-                // sign-in response payload
-                responsePayload = mAsManager.signInOut(uuid, deviceId,
-                        accessToken);
-            } else {
-                // sign-out response
-                mAsManager.signInOut(uuid, deviceId, accessToken);
-                return MessageBuilder.createResponse(request,
-                        ResponseStatus.CHANGED);
-            }
+            responsePayload = mAsManager.signInOut(uuid, deviceId, accessToken);
+        } else {
+            // sign-out response
+            checkQueryException(Constants.REQ_UUID_ID,
+                    request.getUriQueryMap());
+            String uuid = request.getUriQueryMap().get(Constants.REQ_UUID_ID)
+                    .get(0);
+            mAsManager.signInOut(uuid, deviceId, accessToken);
+            return MessageBuilder.createResponse(request,
+                    ResponseStatus.CHANGED);
         }
 
         // sign-in response
index 529eef3..afcc6aa 100644 (file)
@@ -117,6 +117,10 @@ public class InviteManager {
             uidList.add(getInviteTable.getInviteUser());
         }
 
+        if (getInviteList == null || getInviteList.isEmpty()) {
+            throw new BadRequestException("mid or gid is not valid");
+        }
+
         AccountDBManager.getInstance().deleteRecord(Constants.INVITE_TABLE,
                 condition);
 
index d018924..99f953e 100644 (file)
@@ -169,6 +169,7 @@ public class InviteResource extends Resource {
 
             String acceptStr = queryParams.get(Constants.REQ_INVITE_ACCEPT)
                     .get(0);
+
             boolean accepted = false;
             if (acceptStr.equals(Constants.INVITE_ACCEPT)) {
                 accepted = true;
index 9f62d55..a01bf24 100644 (file)
@@ -325,7 +325,8 @@ public class AccountResourceTest {
 
     private IRequest deleteDeviceRequest(String deviceId, String uid) {
         IRequest request = MessageBuilder.createRequest(RequestMethod.DELETE,
-                REGISTER_URI, "di=" + deviceId + ";uid=" + uid);
+                REGISTER_URI,
+                "accesstoken=at0001" + ";di=" + deviceId + ";uid=" + uid);
         return request;
     }
 
index a699048..5224f76 100644 (file)
@@ -313,9 +313,11 @@ public class SessionResourceTest {
         payloadData.put("accesstoken", accessToken);
         payloadData.put("login", false);
         payloadData.put("di", deviceId);
-        payloadData.put("uid", USER_UUID);
+        StringBuffer query = new StringBuffer();
+        query.append("uid=" + USER_UUID);
         request = MessageBuilder.createRequest(RequestMethod.POST,
-                DEFAULT_AUTH_LOGOUT, null, ContentFormat.APPLICATION_CBOR,
+                DEFAULT_AUTH_LOGOUT, query.toString(),
+                ContentFormat.APPLICATION_CBOR,
                 mCbor.encodingPayloadToCbor(payloadData));
         return request;
     }
index a502fc4..af91bcc 100644 (file)
@@ -41,9 +41,9 @@ public class Constants extends OICConstants {
 
     public static final String REQ_GROUP_MASTER_ID = "gmid";
     public static final String REQ_MEMBER_ID       = "mid";
-    public static final String REQ_MEMBER_LIST     = "midlist";
+    public static final String REQ_MEMBER_LIST     = "members";
     public static final String REQ_DEVICE_ID       = "di";
-    public static final String REQ_DEVICE_LIST     = "dilist";
+    public static final String REQ_DEVICE_LIST     = "devices";
     public static final String REQ_INVITE          = "invite";
     public static final String REQ_PING_ARRAY      = "inarray";
     public static final String REQ_PING            = "in";
@@ -60,7 +60,4 @@ public class Constants extends OICConstants {
     public static final String REQ_LINKS           = "links";
     public static final String REQ_HREF            = "href";
     public static final String REQ_CRL             = "crl";
-
-    public static final String KEYFIELD_GROUPS     = "groups";
-    public static final String KEYFIELD_DEVICES    = "devices";
 }
index 1fc959c..8aa5823 100644 (file)
@@ -60,7 +60,9 @@ import io.netty.channel.ChannelPromise;
 
 public class DeviceServerSystem extends ServerSystem {
 
-    IRequestChannel mRDServer = null;
+    private Cbor<HashMap<String, Object>> mCbor     = new Cbor<HashMap<String, Object>>();
+
+    IRequestChannel                       mRDServer = null;
 
     public DeviceServerSystem() {
         mRDServer = ConnectorPool.getConnection("rd");
@@ -185,10 +187,43 @@ public class DeviceServerSystem extends ServerSystem {
                     ctx.close();
                 }
             }
-
             ctx.fireChannelRead(msg);
         }
 
+        @Override
+        public void write(ChannelHandlerContext ctx, Object msg,
+                ChannelPromise promise) throws Exception {
+
+            if (!(msg instanceof CoapResponse)) {
+                throw new BadRequestException(
+                        "this msg type is not CoapResponse");
+            }
+            // This is CoapResponse
+            // Once the response is valid, add this to deviceList
+            CoapResponse response = (CoapResponse) msg;
+
+            switch (response.getUriPath()) {
+                case OICConstants.ACCOUNT_SESSION_FULL_URI:
+                    if (response.getStatus() != ResponseStatus.CHANGED) {
+                        throw new UnAuthorizedException();
+                    }
+
+                    if (response.getPayload() != null) {
+                        break;
+                    }
+
+                    ctx.close();
+                    break;
+                case OICConstants.ACCOUNT_FULL_URI:
+                    if (response.getStatus() != ResponseStatus.DELETED) {
+                        break;
+                    }
+                    ctx.close();
+                    break;
+            }
+            ctx.writeAndFlush(msg);
+        }
+
         @Override
         public void channelActive(ChannelHandlerContext ctx) {
             Device device = ctx.channel().attr(keyDevice).get();
@@ -246,7 +281,6 @@ public class DeviceServerSystem extends ServerSystem {
 
     @Sharable
     class CoapAuthHandler extends ChannelDuplexHandler {
-        private Cbor<HashMap<String, Object>> mCbor = new Cbor<HashMap<String, Object>>();
 
         @Override
         public void channelActive(ChannelHandlerContext ctx) {
@@ -288,7 +322,7 @@ public class DeviceServerSystem extends ServerSystem {
                         ((CoapDevice) device).setExpiredPolicy(remainTime);
 
                         // Remove current auth handler and replace to
-                        // LifeCycleHandler
+                        // LifeCycleHandle
                         ctx.channel().pipeline().replace(this,
                                 "LifeCycleHandler", mLifeCycleHandler);
 
index 4e41179..a4e08ca 100644 (file)
@@ -52,6 +52,33 @@ public class Account extends Resource {
         mASServer = ConnectorPool.getConnection("account");
     }
 
+    class RDReceiveHandler implements IResponseEventHandler {
+
+        private Device    mSrcDevice;
+        private IResponse mResponse;
+        private IRequest  mRequest;
+
+        public RDReceiveHandler(IRequest request, IResponse response,
+                Device srcDevice) {
+            mSrcDevice = srcDevice;
+            mRequest = request;
+            mResponse = response;
+        }
+
+        @Override
+        public void onResponseReceived(IResponse response)
+                throws ClientException {
+            switch (response.getStatus()) {
+                case DELETED:
+                    mSrcDevice.sendResponse(mResponse);
+                    break;
+                default:
+                    mSrcDevice.sendResponse(MessageBuilder.createResponse(
+                            mRequest, ResponseStatus.BAD_REQUEST));
+            }
+        }
+    }
+
     class AccountReceiveHandler implements IResponseEventHandler {
 
         IRequestChannel  mRDServer = null;
@@ -75,7 +102,8 @@ public class Account extends Resource {
                     mRDServer.sendRequest(
                             MessageBuilder.createRequest(RequestMethod.DELETE,
                                     uriPath.toString(), mRequest.getUriQuery()),
-                            mSrcDevice);
+                            new RDReceiveHandler(mRequest, response,
+                                    mSrcDevice));
                     break;
                 case CHANGED:
                 case CONTENT:
@@ -95,8 +123,9 @@ public class Account extends Resource {
             StringBuffer additionalQuery = new StringBuffer();
             additionalQuery
                     .append(Constants.USER_ID + "=" + srcDevice.getUserId());
-            String uriQuery = request.getUriQuery() + ";"
-                    + additionalQuery.toString();
+            String uriQuery = additionalQuery.toString()
+                    + (request.getUriQuery() != null
+                            ? (";" + request.getUriQuery()) : "");
             request = MessageBuilder.modifyRequest(request, null, uriQuery,
                     null, null);
         }
index 7f3bf84..595164a 100644 (file)
@@ -61,10 +61,13 @@ public class AccountSession extends Resource {
         checkPayloadException(Constants.REQ_LOGIN, payloadData);
 
         if (payloadData.get(Constants.REQ_LOGIN).toString().equals("false")) {
-            payloadData.put(Constants.USER_ID, srcDevice.getUserId());
-            payloadData.put(Constants.DEVICE_ID, srcDevice.getDeviceId());
-            payloadData.put(Constants.ACCESS_TOKEN, srcDevice.getAccessToken());
-            request = MessageBuilder.modifyRequest(request, null, null,
+            StringBuffer additionalQuery = new StringBuffer();
+            additionalQuery
+                    .append(Constants.USER_ID + "=" + srcDevice.getUserId());
+            String uriQuery = additionalQuery.toString()
+                    + (request.getUriQuery() != null
+                            ? (";" + request.getUriQuery()) : "");
+            request = MessageBuilder.modifyRequest(request, null, uriQuery,
                     ContentFormat.APPLICATION_CBOR,
                     mCbor.encodingPayloadToCbor(payloadData));
         }
index d106e96..429e537 100644 (file)
@@ -30,6 +30,7 @@ import org.iotivity.cloud.base.device.IRequestChannel;
 import org.iotivity.cloud.base.exception.ServerException;
 import org.iotivity.cloud.base.exception.ServerException.BadRequestException;
 import org.iotivity.cloud.base.protocols.IRequest;
+import org.iotivity.cloud.base.protocols.MessageBuilder;
 import org.iotivity.cloud.base.resource.Resource;
 import org.iotivity.cloud.ciserver.Constants;
 import org.iotivity.cloud.util.Cbor;
@@ -73,6 +74,12 @@ public class AclGroup extends Resource {
                 throw new BadRequestException(
                         request.getMethod() + " request type is not support");
         }
-        mAuthServer.sendRequest(request, srcDevice);
+        StringBuffer additionalQuery = new StringBuffer();
+        additionalQuery.append(Constants.USER_ID + "=" + srcDevice.getUserId());
+        String uriQuery = additionalQuery.toString()
+                + (request.getUriQuery() != null ? (";" + request.getUriQuery())
+                        : "");
+        mAuthServer.sendRequest(MessageBuilder.modifyRequest(request, null,
+                uriQuery, null, null), srcDevice);
     }
 }
\ No newline at end of file
index ff05fab..86e53f1 100644 (file)
@@ -28,9 +28,9 @@ import org.iotivity.cloud.base.connector.ConnectorPool;
 import org.iotivity.cloud.base.device.Device;
 import org.iotivity.cloud.base.device.IRequestChannel;
 import org.iotivity.cloud.base.exception.ServerException;
+import org.iotivity.cloud.base.exception.ServerException.BadRequestException;
 import org.iotivity.cloud.base.protocols.IRequest;
 import org.iotivity.cloud.base.protocols.MessageBuilder;
-import org.iotivity.cloud.base.protocols.enums.ContentFormat;
 import org.iotivity.cloud.base.resource.Resource;
 import org.iotivity.cloud.ciserver.Constants;
 import org.iotivity.cloud.util.Cbor;
@@ -66,28 +66,23 @@ public class AclInvite extends Resource {
                         request.getPayload(), HashMap.class);
 
                 checkPayloadException(Constants.REQ_INVITE, payloadData);
-
-                payloadData.put(Constants.USER_ID, srcDevice.getUserId());
-
-                request = MessageBuilder.modifyRequest(request, null, null,
-                        ContentFormat.APPLICATION_CBOR,
-                        cbor.encodingPayloadToCbor(payloadData));
                 break;
-
-            default:
-
-                StringBuffer additionalQuery = new StringBuffer();
-                additionalQuery.append(
-                        Constants.USER_ID + "=" + srcDevice.getUserId());
-
-                String uriQuery = additionalQuery.toString()
-                        + (request.getUriQuery() != null
-                                ? (";" + request.getUriQuery()) : "");
-                request = MessageBuilder.modifyRequest(request, null, uriQuery,
-                        null, null);
-
+            case GET:
                 break;
+            case DELETE:
+                break;
+            default:
+                throw new BadRequestException(
+                        request.getMethod() + " request type is not support");
         }
+        StringBuffer additionalQuery = new StringBuffer();
+        additionalQuery.append(Constants.USER_ID + "=" + srcDevice.getUserId());
+
+        String uriQuery = additionalQuery.toString()
+                + (request.getUriQuery() != null ? (";" + request.getUriQuery())
+                        : "");
+        request = MessageBuilder.modifyRequest(request, null, uriQuery, null,
+                null);
 
         mAuthServer.sendRequest(request, srcDevice);
     }
index 864c755..fe86968 100644 (file)
@@ -21,6 +21,7 @@
  */
 package org.iotivity.cloud.ciserver.resources.proxy.rd;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
@@ -85,12 +86,14 @@ public class DevicePresence extends Resource {
                         return;
                     }
 
+                    ArrayList<String> devices = (ArrayList<String>) getResponseDeviceList(
+                            payloadData);
+
                     if (mRequest.getUriQuery() != null
                             && mRequest.getUriQueryMap()
                                     .containsKey(Constants.REQ_DEVICE_ID)) {
-                        if (!getResponseDeviceList(payloadData)
-                                .containsAll(mRequest.getUriQueryMap()
-                                        .get(Constants.REQ_DEVICE_ID))) {
+                        if (!devices.containsAll(mRequest.getUriQueryMap()
+                                .get(Constants.REQ_DEVICE_ID))) {
                             mSrcDevice.sendResponse(
                                     MessageBuilder.createResponse(mRequest,
                                             ResponseStatus.BAD_REQUEST));
@@ -104,12 +107,11 @@ public class DevicePresence extends Resource {
                                             ResponseStatus.BAD_REQUEST));
                             return;
                         }
+                        String uriQuery = additionalQuery.toString()
+                                + (mRequest.getUriQuery() != null
+                                        ? (";" + mRequest.getUriQuery()) : "");
                         mRequest = MessageBuilder.modifyRequest(mRequest, null,
-                                additionalQuery
-                                        + (mRequest.getUriQuery() != null
-                                                ? ";" + mRequest.getUriQuery()
-                                                : ""),
-                                null, null);
+                                uriQuery, null, null);
                     }
 
                     mRDServer.sendRequest(mRequest, mSrcDevice);
@@ -154,8 +156,14 @@ public class DevicePresence extends Resource {
     @Override
     public void onDefaultRequestReceived(Device srcDevice, IRequest request)
             throws ServerException {
-        StringBuffer uriQuery = new StringBuffer();
-        uriQuery.append(Constants.REQ_MEMBER_ID + "=" + srcDevice.getUserId());
+        StringBuffer additionalQuery = new StringBuffer();
+        additionalQuery.append(Constants.USER_ID + "=" + srcDevice.getUserId());
+        additionalQuery.append(";");
+        additionalQuery.append(
+                Constants.REQ_MEMBER_LIST + "=" + srcDevice.getUserId());
+        String uriQuery = additionalQuery.toString()
+                + (request.getUriQuery() != null ? (";" + request.getUriQuery())
+                        : "");
 
         StringBuffer uriPath = new StringBuffer();
         uriPath.append(Constants.PREFIX_OIC + "/");
@@ -164,7 +172,7 @@ public class DevicePresence extends Resource {
         uriPath.append(srcDevice.getUserId());
 
         IRequest requestToAS = MessageBuilder.createRequest(RequestMethod.GET,
-                uriPath.toString(), uriQuery.toString());
+                uriPath.toString(), uriQuery);
 
         mASServer.sendRequest(requestToAS,
                 new AccountReceiveHandler(request, srcDevice));
index addbbe8..1be0ebf 100644 (file)
@@ -68,6 +68,9 @@ public class ResourceDirectory extends Resource {
                 HashMap<String, Object> payloadData = mCbor
                         .parsePayloadFromCbor(request.getPayload(),
                                 HashMap.class);
+                StringBuffer query = new StringBuffer();
+                query.append("op=add;");
+                query.append(Constants.USER_ID + "=" + srcDevice.getUserId());
 
                 StringBuffer uriPath = new StringBuffer();
                 uriPath.append(Constants.PREFIX_OIC + "/");
@@ -76,14 +79,13 @@ public class ResourceDirectory extends Resource {
                 uriPath.append(srcDevice.getUserId());
 
                 String di = payloadData.get(Constants.REQ_DEVICE_ID).toString();
-
                 HashMap<String, Object> requestPayload = new HashMap<>();
-                requestPayload.put(Constants.USER_ID, srcDevice.getUserId());
+
                 requestPayload.put(Constants.REQ_GROUP_DEVICES,
                         Arrays.asList(di));
                 IRequest requestToAS = MessageBuilder.createRequest(
-                        RequestMethod.POST, uriPath.toString(), "op=add",
-                        ContentFormat.APPLICATION_CBOR,
+                        RequestMethod.POST, uriPath.toString(),
+                        query.toString(), ContentFormat.APPLICATION_CBOR,
                         mCbor.encodingPayloadToCbor(requestPayload));
 
                 mASServer.sendRequest(requestToAS,
index 656fafc..55da35e 100644 (file)
@@ -86,12 +86,8 @@ public class ResourceFind extends Resource {
                         return;
                     }
 
-                    ArrayList<String> devices = new ArrayList<>();
-
-                    devices = (ArrayList<String>) payloadData
-                            .get(Constants.KEYFIELD_DEVICES);
-
-                    System.out.println("devices : " + devices);
+                    ArrayList<String> devices = (ArrayList<String>) getResponseDeviceList(
+                            payloadData);
 
                     if (mRequest.getUriQuery() != null
                             && mRequest.getUriQueryMap()
@@ -103,15 +99,15 @@ public class ResourceFind extends Resource {
                                             ResponseStatus.BAD_REQUEST));
                         }
                     } else {
-                        String additionalQuery = makeAdditionalQuery(devices);
+                        StringBuilder additionalQuery = makeAdditionalQuery(
+                                devices);
+                        String uriQuery = (additionalQuery != null
+                                ? additionalQuery.toString() : "")
+                                + (mRequest.getUriQuery() != null
+                                        ? (";" + mRequest.getUriQuery()) : "");
                         mRequest = MessageBuilder.modifyRequest(mRequest, null,
-                                (mRequest.getUriQuery() != null
-                                        ? mRequest.getUriQuery() : "")
-                                        + (additionalQuery == null ? ""
-                                                : ";" + additionalQuery),
-                                null, null);
+                                uriQuery, null, null);
                     }
-
                     mRDServer.sendRequest(mRequest, mSrcDevice);
                     break;
                 default:
@@ -120,7 +116,8 @@ public class ResourceFind extends Resource {
             }
         }
 
-        private String makeAdditionalQuery(ArrayList<String> deviceList) {
+        private StringBuilder makeAdditionalQuery(
+                ArrayList<String> deviceList) {
 
             StringBuilder additionalQuery = new StringBuilder();
 
@@ -139,15 +136,17 @@ public class ResourceFind extends Resource {
                     additionalQuery.append(";");
                 }
             }
-            return additionalQuery.toString();
+            return additionalQuery;
         }
 
         @SuppressWarnings("unchecked")
         private List<String> getResponseDeviceList(
                 HashMap<String, Object> payloadData) {
-            List<String> deviceList = (List<String>) payloadData
-                    .get(Constants.REQ_DEVICE_LIST);
-
+            ArrayList<String> deviceList = new ArrayList<>();
+            if (payloadData.containsKey(Constants.REQ_DEVICE_LIST)) {
+                deviceList = (ArrayList<String>) payloadData
+                        .get(Constants.REQ_DEVICE_LIST);
+            }
             return deviceList;
         }
     }
@@ -160,9 +159,16 @@ public class ResourceFind extends Resource {
 
             mRDServer.sendRequest(request, srcDevice);
         } else {
-            StringBuffer uriQuery = new StringBuffer();
-            uriQuery.append(Constants.USER_ID + "=" + srcDevice.getUserId());
-
+            StringBuffer additionalQuery = new StringBuffer();
+            additionalQuery
+                    .append(Constants.USER_ID + "=" + srcDevice.getUserId());
+            additionalQuery.append(";");
+            additionalQuery.append(
+                    Constants.REQ_MEMBER_LIST + "=" + srcDevice.getUserId());
+
+            String uriQuery = additionalQuery.toString()
+                    + (request.getUriQuery() != null
+                            ? (";" + request.getUriQuery()) : "");
             StringBuffer uriPath = new StringBuffer();
             uriPath.append(Constants.PREFIX_OIC + "/");
             uriPath.append(Constants.ACL_URI + "/");
@@ -170,7 +176,7 @@ public class ResourceFind extends Resource {
             uriPath.append(srcDevice.getUserId());
 
             IRequest requestToAS = MessageBuilder.createRequest(
-                    RequestMethod.GET, uriPath.toString(), uriQuery.toString());
+                    RequestMethod.GET, uriPath.toString(), uriQuery);
 
             mASServer.sendRequest(requestToAS,
                     new AccountReceiveHandler(request, srcDevice));
index f708115..59c2981 100644 (file)
@@ -103,12 +103,11 @@ public class ResourcePresence extends Resource {
                                             ResponseStatus.BAD_REQUEST));
                             return;
                         }
+                        String uriQuery = additionalQuery.toString()
+                                + (mRequest.getUriQuery() != null
+                                        ? (";" + mRequest.getUriQuery()) : "");
                         mRequest = MessageBuilder.modifyRequest(mRequest, null,
-                                additionalQuery
-                                        + (mRequest.getUriQuery() != null
-                                                ? ";" + mRequest.getUriQuery()
-                                                : ""),
-                                null, null);
+                                uriQuery, null, null);
                     }
 
                     mRDServer.sendRequest(mRequest, mSrcDevice);
@@ -153,9 +152,15 @@ public class ResourcePresence extends Resource {
     @Override
     public void onDefaultRequestReceived(Device srcDevice, IRequest request)
             throws ServerException {
-        StringBuffer uriQuery = new StringBuffer();
-        uriQuery.append(Constants.REQ_MEMBER_ID + "=" + srcDevice.getUserId());
-
+        StringBuffer additionalQuery = new StringBuffer();
+        additionalQuery.append(Constants.USER_ID + "=" + srcDevice.getUserId());
+        additionalQuery.append(";");
+        additionalQuery.append(
+                Constants.REQ_MEMBER_LIST + "=" + srcDevice.getUserId());
+
+        String uriQuery = additionalQuery.toString()
+                + (request.getUriQuery() != null ? (";" + request.getUriQuery())
+                        : "");
         StringBuffer uriPath = new StringBuffer();
         uriPath.append(Constants.PREFIX_OIC + "/");
         uriPath.append(Constants.ACL_URI + "/");
@@ -163,7 +168,7 @@ public class ResourcePresence extends Resource {
         uriPath.append(srcDevice.getUserId());
 
         IRequest requestToAS = MessageBuilder.createRequest(RequestMethod.GET,
-                uriPath.toString(), uriQuery.toString());
+                uriPath.toString(), uriQuery);
 
         mASServer.sendRequest(requestToAS,
                 new AccountReceiveHandler(request, srcDevice));
index 1f29a41..d53e2e2 100644 (file)
@@ -31,7 +31,6 @@ import java.util.HashMap;
 import java.util.concurrent.CountDownLatch;
 
 import org.iotivity.cloud.base.device.CoapDevice;
-import org.iotivity.cloud.base.exception.ServerException.BadRequestException;
 import org.iotivity.cloud.base.protocols.IRequest;
 import org.iotivity.cloud.base.protocols.IResponse;
 import org.iotivity.cloud.base.protocols.MessageBuilder;
@@ -118,17 +117,6 @@ public class KeepAliveResourceTest {
         assertTrue(methodCheck(mRes, ResponseStatus.VALID));
     }
 
-    @Test(expected = BadRequestException.class)
-    public void testOnDefaultExceptionRequestReceived() {
-        HashMap<String, Integer> payloadData = new HashMap<>();
-        Cbor<HashMap<String, Object>> cbor = new Cbor<>();
-        payloadData.put("in", 8);
-        IRequest request = MessageBuilder.createRequest(RequestMethod.POST,
-                "/oic/ping", null, ContentFormat.APPLICATION_CBOR,
-                cbor.encodingPayloadToCbor(payloadData));
-        keepAliveResource.onDefaultRequestReceived(mockDevice, request);
-    }
-
     private boolean methodCheck(IResponse response,
             ResponseStatus responseStatus) {
         if (responseStatus == response.getStatus())
index d80d24a..a6ad127 100644 (file)
@@ -116,10 +116,10 @@ public class AccountSessionTest {
         // assertion : request msg to the AS is identical to the request msg
         // from the client
         assertTrue(mLatch.await(1L, SECONDS));
-        assertTrue(hashmapCheck(mReq, Constants.USER_ID));
-        assertTrue(hashmapCheck(mReq, Constants.DEVICE_ID));
-        assertTrue(hashmapCheck(mReq, Constants.ACCESS_TOKEN));
-        assertTrue(hashmapCheck(mReq, Constants.REQ_LOGIN));
+        assertTrue(queryCheck(mReq, Constants.USER_ID));
+        assertTrue(payloadCheck(mReq, Constants.DEVICE_ID));
+        assertTrue(payloadCheck(mReq, Constants.ACCESS_TOKEN));
+        assertTrue(payloadCheck(mReq, Constants.REQ_LOGIN));
     }
 
     private IRequest makeSignInRequest() {
@@ -142,13 +142,16 @@ public class AccountSessionTest {
         IRequest request = null;
         HashMap<String, Object> payloadData = new HashMap<>();
         payloadData.put(Constants.REQ_LOGIN, false);
+        payloadData.put(Constants.DEVICE_ID, mDi);
+        payloadData.put(Constants.ACCESS_TOKEN,
+                "1689c70ffa245effc563017fee36d250");
         request = MessageBuilder.createRequest(RequestMethod.POST, SESSION_URI,
                 null, ContentFormat.APPLICATION_CBOR,
                 cbor.encodingPayloadToCbor(payloadData));
         return request;
     }
 
-    private boolean hashmapCheck(IRequest request, String propertyName) {
+    private boolean payloadCheck(IRequest request, String propertyName) {
         Cbor<HashMap<String, Object>> mCbor = new Cbor<>();
         HashMap<String, Object> payloadData = mCbor
                 .parsePayloadFromCbor(request.getPayload(), HashMap.class);
@@ -157,4 +160,11 @@ public class AccountSessionTest {
         else
             return false;
     }
+
+    private boolean queryCheck(IRequest request, String propertyName) {
+        if (request.getUriQueryMap().get(propertyName) != null)
+            return true;
+        else
+            return false;
+    }
 }
index 30b3a44..89c6a5b 100644 (file)
@@ -52,20 +52,21 @@ import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
 public class AclGroupTest {
-    private static final String  TEST_RESOURCE_GROUP_URI = Constants.GROUP_FULL_URI;
+    private static final String   TEST_RESOURCE_GROUP_URI = Constants.GROUP_FULL_URI;
 
-    private CoapDevice           mMockDevice             = mock(
+    private CoapDevice            mMockDevice             = mock(
             CoapDevice.class);
-    private IRequest             mReq                    = null;
-    private DeviceServerSystem   mDeviceServerSystem     = new DeviceServerSystem();
-    private final CountDownLatch mLatch                  = new CountDownLatch(
+    private IRequest              mReq                    = null;
+    private DeviceServerSystem    mDeviceServerSystem     = new DeviceServerSystem();
+    private final CountDownLatch  mLatch                  = new CountDownLatch(
             1);
+    Cbor<HashMap<Object, Object>> mCbor                   = new Cbor<>();
 
     @Mock
-    private IRequestChannel      mRequestChannel;
+    private IRequestChannel       mRequestChannel;
 
     @InjectMocks
-    private AclGroup             mAclGroupHandler        = new AclGroup();
+    private AclGroup              mAclGroupHandler        = new AclGroup();
 
     @Before
     public void setUp() throws Exception {
@@ -100,18 +101,23 @@ public class AclGroupTest {
                 "\t--------------OnRequestReceived(AS) Create Group Test------------");
 
         HashMap<String, Object> payloadData = new HashMap<>();
-        payloadData.put("gtype", "public");
-        Cbor<HashMap<Object, Object>> cbor = new Cbor<>();
+        payloadData.put("owner", "u1");
+        payloadData.put("members", Arrays.asList("ui"));
+        payloadData.put("gname", Arrays.asList("home"));
+
         IRequest request = MessageBuilder.createRequest(RequestMethod.POST,
                 TEST_RESOURCE_GROUP_URI, null, ContentFormat.APPLICATION_CBOR,
-                cbor.encodingPayloadToCbor(payloadData));
+                mCbor.encodingPayloadToCbor(payloadData));
         mAclGroupHandler.onRequestReceived(mMockDevice, request);
 
         assertTrue(mLatch.await(1L, SECONDS));
-        assertTrue(cbor.parsePayloadFromCbor(mReq.getPayload(), HashMap.class)
-                .containsKey("gtype"));
-        assertTrue(cbor.parsePayloadFromCbor(mReq.getPayload(), HashMap.class)
-                .containsKey("gmid"));
+        assertTrue(mCbor.parsePayloadFromCbor(mReq.getPayload(), HashMap.class)
+                .containsKey("owner"));
+        assertTrue(mCbor.parsePayloadFromCbor(mReq.getPayload(), HashMap.class)
+                .containsKey("members"));
+        assertTrue(mCbor.parsePayloadFromCbor(mReq.getPayload(), HashMap.class)
+                .containsKey("gname"));
+        assertTrue(mReq.getUriQueryMap().containsKey("uid"));
         assertEquals(mReq.getUriPath(), TEST_RESOURCE_GROUP_URI);
     }
 
@@ -121,16 +127,18 @@ public class AclGroupTest {
                 "\t--------------OnRequestReceived(AS) Add Member Test------------");
 
         HashMap<String, Object> payloadData = new HashMap<>();
-        Cbor<HashMap<Object, Object>> cbor = new Cbor<>();
+        payloadData.put("members", Arrays.asList("sampleMember"));
         IRequest request = MessageBuilder.createRequest(RequestMethod.POST,
-                TEST_RESOURCE_GROUP_URI + "/" + "sampleGroup", null,
+                TEST_RESOURCE_GROUP_URI + "/" + "sampleGroup", "op=add",
                 ContentFormat.APPLICATION_CBOR,
-                cbor.encodingPayloadToCbor(payloadData));
+                mCbor.encodingPayloadToCbor(payloadData));
         mAclGroupHandler.onRequestReceived(mMockDevice, request);
 
         assertTrue(mLatch.await(1L, SECONDS));
-        assertTrue(cbor.parsePayloadFromCbor(mReq.getPayload(), HashMap.class)
-                .containsKey("midlist"));
+        assertTrue(mCbor.parsePayloadFromCbor(mReq.getPayload(), HashMap.class)
+                .containsKey("members"));
+        assertTrue(mReq.getUriQueryMap().containsKey("op"));
+        assertTrue(mReq.getUriQueryMap().containsKey("uid"));
         assertEquals(mReq.getUriPath(),
                 TEST_RESOURCE_GROUP_URI + "/" + "sampleGroup");
     }
@@ -141,17 +149,18 @@ public class AclGroupTest {
                 "\t--------------OnRequestReceived(AS) Add Device Test------------");
 
         HashMap<String, Object> payloadData = new HashMap<>();
-        payloadData.put("dilist", Arrays.asList("sampleDevice"));
-        Cbor<HashMap<Object, Object>> cbor = new Cbor<>();
+        payloadData.put("devices", Arrays.asList("sampleDevice"));
         IRequest request = MessageBuilder.createRequest(RequestMethod.POST,
-                TEST_RESOURCE_GROUP_URI + "/" + "sampleGroup", null,
+                TEST_RESOURCE_GROUP_URI + "/" + "sampleGroup", "op=add",
                 ContentFormat.APPLICATION_CBOR,
-                cbor.encodingPayloadToCbor(payloadData));
+                mCbor.encodingPayloadToCbor(payloadData));
         mAclGroupHandler.onRequestReceived(mMockDevice, request);
 
         assertTrue(mLatch.await(1L, SECONDS));
-        assertTrue(cbor.parsePayloadFromCbor(mReq.getPayload(), HashMap.class)
-                .containsKey("dilist"));
+        assertTrue(mCbor.parsePayloadFromCbor(mReq.getPayload(), HashMap.class)
+                .containsKey("devices"));
+        assertTrue(mReq.getUriQueryMap().containsKey("op"));
+        assertTrue(mReq.getUriQueryMap().containsKey("uid"));
         assertEquals(mReq.getUriPath(),
                 TEST_RESOURCE_GROUP_URI + "/" + "sampleGroup");
     }
@@ -163,11 +172,12 @@ public class AclGroupTest {
                 "\t--------------OnRequestReceived(AS) Get Group List & Get Group Info Test------------");
 
         IRequest request = MessageBuilder.createRequest(RequestMethod.GET,
-                TEST_RESOURCE_GROUP_URI, null, null, null);
+                TEST_RESOURCE_GROUP_URI, "members=u1", null, null);
         mAclGroupHandler.onRequestReceived(mMockDevice, request);
 
         assertTrue(mLatch.await(1L, SECONDS));
-        assertTrue(mReq.getUriQueryMap().containsKey("mid"));
+        assertTrue(mReq.getUriQueryMap().containsKey("members"));
+        assertTrue(mReq.getUriQueryMap().containsKey("uid"));
         assertEquals(mReq.getUriPath(), TEST_RESOURCE_GROUP_URI);
     }
 
@@ -177,27 +187,32 @@ public class AclGroupTest {
                 "\t--------------OnRequestReceived(AS) Delete Group Test------------");
 
         IRequest request = MessageBuilder.createRequest(RequestMethod.DELETE,
-                TEST_RESOURCE_GROUP_URI, "gid=samplegid", null, null);
+                TEST_RESOURCE_GROUP_URI + "/g1", "owner=u1", null, null);
         mAclGroupHandler.onRequestReceived(mMockDevice, request);
 
         assertTrue(mLatch.await(1L, SECONDS));
-        assertTrue(mReq.getUriQueryMap().containsKey("gid"));
-        assertTrue(mReq.getUriQueryMap().containsKey("gmid"));
-        assertEquals(mReq.getUriPath(), TEST_RESOURCE_GROUP_URI);
+        assertTrue(mReq.getUriQueryMap().containsKey("owner"));
+        assertTrue(mReq.getUriQueryMap().containsKey("uid"));
+        assertEquals(mReq.getUriPath(), TEST_RESOURCE_GROUP_URI + "/g1");
     }
 
     @Test
     public void testDeleteMemberRequestReceived() throws Exception {
         System.out.println(
                 "\t--------------OnRequestReceived(AS) Delete Member Test------------");
-
-        IRequest request = MessageBuilder.createRequest(RequestMethod.DELETE,
-                TEST_RESOURCE_GROUP_URI + "/" + "sampleGroup", null, null,
-                null);
+        HashMap<String, Object> payloadData = new HashMap<>();
+        payloadData.put("members", Arrays.asList("sampleMember"));
+        IRequest request = MessageBuilder.createRequest(RequestMethod.POST,
+                TEST_RESOURCE_GROUP_URI + "/" + "sampleGroup", "op=delete",
+                ContentFormat.APPLICATION_CBOR,
+                mCbor.encodingPayloadToCbor(payloadData));
         mAclGroupHandler.onRequestReceived(mMockDevice, request);
 
         assertTrue(mLatch.await(1L, SECONDS));
-        assertTrue(mReq.getUriQueryMap().containsKey("midlist"));
+        assertTrue(mCbor.parsePayloadFromCbor(mReq.getPayload(), HashMap.class)
+                .containsKey("members"));
+        assertTrue(mReq.getUriQueryMap().containsKey("op"));
+        assertTrue(mReq.getUriQueryMap().containsKey("uid"));
         assertEquals(mReq.getUriPath(),
                 TEST_RESOURCE_GROUP_URI + "/" + "sampleGroup");
     }
@@ -206,14 +221,19 @@ public class AclGroupTest {
     public void testDeleteDeviceRequestReceived() throws Exception {
         System.out.println(
                 "\t--------------OnRequestReceived(AS) Delete Member Test------------");
-
-        IRequest request = MessageBuilder.createRequest(RequestMethod.DELETE,
-                TEST_RESOURCE_GROUP_URI + "/" + "sampleGroup",
-                "dilist=sampledi", null, null);
+        HashMap<String, Object> payloadData = new HashMap<>();
+        payloadData.put("devices", Arrays.asList("sampleDevice"));
+        IRequest request = MessageBuilder.createRequest(RequestMethod.POST,
+                TEST_RESOURCE_GROUP_URI + "/" + "sampleGroup", "op=delete",
+                ContentFormat.APPLICATION_CBOR,
+                mCbor.encodingPayloadToCbor(payloadData));
         mAclGroupHandler.onRequestReceived(mMockDevice, request);
 
         assertTrue(mLatch.await(1L, SECONDS));
-        assertTrue(mReq.getUriQueryMap().containsKey("dilist"));
+        assertTrue(mCbor.parsePayloadFromCbor(mReq.getPayload(), HashMap.class)
+                .containsKey("devices"));
+        assertTrue(mReq.getUriQueryMap().containsKey("op"));
+        assertTrue(mReq.getUriQueryMap().containsKey("uid"));
         assertEquals(mReq.getUriPath(),
                 TEST_RESOURCE_GROUP_URI + "/" + "sampleGroup");
     }
index 443eb68..b6bfe2d 100644 (file)
@@ -103,6 +103,7 @@ public class AclInviteTest {
         HashMap<String, Object> invite = new HashMap<>();
         invite.put("gid", "g0001");
         invite.put("mid", "u0001");
+        payloadData.put("uid", "u0001");
         payloadData.put("invite", Arrays.asList(invite));
         Cbor<HashMap<Object, Object>> cbor = new Cbor<>();
         IRequest request = MessageBuilder.createRequest(RequestMethod.POST,
@@ -111,6 +112,7 @@ public class AclInviteTest {
         mAclInviteHandler.onRequestReceived(mMockDevice, request);
 
         assertTrue(mLatch.await(1L, SECONDS));
+        assertTrue(mReq.getUriQueryMap().containsKey("uid"));
         assertTrue(cbor.parsePayloadFromCbor(mReq.getPayload(), HashMap.class)
                 .containsKey("uid"));
         assertTrue(cbor.parsePayloadFromCbor(mReq.getPayload(), HashMap.class)
@@ -124,16 +126,36 @@ public class AclInviteTest {
     }
 
     @Test
-    public void testGetRequestReceived() throws Exception {
+    public void testGetRequestReceivedAccept() throws Exception {
         System.out.println(
                 "\t--------------OnRequestReceived(AS) Get Message Test------------");
 
         IRequest request = MessageBuilder.createRequest(RequestMethod.GET,
-                TEST_RESOURCE_INVITE_URI, null, null, null);
+                TEST_RESOURCE_INVITE_URI, "gid=g0001;accept=1", null, null);
         mAclInviteHandler.onRequestReceived(mMockDevice, request);
 
         assertTrue(mLatch.await(1L, SECONDS));
         assertTrue(mReq.getUriQueryMap().containsKey("uid"));
+        assertTrue(mReq.getUriQueryMap().containsKey("gid"));
+        assertTrue(mReq.getUriQueryMap().containsKey("accept"));
+        assertTrue(mReq.getUriQueryMap().get("accept").get(0).equals("1"));
+        assertEquals(mReq.getUriPath(), TEST_RESOURCE_INVITE_URI);
+    }
+
+    @Test
+    public void testGetRequestReceivedDeny() throws Exception {
+        System.out.println(
+                "\t--------------OnRequestReceived(AS) Get Message Test------------");
+
+        IRequest request = MessageBuilder.createRequest(RequestMethod.GET,
+                TEST_RESOURCE_INVITE_URI, "gid=g0001;accept=0", null, null);
+        mAclInviteHandler.onRequestReceived(mMockDevice, request);
+
+        assertTrue(mLatch.await(1L, SECONDS));
+        assertTrue(mReq.getUriQueryMap().containsKey("uid"));
+        assertTrue(mReq.getUriQueryMap().containsKey("gid"));
+        assertTrue(mReq.getUriQueryMap().containsKey("accept"));
+        assertTrue(mReq.getUriQueryMap().get("accept").get(0).equals("0"));
         assertEquals(mReq.getUriPath(), TEST_RESOURCE_INVITE_URI);
     }
 
@@ -143,11 +165,12 @@ public class AclInviteTest {
                 "\t--------------OnRequestReceived(AS) Delete Message Test------------");
 
         IRequest request = MessageBuilder.createRequest(RequestMethod.DELETE,
-                TEST_RESOURCE_INVITE_URI, "gid=g0001", null, null);
+                TEST_RESOURCE_INVITE_URI, "gid=g0001;mid=u0002", null, null);
         mAclInviteHandler.onRequestReceived(mMockDevice, request);
 
         assertTrue(mLatch.await(1L, SECONDS));
         assertTrue(mReq.getUriQueryMap().containsKey("gid"));
+        assertTrue(mReq.getUriQueryMap().containsKey("mid"));
         assertTrue(mReq.getUriQueryMap().containsKey("uid"));
         assertEquals(mReq.getUriPath(), TEST_RESOURCE_INVITE_URI);
     }
diff --git a/cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/account/CrlTest.java b/cloud/interface/src/test/java/org/iotivity/cloud/ciserver/resources/proxy/account/CrlTest.java
new file mode 100644 (file)
index 0000000..3bab49f
--- /dev/null
@@ -0,0 +1,83 @@
+package org.iotivity.cloud.ciserver.resources.proxy.account;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import java.util.concurrent.CountDownLatch;
+
+import org.iotivity.cloud.base.OICConstants;
+import org.iotivity.cloud.base.device.CoapDevice;
+import org.iotivity.cloud.base.device.IRequestChannel;
+import org.iotivity.cloud.base.protocols.IRequest;
+import org.iotivity.cloud.base.protocols.MessageBuilder;
+import org.iotivity.cloud.base.protocols.coap.CoapRequest;
+import org.iotivity.cloud.base.protocols.enums.RequestMethod;
+import org.iotivity.cloud.ciserver.Constants;
+import org.iotivity.cloud.ciserver.DeviceServerSystem;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+public class CrlTest {
+
+    private static final String TEST_RESOURCE_CRL_URI = "/"
+            + OICConstants.PREFIX_OIC + "/" + OICConstants.CREDPROV_URI + "/"
+            + Constants.REQ_CRL;
+    private CoapDevice          mMockDevice           = mock(CoapDevice.class);
+    private IRequest            mReq                  = null;
+    private DeviceServerSystem  mDeviceServerSystem   = new DeviceServerSystem();
+    final CountDownLatch        mLatch                = new CountDownLatch(1);
+
+    @Mock
+    private IRequestChannel     mRequestChannel;
+
+    @InjectMocks
+    private Crl                 mCertHandler          = new Crl();
+
+    @Before
+    public void setUp() throws Exception {
+        mReq = null;
+        MockitoAnnotations.initMocks(this);
+        mDeviceServerSystem.addResource(mCertHandler);
+        // callback mock
+        Mockito.doAnswer(new Answer<Object>() {
+            @Override
+            public CoapRequest answer(InvocationOnMock invocation)
+                    throws Throwable {
+                Object[] args = invocation.getArguments();
+                CoapRequest request = (CoapRequest) args[0];
+                System.out.println(
+                        "\t----------payload : " + request.getPayloadString());
+                System.out.println(
+                        "\t----------uripath : " + request.getUriPath());
+                System.out.println(
+                        "\t---------uriquery : " + request.getUriQuery());
+                mReq = request;
+                mLatch.countDown();
+                return null;
+            }
+        }).when(mRequestChannel).sendRequest(Mockito.any(IRequest.class),
+                Mockito.any(CoapDevice.class));
+    }
+
+    @Test
+    public void testOnDefaultRequestReceived() throws Exception {
+        System.out.println(
+                "\t--------------OnRequestReceived(AS) Test------------");
+
+        IRequest request = MessageBuilder.createRequest(RequestMethod.POST,
+                TEST_RESOURCE_CRL_URI, null, null, null);
+        mCertHandler.onRequestReceived(mMockDevice, request);
+
+        assertTrue(mLatch.await(1L, SECONDS));
+        assertEquals(mReq.getUriPath(), TEST_RESOURCE_CRL_URI);
+    }
+
+}
index 1d58984..e2b52a7 100644 (file)
@@ -72,6 +72,7 @@ public class DevicePresenceTest {
         MockitoAnnotations.initMocks(this);
         mDeviceServerSystem.addResource(mPrsHandler);
         Mockito.doReturn("mockDeviceId").when(mMockDevice).getDeviceId();
+        Mockito.doReturn("mockUserId").when(mMockDevice).getUserId();
         Mockito.doAnswer(new Answer<Object>() {
             @Override
             public CoapRequest answer(InvocationOnMock invocation)
@@ -140,9 +141,11 @@ public class DevicePresenceTest {
         mDeviceServerSystem.onRequestReceived(mMockDevice, request);
         assertTrue(mLatch.await(1L, SECONDS));
         HashMap<String, List<String>> queryMap = mReq.getUriQueryMap();
-        assertTrue(queryMap.containsKey("mid"));
+        assertTrue(queryMap.containsKey("uid"));
+        assertTrue(queryMap.containsKey("members"));
         assertTrue(mReq.getMethod().equals(RequestMethod.GET));
-        assertEquals(mReq.getUriPath(), Constants.GROUP_FULL_URI + "/null");
+        assertEquals(mReq.getUriPath(),
+                Constants.GROUP_FULL_URI + "/mockUserId");
     }
 
     // @InjectMocks for testPresenceDeregisterSpecificDeviceOnRequestReceived
@@ -175,8 +178,10 @@ public class DevicePresenceTest {
         assertTrue(mLatch.await(1L, SECONDS));
         assertTrue(mReq.getMethod().equals(RequestMethod.GET));
         HashMap<String, List<String>> queryMap = mReq.getUriQueryMap();
-        assertTrue(queryMap.containsKey("mid"));
-        assertEquals(mReq.getUriPath(), Constants.GROUP_FULL_URI + "/null");
+        assertTrue(queryMap.containsKey("uid"));
+        assertTrue(queryMap.containsKey("members"));
+        assertEquals(mReq.getUriPath(),
+                Constants.GROUP_FULL_URI + "/mockUserId");
     }
 
     public IRequest makePresenceEntireDevice() {
@@ -215,15 +220,15 @@ public class DevicePresenceTest {
         deviceList.add("device1");
         deviceList.add("device2");
         deviceList.add("device3");
-        responsePayload.put("dilist", deviceList);
+        responsePayload.put("devices", deviceList);
         responsePayload.put("gid", "g0001");
         responsePayload.put("gmid", "u0001");
         ArrayList<String> midList = new ArrayList<String>();
         midList.add("u0001");
-        responsePayload.put("midlist", midList);
+        responsePayload.put("members", midList);
         IRequest requestFromCitoAs = MessageBuilder.createRequest(
                 RequestMethod.GET, Constants.GROUP_FULL_URI + "/g0001",
-                "mid=null");
+                "uid=mockUserId;members=mockUserId");
         IResponse response = MessageBuilder.createResponse(requestFromCitoAs,
                 ResponseStatus.CONTENT, ContentFormat.APPLICATION_CBOR,
                 cbor.encodingPayloadToCbor(responsePayload));
index 109b22a..9173cdc 100644 (file)
@@ -59,7 +59,7 @@ import org.mockito.stubbing.Answer;
 public class ResourceFindTest {
     private static final String TEST_RESOURCE_FIND_URI = Constants.WELL_KNOWN_FULL_URI;
     private String              di                     = "B371C481-38E6-4D47-8320-7688D8A5B58C";
-    private CoapDevice          mockDevice             = mock(CoapDevice.class);
+    private CoapDevice          mMockDevice            = mock(CoapDevice.class);
     private IResponse           mRes                   = null;
     private IRequest            mReq                   = null;
     private DeviceServerSystem  mDeviceServerSystem    = new DeviceServerSystem();
@@ -77,7 +77,8 @@ public class ResourceFindTest {
     public void setUp() throws Exception {
         mRes = null;
         mReq = null;
-        Mockito.doReturn("mockDeviceId").when(mockDevice).getDeviceId();
+        Mockito.doReturn("mockDeviceId").when(mMockDevice).getDeviceId();
+        Mockito.doReturn("mockUserId").when(mMockDevice).getUserId();
         MockitoAnnotations.initMocks(this);
         mDeviceServerSystem.addResource(mResHandler);
         // callback mock
@@ -90,7 +91,7 @@ public class ResourceFindTest {
                 mRes = resp;
                 return resp;
             }
-        }).when(mockDevice).sendResponse(Mockito.anyObject());
+        }).when(mMockDevice).sendResponse(Mockito.anyObject());
         Mockito.doAnswer(new Answer<Object>() {
             @Override
             public CoapRequest answer(InvocationOnMock invocation)
@@ -136,7 +137,7 @@ public class ResourceFindTest {
                     "rt=core.light;di=" + "device1");
     @InjectMocks
     ResourceFind.AccountReceiveHandler specificDeviceHandler = mResHandler.new AccountReceiveHandler(
-            requestSpecificDevice, mockDevice);
+            requestSpecificDevice, mMockDevice);
 
     @Test
     public void testSpecificDeviceonResponseReceived()
@@ -158,15 +159,15 @@ public class ResourceFindTest {
             .createRequest(RequestMethod.GET, TEST_RESOURCE_FIND_URI,
                     "rt=core.light");
     @InjectMocks
-    ResourceFind.AccountReceiveHandler handler              = mResHandler.new AccountReceiveHandler(
-            requestEntireDevices, mockDevice);
+    ResourceFind.AccountReceiveHandler entireDevicehandler  = mResHandler.new AccountReceiveHandler(
+            requestEntireDevices, mMockDevice);
 
     @Test
     public void testEntireDeviceonResponseReceived() throws ClientException {
         System.out.println(
                 "\t--------------onResponseReceived(RD) Resource Find (entire deivces) Test------------");
         IResponse response = responseFromAccountServer();
-        handler.onResponseReceived(response);
+        entireDevicehandler.onResponseReceived(response);
         HashMap<String, List<String>> queryMap = mReq.getUriQueryMap();
         assertTrue(mReq.getMethod() == RequestMethod.GET);
         assertTrue(queryMap.get("rt").contains("core.light"));
@@ -180,7 +181,7 @@ public class ResourceFindTest {
             .createRequest(RequestMethod.GET, TEST_RESOURCE_FIND_URI, null);
     @InjectMocks
     ResourceFind.AccountReceiveHandler entireDevicesNoQueryHandler = mResHandler.new AccountReceiveHandler(
-            requestEntireDevicesNoQuery, mockDevice);
+            requestEntireDevicesNoQuery, mMockDevice);
 
     @Test
     public void testEntireDeviceNoQueryonResponseReceived()
@@ -203,11 +204,13 @@ public class ResourceFindTest {
                 "\t--------------OnRequestReceived(RD) Resource Find (entire deivces) Test------------");
         IRequest request = MessageBuilder.createRequest(RequestMethod.GET,
                 TEST_RESOURCE_FIND_URI, "rt=core.light");
-        mResHandler.onRequestReceived(mockDevice, request);
+        mResHandler.onRequestReceived(mMockDevice, request);
         HashMap<String, List<String>> queryMap = mReq.getUriQueryMap();
         assertTrue(mLatch.await(1L, SECONDS));
-        assertTrue(queryMap.containsKey("mid"));
-        assertEquals(mReq.getUriPath(), Constants.GROUP_FULL_URI + "/null");
+        assertTrue(queryMap.containsKey("uid"));
+        assertTrue(queryMap.containsKey("members"));
+        assertEquals(mReq.getUriPath(),
+                Constants.GROUP_FULL_URI + "/mockUserId");
     }
 
     @Test
@@ -217,7 +220,7 @@ public class ResourceFindTest {
                 "\t--------------OnRequestReceived(RD) Resource Find (specific deivce) Test------------");
         IRequest request = MessageBuilder.createRequest(RequestMethod.GET,
                 TEST_RESOURCE_FIND_URI, "rt=core.light;di=" + di);
-        mResHandler.onRequestReceived(mockDevice, request);
+        mResHandler.onRequestReceived(mMockDevice, request);
         HashMap<String, List<String>> queryMap = mReq.getUriQueryMap();
         // assertion: if the request packet from the CI contains the query
         // which includes device ID and the accesstoken
@@ -235,12 +238,12 @@ public class ResourceFindTest {
         deviceList.add("device1");
         deviceList.add("device2");
         deviceList.add("device3");
-        responsePayload.put("dilist", deviceList);
+        responsePayload.put("devices", deviceList);
         responsePayload.put("gid", "g0001");
         responsePayload.put("gmid", "u0001");
         ArrayList<String> midList = new ArrayList<String>();
         midList.add("u0001");
-        responsePayload.put("midlist", midList);
+        responsePayload.put("memebers", midList);
         IResponse response = MessageBuilder.createResponse(requestEntireDevices,
                 ResponseStatus.CONTENT, ContentFormat.APPLICATION_CBOR,
                 cbor.encodingPayloadToCbor(responsePayload));
index 9ed3e0a..93ef37a 100644 (file)
@@ -73,6 +73,7 @@ public class ResourcePresenceTest {
         mRes = null;
         mReq = null;
         Mockito.doReturn("mockDeviceId").when(mMockDevice).getDeviceId();
+        Mockito.doReturn("mockUserId").when(mMockDevice).getUserId();
         MockitoAnnotations.initMocks(this);
         deviceServerSystem.addResource(adHandler);
         Mockito.doAnswer(new Answer<Object>() {
@@ -107,8 +108,10 @@ public class ResourcePresenceTest {
         // assertion: if the request packet from the CI contains the query
         // which includes the accesstoken and the di
         assertTrue(latch.await(1L, SECONDS));
-        assertTrue(queryMap.containsKey("mid"));
-        assertEquals(mReq.getUriPath(), Constants.GROUP_FULL_URI + "/null");
+        assertTrue(queryMap.containsKey("uid"));
+        assertTrue(queryMap.containsKey("members"));
+        assertEquals(mReq.getUriPath(),
+                Constants.GROUP_FULL_URI + "/mockUserId");
     }
 
     @Test
@@ -121,8 +124,10 @@ public class ResourcePresenceTest {
         deviceServerSystem.onRequestReceived(mMockDevice, request);
         HashMap<String, List<String>> queryMap = mReq.getUriQueryMap();
         assertTrue(latch.await(1L, SECONDS));
-        assertTrue(queryMap.containsKey("mid"));
-        assertEquals(mReq.getUriPath(), Constants.GROUP_FULL_URI + "/null");
+        assertTrue(queryMap.containsKey("uid"));
+        assertTrue(queryMap.containsKey("members"));
+        assertEquals(mReq.getUriPath(),
+                Constants.GROUP_FULL_URI + "/mockUserId");
     }
 
     IRequest                               requestEntireDevices = MessageBuilder
@@ -173,12 +178,11 @@ public class ResourcePresenceTest {
         deviceList.add("device1");
         deviceList.add("device2");
         deviceList.add("device3");
-        responsePayload.put("dilist", deviceList);
+        responsePayload.put("devices", deviceList);
         responsePayload.put("gid", "g0001");
-        responsePayload.put("gmid", "u0001");
         ArrayList<String> midList = new ArrayList<String>();
         midList.add("u0001");
-        responsePayload.put("midlist", midList);
+        responsePayload.put("members", midList);
         IResponse response = MessageBuilder.createResponse(requestEntireDevices,
                 ResponseStatus.CONTENT, ContentFormat.APPLICATION_CBOR,
                 cbor.encodingPayloadToCbor(responsePayload));