package io.bootique.jetty;

import io.bootique.meta.module.ModuleMetadata;
import io.bootique.meta.module.ModulesMetadata;
import io.bootique.test.BQTestRuntime;
import io.bootique.test.junit.BQTestFactory;
import org.junit.Rule;
import org.junit.Test;

import java.util.Optional;

import static org.junit.Assert.assertTrue;

public class JettyModuleProvider_MetadataIT {

    @Rule
    public BQTestFactory testFactory = new BQTestFactory();

    @Test
    public void testMetadata() {

        BQTestRuntime runtime = testFactory.app().autoLoadModules().createRuntime();

        ModulesMetadata modulesMetadata = runtime.getRuntime().getInstance(ModulesMetadata.class);
        Optional<ModuleMetadata> jettyOpt = modulesMetadata.getModules()
                .stream()
                .filter(m -> "JettyModule".equals(m.getName()))
                .findFirst();

        assertTrue(jettyOpt.isPresent());
        ModuleMetadata jetty = jettyOpt.get();

        assertTrue(jetty.getDescription().startsWith("Integrates Jetty web server"));
    }
}

@@ -21,16 +21,327 @@
 jetty;%0A%0A
+import io.bootique.meta.config.ConfigListMetadata;%0Aimport io.bootique.meta.config.ConfigMapMetadata;%0Aimport io.bootique.meta.config.ConfigMetadataNode;%0Aimport io.bootique.meta.config.ConfigMetadataVisitor;%0Aimport io.bootique.meta.config.ConfigObjectMetadata;%0Aimport io.bootique.meta.config.ConfigValueMetadata;%0A
 import i
@@ -579,18 +579,92 @@
 til.
-Optional;%0A
+Comparator;%0Aimport java.util.Optional;%0A%0Aimport static org.junit.Assert.assertEquals;
 %0Aimp
@@ -1420,16 +1420,1864 @@
 rver%22));
+%0A%0A        assertEquals(1, jetty.getConfigs().size());%0A        ConfigMetadataNode rootConfig = jetty.getConfigs().stream().findFirst().get();%0A%0A        assertEquals(%22jetty%22, rootConfig.getName());%0A%0A        String result = rootConfig.accept(new ConfigMetadataVisitor%3CString%3E() %7B%0A%0A            @Override%0A            public String visitObjectMetadata(ConfigObjectMetadata metadata) %7B%0A%0A                StringBuilder out = new StringBuilder(metadata.getName());%0A%0A                metadata.getProperties()%0A                        .stream()%0A                        .sorted(Comparator.comparing(ConfigMetadataNode::getName))%0A                        .forEach(p -%3E out.append(%22%5B%22).append(p.accept(this)).append(%22%5D%22));%0A%0A                return out.toString();%0A            %7D%0A%0A            @Override%0A            public String visitValueMetadata(ConfigValueMetadata metadata) %7B%0A                return metadata.getName() + %22:%22 + metadata.getType().getTypeName();%0A            %7D%0A%0A            @Override%0A            public String visitListMetadata(ConfigListMetadata metadata) %7B%0A                return %22list:%22 + metadata.getName();%0A            %7D%0A%0A            @Override%0A            public String visitMapMetadata(ConfigMapMetadata metadata) %7B%0A                return %22map:%22 + metadata.getName();%0A            %7D%0A        %7D);%0A%0A        assertEquals(%22jetty%22 +%0A                %22%5Bcompression:boolean%5D%22 +%0A                %22%5Blist:connectors%5D%22 +%0A                %22%5Bcontext:java.lang.String%5D%22 +%0A                %22%5Bmap:filters%5D%22 +%0A                %22%5BidleThreadTimeout:int%5D%22 +%0A                %22%5BmaxQueuedRequests:int%5D%22 +%0A                %22%5BmaxThreads:int%5D%22 +%0A                %22%5BminThreads:int%5D%22 +%0A                %22%5Bmap:params%5D%22 +%0A                %22%5Bmap:servlets%5D%22 +%0A                %22%5Bsessions:boolean%5D%22 +%0A                %22%5BstaticResourceBase:io.bootique.resource.FolderResourceFactory%5D%22, result);
 %0A    %7D%0A%7D

Upgrade to Bootique 0.21: new app metadata package, annotated config help #56