Search in sources :

Example 6 with MusicDto

use of toby.jpa.dto.MusicDto in project toby-bot by ml404.

the class MusicFileServiceImplIntegrationTest method whenValidDiscordIdAndGuild_thenUserShouldBeFound.

@Test
public void whenValidDiscordIdAndGuild_thenUserShouldBeFound() {
    MusicDto musicDto1 = new MusicDto();
    musicDto1.setId("1_1");
    musicDto1.setFileName("filename");
    musicDto1.setMusicBlob("Some data".getBytes());
    musicFileService.createNewMusicFile(musicDto1);
    MusicDto dbMusicDto1 = musicFileService.getMusicFileById(musicDto1.getId());
    assertEquals(dbMusicDto1.getId(), musicDto1.getId());
    assertEquals(dbMusicDto1.getFileName(), musicDto1.getFileName());
    assertEquals(dbMusicDto1.getMusicBlob(), musicDto1.getMusicBlob());
}
Also used : MusicDto(toby.jpa.dto.MusicDto) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with MusicDto

use of toby.jpa.dto.MusicDto in project toby-bot by ml404.

the class UserServiceImplIntegrationTest method whenMusicFileExistsWithSameDiscordIdAndGuildAndUpdatedOnce_thenUserShouldBeFoundWithMusicFile.

@Test
public void whenMusicFileExistsWithSameDiscordIdAndGuildAndUpdatedOnce_thenUserShouldBeFoundWithMusicFile() {
    UserDto userDto = new UserDto();
    userDto.setDiscordId(1L);
    userDto.setGuildId(1L);
    MusicDto musicDto = new MusicDto(userDto.getDiscordId(), userDto.getGuildId(), null, 0, null);
    userDto.setMusicDto(musicDto);
    userService.createNewUser(userDto);
    UserDto dbUser = userService.getUserById(userDto.getDiscordId(), userDto.getGuildId());
    assertEquals(dbUser.getDiscordId(), userDto.getDiscordId());
    assertEquals(dbUser.getGuildId(), userDto.getGuildId());
    assertTrue(dbUser.hasMusicPermission());
    assertTrue(dbUser.hasMemePermission());
    assertTrue(dbUser.hasDigPermission());
    assertFalse(dbUser.isSuperUser());
    MusicDto dbMusicFileDto = userDto.getMusicDto();
    assertNotNull(dbMusicFileDto);
    assertEquals(dbMusicFileDto.getId(), musicDto.getId());
    assertEquals(dbMusicFileDto.getFileName(), musicDto.getFileName());
    dbMusicFileDto.setFileName("file name");
    dbMusicFileDto.setMusicBlob("test data".getBytes());
    userDto.setMusicDto(dbMusicFileDto);
    UserDto dbUser2 = userService.updateUser(userDto);
    assertEquals(dbUser2.getDiscordId(), userDto.getDiscordId());
    assertEquals(dbUser2.getGuildId(), userDto.getGuildId());
    assertTrue(dbUser2.hasMusicPermission());
    assertTrue(dbUser2.hasMemePermission());
    assertTrue(dbUser2.hasDigPermission());
    assertFalse(dbUser2.isSuperUser());
    dbMusicFileDto = dbUser2.getMusicDto();
    assertNotNull(dbMusicFileDto);
    assertEquals(dbMusicFileDto.getId(), musicDto.getId());
    assertEquals(dbMusicFileDto.getFileName(), musicDto.getFileName());
}
Also used : UserDto(toby.jpa.dto.UserDto) MusicDto(toby.jpa.dto.MusicDto) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with MusicDto

use of toby.jpa.dto.MusicDto in project toby-bot by ml404.

the class UserServiceImplIntegrationTest method testUpdate_thenNewUserValuesShouldBeReturned.

@Test
@Transactional
public void testUpdate_thenNewUserValuesShouldBeReturned() {
    UserDto userDto1 = new UserDto();
    userDto1.setDiscordId(1L);
    userDto1.setGuildId(1L);
    MusicDto musicDto1 = new MusicDto(userDto1.getDiscordId(), userDto1.getGuildId(), null, 0, null);
    userDto1.setMusicDto(musicDto1);
    userDto1 = userService.createNewUser(userDto1);
    UserDto dbUser1 = userService.getUserById(userDto1.getDiscordId(), userDto1.getGuildId());
    assertEquals(dbUser1.getDiscordId(), userDto1.getDiscordId());
    assertEquals(dbUser1.getGuildId(), userDto1.getGuildId());
    assertTrue(dbUser1.hasMusicPermission());
    assertTrue(dbUser1.hasMemePermission());
    assertTrue(dbUser1.hasDigPermission());
    assertFalse(dbUser1.isSuperUser());
    assertNotNull(dbUser1.getMusicDto());
    UserDto userDto2 = new UserDto();
    userDto2.setDiscordId(1L);
    userDto2.setGuildId(1L);
    MusicDto musicDto2 = new MusicDto(userDto2.getDiscordId(), userDto2.getGuildId(), null, 0, null);
    userDto2.setMusicDto(musicDto2);
    userDto2.setDigPermission(false);
    userDto2 = userService.updateUser(userDto2);
    UserDto dbUser2 = userService.getUserById(userDto2.getDiscordId(), userDto2.getGuildId());
    int guildMemberSize = userService.listGuildUsers(userDto2.getGuildId()).size();
    assertEquals(dbUser2.getDiscordId(), userDto2.getDiscordId());
    assertEquals(dbUser2.getGuildId(), userDto2.getGuildId());
    assertTrue(dbUser2.hasMusicPermission());
    assertTrue(dbUser2.hasMemePermission());
    assertFalse(dbUser2.hasDigPermission());
    assertFalse(dbUser2.isSuperUser());
    assertNotNull(dbUser2.getMusicDto());
    assertEquals(1, guildMemberSize);
}
Also used : UserDto(toby.jpa.dto.UserDto) MusicDto(toby.jpa.dto.MusicDto) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with MusicDto

use of toby.jpa.dto.MusicDto in project toby-bot by ml404.

the class MusicFileServiceImplIntegrationTest method testUpdate_thenNewUserValuesShouldBeReturned.

@Test
public void testUpdate_thenNewUserValuesShouldBeReturned() {
    MusicDto musicDto1 = new MusicDto();
    musicDto1.setId("1_1");
    musicDto1.setFileName("file 1");
    musicDto1.setMusicBlob("some data 1".getBytes());
    musicDto1 = musicFileService.createNewMusicFile(musicDto1);
    MusicDto dbMusicDto1 = musicFileService.getMusicFileById(musicDto1.getId());
    assertEquals(dbMusicDto1.getId(), musicDto1.getId());
    assertEquals(dbMusicDto1.getFileName(), musicDto1.getFileName());
    assertEquals(dbMusicDto1.getMusicBlob(), musicDto1.getMusicBlob());
    MusicDto musicDto2 = new MusicDto();
    musicDto2.setId("1_1");
    musicDto2.setFileName("file 2");
    musicDto2.setMusicBlob("some data 2".getBytes());
    musicDto2 = musicFileService.updateMusicFile(musicDto2);
    MusicDto dbMusicDto2 = musicFileService.getMusicFileById(musicDto2.getId());
    assertEquals(dbMusicDto2.getId(), musicDto2.getId());
    assertEquals(dbMusicDto2.getFileName(), musicDto2.getFileName());
    assertEquals(dbMusicDto2.getMusicBlob(), musicDto2.getMusicBlob());
}
Also used : MusicDto(toby.jpa.dto.MusicDto) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with MusicDto

use of toby.jpa.dto.MusicDto in project toby-bot by ml404.

the class MusicFileServiceImplIntegrationTest method musicDtoBlobSerialisesAndDeserialisesCorrectly.

@Test
public void musicDtoBlobSerialisesAndDeserialisesCorrectly() throws IOException {
    ClassLoader classLoader = getClass().getClassLoader();
    URL mp3Resource = classLoader.getResource("test.mp3");
    MusicDto musicDto1 = new MusicDto();
    musicDto1.setId("1_1");
    musicDto1.setFileName("filename");
    musicDto1.setMusicBlob(mp3Resource.openStream().readAllBytes());
    musicFileService.createNewMusicFile(musicDto1);
    MusicDto dbMusicDto1 = musicFileService.getMusicFileById(musicDto1.getId());
    assertEquals(dbMusicDto1.getId(), musicDto1.getId());
    assertEquals(dbMusicDto1.getFileName(), musicDto1.getFileName());
    assertEquals(dbMusicDto1.getMusicBlob(), musicDto1.getMusicBlob());
}
Also used : MusicDto(toby.jpa.dto.MusicDto) URL(java.net.URL) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

MusicDto (toby.jpa.dto.MusicDto)14 UserDto (toby.jpa.dto.UserDto)8 Test (org.junit.jupiter.api.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 IUserService (toby.jpa.service.IUserService)3 Arrays (java.util.Arrays)2 List (java.util.List)2 Message (net.dv8tion.jda.api.entities.Message)2 TextChannel (net.dv8tion.jda.api.entities.TextChannel)2 CommandContext (toby.command.CommandContext)2 ICommand (toby.command.ICommand)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URL (java.net.URL)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1 Query (javax.persistence.Query)1