@Test public void testRemoveLike() { final Activity activityEntity = context.mock(Activity.class); final SetActivityLikeRequest currentRequest = new SetActivityLikeRequest(1L, LikeActionType.REMOVE_LIKE); context.checking(new Expectations() { { oneOf(unlikeMapperMock).execute(with(any(LikedActivity.class))); oneOf(activityEntityMapper).execute(with(any(FindByIdRequest.class))); will(returnValue(activityEntity)); oneOf(activityIndexer).execute(activityEntity); } }); sut.execute(TestContextCreator.createTaskHandlerContextWithPrincipal(currentRequest, null, 5L)); context.assertIsSatisfied(); }
@Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { SetActivityLikeRequest request = (SetActivityLikeRequest) inActionContext.getActionContext().getParams(); final Long userId = inActionContext.getActionContext().getPrincipal().getId(); LikedActivity likeActivityData = new LikedActivity(userId, request.getActivityId()); if (request.getLikeActionType() == LikeActionType.ADD_LIKE) { insertLikedActivity.execute(likeActivityData); inActionContext.getUserActionRequests().add( new UserActionRequest("loadLikedActivityIdsByUserId", null, userId)); CreateNotificationsRequest notificationRequest = new ActivityNotificationsRequest(RequestType.LIKE, userId, 0L, request.getActivityId()); inActionContext.getUserActionRequests().add( new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, notificationRequest)); } else { deleteLikedActivity.execute(likeActivityData); } indexEntity.execute(activityEntityMapper.execute(new FindByIdRequest("Activity", request.getActivityId()))); return Boolean.TRUE; }
SetActivityLikeExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { SetActivityLikeRequest request = (SetActivityLikeRequest) inActionContext.getActionContext().getParams(); final Long userId = inActionContext.getActionContext().getPrincipal().getId(); LikedActivity likeActivityData = new LikedActivity(userId, request.getActivityId()); if (request.getLikeActionType() == LikeActionType.ADD_LIKE) { insertLikedActivity.execute(likeActivityData); inActionContext.getUserActionRequests().add( new UserActionRequest("loadLikedActivityIdsByUserId", null, userId)); CreateNotificationsRequest notificationRequest = new ActivityNotificationsRequest(RequestType.LIKE, userId, 0L, request.getActivityId()); inActionContext.getUserActionRequests().add( new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, notificationRequest)); } else { deleteLikedActivity.execute(likeActivityData); } indexEntity.execute(activityEntityMapper.execute(new FindByIdRequest("Activity", request.getActivityId()))); return Boolean.TRUE; } }
SetActivityLikeExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { SetActivityLikeRequest request = (SetActivityLikeRequest) inActionContext.getActionContext().getParams(); final Long userId = inActionContext.getActionContext().getPrincipal().getId(); LikedActivity likeActivityData = new LikedActivity(userId, request.getActivityId()); if (request.getLikeActionType() == LikeActionType.ADD_LIKE) { insertLikedActivity.execute(likeActivityData); inActionContext.getUserActionRequests().add( new UserActionRequest("loadLikedActivityIdsByUserId", null, userId)); CreateNotificationsRequest notificationRequest = new ActivityNotificationsRequest(RequestType.LIKE, userId, 0L, request.getActivityId()); inActionContext.getUserActionRequests().add( new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, notificationRequest)); } else { deleteLikedActivity.execute(likeActivityData); } indexEntity.execute(activityEntityMapper.execute(new FindByIdRequest("Activity", request.getActivityId()))); return Boolean.TRUE; } SetActivityLikeExecution(final InsertLikedActivity inInsertLikedActivity,
            final DeleteLikedActivity inDeleteLikedActivity, final IndexEntity<Activity> inIndexEntity,
            final FindByIdMapper<Activity> inActivityEntityMapper); }
SetActivityLikeExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { SetActivityLikeRequest request = (SetActivityLikeRequest) inActionContext.getActionContext().getParams(); final Long userId = inActionContext.getActionContext().getPrincipal().getId(); LikedActivity likeActivityData = new LikedActivity(userId, request.getActivityId()); if (request.getLikeActionType() == LikeActionType.ADD_LIKE) { insertLikedActivity.execute(likeActivityData); inActionContext.getUserActionRequests().add( new UserActionRequest("loadLikedActivityIdsByUserId", null, userId)); CreateNotificationsRequest notificationRequest = new ActivityNotificationsRequest(RequestType.LIKE, userId, 0L, request.getActivityId()); inActionContext.getUserActionRequests().add( new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, notificationRequest)); } else { deleteLikedActivity.execute(likeActivityData); } indexEntity.execute(activityEntityMapper.execute(new FindByIdRequest("Activity", request.getActivityId()))); return Boolean.TRUE; } SetActivityLikeExecution(final InsertLikedActivity inInsertLikedActivity,
            final DeleteLikedActivity inDeleteLikedActivity, final IndexEntity<Activity> inIndexEntity,
            final FindByIdMapper<Activity> inActivityEntityMapper); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext); }
SetActivityLikeExecution implements TaskHandlerExecutionStrategy<PrincipalActionContext> { @Override public Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext) throws ExecutionException { SetActivityLikeRequest request = (SetActivityLikeRequest) inActionContext.getActionContext().getParams(); final Long userId = inActionContext.getActionContext().getPrincipal().getId(); LikedActivity likeActivityData = new LikedActivity(userId, request.getActivityId()); if (request.getLikeActionType() == LikeActionType.ADD_LIKE) { insertLikedActivity.execute(likeActivityData); inActionContext.getUserActionRequests().add( new UserActionRequest("loadLikedActivityIdsByUserId", null, userId)); CreateNotificationsRequest notificationRequest = new ActivityNotificationsRequest(RequestType.LIKE, userId, 0L, request.getActivityId()); inActionContext.getUserActionRequests().add( new UserActionRequest(CreateNotificationsRequest.ACTION_NAME, null, notificationRequest)); } else { deleteLikedActivity.execute(likeActivityData); } indexEntity.execute(activityEntityMapper.execute(new FindByIdRequest("Activity", request.getActivityId()))); return Boolean.TRUE; } SetActivityLikeExecution(final InsertLikedActivity inInsertLikedActivity,
            final DeleteLikedActivity inDeleteLikedActivity, final IndexEntity<Activity> inIndexEntity,
            final FindByIdMapper<Activity> inActivityEntityMapper); @Override Serializable execute(final TaskHandlerActionContext<PrincipalActionContext> inActionContext);  }