-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow ContentResolverTest to run without an internet connection (#705)
- Loading branch information
1 parent
9f1688e
commit 1ccc211
Showing
10 changed files
with
163 additions
and
29 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
76 changes: 76 additions & 0 deletions
76
jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/ContentResolverNetworkTest.java
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,76 @@ | ||
/* | ||
* Copyright © 2010-2014 Nokia | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jsonschema2pojo; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.github.tomakehurst.wiremock.junit.WireMockRule; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import java.net.URI; | ||
|
||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; | ||
import static org.hamcrest.Matchers.greaterThan; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThat; | ||
/** | ||
* @author {@link "https://github.com/s13o" "s13o"} | ||
* @since 3/17/2017 | ||
*/ | ||
public class ContentResolverNetworkTest { | ||
|
||
private static final String ADDRESS = "localhost"; | ||
|
||
@Rule | ||
public WireMockRule server = new WireMockRule( | ||
options().dynamicPort().bindAddress(ADDRESS).usingFilesUnderClasspath("wiremock") | ||
); | ||
|
||
@Before | ||
public void before() throws Exception { | ||
server.start(); | ||
} | ||
|
||
@After | ||
public void after() throws Exception { | ||
server.stop(); | ||
} | ||
|
||
private ContentResolver resolver = new ContentResolver(); | ||
|
||
@Test(expected=IllegalArgumentException.class) | ||
public void brokenLinkCausesIllegalArgumentException() { | ||
URI brokenHttpUri = URI.create("http://" + ADDRESS + ":" + server.port() + "/address404.json"); | ||
resolver.resolve(brokenHttpUri); | ||
} | ||
|
||
@Test(expected=IllegalArgumentException.class) | ||
public void serverErrorCausesIllegalArgumentException() { | ||
URI brokenHttpUri = URI.create("http://" + ADDRESS + ":" + server.port() + "/address500.json"); | ||
resolver.resolve(brokenHttpUri); | ||
} | ||
|
||
@Test | ||
public void httpLinkIsResolvedToContent() { | ||
URI httpUri = URI.create("http://" + ADDRESS + ":" + server.port() + "/address.json"); | ||
JsonNode uriContent = resolver.resolve(httpUri); | ||
assertThat(uriContent.path("description").asText().length(), is(greaterThan(0))); | ||
} | ||
|
||
} |
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
13 changes: 13 additions & 0 deletions
13
jsonschema2pojo-core/src/test/resources/wiremock/mappings/address.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,13 @@ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"url": "/address.json" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"body": "{\n\"description\" : \"An Address following the convention of http://microformats.org/wiki/hcard\",\n\"type\" : \"object\",\n\"properties\" : {\n\"post-office-box\" : { \"type\" : \"string\" },\n\"extended-address\" : { \"type\" : \"string\" },\n\"street-address\" : { \"type\":\"string\" },\n\"locality\" : { \"type\" : \"string\", \"required\" : true },\n\"region\" : { \"type\" : \"string\", \"required\" : true },\n\"postal-code\" : { \"type\" : \"string\" },\n\"country-name\" : { \"type\" : \"string\", \"required\" : true }\n},\n\"dependencies\" : {\n\"post-office-box\" : \"street-address\",\n\"extended-address\" : \"street-address\",\n\"street-address\" : \"region\",\n\"locality\" : \"region\",\n\"region\" : \"country-name\"}\n}", | ||
"headers": { | ||
"Content-Type": "application/json" | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
jsonschema2pojo-core/src/test/resources/wiremock/mappings/address404.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,13 @@ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"url": "/address404.json" | ||
}, | ||
"response": { | ||
"status": 404, | ||
"body": "File not found", | ||
"headers": { | ||
"Content-Type": "plain/test" | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
jsonschema2pojo-core/src/test/resources/wiremock/mappings/address500.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,13 @@ | ||
{ | ||
"request": { | ||
"method": "GET", | ||
"url": "/address500.json" | ||
}, | ||
"response": { | ||
"status": 500, | ||
"body": "Server error", | ||
"headers": { | ||
"Content-Type": "plain/test" | ||
} | ||
} | ||
} |
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