Skip to content

Commit

Permalink
Merge pull request #104 from jburel/unit_test
Browse files Browse the repository at this point in the history
adjust tests
  • Loading branch information
sbesson authored Jul 16, 2020
2 parents c664901 + 58fa98d commit 1c5665f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 30 deletions.
18 changes: 9 additions & 9 deletions src/test/java/ome/io/nio/itests/PlaneReadUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ private void createPlanes() throws IOException {
path = new PixelsService(ROOT).getPixelsPath(pixels.getId());
originalDigests = new byte[planeCount][];

FileOutputStream stream = new FileOutputStream(path);

for (int i = 0; i < planeCount; i++) {
byte[] plane = createPlane(planeSize.intValue(), (byte) (i - 128));
originalDigests[i] = Helper.calculateMessageDigest(plane);
stream.write(plane);
try (FileOutputStream stream = new FileOutputStream(path)) {
for (int i = 0; i < planeCount; i++) {
byte[] plane = createPlane(planeSize.intValue(), (byte) (i - 128));
originalDigests[i] = Helper.calculateMessageDigest(plane);
stream.write(plane);
}
}
}

Expand All @@ -107,7 +107,7 @@ protected void setup() throws Exception {
public void testInitialPlane() throws IOException,
DimensionsOutOfBoundsException {
PixelsService service = new PixelsService(ROOT);
PixelBuffer pixbuf = service.getPixelBuffer(pixels);
PixelBuffer pixbuf = service.getPixelBuffer(pixels, true);
PixelData plane = pixbuf.getPlane(0, 0, 0);

byte[] messageDigest = Helper.calculateMessageDigest(plane.getData());
Expand All @@ -120,7 +120,7 @@ public void testInitialPlane() throws IOException,
public void testLastPlane() throws IOException,
DimensionsOutOfBoundsException {
PixelsService service = new PixelsService(ROOT);
PixelBuffer pixbuf = service.getPixelBuffer(pixels);
PixelBuffer pixbuf = service.getPixelBuffer(pixels, true);
PixelData plane = pixbuf.getPlane(pixels.getSizeZ() - 1, pixels
.getSizeC() - 1, pixels.getSizeT() - 1);
int digestOffset = getDigestOffset(pixels.getSizeZ() - 1, pixels
Expand All @@ -136,7 +136,7 @@ public void testLastPlane() throws IOException,
public void testAllPlanes() throws IOException,
DimensionsOutOfBoundsException {
PixelsService service = new PixelsService(ROOT);
PixelBuffer pixbuf = service.getPixelBuffer(pixels);
PixelBuffer pixbuf = service.getPixelBuffer(pixels, true);

String newMessageDigest;
String oldMessageDigest;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/ome/io/nio/itests/PlaneWriteUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testLowerPlaneWrite() throws IOException,
byte[] testPlane = getTestPlane();
pixbuf.setPlane(testPlane, 0, 0, 0);

pixbuf = service.getPixelBuffer(pixels);
pixbuf = service.getPixelBuffer(pixels, true);
PixelData plane = pixbuf.getPlane(0, 0, 0);
Assert.assertNotNull(plane);
byte[] newMD = Helper.calculateMessageDigest(plane.getData());
Expand All @@ -85,7 +85,7 @@ public void testUpperPlaneWrite() throws IOException,
byte[] testPlane = getTestPlane();
pixbuf.setPlane(testPlane, z, c, t);

pixbuf = service.getPixelBuffer(pixels);
pixbuf = service.getPixelBuffer(pixels, true);
PixelData plane = pixbuf.getPlane(z, c, t);
Assert.assertNotNull(plane);
byte[] newMD = Helper.calculateMessageDigest(plane.getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ ShareData[] loadData() throws Exception {

byte[] loadFile(File file) throws Exception{
int size = (int) file.length();
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[size];
fis.read(buf);
fis.close();
try (FileInputStream fis = new FileInputStream(file)) {
fis.read(buf);
}
return buf;
}

Expand Down
9 changes: 6 additions & 3 deletions src/test/java/ome/services/db/HibernateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.FilterDefinition;
import org.springframework.util.ResourceUtils;

Expand All @@ -28,8 +28,11 @@ public class HibernateUtil {
File mockFilter = ResourceUtils
.getFile("classpath:mock_filters.hbm.xml");
Properties props = new Properties();
props.load(new FileInputStream(local));
AnnotationConfiguration cfg = new AnnotationConfiguration();
try (FileInputStream stream = new FileInputStream(local)) {
props.load(stream);
}

Configuration cfg = new Configuration();
cfg.addFilterDefinition(new FilterDefinition("securityFilter",
"1=1", new HashMap()));
cfg.configure(testCfg);
Expand Down
23 changes: 10 additions & 13 deletions src/test/java/ome/services/utests/SVGRasterizerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package ome.services.utests;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

Expand All @@ -41,23 +42,19 @@
public class SVGRasterizerTest {

@Test(groups = {"unit", "ticket:11438"})
public void testCreateJPEG() {
InputStream input = IOUtils.toInputStream(
"<svg xmlns=\"http://www.w3.org/2000/svg\"" +
public void testCreateJPEG() throws IOException {
String value = "<svg xmlns=\"http://www.w3.org/2000/svg\"" +
" xmlns:xlink=\"http://www.w3.org/1999/xlink\">" +
"<rect x=\"10\" y=\"10\" height=\"100\" width=\"100\"" +
" style=\"stroke:#ff0000; fill: #0000ff\"/>" +
"</svg>");
SVGRasterizer rasterizer = new SVGRasterizer(input);
rasterizer.setQuality(1);
OutputStream outputStream = new ByteArrayOutputStream();
try {
"<rect x=\"10\" y=\"10\" height=\"100\" width=\"100\"" +
" style=\"stroke:#ff0000; fill: #0000ff\"/>" +
"</svg>";
try (InputStream input = IOUtils.toInputStream(value, "UTF-8");
OutputStream outputStream = new ByteArrayOutputStream()) {
SVGRasterizer rasterizer = new SVGRasterizer(input);
rasterizer.setQuality(1);
rasterizer.createJPEG(outputStream);
} catch (TranscoderException te) {
Assert.fail("JPEG encoding failed with exception.", te);
} finally {
IOUtils.closeQuietly(outputStream);
IOUtils.closeQuietly(input);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;
import java.util.Random;

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import ome.api.IPixels;
Expand Down Expand Up @@ -80,6 +81,12 @@ protected void setUp()
renderer = new Renderer(quantumFactory, renderingModels,
pixels, settings, pixelBuffer, lutProvider);
}

@AfterClass
protected void tearDown()
{
renderer.close();
}

protected QuantumFactory createQuantumFactory()
{
Expand Down

0 comments on commit 1c5665f

Please sign in to comment.