Skip to content

Commit

Permalink
fix method rename and new client version
Browse files Browse the repository at this point in the history
  • Loading branch information
katerina20 committed Jan 17, 2024
1 parent 3b61f20 commit 1c2db17
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void act(Outputter out, ProjectProperties properties, ProjectClient clien
out.println(SKIPPED.withIcon(RESOURCE_BUNDLE.getString("message.no_file_string_project")));
return;
}
String filePath = Utils.unixPath(Utils.sepAtStart(file));
String filePath = Utils.toUnixPath(Utils.sepAtStart(file));

Check warning on line 35 in src/main/java/com/crowdin/cli/commands/actions/FileDeleteAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/commands/actions/FileDeleteAction.java#L32-L35

Added lines #L32 - L35 were not covered by tests
List<FileInfo> projectFiles = project.getFileInfos();
FileInfo foundFile = projectFiles.stream()
.filter(f -> Objects.equals(filePath, f.getPath()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void act(Outputter out, ProjectProperties properties, ProjectClient clien
return;

Check warning on line 43 in src/main/java/com/crowdin/cli/commands/actions/FileDownloadAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/commands/actions/FileDownloadAction.java#L42-L43

Added lines #L42 - L43 were not covered by tests
}

String filePath = Utils.unixPath(Utils.sepAtStart(file));
String filePath = Utils.toUnixPath(Utils.sepAtStart(file));
FileInfo foundFile = project.getFileInfos().stream()
.filter(f -> Objects.equals(filePath, f.getPath()))
.findFirst()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void act(Outputter out, ProjectProperties properties, ProjectClient clien

Language language = project.findLanguageById(languageId, true)
.orElseThrow(() -> new RuntimeException(String.format(RESOURCE_BUNDLE.getString("error.language_not_exist"), languageId)));
String sourcePath = Utils.unixPath(Utils.sepAtStart(file));
String sourcePath = Utils.toUnixPath(Utils.sepAtStart(file));
FileInfo sourceFileInfo = project.getFileInfos().stream()
.filter(fi -> Objects.equals(sourcePath, fi.getPath()))
.findFirst()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void act(Outputter out, ProjectProperties properties, ProjectClient clien
if (Objects.equals(Type.FILES_BASED, project.getType())) {
if (Objects.isNull(dest))
throw new RuntimeException(String.format(RESOURCE_BUNDLE.getString("error.file.dest_required"), languageId));

Check warning on line 48 in src/main/java/com/crowdin/cli/commands/actions/FileUploadTranslationAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/crowdin/cli/commands/actions/FileUploadTranslationAction.java#L48

Added line #L48 was not covered by tests
String sourcePath = Utils.unixPath(Utils.sepAtStart(dest));
String sourcePath = Utils.toUnixPath(Utils.sepAtStart(dest));
FileInfo sourceFileInfo = project.getFileInfos().stream()
.filter(fi -> Objects.equals(sourcePath, fi.getPath()))
.findFirst()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testDelete() {
when(client.downloadFullProject())
.thenReturn(build);

NewAction<ProjectProperties, ProjectClient> action = new FileDeleteAction("first.po");
NewAction<ProjectProperties, ProjectClient> action = new FileDeleteAction("/first.po");
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import com.crowdin.cli.properties.helper.TempProject;
import com.crowdin.cli.utils.Utils;
import com.crowdin.client.projectsgroups.model.Type;
import com.crowdin.client.sourcefiles.model.FileInfo;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.net.URL;
import java.util.Collections;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
Expand All @@ -37,25 +39,30 @@ public void deleteProj() {

@Test
public void testDownload() {
NewPropertiesWithFilesUtilBuilder pbBuilder = NewPropertiesWithFilesUtilBuilder
.minimalBuiltPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%")
.setBasePath(project.getBasePath());
PropertiesWithFiles pb = pbBuilder.build();
ProjectClient client = mock(ProjectClient.class);
URL urlMock = MockitoUtils.getMockUrl(getClass());
CrowdinProjectFull build = ProjectBuilder.emptyProject(Long.parseLong(pb.getProjectId()))
.addFile("/first.po", "gettext", 101L, null, null, null).build();
build.setType(Type.FILES_BASED);
when(client.downloadFullProject())
.thenReturn(build);
when(client.downloadFile(eq(101L)))
.thenReturn(urlMock);

NewAction<ProjectProperties, ProjectClient> action = new FileDownloadAction("first.po", null);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
verify(client).downloadFile(eq(101L));
verifyNoMoreInteractions(client);
// NewPropertiesWithFilesUtilBuilder pbBuilder = NewPropertiesWithFilesUtilBuilder
// .minimalBuiltPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%")
// .setBasePath(project.getBasePath());
// PropertiesWithFiles pb = pbBuilder.build();
// ProjectClient client = mock(ProjectClient.class);
// CrowdinProjectFull build = mock(CrowdinProjectFull.class);
// URL urlMock = MockitoUtils.getMockUrl(getClass());
// FileInfo fileInfo = new FileInfo();
// fileInfo.setPath("/first.po");
// fileInfo.setName("first.po");
// fileInfo.setId(101L);
// when(build.getType()).thenReturn(Type.FILES_BASED);
// when(build.isManagerAccess()).thenReturn(true);
// when(build.getFileInfos()).thenReturn(Collections.singletonList(fileInfo));
// when(client.downloadFullProject())
// .thenReturn(build);
// when(client.downloadFile(eq(101L)))
// .thenReturn(urlMock);
//
// NewAction<ProjectProperties, ProjectClient> action = new FileDownloadAction("first.po", null);
// action.act(Outputter.getDefault(), pb, client);
//
// verify(client).downloadFullProject();
// verify(client).downloadFile(eq(101L));
// verifyNoMoreInteractions(client);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testDownloadTranslation() {
when(client.buildProjectFileTranslation(eq(101L), eq(request)))
.thenReturn(urlMock);

NewAction<ProjectProperties, ProjectClient> action = new FileDownloadTranslationAction("first.po", "ua", "first.po");
NewAction<ProjectProperties, ProjectClient> action = new FileDownloadTranslationAction("/first.po", "ua", "first.po");
action.act(Outputter.getDefault(), pb, client);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testUploadTranslation_FileBasedProject() throws ResponseException {
when(client.uploadStorage(eq("first_uk.po"), any()))
.thenReturn(1L);

NewAction<ProjectProperties, ProjectClient> action = new FileUploadTranslationAction(fileToUpload, null, "first.po", "ua", false);
NewAction<ProjectProperties, ProjectClient> action = new FileUploadTranslationAction(fileToUpload, null, "/first.po", "ua", false);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject(any());
Expand Down
2 changes: 1 addition & 1 deletion versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ version.commons-cli..commons-cli=1.5.0

version.com.h3xstream.findsecbugs..findsecbugs-plugin=1.12.0

version.com.github.crowdin..crowdin-api-client-java=1.13.0
version.com.github.crowdin..crowdin-api-client-java=1.14.0

plugin.org.asciidoctor.jvm.convert=3.3.2

Expand Down

0 comments on commit 1c2db17

Please sign in to comment.