-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from kbss-cvut/279-rdf-core-types
Implement CoreDataTypes resolving
- Loading branch information
Showing
3 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
s-pipes-web/src/main/java/cz/cvut/spipes/rest/handler/JsonLdCoreLiteralDatatypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package cz.cvut.spipes.rest.handler; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Represents XSD datatypes used in JSON-LD without requiring explicit "@type" declaration. | ||
**/ | ||
public class JsonLdCoreLiteralDatatypes { | ||
|
||
public static final String XSD_NAMESPACE = "http://www.w3.org/2001/XMLSchema#"; | ||
|
||
public static final String XSD_STRING = XSD_NAMESPACE + "string"; | ||
public static final String XSD_INTEGER = XSD_NAMESPACE + "integer"; | ||
public static final String XSD_BOOLEAN = XSD_NAMESPACE + "boolean"; | ||
public static final String XSD_DOUBLE = XSD_NAMESPACE + "double"; | ||
|
||
public static final List<String> CORE_TYPES = List.of(XSD_STRING, XSD_INTEGER, XSD_BOOLEAN, XSD_DOUBLE); | ||
|
||
public static boolean isCorePrimitiveType(String type) { | ||
if(type == null) { | ||
return false; | ||
} | ||
return CORE_TYPES.contains(type); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
s-pipes-web/src/test/java/cz/cvut/spipes/rest/handler/JsonLdCoreLiteralDatatypesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cz.cvut.spipes.rest.handler; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class JsonLdCoreLiteralDatatypesTest { | ||
|
||
@Test | ||
public void testConstants() { | ||
assertEquals("http://www.w3.org/2001/XMLSchema#string", JsonLdCoreLiteralDatatypes.XSD_STRING); | ||
assertEquals("http://www.w3.org/2001/XMLSchema#integer", JsonLdCoreLiteralDatatypes.XSD_INTEGER); | ||
assertEquals("http://www.w3.org/2001/XMLSchema#boolean", JsonLdCoreLiteralDatatypes.XSD_BOOLEAN); | ||
assertEquals("http://www.w3.org/2001/XMLSchema#double", JsonLdCoreLiteralDatatypes.XSD_DOUBLE); | ||
} | ||
|
||
@Test | ||
public void testCoreTypesList() { | ||
List<String> expectedCoreTypes = List.of( | ||
"http://www.w3.org/2001/XMLSchema#string", | ||
"http://www.w3.org/2001/XMLSchema#integer", | ||
"http://www.w3.org/2001/XMLSchema#boolean", | ||
"http://www.w3.org/2001/XMLSchema#double" | ||
); | ||
assertEquals(expectedCoreTypes, JsonLdCoreLiteralDatatypes.CORE_TYPES); | ||
} | ||
|
||
@Test | ||
public void testIsCorePrimitiveTypeWithValidTypes() { | ||
assertTrue(JsonLdCoreLiteralDatatypes.isCorePrimitiveType(JsonLdCoreLiteralDatatypes.XSD_STRING)); | ||
assertTrue(JsonLdCoreLiteralDatatypes.isCorePrimitiveType(JsonLdCoreLiteralDatatypes.XSD_INTEGER)); | ||
assertTrue(JsonLdCoreLiteralDatatypes.isCorePrimitiveType(JsonLdCoreLiteralDatatypes.XSD_BOOLEAN)); | ||
assertTrue(JsonLdCoreLiteralDatatypes.isCorePrimitiveType(JsonLdCoreLiteralDatatypes.XSD_DOUBLE)); | ||
} | ||
|
||
@Test | ||
public void testIsCorePrimitiveTypeWithInvalidTypes() { | ||
assertFalse(JsonLdCoreLiteralDatatypes.isCorePrimitiveType("http://www.w3.org/2001/XMLSchema#nonexistent")); | ||
assertFalse(JsonLdCoreLiteralDatatypes.isCorePrimitiveType("http://www.w3.org/2001/XMLSchema#date")); | ||
assertFalse(JsonLdCoreLiteralDatatypes.isCorePrimitiveType("")); | ||
assertFalse(JsonLdCoreLiteralDatatypes.isCorePrimitiveType(null)); | ||
} | ||
|
||
@Test | ||
public void testIsCorePrimitiveTypeWithEdgeCases() { | ||
assertFalse(JsonLdCoreLiteralDatatypes.isCorePrimitiveType("")); | ||
assertFalse(JsonLdCoreLiteralDatatypes.isCorePrimitiveType(null)); | ||
} | ||
} |