|
| 1 | +/** |
| 2 | + * Copyright (C) 2009-2018 Lightbend Inc. <https://www.lightbend.com> |
| 3 | + */ |
| 4 | + |
| 5 | +package com.lightbend.paradox.apidoc |
| 6 | + |
| 7 | +import com.lightbend.paradox.markdown.Writer |
| 8 | + |
| 9 | +class ApidocPluginSpec extends MarkdownBaseSpec { |
| 10 | + val rootPackage = "akka" |
| 11 | + |
| 12 | + val allClasses = Array( |
| 13 | + "akka.actor.ActorRef", |
| 14 | + "akka.actor.typed.ActorRef", |
| 15 | + "akka.cluster.client.ClusterClient", |
| 16 | + "akka.cluster.client.ClusterClient$", |
| 17 | + "akka.dispatch.Envelope", |
| 18 | + "akka.http.javadsl.model.sse.ServerSentEvent", |
| 19 | + "akka.http.javadsl.marshalling.Marshaller", |
| 20 | + "akka.http.javadsl.marshalling.Marshaller$", |
| 21 | + "akka.http.scaladsl.marshalling.Marshaller", |
| 22 | + "akka.http.scaladsl.marshalling.Marshaller$", |
| 23 | + "akka.stream.javadsl.Source", |
| 24 | + "akka.stream.javadsl.Source$", |
| 25 | + "akka.stream.scaladsl.Source", |
| 26 | + "akka.stream.scaladsl.Source$", |
| 27 | + "akka.stream.javadsl.Flow", |
| 28 | + "akka.stream.javadsl.Flow$", |
| 29 | + "akka.stream.scaladsl.Flow", |
| 30 | + "akka.stream.scaladsl.Flow$" |
| 31 | + ) |
| 32 | + |
| 33 | + override val markdownWriter = new Writer( |
| 34 | + linkRenderer = Writer.defaultLinks, |
| 35 | + verbatimSerializers = Writer.defaultVerbatims, |
| 36 | + serializerPlugins = Writer.defaultPlugins( |
| 37 | + Writer.defaultDirectives ++ Seq( |
| 38 | + (_: Writer.Context) => new ApidocDirective(allClasses) |
| 39 | + ) |
| 40 | + ) |
| 41 | + ) |
| 42 | + |
| 43 | + implicit val context = writerContextWithProperties( |
| 44 | + "scaladoc.akka.base_url" -> "https://doc.akka.io/api/akka/2.5", |
| 45 | + "scaladoc.akka.http.base_url" -> "https://doc.akka.io/api/akka-http/current", |
| 46 | + "javadoc.akka.base_url" -> "https://doc.akka.io/japi/akka/2.5", |
| 47 | + "javadoc.akka.http.base_url" -> "https://doc.akka.io/japi/akka-http/current", |
| 48 | + ) |
| 49 | + |
| 50 | + "Apidoc directive" should "generate markdown correctly when there is only one match" in { |
| 51 | + markdown("@apidoc[Envelope]") shouldEqual |
| 52 | + html( |
| 53 | + """<p><span class="group-scala"> |
| 54 | + |<a href="https://doc.akka.io/api/akka/2.5/akka/dispatch/Envelope.html">Envelope</a></span><span class="group-java"> |
| 55 | + |<a href="https://doc.akka.io/japi/akka/2.5/?akka/dispatch/Envelope.html">Envelope</a></span> |
| 56 | + |</p>""".stripMargin |
| 57 | + ) |
| 58 | + } |
| 59 | + |
| 60 | + it should "throw an exception when there is no match" in { |
| 61 | + val thrown = the[IllegalStateException] thrownBy markdown("@apidoc[ThereIsNoSuchClass]") |
| 62 | + thrown.getMessage shouldEqual |
| 63 | + "No matches found for ThereIsNoSuchClass" |
| 64 | + } |
| 65 | + |
| 66 | + |
| 67 | + it should "generate markdown correctly when 2 matches found and their package names include javadsl/scaladsl" in { |
| 68 | + markdown("@apidoc[Flow]") shouldEqual |
| 69 | + html( |
| 70 | + """<p><span class="group-java"> |
| 71 | + |<a href="https://doc.akka.io/japi/akka/2.5/?akka/stream/javadsl/Flow.html">Flow</a></span><span class="group-scala"> |
| 72 | + |<a href="https://doc.akka.io/api/akka/2.5/akka/stream/scaladsl/Flow.html">Flow</a></span> |
| 73 | + |</p>""".stripMargin |
| 74 | + ) |
| 75 | + } |
| 76 | + |
| 77 | + it should "throw an exception when two matches found but javadsl/scaladsl is not in their packages" in { |
| 78 | + val thrown = the[IllegalStateException] thrownBy markdown("@apidoc[ActorRef]") |
| 79 | + thrown.getMessage shouldEqual |
| 80 | + "2 matches found for ActorRef, but not javadsl/scaladsl: akka.actor.ActorRef, akka.actor.typed.ActorRef. You may want to use the fully qualified class name as @apidoc[fqcn] instead of @apidoc[ActorRef]." |
| 81 | + } |
| 82 | + |
| 83 | + it should "generate markdown correctly when fully qualified class name (fqcn) is specified as @apidoc[fqcn]" in { |
| 84 | + markdown("@apidoc[akka.actor.ActorRef]") shouldEqual |
| 85 | + html( |
| 86 | + """<p><span class="group-scala"> |
| 87 | + |<a href="https://doc.akka.io/api/akka/2.5/akka/actor/ActorRef.html">ActorRef</a></span><span class="group-java"> |
| 88 | + |<a href="https://doc.akka.io/japi/akka/2.5/?akka/actor/ActorRef.html">ActorRef</a></span> |
| 89 | + |</p>""".stripMargin |
| 90 | + ) |
| 91 | + } |
| 92 | + |
| 93 | + it should "throw an exception when `.` is in the [label], but the label is not fqcn" in { |
| 94 | + val thrown = the[IllegalStateException] thrownBy markdown("@apidoc[actor.typed.ActorRef]") |
| 95 | + thrown.getMessage shouldEqual |
| 96 | + "fqcn not found by @apidoc[actor.typed.ActorRef]" |
| 97 | + } |
| 98 | + |
| 99 | + it should "generate markdown correctly for a companion object" in { |
| 100 | + markdown("@apidoc[ClusterClient$]") shouldEqual |
| 101 | + html( |
| 102 | + """<p><span class="group-scala"> |
| 103 | + |<a href="https://doc.akka.io/api/akka/2.5/akka/cluster/client/ClusterClient$.html">ClusterClient</a></span><span class="group-java"> |
| 104 | + |<a href="https://doc.akka.io/japi/akka/2.5/?akka/cluster/client/ClusterClient$.html">ClusterClient</a></span> |
| 105 | + |</p>""".stripMargin |
| 106 | + ) |
| 107 | + } |
| 108 | + |
| 109 | + it should "generate markdown correctly for type parameter and wildcard" in { |
| 110 | + markdown("@apidoc[Source[ServerSentEvent, \\_]]") shouldEqual |
| 111 | + html( |
| 112 | + """<p><span class="group-java"> |
| 113 | + |<a href="https://doc.akka.io/japi/akka/2.5/?akka/stream/javadsl/Source.html">Source<ServerSentEvent, ?></a></span><span class="group-scala"> |
| 114 | + |<a href="https://doc.akka.io/api/akka/2.5/akka/stream/scaladsl/Source.html">Source[ServerSentEvent, _]</a></span> |
| 115 | + |</p>""".stripMargin |
| 116 | + ) |
| 117 | + } |
| 118 | + |
| 119 | + it should "generate markdown correctly for type parameters with concrete names" in { |
| 120 | + markdown("@apidoc[Flow[Message, Message, Mat]]") shouldEqual |
| 121 | + html( |
| 122 | + """<p><span class="group-java"> |
| 123 | + |<a href="https://doc.akka.io/japi/akka/2.5/?akka/stream/javadsl/Flow.html">Flow<Message, Message, Mat></a></span><span class="group-scala"> |
| 124 | + |<a href="https://doc.akka.io/api/akka/2.5/akka/stream/scaladsl/Flow.html">Flow[Message, Message, Mat]</a></span> |
| 125 | + |</p>""".stripMargin |
| 126 | + ) |
| 127 | + } |
| 128 | + |
| 129 | + it should "generate markdown correctly for nested type parameters" in { |
| 130 | + markdown("@apidoc[Marshaller[Try[A], B]]") shouldEqual |
| 131 | + html( |
| 132 | + """<p><span class="group-java"> |
| 133 | + |<a href="https://doc.akka.io/japi/akka-http/current/?akka/http/javadsl/marshalling/Marshaller.html">Marshaller<Try<A>, B></a></span><span class="group-scala"> |
| 134 | + |<a href="https://doc.akka.io/api/akka-http/current/akka/http/scaladsl/marshalling/Marshaller.html">Marshaller[Try[A], B]</a></span> |
| 135 | + |</p>""".stripMargin |
| 136 | + ) |
| 137 | + } |
| 138 | +} |
0 commit comments