Skip to content

Commit 55800a1

Browse files
committed
renaming httpClient members to schemaClient consistently
1 parent cc7fa5a commit 55800a1

File tree

7 files changed

+54
-45
lines changed

7 files changed

+54
-45
lines changed

core/src/main/java/org/everit/json/schema/loader/LoaderConfig.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static LoaderConfig defaultV4Config() {
1919
return new LoaderConfig(new DefaultSchemaClient(), DRAFT_4.defaultFormatValidators(), DRAFT_4, false);
2020
}
2121

22-
final SchemaClient httpClient;
22+
final SchemaClient schemaClient;
2323

2424
final Map<String, FormatValidator> formatValidators;
2525

@@ -31,15 +31,15 @@ static LoaderConfig defaultV4Config() {
3131

3232
final RegexpFactory regexpFactory;
3333

34-
LoaderConfig(SchemaClient httpClient, Map<String, FormatValidator> formatValidators,
34+
LoaderConfig(SchemaClient schemaClient, Map<String, FormatValidator> formatValidators,
3535
SpecificationVersion specVersion, boolean useDefaults) {
36-
this(httpClient, formatValidators, specVersion, useDefaults, false, new JavaUtilRegexpFactory());
36+
this(schemaClient, formatValidators, specVersion, useDefaults, false, new JavaUtilRegexpFactory());
3737
}
3838

39-
LoaderConfig(SchemaClient httpClient, Map<String, FormatValidator> formatValidators,
39+
LoaderConfig(SchemaClient schemaClient, Map<String, FormatValidator> formatValidators,
4040
SpecificationVersion specVersion, boolean useDefaults, boolean nullableSupport,
4141
RegexpFactory regexpFactory) {
42-
this.httpClient = requireNonNull(httpClient, "httpClient cannot be null");
42+
this.schemaClient = requireNonNull(schemaClient, "schemaClient cannot be null");
4343
this.formatValidators = requireNonNull(formatValidators, "formatValidators cannot be null");
4444
this.specVersion = requireNonNull(specVersion, "specVersion cannot be null");
4545
this.useDefaults = useDefaults;

core/src/main/java/org/everit/json/schema/loader/LoadingState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static URI extractChildId(URI parentScopeId, Object childJson, String idKeyword)
7272

7373
SchemaLoader.SchemaLoaderBuilder initChildLoader() {
7474
SchemaLoader.SchemaLoaderBuilder rval = SchemaLoader.builder()
75-
.httpClient(this.config.httpClient)
75+
.schemaClient(this.config.schemaClient)
7676
.formatValidators(new HashMap<>(this.config.formatValidators))
7777
.resolutionScope(id)
7878
.schemaJson(schemaJson)

core/src/main/java/org/everit/json/schema/loader/ReferenceLookup.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ static Map<String, Object> extend(Map<String, Object> additional, Map<String, Ob
4545

4646
private LoadingState ls;
4747

48-
private SchemaClient httpClient;
48+
private SchemaClient schemaClient;
4949

5050
public ReferenceLookup(LoadingState ls) {
5151
this.ls = requireNonNull(ls, "ls cannot be null");
52-
this.httpClient = ls.config.httpClient;
52+
this.schemaClient = ls.config.schemaClient;
5353
}
5454

5555
private Map<String, Object> doExtend(Map<String, Object> additional, Map<String, Object> original) {
@@ -154,7 +154,7 @@ Schema.Builder<?> lookup(String relPointerString, JsonObject ctx) {
154154
boolean isInternal = isSameDocumentRef(absPointerString);
155155
JsonPointerEvaluator pointer = isInternal
156156
? JsonPointerEvaluator.forDocument(ls.rootSchemaJson(), absPointerString)
157-
: JsonPointerEvaluator.forURL(httpClient, absPointerString, ls);
157+
: JsonPointerEvaluator.forURL(schemaClient, absPointerString, ls);
158158
ReferenceSchema.Builder refBuilder = ReferenceSchema.builder()
159159
.refValue(relPointerString);
160160
ls.pointerSchemas.put(absPointerString, refBuilder);

core/src/main/java/org/everit/json/schema/loader/SchemaLoader.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static JSONObject toOrgJSONObject(JsonObject value) {
4747
*/
4848
public static class SchemaLoaderBuilder {
4949

50-
SchemaClient httpClient = new DefaultSchemaClient();
50+
SchemaClient schemaClient = new DefaultSchemaClient();
5151

5252
Object schemaJson;
5353

@@ -148,8 +148,17 @@ public JSONObject getRootSchemaJson() {
148148
return new JSONObject((Map<String, Object>) (rootSchemaJson == null ? schemaJson : rootSchemaJson));
149149
}
150150

151+
/**
152+
* @deprecated use {@link #schemaClient(SchemaClient)} instead
153+
*/
154+
@Deprecated
151155
public SchemaLoaderBuilder httpClient(SchemaClient httpClient) {
152-
this.httpClient = httpClient;
156+
this.schemaClient = httpClient;
157+
return this;
158+
}
159+
160+
public SchemaLoaderBuilder schemaClient(SchemaClient schemaClient) {
161+
this.schemaClient = schemaClient;
153162
return this;
154163
}
155164

@@ -251,14 +260,14 @@ public static Schema load(final JSONObject schemaJson) {
251260
*
252261
* @param schemaJson
253262
* the JSON representation of the schema.
254-
* @param httpClient
263+
* @param schemaClient
255264
* the HTTP client to be used for resolving remote JSON references.
256265
* @return the created schema
257266
*/
258-
public static Schema load(final JSONObject schemaJson, final SchemaClient httpClient) {
267+
public static Schema load(final JSONObject schemaJson, final SchemaClient schemaClient) {
259268
SchemaLoader loader = builder()
260269
.schemaJson(schemaJson)
261-
.httpClient(httpClient)
270+
.schemaClient(schemaClient)
262271
.build();
263272
return loader.load().build();
264273
}
@@ -296,7 +305,7 @@ public SchemaLoader(SchemaLoaderBuilder builder) {
296305
} else {
297306
specVersion = builder.specVersion;
298307
}
299-
this.config = new LoaderConfig(builder.httpClient,
308+
this.config = new LoaderConfig(builder.schemaClient,
300309
builder.formatValidators,
301310
specVersion,
302311
builder.useDefaults,

core/src/test/java/org/everit/json/schema/loader/JsonPointerEvaluatorTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public void escaping() {
6363
assertEquals("tiled", actual.require("description").requireString());
6464
}
6565

66-
private LoadingState createLoadingState(SchemaClient httpClient, String ref) {
67-
LoaderConfig config = new LoaderConfig(httpClient, emptyMap(), SpecificationVersion.DRAFT_4, false);
66+
private LoadingState createLoadingState(SchemaClient schemaClient, String ref) {
67+
LoaderConfig config = new LoaderConfig(schemaClient, emptyMap(), SpecificationVersion.DRAFT_4, false);
6868
URI parentScopeId = null;
6969
Object rootSchemaJson = this.rootSchemaJson;
7070
HashMap<String, Object> schemaJson = new HashMap<>();
@@ -74,10 +74,10 @@ private LoadingState createLoadingState(SchemaClient httpClient, String ref) {
7474

7575
@Test
7676
public void remoteDocumentSuccess() {
77-
SchemaClient httpClient = mock(SchemaClient.class);
78-
when(httpClient.get("http://localhost:1234/hello")).thenReturn(rootSchemaJsonAsStream());
77+
SchemaClient schemaClient = mock(SchemaClient.class);
78+
when(schemaClient.get("http://localhost:1234/hello")).thenReturn(rootSchemaJsonAsStream());
7979
JsonPointerEvaluator pointer = JsonPointerEvaluator
80-
.forURL(httpClient, "http://localhost:1234/hello#/definitions/Bar", createLoadingState(httpClient, "#/definitions/Foo"));
80+
.forURL(schemaClient, "http://localhost:1234/hello#/definitions/Bar", createLoadingState(schemaClient, "#/definitions/Foo"));
8181
JsonObject actual = pointer.query().getQueryResult().requireObject();
8282
assertEquals("dummy schema at #/definitions/Bar", actual.require("description").requireString());
8383
assertEquals("http://localhost:1234/folder/", actual.ls.id.toString());

core/src/test/java/org/everit/json/schema/loader/ReferenceLookupTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public class ReferenceLookupTest {
2424

2525
private static final String v4Subschema = ResourceLoader.DEFAULT.readObj("v4-referred-subschema.json").toString();
2626

27-
private SchemaClient httpClient;
27+
private SchemaClient schemaClient;
2828

2929
@Before
3030
public void before() {
31-
httpClient = mock(SchemaClient.class);
31+
schemaClient = mock(SchemaClient.class);
3232
}
3333

3434
private Schema performLookup(String pointerToRef) {
@@ -46,7 +46,7 @@ private ReferenceSchema obtainReferenceSchema(String pointerToRef) {
4646

4747
@Test
4848
public void referenceSchemaLocationIsSet() {
49-
when(httpClient.get("http://localhost/child-ref")).thenReturn(asStream(v4Subschema));
49+
when(schemaClient.get("http://localhost/child-ref")).thenReturn(asStream(v4Subschema));
5050
ReferenceSchema ref = obtainReferenceSchema("#/properties/definitionInRemote");
5151
assertEquals("http://localhost/child-ref#/definitions/SubSchema", ref.getSchemaLocation());
5252
}
@@ -58,7 +58,7 @@ public void sameDocumentLookup() {
5858
}
5959

6060
private JsonValue query(String pointer) {
61-
LoadingState rootLs = new LoadingState(new LoaderConfig(httpClient, emptyMap(), SpecificationVersion.DRAFT_6, false),
61+
LoadingState rootLs = new LoadingState(new LoaderConfig(schemaClient, emptyMap(), SpecificationVersion.DRAFT_6, false),
6262
new HashMap<>(),
6363
rootSchemaJson,
6464
rootSchemaJson,
@@ -76,21 +76,21 @@ public void sameDocumentLookupById() {
7676

7777
@Test
7878
public void absoluteRef() {
79-
when(httpClient.get("http://localhost/schema.json")).thenReturn(asStream("{\"description\":\"ok\"}"));
79+
when(schemaClient.get("http://localhost/schema.json")).thenReturn(asStream("{\"description\":\"ok\"}"));
8080
Schema actual = performLookup("#/properties/absoluteRef");
8181
assertEquals("ok", actual.getDescription());
8282
}
8383

8484
@Test
8585
public void withParentScope() {
86-
when(httpClient.get("http://localhost/child-ref")).thenReturn(asStream("{\"description\":\"ok\"}"));
86+
when(schemaClient.get("http://localhost/child-ref")).thenReturn(asStream("{\"description\":\"ok\"}"));
8787
Schema actual = performLookup("#/properties/parent/child");
8888
assertEquals("ok", actual.getDescription());
8989
}
9090

9191
@Test
9292
public void schemaVersionChange() {
93-
when(httpClient.get("http://localhost/child-ref")).thenReturn(asStream(v4Subschema));
93+
when(schemaClient.get("http://localhost/child-ref")).thenReturn(asStream(v4Subschema));
9494
NumberSchema actual = (NumberSchema) performLookup("#/properties/definitionInRemote");
9595
assertTrue(actual.isExclusiveMinimum());
9696
}

core/src/test/java/org/everit/json/schema/loader/SchemaLoaderTest.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void builderhasDefaultFormatValidators() {
9090
public void builderUsesDefaultSchemaClient() {
9191
SchemaLoaderBuilder actual = SchemaLoader.builder();
9292
assertNotNull(actual);
93-
assertTrue(actual.httpClient instanceof DefaultSchemaClient);
93+
assertTrue(actual.schemaClient instanceof DefaultSchemaClient);
9494
}
9595

9696
@Test
@@ -338,12 +338,12 @@ public void refWithType() {
338338

339339
@Test
340340
public void remotePointerResulion() {
341-
SchemaClient httpClient = mock(SchemaClient.class);
342-
when(httpClient.get("http://example.org/asd")).thenReturn(asStream("{}"));
343-
when(httpClient.get("http://example.org/otherschema.json")).thenReturn(asStream("{}"));
344-
when(httpClient.get("http://example.org/folder/subschemaInFolder.json")).thenReturn(
341+
SchemaClient schemaClient = mock(SchemaClient.class);
342+
when(schemaClient.get("http://example.org/asd")).thenReturn(asStream("{}"));
343+
when(schemaClient.get("http://example.org/otherschema.json")).thenReturn(asStream("{}"));
344+
when(schemaClient.get("http://example.org/folder/subschemaInFolder.json")).thenReturn(
345345
asStream("{}"));
346-
SchemaLoader.load(get("remotePointerResolution"), httpClient);
346+
SchemaLoader.load(get("remotePointerResolution"), schemaClient);
347347
}
348348

349349
@Test
@@ -439,7 +439,7 @@ public void schemaJsonIdIsRecognized() {
439439
ByteArrayInputStream retval = new ByteArrayInputStream("{}".getBytes());
440440
when(client.get("http://example.org/schema/schema.json")).thenReturn(retval);
441441
SchemaLoader.builder().schemaJson(get("schemaWithId"))
442-
.httpClient(client)
442+
.schemaClient(client)
443443
.build().load();
444444
}
445445

@@ -450,7 +450,7 @@ public void v6SchemaJsonIdIsRecognized() {
450450
when(client.get("http://example.org/schema/schema.json")).thenReturn(retval);
451451
v6Loader()
452452
.schemaJson(get("schemaWithIdV6"))
453-
.httpClient(client)
453+
.schemaClient(client)
454454
.build().load();
455455
}
456456

@@ -509,7 +509,7 @@ public void folderNameResolution() {
509509
SchemaClient client = mock(SchemaClient.class);
510510
when(client.get("http://localhost/folder/Identifier.json")).thenReturn(asStream("{}"));
511511
v6Loader().schemaJson(get("folderNameResolution"))
512-
.httpClient(client).build().load().build();
512+
.schemaClient(client).build().load().build();
513513

514514
}
515515

@@ -520,32 +520,32 @@ public void otherFolderNameResolution() {
520520

521521
@Test
522522
public void refRemoteV4() {
523-
SchemaClient httpClient = mock(SchemaClient.class);
524-
when(httpClient.get("http://localhost:1234/folder/folderInteger.json")).thenReturn(asStream("{}"));
523+
SchemaClient schemaClient = mock(SchemaClient.class);
524+
when(schemaClient.get("http://localhost:1234/folder/folderInteger.json")).thenReturn(asStream("{}"));
525525

526-
SchemaLoader.builder().httpClient(httpClient)
526+
SchemaLoader.builder().schemaClient(schemaClient)
527527
.schemaJson(get("refRemoteV4"))
528528
.build()
529529
.load().build();
530530
}
531531

532532
@Test
533533
public void refPointerDerivatedFromPointer() {
534-
SchemaClient httpClient = mock(SchemaClient.class);
535-
when(httpClient.get("http://localhost:1234/folder/folderInteger.json")).thenReturn(asStream("{}"));
534+
SchemaClient schemaClient = mock(SchemaClient.class);
535+
when(schemaClient.get("http://localhost:1234/folder/folderInteger.json")).thenReturn(asStream("{}"));
536536

537-
SchemaLoader.builder().httpClient(httpClient)
537+
SchemaLoader.builder().schemaClient(schemaClient)
538538
.schemaJson(get("refPointerDerivatedFromPointer"))
539539
.build()
540540
.load().build();
541541
}
542542

543543
@Test
544544
public void relativeIdInReferencedSchemaRoot() {
545-
SchemaClient httpClient = mock(SchemaClient.class);
546-
when(httpClient.get("http://localhost:1234/folder/folderInteger.json")).thenReturn(asStream("{}"));
545+
SchemaClient schemaClient = mock(SchemaClient.class);
546+
when(schemaClient.get("http://localhost:1234/folder/folderInteger.json")).thenReturn(asStream("{}"));
547547

548-
SchemaLoader.builder().httpClient(httpClient)
548+
SchemaLoader.builder().schemaClient(schemaClient)
549549
.schemaJson(get("relativeIdInReferencedSchemaRoot"))
550550
.build()
551551
.load().build();

0 commit comments

Comments
 (0)