/** * Creates a new message collection or message */ @Operation(httpMethods = "POST", bodyParam = "entity") public Future<?> create(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); String msgCollId = request.getParameter("msgCollId"); List<String> messageIds = request.getListParameter("messageIds"); HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); UserId user = request.getUsers().iterator().next(); if (msgCollId == null) { // Request to create a new message collection MessageCollection msgCollection = request.getTypedParameter("entity", MessageCollection.class); return service.createMessageCollection(user, msgCollection, request.getToken()); } // A message collection has been specified, allow for posting HandlerPreconditions.requireEmpty(messageIds,"Message IDs not allowed here, use PUT instead"); Message message = request.getTypedParameter("entity", Message.class); HandlerPreconditions.requireNotEmpty(message.getRecipients(), "No recipients specified"); return service.createMessage(userIds.iterator().next(), request.getAppId(), msgCollId, message, request.getToken()); }
@Test @Ignore public void testPostMessage() throws Exception { MessageImpl message = new MessageImpl("A message body", "A title", Message.Type.PRIVATE_MESSAGE); message.setRecipients(recipients); EasyMock.expect(converter.convertToObject(null, Message.class)).andReturn(message); EasyMock.expect(messageService.createMessage(sender, "messageHandlerTest", "@outbox", message, token)).andReturn(Futures.immediateFuture((Void) null)); EasyMock.replay(messageService, converter); RestHandler operation = registry.getRestHandler("/messages/" + sender.getUserId() + "/@outbox", "POST"); Map<String,String[]> params = ImmutableMap.of(RequestItem.APP_ID, new String[]{"messageHandlerTest"}); operation.execute(params,null, token, converter).get(); EasyMock.verify(converter, messageService); } }
/** * Creates a new message collection or message */ @Operation(httpMethods = "POST", bodyParam = "entity") public Future<?> create(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); String msgCollId = request.getParameter("msgCollId"); List<String> messageIds = request.getListParameter("messageIds"); HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); UserId user = request.getUsers().iterator().next(); if (msgCollId == null) { // Request to create a new message collection MessageCollection msgCollection = request.getTypedParameter("entity", MessageCollection.class); return service.createMessageCollection(user, msgCollection, request.getToken()); } // A message collection has been specified, allow for posting HandlerPreconditions.requireEmpty(messageIds,"Message IDs not allowed here, use PUT instead"); Message message = request.getTypedParameter("entity", Message.class); HandlerPreconditions.requireNotEmpty(message.getRecipients(), "No recipients specified"); return service.createMessage(userIds.iterator().next(), request.getAppId(), msgCollId, message, request.getToken()); }
@Test @Ignore public void testPostMessage() throws Exception { MessageImpl message = new MessageImpl("A message body", "A title", Message.Type.PRIVATE_MESSAGE); message.setRecipients(recipients); EasyMock.expect(converter.convertToObject(null, Message.class)).andReturn(message); EasyMock.expect(messageService.createMessage(sender, "messageHandlerTest", "@outbox", message, token)).andReturn(Futures.immediateFuture((Void) null)); EasyMock.replay(messageService, converter); RestHandler operation = registry.getRestHandler("/messages/" + sender.getUserId() + "/@outbox", "POST"); Map<String,String[]> params = ImmutableMap.of(RequestItem.APP_ID, new String[]{"messageHandlerTest"}); operation.execute(params,null, token, converter).get(); EasyMock.verify(converter, messageService); } }
/** * Creates a new message collection or message */ @Operation(httpMethods = "POST", bodyParam = "entity") public Future<?> modify(SocialRequestItem request) throws ProtocolException { Set<UserId> userIds = request.getUsers(); String msgCollId = request.getParameter("msgCollId"); List<String> messageIds = request.getListParameter("messageIds"); HandlerPreconditions.requireNotEmpty(userIds, "No userId specified"); HandlerPreconditions.requireSingular(userIds, "Multiple userIds not supported"); UserId user = request.getUsers().iterator().next(); if (msgCollId == null) { // Request to create a new message collection MessageCollection msgCollection = request.getTypedParameter("entity", MessageCollection.class); return service.createMessageCollection(user, msgCollection, request.getToken()); } // A message collection has been specified, allow for posting HandlerPreconditions.requireEmpty(messageIds,"Message IDs not allowed here, use PUT instead"); Message message = request.getTypedParameter("entity", Message.class); HandlerPreconditions.requireNotEmpty(message.getRecipients(), "No recipients specified"); return service.createMessage(userIds.iterator().next(), request.getAppId(), msgCollId, message, request.getToken()); }
@Test public void testPostMessage() throws Exception { MessageImpl message = new MessageImpl("A message body", "A title", Message.Type.PRIVATE_MESSAGE); message.setRecipients(recipients); EasyMock.expect(converter.convertToObject(null, Message.class)).andReturn(message); EasyMock.expect(messageService.createMessage(sender, "messageHandlerTest", "@outbox", message, token)).andReturn(ImmediateFuture.newInstance((Void) null)); EasyMock.replay(messageService, converter); RestHandler operation = registry.getRestHandler("/messages/" + sender.getUserId() + "/@outbox", "POST"); Map<String,String[]> params = ImmutableMap.of(RequestItem.APP_ID, new String[]{"messageHandlerTest"}); operation.execute(params,null, token, converter).get(); EasyMock.verify(converter, messageService); } }