mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-03-10 08:30:08 +01:00
Split new subsonic api converting extension functions into different files.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
8a9644b5dd
commit
f7498409b9
@ -69,7 +69,13 @@ import org.moire.ultrasonic.api.subsonic.response.SearchResponse;
|
|||||||
import org.moire.ultrasonic.api.subsonic.response.SearchThreeResponse;
|
import org.moire.ultrasonic.api.subsonic.response.SearchThreeResponse;
|
||||||
import org.moire.ultrasonic.api.subsonic.response.SearchTwoResponse;
|
import org.moire.ultrasonic.api.subsonic.response.SearchTwoResponse;
|
||||||
import org.moire.ultrasonic.api.subsonic.response.SubsonicResponse;
|
import org.moire.ultrasonic.api.subsonic.response.SubsonicResponse;
|
||||||
import org.moire.ultrasonic.data.APIConverter;
|
import org.moire.ultrasonic.data.APIAlbumConverter;
|
||||||
|
import org.moire.ultrasonic.data.APIArtistConverter;
|
||||||
|
import org.moire.ultrasonic.data.APIIndexesConverter;
|
||||||
|
import org.moire.ultrasonic.data.APIMusicDirectoryConverter;
|
||||||
|
import org.moire.ultrasonic.data.APIMusicFolderConverter;
|
||||||
|
import org.moire.ultrasonic.data.APIPlaylistConverter;
|
||||||
|
import org.moire.ultrasonic.data.APISearchConverter;
|
||||||
import org.moire.ultrasonic.domain.Bookmark;
|
import org.moire.ultrasonic.domain.Bookmark;
|
||||||
import org.moire.ultrasonic.domain.ChatMessage;
|
import org.moire.ultrasonic.domain.ChatMessage;
|
||||||
import org.moire.ultrasonic.domain.Genre;
|
import org.moire.ultrasonic.domain.Genre;
|
||||||
@ -234,7 +240,8 @@ public class RESTMusicService implements MusicService
|
|||||||
Response<MusicFoldersResponse> response = subsonicAPIClient.getApi().getMusicFolders().execute();
|
Response<MusicFoldersResponse> response = subsonicAPIClient.getApi().getMusicFolders().execute();
|
||||||
checkResponseSuccessful(response);
|
checkResponseSuccessful(response);
|
||||||
|
|
||||||
List<MusicFolder> musicFolders = APIConverter.toDomainEntityList(response.body().getMusicFolders());
|
List<MusicFolder> musicFolders = APIMusicFolderConverter
|
||||||
|
.toDomainEntityList(response.body().getMusicFolders());
|
||||||
writeCachedMusicFolders(context, musicFolders);
|
writeCachedMusicFolders(context, musicFolders);
|
||||||
return musicFolders;
|
return musicFolders;
|
||||||
}
|
}
|
||||||
@ -269,7 +276,7 @@ public class RESTMusicService implements MusicService
|
|||||||
.getIndexes(musicFolderId == null ? null : Long.valueOf(musicFolderId), null).execute();
|
.getIndexes(musicFolderId == null ? null : Long.valueOf(musicFolderId), null).execute();
|
||||||
checkResponseSuccessful(response);
|
checkResponseSuccessful(response);
|
||||||
|
|
||||||
Indexes indexes = APIConverter.toDomainEntity(response.body().getIndexes());
|
Indexes indexes = APIIndexesConverter.toDomainEntity(response.body().getIndexes());
|
||||||
writeCachedIndexes(context, indexes, musicFolderId);
|
writeCachedIndexes(context, indexes, musicFolderId);
|
||||||
return indexes;
|
return indexes;
|
||||||
}
|
}
|
||||||
@ -303,7 +310,7 @@ public class RESTMusicService implements MusicService
|
|||||||
Response<GetArtistsResponse> response = subsonicAPIClient.getApi().getArtists(null).execute();
|
Response<GetArtistsResponse> response = subsonicAPIClient.getApi().getArtists(null).execute();
|
||||||
checkResponseSuccessful(response);
|
checkResponseSuccessful(response);
|
||||||
|
|
||||||
Indexes indexes = APIConverter.toDomainEntity(response.body().getIndexes());
|
Indexes indexes = APIIndexesConverter.toDomainEntity(response.body().getIndexes());
|
||||||
writeCachedArtists(context, indexes);
|
writeCachedArtists(context, indexes);
|
||||||
return indexes;
|
return indexes;
|
||||||
}
|
}
|
||||||
@ -370,7 +377,7 @@ public class RESTMusicService implements MusicService
|
|||||||
.getMusicDirectory(Long.valueOf(id)).execute();
|
.getMusicDirectory(Long.valueOf(id)).execute();
|
||||||
checkResponseSuccessful(response);
|
checkResponseSuccessful(response);
|
||||||
|
|
||||||
return APIConverter.toDomainEntity(response.body().getMusicDirectory());
|
return APIMusicDirectoryConverter.toDomainEntity(response.body().getMusicDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -388,7 +395,7 @@ public class RESTMusicService implements MusicService
|
|||||||
.getArtist(Long.valueOf(id)).execute();
|
.getArtist(Long.valueOf(id)).execute();
|
||||||
checkResponseSuccessful(response);
|
checkResponseSuccessful(response);
|
||||||
|
|
||||||
return APIConverter.toMusicDirectoryDomainEntity(response.body().getArtist());
|
return APIArtistConverter.toMusicDirectoryDomainEntity(response.body().getArtist());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -406,7 +413,7 @@ public class RESTMusicService implements MusicService
|
|||||||
.getAlbum(Long.valueOf(id)).execute();
|
.getAlbum(Long.valueOf(id)).execute();
|
||||||
checkResponseSuccessful(response);
|
checkResponseSuccessful(response);
|
||||||
|
|
||||||
return APIConverter.toMusicDirectoryDomainEntity(response.body().getAlbum());
|
return APIAlbumConverter.toMusicDirectoryDomainEntity(response.body().getAlbum());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -435,7 +442,7 @@ public class RESTMusicService implements MusicService
|
|||||||
criteria.getSongCount(), null, null).execute();
|
criteria.getSongCount(), null, null).execute();
|
||||||
checkResponseSuccessful(response);
|
checkResponseSuccessful(response);
|
||||||
|
|
||||||
return APIConverter.toDomainEntity(response.body().getSearchResult());
|
return APISearchConverter.toDomainEntity(response.body().getSearchResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -454,7 +461,7 @@ public class RESTMusicService implements MusicService
|
|||||||
criteria.getSongCount(), null).execute();
|
criteria.getSongCount(), null).execute();
|
||||||
checkResponseSuccessful(response);
|
checkResponseSuccessful(response);
|
||||||
|
|
||||||
return APIConverter.toDomainEntity(response.body().getSearchResult());
|
return APISearchConverter.toDomainEntity(response.body().getSearchResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
private SearchResult search3(SearchCriteria criteria,
|
private SearchResult search3(SearchCriteria criteria,
|
||||||
@ -470,7 +477,7 @@ public class RESTMusicService implements MusicService
|
|||||||
criteria.getSongCount(), null).execute();
|
criteria.getSongCount(), null).execute();
|
||||||
checkResponseSuccessful(response);
|
checkResponseSuccessful(response);
|
||||||
|
|
||||||
return APIConverter.toDomainEntity(response.body().getSearchResult());
|
return APISearchConverter.toDomainEntity(response.body().getSearchResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -487,7 +494,7 @@ public class RESTMusicService implements MusicService
|
|||||||
.getPlaylist(Long.valueOf(id)).execute();
|
.getPlaylist(Long.valueOf(id)).execute();
|
||||||
checkResponseSuccessful(response);
|
checkResponseSuccessful(response);
|
||||||
|
|
||||||
MusicDirectory playlist = APIConverter
|
MusicDirectory playlist = APIPlaylistConverter
|
||||||
.toMusicDirectoryDomainEntity(response.body().getPlaylist());
|
.toMusicDirectoryDomainEntity(response.body().getPlaylist());
|
||||||
savePlaylist(name, context, playlist);
|
savePlaylist(name, context, playlist);
|
||||||
return playlist;
|
return playlist;
|
||||||
@ -563,7 +570,7 @@ public class RESTMusicService implements MusicService
|
|||||||
.getPlaylists(null).execute();
|
.getPlaylists(null).execute();
|
||||||
checkResponseSuccessful(response);
|
checkResponseSuccessful(response);
|
||||||
|
|
||||||
return APIConverter.toDomainEntitiesList(response.body().getPlaylists());
|
return APIPlaylistConverter.toDomainEntitiesList(response.body().getPlaylists());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
// Converts Album entity from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient]
|
||||||
|
// to app domain entities.
|
||||||
|
@file:JvmName("APIAlbumConverter")
|
||||||
|
package org.moire.ultrasonic.data
|
||||||
|
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Album
|
||||||
|
import org.moire.ultrasonic.domain.MusicDirectory
|
||||||
|
|
||||||
|
fun Album.toDomainEntity(): MusicDirectory.Entry = MusicDirectory.Entry().apply {
|
||||||
|
id = this@toDomainEntity.id.toString()
|
||||||
|
setIsDirectory(true)
|
||||||
|
title = this@toDomainEntity.name
|
||||||
|
coverArt = this@toDomainEntity.coverArt
|
||||||
|
artist = this@toDomainEntity.artist
|
||||||
|
artistId = this@toDomainEntity.artistId.toString()
|
||||||
|
songCount = this@toDomainEntity.songCount.toLong()
|
||||||
|
duration = this@toDomainEntity.duration
|
||||||
|
created = this@toDomainEntity.created?.time
|
||||||
|
year = this@toDomainEntity.year
|
||||||
|
genre = this@toDomainEntity.genre
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Album.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory().apply {
|
||||||
|
addAll(this@toMusicDirectoryDomainEntity.songList.map { it.toDomainEntity() })
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
// Converts Artist entity from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient]
|
||||||
|
// to app domain entities.
|
||||||
|
@file:JvmName("APIArtistConverter")
|
||||||
|
package org.moire.ultrasonic.data
|
||||||
|
|
||||||
|
import org.moire.ultrasonic.domain.Artist
|
||||||
|
import org.moire.ultrasonic.domain.MusicDirectory
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Artist as APIArtist
|
||||||
|
|
||||||
|
fun APIArtist.toDomainEntity(): Artist = Artist().apply {
|
||||||
|
id = this@toDomainEntity.id.toString()
|
||||||
|
name = this@toDomainEntity.name
|
||||||
|
}
|
||||||
|
|
||||||
|
fun APIArtist.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory().apply {
|
||||||
|
name = this@toMusicDirectoryDomainEntity.name
|
||||||
|
addAll(this@toMusicDirectoryDomainEntity.albumsList.map { it.toDomainEntity() })
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
// Converts Indexes entity from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient]
|
||||||
|
// to app domain entities.
|
||||||
|
@file:JvmName("APIIndexesConverter")
|
||||||
|
package org.moire.ultrasonic.data
|
||||||
|
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Index
|
||||||
|
import org.moire.ultrasonic.domain.Artist
|
||||||
|
import org.moire.ultrasonic.domain.Indexes
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Indexes as APIIndexes
|
||||||
|
|
||||||
|
fun APIIndexes.toDomainEntity(): Indexes = Indexes(this.lastModified, this.ignoredArticles,
|
||||||
|
this.shortcutList.map { it.toDomainEntity() }, this.indexList.foldIndexToArtistList())
|
||||||
|
|
||||||
|
private fun List<Index>.foldIndexToArtistList(): List<Artist> = this.fold(listOf(), {
|
||||||
|
acc, index -> acc + index.artists.map { it.toDomainEntity() }
|
||||||
|
})
|
@ -0,0 +1,41 @@
|
|||||||
|
// Converts MusicDirectory entity from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient]
|
||||||
|
// to app domain entities.
|
||||||
|
@file:JvmName("APIMusicDirectoryConverter")
|
||||||
|
package org.moire.ultrasonic.data
|
||||||
|
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild
|
||||||
|
import org.moire.ultrasonic.domain.MusicDirectory
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.MusicDirectory as APIMusicDirectory
|
||||||
|
|
||||||
|
fun MusicDirectoryChild.toDomainEntity(): MusicDirectory.Entry = MusicDirectory.Entry().apply {
|
||||||
|
id = this@toDomainEntity.id.toString()
|
||||||
|
parent = this@toDomainEntity.parent.toString()
|
||||||
|
setIsDirectory(this@toDomainEntity.isDir)
|
||||||
|
title = this@toDomainEntity.title
|
||||||
|
album = this@toDomainEntity.album
|
||||||
|
albumId = this@toDomainEntity.albumId.toString()
|
||||||
|
artist = this@toDomainEntity.artist
|
||||||
|
artistId = this@toDomainEntity.artistId.toString()
|
||||||
|
track = this@toDomainEntity.track
|
||||||
|
year = this@toDomainEntity.year
|
||||||
|
genre = this@toDomainEntity.genre
|
||||||
|
contentType = this@toDomainEntity.contentType
|
||||||
|
suffix = this@toDomainEntity.suffix
|
||||||
|
transcodedContentType = this@toDomainEntity.transcodedContentType
|
||||||
|
transcodedSuffix = this@toDomainEntity.transcodedSuffix
|
||||||
|
coverArt = this@toDomainEntity.coverArt
|
||||||
|
size = this@toDomainEntity.size
|
||||||
|
duration = this@toDomainEntity.duration
|
||||||
|
bitRate = this@toDomainEntity.bitRate
|
||||||
|
path = this@toDomainEntity.path
|
||||||
|
setIsVideo(this@toDomainEntity.isVideo)
|
||||||
|
created = this@toDomainEntity.created?.time
|
||||||
|
starred = this@toDomainEntity.starred != null
|
||||||
|
discNumber = this@toDomainEntity.discNumber
|
||||||
|
type = this@toDomainEntity.type
|
||||||
|
}
|
||||||
|
|
||||||
|
fun APIMusicDirectory.toDomainEntity(): MusicDirectory = MusicDirectory().apply {
|
||||||
|
name = this@toDomainEntity.name
|
||||||
|
addAll(this@toDomainEntity.childList.map { it.toDomainEntity() })
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
// Converts MusicFolder entity from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient]
|
||||||
|
// to app domain entities.
|
||||||
|
@file:JvmName("APIMusicFolderConverter")
|
||||||
|
package org.moire.ultrasonic.data
|
||||||
|
|
||||||
|
import org.moire.ultrasonic.domain.MusicFolder
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.MusicFolder as APIMusicFolder
|
||||||
|
|
||||||
|
fun APIMusicFolder.toDomainEntity(): MusicFolder = MusicFolder(this.id.toString(), this.name)
|
||||||
|
|
||||||
|
fun List<APIMusicFolder>.toDomainEntityList(): List<MusicFolder>
|
||||||
|
= this.map { it.toDomainEntity() }
|
@ -0,0 +1,21 @@
|
|||||||
|
// Converts Playlist entity from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient]
|
||||||
|
// to app domain entities.
|
||||||
|
@file:JvmName("APIPlaylistConverter")
|
||||||
|
package org.moire.ultrasonic.data
|
||||||
|
|
||||||
|
import org.moire.ultrasonic.domain.MusicDirectory
|
||||||
|
import org.moire.ultrasonic.domain.Playlist
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Playlist as APIPlaylist
|
||||||
|
|
||||||
|
fun APIPlaylist.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory().apply {
|
||||||
|
name = this@toMusicDirectoryDomainEntity.name
|
||||||
|
addAll(this@toMusicDirectoryDomainEntity.entriesList.map { it.toDomainEntity() })
|
||||||
|
}
|
||||||
|
|
||||||
|
fun APIPlaylist.toDomainEntity(): Playlist = Playlist(this.id.toString(), this.name, this.owner,
|
||||||
|
this.comment, this.songCount.toString(),
|
||||||
|
this.created?.let { SimpleDateFormat.getDateTimeInstance().format(it.time) },
|
||||||
|
public.toString())
|
||||||
|
|
||||||
|
fun List<APIPlaylist>.toDomainEntitiesList(): List<Playlist> = this.map { it.toDomainEntity() }
|
@ -0,0 +1,22 @@
|
|||||||
|
// Converts SearchResult entities from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient]
|
||||||
|
// to app domain entities.
|
||||||
|
@file:JvmName("APISearchConverter")
|
||||||
|
package org.moire.ultrasonic.data
|
||||||
|
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.SearchThreeResult
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.SearchTwoResult
|
||||||
|
import org.moire.ultrasonic.domain.SearchResult
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.SearchResult as APISearchResult
|
||||||
|
|
||||||
|
fun APISearchResult.toDomainEntity(): SearchResult = SearchResult(emptyList(), emptyList(),
|
||||||
|
this.matchList.map { it.toDomainEntity() })
|
||||||
|
|
||||||
|
fun SearchTwoResult.toDomainEntity(): SearchResult = SearchResult(
|
||||||
|
this.artistList.map { it.toDomainEntity() },
|
||||||
|
this.albumList.map { it.toDomainEntity() },
|
||||||
|
this.songList.map { it.toDomainEntity() })
|
||||||
|
|
||||||
|
fun SearchThreeResult.toDomainEntity(): SearchResult = SearchResult(
|
||||||
|
this.artistList.map { it.toDomainEntity() },
|
||||||
|
this.albumList.map { it.toDomainEntity() },
|
||||||
|
this.songList.map { it.toDomainEntity() })
|
@ -1,120 +0,0 @@
|
|||||||
// Converts entities from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient] to app domain entities.
|
|
||||||
@file:JvmName("APIConverter")
|
|
||||||
package org.moire.ultrasonic.data
|
|
||||||
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.Album
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.Index
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.SearchThreeResult
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.SearchTwoResult
|
|
||||||
import org.moire.ultrasonic.domain.Artist
|
|
||||||
import org.moire.ultrasonic.domain.Indexes
|
|
||||||
import org.moire.ultrasonic.domain.MusicDirectory
|
|
||||||
import org.moire.ultrasonic.domain.MusicFolder
|
|
||||||
import org.moire.ultrasonic.domain.Playlist
|
|
||||||
import org.moire.ultrasonic.domain.SearchResult
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.Artist as APIArtist
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.Indexes as APIIndexes
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.MusicDirectory as APIMusicDirectory
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.MusicFolder as APIMusicFolder
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.Playlist as APIPlaylist
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.SearchResult as APISearchResult
|
|
||||||
|
|
||||||
fun APIMusicFolder.toDomainEntity(): MusicFolder = MusicFolder(this.id.toString(), this.name)
|
|
||||||
|
|
||||||
fun List<APIMusicFolder>.toDomainEntityList(): List<MusicFolder>
|
|
||||||
= this.map { it.toDomainEntity() }
|
|
||||||
|
|
||||||
fun APIIndexes.toDomainEntity(): Indexes = Indexes(this.lastModified, this.ignoredArticles,
|
|
||||||
this.shortcutList.map { it.toDomainEntity() }, this.indexList.foldIndexToArtistList())
|
|
||||||
|
|
||||||
private fun List<Index>.foldIndexToArtistList(): List<Artist> = this.fold(listOf(), {
|
|
||||||
acc, index -> acc + index.artists.map { it.toDomainEntity() }
|
|
||||||
})
|
|
||||||
|
|
||||||
fun APIArtist.toDomainEntity(): Artist = Artist().apply {
|
|
||||||
id = this@toDomainEntity.id.toString()
|
|
||||||
name = this@toDomainEntity.name
|
|
||||||
}
|
|
||||||
|
|
||||||
fun APIArtist.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory().apply {
|
|
||||||
name = this@toMusicDirectoryDomainEntity.name
|
|
||||||
addAll(this@toMusicDirectoryDomainEntity.albumsList.map { it.toDomainEntity() })
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Album.toDomainEntity(): MusicDirectory.Entry = MusicDirectory.Entry().apply {
|
|
||||||
id = this@toDomainEntity.id.toString()
|
|
||||||
setIsDirectory(true)
|
|
||||||
title = this@toDomainEntity.name
|
|
||||||
coverArt = this@toDomainEntity.coverArt
|
|
||||||
artist = this@toDomainEntity.artist
|
|
||||||
artistId = this@toDomainEntity.artistId.toString()
|
|
||||||
songCount = this@toDomainEntity.songCount.toLong()
|
|
||||||
duration = this@toDomainEntity.duration
|
|
||||||
created = this@toDomainEntity.created?.time
|
|
||||||
year = this@toDomainEntity.year
|
|
||||||
genre = this@toDomainEntity.genre
|
|
||||||
}
|
|
||||||
|
|
||||||
fun Album.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory().apply {
|
|
||||||
addAll(this@toMusicDirectoryDomainEntity.songList.map { it.toDomainEntity() })
|
|
||||||
}
|
|
||||||
|
|
||||||
fun MusicDirectoryChild.toDomainEntity(): MusicDirectory.Entry = MusicDirectory.Entry().apply {
|
|
||||||
id = this@toDomainEntity.id.toString()
|
|
||||||
parent = this@toDomainEntity.parent.toString()
|
|
||||||
setIsDirectory(this@toDomainEntity.isDir)
|
|
||||||
title = this@toDomainEntity.title
|
|
||||||
album = this@toDomainEntity.album
|
|
||||||
albumId = this@toDomainEntity.albumId.toString()
|
|
||||||
artist = this@toDomainEntity.artist
|
|
||||||
artistId = this@toDomainEntity.artistId.toString()
|
|
||||||
track = this@toDomainEntity.track
|
|
||||||
year = this@toDomainEntity.year
|
|
||||||
genre = this@toDomainEntity.genre
|
|
||||||
contentType = this@toDomainEntity.contentType
|
|
||||||
suffix = this@toDomainEntity.suffix
|
|
||||||
transcodedContentType = this@toDomainEntity.transcodedContentType
|
|
||||||
transcodedSuffix = this@toDomainEntity.transcodedSuffix
|
|
||||||
coverArt = this@toDomainEntity.coverArt
|
|
||||||
size = this@toDomainEntity.size
|
|
||||||
duration = this@toDomainEntity.duration
|
|
||||||
bitRate = this@toDomainEntity.bitRate
|
|
||||||
path = this@toDomainEntity.path
|
|
||||||
setIsVideo(this@toDomainEntity.isVideo)
|
|
||||||
created = this@toDomainEntity.created?.time
|
|
||||||
starred = this@toDomainEntity.starred != null
|
|
||||||
discNumber = this@toDomainEntity.discNumber
|
|
||||||
type = this@toDomainEntity.type
|
|
||||||
}
|
|
||||||
|
|
||||||
fun APIMusicDirectory.toDomainEntity(): MusicDirectory = MusicDirectory().apply {
|
|
||||||
name = this@toDomainEntity.name
|
|
||||||
addAll(this@toDomainEntity.childList.map { it.toDomainEntity() })
|
|
||||||
}
|
|
||||||
|
|
||||||
fun APISearchResult.toDomainEntity(): SearchResult = SearchResult(emptyList(), emptyList(),
|
|
||||||
this.matchList.map { it.toDomainEntity() })
|
|
||||||
|
|
||||||
fun SearchTwoResult.toDomainEntity(): SearchResult = SearchResult(
|
|
||||||
this.artistList.map { it.toDomainEntity() },
|
|
||||||
this.albumList.map { it.toDomainEntity() },
|
|
||||||
this.songList.map { it.toDomainEntity() })
|
|
||||||
|
|
||||||
fun SearchThreeResult.toDomainEntity(): SearchResult = SearchResult(
|
|
||||||
this.artistList.map { it.toDomainEntity() },
|
|
||||||
this.albumList.map { it.toDomainEntity() },
|
|
||||||
this.songList.map { it.toDomainEntity() })
|
|
||||||
|
|
||||||
fun APIPlaylist.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory().apply {
|
|
||||||
name = this@toMusicDirectoryDomainEntity.name
|
|
||||||
addAll(this@toMusicDirectoryDomainEntity.entriesList.map { it.toDomainEntity() })
|
|
||||||
}
|
|
||||||
|
|
||||||
fun APIPlaylist.toDomainEntity(): Playlist = Playlist(this.id.toString(), this.name, this.owner,
|
|
||||||
this.comment, this.songCount.toString(),
|
|
||||||
this.created?.let { SimpleDateFormat.getDateTimeInstance().format(it.time) },
|
|
||||||
public.toString())
|
|
||||||
|
|
||||||
fun List<APIPlaylist>.toDomainEntitiesList(): List<Playlist> = this.map { it.toDomainEntity() }
|
|
@ -0,0 +1,54 @@
|
|||||||
|
@file:Suppress("IllegalIdentifier")
|
||||||
|
|
||||||
|
package org.moire.ultrasonic.data
|
||||||
|
|
||||||
|
import org.amshove.kluent.`should equal to`
|
||||||
|
import org.amshove.kluent.`should equal`
|
||||||
|
import org.junit.Test
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Album
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild
|
||||||
|
import java.util.Calendar
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for extension functions in [APIAlbumConverter.kt] file.
|
||||||
|
*/
|
||||||
|
class APIAlbumConverterTest {
|
||||||
|
@Test
|
||||||
|
fun `Should convert Album to domain entity`() {
|
||||||
|
val entity = Album(id = 387L, name = "some-name", coverArt = "asdas", artist = "some-artist",
|
||||||
|
artistId = 390L, songCount = 12, duration = 841, created = Calendar.getInstance(),
|
||||||
|
year = 2017, genre = "some-genre")
|
||||||
|
|
||||||
|
val convertedEntity = entity.toDomainEntity()
|
||||||
|
|
||||||
|
with(convertedEntity) {
|
||||||
|
id `should equal to` entity.id.toString()
|
||||||
|
title `should equal to` entity.name
|
||||||
|
isDirectory `should equal to` true
|
||||||
|
coverArt `should equal to` entity.coverArt
|
||||||
|
artist `should equal to` entity.artist
|
||||||
|
artistId `should equal to` entity.artistId.toString()
|
||||||
|
songCount `should equal to` entity.songCount.toLong()
|
||||||
|
duration `should equal to` entity.duration
|
||||||
|
created `should equal` entity.created?.time
|
||||||
|
year `should equal to` entity.year
|
||||||
|
genre `should equal to` entity.genre
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should convert to MusicDirectory domain entity`() {
|
||||||
|
val entity = Album(id = 101L, name = "some-album", artist = "some-artist", artistId = 54L,
|
||||||
|
coverArt = "some-id", songCount = 10, duration = 456,
|
||||||
|
created = Calendar.getInstance(), year = 2022, genre = "Hard Rock",
|
||||||
|
songList = listOf(MusicDirectoryChild()))
|
||||||
|
|
||||||
|
val convertedEntity = entity.toMusicDirectoryDomainEntity()
|
||||||
|
|
||||||
|
with(convertedEntity) {
|
||||||
|
name `should equal` null
|
||||||
|
children.size `should equal to` entity.songList.size
|
||||||
|
children[0] `should equal` entity.songList[0].toDomainEntity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
@file:Suppress("IllegalIdentifier")
|
||||||
|
|
||||||
|
package org.moire.ultrasonic.data
|
||||||
|
|
||||||
|
import org.amshove.kluent.`should equal to`
|
||||||
|
import org.amshove.kluent.`should equal`
|
||||||
|
import org.junit.Test
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Album
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Artist
|
||||||
|
import java.util.Calendar
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for extension functions in [APIArtistConverter.kt] file.
|
||||||
|
*/
|
||||||
|
class APIArtistConverterTest {
|
||||||
|
@Test
|
||||||
|
fun `Should convert artist entity`() {
|
||||||
|
val entity = Artist(id = 10, name = "artist-name", starred = Calendar.getInstance())
|
||||||
|
|
||||||
|
val convertedEntity = entity.toDomainEntity()
|
||||||
|
|
||||||
|
with(convertedEntity) {
|
||||||
|
id `should equal to` entity.id.toString()
|
||||||
|
name `should equal to` entity.name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should convert Artist entity to domain MusicDirectory entity`() {
|
||||||
|
val entity = Artist(id = 101L, name = "artist-name", coverArt = "some-art", albumCount = 10,
|
||||||
|
albumsList = listOf(Album(id = 562L, name = "some-name", coverArt = "zzz",
|
||||||
|
artist = "artist-name", artistId = 256L, songCount = 10, duration = 345,
|
||||||
|
created = Calendar.getInstance(), year = 2011, genre = "Math Rock")))
|
||||||
|
|
||||||
|
val convertedEntity = entity.toMusicDirectoryDomainEntity()
|
||||||
|
|
||||||
|
with(convertedEntity) {
|
||||||
|
name `should equal to` entity.name
|
||||||
|
children `should equal` entity.albumsList.map { it.toDomainEntity() }.toMutableList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,327 +0,0 @@
|
|||||||
@file:Suppress("IllegalIdentifier")
|
|
||||||
|
|
||||||
package org.moire.ultrasonic.data
|
|
||||||
|
|
||||||
import org.amshove.kluent.`should equal to`
|
|
||||||
import org.amshove.kluent.`should equal`
|
|
||||||
import org.amshove.kluent.`should not equal`
|
|
||||||
import org.junit.Test
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.Album
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.Artist
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.Index
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.Indexes
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.MusicDirectory
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.MusicFolder
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.Playlist
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.SearchResult
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.SearchThreeResult
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.SearchTwoResult
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Calendar
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unit test for functions in SubsonicAPIConverter file.
|
|
||||||
*
|
|
||||||
* @author Yahor Berdnikau
|
|
||||||
*/
|
|
||||||
@Suppress("TooManyFunctions", "LargeClass")
|
|
||||||
class APIConverterTest {
|
|
||||||
@Test
|
|
||||||
fun `Should convert MusicFolder entity`() {
|
|
||||||
val entity = createMusicFolder(10, "some-name")
|
|
||||||
|
|
||||||
val convertedEntity = entity.toDomainEntity()
|
|
||||||
|
|
||||||
convertedEntity.name `should equal to` entity.name
|
|
||||||
convertedEntity.id `should equal to` entity.id.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `Should convert list of MusicFolder entities`() {
|
|
||||||
val entityList = listOf(
|
|
||||||
createMusicFolder(3, "some-name-3"),
|
|
||||||
createMusicFolder(4, "some-name-4")
|
|
||||||
)
|
|
||||||
|
|
||||||
val convertedList = entityList.toDomainEntityList()
|
|
||||||
|
|
||||||
with(convertedList) {
|
|
||||||
size `should equal to` entityList.size
|
|
||||||
this[0].id `should equal to` entityList[0].id.toString()
|
|
||||||
this[0].name `should equal to` entityList[0].name
|
|
||||||
this[1].id `should equal to` entityList[1].id.toString()
|
|
||||||
this[1].name `should equal to` entityList[1].name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `Should convert artist entity`() {
|
|
||||||
val entity = createArtist(10, "artist-name", Calendar.getInstance())
|
|
||||||
|
|
||||||
val convertedEntity = entity.toDomainEntity()
|
|
||||||
|
|
||||||
with(convertedEntity) {
|
|
||||||
id `should equal to` entity.id.toString()
|
|
||||||
name `should equal to` entity.name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `Should convert Indexes entity`() {
|
|
||||||
val artistsA = listOf(createArtist(4, "AC/DC"), createArtist(45, "ABBA"))
|
|
||||||
val artistsT = listOf(createArtist(10, "Taproot"), createArtist(12, "Teebee"))
|
|
||||||
val entity = createIndexes(154, "Le Tre Ze", listOf(
|
|
||||||
createIndex("A", artistsA),
|
|
||||||
createIndex("T", artistsT)
|
|
||||||
), artistsA)
|
|
||||||
|
|
||||||
val convertedEntity = entity.toDomainEntity()
|
|
||||||
|
|
||||||
val expectedArtists = (artistsA + artistsT).map { it.toDomainEntity() }.toMutableList()
|
|
||||||
with(convertedEntity) {
|
|
||||||
lastModified `should equal to` entity.lastModified
|
|
||||||
ignoredArticles `should equal to` entity.ignoredArticles
|
|
||||||
artists.size `should equal to` expectedArtists.size
|
|
||||||
artists `should equal` expectedArtists
|
|
||||||
shortcuts `should equal` artistsA.map { it.toDomainEntity() }.toMutableList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `Should convert MusicDirectory entity`() {
|
|
||||||
val entity = MusicDirectory(id = 1982L, parent = 345L, name = "some-name", userRating = 3,
|
|
||||||
averageRating = 3.4f, starred = Calendar.getInstance(), playCount = 10,
|
|
||||||
childList = listOf(MusicDirectoryChild(1L), MusicDirectoryChild(2L)))
|
|
||||||
|
|
||||||
val convertedEntity = entity.toDomainEntity()
|
|
||||||
|
|
||||||
with(convertedEntity) {
|
|
||||||
name `should equal to` entity.name
|
|
||||||
children.size `should equal to` entity.childList.size
|
|
||||||
children `should equal` entity.childList.map { it.toDomainEntity() }.toMutableList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `Should convert MusicDirectoryChild entity`() {
|
|
||||||
val entity = MusicDirectoryChild(id = 929L, parent = 11L, title = "some-title",
|
|
||||||
album = "some-album", albumId = 231L, artist = "some-artist", artistId = 1233L,
|
|
||||||
track = 12, year = 2002, genre = "some-genre", coverArt = "952", size = 9418123L,
|
|
||||||
contentType = "some-content-type", suffix = "some-suffix",
|
|
||||||
transcodedContentType = "some-transcoded-content-type",
|
|
||||||
transcodedSuffix = "some-transcoded-suffix", duration = 11, bitRate = 256,
|
|
||||||
path = "some-path", isDir = true, isVideo = true, playCount = 323, discNumber = 2,
|
|
||||||
created = Calendar.getInstance(), type = "some-type", starred = Calendar.getInstance())
|
|
||||||
|
|
||||||
val convertedEntity = entity.toDomainEntity()
|
|
||||||
|
|
||||||
with(convertedEntity) {
|
|
||||||
id `should equal to` entity.id.toString()
|
|
||||||
parent `should equal to` entity.parent.toString()
|
|
||||||
isDirectory `should equal to` entity.isDir
|
|
||||||
title `should equal` entity.title
|
|
||||||
album `should equal` entity.album
|
|
||||||
albumId `should equal to` entity.albumId.toString()
|
|
||||||
artist `should equal to` entity.artist
|
|
||||||
artistId `should equal to` entity.artistId.toString()
|
|
||||||
track `should equal to` entity.track
|
|
||||||
year `should equal to` entity.year!!
|
|
||||||
genre `should equal to` entity.genre
|
|
||||||
contentType `should equal to` entity.contentType
|
|
||||||
suffix `should equal to` entity.suffix
|
|
||||||
transcodedContentType `should equal to` entity.transcodedContentType
|
|
||||||
transcodedSuffix `should equal to` entity.transcodedSuffix
|
|
||||||
coverArt `should equal to` entity.coverArt
|
|
||||||
size `should equal to` entity.size
|
|
||||||
duration `should equal to` entity.duration
|
|
||||||
bitRate `should equal to` entity.bitRate
|
|
||||||
path `should equal to` entity.path
|
|
||||||
isVideo `should equal to` entity.isVideo
|
|
||||||
created `should equal` entity.created?.time
|
|
||||||
starred `should equal to` (entity.starred != null)
|
|
||||||
discNumber `should equal to` entity.discNumber
|
|
||||||
type `should equal to` entity.type
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `Should convert Artist entity to domain MusicDirectory entity`() {
|
|
||||||
val entity = Artist(id = 101L, name = "artist-name", coverArt = "some-art", albumCount = 10,
|
|
||||||
albumsList = listOf(Album(id = 562L, name = "some-name", coverArt = "zzz",
|
|
||||||
artist = "artist-name", artistId = 256L, songCount = 10, duration = 345,
|
|
||||||
created = Calendar.getInstance(), year = 2011, genre = "Math Rock")))
|
|
||||||
|
|
||||||
val convertedEntity = entity.toMusicDirectoryDomainEntity()
|
|
||||||
|
|
||||||
with(convertedEntity) {
|
|
||||||
name `should equal to` entity.name
|
|
||||||
children `should equal` entity.albumsList.map { it.toDomainEntity() }.toMutableList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `Should convert Album to domain entity`() {
|
|
||||||
val entity = Album(id = 387L, name = "some-name", coverArt = "asdas", artist = "some-artist",
|
|
||||||
artistId = 390L, songCount = 12, duration = 841, created = Calendar.getInstance(),
|
|
||||||
year = 2017, genre = "some-genre")
|
|
||||||
|
|
||||||
val convertedEntity = entity.toDomainEntity()
|
|
||||||
|
|
||||||
with(convertedEntity) {
|
|
||||||
id `should equal to` entity.id.toString()
|
|
||||||
title `should equal to` entity.name
|
|
||||||
isDirectory `should equal to` true
|
|
||||||
coverArt `should equal to` entity.coverArt
|
|
||||||
artist `should equal to` entity.artist
|
|
||||||
artistId `should equal to` entity.artistId.toString()
|
|
||||||
songCount `should equal to` entity.songCount.toLong()
|
|
||||||
duration `should equal to` entity.duration
|
|
||||||
created `should equal` entity.created?.time
|
|
||||||
year `should equal to` entity.year
|
|
||||||
genre `should equal to` entity.genre
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `Should convert to MusicDirectory domain entity`() {
|
|
||||||
val entity = Album(id = 101L, name = "some-album", artist = "some-artist", artistId = 54L,
|
|
||||||
coverArt = "some-id", songCount = 10, duration = 456,
|
|
||||||
created = Calendar.getInstance(), year = 2022, genre = "Hard Rock",
|
|
||||||
songList = listOf(MusicDirectoryChild()))
|
|
||||||
|
|
||||||
val convertedEntity = entity.toMusicDirectoryDomainEntity()
|
|
||||||
|
|
||||||
with(convertedEntity) {
|
|
||||||
name `should equal` null
|
|
||||||
children.size `should equal to` entity.songList.size
|
|
||||||
children[0] `should equal` entity.songList[0].toDomainEntity()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `Should convert SearchResult to domain entity`() {
|
|
||||||
val entity = SearchResult(offset = 10, totalHits = 3, matchList = listOf(
|
|
||||||
MusicDirectoryChild(id = 101L)
|
|
||||||
))
|
|
||||||
|
|
||||||
val convertedEntity = entity.toDomainEntity()
|
|
||||||
|
|
||||||
with(convertedEntity) {
|
|
||||||
albums `should not equal` null
|
|
||||||
albums.size `should equal to` 0
|
|
||||||
artists `should not equal` null
|
|
||||||
artists.size `should equal to` 0
|
|
||||||
songs.size `should equal to` entity.matchList.size
|
|
||||||
songs[0] `should equal` entity.matchList[0].toDomainEntity()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `Should convert SearchTwoResult to domain entity`() {
|
|
||||||
val entity = SearchTwoResult(listOf(
|
|
||||||
Artist(id = 82, name = "great-artist-name")
|
|
||||||
), listOf(
|
|
||||||
MusicDirectoryChild(id = 762, artist = "bzz")
|
|
||||||
), listOf(
|
|
||||||
MusicDirectoryChild(id = 9118, parent = 112)
|
|
||||||
))
|
|
||||||
|
|
||||||
val convertedEntity = entity.toDomainEntity()
|
|
||||||
|
|
||||||
with(convertedEntity) {
|
|
||||||
artists.size `should equal to` entity.artistList.size
|
|
||||||
artists[0] `should equal` entity.artistList[0].toDomainEntity()
|
|
||||||
albums.size `should equal to` entity.albumList.size
|
|
||||||
albums[0] `should equal` entity.albumList[0].toDomainEntity()
|
|
||||||
songs.size `should equal to` entity.songList.size
|
|
||||||
songs[0] `should equal` entity.songList[0].toDomainEntity()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `Should convert SearchThreeResult to domain entity`() {
|
|
||||||
val entity = SearchThreeResult(
|
|
||||||
artistList = listOf(Artist(id = 612, name = "artist1")),
|
|
||||||
albumList = listOf(Album(id = 221, name = "album1")),
|
|
||||||
songList = listOf(MusicDirectoryChild(id = 7123, title = "song1"))
|
|
||||||
)
|
|
||||||
|
|
||||||
val convertedEntity = entity.toDomainEntity()
|
|
||||||
|
|
||||||
with(convertedEntity) {
|
|
||||||
artists.size `should equal to` entity.artistList.size
|
|
||||||
artists[0] `should equal` entity.artistList[0].toDomainEntity()
|
|
||||||
albums.size `should equal to` entity.albumList.size
|
|
||||||
albums[0] `should equal` entity.albumList[0].toDomainEntity()
|
|
||||||
songs.size `should equal to` entity.songList.size
|
|
||||||
songs[0] `should equal` entity.songList[0].toDomainEntity()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `Should convert Playlist to MusicDirectory domain entity`() {
|
|
||||||
val entity = Playlist(name = "some-playlist-name", entriesList = listOf(
|
|
||||||
MusicDirectoryChild(id = 10L, parent = 1393),
|
|
||||||
MusicDirectoryChild(id = 11L, parent = 1393)
|
|
||||||
))
|
|
||||||
|
|
||||||
val convertedEntity = entity.toMusicDirectoryDomainEntity()
|
|
||||||
|
|
||||||
with(convertedEntity) {
|
|
||||||
name `should equal to` entity.name
|
|
||||||
children.size `should equal to` entity.entriesList.size
|
|
||||||
children[0] `should equal` entity.entriesList[0].toDomainEntity()
|
|
||||||
children[1] `should equal` entity.entriesList[1].toDomainEntity()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `Should convert playlist to domain entity`() {
|
|
||||||
val entity = Playlist(id = 634, name = "some-name", owner = "some-owner",
|
|
||||||
comment = "some-comment", public = false, songCount = 256, duration = 1150,
|
|
||||||
created = Calendar.getInstance(), changed = Calendar.getInstance(),
|
|
||||||
coverArt = "some-art")
|
|
||||||
|
|
||||||
val convertedEntity = entity.toDomainEntity()
|
|
||||||
|
|
||||||
with(convertedEntity) {
|
|
||||||
id `should equal to` entity.id.toString()
|
|
||||||
name `should equal to` entity.name
|
|
||||||
comment `should equal to` entity.comment
|
|
||||||
owner `should equal to` entity.owner
|
|
||||||
public `should equal to` entity.public
|
|
||||||
songCount `should equal to` entity.songCount.toString()
|
|
||||||
created `should equal to` SimpleDateFormat.getDateTimeInstance()
|
|
||||||
.format(entity.created?.time)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `Should convert list of playlists to list of domain entities`() {
|
|
||||||
val entitiesList = listOf(Playlist(id = 23, name = "some-name", songCount = 10))
|
|
||||||
|
|
||||||
val convertedList = entitiesList.toDomainEntitiesList()
|
|
||||||
|
|
||||||
with(convertedList) {
|
|
||||||
size `should equal to` entitiesList.size
|
|
||||||
this[0] `should equal` entitiesList[0].toDomainEntity()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun createMusicFolder(id: Long = 0, name: String = ""): MusicFolder =
|
|
||||||
MusicFolder(id, name)
|
|
||||||
|
|
||||||
private fun createArtist(id: Long = -1, name: String = "", starred: Calendar? = null): Artist
|
|
||||||
= Artist(id = id, name = name, starred = starred)
|
|
||||||
|
|
||||||
private fun createIndex(name: String = "", artistList: List<Artist> = emptyList()): Index
|
|
||||||
= Index(name, artistList)
|
|
||||||
|
|
||||||
private fun createIndexes(
|
|
||||||
lastModified: Long = 0,
|
|
||||||
ignoredArticles: String,
|
|
||||||
indexList: List<Index> = emptyList(),
|
|
||||||
shortcuts: List<Artist> = emptyList()): Indexes
|
|
||||||
= Indexes(lastModified, ignoredArticles, indexList, shortcuts)
|
|
||||||
}
|
|
@ -0,0 +1,40 @@
|
|||||||
|
@file:Suppress("IllegalIdentifier")
|
||||||
|
|
||||||
|
package org.moire.ultrasonic.data
|
||||||
|
|
||||||
|
import org.amshove.kluent.`should equal to`
|
||||||
|
import org.amshove.kluent.`should equal`
|
||||||
|
import org.junit.Test
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Artist
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Index
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Indexes
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit tests for extension functions in [APIIndexesConverter.kt].
|
||||||
|
*/
|
||||||
|
class APIIndexesConverterTest {
|
||||||
|
@Test
|
||||||
|
fun `Should convert Indexes entity`() {
|
||||||
|
val artistsA = listOf(
|
||||||
|
Artist(id =4, name = "AC/DC"),
|
||||||
|
Artist(id =45, name = "ABBA"))
|
||||||
|
val artistsT = listOf(
|
||||||
|
Artist(id = 10, name = "Taproot"),
|
||||||
|
Artist(id = 12, name = "Teebee"))
|
||||||
|
val entity = Indexes(lastModified = 154, ignoredArticles = "Le Tre Ze", indexList = listOf(
|
||||||
|
Index(name = "A", artists = artistsA),
|
||||||
|
Index(name = "T", artists = artistsT)
|
||||||
|
), shortcutList = artistsA)
|
||||||
|
|
||||||
|
val convertedEntity = entity.toDomainEntity()
|
||||||
|
|
||||||
|
val expectedArtists = (artistsA + artistsT).map { it.toDomainEntity() }.toMutableList()
|
||||||
|
with(convertedEntity) {
|
||||||
|
lastModified `should equal to` entity.lastModified
|
||||||
|
ignoredArticles `should equal to` entity.ignoredArticles
|
||||||
|
artists.size `should equal to` expectedArtists.size
|
||||||
|
artists `should equal` expectedArtists
|
||||||
|
shortcuts `should equal` artistsA.map { it.toDomainEntity() }.toMutableList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
@file:Suppress("IllegalIdentifier")
|
||||||
|
|
||||||
|
package org.moire.ultrasonic.data
|
||||||
|
|
||||||
|
import org.amshove.kluent.`should equal to`
|
||||||
|
import org.amshove.kluent.`should equal`
|
||||||
|
import org.junit.Test
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.MusicDirectory
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild
|
||||||
|
import java.util.Calendar
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for extension functions in [APIMusicDirectoryConverter.kt] file.
|
||||||
|
*/
|
||||||
|
class APIMusicDirectoryConverterTest {
|
||||||
|
@Test
|
||||||
|
fun `Should convert MusicDirectory entity`() {
|
||||||
|
val entity = MusicDirectory(id = 1982L, parent = 345L, name = "some-name", userRating = 3,
|
||||||
|
averageRating = 3.4f, starred = Calendar.getInstance(), playCount = 10,
|
||||||
|
childList = listOf(MusicDirectoryChild(1L), MusicDirectoryChild(2L)))
|
||||||
|
|
||||||
|
val convertedEntity = entity.toDomainEntity()
|
||||||
|
|
||||||
|
with(convertedEntity) {
|
||||||
|
name `should equal to` entity.name
|
||||||
|
children.size `should equal to` entity.childList.size
|
||||||
|
children `should equal` entity.childList.map { it.toDomainEntity() }.toMutableList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should convert MusicDirectoryChild entity`() {
|
||||||
|
val entity = MusicDirectoryChild(id = 929L, parent = 11L, title = "some-title",
|
||||||
|
album = "some-album", albumId = 231L, artist = "some-artist", artistId = 1233L,
|
||||||
|
track = 12, year = 2002, genre = "some-genre", coverArt = "952", size = 9418123L,
|
||||||
|
contentType = "some-content-type", suffix = "some-suffix",
|
||||||
|
transcodedContentType = "some-transcoded-content-type",
|
||||||
|
transcodedSuffix = "some-transcoded-suffix", duration = 11, bitRate = 256,
|
||||||
|
path = "some-path", isDir = true, isVideo = true, playCount = 323, discNumber = 2,
|
||||||
|
created = Calendar.getInstance(), type = "some-type", starred = Calendar.getInstance())
|
||||||
|
|
||||||
|
val convertedEntity = entity.toDomainEntity()
|
||||||
|
|
||||||
|
with(convertedEntity) {
|
||||||
|
id `should equal to` entity.id.toString()
|
||||||
|
parent `should equal to` entity.parent.toString()
|
||||||
|
isDirectory `should equal to` entity.isDir
|
||||||
|
title `should equal` entity.title
|
||||||
|
album `should equal` entity.album
|
||||||
|
albumId `should equal to` entity.albumId.toString()
|
||||||
|
artist `should equal to` entity.artist
|
||||||
|
artistId `should equal to` entity.artistId.toString()
|
||||||
|
track `should equal to` entity.track
|
||||||
|
year `should equal to` entity.year!!
|
||||||
|
genre `should equal to` entity.genre
|
||||||
|
contentType `should equal to` entity.contentType
|
||||||
|
suffix `should equal to` entity.suffix
|
||||||
|
transcodedContentType `should equal to` entity.transcodedContentType
|
||||||
|
transcodedSuffix `should equal to` entity.transcodedSuffix
|
||||||
|
coverArt `should equal to` entity.coverArt
|
||||||
|
size `should equal to` entity.size
|
||||||
|
duration `should equal to` entity.duration
|
||||||
|
bitRate `should equal to` entity.bitRate
|
||||||
|
path `should equal to` entity.path
|
||||||
|
isVideo `should equal to` entity.isVideo
|
||||||
|
created `should equal` entity.created?.time
|
||||||
|
starred `should equal to` (entity.starred != null)
|
||||||
|
discNumber `should equal to` entity.discNumber
|
||||||
|
type `should equal to` entity.type
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
@file:Suppress("IllegalIdentifier")
|
||||||
|
|
||||||
|
package org.moire.ultrasonic.data
|
||||||
|
|
||||||
|
import org.amshove.kluent.`should equal to`
|
||||||
|
import org.junit.Test
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.MusicFolder
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for extension functions in file APIMusicFolderConverter.kt.
|
||||||
|
*/
|
||||||
|
class APIMusicFolderConverterTest {
|
||||||
|
@Test
|
||||||
|
fun `Should convert MusicFolder entity`() {
|
||||||
|
val entity = MusicFolder(id = 10, name = "some-name")
|
||||||
|
|
||||||
|
val convertedEntity = entity.toDomainEntity()
|
||||||
|
|
||||||
|
convertedEntity.name `should equal to` entity.name
|
||||||
|
convertedEntity.id `should equal to` entity.id.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should convert list of MusicFolder entities`() {
|
||||||
|
val entityList = listOf(
|
||||||
|
MusicFolder(id = 3, name = "some-name-3"),
|
||||||
|
MusicFolder(id = 4, name = "some-name-4"))
|
||||||
|
|
||||||
|
val convertedList = entityList.toDomainEntityList()
|
||||||
|
|
||||||
|
with(convertedList) {
|
||||||
|
size `should equal to` entityList.size
|
||||||
|
this[0].id `should equal to` entityList[0].id.toString()
|
||||||
|
this[0].name `should equal to` entityList[0].name
|
||||||
|
this[1].id `should equal to` entityList[1].id.toString()
|
||||||
|
this[1].name `should equal to` entityList[1].name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
@file:Suppress("IllegalIdentifier")
|
||||||
|
|
||||||
|
package org.moire.ultrasonic.data
|
||||||
|
|
||||||
|
import org.amshove.kluent.`should equal to`
|
||||||
|
import org.amshove.kluent.`should equal`
|
||||||
|
import org.junit.Test
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Playlist
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Calendar
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for extension functions in [APIPlaylistConverter.kt] file.
|
||||||
|
*/
|
||||||
|
class APIPlaylistConverterTest {
|
||||||
|
@Test
|
||||||
|
fun `Should convert Playlist to MusicDirectory domain entity`() {
|
||||||
|
val entity = Playlist(name = "some-playlist-name", entriesList = listOf(
|
||||||
|
MusicDirectoryChild(id = 10L, parent = 1393),
|
||||||
|
MusicDirectoryChild(id = 11L, parent = 1393)
|
||||||
|
))
|
||||||
|
|
||||||
|
val convertedEntity = entity.toMusicDirectoryDomainEntity()
|
||||||
|
|
||||||
|
with(convertedEntity) {
|
||||||
|
name `should equal to` entity.name
|
||||||
|
children.size `should equal to` entity.entriesList.size
|
||||||
|
children[0] `should equal` entity.entriesList[0].toDomainEntity()
|
||||||
|
children[1] `should equal` entity.entriesList[1].toDomainEntity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should convert playlist to domain entity`() {
|
||||||
|
val entity = Playlist(id = 634, name = "some-name", owner = "some-owner",
|
||||||
|
comment = "some-comment", public = false, songCount = 256, duration = 1150,
|
||||||
|
created = Calendar.getInstance(), changed = Calendar.getInstance(),
|
||||||
|
coverArt = "some-art")
|
||||||
|
|
||||||
|
val convertedEntity = entity.toDomainEntity()
|
||||||
|
|
||||||
|
with(convertedEntity) {
|
||||||
|
id `should equal to` entity.id.toString()
|
||||||
|
name `should equal to` entity.name
|
||||||
|
comment `should equal to` entity.comment
|
||||||
|
owner `should equal to` entity.owner
|
||||||
|
public `should equal to` entity.public
|
||||||
|
songCount `should equal to` entity.songCount.toString()
|
||||||
|
created `should equal to` SimpleDateFormat.getDateTimeInstance()
|
||||||
|
.format(entity.created?.time)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should convert list of playlists to list of domain entities`() {
|
||||||
|
val entitiesList = listOf(Playlist(id = 23, name = "some-name", songCount = 10))
|
||||||
|
|
||||||
|
val convertedList = entitiesList.toDomainEntitiesList()
|
||||||
|
|
||||||
|
with(convertedList) {
|
||||||
|
size `should equal to` entitiesList.size
|
||||||
|
this[0] `should equal` entitiesList[0].toDomainEntity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
@file:Suppress("IllegalIdentifier")
|
||||||
|
|
||||||
|
package org.moire.ultrasonic.data
|
||||||
|
|
||||||
|
import org.amshove.kluent.`should equal to`
|
||||||
|
import org.amshove.kluent.`should equal`
|
||||||
|
import org.amshove.kluent.`should not equal`
|
||||||
|
import org.junit.Test
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Album
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Artist
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.SearchResult
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.SearchThreeResult
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.SearchTwoResult
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for extension function in [APISearchConverter.kt] file.
|
||||||
|
*/
|
||||||
|
class APISearchConverterTest {
|
||||||
|
@Test
|
||||||
|
fun `Should convert SearchResult to domain entity`() {
|
||||||
|
val entity = SearchResult(offset = 10, totalHits = 3, matchList = listOf(
|
||||||
|
MusicDirectoryChild(id = 101L)
|
||||||
|
))
|
||||||
|
|
||||||
|
val convertedEntity = entity.toDomainEntity()
|
||||||
|
|
||||||
|
with(convertedEntity) {
|
||||||
|
albums `should not equal` null
|
||||||
|
albums.size `should equal to` 0
|
||||||
|
artists `should not equal` null
|
||||||
|
artists.size `should equal to` 0
|
||||||
|
songs.size `should equal to` entity.matchList.size
|
||||||
|
songs[0] `should equal` entity.matchList[0].toDomainEntity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should convert SearchTwoResult to domain entity`() {
|
||||||
|
val entity = SearchTwoResult(listOf(
|
||||||
|
Artist(id = 82, name = "great-artist-name")
|
||||||
|
), listOf(
|
||||||
|
MusicDirectoryChild(id = 762, artist = "bzz")
|
||||||
|
), listOf(
|
||||||
|
MusicDirectoryChild(id = 9118, parent = 112)
|
||||||
|
))
|
||||||
|
|
||||||
|
val convertedEntity = entity.toDomainEntity()
|
||||||
|
|
||||||
|
with(convertedEntity) {
|
||||||
|
artists.size `should equal to` entity.artistList.size
|
||||||
|
artists[0] `should equal` entity.artistList[0].toDomainEntity()
|
||||||
|
albums.size `should equal to` entity.albumList.size
|
||||||
|
albums[0] `should equal` entity.albumList[0].toDomainEntity()
|
||||||
|
songs.size `should equal to` entity.songList.size
|
||||||
|
songs[0] `should equal` entity.songList[0].toDomainEntity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should convert SearchThreeResult to domain entity`() {
|
||||||
|
val entity = SearchThreeResult(
|
||||||
|
artistList = listOf(Artist(id = 612, name = "artist1")),
|
||||||
|
albumList = listOf(Album(id = 221, name = "album1")),
|
||||||
|
songList = listOf(MusicDirectoryChild(id = 7123, title = "song1"))
|
||||||
|
)
|
||||||
|
|
||||||
|
val convertedEntity = entity.toDomainEntity()
|
||||||
|
|
||||||
|
with(convertedEntity) {
|
||||||
|
artists.size `should equal to` entity.artistList.size
|
||||||
|
artists[0] `should equal` entity.artistList[0].toDomainEntity()
|
||||||
|
albums.size `should equal to` entity.albumList.size
|
||||||
|
albums[0] `should equal` entity.albumList[0].toDomainEntity()
|
||||||
|
songs.size `should equal to` entity.songList.size
|
||||||
|
songs[0] `should equal` entity.songList[0].toDomainEntity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user