Repository: clerezza Updated Branches: refs/heads/reunited f5d9dd844 -> 01dc25b63
CLEREZZA-1026: Move some tests from rdf.core to api.impl Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/01dc25b6 Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/01dc25b6 Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/01dc25b6 Branch: refs/heads/reunited Commit: 01dc25b63217ccd0e4ea051a633bba4f041bb08f Parents: f5d9dd8 Author: Hasan <[email protected]> Authored: Wed Nov 14 04:57:07 2018 +0100 Committer: Hasan <[email protected]> Committed: Wed Nov 14 04:57:07 2018 +0100 ---------------------------------------------------------------------- .../apache/clerezza/api/impl/LanguageTest.java | 50 ++++++++ .../apache/clerezza/api/impl/UriRefTest.java | 52 ++++++++ .../api/impl/literal/LiteralFactoryTest.java | 122 +++++++++++++++++++ .../apache/clerezza/rdf/core/LanguageTest.java | 50 -------- .../clerezza/rdf/core/LiteralFactoryTest.java | 122 ------------------- .../apache/clerezza/rdf/core/UriRefTest.java | 60 --------- 6 files changed, 224 insertions(+), 232 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/clerezza/blob/01dc25b6/api.impl/src/test/java/org/apache/clerezza/api/impl/LanguageTest.java ---------------------------------------------------------------------- diff --git a/api.impl/src/test/java/org/apache/clerezza/api/impl/LanguageTest.java b/api.impl/src/test/java/org/apache/clerezza/api/impl/LanguageTest.java new file mode 100644 index 0000000..c50e41b --- /dev/null +++ b/api.impl/src/test/java/org/apache/clerezza/api/impl/LanguageTest.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.clerezza.api.impl; + + +import org.apache.clerezza.api.Language; +import org.junit.Assert; +import org.junit.Test; + + +/** + * + * @author reto + */ +public class LanguageTest { + + @Test + public void languageEqualityTest() { + Language lang1 = new Language("DE"); + Language lang2 = new Language("DE"); + Assert.assertEquals(lang1, lang2); + Assert.assertEquals(lang1.hashCode(), lang2.hashCode()); + Language lang3 = new Language("EN"); + Assert.assertFalse(lang1.equals(lang3)); + } + + @Test + public void toStringTest() { + final String id = "de"; + Language lang1 = new Language(id); + Assert.assertEquals(lang1.toString(), id); + } + +} http://git-wip-us.apache.org/repos/asf/clerezza/blob/01dc25b6/api.impl/src/test/java/org/apache/clerezza/api/impl/UriRefTest.java ---------------------------------------------------------------------- diff --git a/api.impl/src/test/java/org/apache/clerezza/api/impl/UriRefTest.java b/api.impl/src/test/java/org/apache/clerezza/api/impl/UriRefTest.java new file mode 100644 index 0000000..5f924a8 --- /dev/null +++ b/api.impl/src/test/java/org/apache/clerezza/api/impl/UriRefTest.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.clerezza.api.impl; + +import org.apache.clerezza.api.IRI; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +import org.junit.Assert; +import org.junit.Test; + +/** + * + * @author reto + */ +public class UriRefTest { + + @Test + public void uriRefEqualityTest() throws UnsupportedEncodingException { + String uriRefString = "http://example.org/üöä"; + IRI uriRef1 = new IRI(uriRefString); + IRI uriRef2 = new IRI(uriRefString); + Assert.assertEquals(uriRef1, uriRef2); + IRI uriRef3 = new IRI(URLEncoder.encode(uriRefString, "utf-8")); + Assert.assertFalse(uriRef1.equals(uriRef3)); + } + + @Test + public void toStringTest() { + String uriRefString = "http://example.org/üöä"; + IRI uriRef = new IRI(uriRefString); + Assert.assertEquals("<"+uriRefString+">", uriRef.toString()); + } + +} http://git-wip-us.apache.org/repos/asf/clerezza/blob/01dc25b6/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/LiteralFactoryTest.java ---------------------------------------------------------------------- diff --git a/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/LiteralFactoryTest.java b/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/LiteralFactoryTest.java new file mode 100644 index 0000000..bba9db6 --- /dev/null +++ b/api.impl/src/test/java/org/apache/clerezza/api/impl/literal/LiteralFactoryTest.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.clerezza.api.impl.literal; + + +import org.apache.clerezza.api.Literal; +import org.apache.clerezza.api.IRI; +import java.util.Arrays; +import java.util.Date; + +import org.junit.Assert; +import org.junit.Test; + +/** + * + * @author reto + */ +public class LiteralFactoryTest { + + /** + * Test that a NoConvertorException thrown for an unsupported convertor + */ + @Test(expected=NoConvertorException.class) + public void unavailableConvertor() { + Object value = new Object() {}; + LiteralFactory.getInstance().createTypedLiteral(value); + } + + /** + * Test conversion of byte[] to literal an back + */ + @Test + public void byteArrayConversion() { + byte[] bytes = new byte[5]; + for (byte i = 0; i < bytes.length; i++) { + bytes[i] = i; + } + Literal literal = LiteralFactory.getInstance().createTypedLiteral(bytes); + Assert.assertEquals(new IRI("http://www.w3.org/2001/XMLSchema#base64Binary"), + literal.getDataType()); + //we are using bytes.getClass() but there should be a way to get + //that instance of Class without getting it from an instance + //but this is java-bug 4071439 (would like byte[].class or byte.class.getArrayType()) + byte[] bytesBack = LiteralFactory.getInstance().createObject(bytes.getClass(), literal); + Assert.assertTrue(Arrays.equals(bytes, bytesBack)); + + } + + /** + * Test conversion of java.util.Date to literal an back + */ + @Test + public void dateConversion() { + Date date = new Date(); + Literal literal = LiteralFactory.getInstance().createTypedLiteral(date); + Assert.assertEquals(new IRI("http://www.w3.org/2001/XMLSchema#dateTime"), + literal.getDataType()); + Date dateBack = LiteralFactory.getInstance().createObject(Date.class, literal); + Assert.assertEquals(date.getTime(), dateBack.getTime()); + + } + + /** + * Test conversion of String to literal an back + */ + @Test + public void stringConversion() { + String value = "Hello world"; + Literal literal = LiteralFactory.getInstance().createTypedLiteral(value); + Assert.assertEquals(new IRI("http://www.w3.org/2001/XMLSchema#string"), + literal.getDataType()); + String valueBack = LiteralFactory.getInstance().createObject(String.class, literal); + Assert.assertEquals(value, valueBack); + + } + + /** + * Test conversion of Integer to literal an back + */ + @Test + public void intConversion() { + int value = 3; + Literal literal = LiteralFactory.getInstance().createTypedLiteral(value); + Assert.assertEquals(new IRI("http://www.w3.org/2001/XMLSchema#int"), + literal.getDataType()); + Integer valueBack = LiteralFactory.getInstance().createObject(Integer.class, literal); + Assert.assertEquals(value, valueBack.intValue()); + + } + + /** + * Test conversion of Long to literal an back + */ + @Test + public void longConversion() { + long value = 332314646; + Literal literal = LiteralFactory.getInstance().createTypedLiteral(value); + Assert.assertEquals(new IRI("http://www.w3.org/2001/XMLSchema#long"), + literal.getDataType()); + Long valueBack = LiteralFactory.getInstance().createObject(Long.class, literal); + Assert.assertEquals(value, valueBack.longValue()); + + } + + +} http://git-wip-us.apache.org/repos/asf/clerezza/blob/01dc25b6/rdf/core/src/test/java/org/apache/clerezza/rdf/core/LanguageTest.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/test/java/org/apache/clerezza/rdf/core/LanguageTest.java b/rdf/core/src/test/java/org/apache/clerezza/rdf/core/LanguageTest.java deleted file mode 100644 index 21d53c3..0000000 --- a/rdf/core/src/test/java/org/apache/clerezza/rdf/core/LanguageTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.clerezza.rdf.core; - - -import org.apache.clerezza.commons.rdf.Language; -import org.junit.Assert; -import org.junit.Test; - - -/** - * - * @author reto - */ -public class LanguageTest { - - @Test - public void languageEqualityTest() { - Language lang1 = new Language("DE"); - Language lang2 = new Language("DE"); - Assert.assertEquals(lang1, lang2); - Assert.assertEquals(lang1.hashCode(), lang2.hashCode()); - Language lang3 = new Language("EN"); - Assert.assertFalse(lang1.equals(lang3)); - } - - @Test - public void toStringTest() { - final String id = "de"; - Language lang1 = new Language(id); - Assert.assertEquals(lang1.toString(), id); - } - -} http://git-wip-us.apache.org/repos/asf/clerezza/blob/01dc25b6/rdf/core/src/test/java/org/apache/clerezza/rdf/core/LiteralFactoryTest.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/test/java/org/apache/clerezza/rdf/core/LiteralFactoryTest.java b/rdf/core/src/test/java/org/apache/clerezza/rdf/core/LiteralFactoryTest.java deleted file mode 100644 index f0dbd79..0000000 --- a/rdf/core/src/test/java/org/apache/clerezza/rdf/core/LiteralFactoryTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.clerezza.rdf.core; - - -import org.apache.clerezza.commons.rdf.Literal; -import org.apache.clerezza.commons.rdf.IRI; -import java.util.Arrays; -import java.util.Date; -import org.junit.Test; - -import junit.framework.Assert; - -/** - * - * @author reto - */ -public class LiteralFactoryTest { - - /** - * Test that a NoConvertorException thrown for an unsupported convertor - */ - @Test(expected=NoConvertorException.class) - public void unavailableConvertor() { - Object value = new Object() {}; - LiteralFactory.getInstance().createTypedLiteral(value); - } - - /** - * Test conversion of byte[] to literal an back - */ - @Test - public void byteArrayConversion() { - byte[] bytes = new byte[5]; - for (byte i = 0; i < bytes.length; i++) { - bytes[i] = i; - } - Literal literal = LiteralFactory.getInstance().createTypedLiteral(bytes); - Assert.assertEquals(new IRI("http://www.w3.org/2001/XMLSchema#base64Binary"), - literal.getDataType()); - //we are using bytes.getClass() but there should be a way to get - //that instance of Class without getting it from an instance - //but this is java-bug 4071439 (would like byte[].class or byte.class.getArrayType()) - byte[] bytesBack = LiteralFactory.getInstance().createObject(bytes.getClass(), literal); - Assert.assertTrue(Arrays.equals(bytes, bytesBack)); - - } - - /** - * Test conversion of java.util.Date to literal an back - */ - @Test - public void dateConversion() { - Date date = new Date(); - Literal literal = LiteralFactory.getInstance().createTypedLiteral(date); - Assert.assertEquals(new IRI("http://www.w3.org/2001/XMLSchema#dateTime"), - literal.getDataType()); - Date dateBack = LiteralFactory.getInstance().createObject(Date.class, literal); - Assert.assertEquals(date.getTime(), dateBack.getTime()); - - } - - /** - * Test conversion of String to literal an back - */ - @Test - public void stringConversion() { - String value = "Hello world"; - Literal literal = LiteralFactory.getInstance().createTypedLiteral(value); - Assert.assertEquals(new IRI("http://www.w3.org/2001/XMLSchema#string"), - literal.getDataType()); - String valueBack = LiteralFactory.getInstance().createObject(String.class, literal); - Assert.assertEquals(value, valueBack); - - } - - /** - * Test conversion of Integer to literal an back - */ - @Test - public void intConversion() { - int value = 3; - Literal literal = LiteralFactory.getInstance().createTypedLiteral(value); - Assert.assertEquals(new IRI("http://www.w3.org/2001/XMLSchema#int"), - literal.getDataType()); - Integer valueBack = LiteralFactory.getInstance().createObject(Integer.class, literal); - Assert.assertEquals(value, valueBack.intValue()); - - } - - /** - * Test conversion of Long to literal an back - */ - @Test - public void longConversion() { - long value = 332314646; - Literal literal = LiteralFactory.getInstance().createTypedLiteral(value); - Assert.assertEquals(new IRI("http://www.w3.org/2001/XMLSchema#long"), - literal.getDataType()); - Long valueBack = LiteralFactory.getInstance().createObject(Long.class, literal); - Assert.assertEquals(value, valueBack.longValue()); - - } - - -} http://git-wip-us.apache.org/repos/asf/clerezza/blob/01dc25b6/rdf/core/src/test/java/org/apache/clerezza/rdf/core/UriRefTest.java ---------------------------------------------------------------------- diff --git a/rdf/core/src/test/java/org/apache/clerezza/rdf/core/UriRefTest.java b/rdf/core/src/test/java/org/apache/clerezza/rdf/core/UriRefTest.java deleted file mode 100644 index 71d6846..0000000 --- a/rdf/core/src/test/java/org/apache/clerezza/rdf/core/UriRefTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.clerezza.rdf.core; - -import org.apache.clerezza.commons.rdf.IRI; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import org.junit.Test; -import junit.framework.Assert; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * @author reto - */ -public class UriRefTest { - - private Logger logger = LoggerFactory.getLogger(UriRefTest.class); - - @Test - public void uriRefEqualityTest() { - try { - String uriRefString = "http://example.org/üöä"; - IRI uriRef1 = new IRI(uriRefString); - IRI uriRef2 = new IRI(uriRefString); - Assert.assertEquals(uriRef1, uriRef2); - IRI uriRef3 = - new IRI(URLEncoder.encode(uriRefString, "utf-8")); - Assert.assertFalse(uriRef1.equals(uriRef3)); - } catch (UnsupportedEncodingException ex) { - logger.error("Exception {} ", ex); - } - } - - @Test - public void toStringTest() { - String uriRefString = "http://example.org/üöä"; - IRI uriRef = new IRI(uriRefString); - Assert.assertEquals("<"+uriRefString+">", uriRef.toString()); - } - -}
