Search in sources :

Example 6 with MethodScope

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

the class JavaxValidationModuleTest 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 7 with MethodScope

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

the class SchemaGenerationContextImplTest method testCreateStandardDefinitionReferenceForMethod_withCustomPropertyDefinition.

@Test
public void testCreateStandardDefinitionReferenceForMethod_withCustomPropertyDefinition() {
    Mockito.doReturn(new CustomPropertyDefinition(this.contextImpl.getGeneratorConfig().createObjectNode().put("$comment", "custom property"))).when(this.contextImpl.getGeneratorConfig()).getCustomDefinition(Mockito.any(MethodScope.class), Mockito.any(), Mockito.any());
    MethodScope targetMethod = this.getTestClassMethod("isBooleanField");
    JsonNode result = this.contextImpl.createStandardDefinitionReference(targetMethod, null);
    Assert.assertEquals("{\"$comment\":\"custom property\",\"title\":\"Method Title\",\"description\":\"Type Description\"}", result.toString());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) CustomPropertyDefinition(com.github.victools.jsonschema.generator.CustomPropertyDefinition) MethodScope(com.github.victools.jsonschema.generator.MethodScope) Test(org.junit.Test) AbstractTypeAwareTest(com.github.victools.jsonschema.generator.AbstractTypeAwareTest)

Example 8 with MethodScope

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

the class SchemaGenerationContextImplTest method testCreateStandardDefinitionReferenceForMethod_withCustomPropertyAndTypeDefinitions.

@Test
public void testCreateStandardDefinitionReferenceForMethod_withCustomPropertyAndTypeDefinitions() {
    Mockito.doReturn(new CustomDefinition(this.contextImpl.getGeneratorConfig().createObjectNode().put("$comment", "custom type"), true)).when(this.contextImpl.getGeneratorConfig()).getCustomDefinition(Mockito.any(ResolvedType.class), Mockito.any(), Mockito.any());
    Mockito.doReturn(new CustomPropertyDefinition(this.contextImpl.getGeneratorConfig().createObjectNode().put("$comment", "custom property"))).when(this.contextImpl.getGeneratorConfig()).getCustomDefinition(Mockito.any(MethodScope.class), Mockito.any(), Mockito.any());
    MethodScope targetMethod = this.getTestClassMethod("isBooleanField");
    JsonNode result = this.contextImpl.createStandardDefinitionReference(targetMethod, null);
    Assert.assertEquals("{\"$comment\":\"custom property\",\"title\":\"Method Title\",\"description\":\"Type Description\"}", result.toString());
}
Also used : CustomDefinition(com.github.victools.jsonschema.generator.CustomDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) CustomPropertyDefinition(com.github.victools.jsonschema.generator.CustomPropertyDefinition) MethodScope(com.github.victools.jsonschema.generator.MethodScope) ResolvedType(com.fasterxml.classmate.ResolvedType) Test(org.junit.Test) AbstractTypeAwareTest(com.github.victools.jsonschema.generator.AbstractTypeAwareTest)

Example 9 with MethodScope

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

the class SchemaGeneratorConfigImplTest method testIsNullableMethod.

@Test
@Parameters(method = "parametersForTestIsNullable")
public void testIsNullableMethod(Boolean configResult, boolean optionEnabled, boolean expectedResult) throws Exception {
    MethodScope method = this.getTestClassMethod("getField");
    Mockito.when(this.methodConfigPart.isNullable(method)).thenReturn(configResult);
    if (optionEnabled) {
        this.enabledOptions.add(Option.NULLABLE_METHOD_RETURN_VALUES_BY_DEFAULT);
    }
    boolean result = this.instance.isNullable(method);
    Assert.assertEquals(expectedResult, result);
}
Also used : MethodScope(com.github.victools.jsonschema.generator.MethodScope) Parameters(junitparams.Parameters) AbstractTypeAwareTest(com.github.victools.jsonschema.generator.AbstractTypeAwareTest) Test(org.junit.Test)

Example 10 with MethodScope

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

the class SchemaGeneratorConfigImplTest method testIsRequiredMethod.

@Test
@Parameters({ "true", "false" })
public void testIsRequiredMethod(boolean configuredAndExpectedResult) throws Exception {
    MethodScope method = this.getTestClassMethod("getField");
    Mockito.when(this.methodConfigPart.isRequired(method)).thenReturn(configuredAndExpectedResult);
    boolean result = this.instance.isRequired(method);
    Assert.assertEquals(configuredAndExpectedResult, result);
}
Also used : MethodScope(com.github.victools.jsonschema.generator.MethodScope) Parameters(junitparams.Parameters) AbstractTypeAwareTest(com.github.victools.jsonschema.generator.AbstractTypeAwareTest) Test(org.junit.Test)

Aggregations

MethodScope (com.github.victools.jsonschema.generator.MethodScope)16 Test (org.junit.Test)8 AbstractTypeAwareTest (com.github.victools.jsonschema.generator.AbstractTypeAwareTest)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 FieldScope (com.github.victools.jsonschema.generator.FieldScope)4 Parameters (junitparams.Parameters)4 ResolvedType (com.fasterxml.classmate.ResolvedType)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 CustomDefinition (com.github.victools.jsonschema.generator.CustomDefinition)3 CustomPropertyDefinition (com.github.victools.jsonschema.generator.CustomPropertyDefinition)3 ConfigFunction (com.github.victools.jsonschema.generator.ConfigFunction)2 MemberScope (com.github.victools.jsonschema.generator.MemberScope)2 JsonSubTypes (com.fasterxml.jackson.annotation.JsonSubTypes)1 JsonTypeInfo (com.fasterxml.jackson.annotation.JsonTypeInfo)1 SchemaGeneratorGeneralConfigPart (com.github.victools.jsonschema.generator.SchemaGeneratorGeneralConfigPart)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 TestCaseName (junitparams.naming.TestCaseName)1