Skip to content

Commit e90d2b3

Browse files
committed
L7
1 parent 1df06f3 commit e90d2b3

6 files changed

Lines changed: 90 additions & 0 deletions

File tree

JavaCore2.iml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<orderEntry type="library" name="Maven: org.codehaus.mojo:animal-sniffer-annotations:1.14" level="project" />
4545
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.11.0" level="project" />
4646
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
47+
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
4748
<orderEntry type="library" name="Maven: commons-io:commons-io:2.6" level="project" />
4849
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.13.2" level="project" />
4950
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-core:2.13.2" level="project" />

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
<version>3.141.59</version>
5353
</dependency>
5454

55+
<dependency>
56+
<groupId>com.google.code.gson</groupId>
57+
<artifactId>gson</artifactId>
58+
<version>2.8.6</version>
59+
</dependency>
60+
5561
<dependency>
5662
<groupId>commons-io</groupId>
5763
<artifactId>commons-io</artifactId>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package apiTest;
2+
3+
import com.google.gson.Gson;
4+
import helpers.Token;
5+
import io.restassured.http.ContentType;
6+
import io.restassured.path.json.JsonPath;
7+
import io.restassured.response.Response;
8+
import models.CreatePlaylistRequest;
9+
import io.restassured.response.Response;
10+
import models.CreatePlaylistResponse;
11+
import org.testng.Assert;
12+
import org.testng.annotations.BeforeMethod;
13+
import org.testng.annotations.Test;
14+
import static io.restassured.RestAssured.*;
15+
16+
public class PlaylistTests {
17+
private String token;
18+
@BeforeMethod
19+
public void init(){
20+
token = Token.retrieveToken();
21+
}
22+
23+
// private final String TOKEN = "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjMwMCwiaXNzIjoiaHR0cHM6Ly9rb2VsYXBwLnRlc3Rwcm8uaW8vYXBpL21lIiwiaWF0IjoxNTkwMDI2NzQwLCJleHAiOjE1OTA2MzE1NDAsIm5iZiI6MTU5MDAyNjc0MCwianRpIjoiQ1ZydTBCUTdPVHlydFpmTSJ9.kRvurIf5uDpIiWn0DoJBBUoT1taBu_k3jqDznMlZtDQ";
24+
25+
@Test
26+
public void playlistTests_CreatePlaylist_PlaylistCreated(){
27+
String[] rules = {};
28+
var playlist = new CreatePlaylistRequest("AAAtttAAA",rules);
29+
var requestBody = new Gson().toJson(playlist);
30+
31+
Response response = given()
32+
.baseUri("https://koelapp.testpro.io/")
33+
.header("Authorization",token)
34+
.basePath("api/playlist")
35+
.contentType(ContentType.JSON)
36+
.body(requestBody)
37+
.when()
38+
.post()
39+
.then()
40+
.statusCode(200)
41+
.extract()
42+
.response();
43+
44+
JsonPath jsonPath = response.jsonPath();
45+
CreatePlaylistResponse createdPlaylist = jsonPath.getObject("$",CreatePlaylistResponse.class);
46+
Assert.assertEquals(playlist.name,createdPlaylist.name);
47+
Assert.assertEquals(createdPlaylist.songs.length,0);
48+
}
49+
50+
}

src/test/java/helpers/Token.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package helpers;
2+
3+
public class Token {
4+
public static String retrieveToken(){
5+
String token="";
6+
//Place your code here
7+
return token;
8+
}
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package models;
2+
3+
public class CreatePlaylistRequest {
4+
public String name;
5+
public String[] rules;
6+
7+
public CreatePlaylistRequest(String name, String[] rules) {
8+
this.name = name;
9+
this.rules = rules;
10+
}
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package models;
2+
3+
public class CreatePlaylistResponse {
4+
public String name;
5+
public int id;
6+
public String[] songs;
7+
8+
public CreatePlaylistResponse(String name, int id, String[] songs) {
9+
this.name = name;
10+
this.id = id;
11+
this.songs = songs;
12+
}
13+
}

0 commit comments

Comments
 (0)