openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1769544 - in /openwebbeans/meecrowave/trunk: meecrowave-core/src/main/java/org/apache/meecrowave/ meecrowave-core/src/test/java/org/apache/meecrowave/runner/ meecrowave-core/src/test/resources/META-INF/services/ meecrowave-doc/src/main/jba...
Date Sun, 13 Nov 2016 20:37:51 GMT
Author: rmannibucau
Date: Sun Nov 13 20:37:51 2016
New Revision: 1769544

URL: http://svn.apache.org/viewvc?rev=1769544&view=rev
Log:
finishing config extension feature with a test

Added:
    openwebbeans/meecrowave/trunk/meecrowave-core/src/test/resources/META-INF/services/org.apache.meecrowave.runner.Cli$Options
Modified:
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/runner/CliTest.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/test/resources/META-INF/services/javax.servlet.ServletContainerInitializer
    openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/meecrowave-core/cli.adoc

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java?rev=1769544&r1=1769543&r2=1769544&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
Sun Nov 13 20:37:51 2016
@@ -698,6 +698,10 @@ public class Meecrowave implements AutoC
         tomcat.getServer().await();
     }
 
+    // this class holds all the built-in config,
+    // extension can use extensions feature (see cli.html) which is basically the same kind
of bean
+    // accessible through builder.getExtension(type) builder being accessible through the
meecrowave.configuration
+    // attribute of the ServletContext.
     public static class Builder {
         @CliOption(name = "http", description = "HTTP port")
         private int httpPort = 8080;

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/runner/CliTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/runner/CliTest.java?rev=1769544&r1=1769543&r2=1769544&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/runner/CliTest.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/runner/CliTest.java
Sun Nov 13 20:37:51 2016
@@ -18,23 +18,35 @@
  */
 package org.apache.meecrowave.runner;
 
+import org.apache.meecrowave.Meecrowave;
 import org.apache.meecrowave.io.IO;
+import org.apache.meecrowave.runner.cli.CliOption;
 import org.junit.Test;
 
+import javax.servlet.ServletContainerInitializer;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 public class CliTest {
+    private static final AtomicBoolean OPTS_SET = new AtomicBoolean();
+
     @Test
     public void bake() throws IOException {
+        OPTS_SET.set(false);
+
         int stop;
         int http;
         try (final ServerSocket s1 = new ServerSocket(0)) {
@@ -54,16 +66,19 @@ public class CliTest {
                         "--context=app",
                         "--stop=" + stop,
                         "--http=" + http,
-                        "--tmp-dir=target/CliTest/simple"
+                        "--tmp-dir=target/CliTest/simple",
+                        "--my-config=val"
                 });
             }
         };
         try {
             runner.start();
+            boolean jsonOk = false;
             for (int i = 0; i < 60; i++) {
                 try {
                     assertEquals("{\"name\":\"test\"}", slurp(new URL("http://localhost:"
+ http + "/app/api/test/json")));
-                    return;
+                    jsonOk = true;
+                    break;
                 } catch (final AssertionError notYet) {
                     try {
                         Thread.sleep(1000);
@@ -73,7 +88,8 @@ public class CliTest {
                     }
                 }
             }
-            fail("Didnt achieved the request");
+            assertTrue(jsonOk);
+            assertTrue(OPTS_SET.get());
         } finally {
             try (final Socket client = new Socket("localhost", stop)) {
                 client.getOutputStream().write("SHUTDOWN".getBytes(StandardCharsets.UTF_8));
@@ -97,4 +113,17 @@ public class CliTest {
         }
         return null;
     }
+
+    public static class MyOpts implements Cli.Options {
+        @CliOption(name = "my-config", description = "test")
+        private String opt;
+    }
+
+    public static class BeanTester implements ServletContainerInitializer {
+        @Override
+        public void onStartup(final Set<Class<?>> set, final ServletContext servletContext)
throws ServletException {
+            OPTS_SET.set("val".equals(
+                    Meecrowave.Builder.class.cast(servletContext.getAttribute("meecrowave.configuration")).getExtension(MyOpts.class).opt));
+        }
+    }
 }

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/test/resources/META-INF/services/javax.servlet.ServletContainerInitializer
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/test/resources/META-INF/services/javax.servlet.ServletContainerInitializer?rev=1769544&r1=1769543&r2=1769544&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/test/resources/META-INF/services/javax.servlet.ServletContainerInitializer
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/test/resources/META-INF/services/javax.servlet.ServletContainerInitializer
Sun Nov 13 20:37:51 2016
@@ -1 +1,2 @@
 org.superbiz.app.Init
+org.apache.meecrowave.runner.CliTest$BeanTester

Added: openwebbeans/meecrowave/trunk/meecrowave-core/src/test/resources/META-INF/services/org.apache.meecrowave.runner.Cli$Options
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/test/resources/META-INF/services/org.apache.meecrowave.runner.Cli%24Options?rev=1769544&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/test/resources/META-INF/services/org.apache.meecrowave.runner.Cli$Options
(added)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/test/resources/META-INF/services/org.apache.meecrowave.runner.Cli$Options
Sun Nov 13 20:37:51 2016
@@ -0,0 +1 @@
+org.apache.meecrowave.runner.CliTest$MyOpts

Modified: openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/meecrowave-core/cli.adoc
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/meecrowave-core/cli.adoc?rev=1769544&r1=1769543&r2=1769544&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/meecrowave-core/cli.adoc
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-doc/src/main/jbake/content/meecrowave-core/cli.adoc
Sun Nov 13 20:37:51 2016
@@ -15,3 +15,13 @@ It can be used to deploy the java classp
 include::../../../../../target/generated-doc/CliConfiguration.adoc[]
 
 Note that `help` command is supported as well.
+
+== Extending the CLI
+
+You can add your own CLI options implementing `org.apache.meecrowave.runner.Cli$Options`
+(just a marker interface, no logic to code) and use `@CliOption` to define fields
+as coming from the CLI arguments. To register your option bean just add it in `META-INF/services/org.apache.meecrowave.runner.Cli$Options`.
+
+TIP: `Meecrowave.Builder` provides a `getExtension(type)` which can be used to get this
+kind of extension. This is common and works in all modes (arquillian, JUnit, embedded etc...)
+replacing the arguments by properties on `Meecrowave.Builder` instance.



Mime
View raw message