|
| 1 | +package com.github.jsonldjava.sesame; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertTrue; |
| 4 | + |
| 5 | +import java.io.StringReader; |
| 6 | +import java.io.StringWriter; |
| 7 | +import java.util.Locale; |
| 8 | + |
| 9 | +import org.junit.Test; |
| 10 | +import org.openrdf.model.Model; |
| 11 | +import org.openrdf.model.util.ModelUtil; |
| 12 | +import org.openrdf.rio.RDFFormat; |
| 13 | +import org.openrdf.rio.Rio; |
| 14 | + |
| 15 | +/** |
| 16 | + * Test for locale-insensitive numeric representations that match the XML Schema |
| 17 | + * Datatype specification. |
| 18 | + * |
| 19 | + * @author Peter Ansell p_ansell@yahoo.com |
| 20 | + * @see <a href="https://github.com/jsonld-java/jsonld-java/issues/131">Github |
| 21 | + * issue #133</a> |
| 22 | + */ |
| 23 | +public class SesameLocaleNumericTest { |
| 24 | + |
| 25 | + @Test |
| 26 | + public void testLocaleUS() throws Exception { |
| 27 | + Locale oldDefault = Locale.getDefault(); |
| 28 | + |
| 29 | + try { |
| 30 | + Locale.setDefault(Locale.US); |
| 31 | + String input = getTestString(); |
| 32 | + Model parse = Rio.parse(new StringReader(input), "", RDFFormat.JSONLD); |
| 33 | + |
| 34 | + StringWriter output = new StringWriter(); |
| 35 | + Rio.write(parse, output, RDFFormat.JSONLD); |
| 36 | + |
| 37 | + System.out.println(output); |
| 38 | + |
| 39 | + Model reparse = Rio.parse(new StringReader(output.toString()), "", RDFFormat.JSONLD); |
| 40 | + |
| 41 | + assertTrue(ModelUtil.equals(parse, reparse)); |
| 42 | + } finally { |
| 43 | + Locale.setDefault(oldDefault); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testLocaleFrench() throws Exception { |
| 49 | + Locale oldDefault = Locale.getDefault(); |
| 50 | + |
| 51 | + try { |
| 52 | + Locale.setDefault(Locale.FRANCE); |
| 53 | + String input = getTestString(); |
| 54 | + Model parse = Rio.parse(new StringReader(input), "", RDFFormat.JSONLD); |
| 55 | + |
| 56 | + StringWriter output = new StringWriter(); |
| 57 | + Rio.write(parse, output, RDFFormat.JSONLD); |
| 58 | + |
| 59 | + System.out.println(output); |
| 60 | + |
| 61 | + Model reparse = Rio.parse(new StringReader(output.toString()), "", RDFFormat.JSONLD); |
| 62 | + |
| 63 | + assertTrue(ModelUtil.equals(parse, reparse)); |
| 64 | + } finally { |
| 65 | + Locale.setDefault(oldDefault); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + private String getTestString() { |
| 70 | + return "{" + "\"@id\": \"http://www.ex.com/product\"," + "\"http://schema.org/price\": {" |
| 71 | + + "\"@value\": 100.00" + "}}}"; |
| 72 | + } |
| 73 | +} |
0 commit comments