Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring Boot-如何测试映像是否正确提供_Java_Image_Testing_Web Applications_Spring Boot - Fatal编程技术网

Java Spring Boot-如何测试映像是否正确提供

Java Spring Boot-如何测试映像是否正确提供,java,image,testing,web-applications,spring-boot,Java,Image,Testing,Web Applications,Spring Boot,我有一个显示图像的web应用程序。我想做一个测试,检查图像是否正确显示 我在root/src/test/resources/static/images/Head.png中找到了该图像 我的代码是: 这会将图像返回给我 ResponseEntity<byte[]> entity = new TestRestTemplate().getForEntity("http://localhost/images/Head.png", byte[].class); 现在,我尝试检查内容是否相同,

我有一个显示图像的web应用程序。我想做一个测试,检查图像是否正确显示

我在
root/src/test/resources/static/images/Head.png
中找到了该图像

我的代码是:

这会将图像返回给我

ResponseEntity<byte[]> entity = new TestRestTemplate().getForEntity("http://localhost/images/Head.png", byte[].class);

现在,我尝试检查内容是否相同,但不起作用。我收到一个
FileNotFoundException

final File fichero = new File("/images/Head.png");
final FileInputStream ficheroStream = new FileInputStream(fichero);
final byte[] contenido = new byte[(int)fichero.length()];
ficheroStream.read(contenido);
assertEquals("Wrong content\n", entity.getBody(), contenido);
如何测试接收到的图像和存储在服务器中的图像是否相同?谢谢,我解决了

final InputStream reader = getClass().getResourceAsStream("/static/images/Head.png");
final byte[] contenido = new byte[442526];
reader.read(contenido);
然后,比较:

assertTrue("Wrong content\n", Arrays.equals(entity.getBody(), contenido));
reader.close();
我解决了

final InputStream reader = getClass().getResourceAsStream("/static/images/Head.png");
final byte[] contenido = new byte[442526];
reader.read(contenido);
然后,比较:

assertTrue("Wrong content\n", Arrays.equals(entity.getBody(), contenido));
reader.close();

FileNotFoundException
发生的原因是您指定的文件路径不正确。是的,我知道。但是我应该指定哪条路径来识别它。或者我应该使用另一种方式获取文件内容吗?可能会出现重复的
FileNotFoundException
,因为您指定的文件路径不正确。是的,我知道。但是我应该指定哪条路径来识别它。或者我应该使用另一种方式来获取我的文件的内容?可能是