3
3
import static bio .terra .pfb .utils .CompareOutputUtils .FileExtension .JSON ;
4
4
import static bio .terra .pfb .utils .CompareOutputUtils .FileExtension .TXT ;
5
5
import static bio .terra .pfb .utils .CompareOutputUtils .PfbCommandType .*;
6
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
6
7
import static org .junit .jupiter .api .Assertions .assertThrows ;
7
8
8
9
import bio .terra .pfb .exceptions .InvalidPfbException ;
9
10
import bio .terra .pfb .utils .CompareOutputUtils ;
11
+ import com .fasterxml .jackson .databind .JsonNode ;
12
+ import com .fasterxml .jackson .databind .ObjectMapper ;
10
13
import java .io .IOException ;
11
14
import java .util .List ;
15
+ import java .util .Spliterator ;
16
+ import java .util .Spliterators ;
12
17
import java .util .stream .Stream ;
18
+ import java .util .stream .StreamSupport ;
19
+ import org .apache .avro .Schema ;
13
20
import org .junit .jupiter .api .Disabled ;
14
21
import org .junit .jupiter .api .Test ;
15
22
import org .junit .jupiter .params .ParameterizedTest ;
@@ -38,6 +45,39 @@ void showSchemaTest(String fileName) throws IOException {
38
45
}
39
46
}
40
47
48
+ // this test validates behavior of the PfbReader.getPfbSchema() method. This method is
49
+ // used internally by PfbReader.showSchema, which is thoroughly tested by {@link
50
+ // #showsSchemaTest()} therefore,
51
+ // this test only performs cursory correctness checks.
52
+ @ ParameterizedTest
53
+ @ MethodSource ("provideTestFiles" )
54
+ void getPfbSchemaTest (String fileName ) throws IOException {
55
+ // TODO - remove when fix is added for AJ-1288
56
+ if (fileName .equals ("empty" )) {
57
+ logger .error ("Skipping test file: {} until fixed in AJ-1288\n " , fileName );
58
+ } else {
59
+ // read the pypfb output for this file
60
+ String expectedStr = CompareOutputUtils .getPyPfbOutput (fileName , SHOW_SCHEMA , JSON );
61
+ // parse the pypfb output for this file
62
+ ObjectMapper mapper = new ObjectMapper ();
63
+ JsonNode expected = mapper .readTree (expectedStr );
64
+ // find the names of all top-level types from the pypfb output
65
+ List <String > expectedNames =
66
+ StreamSupport .stream (
67
+ Spliterators .spliteratorUnknownSize (expected .elements (), Spliterator .ORDERED ),
68
+ false )
69
+ .map (typeNode -> typeNode .get ("name" ).asText ())
70
+ .toList ();
71
+ // get the PfbReader-calculated schema for this file from PfbReader
72
+ List <Schema > actualSchema =
73
+ PfbReader .getPfbSchema (CompareOutputUtils .getAvroFilePath (fileName , "" ));
74
+ // find the names of all top-level types in the actual schema
75
+ List <String > actualNames = actualSchema .stream ().map (Schema ::getName ).toList ();
76
+
77
+ assertEquals (expectedNames , actualNames );
78
+ }
79
+ }
80
+
41
81
@ ParameterizedTest
42
82
@ MethodSource ("provideTestFiles" )
43
83
void showNodesTest (String fileName ) throws IOException {
@@ -57,8 +97,7 @@ void getGenericRecordsStream(String fileName) throws IOException {
57
97
}
58
98
59
99
@ Test
60
- @ MethodSource ("provideTestFiles" )
61
- void getGenericRecordsStreamError () throws IOException {
100
+ void getGenericRecordsStreamError () {
62
101
assertThrows (
63
102
InvalidPfbException .class ,
64
103
() -> CompareOutputUtils .testDataStream ("noFile.txt" ),
0 commit comments