Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >为shenyu的PortUtils.findPort添加单元测试

为shenyu的PortUtils.findPort添加单元测试

作者头像
阿超
发布于 2023-05-11 11:08:06
发布于 2023-05-11 11:08:06
15500
代码可运行
举报
文章被收录于专栏:快乐阿超快乐阿超
运行总次数:0
代码可运行

爱好自由是人的天性,但往往过度而陷于放纵。斯宾诺莎

今天为shenyushenyu-client-core模块下添加了PortUtils.findPorttest case

https://github.com/apache/shenyu/pull/4604

对应的代码如下:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
/*
 * 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.utils;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;

/**
 * Test for {@link PortUtils}.
 */
public class PortUtilsTest {

    @Test
    public void testFindPort() {
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
        beanDefinition.setBeanClass(TomcatServletWebServerFactory.class);
        beanFactory.registerBeanDefinition("webServerFactory", beanDefinition);

        int port = PortUtils.findPort(beanFactory);
        Assertions.assertEquals(8080, port);
    }

}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-05-03,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
mp方法注入支持typeHandler
#{et.name,typeHandler=org.dromara.streamquery.stream.plugin.mybatisplus.JsonFieldHandlerTest$JsonFieldHandler} 即可直接指定typeHandler
阿超
2023/06/23
2730
IDEA阅读spring源码并调试「建议收藏」
目标:搭建起Spring源码阅读和代码调试跟踪的环境,顺便建立一个简单的Demo,能够调试Spring的源代码
全栈程序员站长
2022/09/22
6690
IDEA阅读spring源码并调试「建议收藏」
spring获取AliasFor增强的注解
此处是关于issue:https://gitee.com/dromara/stream-query/issues/I7BSNV
阿超
2023/06/23
2410
Apache-ShenYu让h2数据库持久化到文件中
今天发现使用 调试h2数据库 中的方式连接h2数据库却不行,由于目录里没有创建,所以我们得先创建:
阿超
2024/10/12
1250
终于,月薪过5万了!
本文主要详解bean的生命周期,分为13个环节,每个环节中spring都提供了一些扩展点,我们都将进行详细说明,让大家全面掌握这块的知识。
路人甲Java
2020/04/08
7920
终于,月薪过5万了!
spring-state-machine持久化
https://docs.spring.io/spring-statemachine/docs/current/reference/#statemachine-examples-datapersist
阿超
2023/11/07
3070
stream-query开源合规
然后使用license-eye,我是用brew install license-eye
阿超
2024/03/29
2330
ShenYu 网关开发:在本地启用运行
无论什么方式安装,都需要先初始化数据库,这里我选择了在本地通过 Docker 启用一个 mysql 5.7
晓晨
2022/09/01
1.2K0
ShenYu 网关开发:在本地启用运行
Spring5源码 - 02 Bean和Java对象的区别与猜想验证BeanDefinition
Spring创建的Bean 和 我们提供的Class对象 有什么关系吗? 一定是我们提供的这个对象实例吗?
小小工匠
2021/08/17
4410
不一样的视角来学习Spring源码之容器与Bean---下
此时容器中只有一个Bean,显然config配置类的注解都没有被解析,此时就需要添加工厂后置处理器来解析这些注解了,从而可以往容器中添加更多的bean的定义信息
大忽悠爱学习
2022/05/10
2500
不一样的视角来学习Spring源码之容器与Bean---下
调试h2数据库
在apache-shenyu中也默认用h2数据库作为默认数据库,方便开发、演示、学习、轻量化部署等
阿超
2024/08/23
1330
apache-shenyu插件配置规则处理杂谈
https://github.com/apache/shenyu/issues/5966
阿超
2025/03/24
830
Spring Boot单元测试
Spring Boot 中进行单元测试是一个常见的做法,可以帮助你验证应用程序的各个组件是否按预期工作。所以我们有必要去学习一番!
终有救赎
2023/10/16
3090
Spring Boot单元测试
Spring之动态注册bean
如我之前做个的一个支持扫表的基础平台,使用者只需要添加基础配置 + Groovy任务,就可以丢到这个平台上面来运行了,而这个基础平台是一直都在运行的,所以在新来任务时,最直观需要注册的就是 DataSource 数据源这个bean了,那么可以怎么玩?
一灰灰blog
2018/08/07
1.9K0
Spring之动态注册bean
开发dubbo应用程序(一)入门demo详解
https://github.com/apache/dubbo-samples/tree/2.6.x
Dream城堡
2019/08/07
1.1K0
开发dubbo应用程序(一)入门demo详解
Apache-ShenYu支持namespace功能
https://github.com/apache/shenyu-dashboard/pull/462
阿超
2024/08/23
1160
RPC框架是啥之Apache CXF一款WebService RPC框架入门教程
Apache CXF是一个开源的WebService RPC框架,是由Celtix和Codehaus XFire合并而成的。它可以说是一个功能齐全的集合。
Java猫说
2019/05/08
1.2K0
RPC框架是啥之Apache CXF一款WebService RPC框架入门教程
stream-query的BeanHelper拷贝支持Converter
这里可以自定义Converter,此处new CopyOption()是不带默认内置的Converter的,但是CopyOption.of()是带的
阿超
2024/01/23
1480
Springboot自动装配整理
再模仿Spring Cloud Feign源码解析 中的@EnableFeignClients代码写一个我们自己的标签
算法之名
2019/11/23
4530
七种 BeanDefinition,各显其能!
在 Spring 容器中,我们广泛使用的是一个一个的 Bean,BeanDefinition 从名字上就可以看出是关于 Bean 的定义。
江南一点雨
2023/09/09
3530
七种 BeanDefinition,各显其能!
相关推荐
mp方法注入支持typeHandler
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验