1
1
package com .netflix .hollow .api .codegen ;
2
2
3
+ import static org .junit .Assert .assertEquals ;
4
+
5
+ import com .netflix .hollow .core .schema .HollowSchema ;
6
+ import com .netflix .hollow .core .schema .HollowSchemaParser ;
7
+ import com .netflix .hollow .core .schema .SimpleHollowDataset ;
8
+ import com .netflix .hollow .core .write .objectmapper .HollowPrimaryKey ;
9
+ import java .io .BufferedReader ;
10
+ import java .io .FileInputStream ;
11
+ import java .io .InputStream ;
12
+ import java .io .InputStreamReader ;
13
+ import java .nio .file .Paths ;
14
+ import java .util .HashSet ;
15
+ import java .util .List ;
3
16
import org .junit .Test ;
4
17
5
18
public class HollowAPIGeneratorTest extends AbstractHollowAPIGeneratorTest {
6
19
20
+ @ Test
21
+ public void assertMetaInfoAtCustomLocation () throws Exception {
22
+ runGenerator ("API" , "codegen.api" , MyClass .class , b -> b .withMetaInfo ("meta-info" ));
23
+ assertNonEmptyFileExists (Paths .get ("meta-info" ));
24
+ }
25
+
26
+ @ Test
27
+ public void testSchemaDocAtCustomLocation () throws Exception {
28
+ runGenerator ("MyClassTestAPI" , "codegen.api" , MyClass .class ,
29
+ builder -> builder .withMetaInfo (tmpFolder + "/" + "resources/META-INF/hollow" ));
30
+ assertNonEmptyFileExists (Paths .get (tmpFolder , "resources/META-INF/hollow/codegen.api.MyClassTestAPI.schema" ));
31
+ }
32
+
33
+ @ Test
34
+ public void testSchemaDocContents () throws Exception {
35
+ runGenerator ("MyClassTestAPI" , "codegen.api" , MyClass .class , b -> b .withMetaInfo (Paths .get (sourceFolder )));
36
+ assertNonEmptyFileExists (Paths .get (sourceFolder , "codegen.api.MyClassTestAPI.schema" ));
37
+
38
+ List <HollowSchema > expected = SimpleHollowDataset .fromClassDefinitions (MyClass .class ).getSchemas ();
39
+ try (InputStream input = new FileInputStream (sourceFolder + "/" + "codegen.api.MyClassTestAPI.schema" )) {
40
+ List <HollowSchema > actual = HollowSchemaParser .parseCollectionOfSchemas (new BufferedReader (new InputStreamReader (input )));
41
+ assertEquals (expected .size (), actual .size ());
42
+ assertEquals (new HashSet (expected ), new HashSet (actual ));
43
+ }
44
+ }
45
+
7
46
@ Test
8
47
public void generatesFileUsingDestinationPath () throws Exception {
9
48
runGenerator ("API" , "com.netflix.hollow.example.api.generated" , MyClass .class , b -> b );
@@ -13,15 +52,15 @@ public void generatesFileUsingDestinationPath() throws Exception {
13
52
public void testGenerateWithPostfix () throws Exception {
14
53
runGenerator ("MyClassTestAPI" , "codegen.api" , MyClass .class ,
15
54
builder -> builder .withClassPostfix ("Generated" ));
16
- assertNonEmptyFileExists ("codegen/api/StringGenerated.java" );
55
+ assertNonEmptyFileExists (Paths . get ( sourceFolder , "codegen/api/StringGenerated.java" ) );
17
56
assertClassHasHollowTypeName ("codegen.api.MyClassGenerated" , "MyClass" );
18
57
}
19
58
20
59
@ Test
21
60
public void testGenerateWithPostfixAndPackageGrouping () throws Exception {
22
61
runGenerator ("MyClassTestAPI" , "codegen.api" , MyClass .class ,
23
62
builder -> builder .withClassPostfix ("Generated" ).withPackageGrouping ());
24
- assertNonEmptyFileExists ("codegen/api/core/StringGenerated.java" );
63
+ assertNonEmptyFileExists (Paths . get ( sourceFolder , "codegen/api/core/StringGenerated.java" ) );
25
64
}
26
65
27
66
@ Test
@@ -43,6 +82,7 @@ public void testGenerateWithPostfixAndAggressiveSubstitutions() throws Exception
43
82
}
44
83
45
84
@ SuppressWarnings ("unused" )
85
+ @ HollowPrimaryKey (fields = "id" )
46
86
private static class MyClass {
47
87
int id ;
48
88
String foo ;
0 commit comments