ResourceDescriptionAddressProcessor implements Function<ResourceAddress, ResourceAddress> { @Override public ResourceAddress apply(ResourceAddress address) { ResourceAddress modified = new ResourceAddress(); if (address != null && !address.isEmpty()) { List<String[]> segments = address.asPropertyList().stream() .map(property -> new String[]{property.getName(), property.getValue().asString()}) .collect(toList()); SegmentProcessor.process(segments, segment -> modified.add(segment[0], segment[1])); } return modified; }  @Override ResourceAddress apply(ResourceAddress address);  }
@Test public void serverGroup2() throws Exception { ResourceAddress input = new ResourceAddress() .add("server-group", "main-server-group") .add("system-property", "*"); ResourceAddress expected = new ResourceAddress() .add("server-group", "*") .add("system-property", "*"); ResourceAddress result = processor.apply(input); assertEquals(expected, result); }
@Test public void profile() throws Exception { ResourceAddress input = new ResourceAddress() .add("profile", "full"); ResourceAddress expected = new ResourceAddress() .add("profile", "*"); ResourceAddress result = processor.apply(input); assertEquals(expected, result); }
@Test public void profile2() throws Exception { ResourceAddress input = new ResourceAddress() .add("profile", "full") .add("subsystem", "mail"); ResourceAddress expected = new ResourceAddress() .add("profile", "*") .add("subsystem", "mail"); ResourceAddress result = processor.apply(input); assertEquals(expected, result); }
@Test public void hostInTheMiddle() throws Exception { ResourceAddress input = new ResourceAddress() .add("profile", "full") .add("subsystem", "undertow") .add("server", "*") .add("host", "*") .add("location", "*"); ResourceAddress expected = new ResourceAddress() .add("profile", "*") .add("subsystem", "undertow") .add("server", "*") .add("host", "*") .add("location", "*"); ResourceAddress result = processor.apply(input); assertEquals(expected, result); }
@Test public void serverAtTheEnd() throws Exception { ResourceAddress input = new ResourceAddress() .add("profile", "full") .add("subsystem", "mail") .add("mail-session", "default") .add("server", "imap"); ResourceAddress expected = new ResourceAddress() .add("profile", "*") .add("subsystem", "mail") .add("mail-session", "default") .add("server", "imap"); ResourceAddress result = processor.apply(input); assertEquals(expected, result); }
@Test public void nil() throws Exception { ResourceAddress result = processor.apply(null); assertEquals(new ResourceAddress(), result); }
@Test public void empty() throws Exception { ResourceAddress input = new ResourceAddress(); ResourceAddress expected = new ResourceAddress(); ResourceAddress result = processor.apply(input); assertEquals(expected, result); }
@Test public void simple() throws Exception { ResourceAddress input = new ResourceAddress() .add("foo", "bar"); ResourceAddress expected = new ResourceAddress() .add("foo", "bar"); ResourceAddress result = processor.apply(input); assertEquals(expected, result); }
@Test public void host() throws Exception { ResourceAddress input = new ResourceAddress() .add("host", "master"); ResourceAddress expected = new ResourceAddress() .add("host", "master"); ResourceAddress result = processor.apply(input); assertEquals(expected, result); }
@Test public void host2() throws Exception { ResourceAddress input = new ResourceAddress() .add("host", "master") .add("subsystem", "jmx"); ResourceAddress expected = new ResourceAddress() .add("host", "*") .add("subsystem", "jmx"); ResourceAddress result = processor.apply(input); assertEquals(expected, result); }
@Test public void server() throws Exception { ResourceAddress input = new ResourceAddress() .add("host", "*") .add("server", "server-one"); ResourceAddress expected = new ResourceAddress() .add("host", "*") .add("server", "*"); ResourceAddress result = processor.apply(input); assertEquals(expected, result); }
@Test public void server2() throws Exception { ResourceAddress input = new ResourceAddress() .add("host", "*") .add("server", "server-one") .add("subsystem", "datasources") .add("data-source", "*"); ResourceAddress expected = new ResourceAddress() .add("host", "*") .add("server", "*") .add("subsystem", "datasources") .add("data-source", "*"); ResourceAddress result = processor.apply(input); assertEquals(expected, result); }
@Test public void serverConfig() throws Exception { ResourceAddress input = new ResourceAddress() .add("host", "*") .add("server-config", "server-one"); ResourceAddress expected = new ResourceAddress() .add("host", "*") .add("server-config", "*"); ResourceAddress result = processor.apply(input); assertEquals(expected, result); }
@Test public void serverConfig2() throws Exception { ResourceAddress input = new ResourceAddress() .add("host", "*") .add("server-config", "server-one") .add("jvm", "*"); ResourceAddress expected = new ResourceAddress() .add("host", "*") .add("server-config", "*") .add("jvm", "*"); ResourceAddress result = processor.apply(input); assertEquals(expected, result); }
@Test public void serverGroup() throws Exception { ResourceAddress input = new ResourceAddress() .add("server-group", "main-server-group"); ResourceAddress expected = new ResourceAddress() .add("server-group", "*"); ResourceAddress result = processor.apply(input); assertEquals(expected, result); }