diff --git a/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/ChartTest.java b/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/ChartTest.java index 941f585..2aabf38 100644 --- a/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/ChartTest.java +++ b/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/ChartTest.java @@ -21,11 +21,7 @@ import ec.tstoolkit.timeseries.simplets.TsData; import ec.tstoolkit.timeseries.simplets.TsFrequency; import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; import java.net.URI; -import javax.imageio.ImageIO; import javax.ws.rs.client.Entity; import javax.ws.rs.core.Application; import javax.ws.rs.core.MediaType; @@ -90,24 +86,11 @@ public void chartFromTs() throws JsonProcessingException { case "image/svg+xml": String svgImage = resp.readEntity(String.class); Assert.assertNotNull(svgImage); - - try (PrintWriter out = new PrintWriter(String.format("C:\\Temp\\%s.svg", xmlTsData.name))) { - out.println(svgImage); - } catch (IOException ex) { - Assert.fail(ex.getMessage()); - } break; case "image/png": case "image/jpeg": BufferedImage image = resp.readEntity(BufferedImage.class); Assert.assertNotNull(image); - String subType = resp.getMediaType().getSubtype(); - try { - String path = System.getProperty("java.io.tmpdir"); - ImageIO.write(image, subType, new File(String.format(path + "%s.%s", xmlTsData.name, subType))); - } catch (IOException ex) { - Assert.fail(ex.getMessage()); - } break; } } diff --git a/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/NewXMLTest.java b/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/NewXMLTest.java index 174ad88..d34d99e 100644 --- a/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/NewXMLTest.java +++ b/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/NewXMLTest.java @@ -69,7 +69,9 @@ import org.glassfish.jersey.test.JerseyTest; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.ClassRule; import org.junit.Test; +import org.junit.rules.TemporaryFolder; /** * Tests for the outlier detection service @@ -81,6 +83,9 @@ public class NewXMLTest extends JerseyTest { private final static String INFOSET = "test/infoset", INFO = "test/info", TSDATA = "test/tsdata", X13_REQUEST = "test/x13/request"; private static JerseyWebTarget jwt; + @ClassRule + public static TemporaryFolder temp = new TemporaryFolder(); + @Override protected Application configure() { Logger logger = Logger.getGlobal(); @@ -91,7 +96,6 @@ protected Application configure() { .register(ec.nbb.ws.filters.GZipWriterInterceptor.class) .register(ec.nbb.ws.filters.GZipReaderInterceptor.class) .register(ec.nbb.demetra.filters.ChartBodyWriter.class) - //.register(MyJacksonJsonProvider.class) .register(ec.nbb.ws.filters.CORSFilter.class) .register(new LoggingFilter(logger, true)); } @@ -103,8 +107,7 @@ protected URI getBaseUri() { @BeforeClass public static void setupJerseyLog() throws Exception { - String tmp = System.getProperty("java.io.tmpdir"); - Handler fh = new FileHandler(tmp + "jersey_test.log"); + Handler fh = new FileHandler(temp.newFile("jersey_test.log").getAbsolutePath()); Logger.getLogger("").addHandler(fh); Logger.getLogger("com.sun.jersey").setLevel(Level.FINEST); } @@ -146,10 +149,6 @@ public void xmlInformation() throws Exception { Information info = new Information("y", d); XmlInformation xmlInfo = XmlInformation.create(info); - Response xmlResp = callWS(INFO, xmlInfo, MediaType.APPLICATION_XML); - Assert.assertEquals(200, xmlResp.getStatus()); - XmlInformation xml = xmlResp.readEntity(XmlInformation.class); - Response jsonResp = callWS(INFO, xmlInfo, MediaType.APPLICATION_JSON); Assert.assertEquals(200, jsonResp.getStatus()); XmlInformation json = jsonResp.readEntity(XmlInformation.class); @@ -198,15 +197,13 @@ public void xmlX13Request() { Response xmlResp = callWS(X13_REQUEST, request, MediaType.APPLICATION_XML); Assert.assertEquals(200, xmlResp.getStatus()); - XmlX13Request xml = xmlResp.readEntity(XmlX13Request.class); - Response jsonResp = callWS(X13_REQUEST, request, MediaType.APPLICATION_JSON); - if (jsonResp.getStatus() != 200) { - Assert.fail(jsonResp.readEntity(String.class)); + if (xmlResp.getStatus() != 200) { + Assert.fail(xmlResp.readEntity(String.class)); } else { - XmlX13Request json = jsonResp.readEntity(XmlX13Request.class); + XmlX13Request json = xmlResp.readEntity(XmlX13Request.class); Assert.assertEquals(s.getValues().length, json.getSeries().getValues().length); } - } + } @Test public void x13CustomWithContext() throws JsonProcessingException { diff --git a/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/OutlierTest.java b/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/OutlierTest.java index dae6a11..101650b 100644 --- a/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/OutlierTest.java +++ b/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/OutlierTest.java @@ -63,7 +63,7 @@ protected URI getBaseUri() { @Test public void outlierNewTest() { TsData d = TsData.random(TsFrequency.Monthly); - d.set(d.getObsCount() / 2, 1000); // Creating an outlier + d.set(d.getObsCount() / 2, d.get(d.getObsCount()/2)*5); // Creating an outlier XmlTsData ts = new XmlTsData(); ts.name = "ts"; ts.copy(d); diff --git a/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/X13Test.java b/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/X13Test.java index 14b97d8..fb49d82 100644 --- a/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/X13Test.java +++ b/demetra-webapp/src/test/java/ec/nbb/demetra/rest/test/X13Test.java @@ -107,29 +107,6 @@ public void x13XML() { } } - @Test - public void x13JSON() { - XmlX13Request request = new XmlX13Request(); - request.setDefaultSpecification("RSA5c"); - XmlTs s = new XmlTs(); - XmlTsData.MARSHALLER.marshal(Data.P, s); - request.setSeries(s); - request.getOutputFilter().add("arima.*"); - request.getOutputFilter().add("likelihood.*"); - request.getOutputFilter().add("residuals.*"); - request.getOutputFilter().add("*_f"); - - Response resp = callWSX13(request, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON); - - if (resp.getStatus() != 200) { - Assert.fail(resp.readEntity(String.class)); - } else { - Assert.assertEquals(200, resp.getStatus()); - XmlInformationSet set = resp.readEntity(XmlInformationSet.class); - Assert.assertNotNull(set); - } - } - @Test public void x13CustomXML() { XmlX13Request request = new XmlX13Request();