Skip to content

Commit

Permalink
java: Implement Query object
Browse files Browse the repository at this point in the history
  • Loading branch information
mpkorstanje committed Apr 4, 2024
1 parent 5e8f67e commit bb95b6e
Show file tree
Hide file tree
Showing 37 changed files with 2,733 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/release-mvn.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Release Maven

on:
push:
branches: [release/*]

jobs:
publish-mvn:
name: Publish Maven Package
runs-on: ubuntu-latest
environment: Release
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
cache: 'maven'
- uses: cucumber/action-publish-mvn@v2.0.0
with:
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg-passphrase: ${{ secrets.GPG_PASSPHRASE }}
nexus-username: cukebot
nexus-password: ${{ secrets.SONATYPE_PASSWORD }}
working-directory: java
34 changes: 34 additions & 0 deletions .github/workflows/test-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: test-java

on:
push:
branches:
- main
- renovate/**
pull_request:
branches:
- main
workflow_call:

jobs:
test-java:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
java: ["11", "17"]

steps:
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: "zulu"
java-version: ${{ matrix.java }}
cache: "maven"

- run: mvn verify
working-directory: java

32 changes: 32 additions & 0 deletions .github/workflows/test-testdata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: test-testdata

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test-testdata:
runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
cache: 'npm'
cache-dependency-path: testdata/package-lock.json

- run: npm ci
working-directory: testdata

- name: check repository is not dirty
run: "[[ -z $(git status --porcelain) ]]"

- name: show diff
if: ${{ failure() }}
run: git status --porcelain
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
*.iml
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added
- java: implementation of query ([#39](https://github.com/cucumber/query/pull/39))

## [12.0.2] - 2024-03-26
### Fixed
- Correct repo URL in `package.json`
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,25 @@ status of a step, a scenario or an entire file.
| `getDocumentResults(uri: string): messages.ITestResult[]` | | | | ||
| `getStepMatchArguments(uri: string, lineNumber: number): messages.IStepMatchArgument[]` | | | | ||
| `getGherkinStep(gherkinStepId: string): messages.GherkinDocument.Feature.IStep` | | | | ||
| `countMostSevereTestStepResultStatus()` | | || | |
| `countTestCasesStarted()` | | || | |
| `findAllPickles()` | | || | |
| `findAllPickleSteps()` | | || | |
| `findAllTestCaseStarted()` | | || | |
| `findAllTestSteps()` | | || | |
| `findAllTestCaseStartedGroupedByFeature()` | | || | |
| `findFeatureBy(TestCaseStarted)` | | || | |
| `findMostSevereTestStepResulBy(TestCaseStarted)` | | || | |
| `findNameOf(Pickle, NamingStrategy)` | | || | |
| `findPickleBy(TestCaseStarted)` | | || | |
| `findPickleStepBy(TestStep testStep)` | | || | |
| `findStepBy(PickleStep pickleStep)` | | || | |
| `findTestCaseBy(TestCaseStarted)` | | || | |
| `findTestCaseDurationBy(TestCaseStarted)` | | || | |
| `findTestCaseFinishedBy(TestCaseStarted)` | | || | |
| `findTestRunDuration()` | | || | |
| `findTestRunFinished()` | | || | |
| `findTestRunStarted()` | | || | |
| `findTestStepBy(TestStepFinished)` | | || | |
| `findTestStepsFinishedBy(TestCaseStarted)` | | || | |
| `findTestStepFinishedAndTestStepBy(TestCaseStarted)` | | || | |
1 change: 1 addition & 0 deletions java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
94 changes: 94 additions & 0 deletions java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-parent</artifactId>
<version>4.2.0</version>
</parent>

<artifactId>query</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Cucumber Query</name>
<description>Query messages</description>
<url>https://github.com/cucumber/query</url>

<properties>
<project.Automatic-Module-Name>io.cucumber.query</project.Automatic-Module-Name>
<project.build.outputTimestamp>1711217894</project.build.outputTimestamp>
</properties>

<scm>
<connection>scm:git:git://github.com/cucumber/query.git</connection>
<developerConnection>scm:git:git@github.com:cucumber/query.git</developerConnection>
<url>git://github.com/cucumber/query.git</url>
<tag>HEAD</tag>
</scm>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.17.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>messages</artifactId>
<version>[24.0.0,25.0.0)</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.25.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
90 changes: 90 additions & 0 deletions java/src/main/java/io/cucumber/query/GherkinDocumentElements.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package io.cucumber.query;

import io.cucumber.messages.types.Examples;
import io.cucumber.messages.types.Feature;
import io.cucumber.messages.types.GherkinDocument;
import io.cucumber.messages.types.Rule;
import io.cucumber.messages.types.Scenario;
import io.cucumber.messages.types.TableRow;

import java.util.Objects;
import java.util.Optional;

import static java.util.Objects.requireNonNull;

/**
* A structure containing all ancestors of a given element.
* <p>
* This works without any ordering because Gherkins document
* structure is simple enough to hard code.
*/
class GherkinDocumentElements {
private final GherkinDocument document;
private final Feature feature;
private final Rule rule;
private final Scenario scenario;
private final Examples examples;
private final TableRow example;
private final Integer examplesIndex;
private final Integer exampleIndex;

GherkinDocumentElements(GherkinDocument document, Feature feature, Rule rule, Scenario scenario) {
this(document, feature, rule, scenario, null, null, null, null);
}

GherkinDocumentElements(GherkinDocument document, Feature feature, Rule rule, Scenario scenario, Integer examplesIndex, Examples examples, Integer exampleIndex, TableRow example) {
this.document = requireNonNull(document);
this.feature = feature;
this.rule = rule;
this.scenario = scenario;
this.examplesIndex = examplesIndex;
this.examples = examples;
this.exampleIndex = exampleIndex;
this.example = example;
}

GherkinDocument document() {
return document;
}

Optional<Feature> feature() {
return Optional.ofNullable(feature);
}

Optional<Rule> rule() {
return Optional.ofNullable(rule);
}

Optional<Scenario> scenario() {
return Optional.ofNullable(scenario);
}

Optional<Examples> examples() {
return Optional.ofNullable(examples);
}

Optional<TableRow> example() {
return Optional.ofNullable(example);
}

Optional<Integer> examplesIndex() {
return Optional.ofNullable(examplesIndex);
}

Optional<Integer> exampleIndex() {
return Optional.ofNullable(exampleIndex);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GherkinDocumentElements that = (GherkinDocumentElements) o;
return document.equals(that.document) && feature.equals(that.feature) && Objects.equals(rule, that.rule) && scenario.equals(that.scenario) && Objects.equals(examples, that.examples) && Objects.equals(example, that.example) && Objects.equals(examplesIndex, that.examplesIndex) && Objects.equals(exampleIndex, that.exampleIndex);
}

@Override
public int hashCode() {
return Objects.hash(document, feature, rule, scenario, examples, example, examplesIndex, exampleIndex);
}
}
Loading

0 comments on commit bb95b6e

Please sign in to comment.