iemejia commented on a change in pull request #14520:
URL: https://github.com/apache/beam/pull/14520#discussion_r612939531



##########
File path: 
runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/resources/PipelineResourcesTest.java
##########
@@ -102,8 +100,57 @@ public void testPackagingDirectoryResourceToJarFile() 
throws IOException {
 
   @Test
   public void testIfThrowsWhenThereIsNoTemporaryFolderForJars() throws 
IOException {
-    List<String> filesToStage = new ArrayList<>();
-    filesToStage.add(tmpFolder.newFolder().getAbsolutePath());
+    List<String> filesToStage = 
Arrays.asList(tmpFolder.newFolder().getAbsolutePath());
+
+    IllegalArgumentException exception =
+        assertThrows(
+            IllegalArgumentException.class,
+            () -> PipelineResources.prepareFilesForStaging(filesToStage, 
null));
+
+    assertEquals(
+        "Please provide temporary location for storing the jar files.", 
exception.getMessage());
+  }
+
+  @Test
+  public void testPrepareFilesForStagingFromOptions() throws IOException {
+    String nonexistentFilePath = tmpFolder.getRoot().getPath() + 
"/nonexistent/file";
+    String existingFilePath = 
tmpFolder.newFile("existingFile").getAbsolutePath();
+    List<String> filesToStage = Arrays.asList(nonexistentFilePath, 
existingFilePath);
+    String temporaryLocation = tmpFolder.newFolder().getAbsolutePath();
+
+    FileStagingOptions options = 
PipelineOptionsFactory.create().as(FileStagingOptions.class);
+    options.setFilesToStage(filesToStage);
+    options.setTempLocation(temporaryLocation);
+
+    assertThrows(
+        "To-be-staged file does not exist: ",
+        IllegalStateException.class,
+        () -> PipelineResources.prepareFilesForStaging(filesToStage, 
temporaryLocation));
+  }
+
+  @Test
+  public void testPackagingDirectoryResourceFromOptions() throws IOException {
+    String directoryPath = tmpFolder.newFolder().getAbsolutePath();
+    List<String> filesToStage = Arrays.asList(directoryPath);
+    String temporaryLocation = tmpFolder.newFolder().getAbsolutePath();
+
+    FileStagingOptions options = 
PipelineOptionsFactory.create().as(FileStagingOptions.class);
+    options.setFilesToStage(filesToStage);
+    options.setTempLocation(temporaryLocation);
+
+    PipelineResources.prepareFilesForStaging(options);
+    List<String> result = options.getFilesToStage();
+
+    assertTrue(new File(result.get(0)).exists());

Review comment:
       yep, done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to