You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by ty...@apache.org on 2021/10/01 08:50:45 UTC

[incubator-shenyu] branch master updated: add test case for ShenyuClientRegisterMotanServiceImpl (#2161)

This is an automated email from the ASF dual-hosted git repository.

tydhot pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new dac22f5  add test case for ShenyuClientRegisterMotanServiceImpl (#2161)
dac22f5 is described below

commit dac22f51c7b834ac7a901998a159c7bc407740db
Author: 灰太狼 <76...@qq.com>
AuthorDate: Fri Oct 1 16:50:31 2021 +0800

    add test case for ShenyuClientRegisterMotanServiceImpl (#2161)
    
    * add test case for ShenyuClientRegisterMotanServiceImpl
    
    * adjust code format
    
    * add apache 2.0 license header
    
    Co-authored-by: 张坤 <zh...@jd.com>
---
 .../ShenyuClientRegisterMotanServiceImplTest.java  | 80 ++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/ShenyuClientRegisterMotanServiceImplTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/ShenyuClientRegisterMotanServiceImplTest.java
new file mode 100644
index 0000000..a9805c1
--- /dev/null
+++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/ShenyuClientRegisterMotanServiceImplTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.shenyu.admin.service;
+
+import org.apache.shenyu.admin.service.register.ShenyuClientRegisterMotanServiceImpl;
+import org.apache.shenyu.admin.utils.ShenyuResultMessage;
+import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.ArrayList;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test cases for ShenyuClientRegisterMotanServiceImpl.
+ */
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class ShenyuClientRegisterMotanServiceImplTest {
+    @Mock
+    private ShenyuClientRegisterMotanServiceImpl shenyuClientRegisterMotanService;
+
+    @Mock
+    private RuleService ruleService;
+
+    @Mock
+    private MetaDataService metaDataService;
+
+    @Mock
+    private SelectorService selectorService;
+
+    @Before
+    public void setup() {
+        shenyuClientRegisterMotanService = new ShenyuClientRegisterMotanServiceImpl(metaDataService, selectorService, ruleService);
+    }
+
+    @Test
+    public void testRegister() {
+        MetaDataRegisterDTO dto = buildMetaDataRegisterDTO();
+        assertEquals(ShenyuResultMessage.SUCCESS, shenyuClientRegisterMotanService.register(dto));
+    }
+
+    private MetaDataRegisterDTO buildMetaDataRegisterDTO() {
+        return MetaDataRegisterDTO.builder()
+                .appName("appNameMetaData")
+                .contextPath("contextPathMetaDataRegister")
+                .path("/shenyu")
+                .pathDesc("pathDescMetaData")
+                .rpcType("rpcTypeMetaData")
+                .serviceName("serviceName3")
+                .methodName("methodName3")
+                .ruleName("ruleNameMetaDataRegister")
+                .parameterTypes("parameterTypesMetaData")
+                .rpcExt("rpcExtMetaData")
+                .enabled(true)
+                .host("127.0.0.1")
+                .port(22000)
+                .pluginNames(new ArrayList<>())
+                .registerMetaData(true)
+                .build();
+    }
+}