@Test public void getDocumentForIdTest() throws Exception { PowerMockito.mockStatic(CommonUtils.class); PowerMockito.mockStatic(StringBuilder.class); PowerMockito.when(CommonUtils.getEnvVariableValue(anyString())).thenReturn("123"); final StringBuilder stringBuilder = PowerMockito.spy(new StringBuilder()); PowerMockito.whenNew(StringBuilder.class).withAnyArguments().thenReturn(stringBuilder); PowerMockito.when(CommonUtils.getPropValue(anyString())).thenReturn("123"); PowerMockito.mockStatic(Strings.class); PowerMockito.when(Strings.isNullOrEmpty(anyString())).thenReturn(false); String jsonObject = "{\"ruleUUID\":\"qqqq123\",\"hits\":{\"total\":1000,\"max_score\":null,\"hits\":[{\"_index\":\"bank\",\"_type\":\"_doc\",\"_id\":\"0\",\"sort\":[0],\"_score\":null,\"_source\":{\"account_number\":0,\"balance\":16623,\"firstname\":\"Bradshaw\",\"lastname\":\"Mckenzie\",\"age\":29,\"gender\":\"F\",\"address\":\"244 Columbus Place\",\"employer\":\"Euron\",\"email\":\"bradshawmckenzie@euron.com\",\"city\":\"Hobucken\",\"state\":\"CO\"}}]},\"aggregations\":{\"avg-values-per-day\":{\"buckets\":[{\"key_as_string\":\"ID\",\"Avg-CPU-Utilization\":{\"value\":12},\"Avg-NetworkIn\":{\"value\":12},\"Avg-NetworkOut\":{\"value\":12},\"Avg-DiskReadinBytes\":{\"value\":12},\"Avg-DiskWriteinBytes\":{\"value\":12}}]}}}"; PowerMockito.when(CommonUtils.doHttpPost(anyString(), anyString(),anyMap())).thenReturn(jsonObject); assertNotNull(ESUtils.getDocumentForId("index", "targetType", "_id")); }
public static Map<String, String> getDocumentForId(String index, String targetType, String _id) throws Exception { String url = ESUtils.getEsUrl(); Map<String, Object> filter = new HashMap<>(); filter.put("_id", _id); List<String> fields = new ArrayList<String>(); List<Map<String, String>> details = getDataFromES(url, index.toLowerCase(), targetType.toLowerCase(), filter, null, null, fields, 0, 100); if (details != null && !details.isEmpty()) { return details.get(0); } else { return new HashMap<>(); } }
ESUtils { public static Map<String, String> getDocumentForId(String index, String targetType, String _id) throws Exception { String url = ESUtils.getEsUrl(); Map<String, Object> filter = new HashMap<>(); filter.put("_id", _id); List<String> fields = new ArrayList<String>(); List<Map<String, String>> details = getDataFromES(url, index.toLowerCase(), targetType.toLowerCase(), filter, null, null, fields, 0, 100); if (details != null && !details.isEmpty()) { return details.get(0); } else { return new HashMap<>(); } } }
ESUtils { public static Map<String, String> getDocumentForId(String index, String targetType, String _id) throws Exception { String url = ESUtils.getEsUrl(); Map<String, Object> filter = new HashMap<>(); filter.put("_id", _id); List<String> fields = new ArrayList<String>(); List<Map<String, String>> details = getDataFromES(url, index.toLowerCase(), targetType.toLowerCase(), filter, null, null, fields, 0, 100); if (details != null && !details.isEmpty()) { return details.get(0); } else { return new HashMap<>(); } }  }
ESUtils { public static Map<String, String> getDocumentForId(String index, String targetType, String _id) throws Exception { String url = ESUtils.getEsUrl(); Map<String, Object> filter = new HashMap<>(); filter.put("_id", _id); List<String> fields = new ArrayList<String>(); List<Map<String, String>> details = getDataFromES(url, index.toLowerCase(), targetType.toLowerCase(), filter, null, null, fields, 0, 100); if (details != null && !details.isEmpty()) { return details.get(0); } else { return new HashMap<>(); } }  static List<Map<String, String>> getResourcesFromEs(String index, String targetType,
            Map<String, String> filter, List<String> fields); @SuppressWarnings("unchecked") static long getTotalDocumentCountForIndexAndType(String url, String index, String type,
            Map<String, Object> filter, Map<String, Object> mustNotFilter, HashMultimap<String, Object> shouldFilter); static boolean isValidIndex(final String url, final String index); static boolean isValidType(final String url, final String index, final String type); static String getEsUrl(); static String createMapping(String esUrl, String index, String type); static String createMappingWithParent(String esUrl, String index, String type, String parentType); static void createIndex(String url, String indexName); static void ensureIndexAndTypeForAnnotation(Annotation annotation, Boolean createIndexIfNotFound); static String buildIndexNameFromAnnotation(final Annotation annotation); static String getIssueTypeFromAnnotation(Annotation annotation); @SuppressWarnings("unchecked") static List<Map<String, String>> getDataFromES(final String url, String dataSource, String entityType,
            Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
            final HashMultimap<String, Object> shouldFilter, List<String> fields, long from, long size); static String convertAttributetoKeyword(String attributeName); static Map<String, String> getDocumentForId(String index, String targetType, String _id); static Boolean publishMetrics(Map<String, Object> evalResults,String type); static int getESPort(); static String getESHost(); static Boolean doESPublish(Map<String, Object> evalResults, String indexName, String type); static Boolean doESUpdate(String docId,Map<String, Object> evalResults, String indexName, String type); static String createKeyword(final String key); }
ESUtils { public static Map<String, String> getDocumentForId(String index, String targetType, String _id) throws Exception { String url = ESUtils.getEsUrl(); Map<String, Object> filter = new HashMap<>(); filter.put("_id", _id); List<String> fields = new ArrayList<String>(); List<Map<String, String>> details = getDataFromES(url, index.toLowerCase(), targetType.toLowerCase(), filter, null, null, fields, 0, 100); if (details != null && !details.isEmpty()) { return details.get(0); } else { return new HashMap<>(); } }  static List<Map<String, String>> getResourcesFromEs(String index, String targetType,
            Map<String, String> filter, List<String> fields); @SuppressWarnings("unchecked") static long getTotalDocumentCountForIndexAndType(String url, String index, String type,
            Map<String, Object> filter, Map<String, Object> mustNotFilter, HashMultimap<String, Object> shouldFilter); static boolean isValidIndex(final String url, final String index); static boolean isValidType(final String url, final String index, final String type); static String getEsUrl(); static String createMapping(String esUrl, String index, String type); static String createMappingWithParent(String esUrl, String index, String type, String parentType); static void createIndex(String url, String indexName); static void ensureIndexAndTypeForAnnotation(Annotation annotation, Boolean createIndexIfNotFound); static String buildIndexNameFromAnnotation(final Annotation annotation); static String getIssueTypeFromAnnotation(Annotation annotation); @SuppressWarnings("unchecked") static List<Map<String, String>> getDataFromES(final String url, String dataSource, String entityType,
            Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
            final HashMultimap<String, Object> shouldFilter, List<String> fields, long from, long size); static String convertAttributetoKeyword(String attributeName); static Map<String, String> getDocumentForId(String index, String targetType, String _id); static Boolean publishMetrics(Map<String, Object> evalResults,String type); static int getESPort(); static String getESHost(); static Boolean doESPublish(Map<String, Object> evalResults, String indexName, String type); static Boolean doESUpdate(String docId,Map<String, Object> evalResults, String indexName, String type); static String createKeyword(final String key);  }