简体   繁体   English

Apache Felix-JAXRS-单元测试

[英]Apache Felix - JAXRS - Unit Testing

Its been a while since im struggling with this, so i decided to post the question here. 自从我为此苦苦挣扎以来已经有一段时间了,所以我决定在这里发布问题。

What I wanna do its just create some unit tests for my rest services. 我想做的只是为我的休息服务创建一些单元测试。 Im not having a specific error, given i changed my implementations thousands of times, thats why im not showing any code here. 我没有特定的错误,考虑到我更改了数千次实现,这就是为什么我在此处未显示任何代码的原因。

Im using Apache Felix as OSGI implementation so I would like to load the beans definitions in my unit test and mock some of them. 我使用Apache Felix作为OSGI实现,因此我想在单元测试中加载bean定义并模拟其中的一些。 Im not sure which should be the service container, so any example is welcome. 我不确定哪个应该是服务容器,因此欢迎任何示例。

Thanks in advance 提前致谢

Here is one: https://github.com/everit-org/osgi-remote-jersey 这是一个: https : //github.com/everit-org/osgi-remote-jersey

See the readme for details, how the extender works. 有关扩展程序如何工作的详细信息,请参见自述文件。

Tests are placed into the tests module. 测试被放入测试模块。 If we run "mvn install", first an equinox than a felix environment is started with a random jetty port. 如果我们运行“ mvn install”,则首先使用随机码头端口启动比felix环境更高的春分。 The tests run on these OSGi containers. 测试在这些OSGi容器上运行。

If you want to check the content of the container, you can 如果要检查容器的内容,可以

  • Go to tests/target/eosgi-dist/felixtest/bin directory 转到tests / target / eosgi-dist / felixtest / bin目录
  • start runConsole.sh (or runConsole.bat on windows) 启动runConsole.sh(或Windows上的runConsole.bat)
  • Check the log where the Jetty server is started (or write a fix port in the pom.xml) 检查启动Jetty服务器的日志(或在pom.xml中写入一个修复端口)
  • Open the webconsole at localhost:port/system/console while the container is running 在容器运行时,在localhost:port / system / console上打开Webconsole。

If you opened the modules in eclipse as a maven project, you can Drag&Drop your projects from Eclipse project explorer to the always-on-top deployer window that appears after the container is started. 如果您将Eclipse中的模块作为Maven项目打开,则可以将项目从Eclipse项目资源管理器拖放到容器启动后出现的始终位于最上端的部署程序窗口中。

If you add/remove dependencies in the tests, you can 如果您在测试中添加/删除依赖项,则可以

  • Check the number that appears on the deployer window (the port where the deployer listens). 检查在部署程序窗口(部署程序侦听的端口)上显示的数字。 This will be the port 这将是港口
  • Run "mvn eosgi:dist -Deosgi.servicePort= port " 运行“ mvn eosgi:dist -Deosgi.servicePort = port

Here's another example: https://bitbucket.org/amdatu/amdatu-web/src 这是另一个示例: https : //bitbucket.org/amdatu/amdatu-web/src

It is the source code for the web components, one of which is a REST implementation. 它是Web组件的源代码,其中之一是REST实现。 The source includes tests that run in an OSGi framework and test REST endpoints. 来源包括在OSGi框架中运行的测试和测试REST端点。 The whole project should be run in Eclipse with the Bndtools plugin. 整个项目应使用Bndtools插件在Eclipse中运行。

If you want to learn more about the components themselves: 如果您想了解有关组件本身的更多信息:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM