Skip to content

Commit

Permalink
Cucumber Http Response Glue
Browse files Browse the repository at this point in the history
  • Loading branch information
nhojpatrick committed Dec 13, 2022
1 parent fd40afe commit c61c7a0
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 0 deletions.
4 changes: 4 additions & 0 deletions all-glue/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
<groupId>com.github.nhojpatrick.cucumber</groupId>
<artifactId>nhojpatrick-cucumber-http-request-glue</artifactId>
</dependency>
<dependency>
<groupId>com.github.nhojpatrick.cucumber</groupId>
<artifactId>nhojpatrick-cucumber-http-response-glue</artifactId>
</dependency>
<dependency>
<groupId>com.github.nhojpatrick.cucumber</groupId>
<artifactId>nhojpatrick-cucumber-json-map-glue</artifactId>
Expand Down
1 change: 1 addition & 0 deletions all-glue/src/main/java11/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
requires org.junit.jupiter.api;
requires org.slf4j;
requires transitive com.github.nhojpatrick.cucumber.http.request.glue;
requires transitive com.github.nhojpatrick.cucumber.http.response.glue;
requires transitive com.github.nhojpatrick.cucumber.json.map.glue;
requires transitive com.github.nhojpatrick.cucumber.json.transform.glue;
requires transitive com.github.nhojpatrick.cucumber.state.glue;
Expand Down
5 changes: 5 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
<artifactId>nhojpatrick-cucumber-http-response</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.nhojpatrick.cucumber</groupId>
<artifactId>nhojpatrick-cucumber-http-response-glue</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.nhojpatrick.cucumber</groupId>
<artifactId>nhojpatrick-cucumber-json-all</artifactId>
Expand Down
1 change: 1 addition & 0 deletions http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<module>request</module>
<module>request-glue</module>
<module>response</module>
<module>response-glue</module>
</modules>
<!--repositories / -->
<!--pluginRepositories / -->
Expand Down
85 changes: 85 additions & 0 deletions http/response-glue/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?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 / -->
<modelVersion>4.0.0</modelVersion>
<!--parent / -->
<parent>
<groupId>com.github.nhojpatrick.cucumber</groupId>
<artifactId>nhojpatrick-cucumber</artifactId>
<version>1.0.2-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<!--groupId / -->
<!--artifactId / -->
<artifactId>nhojpatrick-cucumber-http-response-glue</artifactId>
<!--packaging / -->
<!--name / -->
<!--version / -->
<!--description / -->
<!--url / -->
<!--prerequisites / -->
<!--issueManagement / -->
<!--ciManagement / -->
<!--inceptionYear / -->
<!--mailingLists / -->
<!--developers / -->
<!--contributors / -->
<!--licenses / -->
<!--scm / -->
<!--organization / -->
<!--build / -->
<!--profiles / -->
<!--modules / -->
<!--repositories / -->
<!--pluginRepositories / -->
<!--dependencies / -->
<dependencies>
<dependency>
<groupId>com.github.nhojpatrick.cucumber</groupId>
<artifactId>nhojpatrick-cucumber-http-constants</artifactId>
</dependency>
<dependency>
<groupId>com.github.nhojpatrick.cucumber</groupId>
<artifactId>nhojpatrick-cucumber-http-response</artifactId>
</dependency>
<dependency>
<groupId>com.github.nhojpatrick.cucumber</groupId>
<artifactId>nhojpatrick-cucumber-state</artifactId>
</dependency>
<dependency>
<groupId>com.github.nhojpatrick.hamcrest</groupId>
<artifactId>nhojpatrick-hamcrest-lang</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>
<!--reports (Deprecated) / -->
<!--reporting / -->
<!--dependencyManagement / -->
<!--distributionManagement / -->
<!--properties / -->
<properties>
<project.Automatic-Module-Name>com.github.nhojpatrick.cucumber.http.response.glue</project.Automatic-Module-Name>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.github.nhojpatrick.cucumber.http.response.steps;

import com.github.nhojpatrick.cucumber.core.exceptions.IllegalKeyException;
import com.github.nhojpatrick.cucumber.core.exceptions.IllegalTypeClassException;
import com.github.nhojpatrick.cucumber.core.exceptions.TypeMismatchException;
import com.github.nhojpatrick.cucumber.http.core.model.HttpResponse;
import com.github.nhojpatrick.cucumber.state.RunState;
import com.github.nhojpatrick.cucumber.state.exceptions.NullRunStateException;
import com.github.nhojpatrick.cucumber.state.validation.RunStateValidatorFactory;
import com.google.inject.Inject;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.cucumber.java.en.Given;

import static com.github.nhojpatrick.cucumber.http.constants.HttpConstants.HTTP_RESPONSE_BODY;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;

public class HttpResponseSteps {

@SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "Accepted will look at changing")
private final RunState runState;

@Inject
public HttpResponseSteps(final RunState runState) {
this.runState = runState;
}

@Given("http response status code of {int}")
public void httpResponseStatusCode(final int expectedStatusCode)
throws IllegalKeyException,
IllegalTypeClassException,
NullRunStateException,
TypeMismatchException {

RunStateValidatorFactory.getInstance()
.withValue(HTTP_RESPONSE_BODY)
.verify(this.runState);

final HttpResponse httpResponse = this.runState.get(HTTP_RESPONSE_BODY, HttpResponse.class);
final int actualStatusCode = httpResponse.getStatusCode();

assertThat("Unexpected http status code", actualStatusCode, is(equalTo(expectedStatusCode)));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.github.nhojpatrick.cucumber.http.response.steps;

public class ModuleInfoHack {
}
10 changes: 10 additions & 0 deletions http/response-glue/src/main/java11/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module com.github.nhojpatrick.cucumber.http.response.glue {
requires com.github.nhojpatrick.cucumber.http.constants;
requires com.google.guice;
requires io.cucumber.java;
requires org.hamcrest;
requires org.junit.jupiter.api;
requires org.slf4j;
requires transitive com.github.nhojpatrick.cucumber.http.response;
requires transitive com.github.nhojpatrick.cucumber.state;
}
7 changes: 7 additions & 0 deletions http/response-glue/src/test/java11/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
open module com.github.nhojpatrick.cucumber.http.response.glue.test {
requires com.github.nhojpatrick.cucumber.http.response.glue;
requires org.apache.logging.log4j;
requires org.hamcrest;
requires transitive org.junit.jupiter.api;
requires transitive org.junit.jupiter.engine;
}
19 changes: 19 additions & 0 deletions http/response-glue/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="TestConsole %-5p %l %m%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="com.github.nhojpatrick.cucumber.http.response.steps" level="debug">
<AppenderRef ref="Console"/>
</Logger>
<Logger name="com.github.nhojpatrick" level="info">
<AppenderRef ref="Console"/>
</Logger>
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,11 @@
<artifactId>nhojpatrick-cucumber-http-response</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.nhojpatrick.cucumber</groupId>
<artifactId>nhojpatrick-cucumber-http-response-glue</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.nhojpatrick.cucumber</groupId>
<artifactId>nhojpatrick-cucumber-json-all</artifactId>
Expand Down

0 comments on commit c61c7a0

Please sign in to comment.