Yann Ann
2 years ago
committed by
GitHub
1 changed files with 114 additions and 0 deletions
@ -0,0 +1,114 @@
|
||||
/* |
||||
* 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.dao.mapper; |
||||
|
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import javax.annotation.Resource; |
||||
import org.apache.dolphinscheduler.dao.BaseDaoTest; |
||||
import org.apache.dolphinscheduler.dao.entity.WorkerGroup; |
||||
import org.junit.After; |
||||
import org.junit.Assert; |
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
|
||||
public class WorkerGroupMapperTest extends BaseDaoTest { |
||||
|
||||
@Resource |
||||
private WorkerGroupMapper workerGroupMapper; |
||||
|
||||
@Before |
||||
public void setUp() { |
||||
clearTestData(); |
||||
} |
||||
|
||||
@After |
||||
public void after() { |
||||
clearTestData(); |
||||
} |
||||
|
||||
/** |
||||
* clear all test data |
||||
*/ |
||||
public void clearTestData() { |
||||
workerGroupMapper.queryAllWorkerGroup() |
||||
.forEach(workerGroup -> workerGroupMapper.deleteById(workerGroup.getId())); |
||||
} |
||||
|
||||
/** |
||||
* insert a worker group into DB |
||||
* |
||||
* @return worker group |
||||
*/ |
||||
private WorkerGroup insertOneWorkerGroup() { |
||||
WorkerGroup workerGroup = new WorkerGroup(); |
||||
workerGroup.setName("Server1"); |
||||
workerGroup.setDescription("Server1"); |
||||
workerGroup.setCreateTime(new Date()); |
||||
workerGroup.setUpdateTime(new Date()); |
||||
workerGroup.setSystemDefault(true); |
||||
workerGroup.setOtherParamsJson(""); |
||||
workerGroup.setAddrList("localhost"); |
||||
workerGroupMapper.insert(workerGroup); |
||||
return workerGroup; |
||||
} |
||||
|
||||
/** |
||||
* test query all worker groups |
||||
*/ |
||||
@Test |
||||
public void testQueryAllWorkerGroups() { |
||||
insertOneWorkerGroup(); |
||||
List<WorkerGroup> workerGroups = workerGroupMapper.queryAllWorkerGroup(); |
||||
Assert.assertEquals(1, workerGroups.size()); |
||||
} |
||||
|
||||
/** |
||||
* test query worker group by name |
||||
*/ |
||||
@Test |
||||
public void testQueryWorkerGroupByName() { |
||||
WorkerGroup workerGroup = insertOneWorkerGroup(); |
||||
List<WorkerGroup> workerGroups = workerGroupMapper.queryWorkerGroupByName(workerGroup.getName()); |
||||
Assert.assertEquals(1, workerGroups.size()); |
||||
|
||||
workerGroups = workerGroupMapper.queryWorkerGroupByName("server2"); |
||||
Assert.assertEquals(0, workerGroups.size()); |
||||
} |
||||
|
||||
/** |
||||
* test update workerGroup |
||||
*/ |
||||
@Test |
||||
public void testUpdate() { |
||||
WorkerGroup workerGroup = insertOneWorkerGroup(); |
||||
workerGroup.setDescription("Server Update"); |
||||
int update = workerGroupMapper.updateById(workerGroup); |
||||
Assert.assertEquals(1, update); |
||||
} |
||||
|
||||
/** |
||||
* test delete workerGroup |
||||
*/ |
||||
@Test |
||||
public void delete() { |
||||
WorkerGroup workerGroup = insertOneWorkerGroup(); |
||||
int delete = workerGroupMapper.deleteById(workerGroup.getId()); |
||||
Assert.assertEquals(1, delete); |
||||
} |
||||
} |
Loading…
Reference in new issue