-
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.
- Loading branch information
1 parent
4500d96
commit b9dc982
Showing
12 changed files
with
187 additions
and
43 deletions.
There are no files selected for viewing
17 changes: 9 additions & 8 deletions
17
blueprint/src/main/scala/com/nike/redwiggler/blueprint/BlueprintPathParser.scala
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,18 +1,19 @@ | ||
package com.nike.redwiggler.blueprint | ||
|
||
import com.nike.redwiggler.core.models.{LiteralPathComponent, Path, PathComponent} | ||
import com.nike.redwiggler.core.models.{LiteralPathComponent, Path, PathComponent, PlaceHolderPathComponent} | ||
|
||
object BlueprintPathParser { | ||
|
||
def apply(path : String) : Path = { | ||
val seq = Path(path).components.reverse | ||
Path(seq.tail.reverse) / cleanupLast(seq.headOption) | ||
if (path.contains("{?")) { | ||
apply(path.substring(0, path.indexOf("{?"))) | ||
} else { | ||
Path(Path(path).components.map(parseComponent)) | ||
} | ||
} | ||
|
||
def cleanupLast(component : Option[PathComponent]) : Path = component match { | ||
case Some(LiteralPathComponent(path)) if path.contains("{?") => Path(Seq(LiteralPathComponent(path.substring(0, path.indexOf("{?"))))) | ||
case Some(LiteralPathComponent(path)) => Path(Seq(LiteralPathComponent(path))) | ||
case None => Path() | ||
case Some(c) => Path(Seq(c)) | ||
private def parseComponent(component : PathComponent) : PathComponent = component match { | ||
case LiteralPathComponent(c) if c.startsWith(":") => PlaceHolderPathComponent(c.substring(1)) | ||
case _ => component | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
src/test/resources/com/nike/redwiggler/integrationtests/blueprint/basic/API.md
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,48 @@ | ||
FORMAT: 1A | ||
|
||
# My Api Api | ||
|
||
## Overview | ||
**MyAPI** is a sample. | ||
|
||
|
||
### GetItem [GET /my/resource/v2/:id] | ||
|
||
+ Response 200 (application/json; charset=UTF-8) | ||
|
||
+ Schema | ||
|
||
{ | ||
"$schema":"http://json-schema.org/draft-04/schema#", | ||
"type":"object", | ||
"properties":{ | ||
"name":{ | ||
"type":"string", | ||
}, | ||
"id":{ | ||
"type":"string", | ||
"pattern": "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$" | ||
}, | ||
} | ||
} | ||
|
||
### CreateItem [POST /my/resource/v2] | ||
|
||
+ Request | ||
|
||
+ Schema | ||
|
||
{ | ||
"$schema":"http://json-schema.org/draft-04/schema#", | ||
"type":"object", | ||
"properties":{ | ||
"name":{ | ||
"type":"string", | ||
}, | ||
"id":{ | ||
"type":"string", | ||
}, | ||
} | ||
} | ||
|
||
+ Response 201 (application/json; charset=UTF-8) |
20 changes: 20 additions & 0 deletions
20
src/test/resources/com/nike/redwiggler/integrationtests/blueprint/basic/expected.json
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,20 @@ | ||
[ | ||
{ | ||
"verb": "POST", | ||
"path": "/my/resource/v2", | ||
"passed": 0, | ||
"total": 1 | ||
}, | ||
{ | ||
"verb": "GET", | ||
"path": "/foobar", | ||
"passed": 0, | ||
"total": 1 | ||
}, | ||
{ | ||
"verb": "GET", | ||
"path": "/my/resource/v2/{id}", | ||
"passed": 1, | ||
"total": 2 | ||
} | ||
] |
7 changes: 7 additions & 0 deletions
7
...ces/com/nike/redwiggler/integrationtests/blueprint/basic/requests.invalidGetResponse.json
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 @@ | ||
{ | ||
"verb": "GET", | ||
"path": "/my/resource/v2/25", | ||
"responseHeaders": [], | ||
"responseBody": "{\"id\": \"25\", \"name\": \"foo\"}", | ||
"code": 200 | ||
} |
6 changes: 6 additions & 0 deletions
6
...st/resources/com/nike/redwiggler/integrationtests/blueprint/basic/requests.unMatched.json
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,6 @@ | ||
{ | ||
"verb": "GET", | ||
"path": "/foobar", | ||
"responseHeaders": [], | ||
"code": 200 | ||
} |
7 changes: 7 additions & 0 deletions
7
...est/resources/com/nike/redwiggler/integrationtests/blueprint/basic/requests.validGet.json
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 @@ | ||
{ | ||
"verb": "GET", | ||
"path": "/my/resource/v2/53b78f35-2fbb-4207-9777-1b9aa1a05327", | ||
"responseHeaders": [], | ||
"responseBody": "{\"id\": \"53b78f35-2fbb-4207-9777-1b9aa1a05327\", \"name\": \"foo\"}", | ||
"code": 200 | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/scala/com/nike/redwiggler/integrationtests/BlueprintSpec.scala
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,11 @@ | ||
package com.nike.redwiggler.integrationtests | ||
import java.io.File | ||
|
||
import com.nike.redwiggler.blueprint.BlueprintSpecificationProvider | ||
import com.nike.redwiggler.blueprint.parser.ProtagonistBlueprintParser | ||
import com.nike.redwiggler.core.EndpointSpecificationProvider | ||
|
||
class BlueprintSpec extends End2EndSpecBase("blueprint") { | ||
override def specificationProvider(testDir: File): EndpointSpecificationProvider = | ||
BlueprintSpecificationProvider(new File(testDir, "API.md"), ProtagonistBlueprintParser()) | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/scala/com/nike/redwiggler/integrationtests/End2EndSpecBase.scala
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,46 @@ | ||
package com.nike.redwiggler.integrationtests | ||
|
||
|
||
import java.util | ||
|
||
import com.nike.redwiggler.core._ | ||
import com.nike.redwiggler.core.models.RedwigglerReport | ||
import com.nike.redwiggler.html.HtmlReportProcessor | ||
import org.scalatest.{FunSpec, Matchers} | ||
import spray.json.{DefaultJsonProtocol, JsonParser} | ||
|
||
import scala.io.Source | ||
|
||
abstract class End2EndSpecBase(name : String) extends FunSpec with Matchers with DefaultJsonProtocol { | ||
|
||
import java.io._ | ||
|
||
private val testDirs = new File(getClass.getResource(name).getFile).listFiles() | ||
|
||
def specificationProvider(testDir: File): EndpointSpecificationProvider | ||
|
||
for { | ||
testDir <- testDirs | ||
} { | ||
it(s"should process ${testDir.getName}") { | ||
Redwiggler( | ||
callProvider = new GlobEndpointCallProvider(testDir, "requests.*.json"), | ||
specificationProvider = specificationProvider(testDir), | ||
reportProcessor = new ReportProcessor { | ||
val file = File.createTempFile("redwiggler", ".json") | ||
val writer = JsonReportProcessor(file) | ||
|
||
override def process(reports: util.List[RedwigglerReport]): Unit = { | ||
writer.process(reports) | ||
|
||
val expected = JsonParser(Source.fromFile(new File(testDir, "expected.json")).mkString).convertTo[Seq[RedwigglerReportDetails]] | ||
val actual = JsonParser(Source.fromFile(file).mkString).convertTo[Seq[RedwigglerReportDetails]] | ||
|
||
expected should contain theSameElementsAs actual | ||
} | ||
}.andThen(HtmlReportProcessor(new File("/tmp/" + testDir.getName + ".html"))) | ||
) | ||
} | ||
} | ||
|
||
} |
38 changes: 4 additions & 34 deletions
38
src/test/scala/com/nike/redwiggler/integrationtests/SwaggerSpec.scala
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,42 +1,12 @@ | ||
package com.nike.redwiggler.integrationtests | ||
|
||
import java.util | ||
import java.io.File | ||
|
||
import collection.JavaConverters._ | ||
import com.nike.redwiggler.core.models.RedwigglerReport | ||
import com.nike.redwiggler.core._ | ||
import com.nike.redwiggler.html.HtmlReportProcessor | ||
import com.nike.redwiggler.swagger.SwaggerEndpointSpecificationProvider | ||
import org.scalatest.{FunSpec, Matchers} | ||
import spray.json.{DefaultJsonProtocol, JsonParser} | ||
|
||
import scala.io.Source | ||
class SwaggerSpec extends End2EndSpecBase("swagger") { | ||
|
||
class SwaggerSpec extends FunSpec with Matchers with DefaultJsonProtocol { | ||
|
||
import java.io._ | ||
private val testDirs = new File(getClass.getResource("swagger").getFile).listFiles() | ||
|
||
for { | ||
testDir <- testDirs | ||
} { | ||
it(s"should process ${testDir.getName}") { | ||
Redwiggler( | ||
callProvider = new GlobEndpointCallProvider(testDir, "requests.*.json"), | ||
specificationProvider = SwaggerEndpointSpecificationProvider(new File(testDir, "swagger.yaml")), | ||
reportProcessor = new ReportProcessor { | ||
val file = File.createTempFile("redwiggler", ".json") | ||
val writer = JsonReportProcessor(file) | ||
override def process(reports: util.List[RedwigglerReport]): Unit = { | ||
writer.process(reports) | ||
|
||
val expected = JsonParser(Source.fromFile(new File(testDir, "expected.json")).mkString).convertTo[Seq[RedwigglerReportDetails]] | ||
val actual = JsonParser(Source.fromFile(file).mkString).convertTo[Seq[RedwigglerReportDetails]] | ||
|
||
expected should contain theSameElementsAs actual | ||
} | ||
}.andThen(HtmlReportProcessor(new File("/tmp/" + testDir.getName + ".html" ))) | ||
) | ||
} | ||
} | ||
override def specificationProvider(testDir: File): EndpointSpecificationProvider = | ||
SwaggerEndpointSpecificationProvider(new File(testDir, "swagger.yaml")) | ||
} |