From eae34274b1218b365da879d086408437c6b33023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20=C4=8Calfa?= Date: Sun, 6 Nov 2022 16:25:15 +0100 Subject: [PATCH 1/8] updating tests --- package-lock.json | 376 +++++++++++++++++- src/main/resources/crowdin.yml | 18 + .../functionality/PropertiesBuilderTest.java | 101 ++++- .../NewPropertiesWithTargetsUtilBuilder.java | 42 +- 4 files changed, 529 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7d61233e4..3a4eef469 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,8 +1,382 @@ { "name": "@crowdin/cli", "version": "3.9.0", - "lockfileVersion": 1, + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "name": "@crowdin/cli", + "version": "3.9.0", + "license": "MIT", + "dependencies": { + "njre": "^0.2.0", + "shelljs": "^0.8.4" + }, + "bin": { + "crowdin": "jdeploy-bundle/jdeploy.js" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/buffer-crc32": { + "version": "0.2.13", + "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", + "integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=", + "engines": { + "node": "*" + } + }, + "node_modules/chownr": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", + "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==" + }, + "node_modules/command-exists-promise": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/command-exists-promise/-/command-exists-promise-2.0.2.tgz", + "integrity": "sha512-T6PB6vdFrwnHXg/I0kivM3DqaCGZLjjYSOe0a5WgFKcz1sOnmOeIjnhQPXVXX3QjVbLyTJ85lJkX6lUpukTzaA==", + "engines": { + "node": ">=6" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "node_modules/fd-slicer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", + "integrity": "sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=", + "dependencies": { + "pend": "~1.2.0" + } + }, + "node_modules/fs-minipass": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.7.tgz", + "integrity": "sha512-GWSSJGFy4e9GUeCcbIkED+bgAoFyj7XF1mV8rma3QW4NIqX9Kyx79N/PF61H5udOV3aY1IaMLs6pGbH71nlCTA==", + "dependencies": { + "minipass": "^2.6.0" + } + }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "node_modules/function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, + "node_modules/glob": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", + "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "dependencies": { + "function-bind": "^1.1.1" + }, + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-core-module": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.8.1.tgz", + "integrity": "sha512-SdNCUs284hr40hFTFP6l0IfZ/RSrMXF3qgoRHd3/79unUTvrFO/JoXwkGm+5J/Oe3E/b5GsnG330uUNgRpu1PA==", + "dependencies": { + "has": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/minimist": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", + "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" + }, + "node_modules/minipass": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.9.0.tgz", + "integrity": "sha512-wxfUjg9WebH+CUDX/CdbRlh5SmfZiy/hpkxaRI16Y9W56Pa75sWgd/rvFilSgrauD9NyFymP/+JFV3KwzIsJeg==", + "dependencies": { + "safe-buffer": "^5.1.2", + "yallist": "^3.0.0" + } + }, + "node_modules/minizlib": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.3.3.tgz", + "integrity": "sha512-6ZYMOEnmVsdCeTJVE0W9ZD+pVnE8h9Hma/iOwwRDsdQoePpoX56/8B6z3P9VNwppJuBKNRuFDRNRqRWexT9G9Q==", + "dependencies": { + "minipass": "^2.9.0" + } + }, + "node_modules/mkdirp": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "dependencies": { + "minimist": "^1.2.5" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, + "node_modules/njre": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/njre/-/njre-0.2.0.tgz", + "integrity": "sha512-+Wq8R6VmjK+jI8a9NdzfU6Vh50r3tjsdvl5KJE1OyHeH8I/nx5Ptm12qpO3qNUbstXuZfBDgDL0qQZw9JyjhMw==", + "dependencies": { + "command-exists-promise": "^2.0.2", + "node-fetch": "^2.5.0", + "tar": "^4.4.8", + "yauzl": "^2.10.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/node-fetch": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" + }, + "node_modules/pend": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", + "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=" + }, + "node_modules/rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", + "dependencies": { + "resolve": "^1.1.6" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/resolve": { + "version": "1.21.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.21.0.tgz", + "integrity": "sha512-3wCbTpk5WJlyE4mSOtDLhqQmGFi0/TD9VPwmiolnk8U0wRgMEktqCXd3vy5buTO3tljvalNvKrjHEfrd2WpEKA==", + "dependencies": { + "is-core-module": "^2.8.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/shelljs": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", + "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", + "dependencies": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + }, + "bin": { + "shjs": "bin/shjs" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/tar": { + "version": "4.4.19", + "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.19.tgz", + "integrity": "sha512-a20gEsvHnWe0ygBY8JbxoM4w3SJdhc7ZAuxkLqh+nvNQN2IOt0B5lLgM490X5Hl8FF0dl0tOf2ewFYAlIFgzVA==", + "dependencies": { + "chownr": "^1.1.4", + "fs-minipass": "^1.2.7", + "minipass": "^2.9.0", + "minizlib": "^1.3.3", + "mkdirp": "^0.5.5", + "safe-buffer": "^5.2.1", + "yallist": "^3.1.1" + }, + "engines": { + "node": ">=4.5" + } + }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" + }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + }, + "node_modules/yallist": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", + "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==" + }, + "node_modules/yauzl": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", + "integrity": "sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=", + "dependencies": { + "buffer-crc32": "~0.2.3", + "fd-slicer": "~1.1.0" + } + } + }, "dependencies": { "balanced-match": { "version": "1.0.2", diff --git a/src/main/resources/crowdin.yml b/src/main/resources/crowdin.yml index 9dc11bc46..2079c1b42 100644 --- a/src/main/resources/crowdin.yml +++ b/src/main/resources/crowdin.yml @@ -124,4 +124,22 @@ files: [ # # "scheme" : "", } +] + +targets: [ + { + name: "android", + files: [ + { + file: "targets/%two_letters_code%/android.xml", + sources: [ + "file.xlsx" + ], + labels: [ + "mobile", + "ui" + ] + } + ] + } ] \ No newline at end of file diff --git a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java index addc476ef..4a133c155 100644 --- a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java +++ b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java @@ -1,10 +1,7 @@ package com.crowdin.cli.commands.functionality; import com.crowdin.cli.commands.Outputter; -import com.crowdin.cli.properties.ParamsWithFiles; -import com.crowdin.cli.properties.PropertiesWithFiles; -import com.crowdin.cli.properties.NewPropertiesWithFilesUtilBuilder; -import com.crowdin.cli.properties.PropertiesBuilders; +import com.crowdin.cli.properties.*; import com.crowdin.cli.properties.helper.TempProject; import com.crowdin.cli.utils.Utils; import org.junit.jupiter.api.AfterEach; @@ -15,8 +12,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class PropertiesBuilderTest { + public static final String TEST_API_TOKEN = "123abc456"; + public static final String TEST_BASE_URL = "https://crowdin.com"; + public static final String TEST_BASE_PATH = "."; private TempProject tempProject; @@ -55,7 +58,7 @@ public void testOk_Params_WithoutConfigFile() { } @Test - public void testOk_Params_WithConfigFile() { + public void FFtestOk_Params_WithConfigFile() { File configFile = new File("crowdin.yml"); String minimalConfigFileText = NewPropertiesWithFilesUtilBuilder .minimalPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%") @@ -95,4 +98,92 @@ public void testOkBasePath_Params_WithConfigFile() { assertEquals(tempProject.getBasePath() + "folder2" + Utils.PATH_SEPARATOR, pb.getBasePath()); } + + @Test + public void testBuildNoProperties() { + PropertiesBuilders pb = mock(PropertiesBuilders.class); + NoProperties np = mock(NoProperties.class); + when(pb.buildNoProperties()).thenReturn(np); + } + + + + @Test + public void testBuildBaseProperties() { + SettingsBean set = new SettingsBean(); + BaseProperties bp = new BaseProperties(); + String bpath = "."; + String url = "https://crowdin.com"; + String api = "123abc456"; + bp.setBasePath(bpath); + bp.setBaseUrl(url); + bp.setApiToken(api); + bp.setSettings(set); + + assertEquals(bp.getBasePath(), "."); + assertEquals(bp.getBaseUrl(), "https://crowdin.com"); + assertEquals(bp.getApiToken(), "123abc456"); + assertEquals(bp.getSettings(), set); + + } + @Test + public void testBasePropertiesWithNoValues(){ + BaseProperties bp = new BaseProperties(); + String bpath = ""; + String url = ""; + String api = ""; + bp.setBasePath(bpath); + bp.setBaseUrl(url); + bp.setApiToken(api); + + assertEquals(bp.getBasePath(), ""); + assertEquals(bp.getBaseUrl(), ""); + assertEquals(bp.getApiToken(), ""); + + } + + @Test + public void testProjectProperties(){ + ProjectParams params = new ProjectParams(){{ + setIdParam("123"); + setTokenParam("token"); + }}; + + ProjectProperties pp = propertiesBuilders.buildProjectProperties(out,any(),any(),params ); + String projectId = "123"; + pp.setProjectId(projectId); + + assertEquals(pp.getProjectId(), params.getIdParam()); + assertEquals(pp.getApiToken(), params.getTokenParam()); + + } + + @Test + public void testBuildNoTargets(){ + assertThrows(RuntimeException.class, () -> propertiesBuilders.buildPropertiesWithTargets(out, null, null, null)); + } + + @Test + public void testBuildNoConfigFileTargets() { + ParamsWithTargets okParams = new ParamsWithTargets(); + assertThrows(NullPointerException.class, () -> propertiesBuilders.buildPropertiesWithTargets(out, null, null, okParams)); + + } + @Test + public void testPropertiesWithTarget(){ + File configFile = new File("folder/crowdin.yml"); + String minimalConfigFileText = NewPropertiesWithTargetsUtilBuilder + .minimalBuilt().buildToString(); + configFile = tempProject.addFile(configFile.getPath(), minimalConfigFileText); + + ParamsWithTargets okParams = new ParamsWithTargets(); + okParams.setSkipTranslatedOnly(true); + + System.out.println("configText = " + minimalConfigFileText); + PropertiesWithTargets pb = propertiesBuilders.buildPropertiesWithTargets(out, configFile, null, okParams); + + assertEquals(pb.getTargets().size(), 1); + assertEquals(pb.getTargets().get(0).getName(), "android"); + assertEquals(pb.getProjectId(), "666"); + } } diff --git a/src/test/java/com/crowdin/cli/properties/NewPropertiesWithTargetsUtilBuilder.java b/src/test/java/com/crowdin/cli/properties/NewPropertiesWithTargetsUtilBuilder.java index 18528c2d6..e4b44ea18 100644 --- a/src/test/java/com/crowdin/cli/properties/NewPropertiesWithTargetsUtilBuilder.java +++ b/src/test/java/com/crowdin/cli/properties/NewPropertiesWithTargetsUtilBuilder.java @@ -1,5 +1,8 @@ package com.crowdin.cli.properties; +import java.util.ArrayList; +import java.util.List; + public class NewPropertiesWithTargetsUtilBuilder { public static final String TEST_API_TOKEN = "123abc456"; @@ -9,14 +12,19 @@ public class NewPropertiesWithTargetsUtilBuilder { private PropertiesWithTargets pb; public static NewPropertiesWithTargetsUtilBuilder minimalBuilt() { - return minimalBuilt(TEST_API_TOKEN, TEST_BASE_URL, TEST_BASE_PATH); + List targetBeans = new ArrayList(); + TargetBean bean = new TargetBean(); + bean.setName("android"); + targetBeans.add(bean); + return minimalBuilt(TEST_API_TOKEN, TEST_BASE_URL, TEST_BASE_PATH, targetBeans); } - public static NewPropertiesWithTargetsUtilBuilder minimalBuilt(String apiToken, String baseUrl, String basePath) { + public static NewPropertiesWithTargetsUtilBuilder minimalBuilt(String apiToken, String baseUrl, String basePath, List targets) { PropertiesWithTargets pb = new PropertiesWithTargets(); pb.setApiToken(apiToken); pb.setBaseUrl(baseUrl); pb.setBasePath(basePath); + pb.setTargets(targets); NewPropertiesWithTargetsUtilBuilder builder = new NewPropertiesWithTargetsUtilBuilder(); builder.pb = pb; return builder; @@ -30,4 +38,34 @@ public NewPropertiesWithTargetsUtilBuilder setApiToken(String apiToken) { public PropertiesWithTargets build() { return pb; } + + public String buildToString() { + StringBuilder sb = new StringBuilder(); + sb.append("\"project_id\": \"").append("666").append("\"\n"); + + if (pb.getApiToken() != null) { + sb.append("\"api_token\": \"").append(pb.getApiToken()).append("\"\n"); + } + if (pb.getBasePath() != null) { + sb.append("\"base_path\": \"").append(pb.getBasePath().replaceAll("\\\\", "\\\\\\\\")).append("\"\n"); + } + if (pb.getBaseUrl() != null) { + sb.append("\"base_url\": \"").append(pb.getBaseUrl()).append("\"\n"); + } + if (pb.getTargets() != null && !pb.getTargets().isEmpty()) { + sb.append("targets: [\n"); + for (TargetBean tb : pb.getTargets()) { + sb.append("{\n"); + if (tb.getName() != null) { + sb.append("\"name\": \"").append(tb.getName().replaceAll("\\\\", "\\\\\\\\")).append("\",\n"); + } +// if (tb.getFiles() != null) { +// sb.append("\"translation\": \"").append(tb.getFiles().replaceAll("\\\\", "\\\\\\\\")).append("\",\n"); +// } + sb.append("},\n"); + } + sb.append("]"); + } + return sb.toString(); + } } From d7e174f9927dc9955a60101b1d44ec8d7245df19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20=C4=8Calfa?= Date: Sun, 6 Nov 2022 17:17:56 +0100 Subject: [PATCH 2/8] change from any() to null --- .../cli/commands/functionality/PropertiesBuilderTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java index 4a133c155..5544e3d04 100644 --- a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java +++ b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java @@ -12,7 +12,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -149,7 +148,7 @@ public void testProjectProperties(){ setTokenParam("token"); }}; - ProjectProperties pp = propertiesBuilders.buildProjectProperties(out,any(),any(),params ); + ProjectProperties pp = propertiesBuilders.buildProjectProperties(out,null,null,params ); String projectId = "123"; pp.setProjectId(projectId); From d9f3e6f8deb186b40ee88ea07f8c19afea3186ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20=C4=8Calfa?= Date: Mon, 7 Nov 2022 09:00:25 +0100 Subject: [PATCH 3/8] package-lock.json and crowdin.yml revert, make new crowdinTest.yml for tagerts test, deleting extra lines, --- package-lock.json | 2 +- src/main/resources/crowdin.yml | 18 --- src/main/resources/messages/crowdinTest.yml | 145 ++++++++++++++++++ .../functionality/PropertiesBuilderTest.java | 10 +- .../NewPropertiesWithTargetsUtilBuilder.java | 3 - 5 files changed, 149 insertions(+), 29 deletions(-) create mode 100644 src/main/resources/messages/crowdinTest.yml diff --git a/package-lock.json b/package-lock.json index 3a4eef469..54fd91d45 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,7 +1,7 @@ { "name": "@crowdin/cli", "version": "3.9.0", - "lockfileVersion": 2, + "lockfileVersion": 1, "requires": true, "packages": { "": { diff --git a/src/main/resources/crowdin.yml b/src/main/resources/crowdin.yml index 2079c1b42..9dc11bc46 100644 --- a/src/main/resources/crowdin.yml +++ b/src/main/resources/crowdin.yml @@ -124,22 +124,4 @@ files: [ # # "scheme" : "", } -] - -targets: [ - { - name: "android", - files: [ - { - file: "targets/%two_letters_code%/android.xml", - sources: [ - "file.xlsx" - ], - labels: [ - "mobile", - "ui" - ] - } - ] - } ] \ No newline at end of file diff --git a/src/main/resources/messages/crowdinTest.yml b/src/main/resources/messages/crowdinTest.yml new file mode 100644 index 000000000..4d4abafb9 --- /dev/null +++ b/src/main/resources/messages/crowdinTest.yml @@ -0,0 +1,145 @@ +# +# Your Crowdin credentials +# +"project_id" : "" +"api_token" : "" +"base_path" : "" +"base_url" : "" + +# +# Choose file structure in Crowdin +# e.g. true or false +# +"preserve_hierarchy": true + +# +# Files configuration +# +files: [ + { + # + # Source files filter + # e.g. "/resources/en/*.json" + # + "source" : "", + + # + # Where translations will be placed + # e.g. "/resources/%two_letters_code%/%original_file_name%" + # + "translation" : "", + + # + # Files or directories for ignore + # e.g. ["/**/?.txt", "/**/[0-9].txt", "/**/*\?*.txt"] + # + #"ignore" : [], + + # + # The dest allows you to specify a file name in Crowdin + # e.g. "/messages.json" + # + #"dest" : "", + + # + # File type + # e.g. "json" + # + #"type" : "", + + # + # The parameter "update_option" is optional. If it is not set, after the files update the translations for changed strings will be removed. Use to fix typos and for minor changes in the source strings + # e.g. "update_as_unapproved" or "update_without_changes" + # + #"update_option" : "", + + # + # Start block (for XML only) + # + + # + # Defines whether to translate tags attributes. + # e.g. 0 or 1 (Default is 1) + # + # "translate_attributes" : 1, + + # + # Defines whether to translate texts placed inside the tags. + # e.g. 0 or 1 (Default is 1) + # + # "translate_content" : 1, + + # + # This is an array of strings, where each item is the XPaths to DOM element that should be imported + # e.g. ["/content/text", "/content/text[@value]"] + # + # "translatable_elements" : [], + + # + # Defines whether to split long texts into smaller text segments + # e.g. 0 or 1 (Default is 1) + # + # "content_segmentation" : 1, + + # + # End block (for XML only) + # + + # + # Start .properties block + # + + # + # Defines whether single quote should be escaped by another single quote or backslash in exported translations + # e.g. 0 or 1 or 2 or 3 (Default is 3) + # 0 - do not escape single quote; + # 1 - escape single quote by another single quote; + # 2 - escape single quote by backslash; + # 3 - escape single quote by another single quote only in strings containing variables ( {0} ). + # + # "escape_quotes" : 3, + + # + # Defines whether any special characters (=, :, ! and #) should be escaped by backslash in exported translations. + # e.g. 0 or 1 (Default is 0) + # 0 - do not escape special characters + # 1 - escape special characters by a backslash + # + # "escape_special_characters": 0 + # + + # + # End .properties block + # + + # + # Does the first line contain header? + # e.g. true or false + # + #"first_line_contains_header" : true, + + # + # for spreadsheets + # e.g. "identifier,source_phrase,context,uk,ru,fr" + # + # "scheme" : "", + } +] + +targets: [ + { + name: "android", + files: [ + { + file: "targets/%two_letters_code%/android.xml", + sources: [ + "file.xlsx" + ], + labels: [ + "mobile", + "ui" + ] + } + ] + } +] \ No newline at end of file diff --git a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java index 5544e3d04..0b0f102fa 100644 --- a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java +++ b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java @@ -105,8 +105,6 @@ public void testBuildNoProperties() { when(pb.buildNoProperties()).thenReturn(np); } - - @Test public void testBuildBaseProperties() { SettingsBean set = new SettingsBean(); @@ -123,8 +121,8 @@ public void testBuildBaseProperties() { assertEquals(bp.getBaseUrl(), "https://crowdin.com"); assertEquals(bp.getApiToken(), "123abc456"); assertEquals(bp.getSettings(), set); - } + @Test public void testBasePropertiesWithNoValues(){ BaseProperties bp = new BaseProperties(); @@ -138,7 +136,6 @@ public void testBasePropertiesWithNoValues(){ assertEquals(bp.getBasePath(), ""); assertEquals(bp.getBaseUrl(), ""); assertEquals(bp.getApiToken(), ""); - } @Test @@ -154,7 +151,6 @@ public void testProjectProperties(){ assertEquals(pp.getProjectId(), params.getIdParam()); assertEquals(pp.getApiToken(), params.getTokenParam()); - } @Test @@ -166,11 +162,11 @@ public void testBuildNoTargets(){ public void testBuildNoConfigFileTargets() { ParamsWithTargets okParams = new ParamsWithTargets(); assertThrows(NullPointerException.class, () -> propertiesBuilders.buildPropertiesWithTargets(out, null, null, okParams)); - } + @Test public void testPropertiesWithTarget(){ - File configFile = new File("folder/crowdin.yml"); + File configFile = new File("folder/crowdinTest.yml"); String minimalConfigFileText = NewPropertiesWithTargetsUtilBuilder .minimalBuilt().buildToString(); configFile = tempProject.addFile(configFile.getPath(), minimalConfigFileText); diff --git a/src/test/java/com/crowdin/cli/properties/NewPropertiesWithTargetsUtilBuilder.java b/src/test/java/com/crowdin/cli/properties/NewPropertiesWithTargetsUtilBuilder.java index e4b44ea18..96076c71a 100644 --- a/src/test/java/com/crowdin/cli/properties/NewPropertiesWithTargetsUtilBuilder.java +++ b/src/test/java/com/crowdin/cli/properties/NewPropertiesWithTargetsUtilBuilder.java @@ -59,9 +59,6 @@ public String buildToString() { if (tb.getName() != null) { sb.append("\"name\": \"").append(tb.getName().replaceAll("\\\\", "\\\\\\\\")).append("\",\n"); } -// if (tb.getFiles() != null) { -// sb.append("\"translation\": \"").append(tb.getFiles().replaceAll("\\\\", "\\\\\\\\")).append("\",\n"); -// } sb.append("},\n"); } sb.append("]"); From a5c605013af2cba756e25aa2288edee345d1cbdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20=C4=8Calfa?= Date: Mon, 7 Nov 2022 09:31:07 +0100 Subject: [PATCH 4/8] change location of crowdinTest.yml to test folder, and rollback-package.json --- package-lock.json | 376 +----------------- .../resources}/crowdinTest.yml | 0 2 files changed, 1 insertion(+), 375 deletions(-) rename src/{main/resources/messages => test/resources}/crowdinTest.yml (100%) diff --git a/package-lock.json b/package-lock.json index 54fd91d45..de8a4ffb3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3,380 +3,6 @@ "version": "3.9.0", "lockfileVersion": 1, "requires": true, - "packages": { - "": { - "name": "@crowdin/cli", - "version": "3.9.0", - "license": "MIT", - "dependencies": { - "njre": "^0.2.0", - "shelljs": "^0.8.4" - }, - "bin": { - "crowdin": "jdeploy-bundle/jdeploy.js" - } - }, - "node_modules/balanced-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" - }, - "node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/buffer-crc32": { - "version": "0.2.13", - "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", - "integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=", - "engines": { - "node": "*" - } - }, - "node_modules/chownr": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.4.tgz", - "integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==" - }, - "node_modules/command-exists-promise": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/command-exists-promise/-/command-exists-promise-2.0.2.tgz", - "integrity": "sha512-T6PB6vdFrwnHXg/I0kivM3DqaCGZLjjYSOe0a5WgFKcz1sOnmOeIjnhQPXVXX3QjVbLyTJ85lJkX6lUpukTzaA==", - "engines": { - "node": ">=6" - } - }, - "node_modules/concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" - }, - "node_modules/fd-slicer": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", - "integrity": "sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=", - "dependencies": { - "pend": "~1.2.0" - } - }, - "node_modules/fs-minipass": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.7.tgz", - "integrity": "sha512-GWSSJGFy4e9GUeCcbIkED+bgAoFyj7XF1mV8rma3QW4NIqX9Kyx79N/PF61H5udOV3aY1IaMLs6pGbH71nlCTA==", - "dependencies": { - "minipass": "^2.6.0" - } - }, - "node_modules/fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" - }, - "node_modules/function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" - }, - "node_modules/glob": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", - "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/has": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", - "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", - "dependencies": { - "function-bind": "^1.1.1" - }, - "engines": { - "node": ">= 0.4.0" - } - }, - "node_modules/inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dependencies": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" - }, - "node_modules/interpret": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", - "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", - "engines": { - "node": ">= 0.10" - } - }, - "node_modules/is-core-module": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.8.1.tgz", - "integrity": "sha512-SdNCUs284hr40hFTFP6l0IfZ/RSrMXF3qgoRHd3/79unUTvrFO/JoXwkGm+5J/Oe3E/b5GsnG330uUNgRpu1PA==", - "dependencies": { - "has": "^1.0.3" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, - "node_modules/minimist": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", - "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" - }, - "node_modules/minipass": { - "version": "2.9.0", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.9.0.tgz", - "integrity": "sha512-wxfUjg9WebH+CUDX/CdbRlh5SmfZiy/hpkxaRI16Y9W56Pa75sWgd/rvFilSgrauD9NyFymP/+JFV3KwzIsJeg==", - "dependencies": { - "safe-buffer": "^5.1.2", - "yallist": "^3.0.0" - } - }, - "node_modules/minizlib": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.3.3.tgz", - "integrity": "sha512-6ZYMOEnmVsdCeTJVE0W9ZD+pVnE8h9Hma/iOwwRDsdQoePpoX56/8B6z3P9VNwppJuBKNRuFDRNRqRWexT9G9Q==", - "dependencies": { - "minipass": "^2.9.0" - } - }, - "node_modules/mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", - "dependencies": { - "minimist": "^1.2.5" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, - "node_modules/njre": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/njre/-/njre-0.2.0.tgz", - "integrity": "sha512-+Wq8R6VmjK+jI8a9NdzfU6Vh50r3tjsdvl5KJE1OyHeH8I/nx5Ptm12qpO3qNUbstXuZfBDgDL0qQZw9JyjhMw==", - "dependencies": { - "command-exists-promise": "^2.0.2", - "node-fetch": "^2.5.0", - "tar": "^4.4.8", - "yauzl": "^2.10.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dependencies": { - "wrappy": "1" - } - }, - "node_modules/path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/path-parse": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", - "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" - }, - "node_modules/pend": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", - "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=" - }, - "node_modules/rechoir": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", - "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", - "dependencies": { - "resolve": "^1.1.6" - }, - "engines": { - "node": ">= 0.10" - } - }, - "node_modules/resolve": { - "version": "1.21.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.21.0.tgz", - "integrity": "sha512-3wCbTpk5WJlyE4mSOtDLhqQmGFi0/TD9VPwmiolnk8U0wRgMEktqCXd3vy5buTO3tljvalNvKrjHEfrd2WpEKA==", - "dependencies": { - "is-core-module": "^2.8.0", - "path-parse": "^1.0.7", - "supports-preserve-symlinks-flag": "^1.0.0" - }, - "bin": { - "resolve": "bin/resolve" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ] - }, - "node_modules/shelljs": { - "version": "0.8.5", - "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", - "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", - "dependencies": { - "glob": "^7.0.0", - "interpret": "^1.0.0", - "rechoir": "^0.6.2" - }, - "bin": { - "shjs": "bin/shjs" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/supports-preserve-symlinks-flag": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", - "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/tar": { - "version": "4.4.19", - "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.19.tgz", - "integrity": "sha512-a20gEsvHnWe0ygBY8JbxoM4w3SJdhc7ZAuxkLqh+nvNQN2IOt0B5lLgM490X5Hl8FF0dl0tOf2ewFYAlIFgzVA==", - "dependencies": { - "chownr": "^1.1.4", - "fs-minipass": "^1.2.7", - "minipass": "^2.9.0", - "minizlib": "^1.3.3", - "mkdirp": "^0.5.5", - "safe-buffer": "^5.2.1", - "yallist": "^3.1.1" - }, - "engines": { - "node": ">=4.5" - } - }, - "node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=" - }, - "node_modules/webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=" - }, - "node_modules/whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=", - "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" - }, - "node_modules/yallist": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", - "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==" - }, - "node_modules/yauzl": { - "version": "2.10.0", - "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", - "integrity": "sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=", - "dependencies": { - "buffer-crc32": "~0.2.3", - "fd-slicer": "~1.1.0" - } - } - }, "dependencies": { "balanced-match": { "version": "1.0.2", @@ -657,4 +283,4 @@ } } } -} +} \ No newline at end of file diff --git a/src/main/resources/messages/crowdinTest.yml b/src/test/resources/crowdinTest.yml similarity index 100% rename from src/main/resources/messages/crowdinTest.yml rename to src/test/resources/crowdinTest.yml From 5ace7bf99ecb42f1cfd28c9bac953bea0cdaaf88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20=C4=8Calfa?= Date: Mon, 7 Nov 2022 09:49:46 +0100 Subject: [PATCH 5/8] minor changes in formatting --- .../functionality/PropertiesBuilderTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java index 0b0f102fa..520db8489 100644 --- a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java +++ b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java @@ -57,7 +57,7 @@ public void testOk_Params_WithoutConfigFile() { } @Test - public void FFtestOk_Params_WithConfigFile() { + public void testOk_Params_WithConfigFile() { File configFile = new File("crowdin.yml"); String minimalConfigFileText = NewPropertiesWithFilesUtilBuilder .minimalPropertiesBean("*", Utils.PATH_SEPARATOR + "%original_file_name%-CR-%locale%") @@ -124,7 +124,7 @@ public void testBuildBaseProperties() { } @Test - public void testBasePropertiesWithNoValues(){ + public void testBasePropertiesWithNoValues() { BaseProperties bp = new BaseProperties(); String bpath = ""; String url = ""; @@ -139,13 +139,13 @@ public void testBasePropertiesWithNoValues(){ } @Test - public void testProjectProperties(){ + public void testProjectProperties() { ProjectParams params = new ProjectParams(){{ setIdParam("123"); setTokenParam("token"); }}; - ProjectProperties pp = propertiesBuilders.buildProjectProperties(out,null,null,params ); + ProjectProperties pp = propertiesBuilders.buildProjectProperties(out, null, null, params); String projectId = "123"; pp.setProjectId(projectId); @@ -154,7 +154,7 @@ public void testProjectProperties(){ } @Test - public void testBuildNoTargets(){ + public void testBuildNoTargets() { assertThrows(RuntimeException.class, () -> propertiesBuilders.buildPropertiesWithTargets(out, null, null, null)); } @@ -165,7 +165,7 @@ public void testBuildNoConfigFileTargets() { } @Test - public void testPropertiesWithTarget(){ + public void testPropertiesWithTarget() { File configFile = new File("folder/crowdinTest.yml"); String minimalConfigFileText = NewPropertiesWithTargetsUtilBuilder .minimalBuilt().buildToString(); From 7db8cfa8a2e5508bce3d1d7a7c86c4d9407dcb5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20=C4=8Calfa?= Date: Wed, 23 Nov 2022 19:35:13 +0100 Subject: [PATCH 6/8] making more tests for better coverage --- .../functionality/PropertiesBuilderTest.java | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java index 520db8489..619c5da1b 100644 --- a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java +++ b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java @@ -104,6 +104,97 @@ public void testBuildNoProperties() { NoProperties np = mock(NoProperties.class); when(pb.buildNoProperties()).thenReturn(np); } + @Test + public void testMockPropBuildersWithTargets(){ + PropertiesBuilders pb = mock(PropertiesBuilders.class); + when(pb.buildPropertiesWithTargets(null,null,null,null)).thenThrow(NullPointerException.class); + } + @Test + public void testMockPropWithTargets(){ + PropertiesWithTargets pt = mock(PropertiesWithTargets.class); + when(pt.getTargets().isEmpty()).thenThrow(NullPointerException.class); + } + + @Test + public void testMockBasePropUrl(){ + BaseProperties bp = mock(BaseProperties.class); + bp.setBaseUrl("https://crowdin.com"); + String url = "https://crowdin.com"; + when(bp.getBaseUrl()).thenReturn(url); + } + + @Test + public void testMockBasePropPath(){ + BaseProperties bp = mock(BaseProperties.class); + bp.setBasePath("./path"); + String path = "./path"; + when(bp.getBasePath()).thenReturn(path); + } + + @Test + public void testMockBasePropApiToken(){ + BaseProperties bp = mock(BaseProperties.class); + bp.setApiToken("123Token"); + String token = "123Token"; + when(bp.getApiToken()).thenReturn(token); + } + + @Test + public void testMockProjectPropToken(){ + ProjectProperties pp = mock(ProjectProperties.class); + pp.setApiToken("123Token"); + String token = "123Token"; + when(pp.getApiToken()).thenReturn(token); + } + + @Test + public void testMockProjectPropPath(){ + ProjectProperties pp = mock(ProjectProperties.class); + pp.setBasePath("./path"); + String path = "./path"; + when(pp.getBasePath()).thenReturn(path); + } + + @Test + public void testMockProjectPropUrl(){ + ProjectProperties pp = mock(ProjectProperties.class); + pp.setBaseUrl("https://crowdin.com"); + String url = "https://crowdin.com"; + when(pp.getBaseUrl()).thenReturn(url); + } + + @Test + public void testMockPropBuilderBasePropUrl(){ + PropertiesBuilders pb = mock(PropertiesBuilders.class); + File configFile = new File("folder/crowdinTest.yml"); + String minimalConfigFileText = NewPropertiesWithTargetsUtilBuilder + .minimalBuilt().buildToString(); + configFile = tempProject.addFile(configFile.getPath(), minimalConfigFileText); + + ParamsWithTargets okParams = new ParamsWithTargets(); + okParams.setBaseUrlParam("https://crowdin.com"); + + BaseProperties bp = mock(BaseProperties.class); + pb.buildBaseProperties(out, configFile,null, okParams); + + when(bp.getBaseUrl()).thenReturn( "https://crowdin.com"); + } + @Test + public void testMockPropBuilderBasePropIdParam(){ + PropertiesBuilders pb = mock(PropertiesBuilders.class); + File configFile = new File("folder/crowdinTest.yml"); + String minimalConfigFileText = NewPropertiesWithTargetsUtilBuilder + .minimalBuilt().buildToString(); + configFile = tempProject.addFile(configFile.getPath(), minimalConfigFileText); + + ParamsWithTargets okParams = new ParamsWithTargets(); + okParams.setIdParam("123"); + + BaseProperties bp = mock(BaseProperties.class); + pb.buildBaseProperties(out, configFile,null, okParams); + + when(bp.getApiToken()).thenReturn( "123"); + } @Test public void testBuildBaseProperties() { From dd4811b26291bc71a12f4dec0fc9afd6571fb4a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20=C4=8Calfa?= Date: Wed, 23 Nov 2022 19:45:16 +0100 Subject: [PATCH 7/8] making more tests for better coverage --- .../functionality/PropertiesBuilderTest.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java index 520db8489..fa90f3519 100644 --- a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java +++ b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java @@ -181,4 +181,96 @@ public void testPropertiesWithTarget() { assertEquals(pb.getTargets().get(0).getName(), "android"); assertEquals(pb.getProjectId(), "666"); } + + @Test + public void testMockPropBuildersWithTargets(){ + PropertiesBuilders pb = mock(PropertiesBuilders.class); + when(pb.buildPropertiesWithTargets(null,null,null,null)).thenThrow(NullPointerException.class); + } + @Test + public void testMockPropWithTargets(){ + PropertiesWithTargets pt = mock(PropertiesWithTargets.class); + when(pt.getTargets().isEmpty()).thenThrow(NullPointerException.class); + } + + @Test + public void testMockBasePropUrl(){ + BaseProperties bp = mock(BaseProperties.class); + bp.setBaseUrl("https://crowdin.com"); + String url = "https://crowdin.com"; + when(bp.getBaseUrl()).thenReturn(url); + } + + @Test + public void testMockBasePropPath(){ + BaseProperties bp = mock(BaseProperties.class); + bp.setBasePath("./path"); + String path = "./path"; + when(bp.getBasePath()).thenReturn(path); + } + + @Test + public void testMockBasePropApiToken(){ + BaseProperties bp = mock(BaseProperties.class); + bp.setApiToken("123Token"); + String token = "123Token"; + when(bp.getApiToken()).thenReturn(token); + } + + @Test + public void testMockProjectPropToken(){ + ProjectProperties pp = mock(ProjectProperties.class); + pp.setApiToken("123Token"); + String token = "123Token"; + when(pp.getApiToken()).thenReturn(token); + } + + @Test + public void testMockProjectPropPath(){ + ProjectProperties pp = mock(ProjectProperties.class); + pp.setBasePath("./path"); + String path = "./path"; + when(pp.getBasePath()).thenReturn(path); + } + + @Test + public void testMockProjectPropUrl(){ + ProjectProperties pp = mock(ProjectProperties.class); + pp.setBaseUrl("https://crowdin.com"); + String url = "https://crowdin.com"; + when(pp.getBaseUrl()).thenReturn(url); + } + + @Test + public void testMockPropBuilderBasePropUrl(){ + PropertiesBuilders pb = mock(PropertiesBuilders.class); + File configFile = new File("folder/crowdinTest.yml"); + String minimalConfigFileText = NewPropertiesWithTargetsUtilBuilder + .minimalBuilt().buildToString(); + configFile = tempProject.addFile(configFile.getPath(), minimalConfigFileText); + + ParamsWithTargets okParams = new ParamsWithTargets(); + okParams.setBaseUrlParam("https://crowdin.com"); + + BaseProperties bp = mock(BaseProperties.class); + pb.buildBaseProperties(out, configFile,null, okParams); + + when(bp.getBaseUrl()).thenReturn( "https://crowdin.com"); + } + @Test + public void testMockPropBuilderBasePropIdParam(){ + PropertiesBuilders pb = mock(PropertiesBuilders.class); + File configFile = new File("folder/crowdinTest.yml"); + String minimalConfigFileText = NewPropertiesWithTargetsUtilBuilder + .minimalBuilt().buildToString(); + configFile = tempProject.addFile(configFile.getPath(), minimalConfigFileText); + + ParamsWithTargets okParams = new ParamsWithTargets(); + okParams.setIdParam("123"); + + BaseProperties bp = mock(BaseProperties.class); + pb.buildBaseProperties(out, configFile,null, okParams); + + when(bp.getApiToken()).thenReturn( "123"); + } } From b491143f62732247ff0695dbdff416c75d34dd07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrej=20=C4=8Calfa?= Date: Thu, 24 Nov 2022 17:41:38 +0100 Subject: [PATCH 8/8] minor changes in formatting code --- .../functionality/PropertiesBuilderTest.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java index fa90f3519..72b6a27fc 100644 --- a/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java +++ b/src/test/java/com/crowdin/cli/commands/functionality/PropertiesBuilderTest.java @@ -183,18 +183,18 @@ public void testPropertiesWithTarget() { } @Test - public void testMockPropBuildersWithTargets(){ + public void testMockPropBuildersWithTargets() { PropertiesBuilders pb = mock(PropertiesBuilders.class); when(pb.buildPropertiesWithTargets(null,null,null,null)).thenThrow(NullPointerException.class); } @Test - public void testMockPropWithTargets(){ + public void testMockPropWithTargets() { PropertiesWithTargets pt = mock(PropertiesWithTargets.class); when(pt.getTargets().isEmpty()).thenThrow(NullPointerException.class); } @Test - public void testMockBasePropUrl(){ + public void testMockBasePropUrl() { BaseProperties bp = mock(BaseProperties.class); bp.setBaseUrl("https://crowdin.com"); String url = "https://crowdin.com"; @@ -202,7 +202,7 @@ public void testMockBasePropUrl(){ } @Test - public void testMockBasePropPath(){ + public void testMockBasePropPath() { BaseProperties bp = mock(BaseProperties.class); bp.setBasePath("./path"); String path = "./path"; @@ -210,7 +210,7 @@ public void testMockBasePropPath(){ } @Test - public void testMockBasePropApiToken(){ + public void testMockBasePropApiToken() { BaseProperties bp = mock(BaseProperties.class); bp.setApiToken("123Token"); String token = "123Token"; @@ -218,7 +218,7 @@ public void testMockBasePropApiToken(){ } @Test - public void testMockProjectPropToken(){ + public void testMockProjectPropToken() { ProjectProperties pp = mock(ProjectProperties.class); pp.setApiToken("123Token"); String token = "123Token"; @@ -226,7 +226,7 @@ public void testMockProjectPropToken(){ } @Test - public void testMockProjectPropPath(){ + public void testMockProjectPropPath() { ProjectProperties pp = mock(ProjectProperties.class); pp.setBasePath("./path"); String path = "./path"; @@ -234,7 +234,7 @@ public void testMockProjectPropPath(){ } @Test - public void testMockProjectPropUrl(){ + public void testMockProjectPropUrl() { ProjectProperties pp = mock(ProjectProperties.class); pp.setBaseUrl("https://crowdin.com"); String url = "https://crowdin.com"; @@ -242,7 +242,7 @@ public void testMockProjectPropUrl(){ } @Test - public void testMockPropBuilderBasePropUrl(){ + public void testMockPropBuilderBasePropUrl() { PropertiesBuilders pb = mock(PropertiesBuilders.class); File configFile = new File("folder/crowdinTest.yml"); String minimalConfigFileText = NewPropertiesWithTargetsUtilBuilder @@ -257,8 +257,9 @@ public void testMockPropBuilderBasePropUrl(){ when(bp.getBaseUrl()).thenReturn( "https://crowdin.com"); } + @Test - public void testMockPropBuilderBasePropIdParam(){ + public void testMockPropBuilderBasePropIdParam() { PropertiesBuilders pb = mock(PropertiesBuilders.class); File configFile = new File("folder/crowdinTest.yml"); String minimalConfigFileText = NewPropertiesWithTargetsUtilBuilder