@Test public void testFormatMultiValueSwitches() { List<String> values = CollectionUtil.newList("foo", "bar", "baz"); final String expectedMultivalueArgument = "\"foo,bar,baz\""; List<NativeAttribute> multivalueAttributes = CollectionUtil.<NativeAttribute> newList(); for (NativeAttribute it : NativeAttribute.values()) { if (!it.isSingleValue()) { multivalueAttributes.add(it); } } SolarisEntry.Builder bldr = new SolarisEntry.Builder("foo"); Map<NativeAttribute, String> switches = new HashMap<NativeAttribute, String>(); for (NativeAttribute it : multivalueAttributes) { bldr.addAttr(it, values); switches.put(it, COMMAND_LINE_SWITCH_MARKER + it.getName()); } String generatedCommandLineSwitches = CommandSwitches.formatCommandSwitches(bldr.build(), getConnection(), switches); String[] switchElements = generatedCommandLineSwitches.split(COMMAND_LINE_SWITCH_MARKER); for (NativeAttribute attr : multivalueAttributes) { String foundCluster = searchCluster(attr, switchElements); assertNotNull("attribute '" + attr.getName() + "' is missing", foundCluster); assertTrue(foundCluster.contains(expectedMultivalueArgument)); } }
public static String formatCommandSwitches(SolarisEntry entry, SolarisConnection conn, Map<NativeAttribute, String> switches) { StringBuilder buffer = new StringBuilder(); for (Attribute attr : entry.getAttributeSet()) { NativeAttribute nAttrName = NativeAttribute.forAttributeName(attr.getName()); List<Object> values = attr.getValue(); if (nAttrName.isSingleValue()) { if (values == null) { throw new ConnectorException(String.format( "Attribute '%s' has a null value, expecting singleValue", attr .getName())); } Object value = AttributeUtil.getSingleValue(attr); if (value == null || StringUtil.isBlank(value.toString()) || values.isEmpty()) { if (nAttrName == NativeAttribute.USER_INACTIVE) { values = CollectionUtil.newList((Object) "-1"); } else if (PASS_NULL_PARAMS.contains(nAttrName)) { values = CollectionUtil.newList((Object) ""); } } } else { if (values == null) { values = CollectionUtil.newList(); } } String cmdSwitchForAttr = switches.get(nAttrName); if (cmdSwitchForAttr == null) { continue; } switch (nAttrName) { case LOCK: buffer.append(cmdSwitchForAttr).append(" "); break; case PWSTAT: boolean isPasswordForceChange = (Boolean) values.get(0); if (isPasswordForceChange) { buffer.append(cmdSwitchForAttr).append(" "); } else { throw new ConnectorException( "Solaris allows to set 'force_change' attribute only to 'true' value. Anything else is invalid and will be ignored."); } break; case USER_EXPIRE: buffer.append(cmdSwitchForAttr).append(" "); buffer.append("\""); if (values == null || values.isEmpty() || values.get(0) == null) { } else { Long value = AttrUtil.toLong(values.get(0)); if (value != null) { buffer.append(conn.getModeDriver().formatDate(value)); } } buffer.append("\" "); break; default: buffer.append(cmdSwitchForAttr).append(" "); buffer.append("\""); boolean first = true; for (Object itValue : values) { if (!first) { buffer.append(","); } buffer.append(itValue.toString()); first = false; } buffer.append("\" "); break; } } return buffer.toString().trim(); }
CommandSwitches { public static String formatCommandSwitches(SolarisEntry entry, SolarisConnection conn, Map<NativeAttribute, String> switches) { StringBuilder buffer = new StringBuilder(); for (Attribute attr : entry.getAttributeSet()) { NativeAttribute nAttrName = NativeAttribute.forAttributeName(attr.getName()); List<Object> values = attr.getValue(); if (nAttrName.isSingleValue()) { if (values == null) { throw new ConnectorException(String.format( "Attribute '%s' has a null value, expecting singleValue", attr .getName())); } Object value = AttributeUtil.getSingleValue(attr); if (value == null || StringUtil.isBlank(value.toString()) || values.isEmpty()) { if (nAttrName == NativeAttribute.USER_INACTIVE) { values = CollectionUtil.newList((Object) "-1"); } else if (PASS_NULL_PARAMS.contains(nAttrName)) { values = CollectionUtil.newList((Object) ""); } } } else { if (values == null) { values = CollectionUtil.newList(); } } String cmdSwitchForAttr = switches.get(nAttrName); if (cmdSwitchForAttr == null) { continue; } switch (nAttrName) { case LOCK: buffer.append(cmdSwitchForAttr).append(" "); break; case PWSTAT: boolean isPasswordForceChange = (Boolean) values.get(0); if (isPasswordForceChange) { buffer.append(cmdSwitchForAttr).append(" "); } else { throw new ConnectorException( "Solaris allows to set 'force_change' attribute only to 'true' value. Anything else is invalid and will be ignored."); } break; case USER_EXPIRE: buffer.append(cmdSwitchForAttr).append(" "); buffer.append("\""); if (values == null || values.isEmpty() || values.get(0) == null) { } else { Long value = AttrUtil.toLong(values.get(0)); if (value != null) { buffer.append(conn.getModeDriver().formatDate(value)); } } buffer.append("\" "); break; default: buffer.append(cmdSwitchForAttr).append(" "); buffer.append("\""); boolean first = true; for (Object itValue : values) { if (!first) { buffer.append(","); } buffer.append(itValue.toString()); first = false; } buffer.append("\" "); break; } } return buffer.toString().trim(); } }
CommandSwitches { public static String formatCommandSwitches(SolarisEntry entry, SolarisConnection conn, Map<NativeAttribute, String> switches) { StringBuilder buffer = new StringBuilder(); for (Attribute attr : entry.getAttributeSet()) { NativeAttribute nAttrName = NativeAttribute.forAttributeName(attr.getName()); List<Object> values = attr.getValue(); if (nAttrName.isSingleValue()) { if (values == null) { throw new ConnectorException(String.format( "Attribute '%s' has a null value, expecting singleValue", attr .getName())); } Object value = AttributeUtil.getSingleValue(attr); if (value == null || StringUtil.isBlank(value.toString()) || values.isEmpty()) { if (nAttrName == NativeAttribute.USER_INACTIVE) { values = CollectionUtil.newList((Object) "-1"); } else if (PASS_NULL_PARAMS.contains(nAttrName)) { values = CollectionUtil.newList((Object) ""); } } } else { if (values == null) { values = CollectionUtil.newList(); } } String cmdSwitchForAttr = switches.get(nAttrName); if (cmdSwitchForAttr == null) { continue; } switch (nAttrName) { case LOCK: buffer.append(cmdSwitchForAttr).append(" "); break; case PWSTAT: boolean isPasswordForceChange = (Boolean) values.get(0); if (isPasswordForceChange) { buffer.append(cmdSwitchForAttr).append(" "); } else { throw new ConnectorException( "Solaris allows to set 'force_change' attribute only to 'true' value. Anything else is invalid and will be ignored."); } break; case USER_EXPIRE: buffer.append(cmdSwitchForAttr).append(" "); buffer.append("\""); if (values == null || values.isEmpty() || values.get(0) == null) { } else { Long value = AttrUtil.toLong(values.get(0)); if (value != null) { buffer.append(conn.getModeDriver().formatDate(value)); } } buffer.append("\" "); break; default: buffer.append(cmdSwitchForAttr).append(" "); buffer.append("\""); boolean first = true; for (Object itValue : values) { if (!first) { buffer.append(","); } buffer.append(itValue.toString()); first = false; } buffer.append("\" "); break; } } return buffer.toString().trim(); }  }
CommandSwitches { public static String formatCommandSwitches(SolarisEntry entry, SolarisConnection conn, Map<NativeAttribute, String> switches) { StringBuilder buffer = new StringBuilder(); for (Attribute attr : entry.getAttributeSet()) { NativeAttribute nAttrName = NativeAttribute.forAttributeName(attr.getName()); List<Object> values = attr.getValue(); if (nAttrName.isSingleValue()) { if (values == null) { throw new ConnectorException(String.format( "Attribute '%s' has a null value, expecting singleValue", attr .getName())); } Object value = AttributeUtil.getSingleValue(attr); if (value == null || StringUtil.isBlank(value.toString()) || values.isEmpty()) { if (nAttrName == NativeAttribute.USER_INACTIVE) { values = CollectionUtil.newList((Object) "-1"); } else if (PASS_NULL_PARAMS.contains(nAttrName)) { values = CollectionUtil.newList((Object) ""); } } } else { if (values == null) { values = CollectionUtil.newList(); } } String cmdSwitchForAttr = switches.get(nAttrName); if (cmdSwitchForAttr == null) { continue; } switch (nAttrName) { case LOCK: buffer.append(cmdSwitchForAttr).append(" "); break; case PWSTAT: boolean isPasswordForceChange = (Boolean) values.get(0); if (isPasswordForceChange) { buffer.append(cmdSwitchForAttr).append(" "); } else { throw new ConnectorException( "Solaris allows to set 'force_change' attribute only to 'true' value. Anything else is invalid and will be ignored."); } break; case USER_EXPIRE: buffer.append(cmdSwitchForAttr).append(" "); buffer.append("\""); if (values == null || values.isEmpty() || values.get(0) == null) { } else { Long value = AttrUtil.toLong(values.get(0)); if (value != null) { buffer.append(conn.getModeDriver().formatDate(value)); } } buffer.append("\" "); break; default: buffer.append(cmdSwitchForAttr).append(" "); buffer.append("\""); boolean first = true; for (Object itValue : values) { if (!first) { buffer.append(","); } buffer.append(itValue.toString()); first = false; } buffer.append("\" "); break; } } return buffer.toString().trim(); }  static String formatCommandSwitches(SolarisEntry entry, SolarisConnection conn,
            Map<NativeAttribute, String> switches); }
CommandSwitches { public static String formatCommandSwitches(SolarisEntry entry, SolarisConnection conn, Map<NativeAttribute, String> switches) { StringBuilder buffer = new StringBuilder(); for (Attribute attr : entry.getAttributeSet()) { NativeAttribute nAttrName = NativeAttribute.forAttributeName(attr.getName()); List<Object> values = attr.getValue(); if (nAttrName.isSingleValue()) { if (values == null) { throw new ConnectorException(String.format( "Attribute '%s' has a null value, expecting singleValue", attr .getName())); } Object value = AttributeUtil.getSingleValue(attr); if (value == null || StringUtil.isBlank(value.toString()) || values.isEmpty()) { if (nAttrName == NativeAttribute.USER_INACTIVE) { values = CollectionUtil.newList((Object) "-1"); } else if (PASS_NULL_PARAMS.contains(nAttrName)) { values = CollectionUtil.newList((Object) ""); } } } else { if (values == null) { values = CollectionUtil.newList(); } } String cmdSwitchForAttr = switches.get(nAttrName); if (cmdSwitchForAttr == null) { continue; } switch (nAttrName) { case LOCK: buffer.append(cmdSwitchForAttr).append(" "); break; case PWSTAT: boolean isPasswordForceChange = (Boolean) values.get(0); if (isPasswordForceChange) { buffer.append(cmdSwitchForAttr).append(" "); } else { throw new ConnectorException( "Solaris allows to set 'force_change' attribute only to 'true' value. Anything else is invalid and will be ignored."); } break; case USER_EXPIRE: buffer.append(cmdSwitchForAttr).append(" "); buffer.append("\""); if (values == null || values.isEmpty() || values.get(0) == null) { } else { Long value = AttrUtil.toLong(values.get(0)); if (value != null) { buffer.append(conn.getModeDriver().formatDate(value)); } } buffer.append("\" "); break; default: buffer.append(cmdSwitchForAttr).append(" "); buffer.append("\""); boolean first = true; for (Object itValue : values) { if (!first) { buffer.append(","); } buffer.append(itValue.toString()); first = false; } buffer.append("\" "); break; } } return buffer.toString().trim(); }  static String formatCommandSwitches(SolarisEntry entry, SolarisConnection conn,
            Map<NativeAttribute, String> switches);  }