@Test public void identifierAndWeightedElements() { ResourceRecordSet<CNAMEData> rrs = ResourceRecordSet.<CNAMEData>builder() .name("www.denominator.io.") .type("CNAME") .qualifier("foobar") .add(CNAMEData.create("dom1.foo.com.")) .weighted(Weighted.create(1)).build(); assertThat(EncodeChanges.apply(rrs)) .isXmlEqualTo("<ResourceRecordSet>\n" + " <Name>www.denominator.io.</Name>\n" + " <Type>CNAME</Type>\n" + " <SetIdentifier>foobar</SetIdentifier>\n" + " <Weight>1</Weight>\n" + " <TTL>300</TTL>\n" + " <ResourceRecords>\n" + " <ResourceRecord>\n" + " <Value>dom1.foo.com.</Value>\n" + " </ResourceRecord>\n" + " </ResourceRecords>\n" + "</ResourceRecordSet>"); }
static String apply(ResourceRecordSet<?> rrs) { StringBuilder builder = new StringBuilder().append("<ResourceRecordSet>"); builder.append("<Name>").append(rrs.name()).append("</Name>"); builder.append("<Type>").append(rrs.type()).append("</Type>"); if (rrs.qualifier() != null) { builder.append("<SetIdentifier>") .append(rrs.qualifier()) .append("</SetIdentifier>"); } if (rrs.weighted() != null) { builder.append("<Weight>").append(rrs.weighted().weight()).append("</Weight>"); } if (rrs.records().size() == 1 && rrs.records().get(0).containsKey("HostedZoneId")) { builder.append("<AliasTarget>"); Map<String, Object> aliasTarget = rrs.records().get(0); for (String attribute : new String[]{"HostedZoneId", "DNSName"}) { builder.append('<').append(attribute).append('>'); builder.append( checkNotNull(aliasTarget.get(attribute), "missing %s in alias target %s", attribute, rrs)); builder.append("</").append(attribute).append('>'); } builder.append("<EvaluateTargetHealth>false</EvaluateTargetHealth>"); builder.append("</AliasTarget>"); } else { builder.append("<TTL>").append(rrs.ttl() == null ? 300 : rrs.ttl()).append("</TTL>"); builder.append("<ResourceRecords>"); for (Map<String, Object> data : rrs.records()) { String textFormat = join(' ', data.values().toArray()); if ("SPF".equals(rrs.type()) || "TXT".equals(rrs.type())) { textFormat = format("\"%s\"", textFormat); } builder.append("<ResourceRecord>").append("<Value>").append(textFormat).append("</Value>") .append("</ResourceRecord>"); } builder.append("</ResourceRecords>"); } return builder.append("</ResourceRecordSet>").toString(); }
EncodeChanges implements Encoder { static String apply(ResourceRecordSet<?> rrs) { StringBuilder builder = new StringBuilder().append("<ResourceRecordSet>"); builder.append("<Name>").append(rrs.name()).append("</Name>"); builder.append("<Type>").append(rrs.type()).append("</Type>"); if (rrs.qualifier() != null) { builder.append("<SetIdentifier>") .append(rrs.qualifier()) .append("</SetIdentifier>"); } if (rrs.weighted() != null) { builder.append("<Weight>").append(rrs.weighted().weight()).append("</Weight>"); } if (rrs.records().size() == 1 && rrs.records().get(0).containsKey("HostedZoneId")) { builder.append("<AliasTarget>"); Map<String, Object> aliasTarget = rrs.records().get(0); for (String attribute : new String[]{"HostedZoneId", "DNSName"}) { builder.append('<').append(attribute).append('>'); builder.append( checkNotNull(aliasTarget.get(attribute), "missing %s in alias target %s", attribute, rrs)); builder.append("</").append(attribute).append('>'); } builder.append("<EvaluateTargetHealth>false</EvaluateTargetHealth>"); builder.append("</AliasTarget>"); } else { builder.append("<TTL>").append(rrs.ttl() == null ? 300 : rrs.ttl()).append("</TTL>"); builder.append("<ResourceRecords>"); for (Map<String, Object> data : rrs.records()) { String textFormat = join(' ', data.values().toArray()); if ("SPF".equals(rrs.type()) || "TXT".equals(rrs.type())) { textFormat = format("\"%s\"", textFormat); } builder.append("<ResourceRecord>").append("<Value>").append(textFormat).append("</Value>") .append("</ResourceRecord>"); } builder.append("</ResourceRecords>"); } return builder.append("</ResourceRecordSet>").toString(); } }
EncodeChanges implements Encoder { static String apply(ResourceRecordSet<?> rrs) { StringBuilder builder = new StringBuilder().append("<ResourceRecordSet>"); builder.append("<Name>").append(rrs.name()).append("</Name>"); builder.append("<Type>").append(rrs.type()).append("</Type>"); if (rrs.qualifier() != null) { builder.append("<SetIdentifier>") .append(rrs.qualifier()) .append("</SetIdentifier>"); } if (rrs.weighted() != null) { builder.append("<Weight>").append(rrs.weighted().weight()).append("</Weight>"); } if (rrs.records().size() == 1 && rrs.records().get(0).containsKey("HostedZoneId")) { builder.append("<AliasTarget>"); Map<String, Object> aliasTarget = rrs.records().get(0); for (String attribute : new String[]{"HostedZoneId", "DNSName"}) { builder.append('<').append(attribute).append('>'); builder.append( checkNotNull(aliasTarget.get(attribute), "missing %s in alias target %s", attribute, rrs)); builder.append("</").append(attribute).append('>'); } builder.append("<EvaluateTargetHealth>false</EvaluateTargetHealth>"); builder.append("</AliasTarget>"); } else { builder.append("<TTL>").append(rrs.ttl() == null ? 300 : rrs.ttl()).append("</TTL>"); builder.append("<ResourceRecords>"); for (Map<String, Object> data : rrs.records()) { String textFormat = join(' ', data.values().toArray()); if ("SPF".equals(rrs.type()) || "TXT".equals(rrs.type())) { textFormat = format("\"%s\"", textFormat); } builder.append("<ResourceRecord>").append("<Value>").append(textFormat).append("</Value>") .append("</ResourceRecord>"); } builder.append("</ResourceRecords>"); } return builder.append("</ResourceRecordSet>").toString(); }  }
EncodeChanges implements Encoder { static String apply(ResourceRecordSet<?> rrs) { StringBuilder builder = new StringBuilder().append("<ResourceRecordSet>"); builder.append("<Name>").append(rrs.name()).append("</Name>"); builder.append("<Type>").append(rrs.type()).append("</Type>"); if (rrs.qualifier() != null) { builder.append("<SetIdentifier>") .append(rrs.qualifier()) .append("</SetIdentifier>"); } if (rrs.weighted() != null) { builder.append("<Weight>").append(rrs.weighted().weight()).append("</Weight>"); } if (rrs.records().size() == 1 && rrs.records().get(0).containsKey("HostedZoneId")) { builder.append("<AliasTarget>"); Map<String, Object> aliasTarget = rrs.records().get(0); for (String attribute : new String[]{"HostedZoneId", "DNSName"}) { builder.append('<').append(attribute).append('>'); builder.append( checkNotNull(aliasTarget.get(attribute), "missing %s in alias target %s", attribute, rrs)); builder.append("</").append(attribute).append('>'); } builder.append("<EvaluateTargetHealth>false</EvaluateTargetHealth>"); builder.append("</AliasTarget>"); } else { builder.append("<TTL>").append(rrs.ttl() == null ? 300 : rrs.ttl()).append("</TTL>"); builder.append("<ResourceRecords>"); for (Map<String, Object> data : rrs.records()) { String textFormat = join(' ', data.values().toArray()); if ("SPF".equals(rrs.type()) || "TXT".equals(rrs.type())) { textFormat = format("\"%s\"", textFormat); } builder.append("<ResourceRecord>").append("<Value>").append(textFormat).append("</Value>") .append("</ResourceRecord>"); } builder.append("</ResourceRecords>"); } return builder.append("</ResourceRecordSet>").toString(); }  @Override void encode(Object object, Type bodyType, RequestTemplate template); }
EncodeChanges implements Encoder { static String apply(ResourceRecordSet<?> rrs) { StringBuilder builder = new StringBuilder().append("<ResourceRecordSet>"); builder.append("<Name>").append(rrs.name()).append("</Name>"); builder.append("<Type>").append(rrs.type()).append("</Type>"); if (rrs.qualifier() != null) { builder.append("<SetIdentifier>") .append(rrs.qualifier()) .append("</SetIdentifier>"); } if (rrs.weighted() != null) { builder.append("<Weight>").append(rrs.weighted().weight()).append("</Weight>"); } if (rrs.records().size() == 1 && rrs.records().get(0).containsKey("HostedZoneId")) { builder.append("<AliasTarget>"); Map<String, Object> aliasTarget = rrs.records().get(0); for (String attribute : new String[]{"HostedZoneId", "DNSName"}) { builder.append('<').append(attribute).append('>'); builder.append( checkNotNull(aliasTarget.get(attribute), "missing %s in alias target %s", attribute, rrs)); builder.append("</").append(attribute).append('>'); } builder.append("<EvaluateTargetHealth>false</EvaluateTargetHealth>"); builder.append("</AliasTarget>"); } else { builder.append("<TTL>").append(rrs.ttl() == null ? 300 : rrs.ttl()).append("</TTL>"); builder.append("<ResourceRecords>"); for (Map<String, Object> data : rrs.records()) { String textFormat = join(' ', data.values().toArray()); if ("SPF".equals(rrs.type()) || "TXT".equals(rrs.type())) { textFormat = format("\"%s\"", textFormat); } builder.append("<ResourceRecord>").append("<Value>").append(textFormat).append("</Value>") .append("</ResourceRecord>"); } builder.append("</ResourceRecords>"); } return builder.append("</ResourceRecordSet>").toString(); }  @Override void encode(Object object, Type bodyType, RequestTemplate template);  }