forked from madhead/doktor
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from madhead/develop
New features!
- Loading branch information
Showing
43 changed files
with
607 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
package by.dev.madhead.doktor.model | ||
|
||
import java.io.Serializable | ||
import java.util.Arrays | ||
|
||
data class Attachment( | ||
val fileName: String, | ||
val bytes: ByteArray | ||
) : Serializable | ||
) : Serializable { | ||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
|
||
other as Attachment | ||
|
||
if (fileName != other.fileName) return false | ||
if (!Arrays.equals(bytes, other.bytes)) return false | ||
|
||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = fileName.hashCode() | ||
|
||
result = 31 * result + Arrays.hashCode(bytes) | ||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/test/kotlin/by/dev/madhead/doktor/render/DokRendererTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package by.dev.madhead.doktor.render | ||
|
||
import by.dev.madhead.doktor.model.Markup | ||
import by.dev.madhead.doktor.model.RenderedDok | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory | ||
import com.fasterxml.jackson.module.kotlin.readValue | ||
import com.fasterxml.jackson.module.kotlin.registerKotlinModule | ||
import com.github.tomakehurst.wiremock.WireMockServer | ||
import hudson.model.TaskListener | ||
import org.mockito.Mockito | ||
import org.testng.Assert | ||
import org.testng.annotations.DataProvider | ||
import org.testng.annotations.Test | ||
import java.io.File | ||
import java.io.PrintStream | ||
|
||
class DokRendererTest { | ||
val objectMapper = ObjectMapper(YAMLFactory()).registerKotlinModule() | ||
lateinit private var wiremock: WireMockServer | ||
|
||
@DataProvider(name = "markdowns") | ||
fun markdowns(): Array<Array<*>> { | ||
return listOf( | ||
"local_image", | ||
"remote_image", | ||
"zero_image" | ||
).map { | ||
arrayOf( | ||
File(this::class.java.getResource("/by/dev/madhead/doktor/render/DokRenderer/md/${it}.md").toURI()), | ||
objectMapper.readValue<RenderedDok>(this::class.java.getResourceAsStream("/by/dev/madhead/doktor/render/DokRenderer/md/${it}.yml")) | ||
) | ||
}.toTypedArray() | ||
} | ||
|
||
@DataProvider(name = "asciidocs") | ||
fun asciidocs(): Array<Array<*>> { | ||
return listOf( | ||
"local_image_alt", | ||
"local_image_height", | ||
"local_image_no_alt", | ||
"local_image_title", | ||
"local_image_title_specials", | ||
"local_image_width", | ||
"remote_image_alt", | ||
"remote_image_height", | ||
"remote_image_no_alt", | ||
"remote_image_title", | ||
"remote_image_title_specials", | ||
"remote_image_width", | ||
"zero_image" | ||
).map { | ||
arrayOf( | ||
File(this::class.java.getResource("/by/dev/madhead/doktor/render/DokRenderer/adoc/${it}.adoc").toURI()), | ||
objectMapper.readValue<RenderedDok>(this::class.java.getResourceAsStream("/by/dev/madhead/doktor/render/DokRenderer/adoc/${it}.yml")) | ||
) | ||
}.toTypedArray() | ||
} | ||
|
||
@Test(dataProvider = "markdowns") | ||
fun markdown(input: File, expected: RenderedDok) { | ||
test(Markup.MARKDOWN, input, expected) | ||
} | ||
|
||
@Test(dataProvider = "asciidocs") | ||
fun asciidoc(input: File, expected: RenderedDok) { | ||
test(Markup.ASCIIDOC, input, expected) | ||
} | ||
|
||
private fun test(markup: Markup, input: File, expected: RenderedDok) { | ||
val taskListener = Mockito.mock(TaskListener::class.java) | ||
val logger = Mockito.mock(PrintStream::class.java) | ||
val renderer = DokRenderer(markup, taskListener) | ||
|
||
Mockito.`when`(taskListener.logger).thenReturn(logger) | ||
|
||
val renderedDok = renderer.invoke(input, null) | ||
|
||
Assert.assertEquals(renderedDok.content, expected.content) | ||
Assert.assertEquals(renderedDok.images, expected.images) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...st/resources/by/dev/madhead/doktor/render/DokRenderer/adoc/local_image_alt.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: local_image_alt.adoc | ||
--- | ||
|
||
You can't see this image, but it exists: | ||
|
||
image::../image.png[Minimal PNG] |
22 changes: 22 additions & 0 deletions
22
src/test/resources/by/dev/madhead/doktor/render/DokRenderer/adoc/local_image_alt.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
filePath: Not checked | ||
content: | ||
markup: ASCIIDOC | ||
content: |- | ||
<div class="doktor"> | ||
<div class="paragraph"> | ||
<p>You can’t see this image, but it exists:</p> | ||
</div> | ||
<div class="imageblock"> | ||
<div class="content"> | ||
<ac:image ac:alt="Minimal PNG"> | ||
<ri:attachment ri:filename="93ca32a536da1698ea979f183679af29.png"></ri:attachment> | ||
</ac:image> | ||
</div> | ||
</div> | ||
</div> | ||
frontMatter: | ||
title: local_image_alt.adoc | ||
labels: [] | ||
images: | ||
- fileName: 93ca32a536da1698ea979f183679af29.png | ||
bytes: !!binary iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg== |
7 changes: 7 additions & 0 deletions
7
...resources/by/dev/madhead/doktor/render/DokRenderer/adoc/local_image_height.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: local_image_height.adoc | ||
--- | ||
|
||
You can't see this image, but it exists: | ||
|
||
image::../image.png[Minimal PNG, 200, 200] |
22 changes: 22 additions & 0 deletions
22
src/test/resources/by/dev/madhead/doktor/render/DokRenderer/adoc/local_image_height.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
filePath: Not checked | ||
content: | ||
markup: ASCIIDOC | ||
content: |- | ||
<div class="doktor"> | ||
<div class="paragraph"> | ||
<p>You can’t see this image, but it exists:</p> | ||
</div> | ||
<div class="imageblock"> | ||
<div class="content"> | ||
<ac:image ac:width="200" ac:height="200" ac:alt="Minimal PNG"> | ||
<ri:attachment ri:filename="93ca32a536da1698ea979f183679af29.png"></ri:attachment> | ||
</ac:image> | ||
</div> | ||
</div> | ||
</div> | ||
frontMatter: | ||
title: local_image_height.adoc | ||
labels: [] | ||
images: | ||
- fileName: 93ca32a536da1698ea979f183679af29.png | ||
bytes: !!binary iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg== |
7 changes: 7 additions & 0 deletions
7
...resources/by/dev/madhead/doktor/render/DokRenderer/adoc/local_image_no_alt.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
title: local_image_no_alt.adoc | ||
--- | ||
|
||
You can't see this image, but it exists and has no alt: | ||
|
||
image::../image.png[] |
22 changes: 22 additions & 0 deletions
22
src/test/resources/by/dev/madhead/doktor/render/DokRenderer/adoc/local_image_no_alt.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
filePath: Not checked | ||
content: | ||
markup: ASCIIDOC | ||
content: |- | ||
<div class="doktor"> | ||
<div class="paragraph"> | ||
<p>You can’t see this image, but it exists and has no alt:</p> | ||
</div> | ||
<div class="imageblock"> | ||
<div class="content"> | ||
<ac:image ac:alt="image"> | ||
<ri:attachment ri:filename="93ca32a536da1698ea979f183679af29.png"></ri:attachment> | ||
</ac:image> | ||
</div> | ||
</div> | ||
</div> | ||
frontMatter: | ||
title: local_image_no_alt.adoc | ||
labels: [] | ||
images: | ||
- fileName: 93ca32a536da1698ea979f183679af29.png | ||
bytes: !!binary iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg== |
8 changes: 8 additions & 0 deletions
8
.../resources/by/dev/madhead/doktor/render/DokRenderer/adoc/local_image_title.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
title: local_image_title.adoc | ||
--- | ||
|
||
You can't see this image, but it exists and has title: | ||
|
||
.Minimal PNG | ||
image::../image.png[Minimal PNG] |
Oops, something went wrong.