Skip to content

Commit

Permalink
5/12: migrate upload file to cloudinary
Browse files Browse the repository at this point in the history
  • Loading branch information
thuan committed Dec 5, 2023
1 parent e50d262 commit c97df69
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 61 deletions.
114 changes: 57 additions & 57 deletions src/test/java/com/spotify/app/AbstractTestcontainers.java
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
package com.spotify.app;

import lombok.extern.slf4j.Slf4j;
import org.flywaydb.core.Flyway;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.MountableFile;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;


@Testcontainers
@Slf4j
public abstract class AbstractTestcontainers {


@BeforeAll
static void beforeAll() {
Flyway flyway = Flyway
.configure()
.dataSource(
mySQLContainer.getJdbcUrl(),
mySQLContainer.getUsername(),
mySQLContainer.getPassword()
).load();
flyway.migrate();
}
@Container
protected static final MySQLContainer<?> mySQLContainer =
new MySQLContainer<>("mysql:latest")
.withDatabaseName("spotify-dao-unit-test")
.withUsername("kai")
.withPassword("password")
;

@DynamicPropertySource
static void dynamicProperties(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", mySQLContainer::getJdbcUrl);
registry.add("spring.datasource.username", mySQLContainer::getUsername);
registry.add("spring.datasource.password", mySQLContainer::getPassword);
}

//package com.spotify.app;
//
//import lombok.extern.slf4j.Slf4j;
//import org.flywaydb.core.Flyway;
//import org.junit.jupiter.api.BeforeAll;
//import org.junit.jupiter.api.Test;
//import org.springframework.test.context.DynamicPropertyRegistry;
//import org.springframework.test.context.DynamicPropertySource;
//import org.testcontainers.containers.MySQLContainer;
//import org.testcontainers.junit.jupiter.Container;
//import org.testcontainers.junit.jupiter.Testcontainers;
//import org.testcontainers.utility.MountableFile;
//
//import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
//
//
//@Testcontainers
//@Slf4j
//public abstract class AbstractTestcontainers {
//
//
// @BeforeAll
// static void setUp() {
// mySQLContainer.withInitScript("schema.sql");
// mySQLContainer.start();
// static void beforeAll() {
// Flyway flyway = Flyway
// .configure()
// .dataSource(
// mySQLContainer.getJdbcUrl(),
// mySQLContainer.getUsername(),
// mySQLContainer.getPassword()
// ).load();
// flyway.migrate();
// }

@Test
void connectionEstablished() {
assertThat(mySQLContainer.isCreated()).isTrue();
assertThat(mySQLContainer.isRunning()).isTrue();
}
}
// @Container
// protected static final MySQLContainer<?> mySQLContainer =
// new MySQLContainer<>("mysql:latest")
// .withDatabaseName("spotify-dao-unit-test")
// .withUsername("kai")
// .withPassword("password")
// ;
//
// @DynamicPropertySource
// static void dynamicProperties(DynamicPropertyRegistry registry) {
// registry.add("spring.datasource.url", mySQLContainer::getJdbcUrl);
// registry.add("spring.datasource.username", mySQLContainer::getUsername);
// registry.add("spring.datasource.password", mySQLContainer::getPassword);
// }
//
//// @BeforeAll
//// static void setUp() {
//// mySQLContainer.withInitScript("schema.sql");
//// mySQLContainer.start();
//// }
//
// @Test
// void connectionEstablished() {
// assertThat(mySQLContainer.isCreated()).isTrue();
// assertThat(mySQLContainer.isRunning()).isTrue();
// }
//}
8 changes: 5 additions & 3 deletions src/test/java/com/spotify/app/song/SongServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.spotify.app.model.PlaylistSong;
import com.spotify.app.model.Song;
import com.spotify.app.repository.*;
import com.spotify.app.service.CloudinaryService;
import com.spotify.app.service.ReviewService;
import com.spotify.app.service.SongService;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -57,9 +58,9 @@ public class SongServiceTest {
private RestTemplate restTemplate;
@Mock
private SongSearchResponseMapper songSearchResponseMapper;

@Mock
private CloudinaryService cloudinaryService;
private SongService underTest ;

@BeforeEach
public void setUp() {
underTest = new SongService(
Expand All @@ -73,7 +74,8 @@ public void setUp() {
albumRepository,
reviewService,
restTemplate,
songSearchResponseMapper
songSearchResponseMapper,
cloudinaryService
) ;
}
@Test
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/com/spotify/app/user/UserServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public class UserServiceTest {
private PlaylistService playlistService;
@Mock
private RoleService roleService;
@Mock
private CloudinaryService cloudinaryService;

private UserService underTest ;

Expand All @@ -76,7 +78,8 @@ public void setUp() {
followerService,
albumService,
playlistService,
roleService
roleService,
cloudinaryService
) ;
}

Expand Down

0 comments on commit c97df69

Please sign in to comment.