ArraySchema extends Schema { public static Builder builder() { return new Builder(); } ArraySchema(final Builder builder); static Builder builder(); Schema getAllItemSchema(); List<Schema> getItemSchemas(); Integer getMaxItems(); Integer getMinItems(); Schema getSchemaOfAdditionalItems(); Schema getContainedItemSchema(); boolean needsUniqueItems(); boolean permitsAdditionalItems(); boolean requiresArray(); @Override boolean equals(final Object o); @Override int hashCode();  }
@Test public void noAdditionalItems() { ArraySchema subject = ArraySchema.builder() .additionalItems(false) .addItemSchema(BooleanSchema.INSTANCE) .addItemSchema(NullSchema.INSTANCE) .build(); TestSupport.expectFailure(subject, "#", ARRAYS.get("twoItemTupleWithAdditional")); }
@Test public void noItemSchema() { ArraySchema.builder().build().validate(ARRAYS.get("noItemSchema")); }
@Test public void nonUniqueArrayOfArrays() { ArraySchema subject = buildWithLocation(ArraySchema.builder().uniqueItems(true)); TestSupport.failureOf(subject) .expectedPointer("#") .expectedKeyword("uniqueItems") .input(ARRAYS.get("nonUniqueArrayOfArrays")) .expect(); }
@Test(expected = SchemaException.class) public void tupleAndListFailure() { ArraySchema.builder().addItemSchema(BooleanSchema.INSTANCE).allItemSchema(NullSchema.INSTANCE) .build(); }
@Test public void tupleWithOneItem() { BooleanSchema boolSchema = buildWithLocation(BooleanSchema.builder()); ArraySchema subject = buildWithLocation(ArraySchema.builder().addItemSchema(boolSchema)); TestSupport.failureOf(subject) .expectedViolatedSchema(boolSchema) .expectedPointer("#/0") .input(ARRAYS.get("tupleWithOneItem")) .expect(); }
@Test public void subjectHasLessElemsThanTupleEntries() { ArraySchema subject = buildWithLocation(ArraySchema.builder() .addItemSchema(NullSchema.INSTANCE) .addItemSchema(TrueSchema.INSTANCE)); subject.validate(ARRAYS.get("subjectHasLessElemsThanTupleEntries")); }
@Test public void typeFailure() { TestSupport.failureOf(ArraySchema.builder()) .expectedKeyword("type") .input(true) .expect(); }
@Test public void uniqueItemsObjectViolation() { ArraySchema subject = ArraySchema.builder().uniqueItems(true).build(); TestSupport.expectFailure(subject, "#", ARRAYS.get("nonUniqueObjects")); }
@Test public void uniqueItemsViolation() { ArraySchema subject = ArraySchema.builder().uniqueItems(true).build(); TestSupport.expectFailure(subject, "#", ARRAYS.get("nonUniqueItems")); }
@Test public void uniqueItemsWithSameToString() { ArraySchema.builder().uniqueItems(true).build() .validate(ARRAYS.get("uniqueItemsWithSameToString")); }
@Test public void uniqueObjectValues() { ArraySchema.builder().uniqueItems(true).build() .validate(ARRAYS.get("uniqueObjectValues")); }
@Test public void toStringContains() { JSONObject rawSchemaJson = loader.readObj("tostring/arrayschema-contains.json"); String actual = SchemaLoader.builder() .draftV6Support() .schemaJson(rawSchemaJson) .build() .load() .build() .toString(); assertThat(new JSONObject(actual), sameJsonAs(rawSchemaJson)); }
@Test public void containedItemSchemaFailure() { TestSupport.failureOf(ArraySchema.builder() .containsItemSchema(NullSchema.INSTANCE)) .expectedKeyword("contains") .expectedMessageFragment("expected at least one array item to match 'contains' schema") .input(ARRAYS.get("onlyOneItem")) .expect(); }
@Test public void containedItemSchemaEmptyArr() { TestSupport.failureOf(ArraySchema.builder() .containsItemSchema(NullSchema.INSTANCE)) .expectedKeyword("contains") .expectedMessageFragment("expected at least one array item to match 'contains' schema") .input(ARRAYS.get("emptyArray")) .expect(); }
@Test public void additionalItemsSchema() { ArraySchema.builder() .addItemSchema(BooleanSchema.INSTANCE) .schemaOfAdditionalItems(NullSchema.INSTANCE) .build().validate(ARRAYS.get("additionalItemsSchema")); }
@Test public void ignoreAdditionalItemsIfNoItemsSchema() { ArraySchema.builder() .schemaOfAdditionalItems(FalseSchema.INSTANCE) .build().validate(ARRAYS.get("noItemSchema")); }
@Test public void additionalItemsSchemaFailure() { NullSchema nullSchema = buildWithLocation(NullSchema.builder()); ArraySchema subject = buildWithLocation( ArraySchema.builder() .addItemSchema(buildWithLocation(BooleanSchema.builder())) .schemaOfAdditionalItems(nullSchema) ); TestSupport.failureOf(subject) .expectedViolatedSchema(nullSchema) .expectedPointer("#/2") .input(ARRAYS.get("additionalItemsSchemaFailure")) .expect(); }
@Test public void booleanItems() { ArraySchema subject = ArraySchema.builder().allItemSchema(BooleanSchema.INSTANCE).build(); TestSupport.expectFailure(subject, BooleanSchema.INSTANCE, "#/2", ARRAYS.get("boolArrFailure")); }
@Test public void maxItems() { ArraySchema subject = buildWithLocation(ArraySchema.builder().maxItems(0)); TestSupport.failureOf(subject) .subject(subject) .expectedPointer("#") .expectedKeyword("maxItems") .expectedMessageFragment("expected maximum item count: 0, found: 1") .input(ARRAYS.get("onlyOneItem")) .expect(); }
@Test public void minItems() { ArraySchema subject = buildWithLocation(ArraySchema.builder().minItems(2)); TestSupport.failureOf(subject) .expectedPointer("#") .expectedKeyword("minItems") .input(ARRAYS.get("onlyOneItem")) .expect(); }