Skip to content

Commit

Permalink
feat: dryrun for bundle download
Browse files Browse the repository at this point in the history
  • Loading branch information
katerina20 committed Oct 4, 2023
1 parent 3c2f517 commit 9027f3d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,28 @@ public class DownloadBundleAction implements NewAction<ProjectProperties, Client
private final boolean noProgress;
private final boolean plainView;
private final boolean keepArchive;
private final boolean dryrun;
private File to;

private Outputter out;

public DownloadBundleAction(Long id, FilesInterface files, boolean plainView, boolean keepArchive, boolean noProgress) {
public DownloadBundleAction(Long id, FilesInterface files, boolean plainView, boolean keepArchive, boolean noProgress, boolean dryrun) {
this.id = id;
this.files = files;
this.plainView = plainView;
this.keepArchive = keepArchive;
this.noProgress = noProgress;
this.dryrun = dryrun;
}

@Override
public void act(Outputter out, ProjectProperties pb, ClientBundle client) {
this.out = out;
Bundle bundle = getBundle(client);
if (dryrun) {
out.println(OK.withIcon(String.format(RESOURCE_BUNDLE.getString("message.bundle.found"), bundle.getId(), bundle.getName())));
return;
}
BundleExport status = this.buildBundle(out, client, bundle.getId());
to = new File("bundle-" + status.getIdentifier() + ".zip");
downloadBundle(client, bundle.getId(), status.getIdentifier());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ public class DownloadBundleSubcommand extends ActCommandBundle {
@CommandLine.Option(names = {"--keep-archive"}, descriptionKey = "params.keepArchive")
protected boolean keepArchive;

@CommandLine.Option(names = {"--dryrun"})
protected boolean dryrun;

@Override
protected NewAction<ProjectProperties, ClientBundle> getAction(Actions actions) {
return new DownloadBundleAction(id, new FsFiles(), plainView, keepArchive, noProgress);
return new DownloadBundleAction(id, new FsFiles(), plainView, keepArchive, noProgress, dryrun);
}
}
1 change: 1 addition & 0 deletions src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ message.distribution.list_empty=No distributions found
message.distribution.added=@|green,bold Distribution '%s'|@ @|green added successfully|@
message.distribution.released=@|green,bold Distribution '%s'|@ @|green released successfully|@

message.bundle.found=Bundle @|yellow #%d|@ @|green,bold '%s'|@
message.bundle.download_success=@|yellow #%d|@ @|green,bold '%s'|@ @|green downloaded successfully|@
message.bundle.list=@|yellow #%d|@ @|bold '%s'|@ @|green %s|@ @|red %s|@
message.bundle.list_empty=No bundles found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testDownloadBundle() {
.build();

Bundle bundle = new Bundle();
bundle.setId(1l);
bundle.setId(1L);

BundleExport export = new BundleExport();
export.setStatus("finished");
Expand All @@ -63,12 +63,38 @@ public void testDownloadBundle() {
FilesInterface files = mock(FilesInterface.class);

NewAction<ProjectProperties, ClientBundle> action =
new DownloadBundleAction(bundle.getId(), files, false, false, false);
new DownloadBundleAction(bundle.getId(), files, false, false, false, false);
action.act(Outputter.getDefault(), pb, client);

verify(client).getBundle(bundle.getId());
verify(client).startExportingBundle(bundle.getId());
verify(client).downloadBundle(bundle.getId(), null);
verifyNoMoreInteractions(client);
}

@Test
public void testDryRun() {
PropertiesWithFiles pb = NewPropertiesWithFilesUtilBuilder
.minimalBuiltPropertiesBean(
"/values/strings.xml", "/values-%two_letters_code%/%original_file_name%",
null, "/common/%original_file_name%")
.setBasePath(project.getBasePath())
.build();

Bundle bundle = new Bundle();
bundle.setId(1L);
bundle.setName("test-bundle");
ClientBundle client = mock(ClientBundle.class);
when(client.getBundle(bundle.getId()))
.thenReturn(Optional.of(bundle));

FilesInterface files = mock(FilesInterface.class);

NewAction<ProjectProperties, ClientBundle> action =
new DownloadBundleAction(bundle.getId(), files, false, false, false, true);
action.act(Outputter.getDefault(), pb, client);

verify(client).getBundle(bundle.getId());
verifyNoMoreInteractions(client);
}
}

0 comments on commit 9027f3d

Please sign in to comment.