Skip to content

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
co-mmer authored Oct 25, 2024
1 parent cd1ff61 commit 3bdf903
Show file tree
Hide file tree
Showing 21 changed files with 810 additions and 430 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/build-and-analyze.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Java CI with Maven and SonarCloud

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
types: [ opened, synchronize, reopened ]

jobs:
build-and-analyze:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'zulu'

- name: Cache Maven and SonarCloud packages
uses: actions/cache@v4
with:
path: |
~/.m2
~/.sonar/cache
key: ${{ runner.os }}-m2-sonar-${{ hashFiles('**/pom.xml') }}

- name: Build and analyze with Maven
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=co-mmer_aaa-mockmvc -PcoverageReport
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

# Changelog

## [1.2.0]

### Added

- **TestAnswer**: Introduced for accessing the results of HTTP requests.
- New method `answer()` in TestAct for retrieving the result of the executed request.

---

## [1.1.0]

### Added
Expand All @@ -23,6 +32,8 @@
- `assertStatusIsAccessUnauthorized()`
- `assertStatusInRange(int minStatusCode, int maxStatusCode);`

---

## [1.0.0]

- Initial release of the **AAA-MockMvc**
Expand Down
118 changes: 115 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<table border="0" cellspacing="0" cellpadding="0">
<table>
<tr>
<td><img src="./images/aaa-mockmvc-icon.png" alt="icon" style="vertical-align: middle;"/></td>
<td><img src="./images/aaa-mockmvc-icon.png" alt="aaa-mockmvc-icon" style="vertical-align: middle;"/></td>
<td><h1>AAA-MockMvc</h1></td>
</tr>
</table>

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=co-mmer_aaa-mockmvc&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=co-mmer_aaa-mockmvc)
[![SQALE Rating](https://sonarcloud.io/api/project_badges/measure?project=co-mmer_aaa-mockmvc&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=co-mmer_aaa-mockmvc)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=co-mmer_aaa-mockmvc&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=co-mmer_aaa-mockmvc)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=co-mmer_aaa-mockmvc&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=co-mmer_aaa-mockmvc)
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=co-mmer_aaa-mockmvc&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=co-mmer_aaa-mockmvc)

## Overview

This project provides a framework for structuring unit tests following the AAA (Arrange, Act,
Expand Down Expand Up @@ -37,7 +43,7 @@ documentation of the classes.
<dependency>
<groupId>io.github.co-mmer</groupId>
<artifactId>aaa-mockmvc</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -262,6 +268,9 @@ In the provided library, every test follows the AAA structure using the followin
2. **Act**: Perform the operation (e.g., make the API request).
3. **Assert**: Validate the result (e.g., check HTTP status, response content).

Optionally, the result of the request can be accessed using the `answer()` method, allowing for
further examination and validation of the response.

### Arrange Section

<details>
Expand Down Expand Up @@ -1009,6 +1018,109 @@ specific `ResultMatcher` that verifies if the specified cookie is present in the

</details>

### Answer Section

<details>
<summary>Answer ResultActions</summary>

### Retrieve Result Actions

This method retrieves the ResultActions from the executed HTTP request, allowing detailed
examination and validation of the response.

```
var answer = get()
...
.act()
.actPerform()
.answer()
.answerAsResultActions();
```

---

</details>

<details>
<summary>Answer String</summary>

### Retrieve Response as String

This method retrieves the content of the HTTP response as a String.

```
var answer = get()
...
.act()
.actPerform()
.answer()
.answerAsString();
```

---

</details>

<details>
<summary>Answer Byte</summary>

### Retrieve Response as Byte Array

This method retrieves the content of the HTTP response as a byte array.

```
var answer = get()
...
.act()
.actPerform()
.answer()
.answerAsByte();
```

---

</details>

<details>
<summary>Answer Header</summary>

### Retrieve Specific Response Header

This method retrieves the value of a specific response header.

```
var answer = get()
...
.act()
.actPerform()
.answer()
.answerHeader(KEY);
```

---

</details>


<details>
<summary>Answer Void</summary>

### Execute and Discard Response Content

This method retrieves the result of the HTTP request without returning any content. It is used when
the response is not needed.

```
get()
...
.act()
.actPerform()
.answer()
.answerVoid();
```

</details>

---

## Examples
Expand Down
8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.co-mmer</groupId>
<artifactId>aaa-mockmvc</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<packaging>jar</packaging>

<name>AAA-MockMvc</name>
Expand Down Expand Up @@ -51,9 +51,9 @@

<properties>
<java.version>17</java.version>
<sonar.organization>com.github.co-mmer</sonar.organization>
<sonar.organization>co-mmer</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.projectKey>aaa-mockmvc</sonar.projectKey>
<sonar.projectKey>co-mmer_aaa-mockmvc</sonar.projectKey>
</properties>

<dependencies>
Expand Down Expand Up @@ -135,6 +135,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.10.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down Expand Up @@ -178,6 +179,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.12</version>
<executions>
<execution>
<id>prepare-agent</id>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.github.co_mmer.aaamockmvc.test.web.act;

import io.github.co_mmer.aaamockmvc.test.web.act.exception.TestActException;
import io.github.co_mmer.aaamockmvc.test.web.answer.TestAnswer;
import io.github.co_mmer.aaamockmvc.test.web.asserts.TestAssert;
import org.springframework.lang.Nullable;
import org.springframework.test.web.servlet.ResultActions;

/**
* This interface represents a contract for performing actions and obtaining results from HTTP
Expand All @@ -17,59 +16,25 @@
public interface TestAct2 {

/**
* Retrieves the {@link ResultActions} from the executed HTTP request.
* Retrieves the {@link TestAssert} instance for asserting the response of the HTTP request.
*
* @return the result actions of the request
* @throws TestActException if an error occurs while retrieving the result actions
* @since 1.0.0
*/
ResultActions resultActions() throws TestActException;

/**
* Retrieves the response content as a string from the executed HTTP request.
*
* @return the response content as a string
* @throws TestActException if an error occurs while retrieving the response content
* @since 1.0.0
*/
String resultAsString() throws TestActException;

/**
* Retrieves the response content as a byte array from the executed HTTP request.
*
* @return the response content as a byte array
* @throws TestActException if an error occurs while retrieving the response content
* @since 1.0.0
*/
byte[] resultAsByte() throws TestActException;

/**
* Executes the HTTP request without returning any content.
* <p>This method allows for further validation of the result using various assertion methods,
* enabling comprehensive checks on the HTTP response to ensure it meets expected criteria.
*
* @throws TestActException if an error occurs during the execution
* @since 1.0.0
*/
void resultVoid() throws TestActException;

/**
* Retrieves the value of a specified response header from the executed HTTP request.
*
* @param key the name of the response header to retrieve
* @return the value of the response header, or {@code null} if the header is not present
* @throws TestActException if an error occurs while retrieving the header value
* @return a {@code TestAssert} instance for asserting the result of the request
* @throws TestActException if an error occurs while performing the request
* @since 1.0.0
*/
@Nullable
String resultHeader(String key) throws TestActException;
TestAssert asserts() throws TestActException;

/**
* Returns an instance of {@link TestAssert} for asserting the response of the HTTP request.
* Retrieves the {@link TestAnswer} instance for the executed HTTP request.
*
* <p>This method allows for further validation of the result using various assertion methods.
* <p>This method provides access to the response content and other aspects of the request's
* outcome, enabling further validation and examination of the HTTP response.
*
* @return a {@code TestAssert} instance for asserting the result of the request
* @throws TestActException if an error occurs while performing the request
* @since 1.0.0
* @return a {@code TestAnswer} instance for accessing the result of the request
* @since 1.2.0
*/
TestAssert asserts() throws TestActException;
TestAnswer answer();
}
Loading

0 comments on commit 3bdf903

Please sign in to comment.