@Test public void test3mapEntityToViewBean() { XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class); XXService xService = Mockito.mock(XXService.class); XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class); XXServiceDef xServiceDef = Mockito.mock(XXServiceDef.class); RangerPolicy rangerPolicy = rangerPolicy(); XXPolicy policy = policy(); Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao); Mockito.when(xServiceDao.getById(policy.getService())).thenReturn( xService); Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao); Mockito.when(xServiceDefDao.getById(xService.getType())).thenReturn( xServiceDef); RangerPolicy dbRangerPolicy = policyService.mapEntityToViewBean( rangerPolicy, policy); Assert.assertNotNull(dbRangerPolicy); Assert.assertEquals(dbRangerPolicy.getId(), rangerPolicy.getId()); Assert.assertEquals(dbRangerPolicy.getGuid(), rangerPolicy.getGuid()); Assert.assertEquals(dbRangerPolicy.getName(), rangerPolicy.getName()); Assert.assertEquals(dbRangerPolicy.getIsEnabled(), rangerPolicy.getIsEnabled()); Assert.assertEquals(dbRangerPolicy.getVersion(), rangerPolicy.getVersion()); Assert.assertEquals(dbRangerPolicy.getDescription(), rangerPolicy.getDescription()); Mockito.verify(daoManager).getXXService(); }
@Override protected V mapEntityToViewBean(V vObj, T xObj) { XXService xService = daoMgr.getXXService().getById(xObj.getService()); XXServiceDef xServiceDef = daoMgr.getXXServiceDef().getById(xService.getType()); vObj.setGuid(xObj.getGuid()); vObj.setVersion(xObj.getVersion()); vObj.setService(xService.getName()); vObj.setServiceType(xServiceDef.getName()); vObj.setName(StringUtils.trim(xObj.getName())); vObj.setPolicyType(xObj.getPolicyType() == null ? RangerPolicy.POLICY_TYPE_ACCESS : xObj.getPolicyType()); vObj.setPolicyPriority(xObj.getPolicyPriority() == null ? RangerPolicy.POLICY_PRIORITY_NORMAL : xObj.getPolicyPriority()); vObj.setDescription(xObj.getDescription()); vObj.setResourceSignature(xObj.getResourceSignature()); vObj.setIsEnabled(xObj.getIsEnabled()); vObj.setIsAuditEnabled(xObj.getIsAuditEnabled()); String zoneName = convertZoneIdToZoneName(xObj.getZoneId(), vObj); vObj.setZoneName(zoneName); String policyText = xObj.getPolicyText(); RangerPolicy ret = JsonUtils.jsonToObject(policyText, RangerPolicy.class); if (ret != null) { vObj.setOptions(ret.getOptions()); vObj.setValiditySchedules(ret.getValiditySchedules()); vObj.setPolicyLabels(ret.getPolicyLabels()); } return vObj; }
RangerPolicyServiceBase extends
		RangerBaseModelService<T, V> { @Override protected V mapEntityToViewBean(V vObj, T xObj) { XXService xService = daoMgr.getXXService().getById(xObj.getService()); XXServiceDef xServiceDef = daoMgr.getXXServiceDef().getById(xService.getType()); vObj.setGuid(xObj.getGuid()); vObj.setVersion(xObj.getVersion()); vObj.setService(xService.getName()); vObj.setServiceType(xServiceDef.getName()); vObj.setName(StringUtils.trim(xObj.getName())); vObj.setPolicyType(xObj.getPolicyType() == null ? RangerPolicy.POLICY_TYPE_ACCESS : xObj.getPolicyType()); vObj.setPolicyPriority(xObj.getPolicyPriority() == null ? RangerPolicy.POLICY_PRIORITY_NORMAL : xObj.getPolicyPriority()); vObj.setDescription(xObj.getDescription()); vObj.setResourceSignature(xObj.getResourceSignature()); vObj.setIsEnabled(xObj.getIsEnabled()); vObj.setIsAuditEnabled(xObj.getIsAuditEnabled()); String zoneName = convertZoneIdToZoneName(xObj.getZoneId(), vObj); vObj.setZoneName(zoneName); String policyText = xObj.getPolicyText(); RangerPolicy ret = JsonUtils.jsonToObject(policyText, RangerPolicy.class); if (ret != null) { vObj.setOptions(ret.getOptions()); vObj.setValiditySchedules(ret.getValiditySchedules()); vObj.setPolicyLabels(ret.getPolicyLabels()); } return vObj; } }
RangerPolicyServiceBase extends
		RangerBaseModelService<T, V> { @Override protected V mapEntityToViewBean(V vObj, T xObj) { XXService xService = daoMgr.getXXService().getById(xObj.getService()); XXServiceDef xServiceDef = daoMgr.getXXServiceDef().getById(xService.getType()); vObj.setGuid(xObj.getGuid()); vObj.setVersion(xObj.getVersion()); vObj.setService(xService.getName()); vObj.setServiceType(xServiceDef.getName()); vObj.setName(StringUtils.trim(xObj.getName())); vObj.setPolicyType(xObj.getPolicyType() == null ? RangerPolicy.POLICY_TYPE_ACCESS : xObj.getPolicyType()); vObj.setPolicyPriority(xObj.getPolicyPriority() == null ? RangerPolicy.POLICY_PRIORITY_NORMAL : xObj.getPolicyPriority()); vObj.setDescription(xObj.getDescription()); vObj.setResourceSignature(xObj.getResourceSignature()); vObj.setIsEnabled(xObj.getIsEnabled()); vObj.setIsAuditEnabled(xObj.getIsAuditEnabled()); String zoneName = convertZoneIdToZoneName(xObj.getZoneId(), vObj); vObj.setZoneName(zoneName); String policyText = xObj.getPolicyText(); RangerPolicy ret = JsonUtils.jsonToObject(policyText, RangerPolicy.class); if (ret != null) { vObj.setOptions(ret.getOptions()); vObj.setValiditySchedules(ret.getValiditySchedules()); vObj.setPolicyLabels(ret.getPolicyLabels()); } return vObj; } RangerPolicyServiceBase(); }
RangerPolicyServiceBase extends
		RangerBaseModelService<T, V> { @Override protected V mapEntityToViewBean(V vObj, T xObj) { XXService xService = daoMgr.getXXService().getById(xObj.getService()); XXServiceDef xServiceDef = daoMgr.getXXServiceDef().getById(xService.getType()); vObj.setGuid(xObj.getGuid()); vObj.setVersion(xObj.getVersion()); vObj.setService(xService.getName()); vObj.setServiceType(xServiceDef.getName()); vObj.setName(StringUtils.trim(xObj.getName())); vObj.setPolicyType(xObj.getPolicyType() == null ? RangerPolicy.POLICY_TYPE_ACCESS : xObj.getPolicyType()); vObj.setPolicyPriority(xObj.getPolicyPriority() == null ? RangerPolicy.POLICY_PRIORITY_NORMAL : xObj.getPolicyPriority()); vObj.setDescription(xObj.getDescription()); vObj.setResourceSignature(xObj.getResourceSignature()); vObj.setIsEnabled(xObj.getIsEnabled()); vObj.setIsAuditEnabled(xObj.getIsAuditEnabled()); String zoneName = convertZoneIdToZoneName(xObj.getZoneId(), vObj); vObj.setZoneName(zoneName); String policyText = xObj.getPolicyText(); RangerPolicy ret = JsonUtils.jsonToObject(policyText, RangerPolicy.class); if (ret != null) { vObj.setOptions(ret.getOptions()); vObj.setValiditySchedules(ret.getValiditySchedules()); vObj.setPolicyLabels(ret.getPolicyLabels()); } return vObj; } RangerPolicyServiceBase();  }
RangerPolicyServiceBase extends
		RangerBaseModelService<T, V> { @Override protected V mapEntityToViewBean(V vObj, T xObj) { XXService xService = daoMgr.getXXService().getById(xObj.getService()); XXServiceDef xServiceDef = daoMgr.getXXServiceDef().getById(xService.getType()); vObj.setGuid(xObj.getGuid()); vObj.setVersion(xObj.getVersion()); vObj.setService(xService.getName()); vObj.setServiceType(xServiceDef.getName()); vObj.setName(StringUtils.trim(xObj.getName())); vObj.setPolicyType(xObj.getPolicyType() == null ? RangerPolicy.POLICY_TYPE_ACCESS : xObj.getPolicyType()); vObj.setPolicyPriority(xObj.getPolicyPriority() == null ? RangerPolicy.POLICY_PRIORITY_NORMAL : xObj.getPolicyPriority()); vObj.setDescription(xObj.getDescription()); vObj.setResourceSignature(xObj.getResourceSignature()); vObj.setIsEnabled(xObj.getIsEnabled()); vObj.setIsAuditEnabled(xObj.getIsAuditEnabled()); String zoneName = convertZoneIdToZoneName(xObj.getZoneId(), vObj); vObj.setZoneName(zoneName); String policyText = xObj.getPolicyText(); RangerPolicy ret = JsonUtils.jsonToObject(policyText, RangerPolicy.class); if (ret != null) { vObj.setOptions(ret.getOptions()); vObj.setValiditySchedules(ret.getValiditySchedules()); vObj.setPolicyLabels(ret.getPolicyLabels()); } return vObj; } RangerPolicyServiceBase();  static final String OPTION_POLICY_VALIDITY_SCHEDULES; }