|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.shenyu.client.core.disruptor.subcriber; |
| 19 | + |
| 20 | +import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; |
| 21 | +import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO; |
| 22 | +import org.apache.shenyu.register.common.type.DataType; |
| 23 | +import org.junit.jupiter.api.BeforeEach; |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +import java.util.ArrayList; |
| 27 | +import java.util.Collection; |
| 28 | + |
| 29 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 30 | +import static org.mockito.Mockito.mock; |
| 31 | +import static org.mockito.Mockito.verify; |
| 32 | +import static org.mockito.Mockito.never; |
| 33 | +import static org.mockito.Mockito.any; |
| 34 | +import static org.mockito.Mockito.times; |
| 35 | + |
| 36 | +/** |
| 37 | + * Test for {@link ShenyuClientMetadataExecutorSubscriber}. |
| 38 | + */ |
| 39 | +public class ShenyuClientMetadataExecutorSubscriberTest { |
| 40 | + |
| 41 | + private ShenyuClientRegisterRepository shenyuClientRegisterRepository; |
| 42 | + |
| 43 | + private ShenyuClientMetadataExecutorSubscriber executorSubscriber; |
| 44 | + |
| 45 | + @BeforeEach |
| 46 | + public void setUp() { |
| 47 | + shenyuClientRegisterRepository = mock(ShenyuClientRegisterRepository.class); |
| 48 | + executorSubscriber = new ShenyuClientMetadataExecutorSubscriber(shenyuClientRegisterRepository); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void testGetType() { |
| 53 | + DataType expected = DataType.META_DATA; |
| 54 | + DataType actual = executorSubscriber.getType(); |
| 55 | + assertEquals(expected, actual); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void testExecutorWithEmptyData() { |
| 60 | + Collection<MetaDataRegisterDTO> metaDataRegisterDTOList = new ArrayList<>(); |
| 61 | + executorSubscriber.executor(metaDataRegisterDTOList); |
| 62 | + |
| 63 | + verify(shenyuClientRegisterRepository, never()).persistInterface(any()); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void testExecutorValidData() { |
| 68 | + Collection<MetaDataRegisterDTO> metaList = new ArrayList<>(); |
| 69 | + |
| 70 | + MetaDataRegisterDTO metaDataRegisterDTO = |
| 71 | + MetaDataRegisterDTO.builder().contextPath("/test").path("/meta").pathDesc("application/json") |
| 72 | + .rpcType("http") |
| 73 | + .serviceName("UserService") |
| 74 | + .methodName("getUserInfo") |
| 75 | + .ruleName("AuthorizationRule") |
| 76 | + .parameterTypes("String, int") |
| 77 | + .rpcExt("test") |
| 78 | + .enabled(true) |
| 79 | + .host("localhost") |
| 80 | + .port(8080) |
| 81 | + .pluginNames(new ArrayList<>()) |
| 82 | + .build(); |
| 83 | + metaList.add(metaDataRegisterDTO); |
| 84 | + |
| 85 | + executorSubscriber.executor(metaList); |
| 86 | + |
| 87 | + verify(shenyuClientRegisterRepository, times(1)).persistInterface(metaDataRegisterDTO); |
| 88 | + } |
| 89 | + |
| 90 | +} |
0 commit comments