/
EmbedVaadinTest.java
183 lines (152 loc) · 7.45 KB
/
EmbedVaadinTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* Copyright 2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.bsb.common.vaadin.embed.support;
import com.bsb.common.vaadin.embed.AbstractEmbedTest;
import com.bsb.common.vaadin.embed.EmbedVaadinServer;
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;
import java.io.File;
import java.io.IOException;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
/**
* @author Stephane Nicoll
*/
public class EmbedVaadinTest extends AbstractEmbedTest {
private final Button component = new Button("Test");
@Test(expected = IllegalArgumentException.class)
public void withNullContextPath() {
EmbedVaadin.forComponent(component).withContextPath(null);
}
@Test(expected = IllegalArgumentException.class)
public void withNullContextRootDirectory() {
EmbedVaadin.forComponent(component).withContextRootDirectory((File) null);
}
@Test(expected = IllegalArgumentException.class)
public void withNullContextRootDirectoryAsFile() {
EmbedVaadin.forComponent(component).withContextRootDirectory((String) null);
}
@Test(expected = IllegalArgumentException.class)
public void withNullConfigPath() {
EmbedVaadin.forComponent(component).withConfigPath(null);
}
@Test(expected = IllegalArgumentException.class)
public void withNullConfigProperties() {
EmbedVaadin.forComponent(component).withConfigProperties(null);
}
@Test(expected = IllegalArgumentException.class)
public void withNullTheme() {
EmbedVaadin.forComponent(component).withTheme(null);
}
@Test
public void withPort() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withHttpPort(8080);
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.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.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.build().getConfig().getContextPath());
}
@Test
public void withSimpleContextPath() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withContextPath("/bar");
assertEquals("was not detected as expected", "/bar", embed.build().getConfig().getContextPath());
}
@Test(expected = IllegalArgumentException.class)
public void withUnknownContextRootDirectory() {
EmbedVaadin.forComponent(component).withContextRootDirectory(new File(".", "/foo/bar/"));
}
@Test(expected = IllegalArgumentException.class)
public void withFileContextRootDirectory() throws IOException {
EmbedVaadin.forComponent(component).withContextRootDirectory(File.createTempFile("fake", "foo"));
}
@Test
public void withContextRootDirectoryAsFile() {
final File rootContextDir = Files.createTempDir();
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withContextRootDirectory(rootContextDir);
assertEquals("was not detected as expected", rootContextDir, embed.build().getConfig().getContextRootDirectory());
}
@Test
public void withContextRootDirectoryAsRelativeDirectory() {
final File f = new File(".", "src/main/java");
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.build().getConfig().getContextRootDirectory());
}
@Test
public void withVaadinTheme() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withTheme("showcase");
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.build().getConfig().getWidgetSet());
}
@Test
public void withNullWidgetSet() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withWidgetSet(null);
assertEquals("was not detected as expected", null, embed.build().getConfig().getWidgetSet());
}
@Test
public void withProductionMode() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withProductionMode(true);
assertEquals("was not detected as expected", true, embed.build().getConfig().isProductionMode());
}
@Test
public void withOpenBrowser() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).openBrowser(true);
assertEquals("was not detected as expected", true, embed.build().getConfig().shouldOpenBrowser());
}
@Test
public void withOpenBrowserAtEnablesOpenBrowser() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).openBrowserAt("?debug");
final EmbedVaadinServer server = embed.build();
assertEquals("was not detected as expected", "?debug", server.getConfig().getCustomBrowserUrl());
assertTrue("openBrowserAt should enable openBrowser flag automatically",
server.getConfig().shouldOpenBrowser());
}
@Test
public void withCustomConfig() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component)
.withConfigPath("/config/simple-embed-vaadin.properties");
final EmbedComponentConfig config = embed.build().getConfig();
assertServerConfig(config, 12345, "/foo", false);
assertVaadinConfig(config, "com.bsb.foo.MyWidgetSet", true);
}
@Test
public void withDevelopmentHeader() {
final EmbedVaadinComponent embed = EmbedVaadin.forComponent(component).withDevelopmentHeader(true);
assertEquals("was not detected as expected", true, embed.build().getConfig().isDevelopmentHeader());
}
}