Skip to content

Commit

Permalink
feat : adds Integration Test
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Mar 10, 2024
1 parent e4533ae commit 90f3ca1
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 73 deletions.
146 changes: 73 additions & 73 deletions httpClients/boot-restclient/pom.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.0-M2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.restclient</groupId>
<artifactId>boot-restclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>boot-restclient</name>
<description>Demo project for Spring Boot</description>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.0-M2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.restclient</groupId>
<artifactId>boot-restclient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>boot-restclient</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>21</java.version>
<springdoc-openapi.version>2.3.0</springdoc-openapi.version>
<spotless.version>2.43.0</spotless.version>
</properties>
<properties>
<java.version>21</java.version>
<springdoc-openapi.version>2.3.0</springdoc-openapi.version>
<spotless.version>2.43.0</spotless.version>
</properties>

<dependencies>
<dependency>
Expand All @@ -34,47 +34,47 @@
<artifactId>jaxb-runtime</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc-openapi.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc-openapi.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless.version}</version>
<configuration>
<java>
<googleJavaFormat>
<version>1.18.1</version>
<style>AOSP</style>
</googleJavaFormat>
<importOrder />
<removeUnusedImports />
<formatAnnotations />
<version>1.19.2</version>
<style>AOSP</style>
</googleJavaFormat>
<importOrder/>
<removeUnusedImports/>
<formatAnnotations/>
</java>
</configuration>
<executions>
Expand All @@ -86,28 +86,28 @@
</execution>
</executions>
</plugin>
</plugins>
</build>
</plugins>
</build>

<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.example.restclient.bootrestclient.web.controllers;

import static org.hamcrest.CoreMatchers.is;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;

@SpringBootTest
@AutoConfigureMockMvc
class PostControllerIntTest {

@Autowired private MockMvc mockMvc;

@Test
void shouldFindPostById() throws Exception {

this.mockMvc
.perform(get("/api/posts/{id}", 1))
.andExpect(status().isOk())
.andExpect(jsonPath("$.id", is(1)))
.andExpect(
jsonPath(
"$.title",
is(
"sunt aut facere repellat provident occaecati excepturi optio reprehenderit")))
.andExpect(jsonPath("$.userId", is(1)))
.andExpect(
jsonPath(
"$.body",
is(
"quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto")));
}
}

0 comments on commit 90f3ca1

Please sign in to comment.