@Test
public void testRemoveServer()
    throws HmsException, JsonGenerationException, JsonMappingException, IOException
{

    Map<String, Object[]> inventory = new HashMap<String, Object[]>();
    // add node_1
    String nodeId = "N" + TestUtil.getDateTimeStamp();
    ServerNode serverNode = TestUtil.getServerNode( nodeId );
    List<ServerNode> serverNodes = new ArrayList<ServerNode>();
    serverNodes.add( serverNode );
    // add node_2
    String nodeId2 = "N2" + TestUtil.getDateTimeStamp();
    ServerNode serverNode2 = TestUtil.getServerNode( nodeId2 );
    serverNodes.add( serverNode2 );
    // save inventory
    inventory.put( Constants.HOSTS, serverNodes.toArray( new ServerNode[serverNodes.size()] ) );
    String tempDir = TestUtil.getTemporaryDirectory();
    String invFileName = FilenameUtils.concat( tempDir, TestUtil.getDateTimeStamp() + ".json" );
    String invContent = TestUtil.getValueAsString( inventory );
    boolean createdOrUpdated = InventoryUtil.createOrUpdateInventoryFile( invFileName, invContent );
    assertTrue( createdOrUpdated );
    // remove node_1 from inventory
    boolean removed = InventoryUtil.removeServer( invFileName, nodeId );
    assertTrue( removed );
    // Check that hosts does not contain removed node_1.
    Map<String, Object[]> invConfig = InventoryUtil.initializeInventory( invFileName );
    assertNotNull( invConfig );
    assertTrue( invConfig.containsKey( Constants.HOSTS ) );
    Object[] hosts = invConfig.get( Constants.HOSTS );
    assertNotNull( hosts );
    assertTrue( hosts.length == 1 );
    ObjectMapper objectMapper = new ObjectMapper();
    ServerNode[] serverNodes1 = objectMapper.convertValue( hosts, new TypeReference<ServerNode[]>()
    {
    } );
    assertNotNull( serverNodes1 );
    assertTrue( serverNodes1.length == 1 );
    ServerNode serverNode3 = serverNodes1[0];
    assertTrue( StringUtils.equals( nodeId2, serverNode3.getNodeID() ) );
    assertFalse( StringUtils.equals( nodeId, serverNode3.getNodeID() ) );
    assertTrue( FileUtil.deleteDirectory( tempDir ) );
}