HmsInventory { public boolean saveInventory( final String inventoryFile, boolean backup ) { if ( StringUtils.isBlank( inventoryFile ) ) { logger.warn( "In saveInventory, inventory file name is either null or blank." ); return false; } File file = new File( inventoryFile ); if ( backup && file.exists() ) { try { String backupfile = file.getName() + ".bak." + file.lastModified(); File b = new File( file.getParent(), backupfile ); logger.debug( "In saveInventory, Saving backup of HMS inventory file to {}.", b.getAbsolutePath() ); Files.copy( file.toPath(), b.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES ); } catch ( IOException ioe ) { logger.warn( "In saveInventory, Error saving backup copy of file {}.", file.getAbsolutePath(), ioe ); } } try { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.enable( SerializationFeature.INDENT_OUTPUT ); objectMapper.writeValue( file, this.nodeMap ); logger.debug( "In saveInventory, saved inventory to file '{}'.", file.getAbsolutePath() ); return true; } catch ( IOException e ) { logger.error( "In saveInventory, error while saving inventory to file '{}'.", file.getAbsolutePath() ); return false; } } private  HmsInventory(); static HmsInventory getInstance(); boolean loadInventory( final String inventoryFile ); boolean saveInventory( final String inventoryFile, boolean backup ); boolean saveInventory( final String inventoryFile ); boolean saveInventory( final boolean backup ); boolean saveInventory(); List<ServerNode> getHosts(); List<SwitchNode> getSwitches(); String getInventoryFile(); ServerNode getServerNode( final String hostId ); SwitchNode getSwitchNode( final String switchId ); boolean addHost( ServerNode serverNode ); boolean removeHost( final String hostId ); boolean setHosts( List<ServerNode> hosts );  }
@Test @Ignore public void testSaveInventory() { HmsInventory hmsInventory = HmsInventory.getInstance(); assertTrue( hmsInventory.loadInventory( props.getProperty( HMS_IB_INVENTORY_LOCATION_PROPERTY ) ) ); final String nodeId = this.getNodeId( this.getDateTimeInMillis() ); assertTrue( hmsInventory.addHost( getServerNode( nodeId ) ) ); assertTrue( hmsInventory.saveInventory( props.getProperty( HMS_IB_INVENTORY_LOCATION_PROPERTY ), false ) ); HmsGenericUtil.deleteLatestInventoryBackup(); }