带有get和requestBody的WebTestClient不可用

问题描述

我有一个应用程序,其中使用Get方法定义了一个api。它还期望请求主体,然后将其映射到POJO。我正在尝试使用webTestClient测试此控制器。但是我看不到使用get()方法发送请求正文的选项。不确定我是否以正确的方式定义了webTestClient。

我的控制器如下:

import java.awt.Color;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
public class Grey {

    public static void main(String[] args)  {
        File ogImg = new File(args[0]);
        String fileName = ogImg.getName();
        String newName = stripExt(fileName);
        BufferedImage img = null;
        try {
            img = ImageIO.read(ogImg);
            BufferedImage greyscale = new BufferedImage(img.getWidth(),img.getHeight(),BufferedImage.TYPE_INT_RGB);
            
            for (int i = 0; i < img.getWidth(); i++)    {
                for (int j = 0; j < img.getHeight(); j++)   {
                    Color c = new Color(img.getRGB(i,j));
                    int r = c.getRed();
                    int g = c.getGreen();
                    int b = c.getBlue();
                    
                    int grey = (int)((0.3 * r) + (0.59 * g) +(0.11 * b)); 
                    
                    Color GREY = new Color(grey,grey,grey);
                    greyscale.setRGB(i,j,GREY.getRGB());
                }
            }
            
            ImageIO.write(greyscale,"png",new File("C:\\Users\\David\\Downloads\\" + newName + "_grey.png"));
        } catch (IOException e) {
        }
    }
    
    public static String stripExt(String s) {
        int dot = s.lastIndexOf('.');
        return s.substring(0,dot);
    }
}

我的测试方法

@GetMapping
public Flux<ResponseBody> getAllResources(@RequestBody Resource resource) {
//related code here...
}

我在想,因为控制器中允许使用get调用将对象绑定到POJO,所以应该有某种方法可以使用webTestClient对其进行测试。

解决方法

尝试使用:

webTestClient.method(HttpMethod.GET)

代替:

webTestClient.get()

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...