-
Notifications
You must be signed in to change notification settings - Fork 534
/
Copy pathDeserializationUtilsTest.java
60 lines (48 loc) · 2.27 KB
/
DeserializationUtilsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package io.swagger.parser.util;
import com.fasterxml.jackson.databind.JsonNode;
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertNotSame;
public class DeserializationUtilsTest {
@Test
public void testEnumValuesAreNotConvertedToBooleansOAS2() throws IOException {
String yaml = readFile("src/test/resources/EnumYesNoOnOffOAS2.yaml");
JsonNode jsonNode = DeserializationUtils.readYamlTree(yaml, null);
jsonNode.findPath("EnumWithQuotes").get("enum").elements()
.forEachRemaining(element -> {
assertFalse(element.isBoolean());
assertNotSame(element.textValue(), "true");
assertNotSame(element.textValue(), "false");
});
jsonNode.findPath("EnumNoQuotes").get("enum").elements()
.forEachRemaining(element -> {
assertFalse(element.isBoolean());
assertNotSame(element.textValue(), "true");
assertNotSame(element.textValue(), "false");
});
}
@Test
public void testEnumValuesAreNotConvertedToBooleansOAS3() throws IOException {
String yaml = readFile("src/test/resources/EnumYesNoOnOffOAS3.yaml");
JsonNode jsonNode = DeserializationUtils.readYamlTree(yaml, null);
jsonNode.findPath("EnumWithQuotes").get("enum").elements()
.forEachRemaining(element -> {
assertFalse(element.isBoolean());
assertNotSame(element.textValue(), "true");
assertNotSame(element.textValue(), "false");
});
jsonNode.findPath("EnumNoQuotes").get("enum").elements()
.forEachRemaining(element -> {
assertFalse(element.isBoolean());
assertNotSame(element.textValue(), "true");
assertNotSame(element.textValue(), "false");
});
}
private String readFile(String name) throws IOException {
return new String(Files.readAllBytes(new File(name).toPath()), StandardCharsets.UTF_8);
}
}