SegmentProcessor { static void process(List<String[]> segments, Consumer<String[]> consumer) { if (segments != null) { int index = 0; int length = segments.size(); for (String[] segment : segments) { String key = segment[0]; String value = segment[1]; if (key != null && value != null) { switch (key) { case HOST: if (length > 1 && index == 0) { value = "*"; } break; case PROFILE: case SERVER_GROUP: if (index == 0) { value = "*"; } break; case SERVER: case SERVER_CONFIG: if (index == 1) { value = "*"; } break; default: break; } } consumer.accept(new String[]{key, value}); index++; } } } private  SegmentProcessor();   }
@Test public void nil() throws Exception { Fixture fixture = new Fixture.Builder("null") .segments() .expected() .build(); SegmentProcessor.process(fixture.segments, consumer); assertFixture(fixture, consumer.result); }
@Test public void empty() throws Exception { Fixture fixture = new Fixture.Builder("empty") .segments("", "") .expected("", "") .build(); SegmentProcessor.process(fixture.segments, consumer); assertFixture(fixture, consumer.result); }
@Test public void simple() throws Exception { Fixture fixture = new Fixture.Builder("simple") .segments("foo", "bar") .expected("foo", "bar") .build(); SegmentProcessor.process(fixture.segments, consumer); assertFixture(fixture, consumer.result); }
@Test public void host() throws Exception { Fixture fixture = new Fixture.Builder("host") .segments("host", "master") .expected("host", "master") .build(); SegmentProcessor.process(fixture.segments, consumer); assertFixture(fixture, consumer.result); }
@Test public void host2() throws Exception { Fixture fixture = new Fixture.Builder("host2") .segments("host", "master", "subsystem", "jmx") .expected("host", "*", "subsystem", "jmx") .build(); SegmentProcessor.process(fixture.segments, consumer); assertFixture(fixture, consumer.result); }
@Test public void server() throws Exception { Fixture fixture = new Fixture.Builder("server") .segments("host", "*", "server", "server-one") .expected("host", "*", "server", "*") .build(); SegmentProcessor.process(fixture.segments, consumer); assertFixture(fixture, consumer.result); }
@Test public void server2() throws Exception { Fixture fixture = new Fixture.Builder("server2") .segments("host", "*", "server", "server-one", "subsystem", "datasources", "data-source", "*") .expected("host", "*", "server", "*", "subsystem", "datasources", "data-source", "*") .build(); SegmentProcessor.process(fixture.segments, consumer); assertFixture(fixture, consumer.result); }
@Test public void serverConfig() throws Exception { Fixture fixture = new Fixture.Builder("server-config") .segments("host", "*", "server-config", "server-one") .expected("host", "*", "server-config", "*") .build(); SegmentProcessor.process(fixture.segments, consumer); assertFixture(fixture, consumer.result); }
@Test public void serverConfig2() throws Exception { Fixture fixture = new Fixture.Builder("server-config2") .segments("host", "*", "server-config", "server-one", "jvm", "*") .expected("host", "*", "server-config", "*", "jvm", "*") .build(); SegmentProcessor.process(fixture.segments, consumer); assertFixture(fixture, consumer.result); }
@Test public void serverGroup() throws Exception { Fixture fixture = new Fixture.Builder("server-group") .segments("server-group", "main-server-group") .expected("server-group", "*") .build(); SegmentProcessor.process(fixture.segments, consumer); assertFixture(fixture, consumer.result); }
@Test public void serverGroup2() throws Exception { Fixture fixture = new Fixture.Builder("server-group2") .segments("server-group", "main-server-group", "system-property", "*") .expected("server-group", "*", "system-property", "*") .build(); SegmentProcessor.process(fixture.segments, consumer); assertFixture(fixture, consumer.result); }
@Test public void profile() throws Exception { Fixture fixture = new Fixture.Builder("profile") .segments("profile", "full") .expected("profile", "*") .build(); SegmentProcessor.process(fixture.segments, consumer); assertFixture(fixture, consumer.result); }
@Test public void profile2() throws Exception { Fixture fixture = new Fixture.Builder("profile2") .segments("profile", "full", "subsystem", "mail") .expected("profile", "*", "subsystem", "mail") .build(); SegmentProcessor.process(fixture.segments, consumer); assertFixture(fixture, consumer.result); }
@Test public void hostInTheMiddle() throws Exception { Fixture fixture = new Fixture.Builder("host-in-the-middle") .segments("profile", "full", "subsystem", "undertow", "server", "*", "host", "*", "location", "*") .expected("profile", "*", "subsystem", "undertow", "server", "*", "host", "*", "location", "*") .build(); SegmentProcessor.process(fixture.segments, consumer); assertFixture(fixture, consumer.result); }
@Test public void serverAtTheEnd() throws Exception { Fixture fixture = new Fixture.Builder("server-at-the-end") .segments("profile", "full", "subsystem", "mail", "mail-session", "default", "server", "imap") .expected("profile", "*", "subsystem", "mail", "mail-session", "default", "server", "imap") .build(); SegmentProcessor.process(fixture.segments, consumer); assertFixture(fixture, consumer.result); }