InventoryUtil { public static boolean refreshInventoryOnOutOfBand() { logger.debug( "push inventory to Out of band starts" ); String hmsIbInventoryLocation = SpringContextHelper.getIbInventoryLocaiton(); if ( hmsIbInventoryLocation != null ) { try { Map<String, Object[]> inventoryMap = InventoryUtil.initializeInventory( hmsIbInventoryLocation ); AggregatorUtil.populatePlainTextPasswords( inventoryMap ); HmsOobAgentRestTemplate<Map<String, Object[]>> restTemplate = new HmsOobAgentRestTemplate<Map<String, Object[]>>( inventoryMap ); ResponseEntity<Object> response = restTemplate.exchange( HttpMethod.PUT, Constants.HMS_OOB_INVENTORY_RELOAD, Object.class ); if ( response != null && response.getStatusCode() == HttpStatus.OK ) { logger.info( "push inventory to Out of band ends successfully" ); return true; } String exceptionMsg = String.format( "Unsuccessful response: {} from: %s, , can't complete inventory refresh on Out of band", response, Constants.HMS_OOB_INVENTORY_RELOAD ); logger.error( exceptionMsg ); } catch ( Throwable e ) { logger.error( "Exception occured while loading the inventory on Hms oob agent: {}", e ); } } else { String err = String.format( "invalid inventory location: %s, can't complete inventory refresh on Out of band", hmsIbInventoryLocation ); logger.error( err ); } return false; }  static boolean initializeInventory( String inventoryFilePath, String path ); static Map<String, Object[]> initializeInventory( String inventoryFilePath ); static ResponseEntity<HashMap<String, Object[]>> getInventoryOOB( String path, String contentType ); static void putInventoryOOB( String path, String contentType, HmsInventoryConfiguration conf ); static HashMap<String, List<HmsApi>> getOOBSupportedOperations( String path, String contentType ); @SuppressWarnings( "unchecked" ) static Map<String, Object> getUpdatedServerInfos( Object[] hostsToBeUpdated,
                                                             List<ServerInfo> requestServerInfoList ); @SuppressWarnings( "unchecked" ) static List<String> getInvalidHostsinRequest( Object[] inventoryHosts,
                                                         List<ServerInfo> requestServerInfoList ); static boolean createOrUpdateInventoryFile( final String inventoryFilePath,
                                                       final String inventoryFileContent ); static boolean createOrUpdateInventoryFile( final String inventoryFilePath,
                                                       final String inventoryFileContent, final boolean createBackup ); static boolean removeServer( final String inventoryFilePath, final String hostId ); static boolean updateInventoryNodeMap( final String inventoryFileAbsPath ); static boolean isOobAgentInventoryLoaded(); static boolean isInventoryLoaded(); static boolean refreshInventoryOnOutOfBand(); static final String NODE_ID; static final String IB_IP_ADDRESS; static final String USERNAME; static final String PASSWORD; }
@Test public void testRefreshInventoryOnOutOfBand() throws Exception { PowerMockito.mockStatic( SpringContextHelper.class ); when( SpringContextHelper.getIbInventoryLocaiton() ).thenReturn( "dummy.json" ); ResponseEntity<Object> response = new ResponseEntity<>( HttpStatus.OK ); HmsOobAgentRestTemplate<?> restTemplateMock = mock( HmsOobAgentRestTemplate.class ); whenNew( HmsOobAgentRestTemplate.class ).withAnyArguments().thenReturn( restTemplateMock ); when( restTemplateMock.exchange( HttpMethod.PUT, Constants.HMS_OOB_INVENTORY_RELOAD, Object.class ) ).thenReturn( response ); boolean status = InventoryUtil.refreshInventoryOnOutOfBand(); assertTrue( status ); }