From 9b9bf96be35cb12ef28fc0f4800c12cd0a85f645 Mon Sep 17 00:00:00 2001 From: yzerk Date: Mon, 13 Mar 2023 15:07:47 +0200 Subject: [PATCH] #325 - ignore content segmentation option when its null (#539) --- .../com/crowdin/cli/properties/FileBean.java | 2 +- .../actions/UploadSourcesActionTest.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/crowdin/cli/properties/FileBean.java b/src/main/java/com/crowdin/cli/properties/FileBean.java index 1dadac3ce..bd8d9629e 100755 --- a/src/main/java/com/crowdin/cli/properties/FileBean.java +++ b/src/main/java/com/crowdin/cli/properties/FileBean.java @@ -143,7 +143,7 @@ public void populateWithDefaultValues(FileBean bean) { //Translate content bean.setTranslateContent(bean.getTranslateContent() != null ? bean.getTranslateContent() : Boolean.TRUE); //Content segmentation - bean.setContentSegmentation(bean.getContentSegmentation() != null ? bean.getContentSegmentation() : Boolean.TRUE); + bean.setContentSegmentation(bean.getContentSegmentation()); //escape quotes if (bean.getEscapeQuotes() == null) { bean.setEscapeQuotes(3); diff --git a/src/test/java/com/crowdin/cli/commands/actions/UploadSourcesActionTest.java b/src/test/java/com/crowdin/cli/commands/actions/UploadSourcesActionTest.java index 1b704e9f9..8edc7ef1b 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/UploadSourcesActionTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/UploadSourcesActionTest.java @@ -86,6 +86,44 @@ public void testUploadOneSource_EmptyProject() throws ResponseException { verifyNoMoreInteractions(client); } + @Test + public void testUploadOneSourceWithNullContentSegmentation_EmptyProject() throws ResponseException { + project.addFile(Utils.normalizePath("first.po"), "Hello, World!"); + NewPropertiesWithFilesUtilBuilder pbBuilder = NewPropertiesWithFilesUtilBuilder + .minimalBuiltPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%") + .setBasePath(project.getBasePath()); + PropertiesWithFiles pb = pbBuilder.build(); + pb.getFiles().get(0).setContentSegmentation(null); + + ProjectClient client = mock(ProjectClient.class); + when(client.downloadFullProject()) + .thenReturn(ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId())).build()); + when(client.uploadStorage(eq("first.po"), any())) + .thenReturn(1L); + + NewAction action = new UploadSourcesAction(null, false, false, true, false, false); + action.act(Outputter.getDefault(), pb, client); + + verify(client).downloadFullProject(); + verify(client).listLabels(); + verify(client).uploadStorage(eq("first.po"), any()); + AddFileRequest addFileRequest = new AddFileRequest() {{ + setName("first.po"); + setStorageId(1L); + setImportOptions(new OtherFileImportOptions() {{ + setContentSegmentation(pb.getFiles().get(0).getContentSegmentation()); + }} + ); + setExportOptions(new PropertyFileExportOptions() {{ + setEscapeQuotes(pb.getFiles().get(0).getEscapeQuotes()); + setExportPattern(pb.getFiles().get(0).getTranslation().replaceAll("[\\\\/]+", "/")); + }} + ); + }}; + verify(client).addSource(eq(addFileRequest)); + verifyNoMoreInteractions(client); + } + @Test public void testUploadFewSourceWithDirectories_EmptyProject() throws ResponseException { project.addFile(Utils.normalizePath("first.po"), "Hello, World!");