I've a web app which displays an image. I want to do a test that checks that the image is correctly showed.
I've the image in root/src/test/resources/static/images/Head.png
.
My code is:
This returns me the image.
ResponseEntity<byte[]> entity = new TestRestTemplate().getForEntity("http://localhost/images/Head.png", byte[].class);
This checks that the length of the image received is the correct.
assertEquals("Wrong length\n", entity.getHeaders().getContentLength(), 442526);
And now, I try to check that the content is the same, but doesn't work. I receive a 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);
How could I test that the image received and the image I store in my server are the same? Thanks
Aucun commentaire:
Enregistrer un commentaire