-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve testing to try to reproduce #57
- Loading branch information
1 parent
5327842
commit 3201e3f
Showing
3 changed files
with
90 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/test/java/com/fasterxml/jackson/module/jsonSchema/EnumGenerationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.fasterxml.jackson.module.jsonSchema; | ||
|
||
import java.util.*; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
|
||
public class EnumGenerationTest extends SchemaTestBase | ||
{ | ||
public enum Enumerated { | ||
A, B, C; | ||
|
||
// add this; should NOT matter but... | ||
@Override | ||
public String toString() { | ||
return "ToString:"+name(); | ||
} | ||
} | ||
public static class LetterBean { | ||
|
||
public Enumerated letter; | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Test methods | ||
/********************************************************** | ||
*/ | ||
|
||
private final ObjectMapper MAPPER = new ObjectMapper(); | ||
|
||
public void testEnumDefault() throws Exception | ||
{ | ||
JsonSchemaGenerator generator = new JsonSchemaGenerator(MAPPER); | ||
JsonSchema jsonSchema = generator.generateSchema(LetterBean.class); | ||
@SuppressWarnings("unchecked") | ||
Map<String, Object> result = (Map<String, Object>) MAPPER.convertValue(jsonSchema, Map.class); | ||
assertNotNull(result); | ||
assertTrue(jsonSchema.isObjectSchema()); | ||
assertEquals(expectedAsMap(false), result); | ||
} | ||
|
||
public void testEnumWithToString() throws Exception | ||
{ | ||
final ObjectMapper mapper = new ObjectMapper(); | ||
mapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); | ||
|
||
JsonSchemaGenerator generator = new JsonSchemaGenerator(mapper); | ||
JsonSchema jsonSchema = generator.generateSchema(LetterBean.class); | ||
@SuppressWarnings("unchecked") | ||
Map<String, Object> result = (Map<String, Object>) mapper.convertValue(jsonSchema, Map.class); | ||
assertNotNull(result); | ||
assertTrue(jsonSchema.isObjectSchema()); | ||
assertEquals(expectedAsMap(true), result); | ||
} | ||
|
||
@SuppressWarnings("serial") | ||
private Map<String,Object> expectedAsMap(final boolean useToString) | ||
{ | ||
return new LinkedHashMap<String, Object>() { | ||
{ | ||
put("type", "object"); | ||
put("id", "urn:jsonschema:com:fasterxml:jackson:module:jsonSchema:EnumGenerationTest:LetterBean"); | ||
put("properties", | ||
new LinkedHashMap<String, Object>() { | ||
{ | ||
put("letter", | ||
new LinkedHashMap<String, Object>() { | ||
{ | ||
put("type", "string"); | ||
put("enum", new ArrayList<String>() { | ||
{ | ||
add(useToString ? "ToString:A" : "A"); | ||
add(useToString ? "ToString:B" : "B"); | ||
add(useToString ? "ToString:C" : "C"); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters