Skip to content

Commit

Permalink
Enhance Quarkus sample project
Browse files Browse the repository at this point in the history
- Add Selenium UI tests
  • Loading branch information
christophd committed Nov 29, 2023
1 parent 139048d commit 3c2ccf0
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 6 deletions.
Binary file modified demo/sample-quarkus/food-market-app-demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions demo/sample-quarkus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@
<artifactId>citrus-sql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-selenium</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.citrusframework</groupId>
<artifactId>citrus-validation-text</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import org.citrusframework.http.client.HttpClient;
import org.citrusframework.kafka.endpoint.KafkaEndpoint;
import org.citrusframework.mail.server.MailServer;
import org.citrusframework.selenium.endpoint.SeleniumBrowser;
import org.citrusframework.selenium.endpoint.SeleniumBrowserBuilder;
import org.citrusframework.spi.BindToRegistry;
import org.openqa.selenium.remote.Browser;

import static org.citrusframework.actions.StopServerAction.Builder.stop;
import static org.citrusframework.container.SequenceAfterSuite.Builder.afterSuite;
Expand All @@ -28,7 +31,7 @@ public class CitrusEndpointConfig {
@BindToRegistry
public HttpClient httpClient() {
return http().client()
.requestUrl("http://localhost:8081/api")
.requestUrl("http://localhost:8081")
.build();
}

Expand Down Expand Up @@ -100,6 +103,13 @@ public ObjectMapper mapper() {
.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_EMPTY, JsonInclude.Include.NON_EMPTY));
}

@BindToRegistry
public SeleniumBrowser browser() {
return new SeleniumBrowserBuilder()
.type(Browser.HTMLUNIT.browserName())
.build();
}

@BindToRegistry
public AfterSuite afterSuiteActions() {
return afterSuite()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
@QuarkusTest
@CitrusSupport
@CitrusConfiguration(classes = { CitrusEndpointConfig.class })
class FoodMarketApplicationTest {
class FoodMarketEventingTest {

@CitrusEndpoint
private KafkaEndpoint products;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
@QuarkusTest
@CitrusSupport
@CitrusConfiguration(classes = { CitrusEndpointConfig.class })
class FoodMarketApiResourceTest {
class FoodMarketRestApiTest {

@CitrusEndpoint
private HttpClient httpClient;
Expand All @@ -60,7 +60,7 @@ void shouldAddBooking() {
t.when(http()
.client(httpClient)
.send()
.post("/bookings")
.post("/api/bookings")
.message()
.contentType(APPLICATION_JSON)
.body(marshal(booking)));
Expand All @@ -86,7 +86,7 @@ void shouldAddSupply() {
t.when(http()
.client(httpClient)
.send()
.post("/supplies")
.post("/api/supplies")
.message()
.contentType(APPLICATION_JSON)
.body(marshal(supply)));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.camel.demo;

import io.quarkus.test.junit.QuarkusTest;
import org.apache.camel.demo.model.Booking;
import org.apache.camel.demo.model.Product;
import org.citrusframework.TestCaseRunner;
import org.citrusframework.annotations.CitrusConfiguration;
import org.citrusframework.annotations.CitrusEndpoint;
import org.citrusframework.annotations.CitrusResource;
import org.citrusframework.quarkus.CitrusSupport;
import org.citrusframework.selenium.endpoint.SeleniumBrowser;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;

import static org.citrusframework.container.FinallySequence.Builder.doFinally;
import static org.citrusframework.selenium.actions.SeleniumActionBuilder.selenium;

@QuarkusTest
@CitrusSupport
@CitrusConfiguration(classes = { CitrusEndpointConfig.class })
class FoodMarketUiTest {

@CitrusEndpoint
private SeleniumBrowser browser;

@CitrusResource
private TestCaseRunner t;

private final String homeUrl = "http://localhost:8081";;

@Test
void indexPage() {
t.given(selenium()
.browser(browser)
.start());

t.given(doFinally().actions(
selenium()
.browser(browser)
.stop()));

t.when(selenium()
.browser(browser)
.navigate(homeUrl));

t.then(selenium()
.browser(browser)
.find()
.element(By.tagName("h1"))
.text("Food Market demo"));
}

@Test
void shouldCreateBooking() {
Product product = new Product("Peach");
Booking booking = new Booking("browser_client", product, 50, 0.99D);

t.given(selenium()
.browser(browser)
.start());

t.given(doFinally().actions(
selenium()
.browser(browser)
.stop()));

t.when(selenium()
.browser(browser)
.navigate(homeUrl));

t.then(selenium()
.browser(browser)
.select("booking")
.element(By.id("type")));

t.then(selenium()
.browser(browser)
.setInput()
.element(By.id("name"))
.value(booking.getClient()));

t.then(selenium()
.browser(browser)
.setInput()
.element(By.id("product"))
.value(booking.getProduct().getName()));

t.then(selenium()
.browser(browser)
.setInput()
.element(By.id("amount"))
.value(booking.getAmount().toString()));

t.then(selenium()
.browser(browser)
.setInput()
.element(By.id("price"))
.value(booking.getPrice().toString()));

t.then(selenium()
.browser(browser)
.click()
.element(By.id("save")));
}

@Test
void shouldCreateSupply() {
Product product = new Product("Peach");
Booking booking = new Booking("browser_client", product, 50, 0.99D);

t.given(selenium()
.browser(browser)
.start());

t.given(doFinally().actions(
selenium()
.browser(browser)
.stop()));

t.when(selenium()
.browser(browser)
.navigate(homeUrl));

t.then(selenium()
.browser(browser)
.select("supply")
.element(By.id("type")));

t.then(selenium()
.browser(browser)
.setInput()
.element(By.id("name"))
.value(booking.getClient()));

t.then(selenium()
.browser(browser)
.setInput()
.element(By.id("product"))
.value(booking.getProduct().getName()));

t.then(selenium()
.browser(browser)
.setInput()
.element(By.id("amount"))
.value(booking.getAmount().toString()));

t.then(selenium()
.browser(browser)
.setInput()
.element(By.id("price"))
.value(booking.getPrice().toString()));

t.then(selenium()
.browser(browser)
.click()
.element(By.id("save")));
}

}
2 changes: 1 addition & 1 deletion demo/sample-quarkus/src/test/resources/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,4 @@
}
}
}
}
}

0 comments on commit 3c2ccf0

Please sign in to comment.