Utils { public static void postFileActivity(Node node, String activityMsgBundleKey) throws Exception { postFileActivity(node, activityMsgBundleKey, false, false, null, null); }  static String getActivityType(); static void setActivityType(String activityType); static Map<String, String> populateActivityData(Node node,
          String activityOwnerId,
          String activityMsgBundleKey); static Map<String, String> populateActivityData(Node node,
                                                         String activityOwnerId, String activityMsgBundleKey, 
                                                         boolean isComment, String systemComment, String perm); static void postActivity(Node node, String activityMsgBundleKey); static ExoSocialActivity createShareActivity(Node node, String activityMsgBundleKey, String activityType, String comments, String perm); static void postFileActivity(Node node, String activityMsgBundleKey); static ExoSocialActivity postActivity(Node node, String activityMsgBundleKey, boolean needUpdate, 
                                  boolean isSystemComment, String systemComment, String perm); static ExoSocialActivity postFileActivity(Node node, String activityMsgBundleKey, boolean needUpdate, 
                                  boolean isComment, String systemComment, String perm); static void updateNotifyMessages(ExoSocialActivity activity, String activityMsgBundleKey, String systemComment); static String getContentLink(Node node); static ExoSocialActivity createActivity(IdentityManager identityManager,
                                                 String activityOwnerId, Node node,
                                                 String activityMsgBundleKey, String activityType); static ExoSocialActivity createActivity(IdentityManager identityManager,
                                                 String activityOwnerId,
                                                 Node node, String activityMsgBundleKey, String activityType,
                                                 boolean isSystemComment,  String systemComment, String perm); static void deleteFileActivity(Node node); static String getIllustrativeImage(Node node); static String generateThumbnailImageURI(Node file); static String getMimeType(Node node); static String getSummary(Node node); static String getFirstSummaryLines(String source); static String getFirstSummaryLines(String source, int linesCount); static String[] getSystemCommentTitle(Map<String, String> activityParams); static String[] getSystemCommentBundle(Map<String, String> activityParams); static String getBundleValue(String key); static String processMentions(String comment); static void setAvatarUrl(Node commentNode); static final String CONTENT_SPACES; static final String FILE_SPACES; static final String SHARE_FILE; static final String SHARE_CONTENT; static final String EXO_RESOURCES_URI; static final String ICON_FILE_EXTENSION; static final String DEFAULT_AVATAR; }
@Test public void shouldPostFileActivityWhenFileIsPublic() throws Exception { ActivityManager activityManager = mock(ActivityManager.class); IdentityManager identityManager = mock(IdentityManager.class); ActivityCommonService activityCommonService = mock(ActivityCommonService.class); SpaceService spaceService = mock(SpaceService.class); PowerMockito.mockStatic(CommonsUtils.class); when(activityManager.isActivityTypeEnabled(anyString())).thenReturn(true); when(CommonsUtils.getService(eq(ActivityManager.class))).thenReturn(activityManager); when(CommonsUtils.getService(eq(IdentityManager.class))).thenReturn(identityManager); when(CommonsUtils.getService(eq(ActivityCommonService.class))).thenReturn(activityCommonService); when(CommonsUtils.getService(eq(SpaceService.class))).thenReturn(spaceService); when(spaceService.getSpaceByGroupId(anyString())).thenReturn(null); PowerMockito.mockStatic(Utils.class); when(Utils.postFileActivity(any(), anyString(), anyBoolean(), anyBoolean(), anyString(), anyString())).thenCallRealMethod(); Utils spy = PowerMockito.spy(new Utils()); PowerMockito.when(spy, MemberMatcher.method(Utils.class, "getActivityOwnerId", Node.class)) .withArguments(any()) .thenReturn("john"); PowerMockito.when(spy, MemberMatcher.method(Utils.class, "isPublic", Node.class)).withArguments(any()).thenCallRealMethod(); PowerMockito.when(spy, MemberMatcher.method(Utils.class, "createActivity", IdentityManager.class, String.class, Node.class, String.class, String.class, boolean.class, String.class, String.class)) .withArguments(any(), anyString(), any(), anyString(), anyString(), anyBoolean(), anyString(), anyString()) .thenReturn(new ExoSocialActivityImpl()); ExtendedNode node = mock(ExtendedNode.class); when(node.isNodeType(ActivityTypeUtils.EXO_ACTIVITY_INFO)).thenReturn(false); AccessControlList acl = new AccessControlList("john", Arrays.asList(new AccessControlEntry("any", "read"))); when(node.getACL()).thenReturn(acl); Utils.postFileActivity(node, null, false, false, "", ""); verify(activityManager, times(1)).saveActivityNoReturn(any(), any(ExoSocialActivity.class)); }
@Test public void shouldNotPostFileActivityWhenFileIsNotPublic() throws Exception { ActivityManager activityManager = mock(ActivityManager.class); IdentityManager identityManager = mock(IdentityManager.class); ActivityCommonService activityCommonService = mock(ActivityCommonService.class); SpaceService spaceService = mock(SpaceService.class); PowerMockito.mockStatic(CommonsUtils.class); when(CommonsUtils.getService(eq(ActivityManager.class))).thenReturn(activityManager); when(activityManager.isActivityTypeEnabled(anyString())).thenReturn(true); when(CommonsUtils.getService(eq(IdentityManager.class))).thenReturn(identityManager); when(CommonsUtils.getService(eq(ActivityCommonService.class))).thenReturn(activityCommonService); when(CommonsUtils.getService(eq(SpaceService.class))).thenReturn(spaceService); when(spaceService.getSpaceByGroupId(anyString())).thenReturn(null); PowerMockito.mockStatic(Utils.class); when(Utils.postFileActivity(any(), anyString(), anyBoolean(), anyBoolean(), anyString(), anyString())).thenCallRealMethod(); Utils spy = PowerMockito.spy(new Utils()); PowerMockito.when(spy, MemberMatcher.method(Utils.class, "getActivityOwnerId", Node.class)) .withArguments(any()) .thenReturn("john"); PowerMockito.when(spy, MemberMatcher.method(Utils.class, "isPublic", Node.class)).withArguments(any()).thenCallRealMethod(); ExtendedNode node = mock(ExtendedNode.class); when(node.isNodeType(ActivityTypeUtils.EXO_ACTIVITY_INFO)).thenReturn(false); AccessControlList acl = new AccessControlList("john", Arrays.asList(new AccessControlEntry("*:/spaces/space1", "read"))); when(node.getACL()).thenReturn(acl); ExoSocialActivity activity = Utils.postFileActivity(node, null, false, false, "", ""); verify(activityManager, never()).saveActivityNoReturn(any(), any(ExoSocialActivity.class)); }