|
9 | 9 | import org.junit.Assert;
|
10 | 10 | import org.junit.Test;
|
11 | 11 |
|
| 12 | +import java.io.File; |
| 13 | +import java.io.IOException; |
| 14 | + |
12 | 15 | public class JsonSchemaGeneratorTest {
|
13 | 16 |
|
14 | 17 | @Test
|
@@ -54,6 +57,45 @@ public void shouldWriteJsonSchemaToFile() throws Exception {
|
54 | 57 | Assert.assertTrue(FileUtils.getFile(filename).exists());
|
55 | 58 | }
|
56 | 59 |
|
| 60 | + @Test |
| 61 | + public void shouldGeneratePOJOs() throws IOException { |
| 62 | + String json = "{\"createdAt\":\"2017-07-19T16:31:26.843Z\"," + |
| 63 | + "\"sectors\":[{\"times\":[{\"intensity\":30,\"start\":{\"hour\":8,\"minute\":30}," + |
| 64 | + "\"end\":{\"hour\":17,\"minute\":0}},{\"intensity\":10,\"start\":{\"hour\":17,\"minute\":5}," + |
| 65 | + "\"end\":{\"hour\":23,\"minute\":55}}],\"id\":\"dbea21eb-57b5-44c9-a953-f61816fd5876\"}]," + |
| 66 | + "\"dayOfWeek\":\"0,6\",\"createdBy\":\"Admin\",\"name\":\"test weekend preset\"," + |
| 67 | + "\"client\":\"TestClient\",\"id\":\"83d6640a-6d80-487c-b92c-e4239e1ec6d5\"," + |
| 68 | + "\"state\":true, \"dateToday\": \"null\"}"; |
| 69 | + |
| 70 | + String directory = "generated-sources"; |
| 71 | + JsonSchemaGenerator.outputAsPOJO("Schedule", "Test", json, |
| 72 | + "com.example", directory); |
| 73 | + Assert.assertTrue("POJO(s) not generated", |
| 74 | + FileUtils.getFile(directory).list().length > 0); |
| 75 | + FileUtils.forceDeleteOnExit(new File(directory)); |
| 76 | + } |
| 77 | + |
| 78 | + @Test |
| 79 | + public void shouldGeneratePOJOsIntoExistingDirectory() throws IOException { |
| 80 | + String json = "{\"createdAt\":\"2017-07-19T16:31:26.843Z\"," + |
| 81 | + "\"sectors\":[{\"times\":[{\"intensity\":30,\"start\":{\"hour\":8,\"minute\":30}," + |
| 82 | + "\"end\":{\"hour\":17,\"minute\":0}},{\"intensity\":10,\"start\":{\"hour\":17,\"minute\":5}," + |
| 83 | + "\"end\":{\"hour\":23,\"minute\":55}}],\"id\":\"dbea21eb-57b5-44c9-a953-f61816fd5876\"}]," + |
| 84 | + "\"dayOfWeek\":\"0,6\",\"createdBy\":\"Admin\",\"name\":\"test weekend preset\"," + |
| 85 | + "\"client\":\"TestClient\",\"id\":\"83d6640a-6d80-487c-b92c-e4239e1ec6d5\"," + |
| 86 | + "\"state\":true, \"dateToday\": \"null\"}"; |
| 87 | + |
| 88 | + String directory = "generated-src"; |
| 89 | + File dir = new File(directory); |
| 90 | + FileUtils.forceMkdir(dir); |
| 91 | + |
| 92 | + JsonSchemaGenerator.outputAsPOJO("Schedule", "Test", json, |
| 93 | + "com.example", directory); |
| 94 | + Assert.assertTrue("POJO(s) not generated", |
| 95 | + FileUtils.getFile(directory).list().length > 0); |
| 96 | + FileUtils.forceDeleteOnExit(dir); |
| 97 | + } |
| 98 | + |
57 | 99 | private boolean isValid(String json, String result) {
|
58 | 100 | boolean isValid = true;
|
59 | 101 |
|
|
0 commit comments