@Test public void getProfileInfoWhenUserOrgNull() throws MuleException { AcmUser user = new AcmUser(); user.setUserId(USER_ID); UserOrg expectedUserOrg = new UserOrg(); expectedUserOrg.setUser(user); AcmGroup group = new AcmGroup(); group.setName("ACM_INVESTIGATOR"); Set<AcmGroup> groups = new HashSet<>(); groups.add(group); user.setGroups(groups); expect(mockUserOrgDao.findByUserId(USER_ID)).andReturn(null); expect(mockUserDao.findByUserId(USER_ID)).andReturn(user); expect(mockUserDao.findByUserId(USER_ID)).andReturn(user); MuleMessage mockMuleMessage = createMock(MuleMessage.class); MuleException mockMuleException = null; Capture<UserOrg> captureUserOrg = Capture.newInstance(); expect(mockMuleContextManager.getMuleContext()).andReturn(mockMuleContext); expect(mockMuleContext.getRegistry()).andReturn(mockMuleRegistry); expect(mockMuleRegistry.lookupObject(DEFAULT_CMIS_ID)).andReturn(cmisConfig); expect(mockMuleContextManager.send(eq(MULE_ENDPOINT), capture(captureUserOrg), eq(muleMessageProps))).andReturn(mockMuleMessage); expectedUserOrg.setUserOrgId(1L); expect(mockMuleMessage.getPayload(UserOrg.class)).andReturn(expectedUserOrg); expect(mockMuleMessage.getInboundProperty(EXCEPTION_PROPERTY)).andReturn(mockMuleException); mockEventPublisher.publishProfileEvent(expectedUserOrg, mockAuthentication, true, true); expectLastCall().once(); replayAll(); ProfileDTO profileDTO = userOrgService.getProfileInfo(USER_ID, mockAuthentication); verifyAll(); assertEquals(captureUserOrg.getValue().getUser().getUserId(), USER_ID); assertEquals(profileDTO.getUserId(), expectedUserOrg.getUser().getUserId()); assertEquals(profileDTO.getGroups().get(0), group.getName()); assertNull(profileDTO.getCompanyName()); }
@Override @Transactional public ProfileDTO getProfileInfo(String userId, Authentication authentication) { UserOrg userOrg = getUserOrgForUserId(userId); if (userOrg == null) { log.info("Profile info for the user [{}] is not found", userId); userOrg = createUserOrgForUser(userId); try { userOrg = saveUserOrgTransaction(userOrg, authentication); getEventPublisher().publishProfileEvent(userOrg, authentication, true, true); } catch (MuleException e) { log.error("UserOrg for user [{}] was not saved. {}", userId, e); getEventPublisher().publishProfileEvent(userOrg, authentication, true, false); } } AcmUser user = userDao.findByUserId(userId); return createProfileDTO(userOrg, user.getGroups()); }
UserOrgServiceImpl implements UserOrgService { @Override @Transactional public ProfileDTO getProfileInfo(String userId, Authentication authentication) { UserOrg userOrg = getUserOrgForUserId(userId); if (userOrg == null) { log.info("Profile info for the user [{}] is not found", userId); userOrg = createUserOrgForUser(userId); try { userOrg = saveUserOrgTransaction(userOrg, authentication); getEventPublisher().publishProfileEvent(userOrg, authentication, true, true); } catch (MuleException e) { log.error("UserOrg for user [{}] was not saved. {}", userId, e); getEventPublisher().publishProfileEvent(userOrg, authentication, true, false); } } AcmUser user = userDao.findByUserId(userId); return createProfileDTO(userOrg, user.getGroups()); } }
UserOrgServiceImpl implements UserOrgService { @Override @Transactional public ProfileDTO getProfileInfo(String userId, Authentication authentication) { UserOrg userOrg = getUserOrgForUserId(userId); if (userOrg == null) { log.info("Profile info for the user [{}] is not found", userId); userOrg = createUserOrgForUser(userId); try { userOrg = saveUserOrgTransaction(userOrg, authentication); getEventPublisher().publishProfileEvent(userOrg, authentication, true, true); } catch (MuleException e) { log.error("UserOrg for user [{}] was not saved. {}", userId, e); getEventPublisher().publishProfileEvent(userOrg, authentication, true, false); } } AcmUser user = userDao.findByUserId(userId); return createProfileDTO(userOrg, user.getGroups()); }  }
UserOrgServiceImpl implements UserOrgService { @Override @Transactional public ProfileDTO getProfileInfo(String userId, Authentication authentication) { UserOrg userOrg = getUserOrgForUserId(userId); if (userOrg == null) { log.info("Profile info for the user [{}] is not found", userId); userOrg = createUserOrgForUser(userId); try { userOrg = saveUserOrgTransaction(userOrg, authentication); getEventPublisher().publishProfileEvent(userOrg, authentication, true, true); } catch (MuleException e) { log.error("UserOrg for user [{}] was not saved. {}", userId, e); getEventPublisher().publishProfileEvent(userOrg, authentication, true, false); } } AcmUser user = userDao.findByUserId(userId); return createProfileDTO(userOrg, user.getGroups()); }  @Override UserOrg getUserOrgForUserId(String userId); @Override String getProfileLocation(); @Override @Transactional UserOrg saveUserOrgTransaction(UserOrg userOrgInfo, Authentication authentication); @Override @Transactional ProfileDTO getProfileInfo(String userId, Authentication authentication); @Override @Transactional ProfileDTO saveUserOrgInfo(ProfileDTO profile, Authentication authentication); UserDao getUserDao(); void setUserDao(UserDao userDao); OrganizationService getOrganizationService(); void setOrganizationService(OrganizationService organizationService); UserOrgDao getUserOrgDao(); void setUserOrgDao(UserOrgDao userOrgDao); MuleContextManager getMuleContextManager(); void setMuleContextManager(MuleContextManager muleContextManager); ProfileEventPublisher getEventPublisher(); void setEventPublisher(ProfileEventPublisher eventPublisher); AcmGroupDao getGroupDao(); void setGroupDao(AcmGroupDao groupDao); GroupService getGroupService(); void setGroupService(GroupService groupService); String getDefaultCmisId(); void setDefaultCmisId(String defaultCmisId); ProfileConfig getProfileConfig(); void setProfileConfig(ProfileConfig profileConfig); }
UserOrgServiceImpl implements UserOrgService { @Override @Transactional public ProfileDTO getProfileInfo(String userId, Authentication authentication) { UserOrg userOrg = getUserOrgForUserId(userId); if (userOrg == null) { log.info("Profile info for the user [{}] is not found", userId); userOrg = createUserOrgForUser(userId); try { userOrg = saveUserOrgTransaction(userOrg, authentication); getEventPublisher().publishProfileEvent(userOrg, authentication, true, true); } catch (MuleException e) { log.error("UserOrg for user [{}] was not saved. {}", userId, e); getEventPublisher().publishProfileEvent(userOrg, authentication, true, false); } } AcmUser user = userDao.findByUserId(userId); return createProfileDTO(userOrg, user.getGroups()); }  @Override UserOrg getUserOrgForUserId(String userId); @Override String getProfileLocation(); @Override @Transactional UserOrg saveUserOrgTransaction(UserOrg userOrgInfo, Authentication authentication); @Override @Transactional ProfileDTO getProfileInfo(String userId, Authentication authentication); @Override @Transactional ProfileDTO saveUserOrgInfo(ProfileDTO profile, Authentication authentication); UserDao getUserDao(); void setUserDao(UserDao userDao); OrganizationService getOrganizationService(); void setOrganizationService(OrganizationService organizationService); UserOrgDao getUserOrgDao(); void setUserOrgDao(UserOrgDao userOrgDao); MuleContextManager getMuleContextManager(); void setMuleContextManager(MuleContextManager muleContextManager); ProfileEventPublisher getEventPublisher(); void setEventPublisher(ProfileEventPublisher eventPublisher); AcmGroupDao getGroupDao(); void setGroupDao(AcmGroupDao groupDao); GroupService getGroupService(); void setGroupService(GroupService groupService); String getDefaultCmisId(); void setDefaultCmisId(String defaultCmisId); ProfileConfig getProfileConfig(); void setProfileConfig(ProfileConfig profileConfig);  }