AggregatorUtil { public static void populatePlainTextPasswords( Map<String, Object[]> inventoryMap ) throws HMSRestException { if ( inventoryMap != null ) { Object[] hosts = inventoryMap.get( Constants.HOSTS ); Object[] switches = inventoryMap.get( Constants.SWITCHES ); if ( hosts == null || switches == null ) { throw new HMSRestException( Status.INTERNAL_SERVER_ERROR.getStatusCode(), "hosts/switches are null in the provided input file", "invalid inventory file" ); } ObjectMapper mapper = new ObjectMapper(); ServerNode[] serverNodes = mapper.convertValue( hosts, new TypeReference<ServerNode[]>() { } ); SwitchNode[] switchNodes = mapper.convertValue( switches, new TypeReference<SwitchNode[]>() { } ); decryptPassword( serverNodes ); decryptPassword( switchNodes ); Object[] serverNodeObj = mapper.convertValue( serverNodes, new TypeReference<Object[]>() { } ); Object[] switchNodeObj = mapper.convertValue( switchNodes, new TypeReference<Object[]>() { } ); inventoryMap.put( Constants.HOSTS, serverNodeObj ); inventoryMap.put( Constants.SWITCHES, switchNodeObj ); } }  static boolean isComponentAvilableOOB( ServerNode node, ServerComponent component ); @SuppressWarnings( { "deprecation" } ) static void getServerComponentIB( ServerNode node, ServerComponent component ); @SuppressWarnings( "deprecation" ) static void getServerComponentOOB( ServerNode node, ServerComponent component ); static ResponseEntity<T> getResponseEntity( T responseBody, HttpStatus httpStatus ); static ResponseEntity<T> getResponseEntity( HttpStatus httpStatus ); static ResponseEntity<BaseResponse> removeServer( final String hostId ); static ResponseEntity<BaseResponse> changeHostIpmiPassword( String nodeId, String newPassword ); static void populatePlainTextPasswords( Map<String, Object[]> inventoryMap ); static boolean isEsxiHostReachable( ServerNode serverNode, int sshRetryCount, int sshRetryDelay );  }
@Test public void testPopulatePlainTextPasswords() throws HmsException { Map<String, Object[]> inventoryMap = new HashMap<String, Object[]>(); LinkedHashMap<String, Object> nodeMap = new LinkedHashMap<String, Object>(); nodeMap.put( "managementIp", "10.175.17.229" ); nodeMap.put( "nodeID", "N0" ); nodeMap.put( "managementUserPassword", "calvin" ); nodeMap.put( "osPassword", "ca$hc0w" ); Object[] nodesArr = new Object[1]; nodesArr[0] = nodeMap; LinkedHashMap<String, Object> switchMap = new LinkedHashMap<String, Object>(); switchMap.put( "switchId", "S0" ); switchMap.put( "ipAddress", "10.28.197.242" ); switchMap.put( "password", "root123" ); switchMap.put( "role", "MANAGEMENT" ); Object[] switchArr = new Object[1]; switchArr[0] = switchMap; inventoryMap.put( Constants.HOSTS, nodesArr ); inventoryMap.put( Constants.SWITCHES, switchArr ); AggregatorUtil.populatePlainTextPasswords( inventoryMap ); Object[] hostObjs = inventoryMap.get( Constants.HOSTS ); Object[] switchObjs = inventoryMap.get( Constants.SWITCHES ); ObjectMapper mapper = new ObjectMapper(); ServerNode[] serverNodes = mapper.convertValue( hostObjs, new TypeReference<ServerNode[]>() { } ); SwitchNode[] switchNodes = mapper.convertValue( switchObjs, new TypeReference<SwitchNode[]>() { } ); assertEquals( serverNodes[0].getNodeID(), "N0" ); assertEquals( serverNodes[0].getManagementIp(), "10.175.17.229" ); assertEquals( serverNodes[0].getManagementUserPassword(), "calvin" ); assertEquals( serverNodes[0].getOsPassword(), "ca$hc0w" ); assertEquals( switchNodes[0].getSwitchId(), "S0" ); assertEquals( switchNodes[0].getIpAddress(), "10.28.197.242" ); assertEquals( switchNodes[0].getPassword(), "root123" ); }
@Test( expected = HMSRestException.class ) public void testPopulatePlainTextPasswordsForNullInput() throws HmsException { Map<String, Object[]> inventoryMap = new HashMap<String, Object[]>(); AggregatorUtil.populatePlainTextPasswords( inventoryMap ); }