@SuppressWarnings({ "unchecked", "static-access" }) @Test public void createIndexTest() throws Exception{ HttpEntity jsonEntity = new StringEntity("{}", ContentType.APPLICATION_JSON); when(response.getEntity()).thenReturn(jsonEntity); when(restClient.performRequest(anyString(), anyString(), anyMap(), any(HttpEntity.class), Matchers.<Header>anyVararg())).thenReturn(response); ReflectionTestUtils.setField(esManager, "restClient", restClient); when(sl.getStatusCode()).thenReturn(100); when(response.getStatusLine()).thenReturn(sl); esManager.createIndex("index", new ArrayList<>()); when(sl.getStatusCode()).thenReturn(200); when(response.getStatusLine()).thenReturn(sl); esManager.createIndex("index", new ArrayList<>()); when(restClient.performRequest(anyString(), anyString(), anyMap(), any(HttpEntity.class), Matchers.<Header>anyVararg())).thenThrow(new IOException()); ReflectionTestUtils.setField(esManager, "restClient", restClient); esManager.createIndex("index", new ArrayList<>()); }
public static void createIndex(String indexName, List<Map<String, String>> errorList) { if (!indexExists(indexName)) { String payLoad = "{\"settings\": { \"index.mapping.ignore_malformed\": true }}"; try { invokeAPI("PUT", indexName, payLoad); } catch (IOException e) { LOGGER.error("Error in createIndex" ,e ); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Error in createIndex "+indexName); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); errorList.add(errorMap); } } }
ESManager implements Constants { public static void createIndex(String indexName, List<Map<String, String>> errorList) { if (!indexExists(indexName)) { String payLoad = "{\"settings\": { \"index.mapping.ignore_malformed\": true }}"; try { invokeAPI("PUT", indexName, payLoad); } catch (IOException e) { LOGGER.error("Error in createIndex" ,e ); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Error in createIndex "+indexName); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); errorList.add(errorMap); } } } }
ESManager implements Constants { public static void createIndex(String indexName, List<Map<String, String>> errorList) { if (!indexExists(indexName)) { String payLoad = "{\"settings\": { \"index.mapping.ignore_malformed\": true }}"; try { invokeAPI("PUT", indexName, payLoad); } catch (IOException e) { LOGGER.error("Error in createIndex" ,e ); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Error in createIndex "+indexName); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); errorList.add(errorMap); } } }  }
ESManager implements Constants { public static void createIndex(String indexName, List<Map<String, String>> errorList) { if (!indexExists(indexName)) { String payLoad = "{\"settings\": { \"index.mapping.ignore_malformed\": true }}"; try { invokeAPI("PUT", indexName, payLoad); } catch (IOException e) { LOGGER.error("Error in createIndex" ,e ); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Error in createIndex "+indexName); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); errorList.add(errorMap); } } }  static Map<String, Object> uploadData(String index, String type, List<Map<String, Object>> docs, String loaddate); static void refresh(String index); static void uploadData(String index, String type, List<Map<String, Object>> docs, String idKey,
            boolean refresh); static String createESDoc(Map<String, ?> doc); static Response invokeAPI(String method, String endpoint, String payLoad); static void configureIndexAndTypes(String ds, List<Map<String, String>> errorList); static Map<String, Map<String, String>> getExistingInfo(String indexName, String type,
            List<String> filters); @SuppressWarnings("unchecked") static Map<String, Map<String, Map<String, Object>>> fetchCurrentCountStatsForAssetGroups(String date); static void createIndex(String indexName, List<Map<String, String>> errorList); static void createType(String indexName, String typename, List<Map<String, String>> errorList); static void createType(String index, String type, String parent); static void uploadData(String index, String type, List<Map<String, Object>> docs, String[] parentKey); static void deleteOldDocuments(String index, String type, String field, String value); static long updateLoadDate(String index, String type, String accountId, String region, String loaddate,boolean checkLatest); }
ESManager implements Constants { public static void createIndex(String indexName, List<Map<String, String>> errorList) { if (!indexExists(indexName)) { String payLoad = "{\"settings\": { \"index.mapping.ignore_malformed\": true }}"; try { invokeAPI("PUT", indexName, payLoad); } catch (IOException e) { LOGGER.error("Error in createIndex" ,e ); Map<String,String> errorMap = new HashMap<>(); errorMap.put(ERROR, "Error in createIndex "+indexName); errorMap.put(ERROR_TYPE, WARN); errorMap.put(EXCEPTION, e.getMessage()); errorList.add(errorMap); } } }  static Map<String, Object> uploadData(String index, String type, List<Map<String, Object>> docs, String loaddate); static void refresh(String index); static void uploadData(String index, String type, List<Map<String, Object>> docs, String idKey,
            boolean refresh); static String createESDoc(Map<String, ?> doc); static Response invokeAPI(String method, String endpoint, String payLoad); static void configureIndexAndTypes(String ds, List<Map<String, String>> errorList); static Map<String, Map<String, String>> getExistingInfo(String indexName, String type,
            List<String> filters); @SuppressWarnings("unchecked") static Map<String, Map<String, Map<String, Object>>> fetchCurrentCountStatsForAssetGroups(String date); static void createIndex(String indexName, List<Map<String, String>> errorList); static void createType(String indexName, String typename, List<Map<String, String>> errorList); static void createType(String index, String type, String parent); static void uploadData(String index, String type, List<Map<String, Object>> docs, String[] parentKey); static void deleteOldDocuments(String index, String type, String field, String value); static long updateLoadDate(String index, String type, String accountId, String region, String loaddate,boolean checkLatest);  }