Skip to content

Commit

Permalink
#325 - ignore content segmentation option when its null (#539)
Browse files Browse the repository at this point in the history
  • Loading branch information
yzerk committed Apr 12, 2023
1 parent dce6b61 commit 9b9bf96
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/com/crowdin/cli/properties/FileBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PropertiesWithFiles, ProjectClient> 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!");
Expand Down

0 comments on commit 9b9bf96

Please sign in to comment.