Skip to content

Commit

Permalink
feat: update test cases to use WireMock with Testcontainers and Custo…
Browse files Browse the repository at this point in the history
…mHostNameResolver

- Updated all URLs in test cases to use WireMock with Testcontainers.
- Integrated CustomHostNameResolver to ensure tests run without internet.
- Updated `mappings.json` with mappings for all test URLs.
  • Loading branch information
RehanChalana committed Oct 11, 2024
1 parent f594f50 commit 8fd4076
Show file tree
Hide file tree
Showing 2 changed files with 283 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class BrokenHttpLinksCheckerSpec extends Specification {
def "one syntactically correct http URL is ok"() {
given: "an HTML page with a single correct anchor/link"
String HTML = """$HtmlConst.HTML_HEAD
<a href="http://${CustomHostNameResolver.WIREMOCK_HOST}:$port/google">google</a>
<a href="http://google.com:$port">google</a>
$HtmlConst.HTML_END """

htmlPage = new HtmlPage(HTML)
Expand Down Expand Up @@ -147,17 +147,17 @@ class BrokenHttpLinksCheckerSpec extends Specification {
collector.nrOfProblems() == 0

where:
goodUrl << ["https://junit.org/junit4/javadoc/latest/org/junit/Before.html",
"https://plumelib.org/plume-util/api/org/plumelib/util/DeterministicObject.html",
"https://people.csail.mit.edu/cpacheco/publications/randoop-case-study-abstract.html"
goodUrl << ["http://junit.org:$port/junit4",
"http://plumelib.org:$port/plume-util",
"http://people.csail.mit.edu:$port/cpacheco"
]
}


def "single bad link is identified as problem"() {

given: "an HTML page with a single (bad) link"
String badhref = "https://arc42.org/ui98jfuhenu87djch"
String badhref = "http://arc42.org:$port/ui98jfuhenu87djch"
String HTML = """$HtmlConst.HTML_HEAD
<a href=${badhref}>nonexisting arc42 link</a>
$HtmlConst.HTML_END """
Expand All @@ -180,7 +180,7 @@ class BrokenHttpLinksCheckerSpec extends Specification {
//@Ignore("test currently breaks. see issue-219")
def "amazon does not deliver 405 statuscode for links that really exist"() {
given: "an HTML page with a single (good) amazon link"
String goodAmazonLink = "https://www.amazon.com/dp/B01A2QL9SS"
String goodAmazonLink = "http://www.amazon.com:$port/dp/B01A2QL9SS"
String HTML = """$HtmlConst.HTML_HEAD
<a href=${goodAmazonLink}>Amazon</a>
$HtmlConst.HTML_END """
Expand Down Expand Up @@ -223,7 +223,7 @@ class BrokenHttpLinksCheckerSpec extends Specification {
def 'bad link #badLink is recognized as such'() {

given: "an HTML page with a single (broken) link"
String goodURL = "https://mock.codes/${badLink}"
String goodURL = "http://mock.codes$port/${badLink}"
String HTML = """$HtmlConst.HTML_HEAD
<a href=${goodURL}>${badLink}</a>
$HtmlConst.HTML_END """
Expand Down
278 changes: 276 additions & 2 deletions htmlSanityCheck-core/src/test/resources/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,289 @@
"mappings" : [
{
"request": {
"method": "HEAD",
"urlPattern": "/google"
"method": "GET_OR_HEAD",
"urlPattern": "/(|junit4|plume-util|cpacheco)"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET",
"urlPattern": "/dp/B01A2QL9SS"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "HEAD",
"urlPattern": "/dp/B01A2QL9SS"
},
"response": {
"status": 405,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/ui98jfuhenu87djch"
},
"response": {
"status": 400,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/400"
},
"response": {
"status": 400,
"headers": {
"Content-Type": "text/plain"
}
}
},{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "401"
},
"response": {
"status": 401,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/401"
},
"response": {
"status": 401,
"headers": {
"Content-Type": "text/plain"
}
}
},{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/402"
},
"response": {
"status": 402,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/403"
},
"response": {
"status": 403,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/404"
},
"response": {
"status": 404,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/405"
},
"response": {
"status": 405,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/406"
},
"response": {
"status": 406,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/408"
},
"response": {
"status": 408,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/409"
},
"response": {
"status": 409,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/410"
},
"response": {
"status": 410,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/429"
},
"response": {
"status": 429,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/431"
},
"response": {
"status": 431,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/500"
},
"response": {
"status": 500,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/501"
},
"response": {
"status": 501,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/502"
},
"response": {
"status": 502,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/504"
},
"response": {
"status": 504,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/505"
},
"response": {
"status": 505,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/506"
},
"response": {
"status": 506,
"headers": {
"Content-Type": "text/plain"
}
}
},
{
"request": {
"method": "GET_OR_HEAD",
"urlPattern": "/507"
},
"response": {
"status": 507,
"headers": {
"Content-Type": "text/plain"
}
}
}
]
}

0 comments on commit 8fd4076

Please sign in to comment.