diff --git a/opengraphkt/src/test/kotlin/fr/lengrand/opengraphkt/GeneratorTest.kt b/opengraphkt/src/test/kotlin/fr/lengrand/opengraphkt/GeneratorTest.kt
index c9a7b02..9382694 100644
--- a/opengraphkt/src/test/kotlin/fr/lengrand/opengraphkt/GeneratorTest.kt
+++ b/opengraphkt/src/test/kotlin/fr/lengrand/opengraphkt/GeneratorTest.kt
@@ -3,6 +3,7 @@ package fr.lengrand.opengraphkt
import org.junit.jupiter.api.Test
import java.net.URI
import java.time.OffsetDateTime
+import kotlin.test.assertEquals
import kotlin.test.assertTrue
class GeneratorTest {
@@ -103,7 +104,7 @@ class GeneratorTest {
assertTrue(html.contains(""))
assertTrue(html.contains(""))
assertTrue(html.contains(""))
-
+
assertTrue(html.contains(""))
assertTrue(html.contains(""))
assertTrue(html.contains(""))
@@ -248,7 +249,7 @@ class GeneratorTest {
assertTrue(html.contains(""))
assertTrue(html.contains(""))
assertTrue(html.contains(""))
-
+
assertTrue(html.contains(""))
assertTrue(html.contains(""))
assertTrue(html.contains(""))
@@ -292,6 +293,448 @@ class GeneratorTest {
assertTrue(html.contains(""))
}
+ @Test
+ fun `test generate with audio`() {
+ // Create a Data object with audio metadata
+ val data = Data(
+ tags = emptyList(),
+ title = "Test Audio",
+ type = "website",
+ url = URI("https://example.com/audio").toURL(),
+ description = null,
+ siteName = null,
+ determiner = null,
+ locale = null,
+ localeAlternate = emptyList(),
+ images = emptyList(),
+ videos = emptyList(),
+ audios = listOf(
+ Audio(
+ url = "https://example.com/audio.mp3",
+ secureUrl = "https://secure.example.com/audio.mp3",
+ type = "audio/mpeg"
+ ),
+ Audio(
+ url = "https://example.com/audio.wav",
+ secureUrl = null,
+ type = "audio/wav"
+ )
+ ),
+ article = null,
+ profile = null,
+ book = null,
+ musicSong = null,
+ musicAlbum = null,
+ musicPlaylist = null,
+ musicRadioStation = null,
+ videoMovie = null,
+ videoEpisode = null
+ )
+
+ val html = generator.generate(data)
+
+ // Verify that all audio tags are generated correctly
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ }
+
+ @Test
+ fun `test generate with book`() {
+ // Create a Data object with book metadata
+ val data = Data(
+ tags = emptyList(),
+ title = "Test Book",
+ type = "book",
+ url = URI("https://example.com/book").toURL(),
+ description = null,
+ siteName = null,
+ determiner = null,
+ locale = null,
+ localeAlternate = emptyList(),
+ images = emptyList(),
+ videos = emptyList(),
+ audios = emptyList(),
+ article = null,
+ profile = null,
+ book = Book(
+ authors = listOf("Author 1", "Author 2"),
+ isbn = "978-3-16-148410-0",
+ releaseDate = OffsetDateTime.parse("2023-01-01T00:00:00Z"),
+ tags = listOf("fiction", "fantasy")
+ ),
+ musicSong = null,
+ musicAlbum = null,
+ musicPlaylist = null,
+ musicRadioStation = null,
+ videoMovie = null,
+ videoEpisode = null
+ )
+
+ val html = generator.generate(data)
+
+ // Verify that all book tags are generated correctly
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ }
+
+ @Test
+ fun `test generate with music song`() {
+ // Create a Data object with music.song metadata
+ val data = Data(
+ tags = emptyList(),
+ title = "Test Song",
+ type = "music.song",
+ url = URI("https://example.com/song").toURL(),
+ description = null,
+ siteName = null,
+ determiner = null,
+ locale = null,
+ localeAlternate = emptyList(),
+ images = emptyList(),
+ videos = emptyList(),
+ audios = emptyList(),
+ article = null,
+ profile = null,
+ book = null,
+ musicSong = MusicSong(
+ duration = 240,
+ album = "Test Album",
+ albumDisc = 1,
+ albumTrack = 5,
+ musician = listOf("Musician 1", "Musician 2")
+ ),
+ musicAlbum = null,
+ musicPlaylist = null,
+ musicRadioStation = null,
+ videoMovie = null,
+ videoEpisode = null
+ )
+
+ val html = generator.generate(data)
+
+ // Verify that all music.song tags are generated correctly
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ }
+
+ @Test
+ fun `test generate with music album`() {
+ // Create a Data object with music.album metadata
+ val data = Data(
+ tags = emptyList(),
+ title = "Test Album",
+ type = "music.album",
+ url = URI("https://example.com/album").toURL(),
+ description = null,
+ siteName = null,
+ determiner = null,
+ locale = null,
+ localeAlternate = emptyList(),
+ images = emptyList(),
+ videos = emptyList(),
+ audios = emptyList(),
+ article = null,
+ profile = null,
+ book = null,
+ musicSong = null,
+ musicAlbum = MusicAlbum(
+ songs = listOf("Song 1", "Song 2"),
+ songDisc = 1,
+ songTrack = 1,
+ musician = listOf("Musician 1", "Musician 2"),
+ releaseDate = OffsetDateTime.parse("2023-01-01T00:00:00Z")
+ ),
+ musicPlaylist = null,
+ musicRadioStation = null,
+ videoMovie = null,
+ videoEpisode = null
+ )
+
+ val html = generator.generate(data)
+
+ // Verify that all music.album tags are generated correctly
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ }
+
+ @Test
+ fun `test generate with music playlist`() {
+ // Create a Data object with music.playlist metadata
+ val data = Data(
+ tags = emptyList(),
+ title = "Test Playlist",
+ type = "music.playlist",
+ url = URI("https://example.com/playlist").toURL(),
+ description = null,
+ siteName = null,
+ determiner = null,
+ locale = null,
+ localeAlternate = emptyList(),
+ images = emptyList(),
+ videos = emptyList(),
+ audios = emptyList(),
+ article = null,
+ profile = null,
+ book = null,
+ musicSong = null,
+ musicAlbum = null,
+ musicPlaylist = MusicPlaylist(
+ songs = listOf("Song 1", "Song 2"),
+ songDisc = 1,
+ songTrack = 1,
+ creator = "Playlist Creator"
+ ),
+ musicRadioStation = null,
+ videoMovie = null,
+ videoEpisode = null
+ )
+
+ val html = generator.generate(data)
+
+ // Verify that all music.playlist tags are generated correctly
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ }
+
+ @Test
+ fun `test generate with music radio station`() {
+ // Create a Data object with music.radio_station metadata
+ val data = Data(
+ tags = emptyList(),
+ title = "Test Radio Station",
+ type = "music.radio_station",
+ url = URI("https://example.com/radio").toURL(),
+ description = null,
+ siteName = null,
+ determiner = null,
+ locale = null,
+ localeAlternate = emptyList(),
+ images = emptyList(),
+ videos = emptyList(),
+ audios = emptyList(),
+ article = null,
+ profile = null,
+ book = null,
+ musicSong = null,
+ musicAlbum = null,
+ musicPlaylist = null,
+ musicRadioStation = MusicRadioStation(
+ creator = "Radio Station Creator"
+ ),
+ videoMovie = null,
+ videoEpisode = null
+ )
+
+ val html = generator.generate(data)
+
+ // Verify that all music.radio_station tags are generated correctly
+ assertTrue(html.contains(""))
+ }
+
+ @Test
+ fun `test generate with video episode`() {
+ // Create a Data object with video.episode metadata
+ val data = Data(
+ tags = emptyList(),
+ title = "Test Episode",
+ type = "video.episode",
+ url = URI("https://example.com/episode").toURL(),
+ description = null,
+ siteName = null,
+ determiner = null,
+ locale = null,
+ localeAlternate = emptyList(),
+ images = emptyList(),
+ videos = emptyList(),
+ audios = emptyList(),
+ article = null,
+ profile = null,
+ book = null,
+ musicSong = null,
+ musicAlbum = null,
+ musicPlaylist = null,
+ musicRadioStation = null,
+ videoMovie = null,
+ videoEpisode = VideoEpisode(
+ actors = listOf("Actor 1", "Actor 2"),
+ director = listOf("Director"),
+ writer = listOf("Writer 1", "Writer 2"),
+ duration = 45,
+ releaseDate = OffsetDateTime.parse("2023-01-01T00:00:00Z"),
+ tags = listOf("drama", "comedy"),
+ series = "Test Series"
+ )
+ )
+
+ val html = generator.generate(data)
+
+ // Verify that all video.episode tags are generated correctly
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ }
+
+ @Test
+ fun `test generate with null values`() {
+ // Create a Data object with null values
+ val data = Data(
+ tags = emptyList(),
+ title = "Test Null Values",
+ type = "website",
+ url = URI("https://example.com").toURL(),
+ description = null,
+ siteName = null,
+ determiner = null,
+ locale = null,
+ localeAlternate = emptyList(),
+ images = emptyList(),
+ videos = emptyList(),
+ audios = emptyList(),
+ article = null,
+ profile = null,
+ book = null,
+ musicSong = null,
+ musicAlbum = null,
+ musicPlaylist = null,
+ musicRadioStation = null,
+ videoMovie = null,
+ videoEpisode = null
+ )
+
+ val html = generator.generate(data)
+
+ // Verify that only non-null values are included
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+
+ // These should not be in the output
+ assertEquals(false, html.contains("og:description"))
+ assertEquals(false, html.contains("og:site_name"))
+ assertEquals(false, html.contains("og:determiner"))
+ assertEquals(false, html.contains("og:locale"))
+ }
+
+ @Test
+ fun `test generate with empty collections`() {
+ // Create a Data object with empty collections
+ val data = Data(
+ tags = emptyList(),
+ title = "Test Empty Collections",
+ type = "article",
+ url = URI("https://example.com").toURL(),
+ description = null,
+ siteName = null,
+ determiner = null,
+ locale = null,
+ localeAlternate = emptyList(),
+ images = emptyList(),
+ videos = emptyList(),
+ audios = emptyList(),
+ article = Article(
+ publishedTime = null,
+ modifiedTime = null,
+ expirationTime = null,
+ authors = emptyList(),
+ section = null,
+ tags = emptyList()
+ ),
+ profile = null,
+ book = null,
+ musicSong = null,
+ musicAlbum = null,
+ musicPlaylist = null,
+ musicRadioStation = null,
+ videoMovie = null,
+ videoEpisode = null
+ )
+
+ val html = generator.generate(data)
+
+ // Verify that empty collections don't generate any tags
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+
+ // These should not be in the output
+ assertEquals(false, html.contains("og:article:published_time"))
+ assertEquals(false, html.contains("og:article:modified_time"))
+ assertEquals(false, html.contains("og:article:expiration_time"))
+ assertEquals(false, html.contains("og:article:author"))
+ assertEquals(false, html.contains("og:article:section"))
+ assertEquals(false, html.contains("og:article:tag"))
+ }
+
+ @Test
+ fun `test format date time`() {
+ // Create a Data object with date time values
+ val data = Data(
+ tags = emptyList(),
+ title = "Test Date Time",
+ type = "article",
+ url = URI("https://example.com").toURL(),
+ description = null,
+ siteName = null,
+ determiner = null,
+ locale = null,
+ localeAlternate = emptyList(),
+ images = emptyList(),
+ videos = emptyList(),
+ audios = emptyList(),
+ article = Article(
+ publishedTime = OffsetDateTime.parse("2023-01-01T12:34:56+01:00"),
+ modifiedTime = OffsetDateTime.parse("2023-01-02T00:00:00Z"),
+ expirationTime = OffsetDateTime.parse("2023-12-31T23:59:59-08:00"),
+ authors = emptyList(),
+ section = null,
+ tags = emptyList()
+ ),
+ profile = null,
+ book = null,
+ musicSong = null,
+ musicAlbum = null,
+ musicPlaylist = null,
+ musicRadioStation = null,
+ videoMovie = null,
+ videoEpisode = null
+ )
+
+ val html = generator.generate(data)
+
+ // Verify that date time values are formatted correctly
+ // The formatDateTime method converts to UTC/Z time
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ assertTrue(html.contains(""))
+ }
+
@Test
fun `test round trip conversion`() {
// Create a sample HTML with OpenGraph tags
@@ -326,4 +769,4 @@ class GeneratorTest {
assertTrue(generatedHtml.contains(""))
assertTrue(generatedHtml.contains(""))
}
-}
\ No newline at end of file
+}