Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added codestart #119

Merged
merged 2 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>2.0-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,32 @@
package com.vaadin.flow.quarkus.it;

import io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language;
import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;
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)
.setupStandaloneExtensionTest("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,56 @@
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 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)
.setupStandaloneExtensionTest("com.vaadin:vaadin-quarkus")
.putData("vaadin-flow-codestart.vaadinVersion",
System.getProperty("vaadin.platform.version", "24.0.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/"),
checkContains("frontend/generated/"),
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,56 @@
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 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)
.setupStandaloneExtensionTest("com.vaadin:vaadin-quarkus")
.putData("vaadin-flow-codestart.vaadinVersion", "24.1-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/"),
checkContains("frontend/generated/"),
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 jakarta.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 jakarta.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 jakarta.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