Loading dolphinscheduler-common/pom.xml +24 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,30 @@ <artifactId>junit</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <type>jar</type> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito2</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>commons-configuration</groupId> Loading dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java +3 −3 Original line number Diff line number Diff line Loading @@ -110,10 +110,9 @@ public class FileUtils { * create directory and user * @param execLocalPath execute local path * @param userName user name * @param logger logger * @throws IOException errors */ public static void createWorkDirAndUserIfAbsent(String execLocalPath, String userName, Logger logger) throws IOException{ public static void createWorkDirAndUserIfAbsent(String execLocalPath, String userName) throws IOException{ //if work dir exists, first delete File execLocalPathFile = new File(execLocalPath); Loading @@ -123,13 +122,14 @@ public class FileUtils { //create work dir org.apache.commons.io.FileUtils.forceMkdir(execLocalPathFile); logger.info("create dir success {}" , execLocalPath); //if not exists this user,then create if (!OSUtils.getUserList().contains(userName)){ OSUtils.createUser(userName); } logger.info("create user name success {}", userName); } Loading dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/EncryptionUtilsTest.java 0 → 100644 +35 −0 Original line number Diff line number Diff line /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dolphinscheduler.common.utils; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; import org.junit.Assert; import org.junit.Test; /** * encryption utils */ public class EncryptionUtilsTest { @Test public void testGetMd5() { Assert.assertEquals(EncryptionUtils.getMd5(null), EncryptionUtils.getMd5("")); } } dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java +40 −1 Original line number Diff line number Diff line Loading @@ -18,11 +18,50 @@ package org.apache.dolphinscheduler.common.utils; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import static org.apache.dolphinscheduler.common.Constants.YYYYMMDDHHMMSS; @RunWith(PowerMockRunner.class) @PrepareForTest(DateUtils.class) public class FileUtilsTest { @Test public void suffix() { Assert.assertEquals(FileUtils.suffix("ninfor.java"),"java"); } @Test public void testGetDownloadFilename() { PowerMockito.mockStatic(DateUtils.class); PowerMockito.when(DateUtils.getCurrentTime(YYYYMMDDHHMMSS)).thenReturn("20190101101059"); Assert.assertEquals(FileUtils.getDownloadFilename("test"), "/tmp/dolphinscheduler/download/20190101101059/test"); } @Test public void testGetUploadFilename() { Assert.assertEquals(FileUtils.getUploadFilename("aaa","bbb"), "/tmp/dolphinscheduler/aaa/resources/bbb"); } @Test public void testGetProcessExecDir() { String dir = FileUtils.getProcessExecDir(1,2,3, 4); Assert.assertEquals(dir, "/tmp/dolphinscheduler/exec/process/1/2/3/4"); dir = FileUtils.getProcessExecDir(1,2,3); Assert.assertEquals(dir, "/tmp/dolphinscheduler/exec/process/1/2/3"); } @Test public void testCreateWorkDirAndUserIfAbsent() { try { FileUtils.createWorkDirAndUserIfAbsent("/tmp/createWorkDirAndUserIfAbsent", "test123"); Assert.assertTrue(true); } catch (Exception e) { Assert.assertTrue(false); } } } dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HttpUtilsTest.java +11 −11 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.common.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; import org.slf4j.Logger; Loading @@ -32,16 +33,15 @@ public class HttpUtilsTest { public static final Logger logger = LoggerFactory.getLogger(HttpUtilsTest.class); @Ignore @Test public void getTest(){ String result = HttpUtils.get("http://192.168.xx.xx:8088/ws/v1/cluster/info"); logger.info(result); public void testGetTest(){ //success String result = HttpUtils.get("https://github.com/manifest.json"); Assert.assertNotNull(result); JSONObject jsonObject = JSON.parseObject(result); String string = jsonObject.getJSONObject("clusterInfo").getString("haState"); logger.info(string); Assert.assertEquals(jsonObject.getString("name"), "GitHub"); result = HttpUtils.get("https://123.333.111.33/ccc"); Assert.assertNull(result); } } Loading
dolphinscheduler-common/pom.xml +24 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,30 @@ <artifactId>junit</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <type>jar</type> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.powermock</groupId> <artifactId>powermock-api-mockito2</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>commons-configuration</groupId> Loading
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/FileUtils.java +3 −3 Original line number Diff line number Diff line Loading @@ -110,10 +110,9 @@ public class FileUtils { * create directory and user * @param execLocalPath execute local path * @param userName user name * @param logger logger * @throws IOException errors */ public static void createWorkDirAndUserIfAbsent(String execLocalPath, String userName, Logger logger) throws IOException{ public static void createWorkDirAndUserIfAbsent(String execLocalPath, String userName) throws IOException{ //if work dir exists, first delete File execLocalPathFile = new File(execLocalPath); Loading @@ -123,13 +122,14 @@ public class FileUtils { //create work dir org.apache.commons.io.FileUtils.forceMkdir(execLocalPathFile); logger.info("create dir success {}" , execLocalPath); //if not exists this user,then create if (!OSUtils.getUserList().contains(userName)){ OSUtils.createUser(userName); } logger.info("create user name success {}", userName); } Loading
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/EncryptionUtilsTest.java 0 → 100644 +35 −0 Original line number Diff line number Diff line /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.dolphinscheduler.common.utils; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.StringUtils; import org.junit.Assert; import org.junit.Test; /** * encryption utils */ public class EncryptionUtilsTest { @Test public void testGetMd5() { Assert.assertEquals(EncryptionUtils.getMd5(null), EncryptionUtils.getMd5("")); } }
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/FileUtilsTest.java +40 −1 Original line number Diff line number Diff line Loading @@ -18,11 +18,50 @@ package org.apache.dolphinscheduler.common.utils; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import static org.apache.dolphinscheduler.common.Constants.YYYYMMDDHHMMSS; @RunWith(PowerMockRunner.class) @PrepareForTest(DateUtils.class) public class FileUtilsTest { @Test public void suffix() { Assert.assertEquals(FileUtils.suffix("ninfor.java"),"java"); } @Test public void testGetDownloadFilename() { PowerMockito.mockStatic(DateUtils.class); PowerMockito.when(DateUtils.getCurrentTime(YYYYMMDDHHMMSS)).thenReturn("20190101101059"); Assert.assertEquals(FileUtils.getDownloadFilename("test"), "/tmp/dolphinscheduler/download/20190101101059/test"); } @Test public void testGetUploadFilename() { Assert.assertEquals(FileUtils.getUploadFilename("aaa","bbb"), "/tmp/dolphinscheduler/aaa/resources/bbb"); } @Test public void testGetProcessExecDir() { String dir = FileUtils.getProcessExecDir(1,2,3, 4); Assert.assertEquals(dir, "/tmp/dolphinscheduler/exec/process/1/2/3/4"); dir = FileUtils.getProcessExecDir(1,2,3); Assert.assertEquals(dir, "/tmp/dolphinscheduler/exec/process/1/2/3"); } @Test public void testCreateWorkDirAndUserIfAbsent() { try { FileUtils.createWorkDirAndUserIfAbsent("/tmp/createWorkDirAndUserIfAbsent", "test123"); Assert.assertTrue(true); } catch (Exception e) { Assert.assertTrue(false); } } }
dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/HttpUtilsTest.java +11 −11 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.common.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; import org.slf4j.Logger; Loading @@ -32,16 +33,15 @@ public class HttpUtilsTest { public static final Logger logger = LoggerFactory.getLogger(HttpUtilsTest.class); @Ignore @Test public void getTest(){ String result = HttpUtils.get("http://192.168.xx.xx:8088/ws/v1/cluster/info"); logger.info(result); public void testGetTest(){ //success String result = HttpUtils.get("https://github.com/manifest.json"); Assert.assertNotNull(result); JSONObject jsonObject = JSON.parseObject(result); String string = jsonObject.getJSONObject("clusterInfo").getString("haState"); logger.info(string); Assert.assertEquals(jsonObject.getString("name"), "GitHub"); result = HttpUtils.get("https://123.333.111.33/ccc"); Assert.assertNull(result); } }