Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.jsonschema2pojo.ContentResolverTest require internet connection (… #705

Merged
merged 2 commits into from
Mar 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions jsonschema2pojo-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,10 @@ public interface Annotator {
*
* @param field
* the field that contains data that will be serialized
* @param clazz
* the owner of the field (class to which the field belongs)
* @param propertyName
* the name of the JSON property that this field represents
* @param propertyNode
* the schema node defining this property
*/
void dateField(JFieldVar field, JsonNode node);
void dateField(JFieldVar field, JsonNode propertyNode);

void additionalPropertiesField(JFieldVar field, JDefinedClass clazz, String propertyName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class MediaRule implements Rule<JType, JType> {
* Constructs a new media rule.
* </p>
*
* @param ruleFactory the rule factory that created this rule.
* @since 0.4.2
*/
protected MediaRule() {
Expand Down
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)));
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright © 2010-2014 Nokia
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,45 +16,28 @@

package org.jsonschema2pojo;

import static org.junit.Assert.*;
import com.fasterxml.jackson.databind.JsonNode;
import org.junit.Test;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;

import org.junit.Test;

import com.fasterxml.jackson.databind.JsonNode;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;

public class ContentResolverTest {

private ContentResolver resolver = new ContentResolver();
private ContentResolver resolver = new ContentResolver();

@Test(expected=IllegalArgumentException.class)
public void wrongProtocolCausesIllegalArgumentException() {

URI uriWithUnrecognisedProtocol = URI.create("foobar://schema/address.json");
resolver.resolve(uriWithUnrecognisedProtocol);
}

@Test(expected=IllegalArgumentException.class)
public void brokenLinkCausesIllegalArgumentException() {

URI brokenHttpUri = URI.create("http://json-schema.org/address123123213");
resolver.resolve(brokenHttpUri);
}

@Test
public void httpLinkIsResolvedToContent() {

URI httpUri = URI.create("http://json-schema.org/address");
JsonNode uriContent = resolver.resolve(httpUri);

assertThat(uriContent.path("description").asText().length(), is(greaterThan(0)));
}

@Test
public void fileLinkIsResolvedToContent() throws IOException {
Expand Down
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"
}
}
}
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"
}
}
}
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"
}
}
}
2 changes: 1 addition & 1 deletion jsonschema2pojo-gradle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.8.6</version>
<version>${groovy.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<groovy.version>1.8.6</groovy.version>
<gradle.version>1.6</gradle.version>
<gson.version>2.5</gson.version>
<moshi.version>1.1.0</moshi.version>
Expand Down Expand Up @@ -350,6 +351,32 @@
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.24</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>2.5.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-annotations</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
Expand Down