@Test public void testUserGroupMemberRule() throws Exception { ServiceContext serviceContext = ServiceTestUtil.getServiceContext(); AnonymousUser anonymousUser = _anonymousUserLocalService.addAnonymousUser( TestPropsValues.getUserId(), "127.0.0.1", StringPool.BLANK, serviceContext); Rule rule = _rulesRegistry.getRule("UserGroupMemberRule"); UserGroup userGroup = UserGroupLocalServiceUtil.addUserGroup( TestPropsValues.getUserId(), TestPropsValues.getCompanyId(), StringUtil.randomString(), StringUtil.randomString(), new ServiceContext()); UserGroupLocalServiceUtil.addUserUserGroup( TestPropsValues.getUserId(), userGroup.getUserGroupId()); RuleInstance ruleInstance = _ruleInstanceLocalService.addRuleInstance( TestPropsValues.getUserId(), rule.getRuleKey(), 0, String.valueOf(userGroup.getUserGroupId()), serviceContext); Assert.assertTrue(rule.evaluate(null, ruleInstance, anonymousUser)); }
@Test public void testOrganizationMemberRule() throws Exception { ServiceContext serviceContext = ServiceTestUtil.getServiceContext(); AnonymousUser anonymousUser = _anonymousUserLocalService.addAnonymousUser( TestPropsValues.getUserId(), "127.0.0.1", StringPool.BLANK, serviceContext); Rule rule = _rulesRegistry.getRule("OrganizationMemberRule"); Organization organization = OrganizationLocalServiceUtil.addOrganization( TestPropsValues.getUserId(), OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID, StringUtil.randomString(), false); OrganizationLocalServiceUtil.addUserOrganization( TestPropsValues.getUserId(), organization.getOrganizationId()); RuleInstance ruleInstance = _ruleInstanceLocalService.addRuleInstance( TestPropsValues.getUserId(), rule.getRuleKey(), 0, String.valueOf(organization.getOrganizationId()), serviceContext); Assert.assertTrue(rule.evaluate(null, ruleInstance, anonymousUser)); }