@Test public void test1MapViewToEntityBean() { XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class); XXServiceDef xServiceDef = Mockito.mock(XXServiceDef.class); RangerService rangerService = rangerService(); XXService service = service(); int OPERATION_CONTEXT = 1; Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao); Mockito.when(xServiceDefDao.findByName(rangerService.getType())) .thenReturn(xServiceDef); XXService dbService = rangerServiceService.mapViewToEntityBean( rangerService, service, OPERATION_CONTEXT); Assert.assertNotNull(dbService); Assert.assertEquals(dbService, service); Assert.assertEquals(dbService.getDescription(), service.getDescription()); Assert.assertEquals(dbService.getGuid(), service.getGuid()); Assert.assertEquals(dbService.getName(), service.getName()); Assert.assertEquals(dbService.getAddedByUserId(), service.getAddedByUserId()); Assert.assertEquals(dbService.getId(), service.getId()); Assert.assertEquals(dbService.getVersion(), service.getVersion()); Assert.assertEquals(dbService.getType(), service.getType()); Assert.assertEquals(dbService.getUpdatedByUserId(), service.getUpdatedByUserId()); Mockito.verify(daoManager).getXXServiceDef(); }
@Override protected T mapViewToEntityBean(V vObj, T xObj, int OPERATION_CONTEXT) { String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid(); xObj.setGuid(guid); XXServiceDef xServiceDef = daoMgr.getXXServiceDef().findByName(vObj.getType()); if(xServiceDef == null) { throw restErrorUtil.createRESTException( "No ServiceDefinition found with name :" + vObj.getType(), MessageEnums.INVALID_INPUT_DATA); } Long tagServiceId = null; String tagServiceName = vObj.getTagService(); if(! StringUtils.isEmpty(tagServiceName)) { XXService xTagService = daoMgr.getXXService().findByName(tagServiceName); if(xTagService == null) { throw restErrorUtil.createRESTException( "No Service found with name :" + tagServiceName, MessageEnums.INVALID_INPUT_DATA); } tagServiceId = xTagService.getId(); } xObj.setType(xServiceDef.getId()); xObj.setName(vObj.getName()); xObj.setDisplayName(vObj.getDisplayName()); xObj.setTagService(tagServiceId); if (OPERATION_CONTEXT == OPERATION_CREATE_CONTEXT) { xObj.setTagVersion(vObj.getTagVersion()); } xObj.setDescription(vObj.getDescription()); xObj.setIsEnabled(vObj.getIsEnabled()); return xObj; }
RangerServiceServiceBase extends RangerBaseModelService<T, V> { @Override protected T mapViewToEntityBean(V vObj, T xObj, int OPERATION_CONTEXT) { String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid(); xObj.setGuid(guid); XXServiceDef xServiceDef = daoMgr.getXXServiceDef().findByName(vObj.getType()); if(xServiceDef == null) { throw restErrorUtil.createRESTException( "No ServiceDefinition found with name :" + vObj.getType(), MessageEnums.INVALID_INPUT_DATA); } Long tagServiceId = null; String tagServiceName = vObj.getTagService(); if(! StringUtils.isEmpty(tagServiceName)) { XXService xTagService = daoMgr.getXXService().findByName(tagServiceName); if(xTagService == null) { throw restErrorUtil.createRESTException( "No Service found with name :" + tagServiceName, MessageEnums.INVALID_INPUT_DATA); } tagServiceId = xTagService.getId(); } xObj.setType(xServiceDef.getId()); xObj.setName(vObj.getName()); xObj.setDisplayName(vObj.getDisplayName()); xObj.setTagService(tagServiceId); if (OPERATION_CONTEXT == OPERATION_CREATE_CONTEXT) { xObj.setTagVersion(vObj.getTagVersion()); } xObj.setDescription(vObj.getDescription()); xObj.setIsEnabled(vObj.getIsEnabled()); return xObj; } }
RangerServiceServiceBase extends RangerBaseModelService<T, V> { @Override protected T mapViewToEntityBean(V vObj, T xObj, int OPERATION_CONTEXT) { String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid(); xObj.setGuid(guid); XXServiceDef xServiceDef = daoMgr.getXXServiceDef().findByName(vObj.getType()); if(xServiceDef == null) { throw restErrorUtil.createRESTException( "No ServiceDefinition found with name :" + vObj.getType(), MessageEnums.INVALID_INPUT_DATA); } Long tagServiceId = null; String tagServiceName = vObj.getTagService(); if(! StringUtils.isEmpty(tagServiceName)) { XXService xTagService = daoMgr.getXXService().findByName(tagServiceName); if(xTagService == null) { throw restErrorUtil.createRESTException( "No Service found with name :" + tagServiceName, MessageEnums.INVALID_INPUT_DATA); } tagServiceId = xTagService.getId(); } xObj.setType(xServiceDef.getId()); xObj.setName(vObj.getName()); xObj.setDisplayName(vObj.getDisplayName()); xObj.setTagService(tagServiceId); if (OPERATION_CONTEXT == OPERATION_CREATE_CONTEXT) { xObj.setTagVersion(vObj.getTagVersion()); } xObj.setDescription(vObj.getDescription()); xObj.setIsEnabled(vObj.getIsEnabled()); return xObj; } RangerServiceServiceBase(); }
RangerServiceServiceBase extends RangerBaseModelService<T, V> { @Override protected T mapViewToEntityBean(V vObj, T xObj, int OPERATION_CONTEXT) { String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid(); xObj.setGuid(guid); XXServiceDef xServiceDef = daoMgr.getXXServiceDef().findByName(vObj.getType()); if(xServiceDef == null) { throw restErrorUtil.createRESTException( "No ServiceDefinition found with name :" + vObj.getType(), MessageEnums.INVALID_INPUT_DATA); } Long tagServiceId = null; String tagServiceName = vObj.getTagService(); if(! StringUtils.isEmpty(tagServiceName)) { XXService xTagService = daoMgr.getXXService().findByName(tagServiceName); if(xTagService == null) { throw restErrorUtil.createRESTException( "No Service found with name :" + tagServiceName, MessageEnums.INVALID_INPUT_DATA); } tagServiceId = xTagService.getId(); } xObj.setType(xServiceDef.getId()); xObj.setName(vObj.getName()); xObj.setDisplayName(vObj.getDisplayName()); xObj.setTagService(tagServiceId); if (OPERATION_CONTEXT == OPERATION_CREATE_CONTEXT) { xObj.setTagVersion(vObj.getTagVersion()); } xObj.setDescription(vObj.getDescription()); xObj.setIsEnabled(vObj.getIsEnabled()); return xObj; } RangerServiceServiceBase(); RangerServiceList searchRangerServices(SearchFilter searchFilter); }
RangerServiceServiceBase extends RangerBaseModelService<T, V> { @Override protected T mapViewToEntityBean(V vObj, T xObj, int OPERATION_CONTEXT) { String guid = (StringUtils.isEmpty(vObj.getGuid())) ? guidUtil.genGUID() : vObj.getGuid(); xObj.setGuid(guid); XXServiceDef xServiceDef = daoMgr.getXXServiceDef().findByName(vObj.getType()); if(xServiceDef == null) { throw restErrorUtil.createRESTException( "No ServiceDefinition found with name :" + vObj.getType(), MessageEnums.INVALID_INPUT_DATA); } Long tagServiceId = null; String tagServiceName = vObj.getTagService(); if(! StringUtils.isEmpty(tagServiceName)) { XXService xTagService = daoMgr.getXXService().findByName(tagServiceName); if(xTagService == null) { throw restErrorUtil.createRESTException( "No Service found with name :" + tagServiceName, MessageEnums.INVALID_INPUT_DATA); } tagServiceId = xTagService.getId(); } xObj.setType(xServiceDef.getId()); xObj.setName(vObj.getName()); xObj.setDisplayName(vObj.getDisplayName()); xObj.setTagService(tagServiceId); if (OPERATION_CONTEXT == OPERATION_CREATE_CONTEXT) { xObj.setTagVersion(vObj.getTagVersion()); } xObj.setDescription(vObj.getDescription()); xObj.setIsEnabled(vObj.getIsEnabled()); return xObj; } RangerServiceServiceBase(); RangerServiceList searchRangerServices(SearchFilter searchFilter);  }