EnrichmentObjectGet implements StellarFunction { @Override public Object apply(List<Object> args, Context context) throws ParseException { if(args.size() != 2) { throw new IllegalArgumentException("All parameters are mandatory, submit 'hdfs path', 'indicator'"); } if(!isInitialized()) { return null; } String path = (String) args.get(0); String indicator = (String) args.get(1); if(path == null || indicator == null) { return null; } Object value; try { Map cachedMap = (Map) objectCache.get(path); LOG.debug("Looking up value from object at path '{}' using indicator {}", path, indicator); value = cachedMap.get(indicator); } catch(ClassCastException e) { throw new ClassCastException(String.format("The object stored in HDFS at '%s' must be serialized in JSON format.", path)); } return value; }  @Override Object apply(List<Object> args, Context context); @SuppressWarnings("unchecked") @Override void initialize(Context context); @Override boolean isInitialized(); final static String ENRICHMENT_OBJECT_GET_SETTINGS; }
@Test public void restGetShouldThrownExceptionOnMissingParameter() { IllegalArgumentException e = assertThrows( IllegalArgumentException.class, () -> enrichmentObjectGet.apply(new ArrayList<>(), context)); assertTrue(e.getMessage().contains("All parameters are mandatory, submit 'hdfs path', 'indicator'")); }