public void testRoundTrip() throws Exception
{
Set<ServiceBindingSet> input = new HashSet<ServiceBindingSet>();
Set<ServiceBindingMetadata> overrideInput = new HashSet<ServiceBindingMetadata>();
ServiceBindingMetadata complete = new ServiceBindingMetadata("complete", "binding", "host", 10, true, true);
complete.setDescription("desc");
complete.setServiceBindingValueSource(new StringReplacementServiceBindingValueSourceImpl());
complete.setServiceBindingValueSourceConfig(new StringReplacementServiceBindingValueSourceConfig());
overrideInput.add(complete);
ServiceBindingMetadata nulls = new ServiceBindingMetadata("nulls", null, null, 20);
overrideInput.add(nulls);
ServiceBindingSet withOverride = new ServiceBindingSet("withOverride", "localhost", 1000, overrideInput);
input.add(withOverride);
ServiceBindingSet noOverride = new ServiceBindingSet("noOverride", "localhost", 900);
input.add(noOverride);
ServiceBindingSetMapper mapper = new ServiceBindingSetMapper();
MetaValue wrapped = mapper.createMetaValue(null, input);
Set<ServiceBindingSet> output = mapper.unwrapMetaValue(wrapped);
for (ServiceBindingSet outputSet : output)
{
if ("withOverride".equals(outputSet.getName()))
{
Set<ServiceBindingMetadata> overrideOutput = outputSet.getOverrideBindings();
assertNotNull("has overrideOutput", overrideOutput);
assertEquals("localhost", outputSet.getDefaultHostName());
assertEquals(1000, outputSet.getPortOffset());
for (ServiceBindingMetadata md : overrideOutput)
{
if ("complete".equals(md.getServiceName()))
{
assertEquals(complete.getFullyQualifiedName(), md.getFullyQualifiedName());
assertEquals(complete.getBindingName(), md.getBindingName());
assertEquals(complete.getDescription(), md.getDescription());
assertEquals(complete.getHostName(), md.getHostName());
assertEquals(complete.getPort(), md.getPort());
assertEquals(complete.isFixedHostName(), md.isFixedHostName());
assertEquals(complete.isFixedPort(), md.isFixedPort());
// We expect null for the following, but if the impl changes these can change
assertNull(md.getServiceBindingValueSourceClassName());
assertNull(md.getServiceBindingValueSourceConfig());
}
else if ("nulls".equals(md.getServiceName()))
{
assertEquals(nulls.getFullyQualifiedName(), md.getFullyQualifiedName());
assertNull(md.getBindingName());
assertNull(md.getDescription());
assertNull(md.getHostName());
assertEquals(nulls.getPort(), md.getPort());
assertFalse(md.isFixedHostName());
assertFalse(md.isFixedPort());
assertNull(md.getServiceBindingValueSourceClassName());
assertNull(md.getServiceBindingValueSourceConfig());