diff --git a/src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java b/src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java index 4609f7250..525a015af 100644 --- a/src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java +++ b/src/main/java/com/crowdin/cli/client/CrowdinProjectClient.java @@ -29,8 +29,11 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.BiPredicate; +import static com.crowdin.cli.BaseCli.RESOURCE_BUNDLE; + class CrowdinProjectClient extends CrowdinClientCore implements ProjectClient { private final com.crowdin.client.Client client; @@ -42,11 +45,11 @@ public CrowdinProjectClient(com.crowdin.client.Client client, long projectId) { } @Override - public CrowdinProjectFull downloadFullProject() { + public CrowdinProjectFull downloadFullProject(String branchName) { CrowdinProjectFull project = new CrowdinProjectFull(); this.populateProjectWithInfo(project); this.populateProjectWithLangs(project); - this.populateProjectWithStructure(project); + this.populateProjectWithStructure(project, branchName); return project; } @@ -65,12 +68,18 @@ public CrowdinProjectInfo downloadProjectInfo() { return project; } - private void populateProjectWithStructure(CrowdinProjectFull project) { + private void populateProjectWithStructure(CrowdinProjectFull project, String branchName) { + project.setBranches(this.listBranches()); + Optional.ofNullable(branchName) + .map(name -> project.findBranchByName(name) + .orElseThrow(() -> new RuntimeException(RESOURCE_BUNDLE.getString("error.not_found_branch"))) + ) + .ifPresent(project::setBranch); + Long branchId = Optional.ofNullable(project.getBranch()).map(Branch::getId).orElse(null); project.setFiles(executeRequestFullList((limit, offset) -> this.client.getSourceFilesApi() - .listFiles(this.projectId, null, null, null, null, limit, offset))); + .listFiles(this.projectId, branchId, null, null, true, limit, offset))); project.setDirectories(executeRequestFullList((limit, offset) -> this.client.getSourceFilesApi() - .listDirectories(this.projectId, null, null, null, null, limit, offset))); - project.setBranches(this.listBranches()); + .listDirectories(this.projectId, branchId, null, null, true, limit, offset))); } private void populateProjectWithLangs(CrowdinProject project) { diff --git a/src/main/java/com/crowdin/cli/client/CrowdinProjectFull.java b/src/main/java/com/crowdin/cli/client/CrowdinProjectFull.java index 450400909..fcac38275 100644 --- a/src/main/java/com/crowdin/cli/client/CrowdinProjectFull.java +++ b/src/main/java/com/crowdin/cli/client/CrowdinProjectFull.java @@ -20,6 +20,7 @@ public class CrowdinProjectFull extends CrowdinProject { private List files; private List directories; private List branches; + private Branch branch; void setFiles(List files) { this.files = files; @@ -39,6 +40,14 @@ public Map getBranches() { .collect(Collectors.toMap(Branch::getId, Function.identity())); } + public Branch getBranch() { + return branch; + } + + public void setBranch(Branch branch) { + this.branch = branch; + } + public void addBranchToLocalList(Branch branch) { this.branches.add(branch); } diff --git a/src/main/java/com/crowdin/cli/client/ProjectClient.java b/src/main/java/com/crowdin/cli/client/ProjectClient.java index 4e5daa5a5..22990bdc1 100644 --- a/src/main/java/com/crowdin/cli/client/ProjectClient.java +++ b/src/main/java/com/crowdin/cli/client/ProjectClient.java @@ -27,7 +27,11 @@ public interface ProjectClient extends Client { - CrowdinProjectFull downloadFullProject(); + default CrowdinProjectFull downloadFullProject() { + return this.downloadFullProject(null); + } + + CrowdinProjectFull downloadFullProject(String branchName); CrowdinProject downloadProjectWithLanguages(); diff --git a/src/main/java/com/crowdin/cli/commands/actions/DownloadAction.java b/src/main/java/com/crowdin/cli/commands/actions/DownloadAction.java index beb978598..68f8b7be4 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/DownloadAction.java +++ b/src/main/java/com/crowdin/cli/commands/actions/DownloadAction.java @@ -91,7 +91,7 @@ public void act(Outputter out, PropertiesWithFiles pb, ProjectClient client) { CrowdinProjectFull project = ConsoleSpinner .execute(out, "message.spinner.fetching_project_info", "error.collect_project_info", - this.noProgress, this.plainView, client::downloadFullProject); + this.noProgress, this.plainView, () -> client.downloadFullProject(this.branchName)); if (!project.isManagerAccess()) { if (!plainView) { @@ -115,9 +115,7 @@ public void act(Outputter out, PropertiesWithFiles pb, ProjectClient client) { .orElseThrow(() -> new RuntimeException( String.format(RESOURCE_BUNDLE.getString("error.language_not_exist"), lang)))) .collect(Collectors.toList()); - Optional branch = Optional.ofNullable(this.branchName) - .map(br -> project.findBranchByName(br) - .orElseThrow(() -> new RuntimeException(RESOURCE_BUNDLE.getString("error.not_found_branch")))); + Optional branch = Optional.ofNullable(project.getBranch()); Map serverSources = ProjectFilesUtils.buildFilePaths(project.getDirectories(), project.getFiles()); diff --git a/src/main/java/com/crowdin/cli/commands/actions/DownloadSourcesAction.java b/src/main/java/com/crowdin/cli/commands/actions/DownloadSourcesAction.java index a7944fa0d..fc32a35c4 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/DownloadSourcesAction.java +++ b/src/main/java/com/crowdin/cli/commands/actions/DownloadSourcesAction.java @@ -93,11 +93,9 @@ public void act(Outputter out, PropertiesWithFiles properties, ProjectClient cli CrowdinProjectFull project = ConsoleSpinner .execute(out, "message.spinner.fetching_project_info", "error.collect_project_info", - this.noProgress, this.plainView, client::downloadFullProject); + this.noProgress, this.plainView, () -> client.downloadFullProject(this.branchName)); - Long branchId = Optional.ofNullable(this.branchName) - .map(br -> project.findBranchByName(br) - .orElseThrow(() -> new RuntimeException(RESOURCE_BUNDLE.getString("error.not_found_branch")))) + Long branchId = Optional.ofNullable(project.getBranch()) .map(Branch::getId) .orElse(null); diff --git a/src/main/java/com/crowdin/cli/commands/actions/DownloadTargetsAction.java b/src/main/java/com/crowdin/cli/commands/actions/DownloadTargetsAction.java index 92dc4ac26..8d3a68db8 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/DownloadTargetsAction.java +++ b/src/main/java/com/crowdin/cli/commands/actions/DownloadTargetsAction.java @@ -21,7 +21,6 @@ import com.crowdin.client.translations.model.ExportProjectTranslationRequest; import lombok.NonNull; import org.apache.commons.io.FilenameUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import java.io.IOException; @@ -70,16 +69,13 @@ public void act(Outputter out, PropertiesWithTargets pb, ProjectClient client) { CrowdinProjectFull project = ConsoleSpinner .execute(out, "message.spinner.fetching_project_info", "error.collect_project_info", - this.noProgress, this.plainView, client::downloadFullProject); + this.noProgress, this.plainView, () -> client.downloadFullProject(branchName)); PlaceholderUtil placeholderUtil = new PlaceholderUtil( project.getSupportedLanguages(), project.getProjectLanguages(true), pb.getBasePath()); - if (StringUtils.isNotEmpty(branchName) && !project.findBranchByName(branchName).isPresent()) { - throw new RuntimeException(RESOURCE_BUNDLE.getString("error.not_found_branch")); - } - Optional branchId = project.findBranchByName(branchName).map(Branch::getId); + Optional branchId = Optional.ofNullable(project.getBranch()).map(Branch::getId); Map projectFiles = (branchId.isPresent() ? ProjectFilesUtils diff --git a/src/main/java/com/crowdin/cli/commands/actions/ListProjectAction.java b/src/main/java/com/crowdin/cli/commands/actions/ListProjectAction.java index 3c166fade..6bcc32d80 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/ListProjectAction.java +++ b/src/main/java/com/crowdin/cli/commands/actions/ListProjectAction.java @@ -8,9 +8,8 @@ import com.crowdin.cli.properties.ProjectProperties; import com.crowdin.cli.utils.console.ConsoleSpinner; import com.crowdin.client.sourcefiles.model.Branch; -import org.apache.commons.lang3.StringUtils; -import static com.crowdin.cli.BaseCli.RESOURCE_BUNDLE; +import java.util.Optional; class ListProjectAction implements NewAction { @@ -30,13 +29,9 @@ public ListProjectAction(boolean noProgress, String branchName, boolean treeView public void act(Outputter out, ProjectProperties pb, ProjectClient client) { CrowdinProjectFull project = ConsoleSpinner .execute(out, "message.spinner.fetching_project_info", "error.collect_project_info", - this.noProgress, this.plainView, client::downloadFullProject); + this.noProgress, this.plainView, () -> client.downloadFullProject(this.branchName)); - Long branchId = (StringUtils.isNotEmpty(this.branchName)) - ? project.findBranchByName(this.branchName) - .map(Branch::getId) - .orElseThrow(() -> new RuntimeException(RESOURCE_BUNDLE.getString("error.not_found_branch"))) - : null; + Long branchId = Optional.ofNullable(project.getBranch()).map(Branch::getId).orElse(null); (new DryrunProjectFiles(project.getFileInfos(), project.getDirectories(), project.getBranches(), branchId)).run(out, treeView, plainView); } diff --git a/src/main/java/com/crowdin/cli/commands/actions/ListSourcesAction.java b/src/main/java/com/crowdin/cli/commands/actions/ListSourcesAction.java index 436e9b855..34db9e919 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/ListSourcesAction.java +++ b/src/main/java/com/crowdin/cli/commands/actions/ListSourcesAction.java @@ -36,7 +36,7 @@ public ListSourcesAction(boolean deleteObsolete, String branchName, boolean noPr @Override public void act(Outputter out, PropertiesWithFiles pb, ProjectClient client) { CrowdinProject project = ConsoleSpinner.execute(out, "message.spinner.fetching_project_info", "error.collect_project_info", - this.noProgress, this.plainView, (deleteObsolete) ? client::downloadFullProject : client::downloadProjectWithLanguages); + this.noProgress, this.plainView, (deleteObsolete) ? () -> client.downloadFullProject(this.branchName) : client::downloadProjectWithLanguages); PlaceholderUtil placeholderUtil = new PlaceholderUtil(project.getSupportedLanguages(), project.getProjectLanguages(false), pb.getBasePath()); if (!project.isManagerAccess() && deleteObsolete) { @@ -50,9 +50,7 @@ public void act(Outputter out, PropertiesWithFiles pb, ProjectClient client) { if (deleteObsolete) { CrowdinProjectFull projectFull = (CrowdinProjectFull) project; - Long branchId = Optional.ofNullable(branchName) - .map(br -> projectFull.findBranchByName(br) - .orElseThrow(() -> new RuntimeException(RESOURCE_BUNDLE.getString("error.not_found_branch")))) + Long branchId = Optional.ofNullable(((CrowdinProjectFull) project).getBranch()) .map(Branch::getId) .orElse(null); (new DryrunObsoleteSources(pb, placeholderUtil, projectFull.getDirectories(branchId), projectFull.getFiles(branchId))).run(out, treeView, plainView); diff --git a/src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java b/src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java index 3ecc5a89b..048a88efd 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java +++ b/src/main/java/com/crowdin/cli/commands/actions/PreTranslateAction.java @@ -67,7 +67,7 @@ public PreTranslateAction( @Override public void act(Outputter out, PropertiesWithFiles properties, ProjectClient client) { CrowdinProjectFull project = ConsoleSpinner.execute(out, "message.spinner.fetching_project_info", "error.collect_project_info", - this.noProgress, this.plainView, client::downloadFullProject); + this.noProgress, this.plainView, () -> client.downloadFullProject(this.branchName)); List languages = this.prepareLanguageIds(project); List fileIds = this.prepareFileIds(out, properties, project); diff --git a/src/main/java/com/crowdin/cli/commands/actions/StringListAction.java b/src/main/java/com/crowdin/cli/commands/actions/StringListAction.java index b78e33a57..1497756d7 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/StringListAction.java +++ b/src/main/java/com/crowdin/cli/commands/actions/StringListAction.java @@ -43,11 +43,9 @@ public StringListAction(boolean noProgress, boolean isVerbose, String file, Stri @Override public void act(Outputter out, ProjectProperties pb, ProjectClient client) { CrowdinProjectFull project = ConsoleSpinner.execute(out, "message.spinner.fetching_project_info", "error.collect_project_info", - this.noProgress, false, client::downloadFullProject); + this.noProgress, false, () -> client.downloadFullProject(this.branchName)); - Long branchId = Optional.ofNullable(this.branchName) - .map(br -> project.findBranchByName(br) - .orElseThrow(() -> new RuntimeException(RESOURCE_BUNDLE.getString("error.not_found_branch")))) + Long branchId = Optional.ofNullable(project.getBranch()) .map(Branch::getId) .orElse(null); diff --git a/src/main/java/com/crowdin/cli/commands/actions/UploadTranslationsAction.java b/src/main/java/com/crowdin/cli/commands/actions/UploadTranslationsAction.java index 0c9e834f5..e49445282 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/UploadTranslationsAction.java +++ b/src/main/java/com/crowdin/cli/commands/actions/UploadTranslationsAction.java @@ -66,7 +66,7 @@ public UploadTranslationsAction( @Override public void act(Outputter out, PropertiesWithFiles pb, ProjectClient client) { CrowdinProjectFull project = ConsoleSpinner.execute(out, "message.spinner.fetching_project_info", "error.collect_project_info", - this.noProgress, this.plainView, client::downloadFullProject); + this.noProgress, this.plainView, () -> client.downloadFullProject(this.branchName)); if (!project.isManagerAccess()) { if (!plainView) { diff --git a/src/test/java/com/crowdin/cli/client/CrowdinProjectClientTest.java b/src/test/java/com/crowdin/cli/client/CrowdinProjectClientTest.java index 97ac0bd84..a5214694c 100644 --- a/src/test/java/com/crowdin/cli/client/CrowdinProjectClientTest.java +++ b/src/test/java/com/crowdin/cli/client/CrowdinProjectClientTest.java @@ -188,7 +188,7 @@ public void testDownloadProjectFull() { when(httpClientMock.get(eq(listBranchesUrl), any(), eq(BranchResponseList.class))) .thenReturn(branchesResponse); - CrowdinProject crowdinProject = client.downloadFullProject(); + CrowdinProject crowdinProject = client.downloadFullProject(null); assertEquals(1, crowdinProject.getProjectLanguages(false).size()); assertEquals(2, crowdinProject.getSupportedLanguages().size()); assertTrue(crowdinProject.findLanguageById("ua", false).isPresent()); diff --git a/src/test/java/com/crowdin/cli/commands/actions/DownloadActionTest.java b/src/test/java/com/crowdin/cli/commands/actions/DownloadActionTest.java index 76634e17c..162dc71d5 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/DownloadActionTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/DownloadActionTest.java @@ -65,7 +65,7 @@ public void testEmptyProject() throws ResponseException, IOException { PropertiesWithFiles pb = pbBuilder.build(); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())).build()); CrowdinTranslationCreateProjectBuildForm buildProjectTranslationRequest = new CrowdinTranslationCreateProjectBuildForm(); long buildId = 42L; @@ -90,7 +90,7 @@ public void testEmptyProject() throws ResponseException, IOException { new DownloadAction(files, false, null, false, null, false, false, false, false, false); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).startBuildingTranslation(eq(buildProjectTranslationRequest)); verify(client).downloadBuild(eq(buildId)); verifyNoMoreInteractions(client); @@ -112,7 +112,7 @@ public void testProjectOneFittingFile() throws ResponseException, IOException { project.addFile("first.po"); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.po", "gettext", 101L, null, null, "/%original_file_name%-CR-%locale%").build()); CrowdinTranslationCreateProjectBuildForm buildProjectTranslationRequest = new CrowdinTranslationCreateProjectBuildForm(); @@ -140,7 +140,7 @@ public void testProjectOneFittingFile() throws ResponseException, IOException { new DownloadAction(files, false, null, false, null, false, false, false, false, false); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).startBuildingTranslation(eq(buildProjectTranslationRequest)); verify(client).downloadBuild(eq(buildId)); verifyNoMoreInteractions(client); @@ -170,7 +170,7 @@ public void testProjectOneFittingFile_WithExportApprovedOnly_WithSkipUntranslate project.addFile("first.po"); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.po", "gettext", 101L, null, null, "/%original_file_name%-CR-%locale%").build()); CrowdinTranslationCreateProjectBuildForm buildProjectTranslationRequest = new CrowdinTranslationCreateProjectBuildForm() {{ @@ -201,7 +201,7 @@ public void testProjectOneFittingFile_WithExportApprovedOnly_WithSkipUntranslate new DownloadAction(files, false, null, false, null, false, false, false, false, false); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).startBuildingTranslation(eq(buildProjectTranslationRequest)); verify(client).downloadBuild(eq(buildId)); verifyNoMoreInteractions(client); @@ -229,7 +229,7 @@ public void testProjectDownloadWithKeepArchive() throws IOException { project.addFile("first.po"); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.po", "gettext", 101L, null, null, "/%original_file_name%-CR-%locale%").build()); CrowdinTranslationCreateProjectBuildForm buildProjectTranslationRequest = new CrowdinTranslationCreateProjectBuildForm(); @@ -257,7 +257,7 @@ public void testProjectDownloadWithKeepArchive() throws IOException { new DownloadAction(files, false, null, false, null, false, false, false, false, true); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).startBuildingTranslation(eq(buildProjectTranslationRequest)); verify(client).downloadBuild(eq(buildId)); verifyNoMoreInteractions(client); @@ -284,7 +284,7 @@ public void testProjectOneFittingFile_LongBuild() throws ResponseException, IOEx project.addFile("first.po"); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.po", "gettext", 101L, null, null, "/%original_file_name%-CR-%locale%").build()); CrowdinTranslationCreateProjectBuildForm buildProjectTranslationRequest = new CrowdinTranslationCreateProjectBuildForm(); @@ -316,7 +316,7 @@ public void testProjectOneFittingFile_LongBuild() throws ResponseException, IOEx new DownloadAction(files, false, null, false, null, false, false, false, false, false); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).startBuildingTranslation(eq(buildProjectTranslationRequest)); verify(client, times(3)).checkBuildingTranslation(eq(buildId)); verify(client).downloadBuild(eq(buildId)); @@ -345,7 +345,7 @@ public void testProjectOneFittingOneUnfittingFile_LongBuild() throws ResponseExc project.addFile("first.po"); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.po", "gettext", 101L, null, null, "/%original_file_name%-CR-%locale%") .addFile("second.po", "gettext", 102L, null, null, "/%original_file_name%-CR-%locale%") @@ -377,7 +377,7 @@ public void testProjectOneFittingOneUnfittingFile_LongBuild() throws ResponseExc new DownloadAction(files, false, null, false, null, false, false, false, false, false); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).startBuildingTranslation(eq(buildProjectTranslationRequest)); verify(client).downloadBuild(eq(buildId)); verifyNoMoreInteractions(client); @@ -405,7 +405,7 @@ public void testProjectOneFittingOneUnfittingOneWithUnfoundSourceFile_LongBuild( project.addFile("first.po"); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.po", "gettext", 101L, null, null, "/%original_file_name%-CR-%locale%") .addFile("second.po", "gettext", 102L, null, null, "/%original_file_name%-CR-%locale%") @@ -438,7 +438,7 @@ public void testProjectOneFittingOneUnfittingOneWithUnfoundSourceFile_LongBuild( new DownloadAction(files, false, null, false, null, false, true, false, false, false); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).startBuildingTranslation(eq(buildProjectTranslationRequest)); verify(client).downloadBuild(eq(buildId)); verifyNoMoreInteractions(client); @@ -466,7 +466,7 @@ public void testProjectOneFittingFile_WithLanguageMapping() throws ResponseExcep project.addFile("first.po"); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.po", "gettext", 101L, null, null, "/%original_file_name%-CR-%locale%") .addFile("second.po", "gettext", 102L, null, null, "/%original_file_name%-CR-%locale%") @@ -500,7 +500,7 @@ public void testProjectOneFittingFile_WithLanguageMapping() throws ResponseExcep new DownloadAction(files, false, null, false, null, false, true, false, false, false); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).startBuildingTranslation(eq(buildProjectTranslationRequest)); verify(client).downloadBuild(eq(buildId)); verifyNoMoreInteractions(client); @@ -528,7 +528,7 @@ public void testProjectOneFittingFile_FailBuild() throws ResponseException, IOEx project.addFile("first.po"); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.po", "gettext", 101L, null, null, "/%original_file_name%-CR-%locale%").build()); CrowdinTranslationCreateProjectBuildForm buildProjectTranslationRequest = new CrowdinTranslationCreateProjectBuildForm(); @@ -545,7 +545,7 @@ public void testProjectOneFittingFile_FailBuild() throws ResponseException, IOEx new DownloadAction(files, false, null, false, null, false, false, false, false, false); assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), pb, client)); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).startBuildingTranslation(eq(buildProjectTranslationRequest)); verifyNoMoreInteractions(client); @@ -562,7 +562,7 @@ public void testProjectOneFittingFile_failDownloadProject() throws ResponseExcep project.addFile("first.po"); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenThrow(new RuntimeException()); FilesInterface files = mock(FilesInterface.class); @@ -571,7 +571,7 @@ public void testProjectOneFittingFile_failDownloadProject() throws ResponseExcep new DownloadAction(files, false, null, false, null, false, false, false, false, false); assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), pb, client)); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verifyNoMoreInteractions(client); verifyNoMoreInteractions(files); @@ -587,7 +587,7 @@ public void testProjectOneFittingFile_failDeleteFile() throws ResponseException, project.addFile("first.po"); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.po", "gettext", 101L, null, null, "/%original_file_name%-CR-%locale%").build()); CrowdinTranslationCreateProjectBuildForm buildProjectTranslationRequest = new CrowdinTranslationCreateProjectBuildForm(); @@ -620,7 +620,7 @@ public void testProjectOneFittingFile_failDeleteFile() throws ResponseException, // assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), pb, client)); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).startBuildingTranslation(eq(buildProjectTranslationRequest)); verify(client).downloadBuild(eq(buildId)); verifyNoMoreInteractions(client); @@ -648,7 +648,7 @@ public void testProjectOneFittingFile_failDownloadingException() throws Response project.addFile("first.po"); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.po", "gettext", 101L, null, null, "/%original_file_name%-CR-%locale%").build()); CrowdinTranslationCreateProjectBuildForm buildProjectTranslationRequest = new CrowdinTranslationCreateProjectBuildForm(); @@ -664,7 +664,7 @@ public void testProjectOneFittingFile_failDownloadingException() throws Response new DownloadAction(files, false, null, false, null, false, false, false, false, false); assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), pb, client)); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).startBuildingTranslation(eq(buildProjectTranslationRequest)); verify(client).downloadBuild(eq(buildId)); verifyNoMoreInteractions(client); @@ -682,7 +682,7 @@ public void testProjectOneFittingFile_failWritingFile() throws ResponseException project.addFile("first.po"); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.po", "gettext", 101L, null, null, "/%original_file_name%-CR-%locale%").build()); CrowdinTranslationCreateProjectBuildForm buildProjectTranslationRequest = new CrowdinTranslationCreateProjectBuildForm(); @@ -702,7 +702,7 @@ public void testProjectOneFittingFile_failWritingFile() throws ResponseException new DownloadAction(files, false, null, false, null, false, false, false, false, false); assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), pb, client)); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).startBuildingTranslation(eq(buildProjectTranslationRequest)); verify(client).downloadBuild(eq(buildId)); verifyNoMoreInteractions(client); diff --git a/src/test/java/com/crowdin/cli/commands/actions/DownloadSourcesActionTest.java b/src/test/java/com/crowdin/cli/commands/actions/DownloadSourcesActionTest.java index d667d5b81..1b846b8b7 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/DownloadSourcesActionTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/DownloadSourcesActionTest.java @@ -51,7 +51,7 @@ public void testDest() throws IOException { .build(); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addDirectory("common", 201L, null, null) .addFile("strings.xml", "gettext", 101L, 201L, null, "/values-%two_letters_code%/%original_file_name%").build()); @@ -65,7 +65,7 @@ public void testDest() throws IOException { new DownloadSourcesAction(files, false, false, null, true, false, false); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).downloadFile(eq(101L)); verifyNoMoreInteractions(client); @@ -83,7 +83,7 @@ public void testDestAndUnaryAsterisk() throws IOException { .build(); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addDirectory("destination", 201L, null, null) .addFile("crowdin_sample_android.xml", "gettext", 101L, 201L, null, "/tests/tr-%locale%/%original_file_name%").build()); @@ -97,7 +97,7 @@ public void testDestAndUnaryAsterisk() throws IOException { new DownloadSourcesAction(files, false, false, null, true, false, false); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).downloadFile(eq(101L)); verifyNoMoreInteractions(client); @@ -117,7 +117,7 @@ public void testDifferentPatterns() throws IOException { .build(); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addDirectory("folder_1", 201L, null, null) .addDirectory("f1", 202L, 201L, null) @@ -153,7 +153,7 @@ public void testDifferentPatterns() throws IOException { new DownloadSourcesAction(files, false, false, null, true, false, false); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).downloadFile(eq(101L)); verify(client).downloadFile(eq(102L)); verify(client).downloadFile(eq(103L)); @@ -185,7 +185,7 @@ public void testWithPreserveHierarchyFalse() throws IOException { .build(); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addDirectory("f1", 201L, null, null) .addDirectory("folder_1", 202L, null, null) @@ -219,7 +219,7 @@ public void testWithPreserveHierarchyFalse() throws IOException { new DownloadSourcesAction(files, false, false, null, true, false, false); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).downloadFile(eq(101L)); verify(client).downloadFile(eq(102L)); verify(client).downloadFile(eq(103L)); @@ -253,7 +253,7 @@ public void testDryRun() { .build(); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addDirectory("common", 201L, null, null) .addFile("strings.xml", "gettext", 101L, 201L, null, "/values-%two_letters_code%/%original_file_name%").build()); @@ -270,7 +270,7 @@ public void testDryRun() { String outMessage1 = "✔️ Fetching project info\n"; String outMessage2 = "✔️ File @|bold 'common/strings.xml'|@\n"; - client.downloadFullProject(); + client.downloadFullProject(null); client.downloadFile(101L); assertTrue(outContent.toString().contains(outMessage1)); @@ -291,7 +291,7 @@ public void testReviewedOnly() throws IOException { .build(); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addDirectory("common", 201L, null, null) .addFile("strings.xml", "gettext", 101L, 201L, null, "/values-%two_letters_code%/%original_file_name%").build()); @@ -307,7 +307,7 @@ public void testReviewedOnly() throws IOException { String warnMessage = "⚠️ Operation is available only for Crowdin Enterprise\n"; - client.downloadFullProject(); + client.downloadFullProject(null); assertEquals(warnMessage, outContent.toString()); } } diff --git a/src/test/java/com/crowdin/cli/commands/actions/ListProjectActionTest.java b/src/test/java/com/crowdin/cli/commands/actions/ListProjectActionTest.java index b27a8083c..89ddd9f5d 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/ListProjectActionTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/ListProjectActionTest.java @@ -15,7 +15,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -45,31 +44,14 @@ public void testForServerInteraction() throws ResponseException { .minimalBuiltPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%") .setBasePath(project.getBasePath()); pb = pbBuilder.build(); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.po", "gettext", 101L, null, null).build()); action = new ListProjectAction(false, null, true, false); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); - verifyNoMoreInteractions(client); - } - - @Test - public void testForNonexistentBranch() throws ResponseException { - NewPropertiesWithFilesUtilBuilder pbBuilder = NewPropertiesWithFilesUtilBuilder - .minimalBuiltPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%") - .setBasePath(project.getBasePath()); - pb = pbBuilder.build(); - when(client.downloadFullProject()) - .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) - .addFile("first.po", "gettext", 101L, null, null).build()); - - action = new ListProjectAction(false, "nonexistentBranch", false, false); - assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), pb, client)); - - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verifyNoMoreInteractions(client); } @@ -79,7 +61,7 @@ public void testForExistentBranch() throws ResponseException { .minimalBuiltPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%") .setBasePath(project.getBasePath()); pb = pbBuilder.build(); - when(client.downloadFullProject()) + when(client.downloadFullProject("existentBranch")) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.po", "gettext", 101L, null, null) .addBranches(1L, "existentBranch").build()); @@ -87,7 +69,7 @@ public void testForExistentBranch() throws ResponseException { action = new ListProjectAction(false, "existentBranch", false, false); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject("existentBranch"); verifyNoMoreInteractions(client); } } diff --git a/src/test/java/com/crowdin/cli/commands/actions/StringEditActionTest.java b/src/test/java/com/crowdin/cli/commands/actions/StringEditActionTest.java index 793db924e..17dcd6c52 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/StringEditActionTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/StringEditActionTest.java @@ -51,7 +51,7 @@ public void testStringList( .minimalBuiltPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%") .setBasePath(Utils.PATH_SEPARATOR); pb = pbBuilder.build(); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.csv", "csv", 101L, null, null).build()); when(client.listSourceString(null, null, null, null, null)) @@ -118,7 +118,7 @@ public void testBothIdAndIdentifier_throws() throws ResponseException { .minimalBuiltPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%") .setBasePath(Utils.PATH_SEPARATOR); pb = pbBuilder.build(); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.csv", "csv", 101L, null, null).build()); when(client.listSourceString(null, null, null, null, null)) diff --git a/src/test/java/com/crowdin/cli/commands/actions/StringListActionTest.java b/src/test/java/com/crowdin/cli/commands/actions/StringListActionTest.java index 06ce18cc9..6b455ef57 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/StringListActionTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/StringListActionTest.java @@ -38,7 +38,7 @@ public void testStringList(String file, String filter) throws ResponseException .minimalBuiltPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%") .setBasePath(Utils.PATH_SEPARATOR); pb = pbBuilder.build(); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.csv", "csv", 101L, null, null).build()); when(client.listSourceString(101L, null, null, filter, null)) @@ -49,7 +49,7 @@ public void testStringList(String file, String filter) throws ResponseException action = new StringListAction(true, true, file, filter, null, null); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).listLabels(); if (file != null) { verify(client).listSourceString(101L, null, null, filter, null); @@ -73,13 +73,13 @@ public void testGetProjectThrows() throws ResponseException { .minimalBuiltPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%") .setBasePath(Utils.PATH_SEPARATOR); pb = pbBuilder.build(); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenThrow(new RuntimeException("Whoops")); action = new StringListAction(true, true, null, null, null, null); assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), pb, client)); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verifyNoMoreInteractions(client); } @@ -90,14 +90,14 @@ public void testFileNotExistThrows() throws ResponseException { .minimalBuiltPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%") .setBasePath(Utils.PATH_SEPARATOR); pb = pbBuilder.build(); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.csv", "csv", 101L, null, null).build()); action = new StringListAction(true, true, "nonexistent.csv", null, null, null); assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), pb, client)); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).listLabels(); verifyNoMoreInteractions(client); } diff --git a/src/test/java/com/crowdin/cli/commands/actions/UploadTranslationsActionTest.java b/src/test/java/com/crowdin/cli/commands/actions/UploadTranslationsActionTest.java index 55b661fe7..09f68a4ed 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/UploadTranslationsActionTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/UploadTranslationsActionTest.java @@ -49,7 +49,7 @@ public void testUploadOneOfTwoTranslation_Project() throws ResponseException { .setBasePath(project.getBasePath()); PropertiesWithFiles pb = pbBuilder.build(); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.po", "gettext", 301L, null, null).build()); when(client.uploadStorage(eq("first.po-CR-uk-UA"), any())) @@ -58,7 +58,7 @@ public void testUploadOneOfTwoTranslation_Project() throws ResponseException { NewAction action = new UploadTranslationsAction(false, null, null, false, false, false, false, false); assertDoesNotThrow(() -> action.act(Outputter.getDefault(), pb, client)); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).uploadStorage(eq("first.po-CR-uk-UA"), any()); UploadTranslationsRequest uploadTranslationRequest = new UploadTranslationsRequest() {{ setStorageId(1L); @@ -81,7 +81,7 @@ public void testUploadBothTranslation_Project() throws ResponseException { .setBasePath(project.getBasePath()); PropertiesWithFiles pb = pbBuilder.build(); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.po", "gettext", 301L, null, null).build()); when(client.uploadStorage(eq("first.po-CR-uk-UA"), any())) @@ -92,7 +92,7 @@ public void testUploadBothTranslation_Project() throws ResponseException { NewAction action = new UploadTranslationsAction(false, null, null, false, false, false, false, false); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).uploadStorage(eq("first.po-CR-uk-UA"), any()); verify(client).uploadStorage(eq("first.po-CR-ru-RU"), any()); UploadTranslationsRequest uploadTranslationRequest1 = new UploadTranslationsRequest() {{ @@ -123,13 +123,13 @@ public void testUploadOneOfTwoTranslation_EmptyProject() throws ResponseExceptio .setBasePath(project.getBasePath()); PropertiesWithFiles pb = pbBuilder.build(); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())).build()); NewAction action = new UploadTranslationsAction(false, null, null, false, false, false, false, false); assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), pb, client)); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verifyNoMoreInteractions(client); } @@ -143,7 +143,7 @@ public void testUploadSpreadsheetTranslation_Project() throws ResponseException PropertiesWithFiles pb = pbBuilder.build(); pb.getFiles().get(0).setScheme("identifier,source_phrase,context,uk,ru,fr"); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("first.csv", "csv", 301L, null, null).build()); when(client.uploadStorage(eq("first.csv-CR"), any())) @@ -152,7 +152,7 @@ public void testUploadSpreadsheetTranslation_Project() throws ResponseException NewAction action = new UploadTranslationsAction(false, null, null, false, false, false, false, false); action.act(Outputter.getDefault(), pb, client); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).uploadStorage(eq("first.csv-CR"), any()); UploadTranslationsRequest uploadTranslationRequest = new UploadTranslationsRequest() {{ setStorageId(1L); @@ -175,7 +175,7 @@ public void testUploadWithDest() throws ResponseException { .setBasePath(project.getBasePath()); PropertiesWithFiles pb = pbBuilder.build(); ProjectClient client = mock(ProjectClient.class); - when(client.downloadFullProject()) + when(client.downloadFullProject(null)) .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())) .addFile("second.po", "gettext", 301L, null, null).build()); when(client.uploadStorage(eq("first.po-CR-uk-UA"), any())) @@ -184,7 +184,7 @@ public void testUploadWithDest() throws ResponseException { NewAction action = new UploadTranslationsAction(false, null, null, false, false, false, false, false); assertDoesNotThrow(() -> action.act(Outputter.getDefault(), pb, client)); - verify(client).downloadFullProject(); + verify(client).downloadFullProject(null); verify(client).uploadStorage(eq("first.po-CR-uk-UA"), any()); UploadTranslationsRequest uploadTranslationRequest = new UploadTranslationsRequest() {{ setStorageId(1L);