RulesManager { public List<Rules> getRules(EntityManager em, String tenantId) throws Exception { Tenant tenant = getTenant(em, tenantId); if (tenant == null) { throw new NoResultException("Tenant not found"); } try { List<Rules> result = em.createNamedQuery(Queries.RULES_FIND_ALL_BY_TENANT_ID, Rules.class) .setParameter(PARAM_TENANT_ID, tenantId).getResultList(); return result; } catch (Exception e) { logger.log(Level.SEVERE, "Failed to load rules for tenant:" + tenantId, e); throw e; } } private  RulesManager(); static RulesManager getInstance(); short createNewRule(EntityManager em, Rules dbRule, Tenant tenant); Rule saveRule(EntityManager em, Rules dbRule, Tenant tenant, Rule currRule, ApplicationManager am); void sendRuleToKafka(boolean delete, String tenantId, Rule rule, ApplicationManager am); void sendRuleToKafka(boolean delete, String tenantId, String ruleJson, ApplicationManager am); Rules getRule(EntityManager em, String tenantId, short ruleId); List<Short> getRuleByTemplateId(EntityManager em, String tenantId, short templateId); void deleteRule(EntityManager em, String tenantId, short ruleId, ApplicationManager am); void deleteRules(EntityManager em, Tenant tenant, ApplicationManager am); void disableAllRules(EntityManager em, String tenantId, ApplicationManager am); List<Rule> getRuleObjects(EntityManager em, String tenantId); List<Rules> getRules(EntityManager em, String tenantId); String getRuleContents(EntityManager em, String tenantId, boolean pretty, int filter); Rules enableDisableRule(EntityManager em, boolean ruleState, String tenantId, short ruleId,
			ApplicationManager am); Tenant getTenant(EntityManager em, String tenantId);  }
@Test public void testGetRules() throws Exception { List<Rules> rules = null; try { rules = RulesManager.getInstance().getRules(em, TENANT_ID_1); assertEquals(0, rules.size()); } catch (NoResultException e) { } Rules rule = new Rules(); Tenant tenant = RulesManager.getInstance().getTenant(em, TENANT_ID_1); short ruleId = RulesManager.getInstance().createNewRule(em, rule, tenant); try { rules = RulesManager.getInstance().getRules(em, TENANT_ID_1); assertEquals(1, rules.size()); assertEquals(ruleId, rules.get(0).getRuleId()); } catch (NoResultException e) { } try { rules = RulesManager.getInstance().getRules(em, TENANT_ID_1 + "1"); fail("Tenant doesn't exist"); } catch (NoResultException e) { } }