Skip to content

Commit

Permalink
Merge pull request #94 from christophd/issue/75/add-maven-repository
Browse files Browse the repository at this point in the history
fix(#75): Support custom Maven repository configuration
  • Loading branch information
christophd authored Apr 28, 2020
2 parents 049255b + 5df897d commit 52bfb6f
Show file tree
Hide file tree
Showing 31 changed files with 1,296 additions and 65 deletions.
176 changes: 145 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
![build](https://github.com/citrusframework/yaks/workflows/build/badge.svg?branch=master)

# YAKS

![logo][1]

# YAKS

YAKS Cloud-Native BDD testing or simply: Yet Another Kubernetes Service

* [Getting started](#getting-started)
* [Installation](#installation)
* [Running](#running-the-hello-world)
* [Steps](#steps)
* [Citrus Steps](#citrus-steps)
* Apache Camel Steps
* [Camel K Steps](#camel-k-steps)
* [JDBC Steps](#jdbc-steps)
* Http Steps
* Open API Steps
* Kafka Steps
* Jms Steps
* [Custom Steps](#custom-steps)
* [Runtime configuration](#runtime-configuration)
* [Add custom runtime dependencies](#add-custom-runtime-dependencies)
* [Add custom Maven repositories](#add-custom-maven-repositories)
* [Pre/Post scripts](#prepos-scripts)
* [Reporting options](#reporting-options)
* [For YAKS developers](#for-yaks-developers)

## Getting Started

YAKS allows you to perform Could-Native BDD testing. Cloud-Native here means that your tests execute within a POD in a
Expand Down Expand Up @@ -212,7 +232,12 @@ hello Passed

You can now change the test to use more complex steps and run it again with `./yaks test hello.feature`.

### Using Citrus features
## Steps

Each line in a BDD feature file is backed by a step implementation that covers the actual runtime logic executed. YAKS
provides a set of out-of-the-box step implementations that you can just use in your feature file.

### Citrus steps

The Citrus framework provides a lot of features and predefined steps that can be used to write feature files.

Expand All @@ -233,7 +258,7 @@ Feature: Integration Works
```

### Using Camel K steps
### Camel K steps

If the subject under test is a Camel K integration, you can leverage the YAKS Camel K bindings
that provide useful steps for checking the status of integrations.
Expand All @@ -248,7 +273,7 @@ For example:

The Camel K extension library is provided by default in YAKS.

### Using JDBC steps
### JDBC steps

YAKS provides a library that allows to execute SQL actions on relational DBs (limited to PostgreSQL for this POC).

Expand All @@ -257,7 +282,7 @@ You can find examples of JDBC steps in the [examples](/examples/jdbc.feature) fi
There's also an example that uses [JDBC and REST together](/examples/task-api.feature) and targets the
[Syndesis TODO App](https://github.com/syndesisio/todo-example) database.

### Using custom steps
### Custom steps

It's often useful to plug some custom steps into the testing environment. Custom steps help keeping the
tests short and self-explanatory and at the same time help teams to add generic assertions that are meaningful in their
Expand All @@ -280,7 +305,41 @@ This happens transparently to the user.

The local library can also be uploaded to the Snap Minio server prior to running the test, using the `yaks upload` command.

### Adding custom runtime dependencies
## Runtime configuration

There are several runtime options that you can set in order to configure which tests to run for instance. Each test directory
can have its own `yaks-config.yaml` configuration file that holds the runtime options for this specific test suite.

```yaml
config:
runtime:
cucumber:
tags:
- "not @ignored"
glue:
- "org.citrusframework.yaks"
- "com.company.steps.custom"
```
The sample above uses different runtime options for Cucumber to specify a tag filter and some custom glue packages that
should be loaded. The given runtime options will be set as environment variables in the YAKS runtime pod.
You can also specify the Cucumber options that get passed to the Cucumber runtime.
```yaml
config:
runtime:
cucumber:
options: "--strict --monochrome --glue org.citrusframework.yaks"
```
Also we can make use of command line options when using the `yaks` binary.

```bash
$ yaks test hello-world.feature --tag @regression --glue org.citrusframework.yaks
```

### Add custom runtime dependencies

The YAKS testing framework provides a base runtime image that holds all required libraries and artifacts to execute tests. You may need to add
additional runtime dependencies though in order to extend the framework capabilities.
Expand Down Expand Up @@ -396,41 +455,96 @@ dependencies:
You can add the configuration file when running the test via `yaks` CLI like follows:

```bash
$ yaks test --settings yaks.dependency.yaml camel-route.feature
$ yaks test --settings yaks.settings.yaml camel-route.feature
```

## Runtime configuration
### Add custom Maven repositories

There are several runtime options that you can set in order to configure which tests to run for instance. Each test directory
can have its own `yaks-config.yaml` configuration file that holds the runtime options for this specific test suite.
When adding custom runtime dependencies those artifacts might not be available on the public central Maven repository.
Instead you may need to add a custom repository that holds your artifacts.

```yaml
config:
runtime:
cucumber:
tags:
- "not @ignored"
glue:
- "org.citrusframework.yaks"
- "com.company.steps.custom"
You can do this with several configuration options:

#### Add Maven repository via System property or environment setting

You can add repositories also by specifying the repositories as command line parameter when running the test via `yaks` CLI.

```bash
$ yaks test --maven-repository jboss-ea=https://repository.jboss.org/nexus/content/groups/ea/ my.feature
```

The sample above uses different runtime options for Cucumber to specify a tag filter and some custom glue packages that
should be loaded. The given runtime options will be set as environment variables in the YAKS runtime pod.
This will add a environment setting in the YAKS runtime container and the repository will be added to the Maven runtime project model.

You can also specify the Cucumber options that get passed to the Cucumber runtime.
#### Add Maven repository via property file

YAKS supports adding Maven repository information to a property file called `yaks.properties`. The dependency is added through
Maven repository id and url in the property file using a common property key prefix `yaks.repository.`

```properties
# Maven repositories
yaks.repository.central=https://repo.maven.apache.org/maven2/
yaks.repository.jboss-ea=https://repository.jboss.org/nexus/content/groups/ea/
```

You can add the property file when running the test via `yaks` CLI like follows:

```bash
$ yaks test --settings yaks.properties my.feature
```

#### Add Maven repository via configuration file

More complex repository configuration might require to add a configuration file as `.yaml` or `.json`.

The configuration file is able to declare multiple repositories:

```yaml
config:
runtime:
cucumber:
options: "--strict --monochrome --glue org.citrusframework.yaks"
repositories:
- repository:
id: "central"
name: "Maven Central"
url: "https://repo.maven.apache.org/maven2/"
releases:
enabled: "true"
updatePolicy: "daily"
snapshots:
enabled: "false"
- repository:
id: "jboss-ea"
name: "JBoss Community Early Access Release Repository"
url: "https://repository.jboss.org/nexus/content/groups/ea/"
layout: "default"
```

Also we can make use of command line options when using the `yaks` binary.
```json
{
"repositories": [
{
"id": "central",
"name": "Maven Central",
"url": "https://repo.maven.apache.org/maven2/",
"releases": {
"enabled": "true",
"updatePolicy": "daily"
},
"snapshots": {
"enabled": "false"
}
},
{
"id": "jboss-ea",
"name": "JBoss Community Early Access Release Repository",
"url": "https://repository.jboss.org/nexus/content/groups/ea/",
"layout": "default"
}
]
}
```

You can add the configuration file when running the test via `yaks` CLI like follows:

```bash
$ yaks test hello-world.feature --tag @regression --glue org.citrusframework.yaks
$ yaks test --settings yaks.settings.yaml my.feature
```

## Pre/Post scripts
Expand All @@ -441,7 +555,7 @@ You can run scripts before/after a test group. Just add your commands to the `ya
config:
namespace:
temporary: false
autoremove: true
autoRemove: true
pre:
- script: prepare.sh
- run: echo Start!
Expand Down Expand Up @@ -540,7 +654,7 @@ Test results: Total: 5, Passed: 5, Failed: 0, Skipped: 0
classpath:org/citrusframework/yaks/test3.feature:3: Passed
```

## For YAKS Developers
## For YAKS developers

Requirements:
- Go 1.12+
Expand Down
5 changes: 5 additions & 0 deletions examples/jitpack/jitpack.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: JitPack steps extension

Scenario: Use custom steps
Given My steps are loaded
Then I can do whatever I want!
6 changes: 6 additions & 0 deletions examples/jitpack/yaks-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
config:
runtime:
cucumber:
glue:
- "org.citrusframework.yaks"
- "dev.yaks.testing.standard"
19 changes: 19 additions & 0 deletions examples/jitpack/yaks.settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repositories:
- repository:
id: "central"
name: "Maven Central"
url: "https://repo.maven.apache.org/maven2/"
releases:
enabled: "true"
updatePolicy: "daily"
snapshots:
enabled: "false"
- repository:
id: "jitpack.io"
name: "JitPack Repository"
url: "https://jitpack.io"
dependencies:
- dependency:
groupId: com.github.citrusframework
artifactId: yaks-step-extension
version: "0.0.1"
7 changes: 6 additions & 1 deletion examples/yaks.properties
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
yaks.dependency.camel-groovy=org.apache.camel:camel-groovy:@camel.version@
# Maven repositories
yaks.repository.central=https://repo.maven.apache.org/maven2/
yaks.repository.jboss-ea=https://repository.jboss.org/nexus/content/groups/ea/

# Additional dependencies
yaks.dependency.camel-groovy=org.apache.camel:camel-groovy:@camel.version@
20 changes: 20 additions & 0 deletions examples/yaks.settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
{
"repositories": [
{
"id": "central",
"name": "Maven Central",
"url": "https://repo.maven.apache.org/maven2/",
"releases": {
"enabled": "true",
"updatePolicy": "daily"
},
"snapshots": {
"enabled": "false"
}
},
{
"id": "jboss-ea",
"name": "JBoss Community Early Access Release Repository",
"url": "https://repository.jboss.org/nexus/content/groups/ea/",
"layout": "default"
}
],
"dependencies": [
{
"groupId": "org.apache.camel",
Expand Down
17 changes: 16 additions & 1 deletion examples/yaks.settings.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
repositories:
- repository:
id: "central"
name: "Maven Central"
url: "https://repo.maven.apache.org/maven2/"
releases:
enabled: "true"
updatePolicy: "daily"
snapshots:
enabled: "false"
- repository:
id: "jboss-ea"
name: "JBoss Community Early Access Release Repository"
url: "https://repository.jboss.org/nexus/content/groups/ea/"
layout: "default"
dependencies:
- dependency:
groupId: org.apache.camel
artifactId: camel-groovy
version: "@camel.version@"
version: "@camel.version@"
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public final class ExtensionSettings {
public static final String DEPENDENCIES_SETTING_KEY = "yaks.dependencies";
public static final String DEPENDENCIES_SETTING_ENV = "YAKS_DEPENDENCIES";

public static final String REPOSITORIES_SETTING_KEY = "yaks.repositories";
public static final String REPOSITORIES_SETTING_ENV = "YAKS_REPOSITORIES";

/**
* Prevent instantiation of utility class.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@

import java.util.List;

import org.citrusframework.yaks.maven.extension.configuration.FileBasedDependencyLoader;
import org.citrusframework.yaks.maven.extension.configuration.cucumber.FeatureTagsDependencyLoader;
import org.citrusframework.yaks.maven.extension.configuration.env.EnvironmentSettingDependencyLoader;
import org.citrusframework.yaks.maven.extension.configuration.properties.SystemPropertyDependencyLoader;
import org.apache.maven.execution.ProjectExecutionEvent;
import org.apache.maven.execution.ProjectExecutionListener;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Resource;
import org.citrusframework.yaks.maven.extension.configuration.FileBasedDependencyLoader;
import org.citrusframework.yaks.maven.extension.configuration.cucumber.FeatureTagsDependencyLoader;
import org.citrusframework.yaks.maven.extension.configuration.env.EnvironmentSettingDependencyLoader;
import org.citrusframework.yaks.maven.extension.configuration.properties.SystemPropertyDependencyLoader;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
Expand All @@ -40,7 +40,7 @@
* @author Christoph Deppisch
*/
@Component( role = ProjectExecutionListener.class )
public class ResourceInjectionListener implements ProjectExecutionListener {
public class ProjectModelEnricher implements ProjectExecutionListener {

@Requirement
private Logger logger;
Expand Down Expand Up @@ -77,7 +77,6 @@ private void injectTestResources(Model projectModel) {
*/
private void injectProjectDependencies(Model projectModel) throws LifecycleExecutionException {
logger.info("Add dynamic project dependencies ...");

List<Dependency> dependencyList = projectModel.getDependencies();
dependencyList.addAll(new FileBasedDependencyLoader().load(projectModel.getProperties(), logger));
dependencyList.addAll(new SystemPropertyDependencyLoader().load(projectModel.getProperties(), logger));
Expand Down
Loading

0 comments on commit 52bfb6f

Please sign in to comment.