You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by he...@apache.org on 2024/02/28 05:13:07 UTC

(shenyu) branch master updated: Add test case for `ShenyuClientRegisterRepositoryFactoryTest` (#5443)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new d6aabd0932 Add test case for `ShenyuClientRegisterRepositoryFactoryTest` (#5443)
d6aabd0932 is described below

commit d6aabd0932b512a0c029c44891b8b986e342a18c
Author: Divyansh200102 <14...@users.noreply.github.com>
AuthorDate: Wed Feb 28 10:43:01 2024 +0530

    Add test case for `ShenyuClientRegisterRepositoryFactoryTest` (#5443)
    
    * Add tests
    
    * Update ShenyuClientRegisterRepositoryFactoryTest.java
    
    ---------
    
    Co-authored-by: xiaoyu <xi...@apache.org>
---
 .../ShenyuClientRegisterRepositoryFactory.java     |  9 ++++
 .../ShenyuClientRegisterRepositoryFactoryTest.java | 53 ++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/ShenyuClientRegisterRepositoryFactory.java b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/ShenyuClientRegisterRepositoryFactory.java
index 8882b0e04f..7c2b0d9aa0 100644
--- a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/ShenyuClientRegisterRepositoryFactory.java
+++ b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/ShenyuClientRegisterRepositoryFactory.java
@@ -31,6 +31,15 @@ import org.apache.shenyu.spi.ExtensionLoader;
 public final class ShenyuClientRegisterRepositoryFactory {
     
     private static final Map<String, ShenyuClientRegisterRepository> REPOSITORY_MAP = new ConcurrentHashMap<>();
+
+    /**
+     * Retrieves the repository map containing mappings of register types to corresponding ShenyuClientRegisterRepository instances.
+     *
+     * @return A {@link Map} where keys are register types and values are associated {@link ShenyuClientRegisterRepository} instances.
+     */
+    public static Map<String, ShenyuClientRegisterRepository> getRepositoryMap() {
+        return REPOSITORY_MAP;
+    }
     
     /**
      * New instance shenyu client register repository.
diff --git a/shenyu-client/shenyu-client-core/src/test/java/org/apache/shenyu/client/core/register/ShenyuClientRegisterRepositoryFactoryTest.java b/shenyu-client/shenyu-client-core/src/test/java/org/apache/shenyu/client/core/register/ShenyuClientRegisterRepositoryFactoryTest.java
new file mode 100644
index 0000000000..c07b878569
--- /dev/null
+++ b/shenyu-client/shenyu-client-core/src/test/java/org/apache/shenyu/client/core/register/ShenyuClientRegisterRepositoryFactoryTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.client.core.register;
+
+import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
+import org.apache.shenyu.register.common.config.ShenyuRegisterCenterConfig;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.apache.shenyu.client.core.register.ShenyuClientRegisterRepositoryFactory.getRepositoryMap;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+public class ShenyuClientRegisterRepositoryFactoryTest {
+
+    @Mock
+    private ShenyuClientRegisterRepository repository;
+
+    @Mock
+    private ShenyuRegisterCenterConfig config;
+
+    @Test
+    public void testNewInstanceExistingRegisterType() {
+
+        when(config.getRegisterType()).thenReturn("existingType");
+
+        ShenyuClientRegisterRepositoryFactory.getRepositoryMap().put("existingType", repository);
+
+        ShenyuClientRegisterRepository returnedRepository = ShenyuClientRegisterRepositoryFactory.newInstance(config);
+
+        Assertions.assertEquals(repository, returnedRepository);
+        Assertions.assertEquals(1, getRepositoryMap().size());
+    }
+}
+