77import bio .guoda .preston .store .KeyTo3LevelPath ;
88import bio .guoda .preston .store .KeyValueStoreLocalFileSystem ;
99import bio .guoda .preston .store .ValidatingKeyValueStreamContentAddressedFactory ;
10+ import com .fasterxml .jackson .databind .JsonNode ;
1011import com .fasterxml .jackson .databind .ObjectMapper ;
1112import com .fasterxml .jackson .databind .node .ObjectNode ;
1213import org .apache .commons .io .FileUtils ;
@@ -138,7 +139,7 @@ public void streamSomeProvStatements() throws IOException {
138139
139140 CmdStream cmdStream = new CmdStream ();
140141
141- Collection <File > filesAfter = getFiles (provLogGeneratedByElton , outputStream , errorStream , cmdStream , "/b92cd44dcba945c760229a14d3b9becb2dd0c147.zip" );
142+ Collection <File > filesAfter = runStreamAndGetFiles (provLogGeneratedByElton , outputStream , errorStream , cmdStream , "/b92cd44dcba945c760229a14d3b9becb2dd0c147.zip" );
142143
143144 List <String > filenames = filesAfter .stream ().map (File ::getName ).collect (Collectors .toList ());
144145
@@ -148,8 +149,48 @@ public void streamSomeProvStatements() throws IOException {
148149 }
149150
150151 @ Test
151- public void streamSomeProvStatementsAnchored () throws IOException {
152+ public void streamSomeProvStatementsAnchoredForInteractionRecordType () throws IOException {
153+ ByteArrayOutputStream outputStream = streamData ("interaction" , "hash://md5/d3b07384d113edec49eaa6238ad5ff00" );
154+ String columnNames = headerInteractions ();
155+ assertHeaderAndMore (outputStream , columnNames );
156+ List <String > split = Arrays .asList (StringUtils .split (columnNames , "\t " ));
157+ int indexContentHash = split .indexOf ("contentHash" );
158+
159+ assertThat (indexContentHash , Is .is (51 ));
160+
161+ String interactions = new String (outputStream .toByteArray (), StandardCharsets .UTF_8 );
162+
163+ String [] lines = interactions .split ("\n " );
164+
165+ assertThat (StringUtils .splitByWholeSeparatorPreserveAllTokens (lines [1 ], "\t " )[indexContentHash ], Is .is ("hash://md5/d3b07384d113edec49eaa6238ad5ff00" ));
166+ assertThat (lines [1 ], containsString ("hash://md5/d3b07384d113edec49eaa6238ad5ff00" ));
167+ }
168+
169+ @ Test
170+ public void streamSomeProvStatementsAnchoredForReviewRecordType () throws IOException {
171+ String provenanceAnchor = "hash://md5/d3b07384d113edec49eaa6238ad5ff00" ;
172+ ByteArrayOutputStream outputStream = streamData ("review" , provenanceAnchor );
173+ String columnNames = headerReviewNotes ();
174+ assertHeaderAndMore (outputStream , columnNames );
175+ List <String > split = Arrays .asList (StringUtils .split (columnNames , "\t " ));
176+ int indexContentHash = split .indexOf ("dataContext" );
177+
178+ assertThat (indexContentHash , Is .is (14 ));
179+
180+ String interactions = new String (outputStream .toByteArray (), StandardCharsets .UTF_8 );
181+
182+ String [] lines = interactions .split ("\n " );
183+
184+ String dataContext = StringUtils .splitByWholeSeparatorPreserveAllTokens (lines [1 ], "\t " )[indexContentHash ];
185+
186+ JsonNode jsonNode = new ObjectMapper ().readTree (dataContext );
187+ assertThat (jsonNode .at ("/reviewComment" ).asText (), Is .is ("biotic interaction found" ));
188+ assertThat (jsonNode .at ("/context/contentHash" ).asText (), Is .is (provenanceAnchor ));
189+
190+ }
191+
152192
193+ private ByteArrayOutputStream streamData (String recordType , String provenanceAnchor ) throws IOException {
153194 String provLogGeneratedByElton = "<urn:lsid:globalbioticinteractions.org:globalbioticinteractions/template-dataset> <http://www.w3.org/ns/prov#wasAssociatedWith> <https://github.com/globalbioticinteractions/template-dataset/archive/b92cd44dcba945c760229a14d3b9becb2dd0c147.zip> <urn:uuid:16b63a6d-153b-4f16-afed-a67fa09383a7> .\n " +
154195 "<https://github.com/globalbioticinteractions/template-dataset/archive/b92cd44dcba945c760229a14d3b9becb2dd0c147.zip> <http://purl.org/dc/elements/1.1/format> \" application/globi\" <urn:uuid:16b63a6d-153b-4f16-afed-a67fa09383a7> .\n " +
155196 "<urn:uuid:41389744-0f4d-47e2-8506-76999e1b5c34> <http://www.w3.org/ns/prov#used> <https://github.com/globalbioticinteractions/template-dataset/archive/b92cd44dcba945c760229a14d3b9becb2dd0c147.zip> <urn:uuid:16b63a6d-153b-4f16-afed-a67fa09383a7> .\n " +
@@ -163,28 +204,15 @@ public void streamSomeProvStatementsAnchored() throws IOException {
163204 ByteArrayOutputStream errorStream = new ByteArrayOutputStream ();
164205
165206 CmdStream cmdStream = new CmdStream ();
166- cmdStream .setProvenanceAnchor (RefNodeFactory .toIRI ("hash://md5/d3b07384d113edec49eaa6238ad5ff00" ));
207+ cmdStream .setProvenanceAnchor (RefNodeFactory .toIRI (provenanceAnchor ));
208+ cmdStream .setRecordType (recordType );
167209
168- Collection <File > filesAfter = getFiles (provLogGeneratedByElton , outputStream , errorStream , cmdStream , "/b92cd44dcba945c760229a14d3b9becb2dd0c147.zip" );
210+ Collection <File > filesAfter = runStreamAndGetFiles (provLogGeneratedByElton , outputStream , errorStream , cmdStream , "/b92cd44dcba945c760229a14d3b9becb2dd0c147.zip" );
169211
170212 List <String > filenames = filesAfter .stream ().map (File ::getName ).collect (Collectors .toList ());
171213
172214 assertThat (filenames , hasItems ("76c00c8b64e422800b85d29db93bcfa9ebee999f52f21e16cbd00ba750e98b44" ));
173-
174- String columnNames = headerInteractions ();
175- assertHeaderAndMore (outputStream , columnNames );
176- List <String > split = Arrays .asList (StringUtils .split (columnNames , "\t " ));
177- int indexContentHash = split .indexOf ("contentHash" );
178-
179- assertThat (indexContentHash , Is .is (51 ));
180-
181- String interactions = new String (outputStream .toByteArray (), StandardCharsets .UTF_8 );
182-
183- String [] lines = interactions .split ("\n " );
184-
185- assertThat (StringUtils .splitByWholeSeparatorPreserveAllTokens (lines [1 ], "\t " )[indexContentHash ], Is .is ("hash://md5/d3b07384d113edec49eaa6238ad5ff00" ));
186- assertThat (lines [1 ], containsString ("hash://md5/d3b07384d113edec49eaa6238ad5ff00" ));
187-
215+ return outputStream ;
188216 }
189217
190218 @ Test
@@ -204,7 +232,7 @@ public void streamSomeProvStatementsEmbeddedGzip() throws IOException {
204232
205233 CmdStream cmdStream = new CmdStream ();
206234
207- Collection <File > filesAfter = getFiles (provLogGeneratedByElton , outputStream , errorStream , cmdStream , "/b92cd44dcba945c760229a14d3b9becb2dd0c147_gzip.zip" );
235+ Collection <File > filesAfter = runStreamAndGetFiles (provLogGeneratedByElton , outputStream , errorStream , cmdStream , "/b92cd44dcba945c760229a14d3b9becb2dd0c147_gzip.zip" );
208236
209237 List <String > filenames = filesAfter .stream ().map (File ::getName ).collect (Collectors .toList ());
210238
@@ -213,7 +241,7 @@ public void streamSomeProvStatementsEmbeddedGzip() throws IOException {
213241 assertHeaderAndMore (outputStream , headerInteractions ());
214242 }
215243
216- private Collection <File > getFiles (String provLogGeneratedByElton , ByteArrayOutputStream outputStream , ByteArrayOutputStream errorStream , CmdStream cmdStream , String resource ) throws IOException {
244+ private Collection <File > runStreamAndGetFiles (String provLogGeneratedByElton , ByteArrayOutputStream outputStream , ByteArrayOutputStream errorStream , CmdStream cmdStream , String resource ) throws IOException {
217245 File tmpDir = folder .newFolder ("tmpDir" );
218246 tmpDir .mkdirs ();
219247
@@ -471,7 +499,7 @@ public void streamSomeProvStatementsTemplateDataset() throws IOException {
471499
472500 CmdStream cmdStream = new CmdStream ();
473501
474- Collection <File > filesAfter = getFiles (provLogGeneratedByEltonTrack , outputStream , errorStream , cmdStream , "/template-dataset-0.0.3.zip" );
502+ Collection <File > filesAfter = runStreamAndGetFiles (provLogGeneratedByEltonTrack , outputStream , errorStream , cmdStream , "/template-dataset-0.0.3.zip" );
475503
476504 List <String > filenames = filesAfter .stream ().map (File ::getName ).collect (Collectors .toList ());
477505
@@ -551,7 +579,7 @@ public void streamProvStatementsGeneratedByEltonProv() throws IOException {
551579
552580 CmdStream cmdStream = new CmdStream ();
553581
554- Collection <File > filesAfter = getFiles (provLogGeneratedByEltonTrack , outputStream , errorStream , cmdStream , "/template-dataset-0.0.3.zip" );
582+ Collection <File > filesAfter = runStreamAndGetFiles (provLogGeneratedByEltonTrack , outputStream , errorStream , cmdStream , "/template-dataset-0.0.3.zip" );
555583
556584 List <String > filenames = filesAfter .stream ().map (File ::getName ).collect (Collectors .toList ());
557585
0 commit comments