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/09/14 16:03:14 UTC
[incubator-linkis] branch dev-1.3.1 updated: [ISSUE-3308]Add DefaultInsLabelServiceTest unit test (#3309)
This is an automated email from the ASF dual-hosted git repository.
casion pushed a commit to branch dev-1.3.1
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git
The following commit(s) were added to refs/heads/dev-1.3.1 by this push:
new 1ff87b2ad [ISSUE-3308]Add DefaultInsLabelServiceTest unit test (#3309)
1ff87b2ad is described below
commit 1ff87b2ad869ca294c8ef7a3538d998964296bc7
Author: 成彬彬 <10...@users.noreply.github.com>
AuthorDate: Thu Sep 15 00:03:05 2022 +0800
[ISSUE-3308]Add DefaultInsLabelServiceTest unit test (#3309)
---
.../service/impl/DefaultInsLabelServiceTest.java | 134 +++++++++++++++++++++
1 file changed, 134 insertions(+)
diff --git a/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/test/java/org/apache/linkis/instance/label/service/impl/DefaultInsLabelServiceTest.java b/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/test/java/org/apache/linkis/instance/label/service/impl/DefaultInsLabelServiceTest.java
new file mode 100644
index 000000000..a862645cf
--- /dev/null
+++ b/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-server/src/test/java/org/apache/linkis/instance/label/service/impl/DefaultInsLabelServiceTest.java
@@ -0,0 +1,134 @@
+/*
+ * 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.instance.label.service.impl;
+
+import org.apache.linkis.common.ServiceInstance;
+import org.apache.linkis.instance.label.dao.InsLabelRelationDao;
+import org.apache.linkis.instance.label.dao.InstanceInfoDao;
+import org.apache.linkis.instance.label.entity.InsPersistenceLabel;
+import org.apache.linkis.instance.label.entity.InstanceInfo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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 static org.junit.jupiter.api.Assertions.assertTrue;
+
+/** DefaultInsLabelService Tester */
+@ExtendWith(MockitoExtension.class)
+public class DefaultInsLabelServiceTest {
+
+ @InjectMocks private DefaultInsLabelService defaultInsLabelService;
+
+ @Mock private InsLabelRelationDao insLabelRelationDao;
+
+ @Mock private InstanceInfoDao instanceInfoDao;
+
+ @Mock private InstanceInfoDao instanceDao;
+
+ @Test
+ public void testRemoveLabelsFromInstance() throws Exception {
+ // TODO: Test goes here...
+ List<InsPersistenceLabel> labelsCandidateRemoved = new ArrayList<>();
+ InsPersistenceLabel insPersistenceLabel = new InsPersistenceLabel();
+ insPersistenceLabel.setId(1);
+ insPersistenceLabel.setLabelKey("testLabelKey");
+ insPersistenceLabel.setStringValue("testStringValue");
+ labelsCandidateRemoved.add(insPersistenceLabel);
+ ServiceInstance serviceInstance = new ServiceInstance();
+ serviceInstance.setInstance("testInstance");
+ serviceInstance.setApplicationName("testApplicationName");
+ Mockito.when(insLabelRelationDao.searchLabelsByInstance(serviceInstance.getInstance()))
+ .thenReturn(labelsCandidateRemoved);
+ Mockito.doNothing()
+ .when(insLabelRelationDao)
+ .dropRelationsByInstance(serviceInstance.getInstance());
+ defaultInsLabelService.removeLabelsFromInstance(serviceInstance);
+ }
+
+ @Test
+ public void testListAllInstanceWithLabel() throws Exception {
+ // TODO: Test goes here...
+ List<InstanceInfo> list = new ArrayList<>();
+ InstanceInfo instanceInfo = new InstanceInfo();
+ instanceInfo.setInstance("testInstance");
+ instanceInfo.setApplicationName("testApplicationName");
+ instanceInfo.setId(1);
+ list.add(instanceInfo);
+ Mockito.when(defaultInsLabelService.listAllInstanceWithLabel()).thenReturn(list);
+ List<InstanceInfo> list1 = defaultInsLabelService.listAllInstanceWithLabel();
+ assertTrue(list.equals(list1));
+ }
+
+ @Test
+ public void testGetInstancesByNames() throws Exception {
+ // TODO: Test goes here...
+ String appName = "testApplicationName";
+ List<ServiceInstance> list = new ArrayList<>();
+ ServiceInstance serviceInstance = new ServiceInstance();
+ serviceInstance.setInstance("testInstance");
+ serviceInstance.setApplicationName("testApplicationName");
+ list.add(serviceInstance);
+ Mockito.when(insLabelRelationDao.getInstancesByNames(appName)).thenReturn(list);
+ List<ServiceInstance> list1 = defaultInsLabelService.getInstancesByNames(appName);
+ assertTrue(list.equals(list1));
+ }
+
+ @Test
+ public void testRemoveInstance() throws Exception {
+ // TODO: Test goes here...
+ ServiceInstance serviceInstance = new ServiceInstance();
+ serviceInstance.setInstance("testInstance");
+ Mockito.doNothing().when(instanceInfoDao).removeInstance(serviceInstance);
+ defaultInsLabelService.removeInstance(serviceInstance);
+ }
+
+ @Test
+ public void testGetInstanceInfoByServiceInstance() throws Exception {
+ // TODO: Test goes here...
+ InstanceInfo instanceInfo = new InstanceInfo();
+ instanceInfo.setInstance("testInstance");
+ instanceInfo.setApplicationName("testApplicationName");
+ instanceInfo.setId(1);
+ ServiceInstance serviceInstance = new ServiceInstance();
+ serviceInstance.setInstance("testInstance");
+ serviceInstance.setApplicationName("testApplicationName");
+ Mockito.when(instanceInfoDao.getInstanceInfoByServiceInstance(serviceInstance))
+ .thenReturn(instanceInfo);
+ InstanceInfo instanceInfo1 =
+ defaultInsLabelService.getInstanceInfoByServiceInstance(serviceInstance);
+ assertTrue(instanceInfo1.equals(instanceInfo));
+ }
+
+ @Test
+ public void testUpdateInstance() throws Exception {
+ // TODO: Test goes here...
+ InstanceInfo instanceInfo = new InstanceInfo();
+ instanceInfo.setInstance("testInstance1");
+ instanceInfo.setApplicationName("testApplicationName1");
+ instanceInfo.setId(1);
+ Mockito.doNothing().when(instanceInfoDao).updateInstance(instanceInfo);
+ defaultInsLabelService.updateInstance(instanceInfo);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org