Search in sources :

Example 16 with ConfigFunction

use of com.github.victools.jsonschema.generator.ConfigFunction in project jsonschema-generator by victools.

the class JakartaValidationModuleTest method testNullableCheckOnMethod.

private void testNullableCheckOnMethod(String fieldName, Boolean expectedResult) throws Exception {
    ArgumentCaptor<ConfigFunction<MethodScope, Boolean>> captor = ArgumentCaptor.forClass(ConfigFunction.class);
    Mockito.verify(this.methodConfigPart).withNullableCheck(captor.capture());
    TestType testType = new TestType(TestClassForNullableCheck.class);
    String methodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
    MethodScope method = testType.getMemberMethod(methodName);
    Boolean result = captor.getValue().apply(method);
    Assert.assertEquals(expectedResult, result);
}
Also used : ConfigFunction(com.github.victools.jsonschema.generator.ConfigFunction) MethodScope(com.github.victools.jsonschema.generator.MethodScope)

Example 17 with ConfigFunction

use of com.github.victools.jsonschema.generator.ConfigFunction in project jsonschema-generator by victools.

the class JakartaValidationModuleTest method testNullableCheckOnField.

private void testNullableCheckOnField(String fieldName, Boolean expectedResult) throws Exception {
    ArgumentCaptor<ConfigFunction<FieldScope, Boolean>> captor = ArgumentCaptor.forClass(ConfigFunction.class);
    Mockito.verify(this.fieldConfigPart).withNullableCheck(captor.capture());
    TestType testType = new TestType(TestClassForNullableCheck.class);
    FieldScope field = testType.getMemberField(fieldName);
    Boolean result = captor.getValue().apply(field);
    Assert.assertEquals(expectedResult, result);
}
Also used : FieldScope(com.github.victools.jsonschema.generator.FieldScope) ConfigFunction(com.github.victools.jsonschema.generator.ConfigFunction)

Example 18 with ConfigFunction

use of com.github.victools.jsonschema.generator.ConfigFunction in project jsonschema-generator by victools.

the class JakartaValidationModuleTest method testStringLengthResolvers.

private void testStringLengthResolvers(String fieldName, Integer expectedMinLength, Integer expectedMaxLength) throws Exception {
    TestType testType = new TestType(TestClassForStringProperties.class);
    FieldScope field = testType.getMemberField(fieldName);
    ArgumentCaptor<ConfigFunction<FieldScope, Integer>> minLengthCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
    Mockito.verify(this.fieldConfigPart).withStringMinLengthResolver(minLengthCaptor.capture());
    Integer minLength = minLengthCaptor.getValue().apply(field);
    Assert.assertEquals(expectedMinLength, minLength);
    ArgumentCaptor<ConfigFunction<FieldScope, Integer>> maxLengthCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
    Mockito.verify(this.fieldConfigPart).withStringMaxLengthResolver(maxLengthCaptor.capture());
    Integer maxLength = maxLengthCaptor.getValue().apply(field);
    Assert.assertEquals(expectedMaxLength, maxLength);
}
Also used : BigInteger(java.math.BigInteger) FieldScope(com.github.victools.jsonschema.generator.FieldScope) ConfigFunction(com.github.victools.jsonschema.generator.ConfigFunction)

Example 19 with ConfigFunction

use of com.github.victools.jsonschema.generator.ConfigFunction in project jsonschema-generator by victools.

the class JavaxValidationModuleTest method testValidationGroupSetting.

@Test
@Parameters
@TestCaseName("{method}({0}, {1}, {2}) [{index}]")
public void testValidationGroupSetting(String testCase, String fieldName, Boolean expectedResult, Class<?>[] validationGroups) {
    JavaxValidationModule module = new JavaxValidationModule();
    if (validationGroups != null) {
        module.forValidationGroups(validationGroups);
    }
    module.applyToConfigBuilder(this.configBuilder);
    ArgumentCaptor<ConfigFunction<FieldScope, Boolean>> captor = ArgumentCaptor.forClass(ConfigFunction.class);
    Mockito.verify(this.fieldConfigPart).withNullableCheck(captor.capture());
    TestType testType = new TestType(TestClassForValidationGroups.class);
    FieldScope field = testType.getMemberField(fieldName);
    Boolean result = captor.getValue().apply(field);
    Assert.assertEquals(expectedResult, result);
}
Also used : FieldScope(com.github.victools.jsonschema.generator.FieldScope) ConfigFunction(com.github.victools.jsonschema.generator.ConfigFunction) Parameters(junitparams.Parameters) Test(org.junit.Test) TestCaseName(junitparams.naming.TestCaseName)

Example 20 with ConfigFunction

use of com.github.victools.jsonschema.generator.ConfigFunction in project jsonschema-generator by victools.

the class JavaxValidationModuleTest method testArrayItemCountResolvers.

private void testArrayItemCountResolvers(String fieldName, Integer expectedMinItems, Integer expectedMaxItems) throws Exception {
    TestType testType = new TestType(TestClassForArrayItemCount.class);
    FieldScope field = testType.getMemberField(fieldName);
    ArgumentCaptor<ConfigFunction<FieldScope, Integer>> minItemCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
    Mockito.verify(this.fieldConfigPart).withArrayMinItemsResolver(minItemCaptor.capture());
    Integer minItemCount = minItemCaptor.getValue().apply(field);
    Assert.assertEquals(expectedMinItems, minItemCount);
    ArgumentCaptor<ConfigFunction<FieldScope, Integer>> maxItemCaptor = ArgumentCaptor.forClass(ConfigFunction.class);
    Mockito.verify(this.fieldConfigPart).withArrayMaxItemsResolver(maxItemCaptor.capture());
    Integer maxItemCount = maxItemCaptor.getValue().apply(field);
    Assert.assertEquals(expectedMaxItems, maxItemCount);
}
Also used : BigInteger(java.math.BigInteger) FieldScope(com.github.victools.jsonschema.generator.FieldScope) ConfigFunction(com.github.victools.jsonschema.generator.ConfigFunction)

Aggregations

ConfigFunction (com.github.victools.jsonschema.generator.ConfigFunction)23 FieldScope (com.github.victools.jsonschema.generator.FieldScope)20 Parameters (junitparams.Parameters)11 Test (org.junit.Test)11 BigInteger (java.math.BigInteger)4 MethodScope (com.github.victools.jsonschema.generator.MethodScope)3 TypeScope (com.github.victools.jsonschema.generator.TypeScope)3 BigDecimal (java.math.BigDecimal)3 TestCaseName (junitparams.naming.TestCaseName)2 JsonClassDescription (com.fasterxml.jackson.annotation.JsonClassDescription)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 JsonPropertyDescription (com.fasterxml.jackson.annotation.JsonPropertyDescription)1 PropertyNamingStrategies (com.fasterxml.jackson.databind.PropertyNamingStrategies)1 JsonNaming (com.fasterxml.jackson.databind.annotation.JsonNaming)1 AbstractTypeAwareTest (com.github.victools.jsonschema.generator.AbstractTypeAwareTest)1 SchemaGeneratorConfigBuilder (com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder)1 SchemaGeneratorConfigPart (com.github.victools.jsonschema.generator.SchemaGeneratorConfigPart)1 SchemaGeneratorGeneralConfigPart (com.github.victools.jsonschema.generator.SchemaGeneratorGeneralConfigPart)1 TypeContext (com.github.victools.jsonschema.generator.TypeContext)1 Type (java.lang.reflect.Type)1