You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by ca...@apache.org on 2022/08/11 06:51:29 UTC
[incubator-linkis] branch dev-1.2.1 updated: [ISSUES-2677]Add ResourceServiceImplTest unit test (#2678)
This is an automated email from the ASF dual-hosted git repository.
casion pushed a commit to branch dev-1.2.1
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git
The following commit(s) were added to refs/heads/dev-1.2.1 by this push:
new f15569f41 [ISSUES-2677]Add ResourceServiceImplTest unit test (#2678)
f15569f41 is described below
commit f15569f410a79e6f75753c0f9a9f8214b3e9675a
Author: 成彬彬 <10...@users.noreply.github.com>
AuthorDate: Thu Aug 11 14:51:24 2022 +0800
[ISSUES-2677]Add ResourceServiceImplTest unit test (#2678)
* Add ResourceServiceImplTest unit test
---
.../linkis/bml/service/BmlProjectServiceTest.java | 50 +------
.../bml/service/ResourceServiceImplTest.java | 160 +++++++++++++++++++++
2 files changed, 164 insertions(+), 46 deletions(-)
diff --git a/linkis-public-enhancements/linkis-bml/linkis-bml-server/src/test/java/org/apache/linkis/bml/service/BmlProjectServiceTest.java b/linkis-public-enhancements/linkis-bml/linkis-bml-server/src/test/java/org/apache/linkis/bml/service/BmlProjectServiceTest.java
index 82c7ecc9d..6b1e3beb3 100644
--- a/linkis-public-enhancements/linkis-bml/linkis-bml-server/src/test/java/org/apache/linkis/bml/service/BmlProjectServiceTest.java
+++ b/linkis-public-enhancements/linkis-bml/linkis-bml-server/src/test/java/org/apache/linkis/bml/service/BmlProjectServiceTest.java
@@ -21,9 +21,6 @@ import org.apache.linkis.bml.dao.BmlProjectDao;
import org.apache.linkis.bml.entity.BmlProject;
import org.apache.linkis.bml.service.impl.BmlProjectServiceImpl;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
@@ -46,14 +43,6 @@ public class BmlProjectServiceTest {
@Mock private BmlProjectDao bmlProjectDao;
- @BeforeEach
- @DisplayName("Each unit test method is executed once before execution")
- public void before() throws Exception {}
-
- @AfterEach
- @DisplayName("Each unit test method is executed once before execution")
- public void after() throws Exception {}
-
public BmlProject addBmlProject() {
BmlProject bmlProject = new BmlProject();
bmlProject.setName("testName");
@@ -68,10 +57,7 @@ public class BmlProjectServiceTest {
}
@Test
- @DisplayName("Method description: ...")
public void testCreateBmlProject() throws Exception {
- // TODO: Test goes here...
-
/*String projectName = "testName1";
String creator = "creCreatorUser1";
List<String> editUsers = new ArrayList<>();
@@ -93,9 +79,7 @@ public class BmlProjectServiceTest {
}
@Test
- @DisplayName("Method description: ...")
public void testCheckEditPriv() throws Exception {
- // TODO: Test goes here...
String projectName = "testProjectName";
String username = "testUsername";
Mockito.when(bmlProjectDao.getPrivInProject(projectName, username)).thenReturn(6);
@@ -104,9 +88,7 @@ public class BmlProjectServiceTest {
}
@Test
- @DisplayName("Method description: ...")
public void testCheckAccessPriv() throws Exception {
- // TODO: Test goes here...
String projectName = "testProjectName";
String username = "testUsername";
Mockito.when(bmlProjectDao.getPrivInProject(projectName, username)).thenReturn(4);
@@ -115,9 +97,7 @@ public class BmlProjectServiceTest {
}
@Test
- @DisplayName("Method description: ...")
public void testSetProjectEditPriv() throws Exception {
- // TODO: Test goes here...
String projectName = "testName";
List<String> editUsers = new ArrayList<>();
BmlProject bmlProject = addBmlProject();
@@ -126,21 +106,13 @@ public class BmlProjectServiceTest {
}
@Test
- @DisplayName("Method description: ...")
- public void testAddProjectEditPriv() throws Exception {
- // TODO: Test goes here...
- }
+ public void testAddProjectEditPriv() throws Exception {}
@Test
- @DisplayName("Method description: ...")
- public void testDeleteProjectEditPriv() throws Exception {
- // TODO: Test goes here...
- }
+ public void testDeleteProjectEditPriv() throws Exception {}
@Test
- @DisplayName("Method description: ...")
public void testSetProjectAccessPriv() throws Exception {
- // TODO: Test goes here...
String projectName = "testName";
List<String> editUsers = new ArrayList<>();
BmlProject bmlProject = addBmlProject();
@@ -149,21 +121,13 @@ public class BmlProjectServiceTest {
}
@Test
- @DisplayName("Method description: ...")
- public void testAddProjectAccessPriv() throws Exception {
- // TODO: Test goes here...
- }
+ public void testAddProjectAccessPriv() throws Exception {}
@Test
- @DisplayName("Method description: ...")
- public void testDeleteProjectAccessPriv() throws Exception {
- // TODO: Test goes here...
- }
+ public void testDeleteProjectAccessPriv() throws Exception {}
@Test
- @DisplayName("Method description: ...")
public void testGetProjectNameByResourceId() throws Exception {
- // TODO: Test goes here...
String resourceId = "123";
Mockito.when(bmlProjectDao.getProjectNameByResourceId(resourceId)).thenReturn("testName");
String projectName = bmlProjectService.getProjectNameByResourceId(resourceId);
@@ -171,9 +135,7 @@ public class BmlProjectServiceTest {
}
@Test
- @DisplayName("Method description: ...")
public void testAddProjectResource() throws Exception {
- // TODO: Test goes here...
String resourceId = "123";
String projectName = "testName";
BmlProject bmlProject = addBmlProject();
@@ -182,9 +144,7 @@ public class BmlProjectServiceTest {
}
@Test
- @DisplayName("Method description: ...")
public void testAttach() throws Exception {
- // TODO: Test goes here...
String projectName = "testName";
String resourceId = "123";
Mockito.when(bmlProjectDao.getProjectIdByName(projectName)).thenReturn(1);
@@ -193,9 +153,7 @@ public class BmlProjectServiceTest {
}
@Test
- @DisplayName("Method description: ...")
public void testUpdateProjectUsers() throws Exception {
- // TODO: Test goes here...
String username = "testUsername";
String projectName = "testName";
List<String> editUsers = new ArrayList<>();
diff --git a/linkis-public-enhancements/linkis-bml/linkis-bml-server/src/test/java/org/apache/linkis/bml/service/ResourceServiceImplTest.java b/linkis-public-enhancements/linkis-bml/linkis-bml-server/src/test/java/org/apache/linkis/bml/service/ResourceServiceImplTest.java
new file mode 100644
index 000000000..163b25ad5
--- /dev/null
+++ b/linkis-public-enhancements/linkis-bml/linkis-bml-server/src/test/java/org/apache/linkis/bml/service/ResourceServiceImplTest.java
@@ -0,0 +1,160 @@
+/*
+ * 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.linkis.bml.service;
+
+import org.apache.linkis.bml.dao.ResourceDao;
+import org.apache.linkis.bml.dao.VersionDao;
+import org.apache.linkis.bml.entity.Resource;
+import org.apache.linkis.bml.entity.ResourceVersion;
+import org.apache.linkis.bml.service.impl.ResourceServiceImpl;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.*;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/** ResourceServiceImpl Tester */
+@ExtendWith(MockitoExtension.class)
+public class ResourceServiceImplTest {
+
+ @InjectMocks private ResourceServiceImpl resourceServiceImpl;
+
+ @Mock private ResourceDao resourceDao;
+
+ @Mock private VersionDao versionDao;
+
+ Resource buildResource() {
+ Resource resource = new Resource();
+ resource.setResourceId("123");
+ resource.setResourceHeader("2");
+ resource.setDownloadedFileName("testFileName");
+ resource.setSystem("testSystem");
+ resource.setCreateTime(new Date());
+ resource.setUser("testUser");
+ resource.setExpireTime("2012.12.02");
+ resource.setMaxVersion(3);
+ resource.setUpdateTime(new Date());
+ resource.setUpdator("testUpdator");
+ resource.setEnableFlag(true);
+ return resource;
+ }
+
+ @Test
+ public void testGetResources() throws Exception {
+ Map paramMap = new HashMap();
+ paramMap.put("resource_id", "1");
+ paramMap.put("owner", "owner");
+ paramMap.put("sys", "sys");
+ List<Resource> list = new ArrayList<>();
+ list.add(buildResource());
+ Mockito.when(resourceDao.getResources(paramMap)).thenReturn(list);
+ List<Resource> resourceList = resourceServiceImpl.getResources(paramMap);
+ assertTrue(resourceList.size() > 0);
+ }
+
+ @Test
+ public void testDeleteResource() throws Exception {
+ String resourceId = "123";
+ resourceServiceImpl.deleteResource(resourceId);
+ }
+
+ @Test
+ public void testBatchDeleteResources() throws Exception {
+ List<String> list = new ArrayList<>();
+ list.add("123");
+ list.add("234");
+ resourceServiceImpl.batchDeleteResources(list);
+ }
+
+ @Test
+ public void testUpload() throws Exception {
+ /*List< MultipartFile > files =new ArrayList<>();
+ String user="testuser";
+ Map<String, Object> properties =new HashMap<>();
+ properties.put("resourceId","123");
+ ResourceHelper resourceHelper = ResourceHelperFactory.getResourceHelper();
+ Mockito.when(ResourceHelperFactory.getResourceHelper()).thenReturn(resourceHelper);
+ Mockito.when(resourceHelper.generatePath(user,"123",properties)).thenReturn("testpath");*/
+ }
+
+ @Test
+ public void testCheckResourceId() throws Exception {
+ String resourceId = "123";
+ Mockito.when(resourceDao.checkExists(resourceId)).thenReturn(1);
+ boolean whether = resourceServiceImpl.checkResourceId(resourceId);
+ assertTrue(whether == true);
+ }
+
+ @Test
+ public void testGetResource() throws Exception {
+ String resourceId = "123";
+ Resource resource = buildResource();
+ Mockito.when(resourceDao.getResource(resourceId)).thenReturn(resource);
+ Resource rs = resourceServiceImpl.getResource(resourceId);
+ assertTrue(rs != null);
+ }
+
+ @Test
+ public void testCheckAuthority() throws Exception {
+ String resourceId = "123";
+ String user = "testuser";
+ Mockito.when(resourceDao.getUserByResourceId(resourceId)).thenReturn("testuser");
+ boolean whether = resourceServiceImpl.checkAuthority(user, resourceId);
+ assertTrue(whether == true);
+ }
+
+ @Test
+ public void testCheckExpire() throws Exception {
+ String resourceId = "123";
+ String version = "321";
+ Resource resource = buildResource();
+ ResourceVersion resourceVersion = new ResourceVersion();
+ resourceVersion.setEnableFlag(true);
+ Mockito.when(resourceDao.getResource(resourceId)).thenReturn(resource);
+ Mockito.when(versionDao.getResourceVersion(resourceId, version))
+ .thenReturn(resourceVersion);
+ boolean whether = resourceServiceImpl.checkExpire(resourceId, version);
+ assertTrue(whether == true);
+ }
+
+ @Test
+ public void testCleanExpiredResources() throws Exception {}
+
+ @Test
+ public void testChangeOwnerByResourceId() throws Exception {
+
+ String resourceId = "123";
+ String oldOwner = "oldOwnertest";
+ String newOwner = "newOwnertest";
+ resourceServiceImpl.changeOwnerByResourceId(resourceId, oldOwner, newOwner);
+ }
+
+ @Test
+ public void testCopyResourceToOtherUser() throws Exception {
+
+ String resourceId = "123";
+ String otherUser = "otherUser";
+ resourceServiceImpl.copyResourceToOtherUser(resourceId, otherUser);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org