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());
}
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());
}
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);
}
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());
}
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());
}
Aggregations