@Test(expected = IllegalArgumentException.class) public void valueMustBeGiven() { Dimension dimension = mapEntryToDimension.apply(ImmutableMap.of( "name", (Object) "some_name", "no_value", (Object)"some_value")); assertThat(dimension.getName()).isEqualTo("some_name"); assertThat(dimension.getValue()).isEqualTo("some_value"); }
@Nullable @Override public Dimension apply(Map<String, Object> dimension) { String name = null; String value = null; if (dimension.containsKey(NAME)) { name = String.valueOf(dimension.get(NAME)); } if (dimension.containsKey(VALUE)) { value = String.valueOf(dimension.get(VALUE)); } if (name == null || value == null) { throw new IllegalArgumentException(format("Incomplete dimension: Missing non-null '%s' and '%s' in '%s'", NAME, VALUE, dimension.toString())); } if (value.startsWith("$")) { try { Method m = EC2MetadataUtils.class.getMethod("get" + value.substring(1)); value = String.valueOf(m.invoke(null)); } catch (NoSuchMethodException e) { log.warn("Could not resolve {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e); } catch (IllegalAccessException e) { log.warn("Could not load {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e); } catch (InvocationTargetException e) { log.warn("Could not retrieve {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e); } } return new Dimension().withName(name).withValue(value); }
MapEntryToDimension implements Function<Map<String, Object>, Dimension> { @Nullable @Override public Dimension apply(Map<String, Object> dimension) { String name = null; String value = null; if (dimension.containsKey(NAME)) { name = String.valueOf(dimension.get(NAME)); } if (dimension.containsKey(VALUE)) { value = String.valueOf(dimension.get(VALUE)); } if (name == null || value == null) { throw new IllegalArgumentException(format("Incomplete dimension: Missing non-null '%s' and '%s' in '%s'", NAME, VALUE, dimension.toString())); } if (value.startsWith("$")) { try { Method m = EC2MetadataUtils.class.getMethod("get" + value.substring(1)); value = String.valueOf(m.invoke(null)); } catch (NoSuchMethodException e) { log.warn("Could not resolve {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e); } catch (IllegalAccessException e) { log.warn("Could not load {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e); } catch (InvocationTargetException e) { log.warn("Could not retrieve {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e); } } return new Dimension().withName(name).withValue(value); } }
MapEntryToDimension implements Function<Map<String, Object>, Dimension> { @Nullable @Override public Dimension apply(Map<String, Object> dimension) { String name = null; String value = null; if (dimension.containsKey(NAME)) { name = String.valueOf(dimension.get(NAME)); } if (dimension.containsKey(VALUE)) { value = String.valueOf(dimension.get(VALUE)); } if (name == null || value == null) { throw new IllegalArgumentException(format("Incomplete dimension: Missing non-null '%s' and '%s' in '%s'", NAME, VALUE, dimension.toString())); } if (value.startsWith("$")) { try { Method m = EC2MetadataUtils.class.getMethod("get" + value.substring(1)); value = String.valueOf(m.invoke(null)); } catch (NoSuchMethodException e) { log.warn("Could not resolve {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e); } catch (IllegalAccessException e) { log.warn("Could not load {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e); } catch (InvocationTargetException e) { log.warn("Could not retrieve {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e); } } return new Dimension().withName(name).withValue(value); }  }
MapEntryToDimension implements Function<Map<String, Object>, Dimension> { @Nullable @Override public Dimension apply(Map<String, Object> dimension) { String name = null; String value = null; if (dimension.containsKey(NAME)) { name = String.valueOf(dimension.get(NAME)); } if (dimension.containsKey(VALUE)) { value = String.valueOf(dimension.get(VALUE)); } if (name == null || value == null) { throw new IllegalArgumentException(format("Incomplete dimension: Missing non-null '%s' and '%s' in '%s'", NAME, VALUE, dimension.toString())); } if (value.startsWith("$")) { try { Method m = EC2MetadataUtils.class.getMethod("get" + value.substring(1)); value = String.valueOf(m.invoke(null)); } catch (NoSuchMethodException e) { log.warn("Could not resolve {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e); } catch (IllegalAccessException e) { log.warn("Could not load {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e); } catch (InvocationTargetException e) { log.warn("Could not retrieve {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e); } } return new Dimension().withName(name).withValue(value); }  @Nullable @Override Dimension apply(Map<String, Object> dimension); }
MapEntryToDimension implements Function<Map<String, Object>, Dimension> { @Nullable @Override public Dimension apply(Map<String, Object> dimension) { String name = null; String value = null; if (dimension.containsKey(NAME)) { name = String.valueOf(dimension.get(NAME)); } if (dimension.containsKey(VALUE)) { value = String.valueOf(dimension.get(VALUE)); } if (name == null || value == null) { throw new IllegalArgumentException(format("Incomplete dimension: Missing non-null '%s' and '%s' in '%s'", NAME, VALUE, dimension.toString())); } if (value.startsWith("$")) { try { Method m = EC2MetadataUtils.class.getMethod("get" + value.substring(1)); value = String.valueOf(m.invoke(null)); } catch (NoSuchMethodException e) { log.warn("Could not resolve {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e); } catch (IllegalAccessException e) { log.warn("Could not load {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e); } catch (InvocationTargetException e) { log.warn("Could not retrieve {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e); } } return new Dimension().withName(name).withValue(value); }  @Nullable @Override Dimension apply(Map<String, Object> dimension);  }