Skip to content

Commit b093cc0

Browse files
authored
Merge pull request #3 from gnieser/develop
Made slf4j the logging facade
2 parents 7fd0f0a + 821fcf5 commit b093cc0

File tree

2 files changed

+104
-108
lines changed

2 files changed

+104
-108
lines changed

pom.xml

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@
118118
<version>${commons-codec.version}</version>
119119
</dependency>
120120

121+
<!-- Logging -->
122+
<dependency>
123+
<groupId>org.slf4j</groupId>
124+
<artifactId>slf4j-api</artifactId>
125+
<version>${slf4j-api.version}</version>
126+
</dependency>
127+
<dependency>
128+
<groupId>org.slf4j</groupId>
129+
<artifactId>jcl-over-slf4j</artifactId>
130+
<version>${jcl-over-slf4j.version}</version>
131+
</dependency>
132+
121133
<dependency>
122134
<groupId>org.projectlombok</groupId>
123135
<artifactId>lombok</artifactId>
@@ -132,12 +144,6 @@
132144
<version>${junit.version}</version>
133145
<scope>test</scope>
134146
</dependency>
135-
<dependency>
136-
<groupId>org.slf4j</groupId>
137-
<artifactId>slf4j-api</artifactId>
138-
<version>${slf4j-api.version}</version>
139-
<scope>test</scope>
140-
</dependency>
141147
<dependency>
142148
<groupId>org.assertj</groupId>
143149
<artifactId>assertj-core</artifactId>
@@ -149,12 +155,6 @@
149155
<artifactId>wiremock</artifactId>
150156
<version>${wiremock.version}</version>
151157
<scope>test</scope>
152-
<exclusions>
153-
<exclusion>
154-
<groupId>org.slf4j</groupId>
155-
<artifactId>slf4j-api</artifactId>
156-
</exclusion>
157-
</exclusions>
158158
</dependency>
159159

160160
<dependency>
@@ -166,12 +166,6 @@
166166
<groupId>org.testcontainers</groupId>
167167
<artifactId>testcontainers</artifactId>
168168
<scope>test</scope>
169-
<exclusions>
170-
<exclusion>
171-
<groupId>org.slf4j</groupId>
172-
<artifactId>slf4j-api</artifactId>
173-
</exclusion>
174-
</exclusions>
175169
</dependency>
176170
<dependency>
177171
<groupId>org.seleniumhq.selenium</groupId>
@@ -185,12 +179,7 @@
185179
<version>${selenium.version}</version>
186180
<scope>test</scope>
187181
</dependency>
188-
<dependency>
189-
<groupId>org.slf4j</groupId>
190-
<artifactId>jcl-over-slf4j</artifactId>
191-
<version>${jcl-over-slf4j.version}</version>
192-
<scope>test</scope>
193-
</dependency>
182+
194183
<dependency>
195184
<groupId>ch.qos.logback</groupId>
196185
<artifactId>logback-classic</artifactId>

src/test/java/io/mosparo/client/AbstractMosparoIT.java

Lines changed: 91 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package io.mosparo.client;
22

33
import java.io.File;
4+
import java.io.IOException;
45
import java.net.URL;
56
import java.nio.charset.StandardCharsets;
67
import java.time.Duration;
78
import java.util.HashMap;
89
import java.util.Map;
910
import java.util.logging.Level;
1011

12+
import org.junit.jupiter.api.BeforeAll;
1113
import org.junit.jupiter.api.extension.ExtendWith;
1214
import org.openqa.selenium.By;
1315
import org.openqa.selenium.WebElement;
@@ -40,7 +42,8 @@ abstract class AbstractMosparoIT {
4042

4143
static RemoteWebDriver driver;
4244

43-
static {
45+
@BeforeAll
46+
static void startEnvironment() throws IOException {
4447
environment = new ComposeContainer(new File("src/test/resources/docker-compose.yaml"))
4548
.withExposedService(MOSPARO_WEB_COMPOSE_SERVICE, MOSPARO_WEB_EXPOSED_PORT)
4649
.withExposedService("firefox", 4444);
@@ -51,87 +54,82 @@ abstract class AbstractMosparoIT {
5154
Integer mosparoPort = environment.getServicePort(MOSPARO_WEB_COMPOSE_SERVICE, MOSPARO_WEB_EXPOSED_PORT);
5255
mosparoUrl = "http://" + mosparoHost + ":" + mosparoPort;
5356

54-
try {
55-
// Connecting to selenium container
56-
String firefoxHost = environment.getServiceHost("firefox", 4444);
57-
Integer firefoxPort = environment.getServicePort("firefox", 4444);
58-
URL spec = new URL("http://" + firefoxHost + ":" + firefoxPort + "/wd/hub");
59-
FirefoxOptions options = new FirefoxOptions();
60-
driver = new RemoteWebDriver(spec, options);
61-
driver.setLogLevel(Level.ALL);
62-
63-
// Page: Database
64-
driver.get("http://mosparo_web/setup/database");
65-
new WebDriverWait(driver, Duration.ofSeconds(60)).until(ExpectedConditions.titleIs("Database - mosparo"));
66-
new Select(driver.findElement(By.id("form_system"))).selectByVisibleText("MySQL/MariaDB");
67-
driver.findElement(By.id("form_host")).sendKeys("db");
68-
driver.findElement(By.id("form_port")).clear();
69-
driver.findElement(By.id("form_port")).sendKeys("3306");
70-
driver.findElement(By.id("form_database")).sendKeys("mosparo");
71-
driver.findElement(By.id("form_user")).sendKeys("mosparo");
72-
driver.findElement(By.id("form_password")).sendKeys("password");
73-
scrollIntoViewAndClick(By.cssSelector("button[type='submit']"));
74-
75-
// Page: Other information
76-
new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.titleIs("Other information - mosparo"));
77-
driver.findElement(By.id("form_name")).sendKeys("mosparo");
78-
driver.findElement(By.id("form_emailAddress")).sendKeys("test@mosparo.io");
79-
driver.findElement(By.id("form_password_plainPassword_first")).sendKeys("password");
80-
driver.findElement(By.id("form_password_plainPassword_second")).sendKeys("password");
81-
scrollIntoViewAndClick(By.cssSelector("button[type='submit']"));
82-
83-
// The installation was successfully completed
84-
new WebDriverWait(driver, Duration.ofSeconds(5))
85-
.until(ExpectedConditions.elementToBeClickable(By.linkText("Go to login")));
86-
scrollIntoViewAndClick(By.linkText("Go to login"));
87-
88-
// Page: Login
89-
new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.titleIs("Login - mosparo"));
90-
driver.findElement(By.id("field-email")).sendKeys("test@mosparo.io");
91-
driver.findElement(By.id("field-password")).sendKeys("password");
92-
scrollIntoViewAndClick(By.cssSelector("button[type='submit']"));
93-
94-
// Page: Projects
95-
new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.titleIs("Projects - mosparo"));
96-
scrollIntoViewAndClick(By.xpath("//button[normalize-space()='Create']"));
97-
scrollIntoViewAndClick(By.linkText("Create project"));
98-
99-
// Page: Create project
100-
new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.titleIs("Create project - mosparo"));
101-
driver.findElement(By.id("project_form_name")).sendKeys("tests");
102-
driver.findElement(By.id("project_form_description"))
103-
.sendKeys("Test project for mosparo Java API MosparoDefaultClient");
104-
driver.findElement(By.cssSelector("input[id^='project_form_hosts_']")).sendKeys("*");
105-
scrollIntoViewAndClick(By.cssSelector("button[type='submit']"));
106-
107-
// Page: Create project › Select design
108-
new WebDriverWait(driver, Duration.ofSeconds(5))
109-
.until(ExpectedConditions.titleIs("Create project › Select design - mosparo"));
110-
scrollIntoViewAndClick(By.cssSelector("button[type='submit']"));
111-
112-
// Page: Create project › Enable security features
113-
new WebDriverWait(driver, Duration.ofSeconds(5))
114-
.until(ExpectedConditions.titleIs("Create project › Enable security features - mosparo"));
115-
scrollIntoViewAndClick(By.cssSelector("button[type='submit']"));
116-
117-
// Page: Create project › Connection details
118-
new WebDriverWait(driver, Duration.ofSeconds(5))
119-
.until(ExpectedConditions.titleIs("Create project › Connection details - mosparo"));
120-
projectUuid = driver.findElement(By.id("projectUuid")).getDomAttribute("value");
121-
projectPublicKey = driver.findElement(By.id("projectPublicKey")).getDomAttribute("value");
122-
projectPrivateKey = driver.findElement(By.id("projectPrivateKey")).getDomAttribute("value");
123-
124-
// Generate the demo form
125-
String html = IOUtils.resourceToString("index.html", StandardCharsets.UTF_8,
126-
AbstractMosparoIT.class.getClassLoader());
127-
html = html.replace("#projectUuid#", projectUuid);
128-
html = html.replace("#projectPublicKey#", projectPublicKey);
129-
ContainerState website = environment.getContainerByServiceName("website").orElseThrow();
130-
website.copyFileToContainer(Transferable.of(html), "/usr/share/nginx/html/index.html");
131-
132-
} catch (Exception e) {
133-
throw new RuntimeException(e);
134-
}
57+
// Connecting to selenium container
58+
String firefoxHost = environment.getServiceHost("firefox", 4444);
59+
Integer firefoxPort = environment.getServicePort("firefox", 4444);
60+
URL spec = new URL("http://" + firefoxHost + ":" + firefoxPort + "/wd/hub");
61+
FirefoxOptions options = new FirefoxOptions();
62+
driver = new RemoteWebDriver(spec, options);
63+
driver.setLogLevel(Level.ALL);
64+
65+
// Page: Database
66+
driver.get("http://mosparo_web/setup/database");
67+
new WebDriverWait(driver, Duration.ofSeconds(60)).until(ExpectedConditions.titleIs("Database - mosparo"));
68+
new Select(driver.findElement(By.id("form_system"))).selectByVisibleText("MySQL/MariaDB");
69+
driver.findElement(By.id("form_host")).sendKeys("db");
70+
driver.findElement(By.id("form_port")).clear();
71+
driver.findElement(By.id("form_port")).sendKeys("3306");
72+
driver.findElement(By.id("form_database")).sendKeys("mosparo");
73+
driver.findElement(By.id("form_user")).sendKeys("mosparo");
74+
driver.findElement(By.id("form_password")).sendKeys("password");
75+
scrollIntoViewAndClick(By.cssSelector("button[type='submit']"));
76+
77+
// Page: Other information
78+
new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.titleIs("Other information - mosparo"));
79+
driver.findElement(By.id("form_name")).sendKeys("mosparo");
80+
driver.findElement(By.id("form_emailAddress")).sendKeys("test@mosparo.io");
81+
driver.findElement(By.id("form_password_plainPassword_first")).sendKeys("password");
82+
driver.findElement(By.id("form_password_plainPassword_second")).sendKeys("password");
83+
scrollIntoViewAndClick(By.cssSelector("button[type='submit']"));
84+
85+
// The installation was successfully completed
86+
new WebDriverWait(driver, Duration.ofSeconds(5))
87+
.until(ExpectedConditions.elementToBeClickable(By.linkText("Go to login")));
88+
scrollIntoViewAndClick(By.linkText("Go to login"));
89+
90+
// Page: Login
91+
new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.titleIs("Login - mosparo"));
92+
driver.findElement(By.id("field-email")).sendKeys("test@mosparo.io");
93+
driver.findElement(By.id("field-password")).sendKeys("password");
94+
scrollIntoViewAndClick(By.cssSelector("button[type='submit']"));
95+
96+
// Page: Projects
97+
new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.titleIs("Projects - mosparo"));
98+
scrollIntoViewAndClick(By.xpath("//button[normalize-space()='Create']"));
99+
scrollIntoViewAndClick(By.linkText("Create project"));
100+
101+
// Page: Create project
102+
new WebDriverWait(driver, Duration.ofSeconds(5)).until(ExpectedConditions.titleIs("Create project - mosparo"));
103+
driver.findElement(By.id("project_form_name")).sendKeys("tests");
104+
driver.findElement(By.id("project_form_description"))
105+
.sendKeys("Test project for mosparo Java API MosparoDefaultClient");
106+
driver.findElement(By.cssSelector("input[id^='project_form_hosts_']")).sendKeys("*");
107+
scrollIntoViewAndClick(By.cssSelector("button[type='submit']"));
108+
109+
// Page: Create project › Select design
110+
new WebDriverWait(driver, Duration.ofSeconds(5))
111+
.until(ExpectedConditions.titleIs("Create project › Select design - mosparo"));
112+
scrollIntoViewAndClick(By.cssSelector("button[type='submit']"));
113+
114+
// Page: Create project › Enable security features
115+
new WebDriverWait(driver, Duration.ofSeconds(5))
116+
.until(ExpectedConditions.titleIs("Create project › Enable security features - mosparo"));
117+
scrollIntoViewAndClick(By.cssSelector("button[type='submit']"));
118+
119+
// Page: Create project › Connection details
120+
new WebDriverWait(driver, Duration.ofSeconds(5))
121+
.until(ExpectedConditions.titleIs("Create project › Connection details - mosparo"));
122+
projectUuid = driver.findElement(By.id("projectUuid")).getDomAttribute("value");
123+
projectPublicKey = driver.findElement(By.id("projectPublicKey")).getDomAttribute("value");
124+
projectPrivateKey = driver.findElement(By.id("projectPrivateKey")).getDomAttribute("value");
125+
126+
// Generate the demo form
127+
String html = IOUtils.resourceToString("index.html", StandardCharsets.UTF_8,
128+
AbstractMosparoIT.class.getClassLoader());
129+
html = html.replace("#projectUuid#", projectUuid);
130+
html = html.replace("#projectPublicKey#", projectPublicKey);
131+
ContainerState website = environment.getContainerByServiceName("website").orElseThrow();
132+
website.copyFileToContainer(Transferable.of(html), "/usr/share/nginx/html/index.html");
135133
}
136134

137135
static void scrollIntoViewAndClick(By locator) {
@@ -157,9 +155,18 @@ Map<String, Object> visitForm(Map<String, Object> input) {
157155
new Actions(driver).moveToElement(element).click().perform();
158156

159157
// Retrieve the tokens
160-
String mosparoSubmitToken = driver.findElement(By.name("_mosparo_submitToken")).getDomAttribute("value");
158+
WebElement submitTokenElement = driver.findElement(By.name("_mosparo_submitToken"));
159+
new WebDriverWait(driver, Duration.ofSeconds(2)).until(
160+
ExpectedConditions.not(ExpectedConditions.domAttributeToBe(submitTokenElement, "value", "")));
161+
162+
String mosparoSubmitToken = submitTokenElement.getDomAttribute("value");
161163
formData.put("_mosparo_submitToken", mosparoSubmitToken);
162-
String mosparoValidationToken = driver.findElement(By.name("_mosparo_validationToken")).getDomAttribute("value");
164+
165+
WebElement validationTokenElement = driver.findElement(By.name("_mosparo_validationToken"));
166+
new WebDriverWait(driver, Duration.ofSeconds(2)).until(
167+
ExpectedConditions.not(ExpectedConditions.domAttributeToBe(validationTokenElement, "value", "")));
168+
169+
String mosparoValidationToken = validationTokenElement.getDomAttribute("value");
163170
formData.put("_mosparo_validationToken", mosparoValidationToken);
164171

165172
// Submit form

0 commit comments

Comments
 (0)