-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ea36b58
Showing
11 changed files
with
535 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# This workflow will build a Java project with Maven | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven | ||
|
||
name: Java CI with Maven | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
repository_dispatch: | ||
types: contracts changed | ||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
java: [17] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
path: main | ||
- name: Set up JDK ${{ matrix.java }} | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'oracle' | ||
java-version: ${{ matrix.java }} | ||
- name: Build with Maven | ||
working-directory: main | ||
run: mvn test package jacoco:report | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: jacoco coverage report | ||
path: /home/runner/work/specmatic-api-coding-test/specmatic-api-coding-test/main/target/site/jacoco |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
target/* | ||
build/* | ||
.DS_Store | ||
lib/* | ||
*.iml | ||
*.idea | ||
.specmatic | ||
.vscode/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Specmatic Coding Test | ||
|
||
### Prerequisites: | ||
JDK 17+ | ||
|
||
### Instructions: | ||
|
||
### 1. Clone this repository to your local machine. | ||
From a terminal, run the following command: | ||
```bash | ||
mvn clean test | ||
``` | ||
You should see two failing tests: | ||
```bash | ||
[ERROR] Tests run: 2, Failures: 2, Errors: 0, Skipped: 0 | ||
[INFO] | ||
[INFO] ------------------------------------------------------------------------ | ||
[INFO] BUILD FAILURE | ||
[INFO] ------------------------------------------------------------------------ | ||
``` | ||
Your objective is to get these two tests to pass by following the rest of the instructions. | ||
|
||
### 2. Implement REST endpoints: | ||
This is a Kotlin based Spring Boot application. | ||
You are expected to implement the following endpoints to the **Products** controller: | ||
|
||
#### A. POST /products | ||
Implement a **POST** route ```/products``` which accepts a json payload. | ||
|
||
##### Request Schema: | ||
```json | ||
{ | ||
"name": "(string)", | ||
"type": "(string enum)", | ||
"inventory": "(integer)" | ||
} | ||
``` | ||
The ```type``` field is an enum which can take the following values: | ||
```yaml | ||
- gadget | ||
- book | ||
- food | ||
- other | ||
``` | ||
On successful creation of a product entity, the ```id``` of the created product should be returned: | ||
##### Response Schema: | ||
```json | ||
{ | ||
"id": "(integer)" | ||
} | ||
``` | ||
| ||
| ||
| ||
|
||
#### B. GET /products | ||
Implement a **GET** route ```/products``` which accepts an **optional** query parameter called ```type```, which is an enum of the following values: | ||
```yaml | ||
- gadget | ||
- book | ||
- food | ||
- other | ||
``` | ||
and returns a list of products with following schema. | ||
##### Response Schema: | ||
```json | ||
[ | ||
{ | ||
"id": "(integer)", | ||
"name": "(string)", | ||
"type": "(string enum)", | ||
"inventory": "(integer)" | ||
} | ||
] | ||
``` | ||
|
||
### Note: | ||
- You are **not** expected to use a database. | ||
You are free to use any datastructures like maps, lists, etc to store and retrieve products. | ||
|
||
- Writing any unit tests that you deem fit will be appreciated. | ||
|
||
- Please do not alter the following files: | ||
- ContractTest.kt | ||
- products_api.yaml | ||
- specmatic.json | ||
|
||
### 3. Once you have both the tests passing, commit your changes and push to this repository. | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
<?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> | ||
|
||
<groupId>com.store</groupId> | ||
<artifactId>specmatic-api-coding-test</artifactId> | ||
<version>1.0</version> | ||
|
||
<properties> | ||
<kotlin.version>1.9.21</kotlin.version> | ||
<maven.compiler>17</maven.compiler> | ||
<specmatic.version>1.3.19</specmatic.version> | ||
<spring.boot.version>3.2.5</spring.boot.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
<version>${spring.boot.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<version>${spring.boot.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-validation</artifactId> | ||
<version>${spring.boot.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<version>${spring.boot.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>${spring.boot.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.5.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>5.5.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.platform</groupId> | ||
<artifactId>junit-platform-runner</artifactId> | ||
<version>1.6.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.platform</groupId> | ||
<artifactId>junit-platform-engine</artifactId> | ||
<version>1.6.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>in.specmatic</groupId> | ||
<artifactId>junit5-support</artifactId> | ||
<version>${specmatic.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-reflect</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib-jdk8</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-test-junit5</artifactId> | ||
<version>${kotlin.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<testResources> | ||
<testResource> | ||
<directory>src/test/java</directory> | ||
<excludes> | ||
<exclude>**/*.java</exclude> | ||
</excludes> | ||
</testResource> | ||
<testResource> | ||
<directory>src/test/resources</directory> | ||
</testResource> | ||
</testResources> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<version>${kotlin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>compile</id> | ||
<phase>process-sources</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>test-compile</id> | ||
<phase>process-test-sources</phase> | ||
<goals> | ||
<goal>test-compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<jvmTarget>17</jvmTarget> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<encoding>UTF-8</encoding> | ||
<source>${maven.compiler}</source> | ||
<target>${maven.compiler}</target> | ||
<compilerArgument>-Werror</compilerArgument> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.2</version> | ||
<configuration> | ||
<argLine>@{argLine} -Dfile.encoding=UTF-8</argLine> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>2.3.4.RELEASE</version> | ||
<configuration> | ||
<fork>true</fork> | ||
<mainClass>com.store.Application</mainClass> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
<version>0.8.8</version> | ||
<executions> | ||
<execution> | ||
<id>jacoco-initialize</id> | ||
<goals> | ||
<goal>prepare-agent</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>report</id> | ||
<phase>prepare-package</phase> | ||
<goals> | ||
<goal>report</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<excludes> | ||
<exclude>**/DB.*</exclude> | ||
<exclude>**/APIKeyAuthFilter.*</exclude> | ||
</excludes> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Oops, something went wrong.