@Test public void test9updateSecurityZoneByUnknownId() throws Exception { RangerSecurityZone securityZoneToUpdate = new RangerSecurityZone(); securityZoneToUpdate.setId(2L); XXSecurityZoneDao xXSecurityZoneDao = Mockito.mock(XXSecurityZoneDao.class); Mockito.when(daoManager.getXXSecurityZoneDao()).thenReturn(xXSecurityZoneDao); Mockito.when(xXSecurityZoneDao.findByZoneId(securityZoneToUpdate.getId())).thenReturn(null); Mockito.when(restErrorUtil.createRESTException(Mockito.anyString())).thenThrow(new WebApplicationException()); thrown.expect(WebApplicationException.class); securityZoneDBStore.updateSecurityZoneById(securityZoneToUpdate); Mockito.verify(daoManager, times(1)).getXXSecurityZoneDao(); Mockito.verify(xXSecurityZoneDao, times(1)).findByZoneId(securityZoneToUpdate.getId()); }
@Override public RangerSecurityZone updateSecurityZoneById(RangerSecurityZone securityZone) throws Exception { XXSecurityZone xxSecurityZone = daoMgr.getXXSecurityZoneDao().findByZoneId(securityZone.getId()); if (xxSecurityZone == null) { throw restErrorUtil.createRESTException("security-zone with id: " + securityZone.getId() + " does not exist"); } Gson gsonBuilder = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSS-Z").create(); RangerSecurityZone oldSecurityZone = gsonBuilder.fromJson(xxSecurityZone.getJsonData(), RangerSecurityZone.class); daoMgr.getXXGlobalState().onGlobalStateChange(RANGER_GLOBAL_STATE_NAME); RangerSecurityZone updatedSecurityZone = securityZoneService.update(securityZone); if (updatedSecurityZone == null) { throw new Exception("Cannot update security zone:[" + securityZone + "]"); } securityZoneRefUpdater.createNewZoneMappingForRefTable(updatedSecurityZone); List<XXTrxLog> trxLogList = securityZoneService.getTransactionLog(updatedSecurityZone, oldSecurityZone, "update"); bizUtil.createTrxLog(trxLogList); return securityZone; }
SecurityZoneDBStore implements SecurityZoneStore { @Override public RangerSecurityZone updateSecurityZoneById(RangerSecurityZone securityZone) throws Exception { XXSecurityZone xxSecurityZone = daoMgr.getXXSecurityZoneDao().findByZoneId(securityZone.getId()); if (xxSecurityZone == null) { throw restErrorUtil.createRESTException("security-zone with id: " + securityZone.getId() + " does not exist"); } Gson gsonBuilder = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSS-Z").create(); RangerSecurityZone oldSecurityZone = gsonBuilder.fromJson(xxSecurityZone.getJsonData(), RangerSecurityZone.class); daoMgr.getXXGlobalState().onGlobalStateChange(RANGER_GLOBAL_STATE_NAME); RangerSecurityZone updatedSecurityZone = securityZoneService.update(securityZone); if (updatedSecurityZone == null) { throw new Exception("Cannot update security zone:[" + securityZone + "]"); } securityZoneRefUpdater.createNewZoneMappingForRefTable(updatedSecurityZone); List<XXTrxLog> trxLogList = securityZoneService.getTransactionLog(updatedSecurityZone, oldSecurityZone, "update"); bizUtil.createTrxLog(trxLogList); return securityZone; } }
SecurityZoneDBStore implements SecurityZoneStore { @Override public RangerSecurityZone updateSecurityZoneById(RangerSecurityZone securityZone) throws Exception { XXSecurityZone xxSecurityZone = daoMgr.getXXSecurityZoneDao().findByZoneId(securityZone.getId()); if (xxSecurityZone == null) { throw restErrorUtil.createRESTException("security-zone with id: " + securityZone.getId() + " does not exist"); } Gson gsonBuilder = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSS-Z").create(); RangerSecurityZone oldSecurityZone = gsonBuilder.fromJson(xxSecurityZone.getJsonData(), RangerSecurityZone.class); daoMgr.getXXGlobalState().onGlobalStateChange(RANGER_GLOBAL_STATE_NAME); RangerSecurityZone updatedSecurityZone = securityZoneService.update(securityZone); if (updatedSecurityZone == null) { throw new Exception("Cannot update security zone:[" + securityZone + "]"); } securityZoneRefUpdater.createNewZoneMappingForRefTable(updatedSecurityZone); List<XXTrxLog> trxLogList = securityZoneService.getTransactionLog(updatedSecurityZone, oldSecurityZone, "update"); bizUtil.createTrxLog(trxLogList); return securityZone; }  }
SecurityZoneDBStore implements SecurityZoneStore { @Override public RangerSecurityZone updateSecurityZoneById(RangerSecurityZone securityZone) throws Exception { XXSecurityZone xxSecurityZone = daoMgr.getXXSecurityZoneDao().findByZoneId(securityZone.getId()); if (xxSecurityZone == null) { throw restErrorUtil.createRESTException("security-zone with id: " + securityZone.getId() + " does not exist"); } Gson gsonBuilder = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSS-Z").create(); RangerSecurityZone oldSecurityZone = gsonBuilder.fromJson(xxSecurityZone.getJsonData(), RangerSecurityZone.class); daoMgr.getXXGlobalState().onGlobalStateChange(RANGER_GLOBAL_STATE_NAME); RangerSecurityZone updatedSecurityZone = securityZoneService.update(securityZone); if (updatedSecurityZone == null) { throw new Exception("Cannot update security zone:[" + securityZone + "]"); } securityZoneRefUpdater.createNewZoneMappingForRefTable(updatedSecurityZone); List<XXTrxLog> trxLogList = securityZoneService.getTransactionLog(updatedSecurityZone, oldSecurityZone, "update"); bizUtil.createTrxLog(trxLogList); return securityZone; }  void init(); @PostConstruct void initStore(); @Override RangerSecurityZone createSecurityZone(RangerSecurityZone securityZone); @Override RangerSecurityZone updateSecurityZoneById(RangerSecurityZone securityZone); @Override void deleteSecurityZoneByName(String zoneName); @Override void deleteSecurityZoneById(Long zoneId); @Override RangerSecurityZone getSecurityZone(Long id); @Override RangerSecurityZone getSecurityZoneByName(String name); @Override List<RangerSecurityZone> getSecurityZones(SearchFilter filter); @Override Map<String, RangerSecurityZone.RangerSecurityZoneService> getSecurityZonesForService(String serviceName); }
SecurityZoneDBStore implements SecurityZoneStore { @Override public RangerSecurityZone updateSecurityZoneById(RangerSecurityZone securityZone) throws Exception { XXSecurityZone xxSecurityZone = daoMgr.getXXSecurityZoneDao().findByZoneId(securityZone.getId()); if (xxSecurityZone == null) { throw restErrorUtil.createRESTException("security-zone with id: " + securityZone.getId() + " does not exist"); } Gson gsonBuilder = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSS-Z").create(); RangerSecurityZone oldSecurityZone = gsonBuilder.fromJson(xxSecurityZone.getJsonData(), RangerSecurityZone.class); daoMgr.getXXGlobalState().onGlobalStateChange(RANGER_GLOBAL_STATE_NAME); RangerSecurityZone updatedSecurityZone = securityZoneService.update(securityZone); if (updatedSecurityZone == null) { throw new Exception("Cannot update security zone:[" + securityZone + "]"); } securityZoneRefUpdater.createNewZoneMappingForRefTable(updatedSecurityZone); List<XXTrxLog> trxLogList = securityZoneService.getTransactionLog(updatedSecurityZone, oldSecurityZone, "update"); bizUtil.createTrxLog(trxLogList); return securityZone; }  void init(); @PostConstruct void initStore(); @Override RangerSecurityZone createSecurityZone(RangerSecurityZone securityZone); @Override RangerSecurityZone updateSecurityZoneById(RangerSecurityZone securityZone); @Override void deleteSecurityZoneByName(String zoneName); @Override void deleteSecurityZoneById(Long zoneId); @Override RangerSecurityZone getSecurityZone(Long id); @Override RangerSecurityZone getSecurityZoneByName(String name); @Override List<RangerSecurityZone> getSecurityZones(SearchFilter filter); @Override Map<String, RangerSecurityZone.RangerSecurityZoneService> getSecurityZonesForService(String serviceName);  }