-
Notifications
You must be signed in to change notification settings - Fork 2
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
thuan
committed
Nov 13, 2023
1 parent
bc67405
commit 10de3d7
Showing
14 changed files
with
545 additions
and
263 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
17 changes: 0 additions & 17 deletions
17
src/test/java/com/spotify/app/album/AlbumRepositoryTest.java
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
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,4 @@ | ||
package com.spotify.app.auth; | ||
|
||
public class AuthServiceTest { | ||
} |
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 |
---|---|---|
|
@@ -12,4 +12,5 @@ | |
//public class CategoryRepositoryTest extends AbstractTestcontainers { | ||
// | ||
// | ||
// | ||
//} |
13 changes: 13 additions & 0 deletions
13
src/test/java/com/spotify/app/follower/FollowerRepositoryTest.java
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,13 @@ | ||
//package com.spotify.app.follower; | ||
// | ||
//import com.spotify.app.AbstractTestcontainers; | ||
//import com.spotify.app.TestConfig; | ||
//import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
//import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
//import org.springframework.context.annotation.Import; | ||
// | ||
//@DataJpaTest | ||
//@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) | ||
//@Import({TestConfig.class}) | ||
//public class FollowerRepositoryTest extends AbstractTestcontainers { | ||
//} |
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 |
---|---|---|
@@ -1,4 +1,64 @@ | ||
package com.spotify.app.journey; | ||
|
||
public class AlbumIT { | ||
import com.github.javafaker.Faker; | ||
import com.spotify.app.AbstractTestcontainers; | ||
import com.spotify.app.dto.AlbumDTO; | ||
import com.spotify.app.dto.request.AlbumRequest; | ||
import com.spotify.app.dto.response.UserNoAssociationResponse; | ||
import com.spotify.app.security.auth.AuthenticationRequest; | ||
import com.spotify.app.security.auth.AuthenticationResponse; | ||
import com.spotify.app.security.jwt.JwtService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.http.*; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@Slf4j | ||
public class AlbumIT extends AbstractTestcontainers { | ||
|
||
private static final String AUTH_PATH = "/api/v1/auth"; | ||
private static final String ALBUM_PATH = "/api/v1/album"; | ||
|
||
@Autowired | ||
private TestRestTemplate restTemplate; | ||
@Autowired | ||
private JwtService jwtService; | ||
|
||
@Test | ||
public void canArtistAddAlbum() { | ||
// given | ||
Faker faker = new Faker(); | ||
String email = "[email protected]"; | ||
String password = "thuan2023"; | ||
AuthenticationRequest authRequest = new AuthenticationRequest(email,password); | ||
AuthenticationResponse authResponse = restTemplate.postForObject(AUTH_PATH+"/authenticate", authRequest, AuthenticationResponse.class); | ||
log.info(String.valueOf(authResponse)); | ||
String token = authResponse.getAccessToken(); | ||
|
||
|
||
Long userId = authResponse.getUser().id(); | ||
|
||
AlbumRequest albumRequest = new AlbumRequest(faker.funnyName().name()); | ||
|
||
HttpHeaders httpHeaders = new HttpHeaders(); | ||
httpHeaders.set(HttpHeaders.ACCEPT , MediaType.APPLICATION_JSON_VALUE); | ||
httpHeaders.set("Authorization", "Bearer " + token); | ||
|
||
HttpEntity<?> request = new HttpEntity<>(albumRequest, httpHeaders); | ||
|
||
String url = String.format(ALBUM_PATH.concat("/%d/add"),userId); | ||
log.info(url); | ||
|
||
// when | ||
ResponseEntity<AlbumDTO> response = restTemplate.exchange(url, HttpMethod.POST ,request, AlbumDTO.class); | ||
|
||
// then | ||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,40 @@ | ||
package com.spotify.app.journey; | ||
|
||
public class CategoryIT { | ||
import com.spotify.app.AbstractTestcontainers; | ||
import com.spotify.app.dto.CategoryDTO; | ||
import com.spotify.app.dto.response.UserNoAssociationResponse; | ||
import com.spotify.app.security.jwt.JwtService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.assertj.core.api.AssertionsForClassTypes; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import java.net.http.HttpResponse; | ||
import java.util.Set; | ||
|
||
import static org.assertj.core.api.FactoryBasedNavigableListAssert.assertThat; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@Slf4j | ||
public class CategoryIT extends AbstractTestcontainers { | ||
|
||
private static final String CATEGORY_PATH = "/api/v1/category"; | ||
@Autowired | ||
private TestRestTemplate restTemplate; | ||
|
||
@Test | ||
public void canGetAllCategoryParent() { | ||
|
||
// given | ||
String url = CATEGORY_PATH.concat("/getAllParent"); | ||
// when | ||
ResponseEntity<Set> response = restTemplate.getForEntity(url, Set.class); | ||
// then | ||
AssertionsForClassTypes.assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,63 @@ | ||
package com.spotify.app.journey; | ||
|
||
public class FollowerIT { | ||
import com.spotify.app.AbstractTestcontainers; | ||
import com.spotify.app.dto.response.UserNoAssociationResponse; | ||
import com.spotify.app.security.auth.AuthenticationRequest; | ||
import com.spotify.app.security.auth.AuthenticationResponse; | ||
import com.spotify.app.security.jwt.JwtService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.http.*; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@Slf4j | ||
public class FollowerIT extends AbstractTestcontainers { | ||
|
||
private static final String AUTH_PATH = "/api/v1/auth"; | ||
private static final String FOLLOWER_PATH = "/api/v1/follower"; | ||
|
||
@Autowired | ||
private TestRestTemplate restTemplate; | ||
@Autowired | ||
private JwtService jwtService; | ||
|
||
|
||
@Test | ||
public void canFollowUser() { | ||
// given | ||
Long currentUserId ; | ||
Long targetUserId = 1L; | ||
|
||
|
||
String email = "[email protected]"; | ||
String password = "thuan2023"; | ||
AuthenticationRequest authRequest = new AuthenticationRequest(email,password); | ||
AuthenticationResponse authResponse = restTemplate.postForObject(AUTH_PATH+"/authenticate", authRequest, AuthenticationResponse.class); | ||
log.info(String.valueOf(authResponse)); | ||
String token = authResponse.getAccessToken(); | ||
|
||
currentUserId = authResponse.getUser().id(); | ||
|
||
HttpHeaders httpHeaders = new HttpHeaders(); | ||
httpHeaders.set(HttpHeaders.ACCEPT , MediaType.APPLICATION_JSON_VALUE); | ||
httpHeaders.set("Authorization", "Bearer " + token); | ||
|
||
HttpEntity<?> request = new HttpEntity<>(httpHeaders); | ||
|
||
String url = String.format(FOLLOWER_PATH.concat("/%d/follow/%d"),currentUserId,targetUserId); | ||
|
||
log.info(url); | ||
// when | ||
ResponseEntity<UserNoAssociationResponse[]> response = restTemplate.exchange(url, HttpMethod.GET ,request, UserNoAssociationResponse[].class); | ||
|
||
// then | ||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); | ||
|
||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,4 +1,61 @@ | ||
package com.spotify.app.journey; | ||
|
||
public class PlaylistIT { | ||
import com.github.javafaker.Faker; | ||
import com.spotify.app.AbstractTestcontainers; | ||
import com.spotify.app.dto.response.SongResponse; | ||
import com.spotify.app.security.auth.AuthenticationRequest; | ||
import com.spotify.app.security.auth.AuthenticationResponse; | ||
import com.spotify.app.security.jwt.JwtService; | ||
import com.spotify.app.service.PlaylistUserService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.http.*; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@Slf4j | ||
public class PlaylistIT extends AbstractTestcontainers { | ||
|
||
private static final String AUTH_PATH = "/api/v1/auth"; | ||
private static final String REVIEW_PATH = "/api/v1/playlist"; | ||
@Autowired | ||
private TestRestTemplate restTemplate; | ||
|
||
@Autowired | ||
private PlaylistUserService playlistUserService; | ||
|
||
@Autowired | ||
private JwtService jwtService; | ||
|
||
@Test | ||
public void canUserCreatePlaylist() { | ||
String email = "[email protected]"; | ||
String password = "thuan2023"; | ||
AuthenticationRequest authRequest = new AuthenticationRequest(email,password); | ||
AuthenticationResponse authResponse = restTemplate.postForObject(AUTH_PATH+"/authenticate", authRequest, AuthenticationResponse.class); | ||
log.info(String.valueOf(authResponse)); | ||
String token = authResponse.getAccessToken(); | ||
|
||
Long userId = authResponse.getUser().id(); | ||
HttpHeaders httpHeaders = new HttpHeaders(); | ||
httpHeaders.set(HttpHeaders.ACCEPT , MediaType.APPLICATION_JSON_VALUE); | ||
httpHeaders.set("Authorization", "Bearer " + token); | ||
|
||
HttpEntity<?> request = new HttpEntity<>(httpHeaders); | ||
|
||
String url = String.format(REVIEW_PATH.concat("/%d/create/playlist"),userId); | ||
|
||
log.info(url); | ||
// when | ||
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET ,request, String.class); | ||
|
||
// then | ||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); | ||
|
||
|
||
} | ||
} |
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,66 @@ | ||
package com.spotify.app.journey; | ||
|
||
import com.github.javafaker.Faker; | ||
import com.spotify.app.AbstractTestcontainers; | ||
import com.spotify.app.dto.ReviewDTO; | ||
import com.spotify.app.dto.response.ReviewResponse; | ||
import com.spotify.app.dto.response.SongResponse; | ||
import com.spotify.app.security.auth.AuthenticationRequest; | ||
import com.spotify.app.security.auth.AuthenticationResponse; | ||
import com.spotify.app.security.jwt.JwtService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.http.*; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
@Slf4j | ||
public class ReviewIT extends AbstractTestcontainers { | ||
|
||
private static final String AUTH_PATH = "/api/v1/auth"; | ||
private static final String REVIEW_PATH = "/api/v1/review"; | ||
@Autowired | ||
private TestRestTemplate restTemplate; | ||
|
||
@Autowired | ||
private JwtService jwtService; | ||
|
||
@Test | ||
public void canReviewInSong() { | ||
|
||
// given | ||
Faker faker = new Faker(); | ||
String email = "[email protected]"; | ||
String password = "thuan2023"; | ||
AuthenticationRequest authRequest = new AuthenticationRequest(email,password); | ||
AuthenticationResponse authResponse = restTemplate.postForObject(AUTH_PATH+"/authenticate", authRequest, AuthenticationResponse.class); | ||
log.info(String.valueOf(authResponse)); | ||
String token = authResponse.getAccessToken(); | ||
|
||
Long userId = authResponse.getUser().id(); | ||
Long songId = 1L; | ||
String reviewContent = faker.animal().name(); | ||
|
||
ReviewDTO reviewRequest = new ReviewDTO(0L,reviewContent); | ||
HttpHeaders httpHeaders = new HttpHeaders(); | ||
httpHeaders.set(HttpHeaders.ACCEPT , MediaType.APPLICATION_JSON_VALUE); | ||
httpHeaders.set("Authorization", "Bearer " + token); | ||
|
||
HttpEntity<?> request = new HttpEntity<>(reviewRequest,httpHeaders); | ||
|
||
String urlRequest = String.format(REVIEW_PATH.concat("/%d/review/in/%d"),userId,songId); | ||
|
||
log.info(urlRequest); | ||
// when | ||
ResponseEntity<ReviewResponse[]> response = restTemplate.exchange(urlRequest, HttpMethod.POST ,request, ReviewResponse[].class); | ||
// then | ||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); | ||
|
||
} | ||
} |
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
Oops, something went wrong.