Browse Source

refactor code style

pull/3/MERGE
baoliang 4 years ago
parent
commit
8b879746cc
  1. 46
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UdfFuncMapperTest.java

46
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UdfFuncMapperTest.java

@ -59,9 +59,10 @@ public class UdfFuncMapperTest {
/** /**
* insert one udf * insert one udf
*
* @return UdfFunc * @return UdfFunc
*/ */
private UdfFunc insertOne(){ private UdfFunc insertOne() {
UdfFunc udfFunc = new UdfFunc(); UdfFunc udfFunc = new UdfFunc();
udfFunc.setUserId(1); udfFunc.setUserId(1);
udfFunc.setFuncName("dolphin_udf_func"); udfFunc.setFuncName("dolphin_udf_func");
@ -77,9 +78,10 @@ public class UdfFuncMapperTest {
/** /**
* insert one udf * insert one udf
*
* @return * @return
*/ */
private UdfFunc insertOne(User user){ private UdfFunc insertOne(User user) {
UdfFunc udfFunc = new UdfFunc(); UdfFunc udfFunc = new UdfFunc();
udfFunc.setUserId(user.getId()); udfFunc.setUserId(user.getId());
udfFunc.setFuncName("dolphin_udf_func"); udfFunc.setFuncName("dolphin_udf_func");
@ -95,9 +97,10 @@ public class UdfFuncMapperTest {
/** /**
* insert one user * insert one user
*
* @return User * @return User
*/ */
private User insertOneUser(){ private User insertOneUser() {
User user = new User(); User user = new User();
user.setUserName("user1"); user.setUserName("user1");
user.setUserPassword("1"); user.setUserPassword("1");
@ -112,9 +115,10 @@ public class UdfFuncMapperTest {
/** /**
* insert one user * insert one user
*
* @return User * @return User
*/ */
private User insertOneUser(String userName){ private User insertOneUser(String userName) {
User user = new User(); User user = new User();
user.setUserName(userName); user.setUserName(userName);
user.setUserPassword("1"); user.setUserPassword("1");
@ -129,11 +133,12 @@ public class UdfFuncMapperTest {
/** /**
* insert UDFUser * insert UDFUser
*
* @param user user * @param user user
* @param udfFunc udf func * @param udfFunc udf func
* @return UDFUser * @return UDFUser
*/ */
private UDFUser insertOneUDFUser(User user,UdfFunc udfFunc){ private UDFUser insertOneUDFUser(User user, UdfFunc udfFunc) {
UDFUser udfUser = new UDFUser(); UDFUser udfUser = new UDFUser();
udfUser.setUdfId(udfFunc.getId()); udfUser.setUdfId(udfFunc.getId());
udfUser.setUserId(user.getId()); udfUser.setUserId(user.getId());
@ -145,9 +150,10 @@ public class UdfFuncMapperTest {
/** /**
* create general user * create general user
*
* @return User * @return User
*/ */
private User createGeneralUser(String userName){ private User createGeneralUser(String userName) {
User user = new User(); User user = new User();
user.setUserName(userName); user.setUserName(userName);
user.setUserPassword("1"); user.setUserPassword("1");
@ -164,7 +170,7 @@ public class UdfFuncMapperTest {
* test update * test update
*/ */
@Test @Test
public void testUpdate(){ public void testUpdate() {
//insertOne //insertOne
UdfFunc udfFunc = insertOne(); UdfFunc udfFunc = insertOne();
udfFunc.setResourceName("dolphin_resource_update"); udfFunc.setResourceName("dolphin_resource_update");
@ -181,7 +187,7 @@ public class UdfFuncMapperTest {
* test delete * test delete
*/ */
@Test @Test
public void testDelete(){ public void testDelete() {
//insertOne //insertOne
UdfFunc udfFunc = insertOne(); UdfFunc udfFunc = insertOne();
//delete //delete
@ -193,7 +199,7 @@ public class UdfFuncMapperTest {
* test query * test query
*/ */
@Test @Test
public void testQuery(){ public void testQuery() {
//insertOne //insertOne
UdfFunc udfFunc = insertOne(); UdfFunc udfFunc = insertOne();
//query //query
@ -210,9 +216,9 @@ public class UdfFuncMapperTest {
UdfFunc udfFunc = insertOne(); UdfFunc udfFunc = insertOne();
//insertOne //insertOne
UdfFunc udfFunc1 = insertOne(); UdfFunc udfFunc1 = insertOne();
int[] idArray = new int[]{udfFunc.getId(),udfFunc1.getId()}; int[] idArray = new int[]{udfFunc.getId(), udfFunc1.getId()};
//queryUdfByIdStr //queryUdfByIdStr
List<UdfFunc> udfFuncList = udfFuncMapper.queryUdfByIdStr(idArray,""); List<UdfFunc> udfFuncList = udfFuncMapper.queryUdfByIdStr(idArray, "");
Assert.assertNotEquals(udfFuncList.size(), 0); Assert.assertNotEquals(udfFuncList.size(), 0);
} }
@ -226,8 +232,8 @@ public class UdfFuncMapperTest {
//insertOne //insertOne
UdfFunc udfFunc = insertOne(user); UdfFunc udfFunc = insertOne(user);
//queryUdfFuncPaging //queryUdfFuncPaging
Page<UdfFunc> page = new Page(1,3); Page<UdfFunc> page = new Page(1, 3);
IPage<UdfFunc> udfFuncIPage = udfFuncMapper.queryUdfFuncPaging(page,user.getId(),""); IPage<UdfFunc> udfFuncIPage = udfFuncMapper.queryUdfFuncPaging(page, user.getId(), "");
Assert.assertNotEquals(udfFuncIPage.getTotal(), 0); Assert.assertNotEquals(udfFuncIPage.getTotal(), 0);
} }
@ -282,7 +288,7 @@ public class UdfFuncMapperTest {
} }
@Test @Test
public void testListAuthorizedUdfFunc(){ public void testListAuthorizedUdfFunc() {
//create general user //create general user
User generalUser1 = createGeneralUser("user1"); User generalUser1 = createGeneralUser("user1");
User generalUser2 = createGeneralUser("user2"); User generalUser2 = createGeneralUser("user2");
@ -292,30 +298,30 @@ public class UdfFuncMapperTest {
UdfFunc unauthorizdUdfFunc = insertOne(generalUser2); UdfFunc unauthorizdUdfFunc = insertOne(generalUser2);
//udf function ids //udf function ids
Integer[] udfFuncIds = new Integer[]{udfFunc.getId(),unauthorizdUdfFunc.getId()}; Integer[] udfFuncIds = new Integer[]{udfFunc.getId(), unauthorizdUdfFunc.getId()};
List<UdfFunc> authorizedUdfFunc = udfFuncMapper.listAuthorizedUdfFunc(generalUser1.getId(), udfFuncIds); List<UdfFunc> authorizedUdfFunc = udfFuncMapper.listAuthorizedUdfFunc(generalUser1.getId(), udfFuncIds);
Assert.assertEquals(generalUser1.getId(),udfFunc.getUserId()); Assert.assertEquals(generalUser1.getId(), udfFunc.getUserId());
Assert.assertNotEquals(generalUser1.getId(),unauthorizdUdfFunc.getUserId()); Assert.assertNotEquals(generalUser1.getId(), unauthorizdUdfFunc.getUserId());
Assert.assertFalse(authorizedUdfFunc.stream().map(t -> t.getId()).collect(toList()).containsAll(Arrays.asList(udfFuncIds))); Assert.assertFalse(authorizedUdfFunc.stream().map(t -> t.getId()).collect(toList()).containsAll(Arrays.asList(udfFuncIds)));
//authorize object unauthorizdUdfFunc to generalUser1 //authorize object unauthorizdUdfFunc to generalUser1
insertOneUDFUser(generalUser1,unauthorizdUdfFunc); insertOneUDFUser(generalUser1, unauthorizdUdfFunc);
authorizedUdfFunc = udfFuncMapper.listAuthorizedUdfFunc(generalUser1.getId(), udfFuncIds); authorizedUdfFunc = udfFuncMapper.listAuthorizedUdfFunc(generalUser1.getId(), udfFuncIds);
Assert.assertTrue(authorizedUdfFunc.stream().map(t -> t.getId()).collect(toList()).containsAll(Arrays.asList(udfFuncIds))); Assert.assertTrue(authorizedUdfFunc.stream().map(t -> t.getId()).collect(toList()).containsAll(Arrays.asList(udfFuncIds)));
} }
@Test @Test
public void batchUpdateUdfFuncTest(){ public void batchUpdateUdfFuncTest() {
//create general user //create general user
User generalUser1 = createGeneralUser("user1"); User generalUser1 = createGeneralUser("user1");
UdfFunc udfFunc = insertOne(generalUser1); UdfFunc udfFunc = insertOne(generalUser1);
udfFunc.setResourceName("/updateTest"); udfFunc.setResourceName("/updateTest");
List<UdfFunc> udfFuncList = new ArrayList<>(); List<UdfFunc> udfFuncList = new ArrayList<>();
udfFuncList.add(udfFunc); udfFuncList.add(udfFunc);
Assert.assertTrue(udfFuncMapper.batchUpdateUdfFunc(udfFuncList)>0); Assert.assertTrue(udfFuncMapper.batchUpdateUdfFunc(udfFuncList) > 0);
} }
} }
Loading…
Cancel
Save