如何仅为单元测试禁用球衣过滤器(使用spring-boot)(How to disable jersey filters for unit tests only (using spring-boot))
我有一个使用Jersey作为REST引擎的spring-boot应用程序。 我正在使用Jersey过滤器来验证每个请求。 问题是在REST控制器(使用JUnit)的单元测试期间禁用这些过滤器或提供模拟过滤器的适当方法是什么?
这是我有的:
Spring启动应用程序:
@PropertySource("classpath:security-api.properties") @SpringBootApplication public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } }
泽西配置文件:
@Configuration @ApplicationPath("/some/path") public class MyJerseyConfiguration extends ResourceConfig { public AnalyzerJerseyConfiguration() { packages(BaseController.class.getPackage().getName()); register(AuthorizationRequestFilter.class); register(AuthorizationResponseFilter.class); } }
I have a spring-boot application with Jersey as the REST engine. I am using Jersey filters for authenticating each request. The question is what is the appropriate way to disable these filters or provide mock filters during unit tests of the REST controllers (with JUnit)?
Here is what I have:
Spring boot application:
@PropertySource("classpath:security-api.properties") @SpringBootApplication public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } }
Jersey Configuration file:
@Configuration @ApplicationPath("/some/path") public class MyJerseyConfiguration extends ResourceConfig { public AnalyzerJerseyConfiguration() { packages(BaseController.class.getPackage().getName()); register(AuthorizationRequestFilter.class); register(AuthorizationResponseFilter.class); } }
原文:https://stackoverflow.com/questions/37538714
最满意答案
问题源于您使用介于0.00和1.00之间的大小值。 这些被解释为相对大小/百分比,在这种情况下为5%。 这就是为什么它只显示20行(0到19)。 尝试使用“50.0”代替,问题就消失了。 或者使用
TableLayout.PREFERRED
。The problem stems from you using size values between 0.00 and 1.00. These are interpreted as relative sizes/percentages, in this case 5%. That's why it's showing 20 rows only (0 to 19 inclusive). Try using "50.0" instead and the problem goes away. Or use
TableLayout.PREFERRED
.
相关问答
更多-
如果不使用布局管理器,即使用setLayout(null)时,面板的组件必须按代码布局。 大多数组件从零开始,因此不会显示。 在上面的代码中,缺少滚动窗格的位置和尺寸: jsp.setBounds(...)就像使用其他组件一样。 通常不建议自己布置组件,更好地使用LayoutManager(例如GridBagLayout,BorderLayout,...)。 请参阅Oracle教程: 课程:在容器中布置组件 The components of a panel must be lay out by code ...
-
您有JPanel的ScrollPane ,但JPanel不会更改大小以适应JButton的大小,因为您已设置其首选大小。 如果你拿出finalPan2.setPreferredSize(new Dimension(620, 540)); ,面板应调整大小以适应按钮,滚动窗格应该工作。 You have the ScrollPane for the JPanel, but the JPanel doesn't change size to accomodate for the size of the JBut ...
-
关注第3小组,请考虑以下事项: 给面板一个GridLayout(0, 3) ,它指定三列中的任意数字行。 实现Scrollable接口,让getPreferredScrollableViewportSize()返回一个Dimension ,它是按钮高度的倍数。 添加每个按钮后,给它一个合适的Action 。 添加按钮时, revalidate()面板并repaint()它。 Focusing on panel 3, consider the following: Give the panel a GridL ...
-
JScrollPane和JPanel(JScrollPane and JPanel)[2022-06-12]
所以,我做了这个非常快速的测试,对我来说工作得很好...... public class TestPane extends JPanel { public TestPane() { setBorder(new LineBorder(Color.RED)); // This is for demonstration purposes only // One should always rely on the layout manager ... -
Java,添加JScrollPane列出一个JPanel [重复](Java, adding JScrollPane to list ON a JPanel [duplicate])[2022-06-04]
将JScrollPane添加到JPanel。 public class MyClass{ public static void main(String args[]){ //Declaring JFrame, JPanel, JList, JScrollPane objects JFrame frame = new JFrame(); JPanel panel = new JPanel(); JList list; JScrollPane scroll; String[] numberTest = { ... -
好的,基本上,您需要根据JViewport和组件的高度更改getScrollableTracksViewportHeight工作方式。 您基本上希望组件跟踪视口的高度(调整自身以匹配),而视口的高度大于组件的首选高度。 当组件的首选高度大于视口时,您希望停止跟踪并允许组件“溢出”滚动窗格,例如... @Override public boolean getScrollableTracksViewportHeight() { boolean track = true; Container p ...
-
Java Swing:未使用JScrollPane添加到JPanel的组件(Java Swing: components not added to JPanel with JScrollPane)[2023-04-24]
问题源于您使用介于0.00和1.00之间的大小值。 这些被解释为相对大小/百分比,在这种情况下为5%。 这就是为什么它只显示20行(0到19)。 尝试使用“50.0”代替,问题就消失了。 或者使用TableLayout.PREFERRED 。 The problem stems from you using size values between 0.00 and 1.00. These are interpreted as relative sizes/percentages, in this case ... -
您遇到的主要问题是,当您将buttonsPane添加到窗格时,它会从滚动窗格中删除它... JScrollPane scroll = new JScrollPane(buttonsPanel); pane.add(buttonsPanel); this.add(pane, BorderLayout.CENTER); 事实上你从未真正将滚动窗格添加到任何东西也无济于事。 组件可能只有一个父组件,因此当您将buttonsPane添加到pane ,它会从滚动窗格中有效删除 相反,将HiraganaPage的布局 ...
-
JScrollPane scroll = new JScrollPane(jp); JScrollPane scroll = new JScrollPane(jp);
-
我需要在添加新组件时动态调整JPanel的大小(I need to make my JPanel resize dynamically as new components are being added to it)[2023-11-28]
我将JPanel的布局更改为GridLayout ,因此布局管理器的大小只是handeld,具体取决于面板上的组件。 JFrame f = new JFrame(); f.setLayout(new BorderLayout()); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(new GridLayout(0, 5)); JScrollPane jsp = new JS ...