Skip to content

Commit

Permalink
add HostComponentServiceTest
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Oct 14, 2024
1 parent 9966e09 commit f25f36c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

@ExtendWith(MockitoExtension.class)
public class ClusterServiceTest {
private static final String CLUSTER_NAME = "TestCluster";

@Mock
private ClusterDao clusterDao;
Expand All @@ -70,7 +71,7 @@ public class ClusterServiceTest {
private RepoDao repoDao;

@InjectMocks
private ClusterServiceImpl clusterService = new ClusterServiceImpl();
private ClusterService clusterService = new ClusterServiceImpl();

@Mock
private HostService hostService;
Expand All @@ -83,10 +84,10 @@ public class ClusterServiceTest {
public void setup() {
clusterPO = new ClusterPO();
clusterPO.setId(1L);
clusterPO.setClusterName("TestCluster");
clusterPO.setClusterName(CLUSTER_NAME);

clusterDTO = new ClusterDTO();
clusterDTO.setClusterName("TestCluster");
clusterDTO.setClusterName(CLUSTER_NAME);
clusterDTO.setStackName("TestStack");
clusterDTO.setStackVersion("1.0.0");
RepoDTO repoDTO = new RepoDTO();
Expand All @@ -110,11 +111,11 @@ public void testListAndGetAndUpdate() {
assertThrows(ApiException.class, () -> clusterService.get(1L)).getEx());

when(clusterDao.findByIdJoin(any())).thenReturn(clusterPO);
assert clusterService.get(1L).getClusterName().equals("TestCluster");
assert clusterService.get(1L).getClusterName().equals(CLUSTER_NAME);

ClusterDTO clusterDTO = new ClusterDTO();
clusterDTO.setClusterName("TestCluster");
assert clusterService.update(1L, clusterDTO).getClusterName().equals("TestCluster");
clusterDTO.setClusterName(CLUSTER_NAME);
assert clusterService.update(1L, clusterDTO).getClusterName().equals(CLUSTER_NAME);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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
*
* https://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.bigtop.manager.server.service;

import org.apache.bigtop.manager.dao.repository.HostComponentDao;
import org.apache.bigtop.manager.server.service.impl.HostComponentServiceImpl;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.ArrayList;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
public class HostComponentServiceTest {
@Mock
private HostComponentDao hostComponentDao;

@InjectMocks
private HostComponentService hostComponentService = new HostComponentServiceImpl();

@Test
public void testListHostComponent() {
when(hostComponentDao.findAllByClusterId(any())).thenReturn(new ArrayList<>());
assert hostComponentService.list(1L) != null;

when(hostComponentDao.findAllByClusterIdAndHostId(any(), any())).thenReturn(null);
assert hostComponentService.listByHost(1L, 1L) == null;

when(hostComponentDao.findAllByClusterIdAndServiceId(any(), any())).thenReturn(null);
assert hostComponentService.listByService(1L, 1L) == null;
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<!-- JUnit/Mockito -->
<junit.version>5.10.3</junit.version>
<mockito.version>5.12.0</mockito.version>
<mock-inlie.version>4.10.0</mock-inlie.version>
<mock-inlie.version>5.2.0</mock-inlie.version>

<mapstruct.version>1.5.5.Final</mapstruct.version>
<lombok.version>1.18.30</lombok.version>
Expand Down

0 comments on commit f25f36c

Please sign in to comment.