AbstractConfig implements Config { @Override public void setAttribute(String name, String value, ConfigSource source) { Object attObjectValue; Class valueType = getAttributeType(name); try { if (valueType.equals(String.class)) { attObjectValue = value; } else if (valueType.equals(String[].class)) { if (StringUtils.isBlank(value)) { attObjectValue = new String[0]; } else { attObjectValue = value.split(","); } } else if (valueType.equals(Integer.class)) { attObjectValue = Integer.valueOf(value); } else if (valueType.equals(Long.class)) { attObjectValue = Long.valueOf(value); } else if (valueType.equals(Boolean.class)) { attObjectValue = Boolean.valueOf(value); } else if (valueType.equals(File.class)) { attObjectValue = new File(value); } else if (valueType.equals(int[].class)) { int minus = value.indexOf('-'); if (minus <= 0) { throw new IllegalArgumentException( "expected a setting in the form X-Y but found no dash for attribute " + name); } int[] tempValue = new int[2]; tempValue[0] = Integer.valueOf(value.substring(0, minus)); tempValue[1] = Integer.valueOf(value.substring(minus + 1)); attObjectValue = tempValue; } else if (valueType.equals(InetAddress.class)) { try { attObjectValue = InetAddress.getByName(value); } catch (UnknownHostException ex) { throw new IllegalArgumentException( String.format("%s value %s must be a valid host name. %s", name, value, ex.toString())); } } else if (valueType.equals(FlowControlParams.class)) { String[] values = value.split(","); if (values.length != 3) { throw new IllegalArgumentException( String.format("%s value %s must have three elements separated by commas", name, value)); } int allowance; float threshold; int waitTime; try { allowance = Integer.parseInt(values[0].trim()); threshold = Float.valueOf(values[1].trim()); waitTime = Integer.parseInt(values[2].trim()); } catch (NumberFormatException e) { throw new IllegalArgumentException( String.format("%s value %s must be composed of an integer, a float, and an integer", name, value)); } attObjectValue = new FlowControlParams(allowance, threshold, waitTime); } else if (valueType.isArray() && SecurableCommunicationChannel.class.equals(valueType.getComponentType())) { attObjectValue = commaDelimitedStringToSecurableCommunicationChannels(value); } else { throw new InternalGemFireException( String.format("unhandled attribute type %s for %s.", valueType, name)); } } catch (NumberFormatException ex) { throw new IllegalArgumentException(String.format("%s value %s must be a number.", name, value)); } setAttributeObject(name, attObjectValue, source); }  @Override String toString(); @Override String toLoggerString(); Map<String, String> getConfigPropsFromSource(ConfigSource source); Map<String, String> getConfigPropsDefinedUsingFiles(); @Override Properties toProperties(); @Override void toFile(File file); @Override boolean sameAs(Config other); @Override String getAttribute(String name); @Override ConfigSource getAttributeSource(String name); @Override void setAttribute(String name, String value, ConfigSource source); @Override String getAttributeDescription(String name);  }
@Test public void setAttributeForStringArrayTypeWithEmpty() { abstractConfig.setAttribute(stringArrayAttributeName, "", source); verify(abstractConfig).setAttributeObject(stringArrayAttributeName, new String[0], source); }
@Test public void setAttributeForStringArrayTypeWithNull() { abstractConfig.setAttribute(stringArrayAttributeName, null, source); verify(abstractConfig).setAttributeObject(stringArrayAttributeName, new String[0], source); }
@Test public void setAttributeForStringArrayTypeWithNoCommas() { abstractConfig.setAttribute(stringArrayAttributeName, "value", source); verify(abstractConfig).setAttributeObject(stringArrayAttributeName, new String[] {"value"}, source); }
@Test public void setAttributeForStringArrayTypeWithNestedComma() { abstractConfig.setAttribute(stringArrayAttributeName, "value1,value2", source); verify(abstractConfig).setAttributeObject(stringArrayAttributeName, new String[] {"value1", "value2"}, source); }
@Test public void setAttributeForStringArrayTypeStartingWithComma() { abstractConfig.setAttribute(stringArrayAttributeName, ",value", source); verify(abstractConfig).setAttributeObject(stringArrayAttributeName, new String[] {"", "value"}, source); }
@Test public void setAttributeForStringArrayTypeEndingWithComma() { abstractConfig.setAttribute(stringArrayAttributeName, "value,", source); verify(abstractConfig).setAttributeObject(stringArrayAttributeName, new String[] {"value"}, source); }