Skip to content

Commit 0a3896f

Browse files
authored
[JAVA-46835] Created new module rest-assured-2 and moved code from re… (#18570)
1 parent 93c49b2 commit 0a3896f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+719
-201
lines changed

testing-modules/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<module>parallel-tests-junit</module>
5050
<module>powermock</module>
5151
<module>rest-assured</module>
52+
<module>rest-assured-2</module>
5253
<module>rest-testing</module>
5354
<module>selenide</module>
5455
<module>selenium</module>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*.class
2+
3+
#folders#
4+
/target
5+
/neoDb*
6+
/data
7+
/src/main/webapp/WEB-INF/classes
8+
*/META-INF/*
9+
10+
# Packaged files #
11+
*.jar
12+
*.war
13+
*.ear
14+
15+
.externalToolBuilders
16+
.settings
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>rest-assured-2</artifactId>
7+
<version>1.0</version>
8+
<name>rest-assured-2</name>
9+
10+
<parent>
11+
<groupId>com.baeldung</groupId>
12+
<artifactId>parent-boot-3</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<relativePath>../../parent-boot-3</relativePath>
15+
</parent>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-starter-web</artifactId>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-json</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-test</artifactId>
29+
<scope>test</scope>
30+
</dependency>
31+
<dependency>
32+
<groupId>jakarta.servlet</groupId>
33+
<artifactId>jakarta.servlet-api</artifactId>
34+
<version>${jakarta.servlet-api.version}</version>
35+
<scope>provided</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.eclipse.jetty</groupId>
39+
<artifactId>jetty-security</artifactId>
40+
<version>${jetty.version}</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.eclipse.jetty</groupId>
44+
<artifactId>jetty-servlet</artifactId>
45+
<version>${jetty.version}</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.eclipse.jetty</groupId>
49+
<artifactId>jetty-servlets</artifactId>
50+
<version>${jetty.version}</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.eclipse.jetty</groupId>
54+
<artifactId>jetty-io</artifactId>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.eclipse.jetty</groupId>
58+
<artifactId>jetty-http</artifactId>
59+
<version>${jetty.version}</version>
60+
</dependency>
61+
<dependency>
62+
<groupId>org.eclipse.jetty</groupId>
63+
<artifactId>jetty-server</artifactId>
64+
<version>${jetty.version}</version>
65+
</dependency>
66+
<dependency>
67+
<groupId>org.eclipse.jetty</groupId>
68+
<artifactId>jetty-util</artifactId>
69+
<version>${jetty.version}</version>
70+
</dependency>
71+
<dependency>
72+
<groupId>org.apache.httpcomponents.core5</groupId>
73+
<artifactId>httpcore5</artifactId>
74+
<version>${httpcore5.version}</version>
75+
</dependency>
76+
<dependency>
77+
<groupId>org.apache.commons</groupId>
78+
<artifactId>commons-lang3</artifactId>
79+
</dependency>
80+
<dependency>
81+
<groupId>javax.mail</groupId>
82+
<artifactId>mail</artifactId>
83+
<version>${javax.mail.version}</version>
84+
</dependency>
85+
<dependency>
86+
<groupId>com.fasterxml.jackson.core</groupId>
87+
<artifactId>jackson-annotations</artifactId>
88+
</dependency>
89+
<dependency>
90+
<groupId>com.fasterxml.jackson.core</groupId>
91+
<artifactId>jackson-databind</artifactId>
92+
</dependency>
93+
<dependency>
94+
<groupId>org.apache.httpcomponents.client5</groupId>
95+
<artifactId>httpclient5</artifactId>
96+
<version>${httpclient5.version}</version>
97+
</dependency>
98+
<dependency>
99+
<groupId>org.wiremock</groupId>
100+
<artifactId>wiremock-standalone</artifactId>
101+
<version>${wiremock.version}</version>
102+
</dependency>
103+
<dependency>
104+
<groupId>commons-collections</groupId>
105+
<artifactId>commons-collections</artifactId>
106+
<version>${commons-collections.version}</version>
107+
</dependency>
108+
<!-- Rest Assured Dependencies -->
109+
<dependency>
110+
<groupId>io.rest-assured</groupId>
111+
<artifactId>rest-assured</artifactId>
112+
<version>${rest-assured.version}</version>
113+
<scope>test</scope>
114+
</dependency>
115+
<dependency>
116+
<groupId>io.rest-assured</groupId>
117+
<artifactId>spring-mock-mvc</artifactId>
118+
<version>${rest-assured.version}</version>
119+
<scope>test</scope>
120+
</dependency>
121+
<dependency>
122+
<groupId>io.rest-assured</groupId>
123+
<artifactId>rest-assured-all</artifactId>
124+
<version>${rest-assured.version}</version>
125+
<scope>test</scope>
126+
</dependency>
127+
<dependency>
128+
<groupId>com.github.scribejava</groupId>
129+
<artifactId>scribejava-apis</artifactId>
130+
<version>${scribejava.version}</version>
131+
<scope>test</scope>
132+
</dependency>
133+
<dependency>
134+
<groupId>org.skyscreamer</groupId>
135+
<artifactId>jsonassert</artifactId>
136+
<version>${json.assert.version}</version>
137+
<scope>test</scope>
138+
</dependency>
139+
<dependency>
140+
<groupId>net.javacrumbs.json-unit</groupId>
141+
<artifactId>json-unit-assertj</artifactId>
142+
<version>${json.unit.version}</version>
143+
<scope>test</scope>
144+
</dependency>
145+
<dependency>
146+
<groupId>net.javacrumbs.json-unit</groupId>
147+
<artifactId>json-unit</artifactId>
148+
<version>${json.unit.version}</version>
149+
<scope>test</scope>
150+
</dependency>
151+
<dependency>
152+
<groupId>uk.org.webcompere</groupId>
153+
<artifactId>model-assert</artifactId>
154+
<version>${model.assert.version}</version>
155+
</dependency>
156+
<dependency>
157+
<groupId>uk.co.datumedge</groupId>
158+
<artifactId>hamcrest-json</artifactId>
159+
<version>${hamcrest.json.version}</version>
160+
</dependency>
161+
<dependency>
162+
<groupId>io.rest-assured</groupId>
163+
<artifactId>json-schema-validator</artifactId>
164+
<version>${rest-assured.version}</version>
165+
<scope>test</scope>
166+
</dependency>
167+
</dependencies>
168+
169+
<build>
170+
<plugins>
171+
<plugin>
172+
<groupId>org.apache.maven.plugins</groupId>
173+
<artifactId>maven-compiler-plugin</artifactId>
174+
<configuration>
175+
<compilerArgs>
176+
<arg>-parameters</arg>
177+
</compilerArgs>
178+
</configuration>
179+
</plugin>
180+
</plugins>
181+
</build>
182+
183+
<properties>
184+
<jakarta.servlet-api.version>6.1.0</jakarta.servlet-api.version>
185+
<javax.mail.version>1.4.7</javax.mail.version>
186+
<jetty.version>9.4.0.v20161208</jetty.version>
187+
<commons-collections.version>3.2.2</commons-collections.version>
188+
<httpcore5.version>5.2.5</httpcore5.version>
189+
<httpclient5.version>5.2.3</httpclient5.version>
190+
<wiremock.version>3.9.1</wiremock.version>
191+
<scribejava.version>2.5.3</scribejava.version>
192+
<rest-assured.version>5.5.0</rest-assured.version>
193+
<json.assert.version>1.5.3</json.assert.version>
194+
<json.unit.version>3.4.1</json.unit.version>
195+
<model.assert.version>1.0.3</model.assert.version>
196+
<hamcrest.json.version>0.2</hamcrest.json.version>
197+
</properties>
198+
199+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.restassured;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(Application.class, args);
11+
}
12+
13+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.baeldung.restassured.controller;
2+
3+
import java.io.File;
4+
import java.io.FileInputStream;
5+
import java.io.FileNotFoundException;
6+
import java.util.Set;
7+
import java.util.UUID;
8+
9+
import jakarta.servlet.http.Cookie;
10+
import jakarta.servlet.http.HttpServletResponse;
11+
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.core.io.InputStreamResource;
14+
import org.springframework.core.io.Resource;
15+
import org.springframework.http.HttpHeaders;
16+
import org.springframework.http.HttpStatus;
17+
import org.springframework.http.MediaType;
18+
import org.springframework.http.ResponseEntity;
19+
import org.springframework.web.bind.annotation.GetMapping;
20+
import org.springframework.web.bind.annotation.PathVariable;
21+
import org.springframework.web.bind.annotation.PostMapping;
22+
import org.springframework.web.bind.annotation.RequestBody;
23+
import org.springframework.web.bind.annotation.ResponseStatus;
24+
import org.springframework.web.bind.annotation.RestController;
25+
26+
import com.baeldung.restassured.model.Movie;
27+
import com.baeldung.restassured.service.AppService;
28+
29+
@RestController
30+
public class AppController {
31+
32+
@Autowired
33+
AppService appService;
34+
35+
@GetMapping("/movies")
36+
public ResponseEntity<?> getMovies() {
37+
38+
Set<Movie> result = appService.getAll();
39+
40+
return ResponseEntity.ok()
41+
.body(result);
42+
}
43+
44+
@PostMapping("/movie")
45+
@ResponseStatus(HttpStatus.CREATED)
46+
public Movie addMovie(@RequestBody Movie movie) {
47+
48+
appService.add(movie);
49+
return movie;
50+
}
51+
52+
@GetMapping("/movie/{id}")
53+
public ResponseEntity<?> getMovie(@PathVariable int id) {
54+
55+
Movie movie = appService.findMovie(id);
56+
if (movie == null) {
57+
return ResponseEntity.badRequest()
58+
.body("Invalid movie id");
59+
}
60+
61+
return ResponseEntity.ok(movie);
62+
}
63+
64+
@GetMapping("/welcome")
65+
public ResponseEntity<?> welcome(HttpServletResponse response) {
66+
67+
HttpHeaders headers = new HttpHeaders();
68+
headers.add(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
69+
headers.add("sessionId", UUID.randomUUID()
70+
.toString());
71+
72+
Cookie cookie = new Cookie("token", "some-token");
73+
cookie.setDomain("localhost");
74+
75+
response.addCookie(cookie);
76+
77+
return ResponseEntity.noContent()
78+
.headers(headers)
79+
.build();
80+
}
81+
82+
@GetMapping("/download/{id}")
83+
public ResponseEntity<Resource> getFile(@PathVariable int id) throws FileNotFoundException {
84+
85+
File file = appService.getFile(id);
86+
87+
if (file == null) {
88+
return ResponseEntity.notFound()
89+
.build();
90+
}
91+
92+
InputStreamResource resource = new InputStreamResource(new FileInputStream(file));
93+
94+
return ResponseEntity.ok()
95+
.contentLength(file.length())
96+
.contentType(MediaType.parseMediaType("application/octet-stream"))
97+
.body(resource);
98+
}
99+
100+
}

0 commit comments

Comments
 (0)