Package com.linkedin.data.schema.validation

Examples of com.linkedin.data.schema.validation.ValidationOptions


    }
    // Validate against the class schema with FixupMode.STRING_TO_PRIMITIVE to parse the
    // strings into the corresponding primitive types.
    ValidateDataAgainstSchema.validate(paramRecordTemplate.data(),
                                       paramRecordTemplate.schema(),
                                       new ValidationOptions(RequiredMode.CAN_BE_ABSENT_IF_HAS_DEFAULT,
                                                             CoercionMode.STRING_TO_PRIMITIVE));
    return paramRecordTemplate;
  }
View Full Code Here


    {
      data = DataMapUtils.readMap(request);
    }
    DynamicRecordTemplate template = new DynamicRecordTemplate(data, resourceMethodDescriptor.getRequestDataSchema());
    ValidationResult result =
        ValidateDataAgainstSchema.validate(data, template.schema(), new ValidationOptions(RequiredMode.IGNORE,
                                                                                          CoercionMode.NORMAL));
    if (!result.isValid())
    {
      throw new RoutingException("Parameters of method '" + resourceMethodDescriptor.getActionName()
          + "' failed validation with error '" + result.getMessages() + "'", HttpStatus.S_400_BAD_REQUEST.getCode());
View Full Code Here

      Greeting fetchedGreeting = fetchedGreetings.get(i);
      Greeting expectedGreeting = expectedGreetings.get(i);

      // Make sure the types of the fetched Greeting match the types in the schema. This happens as a side effect of the
      // validate method
      ValidateDataAgainstSchema.validate(fetchedGreeting.data(), fetchedGreeting.schema(), new ValidationOptions());

      if (fieldsToIgnore == null || fieldsToIgnore.isEmpty())
      {
        Assert.assertEquals(fetchedGreeting, expectedGreeting);
      }
View Full Code Here

      // Make sure the types of the fetched Greeting match the types in the schema. This happens as a side effect of the
      // validate method
      // This is why we can't do Assert.assertEquals(getAllReturnedGreetings, greetings) directly
      ValidateDataAgainstSchema.validate(getAllReturnedGreeting.data(),
                                         getAllReturnedGreeting.schema(),
                                         new ValidationOptions());
      Assert.assertEquals(getAllReturnedGreeting, greeting);
    }

    deleteAndVerifyBatchTestDataSerially(builders, createdIds);
  }
View Full Code Here

      {
        // translate from Avro back to Pegasus
        DataMap dataMapResult = DataTranslator.genericRecordToDataMap(avroRecord, recordDataSchema, avroSchema);
        ValidationResult vr = ValidateDataAgainstSchema.validate(dataMap,
                                                                 recordDataSchema,
                                                                 new ValidationOptions(RequiredMode.MUST_BE_PRESENT,
                                                                                       CoercionMode.NORMAL));
        DataMap fixedInputDataMap = (DataMap) vr.getFixed();
        assertTrue(vr.isValid());
        if (oneWay == false)
        {
          assertEquals(dataMapResult, fixedInputDataMap);
        }

        // serialize avroRecord to binary and back
        byte[] avroBytes = AvroUtil.bytesFromGenericRecord(avroRecord);
        GenericRecord avroRecordFromBytes = AvroUtil.genericRecordFromBytes(avroBytes, avroRecord.getSchema());
        byte[] avroBytesAgain = AvroUtil.bytesFromGenericRecord(avroRecordFromBytes);
        assertEquals(avroBytes, avroBytesAgain);

        // check result of roundtrip binary serialization
        DataMap dataMapFromBinaryResult = DataTranslator.genericRecordToDataMap(avroRecordFromBytes, recordDataSchema, avroSchema);
        vr = ValidateDataAgainstSchema.validate(dataMapFromBinaryResult,
                                                recordDataSchema,
                                                new ValidationOptions(RequiredMode.MUST_BE_PRESENT,
                                                                      CoercionMode.NORMAL));
        fixedInputDataMap = (DataMap) vr.getFixed();
        assertTrue(vr.isValid());
        if (oneWay == false)
        {
View Full Code Here

  @Test
  public void testEmpty()
  {
    final EmptyRecord record = new EmptyRecord();
    final DataSchemaAnnotationValidator validator = new DataSchemaAnnotationValidator(record.schema());
    final ValidationResult result = ValidateDataAgainstSchema.validate(record.data(), record.schema(), new ValidationOptions(), validator);
    Assert.assertTrue(result.isValid());
  }
View Full Code Here

    final EmptyRecord record = new EmptyRecord();
    record.data().put("non", "empty");
    final DataSchemaAnnotationValidator validator = new DataSchemaAnnotationValidator(record.schema());
    final ValidationResult result = ValidateDataAgainstSchema.validate(record.data(),
                                                                       record.schema(),
                                                                       new ValidationOptions(),
                                                                       validator);
    Assert.assertFalse(result.isValid());
  }
View Full Code Here

            // make sure Avro accepts it
            Schema avroSchema = Schema.parse(avroTextFromSchema);
            if (debug) System.out.println("AvroSchema: " + avroSchema);

            SchemaParser parser = new SchemaParser();
            ValidationOptions options = new ValidationOptions();
            options.setAvroUnionMode(true);
            parser.setValidationOptions(options);
            parser.parse(avroTextFromSchema);
            assertFalse(parser.hasError(), parser.errorMessage());

            if (optionalDefaultMode == DataToAvroSchemaTranslationOptions.DEFAULT_OPTIONAL_DEFAULT_MODE)
View Full Code Here

          asList(Mode.ANCESTOR_AND_SET, "", "/bar", "/bar/baz", "/bar/baz/bazInt"),
        },
      };

    DataSchema schema = dataSchemaFromString(schemaText);
    ValidationOptions options = new ValidationOptions(RequiredMode.CAN_BE_ABSENT_IF_HAS_DEFAULT, CoercionMode.NORMAL);
    for (Object[] row : inputs)
    {
      String value = (String) row[0];
      String patch = (String) row[1];
      String patchPath = (String) row[2];
View Full Code Here

        {
          DataList list = new DataList();
          list.add(arrayFieldValue);
          ValidateDataAgainstSchema.validate(list,
                                             f.getType(),
                                             new ValidationOptions(RequiredMode.CAN_BE_ABSENT_IF_HAS_DEFAULT,
                                                                   CoercionMode.STRING_TO_PRIMITIVE));
          dataMap.put(fieldName, list);
        }
      }
    }
View Full Code Here

TOP

Related Classes of com.linkedin.data.schema.validation.ValidationOptions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.