Permalink
Browse files

Restructure: split wrapping of application and component in separate …

…packages. This should also ensure the code is modular enough to allow clean external extensions.
  • Loading branch information...
1 parent 47866aa commit b06c5fff0fc8401f03afe4ee8a6d30b176c16deb @coekie coekie committed Mar 30, 2012
Showing with 317 additions and 147 deletions.
  1. +4 −0 pom.xml
  2. +37 −59 src/main/java/com/bsb/common/vaadin/embed/EmbedVaadinConfig.java
  3. +28 −33 src/main/java/com/bsb/common/vaadin/embed/EmbedVaadinServerBuilder.java
  4. +3 −1 src/main/java/com/bsb/common/vaadin/embed/{ → application}/ApplicationBasedEmbedVaadinTomcat.java
  5. +20 −2 src/main/java/com/bsb/common/vaadin/embed/{ → application}/EmbedVaadinApplication.java
  6. +10 −3 src/main/java/com/bsb/common/vaadin/embed/{ → component}/ComponentBasedEmbedVaadinTomcat.java
  7. +14 −0 src/main/java/com/bsb/common/vaadin/embed/component/ComponentBasedVaadinServer.java
  8. +3 −3 src/main/java/com/bsb/common/vaadin/embed/{ → component}/ComponentWrapper.java
  9. +3 −3 src/main/java/com/bsb/common/vaadin/embed/{ → component}/DevApplication.java
  10. +2 −1 src/main/java/com/bsb/common/vaadin/embed/{ → component}/DevApplicationHeader.java
  11. +2 −2 src/main/java/com/bsb/common/vaadin/embed/{ → component}/DevApplicationServlet.java
  12. +61 −0 src/main/java/com/bsb/common/vaadin/embed/component/EmbedComponentConfig.java
  13. +22 −5 src/main/java/com/bsb/common/vaadin/embed/{ → component}/EmbedVaadinComponent.java
  14. +3 −1 src/main/java/com/bsb/common/vaadin/embed/{ → support}/EmbedVaadin.java
  15. +2 −3 src/test/java/com/bsb/common/vaadin/embed/AbstractEmbedTest.java
  16. +1 −0 src/test/java/com/bsb/common/vaadin/embed/ApplicationBasedEmbedVaadinTomcatTest.java
  17. +7 −7 src/test/java/com/bsb/common/vaadin/embed/EmbedVaadinConfigTest.java
  18. +1 −0 src/test/java/com/bsb/common/vaadin/embed/SampleMain.java
  19. +4 −1 src/test/java/com/bsb/common/vaadin/embed/{ → component}/ComponentBasedEmbedVaadinTomcatTest.java
  20. +12 −4 src/test/java/com/bsb/common/vaadin/embed/{ → component}/ComponentWrapperTest.java
  21. +50 −0 src/test/java/com/bsb/common/vaadin/embed/component/EmbedComponentConfigTest.java
  22. +28 −19 src/test/java/com/bsb/common/vaadin/embed/{ → support}/EmbedVaadinTest.java
View
4 pom.xml
@@ -32,6 +32,10 @@
<id>snicoll</id>
<name>Stephane Nicoll</name>
</developer>
+ <developer>
+ <id>wco</id>
+ <name>Wouter Coekaerts</name>
+ </developer>
</developers>
<properties>
View
96 src/main/java/com/bsb/common/vaadin/embed/EmbedVaadinConfig.java
@@ -37,7 +37,6 @@
* <li><tt>context.path</tt>: to specify the context path of the deployed application</li>
* <li><tt>context.rootDir</tt>: to specify the root directory of the web application</li>
* <li><tt>server.await</tt>: to specify if the thread should block when the server has started</li>
- * <li><tt>vaadin.theme</tt>: to specify the theme to use for the vaadin application</li>
* <li><tt>vaadin.widgetSet</tt>: to specify the widgetSet to use for the vaadin application</li>
* </ul>
*
@@ -66,11 +65,6 @@
public static final boolean DEFAULT_WAITING = true;
/**
- * The default theme if none is set.
- */
- public static final String DEFAULT_THEME = "reindeer";
-
- /**
* Do not start the browser by default.
*/
public static final boolean DEFAULT_START_BROWSER = false;
@@ -81,12 +75,16 @@
private File contextRootDirectory;
private boolean waiting;
- private String theme;
private String widgetSet;
private boolean openBrowser;
- private EmbedVaadinConfig(Properties properties) {
+ /**
+ * Creates a new instance using the configuration in the given {@link Properties}
+ *
+ * @param properties configuration properties
+ */
+ public EmbedVaadinConfig(Properties properties) {
port = Integer.valueOf(properties.getProperty("server.port", String.valueOf(DEFAULT_PORT)));
contextPath = properties.getProperty("context.path", DEFAULT_CONTEXT_PATH);
final String contextBase = properties.getProperty("context.rootDir");
@@ -97,7 +95,6 @@ private EmbedVaadinConfig(Properties properties) {
}
waiting = Boolean.valueOf(properties.getProperty("server.await", String.valueOf(DEFAULT_WAITING)));
- theme = properties.getProperty("vaadin.theme", DEFAULT_THEME);
widgetSet = properties.getProperty("vaadin.widgetSet");
openBrowser = Boolean.valueOf(properties.getProperty("open.browser", String.valueOf(DEFAULT_START_BROWSER)));
@@ -113,44 +110,16 @@ private EmbedVaadinConfig(Properties properties) {
*
* @param clone the instance to clone
*/
- public EmbedVaadinConfig(EmbedVaadinConfig clone) {
+ protected EmbedVaadinConfig(EmbedVaadinConfig clone) {
this.port = clone.port;
this.contextPath = clone.contextPath;
this.contextRootDirectory = clone.contextRootDirectory;
this.waiting = clone.waiting;
- this.theme = clone.theme;
this.widgetSet = clone.widgetSet;
this.openBrowser = clone.openBrowser;
}
/**
- * Loads a configuration file from the default {@link #CONFIG_LOCATION config location}.
- * <p/>
- * If no file is found, only the standard default are available.
- *
- * @return a new instance with the default settings, potentially customized by an
- * external properties file at the default location
- * @see #CONFIG_LOCATION
- */
- public static EmbedVaadinConfig load() {
- return new EmbedVaadinConfig(loadProperties(CONFIG_LOCATION, false));
- }
-
-
- /**
- * Loads a configuration file from the specified location. Fails if the
- * specified <tt>path</tt> does not exist.
- *
- * @param path the location of a properties file in the classpath
- * @return a new instance with the default settings customized by an
- * external properties file at the specified location
- * @throws IllegalStateException if no such properties file is found
- */
- public static EmbedVaadinConfig load(String path) {
- return new EmbedVaadinConfig(loadProperties(path, true));
- }
-
- /**
* Creates a new instance with the default settings, i.e. does not attempt
* to load customized settings from the {@link #CONFIG_LOCATION config location}.
*
@@ -212,17 +181,6 @@ public boolean isWaiting() {
}
/**
- * Returns the vaadin theme to use for the application. Only taken into account
- * when a wrapper application is created for a component.
- *
- * @return the theme to use
- * @see #DEFAULT_THEME
- */
- public String getTheme() {
- return theme;
- }
-
- /**
* Returns the vaadin widgetSet to use for the application. Returns <tt>null</tt>
* if no specific widgetSet is configured and the default one should be used.
*
@@ -241,31 +199,27 @@ public boolean shouldOpenBrowser() {
return openBrowser;
}
- protected void setPort(int port) {
+ void setPort(int port) {
this.port = port;
}
- protected void setContextPath(String contextPath) {
+ void setContextPath(String contextPath) {
this.contextPath = contextPath;
}
- protected void setContextRootDirectory(File contextRootDirectory) {
+ void setContextRootDirectory(File contextRootDirectory) {
this.contextRootDirectory = contextRootDirectory;
}
- protected void setWaiting(boolean waiting) {
+ void setWaiting(boolean waiting) {
this.waiting = waiting;
}
- protected void setTheme(String theme) {
- this.theme = theme;
- }
-
- protected void setWidgetSet(String widgetSet) {
+ void setWidgetSet(String widgetSet) {
this.widgetSet = widgetSet;
}
- protected void setOpenBrowser(boolean openBrowser) {
+ void setOpenBrowser(boolean openBrowser) {
this.openBrowser = openBrowser;
}
@@ -276,6 +230,30 @@ private void validate() {
}
}
+ /**
+ * Loads a configuration file from the default {@link #CONFIG_LOCATION config location}.
+ * <p/>
+ * If no file is found, only the standard default are available.
+ *
+ * @return Properties loaded from the default locations, or empty Properties if the file doesn't exist.
+ * @see #CONFIG_LOCATION
+ */
+ public static Properties loadProperties() {
+ return loadProperties(CONFIG_LOCATION, false);
+ }
+
+ /**
+ * Loads a configuration file from the specified location. Fails if the
+ * specified <tt>path</tt> does not exist.
+ *
+ * @param path the location of a properties file in the classpath
+ * @return Properties Properties loaded from the <code>.properties</code> file at the specified location
+ * @throws IllegalStateException if no such properties file is found
+ */
+ public static Properties loadProperties(String path) {
+ return loadProperties(path, true);
+ }
+
private static Properties loadProperties(String path, boolean failIfNotFound) {
try {
final Properties properties = new Properties();
View
61 src/main/java/com/bsb/common/vaadin/embed/EmbedVaadinServerBuilder.java
@@ -16,6 +16,7 @@
package com.bsb.common.vaadin.embed;
import java.io.File;
+import java.util.Properties;
/**
* A basic builder for an {@link EmbedVaadinServer}.
@@ -25,21 +26,10 @@
public abstract class EmbedVaadinServerBuilder<B extends EmbedVaadinServerBuilder<B, S>,
S extends EmbedVaadinServer> {
- private EmbedVaadinConfig config;
-
/**
- * Creates a new instance, initializing the properties with a default
- * {@link EmbedVaadinConfig} instance.
- *
- * @param loadDefault <tt>true</tt> to initialize the builder with the default config
- * @see EmbedVaadinConfig#load()
+ * Creates a new instance
*/
- protected EmbedVaadinServerBuilder(boolean loadDefault) {
- if (loadDefault) {
- this.config = EmbedVaadinConfig.load();
- } else {
- this.config = EmbedVaadinConfig.defaultConfig();
- }
+ protected EmbedVaadinServerBuilder() {
}
/**
@@ -57,26 +47,34 @@ protected EmbedVaadinServerBuilder(boolean loadDefault) {
public abstract S build();
/**
- * Applies the content of the specified {@link EmbedVaadinConfig}.
+ * Loads a configuration file from the specified location. Fails if the
+ * specified <tt>path</tt> does not exist.
*
- * @param config the configuration to use
+ * @param path the location of a properties file in the classpath
* @return this
+ * @throws IllegalStateException if no such properties file is found
*/
- public B withConfig(EmbedVaadinConfig config) {
- assertNotNull(config, "embed config could not be null.");
- this.config = new EmbedVaadinConfig(config);
-
+ public B withConfigPath(String path) {
+ withConfigProperties(EmbedVaadinConfig.loadProperties(path));
return self();
}
/**
+ * Loads configuration from the specified {@link Properties}, usually read from a <code>.properties</code> file.
+ *
+ * @param properties configuration properties
+ * @return this
+ */
+ public abstract B withConfigProperties(Properties properties);
+
+ /**
* Specifies the HTTP port to use.
*
* @param httpPort the http port
* @return this
*/
public B withHttpPort(int httpPort) {
- this.config.setPort(httpPort);
+ getConfig().setPort(httpPort);
return self();
}
@@ -92,11 +90,11 @@ public B withContextPath(String contextPath) {
// Special handling so that / can be used for the root context as well
if (contextPath.equals("/") || contextPath.trim().equals("")) {
- this.config.setContextPath("");
+ getConfig().setContextPath("");
} else if (!contextPath.startsWith("/")) {
- this.config.setContextPath("/" + contextPath);
+ getConfig().setContextPath("/" + contextPath);
} else {
- this.config.setContextPath(contextPath);
+ getConfig().setContextPath(contextPath);
}
return self();
}
@@ -120,7 +118,7 @@ public B withContextRootDirectory(File webappRootDirectory) {
throw new IllegalArgumentException("the specified value ["
+ webappRootDirectory.getAbsolutePath() + "] is not a directory!");
}
- this.config.setContextRootDirectory(webappRootDirectory);
+ getConfig().setContextRootDirectory(webappRootDirectory);
return self();
}
@@ -152,7 +150,7 @@ public B withContextRootDirectory(String relativeDirectory) {
* @return this
*/
public B withWidgetSet(String widgetSet) {
- this.config.setWidgetSet(widgetSet);
+ getConfig().setWidgetSet(widgetSet);
return self();
}
@@ -167,7 +165,7 @@ public B withWidgetSet(String widgetSet) {
* @return this
*/
public B wait(boolean shouldWait) {
- this.config.setWaiting(shouldWait);
+ getConfig().setWaiting(shouldWait);
return self();
}
@@ -179,7 +177,7 @@ public B wait(boolean shouldWait) {
* @return this
*/
public B openBrowser(boolean open) {
- this.config.setOpenBrowser(open);
+ getConfig().setOpenBrowser(open);
return self();
}
@@ -194,18 +192,15 @@ public S start() {
return server;
}
-
- // Helpers for concrete builders
-
/**
* Returns the underling {@link EmbedVaadinConfig} that this instance is managing.
+ * Must be implemented by a concrete builder because the type of configuration can be different.
*
* @return the configuration
*/
- protected EmbedVaadinConfig getConfig() {
- return config;
- }
+ protected abstract EmbedVaadinConfig getConfig();
+ // Helpers for concrete builders
protected void assertNotNull(Object value, String message) {
if (value == null) {
View
4 ...ed/ApplicationBasedEmbedVaadinTomcat.java → ...on/ApplicationBasedEmbedVaadinTomcat.java
@@ -13,8 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.bsb.common.vaadin.embed;
+package com.bsb.common.vaadin.embed.application;
+import com.bsb.common.vaadin.embed.AbstractEmbedVaadinTomcat;
+import com.bsb.common.vaadin.embed.EmbedVaadinConfig;
import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.ApplicationServlet;
import org.apache.catalina.Wrapper;
View
22 .../vaadin/embed/EmbedVaadinApplication.java → ...d/application/EmbedVaadinApplication.java
@@ -1,7 +1,12 @@
-package com.bsb.common.vaadin.embed;
+package com.bsb.common.vaadin.embed.application;
+import com.bsb.common.vaadin.embed.EmbedVaadinConfig;
+import com.bsb.common.vaadin.embed.EmbedVaadinServer;
+import com.bsb.common.vaadin.embed.EmbedVaadinServerBuilder;
import com.vaadin.Application;
+import java.util.Properties;
+
/**
* A builder for a server embedding an application.
*
@@ -10,11 +15,13 @@
public class EmbedVaadinApplication extends EmbedVaadinServerBuilder<EmbedVaadinApplication, EmbedVaadinServer> {
private final Class<? extends Application> applicationClass;
+ private EmbedVaadinConfig config;
public EmbedVaadinApplication(Class<? extends Application> applicationClass) {
- super(true);
+ super();
assertNotNull(applicationClass, "applicationClass could not be null.");
this.applicationClass = applicationClass;
+ withConfigProperties(EmbedVaadinConfig.loadProperties());
}
/**
@@ -35,4 +42,15 @@ protected EmbedVaadinApplication self() {
public EmbedVaadinServer build() {
return new ApplicationBasedEmbedVaadinTomcat(getConfig(), getApplicationClass());
}
+
+ @Override
+ public EmbedVaadinApplication withConfigProperties(Properties properties) {
+ this.config = new EmbedVaadinConfig(properties);
+ return self();
+ }
+
+ @Override
+ protected EmbedVaadinConfig getConfig() {
+ return config;
+ }
}
View
13 ...mbed/ComponentBasedEmbedVaadinTomcat.java → ...nent/ComponentBasedEmbedVaadinTomcat.java
@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.bsb.common.vaadin.embed;
+package com.bsb.common.vaadin.embed.component;
+import com.bsb.common.vaadin.embed.AbstractEmbedVaadinTomcat;
import com.vaadin.ui.Component;
import org.apache.catalina.Wrapper;
@@ -26,8 +27,9 @@
*
* @author Stephane Nicoll
*/
-public class ComponentBasedEmbedVaadinTomcat extends AbstractEmbedVaadinTomcat {
+public class ComponentBasedEmbedVaadinTomcat extends AbstractEmbedVaadinTomcat implements ComponentBasedVaadinServer {
+ private final EmbedComponentConfig config;
private final Component component;
/**
@@ -36,11 +38,16 @@
* @param config the config to use
* @param component the component to display
*/
- public ComponentBasedEmbedVaadinTomcat(EmbedVaadinConfig config, Component component) {
+ public ComponentBasedEmbedVaadinTomcat(EmbedComponentConfig config, Component component) {
super(config);
+ this.config = config;
this.component = component;
}
+ public EmbedComponentConfig getConfig() {
+ return config;
+ }
+
@Override
protected void configure() {
initConfiguration();
View
14 src/main/java/com/bsb/common/vaadin/embed/component/ComponentBasedVaadinServer.java
@@ -0,0 +1,14 @@
+package com.bsb.common.vaadin.embed.component;
+
+import com.bsb.common.vaadin.embed.EmbedVaadinServer;
+
+/**
+ * A {@link EmbedVaadinServer} that deploys a component.
+ *
+ * @author Wouter Coekaerts
+ */
+public interface ComponentBasedVaadinServer extends EmbedVaadinServer {
+
+ // overriding, narrowing return type
+ EmbedComponentConfig getConfig();
+}
View
6 ...common/vaadin/embed/ComponentWrapper.java → ...din/embed/component/ComponentWrapper.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.bsb.common.vaadin.embed;
+package com.bsb.common.vaadin.embed.component;
import com.vaadin.Application;
import com.vaadin.terminal.Sizeable;
@@ -30,14 +30,14 @@
*/
public class ComponentWrapper {
- private final EmbedVaadinServer server;
+ private final ComponentBasedVaadinServer server;
/**
* Creates a new instance.
*
* @param server the server handling this application
*/
- public ComponentWrapper(EmbedVaadinServer server) {
+ public ComponentWrapper(ComponentBasedVaadinServer server) {
this.server = server;
}
View
6 ...b/common/vaadin/embed/DevApplication.java → ...aadin/embed/component/DevApplication.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.bsb.common.vaadin.embed;
+package com.bsb.common.vaadin.embed.component;
import com.vaadin.Application;
import com.vaadin.ui.Window;
@@ -25,7 +25,7 @@
*/
public class DevApplication extends Application {
- private final transient EmbedVaadinServer server;
+ private final transient ComponentBasedVaadinServer server;
private final Window mainWindow;
/**
@@ -34,7 +34,7 @@
* @param server the server handling this application
* @param mainWindow the main window
*/
- public DevApplication(EmbedVaadinServer server, Window mainWindow) {
+ public DevApplication(ComponentBasedVaadinServer server, Window mainWindow) {
this.server = server;
this.mainWindow = mainWindow;
}
View
3 ...on/vaadin/embed/DevApplicationHeader.java → ...embed/component/DevApplicationHeader.java
@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.bsb.common.vaadin.embed;
+package com.bsb.common.vaadin.embed.component;
+import com.bsb.common.vaadin.embed.EmbedVaadinServer;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
View
4 ...n/vaadin/embed/DevApplicationServlet.java → ...mbed/component/DevApplicationServlet.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.bsb.common.vaadin.embed;
+package com.bsb.common.vaadin.embed.component;
import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.ApplicationServlet;
@@ -42,7 +42,7 @@
* @param server the server handling this application
* @param component the component to display
*/
- public DevApplicationServlet(EmbedVaadinServer server, Component component) {
+ public DevApplicationServlet(ComponentBasedVaadinServer server, Component component) {
this.application = new ComponentWrapper(server).wrap(component);
}
View
61 src/main/java/com/bsb/common/vaadin/embed/component/EmbedComponentConfig.java
@@ -0,0 +1,61 @@
+package com.bsb.common.vaadin.embed.component;
+
+import com.bsb.common.vaadin.embed.EmbedVaadinConfig;
+
+import java.util.Properties;
+
+/**
+ * Configuration for an embedded server showing a component.
+ * <p>
+ * This extends the {@link EmbedVaadinConfig} and is configured in the same way.
+ * The properties file may contain any of the properties documented on {@link EmbedVaadinConfig} and
+ * additionally:
+ * <ul>
+ * <li><tt>vaadin.theme</tt>: to specify the theme to use for the vaadin application</li>
+ * </ul>
+ *
+ * @author Wouter Coekaerts
+ */
+public final class EmbedComponentConfig extends EmbedVaadinConfig {
+ /**
+ * The default theme if none is set.
+ */
+ public static final String DEFAULT_THEME = "reindeer";
+
+ private String theme;
+
+ protected EmbedComponentConfig(Properties properties) {
+ super(properties);
+ theme = properties.getProperty("vaadin.theme", DEFAULT_THEME);
+ }
+
+ protected EmbedComponentConfig(EmbedComponentConfig clone) {
+ super(clone);
+ theme = clone.theme;
+ }
+
+ /**
+ * Returns the vaadin theme to use for the application. Only taken into account
+ * when a wrapper application is created for a component.
+ *
+ * @return the theme to use
+ * @see #DEFAULT_THEME
+ */
+ public String getTheme() {
+ return theme;
+ }
+
+ void setTheme(String theme) {
+ this.theme = theme;
+ }
+
+ /**
+ * Creates a new instance with the default settings, i.e. does not attempt
+ * to load customized settings from the {@link #CONFIG_LOCATION config location}.
+ *
+ * @return a new instance with the default settings
+ */
+ public static EmbedComponentConfig defaultConfig() {
+ return new EmbedComponentConfig(new Properties());
+ }
+}
View
27 ...on/vaadin/embed/EmbedVaadinComponent.java → ...embed/component/EmbedVaadinComponent.java
@@ -1,7 +1,12 @@
-package com.bsb.common.vaadin.embed;
+package com.bsb.common.vaadin.embed.component;
+import com.bsb.common.vaadin.embed.EmbedVaadinConfig;
+import com.bsb.common.vaadin.embed.EmbedVaadinServer;
+import com.bsb.common.vaadin.embed.EmbedVaadinServerBuilder;
import com.vaadin.ui.Component;
+import java.util.Properties;
+
/**
* A builder for a server embedding a component.
*
@@ -10,11 +15,13 @@
public class EmbedVaadinComponent extends EmbedVaadinServerBuilder<EmbedVaadinComponent, EmbedVaadinServer> {
private final Component component;
+ private EmbedComponentConfig config;
public EmbedVaadinComponent(Component component) {
- super(true);
+ super();
assertNotNull(component, "component could not be null.");
this.component = component;
+ withConfigProperties(EmbedVaadinConfig.loadProperties());
}
/**
@@ -25,7 +32,6 @@ public EmbedVaadinComponent(Component component) {
*/
public EmbedVaadinComponent withTheme(String theme) {
assertNotNull(theme, "theme could not be null.");
-
getConfig().setTheme(theme);
return self();
}
@@ -45,7 +51,18 @@ protected EmbedVaadinComponent self() {
}
@Override
- public EmbedVaadinServer build() {
- return new ComponentBasedEmbedVaadinTomcat(getConfig(), getComponent());
+ public ComponentBasedVaadinServer build() {
+ return new ComponentBasedEmbedVaadinTomcat(config, getComponent());
+ }
+
+ @Override
+ public EmbedVaadinComponent withConfigProperties(Properties properties) {
+ this.config = new EmbedComponentConfig(properties);
+ return self();
+ }
+
+ @Override
+ protected EmbedComponentConfig getConfig() {
+ return config;
}
}
View
4 .../bsb/common/vaadin/embed/EmbedVaadin.java → ...mon/vaadin/embed/support/EmbedVaadin.java
@@ -13,8 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.bsb.common.vaadin.embed;
+package com.bsb.common.vaadin.embed.support;
+import com.bsb.common.vaadin.embed.application.EmbedVaadinApplication;
+import com.bsb.common.vaadin.embed.component.EmbedVaadinComponent;
import com.vaadin.Application;
import com.vaadin.ui.Component;
View
5 src/test/java/com/bsb/common/vaadin/embed/AbstractEmbedTest.java
@@ -36,9 +36,8 @@ protected void assertServerConfig(EmbedVaadinConfig config, int port, String con
assertEquals("Wrong waiting flag", waiting, config.isWaiting());
}
- protected void assertVaadinConfig(EmbedVaadinConfig config, String theme, String widgetSet) {
+ protected void assertVaadinConfig(EmbedVaadinConfig config, String widgetSet) {
assertConfigIsNotNull(config);
- assertEquals("Wrong theme", theme, config.getTheme());
assertEquals("Wrong widgetSet", widgetSet, config.getWidgetSet());
}
@@ -69,7 +68,7 @@ protected void checkVaadinIsDeployed(int port, String context) {
}
}
- private void assertConfigIsNotNull(EmbedVaadinConfig config) {
+ protected void assertConfigIsNotNull(EmbedVaadinConfig config) {
assertNotNull("config could not be null.", config);
}
}
View
1 src/test/java/com/bsb/common/vaadin/embed/ApplicationBasedEmbedVaadinTomcatTest.java
@@ -15,6 +15,7 @@
*/
package com.bsb.common.vaadin.embed;
+import com.bsb.common.vaadin.embed.support.EmbedVaadin;
import com.bsb.common.vaadin.embed.test.TestApplication;
import org.junit.Test;
View
14 src/test/java/com/bsb/common/vaadin/embed/EmbedVaadinConfigTest.java
@@ -29,26 +29,27 @@ public void createDefaultInstance() {
final EmbedVaadinConfig config = EmbedVaadinConfig.defaultConfig();
assertServerConfig(config, EmbedVaadinConfig.DEFAULT_PORT, EmbedVaadinConfig.DEFAULT_CONTEXT_PATH,
EmbedVaadinConfig.DEFAULT_WAITING);
- assertVaadinConfig(config, EmbedVaadinConfig.DEFAULT_THEME, null);
+ assertVaadinConfig(config, null);
assertBrowserConfig(config, EmbedVaadinConfig.DEFAULT_START_BROWSER);
}
@Test(expected = IllegalStateException.class)
public void loadUnknownFile() {
- EmbedVaadinConfig.load("/foo/bar/does-not-exist.properties");
+ EmbedVaadinConfig.loadProperties("/foo/bar/does-not-exist.properties");
}
@Test
public void load() {
- final EmbedVaadinConfig config = EmbedVaadinConfig.load("/config/simple-embed-vaadin.properties");
+ final EmbedVaadinConfig config = new EmbedVaadinConfig(
+ EmbedVaadinConfig.loadProperties("/config/simple-embed-vaadin.properties"));
assertServerConfig(config, 12345, "/foo", false);
- assertVaadinConfig(config, "myTheme", "com.bsb.foo.MyWidgetSet");
+ assertVaadinConfig(config, "com.bsb.foo.MyWidgetSet");
assertBrowserConfig(config, true);
}
@Test(expected = IllegalStateException.class)
public void loadWithInvalidRootWebDir() {
- EmbedVaadinConfig.load("/config/root-dir-embed-vaadin.properties");
+ new EmbedVaadinConfig(EmbedVaadinConfig.loadProperties("/config/root-dir-embed-vaadin.properties"));
}
@Test
@@ -60,15 +61,14 @@ public void cloneConfig() {
config.setPort(1);
config.setContextPath("/foo/bar");
config.setContextRootDirectory(new File("."));
- config.setTheme("fooBarTheme");
config.setWidgetSet("com.bar.MyAnotherWidgetSet");
config.setWaiting(true);
config.setOpenBrowser(true);
// Now validate the clone has not changed
assertServerConfig(clone, EmbedVaadinConfig.DEFAULT_PORT, EmbedVaadinConfig.DEFAULT_CONTEXT_PATH,
EmbedVaadinConfig.DEFAULT_WAITING);
- assertVaadinConfig(clone, EmbedVaadinConfig.DEFAULT_THEME, null);
+ assertVaadinConfig(clone, null);
assertBrowserConfig(clone, EmbedVaadinConfig.DEFAULT_START_BROWSER);
}
View
1 src/test/java/com/bsb/common/vaadin/embed/SampleMain.java
@@ -1,5 +1,6 @@
package com.bsb.common.vaadin.embed;
+import com.bsb.common.vaadin.embed.support.EmbedVaadin;
import com.vaadin.ui.Button;
/**
View
5 .../ComponentBasedEmbedVaadinTomcatTest.java → .../ComponentBasedEmbedVaadinTomcatTest.java
@@ -13,8 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.bsb.common.vaadin.embed;
+package com.bsb.common.vaadin.embed.component;
+import com.bsb.common.vaadin.embed.AbstractEmbedTest;
+import com.bsb.common.vaadin.embed.EmbedVaadinServer;
+import com.bsb.common.vaadin.embed.support.EmbedVaadin;
import com.vaadin.ui.Button;
import org.junit.Test;
View
16 ...on/vaadin/embed/ComponentWrapperTest.java → ...embed/component/ComponentWrapperTest.java
@@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.bsb.common.vaadin.embed;
+package com.bsb.common.vaadin.embed.component;
+import com.bsb.common.vaadin.embed.AbstractEmbedVaadinTomcat;
import com.vaadin.Application;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
@@ -34,7 +35,7 @@
public class ComponentWrapperTest {
private final ComponentWrapper instance = new ComponentWrapper(
- new TestableEmbedVaadinServer(EmbedVaadinConfig.defaultConfig()));
+ new TestableEmbedVaadinServer(EmbedComponentConfig.defaultConfig()));
@Test
public void wrapWindow() {
@@ -80,15 +81,22 @@ private Layout assertWrappingLayout(Application app) {
// A testable server that does not need any vaadin component
- private static final class TestableEmbedVaadinServer extends AbstractEmbedVaadinTomcat {
+ private static final class TestableEmbedVaadinServer extends AbstractEmbedVaadinTomcat
+ implements ComponentBasedVaadinServer{
+ private final EmbedComponentConfig config;
- private TestableEmbedVaadinServer(EmbedVaadinConfig config) {
+ private TestableEmbedVaadinServer(EmbedComponentConfig config) {
super(config);
+ this.config = config;
}
@Override
protected void configure() {
}
+
+ public EmbedComponentConfig getConfig() {
+ return config;
+ }
}
View
50 src/test/java/com/bsb/common/vaadin/embed/component/EmbedComponentConfigTest.java
@@ -0,0 +1,50 @@
+package com.bsb.common.vaadin.embed.component;
+
+import com.bsb.common.vaadin.embed.AbstractEmbedTest;
+import com.bsb.common.vaadin.embed.EmbedVaadinConfig;
+import org.junit.Test;
+
+import static junit.framework.Assert.assertEquals;
+
+/**
+ * @author Wouter Coekaerts
+ */
+public class EmbedComponentConfigTest extends AbstractEmbedTest {
+
+ @Test
+ public void createDefaultInstance() {
+ final EmbedComponentConfig config = EmbedComponentConfig.defaultConfig();
+ assertServerConfig(config, EmbedVaadinConfig.DEFAULT_PORT, EmbedVaadinConfig.DEFAULT_CONTEXT_PATH,
+ EmbedVaadinConfig.DEFAULT_WAITING);
+ assertComponentConfig(config, EmbedComponentConfig.DEFAULT_THEME);
+ assertVaadinConfig(config, null);
+ assertBrowserConfig(config, EmbedVaadinConfig.DEFAULT_START_BROWSER);
+ }
+
+ @Test
+ public void load() {
+ final EmbedComponentConfig config = new EmbedComponentConfig(
+ EmbedVaadinConfig.loadProperties("/config/simple-embed-vaadin.properties"));
+ assertServerConfig(config, 12345, "/foo", false);
+ assertVaadinConfig(config, "com.bsb.foo.MyWidgetSet");
+ assertComponentConfig(config, "myTheme");
+ assertBrowserConfig(config, true);
+ }
+
+ @Test
+ public void cloneConfig() {
+ final EmbedComponentConfig config = EmbedComponentConfig.defaultConfig();
+ final EmbedComponentConfig clone = new EmbedComponentConfig(config);
+
+ // Change stuff
+ config.setTheme("fooBarTheme");
+
+ // Now validate the clone has not changed
+ assertComponentConfig(clone, EmbedComponentConfig.DEFAULT_THEME);
+ }
+
+ protected void assertComponentConfig(EmbedComponentConfig config, String theme) {
+ assertConfigIsNotNull(config);
+ assertEquals("Wrong theme", theme, config.getTheme());
+ }
+}
View
47 .../common/vaadin/embed/EmbedVaadinTest.java → ...vaadin/embed/support/EmbedVaadinTest.java
@@ -13,8 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.bsb.common.vaadin.embed;
+package com.bsb.common.vaadin.embed.support;
+import com.bsb.common.vaadin.embed.AbstractEmbedTest;
+import com.bsb.common.vaadin.embed.component.EmbedComponentConfig;
+import com.bsb.common.vaadin.embed.component.EmbedVaadinComponent;
import com.google.common.io.Files;
import com.vaadin.ui.Button;
import org.junit.Test;
@@ -47,9 +50,14 @@ public void withNullContextRootDirectoryAsFile() {
EmbedVaadin.forComponent(component).withContextRootDirectory((String) null);
}
- @Test(expected = IllegalArgumentException.class)
- public void withNullConfig() {
- EmbedVaadin.forComponent(component).withConfig(null);
+ @Test(expected = NullPointerException.class)
+ public void withNullConfigPath() {
+ EmbedVaadin.forComponent(component).withConfigPath(null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void withNullConfigProperties() {
+ EmbedVaadin.forComponent(component).withConfigProperties(null);
}
@Test(expected = IllegalArgumentException.class)
@@ -60,33 +68,33 @@ public void withNullTheme() {
@Test
public void withPort() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withHttpPort(8080);
- assertEquals("was not detected as expected", 8080, embed.getConfig().getPort());
+ assertEquals("was not detected as expected", 8080, embed.build().getConfig().getPort());
}
@Test
public void withRootContextPath() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withContextPath("/");
- assertEquals("/ was not detected as root context properly", "", embed.getConfig().getContextPath());
+ assertEquals("/ was not detected as root context properly", "", embed.build().getConfig().getContextPath());
}
@Test
public void withEmptyContextPath() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withContextPath(" ");
assertEquals("empty string was not detected as root context properly",
- "", embed.getConfig().getContextPath());
+ "", embed.build().getConfig().getContextPath());
}
@Test
public void withContextWithoutForwardSlash() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withContextPath("foo");
assertEquals("forward slash was not added to context as expected",
- "/foo", embed.getConfig().getContextPath());
+ "/foo", embed.build().getConfig().getContextPath());
}
@Test
public void withSimpleContextPath() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withContextPath("/bar");
- assertEquals("was not detected as expected", "/bar", embed.getConfig().getContextPath());
+ assertEquals("was not detected as expected", "/bar", embed.build().getConfig().getContextPath());
}
@Test(expected = IllegalArgumentException.class)
@@ -103,7 +111,7 @@ public void withFileContextRootDirectory() throws IOException {
public void withContextRootDirectoryAsFile() {
final File rootContextDir = Files.createTempDir();
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withContextRootDirectory(rootContextDir);
- assertEquals("was not detected as expected", rootContextDir, embed.getConfig().getContextRootDirectory());
+ assertEquals("was not detected as expected", rootContextDir, embed.build().getConfig().getContextRootDirectory());
}
@Test
@@ -112,40 +120,41 @@ public void withContextRootDirectoryAsRelativeDirectory() {
assertTrue("src/main/java should exist [" + f.getAbsolutePath() + "] make sure you are running " +
"the tests with the working directory set to this module.", f.exists());
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withContextRootDirectory("src/main/java");
- assertEquals("was not detected as expected", f, embed.getConfig().getContextRootDirectory());
+ assertEquals("was not detected as expected", f, embed.build().getConfig().getContextRootDirectory());
}
@Test
public void withVaadinTheme() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withTheme("showcase");
- assertEquals("was not detected as expected", "showcase", embed.getConfig().getTheme());
+ assertEquals("was not detected as expected", "showcase", embed.build().getConfig().getTheme());
}
@Test
public void withWidgetSet() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withWidgetSet("com.bsb.foo.MyWidgetSet");
- assertEquals("was not detected as expected", "com.bsb.foo.MyWidgetSet", embed.getConfig().getWidgetSet());
+ assertEquals("was not detected as expected", "com.bsb.foo.MyWidgetSet", embed.build().getConfig().getWidgetSet());
}
@Test
public void withNullWidgetSet() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withWidgetSet(null);
- assertEquals("was not detected as expected", null, embed.getConfig().getWidgetSet());
+ assertEquals("was not detected as expected", null, embed.build().getConfig().getWidgetSet());
}
@Test
public void withOpenBrowser() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).openBrowser(true);
- assertEquals("was not detected as expected", true, embed.getConfig().shouldOpenBrowser());
+ assertEquals("was not detected as expected", true, embed.build().getConfig().shouldOpenBrowser());
}
@Test
public void withCustomConfig() {
- final EmbedVaadinConfig config = EmbedVaadinConfig.load("/config/simple-embed-vaadin.properties");
- final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withConfig(config);
+ final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component)
+ .withConfigPath("/config/simple-embed-vaadin.properties");
- assertServerConfig(embed.getConfig(), 12345, "/foo", false);
- assertVaadinConfig(embed.getConfig(), "myTheme", "com.bsb.foo.MyWidgetSet");
+ final EmbedComponentConfig config = embed.build().getConfig();
+ assertServerConfig(config, 12345, "/foo", false);
+ assertVaadinConfig(config, "com.bsb.foo.MyWidgetSet");
}

0 comments on commit b06c5ff

Please sign in to comment.