ResourceDescriptionTemplateProcessor implements Function<AddressTemplate, AddressTemplate> { @Override public AddressTemplate apply(AddressTemplate template) { AddressTemplate modified = AddressTemplate.ROOT; if (template != null && !AddressTemplate.ROOT.equals(template)) { List<String[]> segments = stream(template.spliterator(), false) .map(segment -> { if (segment.contains("=")) { return Splitter.on('=') .omitEmptyStrings() .trimResults() .limit(2) .splitToList(segment) .toArray(new String[2]); } return new String[]{segment, null}; }) .collect(toList()); StringBuilder builder = new StringBuilder(); SegmentProcessor.process(segments, segment -> { builder.append("/").append(segment[0]); if (segment[1] != null) { builder.append("=").append(segment[1]); } }); modified = AddressTemplate.of(builder.toString()); } return modified; }  @Override AddressTemplate apply(AddressTemplate template);  }
@Test public void nil() throws Exception { AddressTemplate result = processor.apply(null); assertEquals(AddressTemplate.ROOT, result); }
@Test public void empty() throws Exception { AddressTemplate input = AddressTemplate.of(""); AddressTemplate result = processor.apply(input); assertEquals(AddressTemplate.ROOT, result); }
@Test public void simple() throws Exception { AddressTemplate input = AddressTemplate.of("/foo=bar"); AddressTemplate expected = AddressTemplate.of("/foo=bar"); AddressTemplate result = processor.apply(input); assertEquals(expected, result); }
@Test public void host() throws Exception { AddressTemplate input = AddressTemplate.of("/host=master"); AddressTemplate expected = AddressTemplate.of("/host=master"); AddressTemplate result = processor.apply(input); assertEquals(expected, result); }
@Test public void host2() throws Exception { AddressTemplate input = AddressTemplate.of("/host=master/subsystem=jmx"); AddressTemplate expected = AddressTemplate.of("/host=*/subsystem=jmx"); AddressTemplate result = processor.apply(input); assertEquals(expected, result); }
@Test public void server() throws Exception { AddressTemplate input = AddressTemplate.of("/host=master/server=server-one"); AddressTemplate expected = AddressTemplate.of("/host=*/server=*"); AddressTemplate result = processor.apply(input); assertEquals(expected, result); }
@Test public void server2() throws Exception { AddressTemplate input = AddressTemplate.of( "/host=master/server=server-one/subsystem=datasources/data-source=*"); AddressTemplate expected = AddressTemplate.of("/host=*/server=*/subsystem=datasources/data-source=*"); AddressTemplate result = processor.apply(input); assertEquals(expected, result); }
@Test public void serverConfig() throws Exception { AddressTemplate input = AddressTemplate.of("/host=master/server-config=server-one"); AddressTemplate expected = AddressTemplate.of("/host=*/server-config=*"); AddressTemplate result = processor.apply(input); assertEquals(expected, result); }
@Test public void serverConfig2() throws Exception { AddressTemplate input = AddressTemplate.of("/host=master/server-config=server-one/jvm=*"); AddressTemplate expected = AddressTemplate.of("/host=*/server-config=*/jvm=*"); AddressTemplate result = processor.apply(input); assertEquals(expected, result); }
@Test public void serverGroup() throws Exception { AddressTemplate input = AddressTemplate.of("/server-group=main-server-group"); AddressTemplate expected = AddressTemplate.of("/server-group=*"); AddressTemplate result = processor.apply(input); assertEquals(expected, result); }
@Test public void serverGroup2() throws Exception { AddressTemplate input = AddressTemplate.of("/server-group=main-server-group/system-property=*"); AddressTemplate expected = AddressTemplate.of("/server-group=*/system-property=*"); AddressTemplate result = processor.apply(input); assertEquals(expected, result); }
@Test public void profile() throws Exception { AddressTemplate input = AddressTemplate.of("/profile=full"); AddressTemplate expected = AddressTemplate.of("/profile=*"); AddressTemplate result = processor.apply(input); assertEquals(expected, result); }
@Test public void profile2() throws Exception { AddressTemplate input = AddressTemplate.of("/profile=full/subsystem=mail"); AddressTemplate expected = AddressTemplate.of("/profile=*/subsystem=mail"); AddressTemplate result = processor.apply(input); assertEquals(expected, result); }
@Test public void hostInTheMiddle() throws Exception { AddressTemplate input = AddressTemplate.of("/profile=full/subsystem=undertow/server=*/host=*/location=*"); AddressTemplate expected = AddressTemplate.of("/profile=*/subsystem=undertow/server=*/host=*/location=*"); AddressTemplate result = processor.apply(input); assertEquals(expected, result); }
@Test public void serverAtTheEnd() throws Exception { AddressTemplate input = AddressTemplate.of("/profile=full/subsystem=mail/mail-session=default/server=imap"); AddressTemplate expected = AddressTemplate.of("/profile=*/subsystem=mail/mail-session=default/server=imap"); AddressTemplate result = processor.apply(input); assertEquals(expected, result); }