Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneBinder committed May 26, 2016
1 parent d27e649 commit 8b1010f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 21 deletions.
16 changes: 15 additions & 1 deletion controllers/nifconverter/src/test/resources/data/source_xlf.xlf
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?><xliff version="1.2"><file source-language="en" target-language="it" datatype="x-test" original="file.ext"><body><trans-unit id="1"><source>Hello World!</source><target>Ciao Mondo!</target></trans-unit><trans-unit id="2"><source>What a beatiful day!</source><target>Che bella giornata!</target></trans-unit></body></file></xliff>
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2">
<file source-language="en" target-language="it" datatype="x-test" original="file.ext">
<body>
<trans-unit id="1">
<source>Hello World!</source>
<target>Ciao Mondo!</target>
</trans-unit>
<trans-unit id="2">
<source>What a beatiful day!</source>
<target>Che bella giornata!</target>
</trans-unit>
</body>
</file>
</xliff>
2 changes: 1 addition & 1 deletion filters/internationalization-filter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<dependency>
<groupId>eu.freme.bservices</groupId>
<artifactId>internationalization</artifactId>
<version>0.3</version>
<version>0.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>eu.freme.bservices</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ public void doFilter(ServletRequest req, ServletResponse res,

if (!roundtripping) {
chain.doFilter(bssr, res);
nif.close();
return;
}

Expand All @@ -316,6 +317,7 @@ public void doFilter(ServletRequest req, ServletResponse res,
new ByteArrayInputStream(baosData), informat, outformat);

chain.doFilter(bssr, dummyResponse);
nif.close();

ServletOutputStream sos = httpResponse.getOutputStream();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ public void close() {
} else {
model.write(writer);
}
outputStream.close();
/*
// dummy deletion to detect file access
if (file!=null && file.exists()) {
boolean fileDeleted = file.delete();
logger.debug("fileDeleted: "+fileDeleted);
}*/
}

} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public class InternationalizationAPITest {
Logger logger = Logger.getLogger(InternationalizationAPITest.class);
RestHelper restHelper;

InternationalizationAPI InternationalizationAPI;
InternationalizationAPI internationalizationAPI;


public InternationalizationAPITest() throws UnirestException {
ApplicationContext context = IntegrationTestSetup.getContext("internationalization-test-package.xml");// FREMEStarter.startPackageFromClasspath("ratelimiter-test-package.xml");
th = context.getBean(TestHelper.class);
restHelper = context.getBean(RestHelper.class);
InternationalizationAPI = context.getBean(InternationalizationAPI.class);
internationalizationAPI = context.getBean(InternationalizationAPI.class);
classLoader = getClass().getClassLoader();
}

Expand All @@ -61,7 +61,7 @@ public void testEInternationalizationAPIXliff() {
InputStream is = getClass().getResourceAsStream(
"/nifConversion/src1/test1.xlf");
try {
Reader nifReader = InternationalizationAPI.convertToTurtle(is,
Reader nifReader = internationalizationAPI.convertToTurtle(is,
InternationalizationAPI.MIME_TYPE_XLIFF_1_2);
Model model = ModelFactory.createDefaultModel();
model.read(nifReader, null,
Expand All @@ -82,17 +82,18 @@ public void testEInternationalizationAPIXliff() {
}
}

//@Test
public void testEInternationalizationAPIHTML() {
@Test
public void testEInternationalizationAPIHTML() throws IOException {

InputStream is = getClass().getResourceAsStream(
"/nifConversion/src1/test10.html");
try {
Reader nifReader = InternationalizationAPI.convertToTurtle(is,
Reader nifReader = internationalizationAPI.convertToTurtle(is,
InternationalizationAPI.MIME_TYPE_HTML);
Model model = ModelFactory.createDefaultModel();
model.read(nifReader, null,
RDFConstants.RDFSerialization.TURTLE.toRDFLang());
nifReader.close();
Reader expectedReader = new InputStreamReader(getClass()
.getResourceAsStream(
"/nifConversion/expected_text10.html.ttl"), "UTF-8");
Expand All @@ -111,7 +112,7 @@ public void testEInternationalizationAPIXML() {
InputStream is = getClass().getResourceAsStream(
"/nifConversion/src1/test1.xml");
try {
Reader nifReader = InternationalizationAPI.convertToTurtle(is,
Reader nifReader = internationalizationAPI.convertToTurtle(is,
InternationalizationAPI.MIME_TYPE_XML);
Model model = ModelFactory.createDefaultModel();
model.read(nifReader, null,
Expand All @@ -134,8 +135,8 @@ public void testEInternationalizationAPIXML() {
public void testEInternationalizationAPIODT() throws Exception {

InputStream is = getClass().getResourceAsStream("/nifConversion/src2/TestDocument02.odt");
Reader nifReader = InternationalizationAPI.convertToTurtle(is,
InternationalizationAPI.MIME_TYPE_ODT);
Reader nifReader = internationalizationAPI.convertToTurtle(is,
internationalizationAPI.MIME_TYPE_ODT);

String result = IOUtils.toString(nifReader);
String cleanedResult = result.replaceAll("http://freme-project.eu/[^#]*#char", "http://freme-project.eu/test#char");
Expand All @@ -151,24 +152,24 @@ public void testEInternationalizationAPIODT() throws Exception {

}

@Test
//@Test
public void testEInternationalizationAPIUnsupportedMimeType() {

String unsupportedMimeType = "unsupp/mime-type";
InputStream is = getClass().getResourceAsStream(
"/nifConversion/src1/test1.xlf");
ConversionException exception = null;
try {
InternationalizationAPI.convertToTurtle(is, unsupportedMimeType);
internationalizationAPI.convertToTurtle(is, unsupportedMimeType);
} catch (ConversionException e) {
exception = e;
}
Assert.assertNotNull(exception);
UnsupportedMimeTypeException unsuppException = new
UnsupportedMimeTypeException(
unsupportedMimeType, new String[] {
InternationalizationAPI.MIME_TYPE_XLIFF_1_2,
InternationalizationAPI.MIME_TYPE_HTML });
internationalizationAPI.MIME_TYPE_XLIFF_1_2,
internationalizationAPI.MIME_TYPE_HTML });
Assert.assertEquals(
unsuppException.getMessage(),
exception.getMessage());
Expand All @@ -184,7 +185,7 @@ public void testEInternationalizationAPIUnsupportedMimeType() {
// including markups.
// InputStream originalFile = getClass().getResourceAsStream(
// "/roundtripping/input-html.txt");
// Reader skeletonReader = InternationalizationAPI
// Reader skeletonReader = internationalizationAPI
// .convertToTurtleWithMarkups(originalFile,
// EInternationalizationAPI.MIME_TYPE_HTML);
//
Expand All @@ -207,7 +208,7 @@ public void testEInternationalizationAPIUnsupportedMimeType() {
// InputStream skeletonStream = new FileInputStream(skeletonFile);
// InputStream turtle = getClass().getResourceAsStream(
// "/roundtripping/input-turtle.txt");
// Reader reader = InternationalizationAPI.convertBack(skeletonStream,
// Reader reader = internationalizationAPI.convertBack(skeletonStream,
// turtle);
// br = new BufferedReader(reader);
// while ((line = br.readLine()) != null) {
Expand All @@ -229,9 +230,9 @@ public void testRoundTripping(String originalFilePath, String enrichmentPath)
// including markups.
InputStream originalFile = getClass().getResourceAsStream(
originalFilePath);
Reader skeletonReader = InternationalizationAPI
Reader skeletonReader = internationalizationAPI
.convertToTurtleWithMarkups(originalFile,
InternationalizationAPI.MIME_TYPE_HTML);
internationalizationAPI.MIME_TYPE_HTML);

// STEP 2: save the skeleton file somewhere on the machine
BufferedReader br = new BufferedReader(skeletonReader);
Expand All @@ -249,7 +250,7 @@ public void testRoundTripping(String originalFilePath, String enrichmentPath)
// and the enriched file
InputStream skeletonStream = new FileInputStream(skeletonFile);
InputStream turtle = getClass().getResourceAsStream(enrichmentPath);
Reader reader = InternationalizationAPI.convertBack(skeletonStream,
Reader reader = internationalizationAPI.convertBack(skeletonStream,
turtle);
br = new BufferedReader(reader);
while ((line = br.readLine()) != null) {
Expand Down Expand Up @@ -283,7 +284,7 @@ public void testRoundtrippingMultipleValuesAttrs()
// getClass().getResourceAsStream("/roundtripping/short-html.html");
// try {
// Reader nifReader =
// InternationalizationAPI.convertToTurtle(fileToConvert,
// internationalizationAPI.convertToTurtle(fileToConvert,
// EInternationalizationAPI.MIME_TYPE_HTML);
// File nifFile = new File(System.getProperty("user.home"),
// "convertedHtml.ttl");
Expand Down

0 comments on commit 8b1010f

Please sign in to comment.