Skip to content

Commit

Permalink
feat: added codestart (#119) (#122)
Browse files Browse the repository at this point in the history
Added a codestart that provides a Flow application with an example view.
Closes #112
  • Loading branch information
mcollovati authored May 15, 2023
1 parent eeea5ed commit 485c48e
Show file tree
Hide file tree
Showing 26 changed files with 684 additions and 0 deletions.
61 changes: 61 additions & 0 deletions integration-tests/codestarts/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-quarkus-integration-tests</artifactId>
<version>1.1-SNAPSHOT</version>
</parent>

<artifactId>vaadin-quarkus-codestarts-tests</artifactId>
<name>Vaadin Quarkus - Codestarts tests</name>
<packaging>jar</packaging>

<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<dependencies>

<!-- Test dependencies -->
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-quarkus</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devtools-testing</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.vaadin.flow.quarkus.it;

import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.RepositoryBase;
import org.assertj.core.api.SoftAssertions;

import static org.assertj.core.api.Assertions.assertThat;

final class CodestartTestUtils {

static void assertThatHasVaadinBom(Model pom, SoftAssertions soft) {
soft.assertThat(pom.getDependencyManagement().getDependencies())
.filteredOn(dep -> "com.vaadin".equals(dep.getGroupId())
&& "vaadin-bom".equals(dep.getArtifactId()))
.singleElement()
.extracting(Dependency::getType, Dependency::getScope)
.contains("pom", "import");
}

static void assertThatHasVaadinQuarkusExtension(Model pom,
SoftAssertions soft) {
soft.assertThat(pom.getDependencies())
.filteredOn(dep -> "com.vaadin".equals(dep.getGroupId())
&& "vaadin-quarkus-extension"
.equals(dep.getArtifactId()))
.hasSize(1);
}

static void assertThatHasProductionProfile(Model pom, SoftAssertions soft) {
soft.assertThat(pom.getProfiles())
.filteredOn(dep -> "production".equals(dep.getId()))
.flatExtracting(profile -> profile.getBuild().getPlugins())
.filteredOn(plugin -> "com.vaadin".equals(plugin.getGroupId())
&& "vaadin-maven-plugin".equals(plugin.getArtifactId()))
.singleElement()
.satisfies(plugin -> assertThat(plugin.getExecutions())
.flatMap(PluginExecution::getGoals)
.contains("prepare-frontend", "build-frontend"))
.extracting(Plugin::getVersion).isEqualTo("${vaadin.version}");
}

static void assertThatHasPreReleaseRepositories(Model pom,
SoftAssertions soft) {
soft.assertThat(pom.getRepositories())
.filteredOn(repo -> "vaadin-prereleases".equals(repo.getId()))
.singleElement().extracting(RepositoryBase::getUrl)
.isEqualTo("https://maven.vaadin.com/vaadin-prereleases/");
soft.assertThat(pom.getPluginRepositories())
.filteredOn(repo -> "vaadin-prereleases".equals(repo.getId()))
.singleElement().extracting(RepositoryBase::getUrl)
.isEqualTo("https://maven.vaadin.com/vaadin-prereleases/");

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.vaadin.flow.quarkus.it;

import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language;
import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;
import io.quarkus.maven.ArtifactKey;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.extension.RegisterExtension;

@EnabledIfSystemProperty(named = "vaadin.platform.version", matches = ".*", disabledReason = "Project should not have dependencies on platform. "
+ "Vaadin platform version should be provided as system property to test code start build.")
public class VaadinExtensionBuildCodestartTest {

@RegisterExtension
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest
.builder().languages(Language.JAVA).standaloneExtensionCatalog()
.extension(ArtifactKey.fromString("com.vaadin:vaadin-quarkus"))
.putData("vaadin-flow-codestart.vaadinVersion",
System.getProperty("vaadin.platform.version"))
.build();

/**
* This test runs the build (with tests) on generated projects for all
* selected languages. To compile the source classes dependencies to vaadin
* platform artifacts are required. Use {@literal vaadin.platform.version}
* system property to provide a valid Vaadin platform version to enable the
* test, for example {@literal -Dvaadin.platform.version=24.1-SNAPSHOT}
*/
@Test
void buildAllProjects() throws Throwable {
codestartTest.buildAllProjects();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.vaadin.flow.quarkus.it;

import java.util.Map;

import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language;
import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;
import io.quarkus.maven.ArtifactKey;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.DefaultModelReader;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static com.vaadin.flow.quarkus.it.CodestartTestUtils.assertThatHasProductionProfile;
import static com.vaadin.flow.quarkus.it.CodestartTestUtils.assertThatHasVaadinBom;
import static com.vaadin.flow.quarkus.it.CodestartTestUtils.assertThatHasVaadinQuarkusExtension;
import static io.quarkus.devtools.testing.SnapshotTesting.checkContains;
import static org.assertj.core.api.SoftAssertions.assertSoftly;

public class VaadinExtensionCodestartTest {

@RegisterExtension
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest
.builder().languages(Language.JAVA).standaloneExtensionCatalog()
.extension(ArtifactKey.fromString("com.vaadin:vaadin-quarkus"))
.putData("vaadin-flow-codestart.vaadinVersion",
System.getProperty("vaadin.platform.version", "23.3.5"))
.build();

@Test
void testApplicationContents() throws Throwable {
// source code
codestartTest.checkGeneratedSource("org.acme.example.MainView");
codestartTest.checkGeneratedSource("org.acme.example.AppConfig");
codestartTest.checkGeneratedSource("org.acme.example.GreetService");

codestartTest.assertThatGeneratedTreeMatchSnapshots(Language.JAVA,
"frontend");

codestartTest.assertThatGeneratedFile(Language.JAVA, ".gitignore")
.satisfies(checkContains("node_modules/")
.andThen(checkContains("frontend/generated/"))
.andThen(checkContains("vite.generated.ts")));

// Check POM file: vaadin-bom, deps, production profile
codestartTest.assertThatGeneratedFile(Language.JAVA, "pom.xml")
.satisfies(pomFile -> {
Model pom = new DefaultModelReader().read(pomFile.toFile(),
Map.of());
assertSoftly(soft -> {
assertThatHasVaadinBom(pom, soft);
assertThatHasVaadinQuarkusExtension(pom, soft);
assertThatHasProductionProfile(pom, soft);
});
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.vaadin.flow.quarkus.it;

import java.util.Map;

import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language;
import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;
import io.quarkus.maven.ArtifactKey;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.DefaultModelReader;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static com.vaadin.flow.quarkus.it.CodestartTestUtils.assertThatHasPreReleaseRepositories;
import static com.vaadin.flow.quarkus.it.CodestartTestUtils.assertThatHasProductionProfile;
import static com.vaadin.flow.quarkus.it.CodestartTestUtils.assertThatHasVaadinBom;
import static com.vaadin.flow.quarkus.it.CodestartTestUtils.assertThatHasVaadinQuarkusExtension;
import static io.quarkus.devtools.testing.SnapshotTesting.checkContains;
import static org.assertj.core.api.SoftAssertions.assertSoftly;

public class VaadinExtensionPreReleaseCodestartTest {

@RegisterExtension
public static QuarkusCodestartTest codestartTest = QuarkusCodestartTest
.builder().languages(Language.JAVA).standaloneExtensionCatalog()
.extension(ArtifactKey.fromString("com.vaadin:vaadin-quarkus"))
.putData("vaadin-flow-codestart.vaadinVersion", "23.3-SNAPSHOT")
.build();

@Test
void testApplicationContents() throws Throwable {
codestartTest.checkGeneratedSource("org.acme.example.MainView");
codestartTest.checkGeneratedSource("org.acme.example.AppConfig");
codestartTest.checkGeneratedSource("org.acme.example.GreetService");

codestartTest.assertThatGeneratedTreeMatchSnapshots(Language.JAVA,
"frontend");

codestartTest.assertThatGeneratedFile(Language.JAVA, ".gitignore")
.satisfies(checkContains("node_modules/")
.andThen(checkContains("frontend/generated/"))
.andThen(checkContains("vite.generated.ts")));

// Check POM file: vaadin-bom, deps, production profile
codestartTest.assertThatGeneratedFile(Language.JAVA, "pom.xml")
.satisfies(pomFile -> {
Model pom = new DefaultModelReader().read(pomFile.toFile(),
Map.of());
assertSoftly(soft -> {
assertThatHasVaadinBom(pom, soft);
assertThatHasVaadinQuarkusExtension(pom, soft);
assertThatHasProductionProfile(pom, soft);
assertThatHasPreReleaseRepositories(pom, soft);
});
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/
themes/
themes/starter-theme/
themes/starter-theme/components/
themes/starter-theme/components/vaadin-text-field.css
themes/starter-theme/styles.css
themes/starter-theme/theme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ilove.quark.us.example;

import com.vaadin.flow.component.page.AppShellConfigurator;
import com.vaadin.flow.theme.Theme;

@Theme("starter-theme")
public class AppConfig implements AppShellConfigurator {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ilove.quark.us.example;

import javax.enterprise.context.Dependent;

@Dependent
public class GreetService {

public String greet(String name) {
if (name == null || name.isEmpty()) {
return "Hello anonymous user";
} else {
return "Hello " + name;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ilove.quark.us.example;

import javax.inject.Inject;

import com.vaadin.flow.component.Key;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.html.Paragraph;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.Route;

/**
* The main view contains a button and a click listener.
*/
@Route("")
public class MainView extends VerticalLayout {

@Inject
GreetService greetService;

public MainView() {
// Use TextField for standard text input
TextField textField = new TextField("Your name");
textField.addThemeName("bordered");

// Button click listeners can be defined as lambda expressions
Button button = new Button("Say hello", e -> {
add(new Paragraph(greetService.greet(textField.getValue())));
});

// Theme variants give you predefined extra styles for components.
// Example: Primary button is more prominent look.
button.addThemeVariants(ButtonVariant.LUMO_PRIMARY);

// You can specify keyboard shortcuts for buttons.
// Example: Pressing enter in this view clicks the Button.
button.addClickShortcut(Key.ENTER);

// Use custom CSS classes to apply styling. This is defined in
// shared-styles.css.
addClassName("centered-content");

add(textField, button);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/
themes/
themes/starter-theme/
themes/starter-theme/components/
themes/starter-theme/components/vaadin-text-field.css
themes/starter-theme/styles.css
themes/starter-theme/theme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ilove.quark.us.example;

import com.vaadin.flow.component.page.AppShellConfigurator;
import com.vaadin.flow.theme.Theme;

@Theme("starter-theme")
public class AppConfig implements AppShellConfigurator {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ilove.quark.us.example;

import javax.enterprise.context.Dependent;

@Dependent
public class GreetService {

public String greet(String name) {
if (name == null || name.isEmpty()) {
return "Hello anonymous user";
} else {
return "Hello " + name;
}
}
}
Loading

0 comments on commit 485c48e

Please sign in to comment.