Browse Source

just add WorkerGroupMapper UT (#12242)

3.2.0-release
Yann Ann 2 years ago committed by GitHub
parent
commit
60c43d5d32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 114
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapperTest.java

114
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapperTest.java

@ -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…
Cancel
Save