Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Commit

Permalink
RDFTypes renaming
Browse files Browse the repository at this point in the history
Signed-off-by: Ricardo Herrera <neormx@gmail.com>
  • Loading branch information
neormx committed Jun 8, 2019
1 parent b573739 commit 6abb6c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
Expand Up @@ -76,7 +76,7 @@
import org.eclipse.lyo.oslc4j.core.exception.OslcCoreMisusedOccursException;
import org.eclipse.lyo.oslc4j.core.exception.OslcCoreRelativeURIException;
import org.eclipse.lyo.oslc4j.core.model.*;
import org.eclipse.lyo.oslc4j.provider.jena.ordfm.RDFTypes;
import org.eclipse.lyo.oslc4j.provider.jena.ordfm.ResourcePackages;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -331,7 +331,7 @@ public static Object fromJenaResource(final Resource resource, final Class<?> be
final Map<Class<?>, Map<String, Method>> classPropertyDefinitionsToSetMethods = new HashMap<>();
final Map<String,Object> visitedResources = new HashMap<>();
final HashSet<String> rdfTypes = new HashSet<>();
RDFTypes.mapPackage(beanClass.getPackage());
ResourcePackages.mapPackage(beanClass.getPackage());
fromResource(classPropertyDefinitionsToSetMethods,
beanClass,
newInstance,
Expand Down Expand Up @@ -500,7 +500,7 @@ private static List<Object> createObjectResultList(final Class<?> beanClass,
OslcCoreApplicationException, URISyntaxException,
NoSuchMethodException {
if (null != listSubjects) {
RDFTypes.mapPackage(beanClass.getPackage());
ResourcePackages.mapPackage(beanClass.getPackage());
final Map<Class<?>, Map<String, Method>> classPropertyDefinitionsToSetMethods = new HashMap<>();

for (final Resource resource : listSubjects) {
Expand Down Expand Up @@ -855,7 +855,7 @@ else if (o.isResource())
}
else
{
Optional<Class<?>> optionalResourceClass = RDFTypes.getClassOf(nestedResource, setMethodComponentParameterClass);
Optional<Class<?>> optionalResourceClass = ResourcePackages.getClassOf(nestedResource, setMethodComponentParameterClass);
Class<?> resourceClass = optionalResourceClass.isPresent() ? optionalResourceClass.get() : setMethodComponentParameterClass;
final Object nestedBean = resourceClass.newInstance();
fromResource(classPropertyDefinitionsToSetMethods,
Expand Down
Expand Up @@ -36,12 +36,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RDFTypes {
public class ResourcePackages {

/**
* The logger of this class.
*/
private static final Logger LOGGER = LoggerFactory.getLogger(RDFTypes.class);
private static final Logger LOGGER = LoggerFactory.getLogger(ResourcePackages.class);

/**
* The set of scanned packages.
Expand Down Expand Up @@ -147,7 +147,7 @@ public static Optional<Class<?>> getClassOf(Resource resource, Class<?>... prefe
LOGGER.debug("> resolving class for resource {}", resource.getURI());
StmtIterator rdfTypes = resource.listProperties(RDF.type);
List<Class<?>> candidates = new ArrayList<>();
synchronized(RDFTypes.class) {
synchronized(ResourcePackages.class) {
while(rdfTypes.hasNext()) {
Statement statement = rdfTypes.nextStatement();
String typeURI = statement.getObject().asResource().getURI();
Expand Down
Expand Up @@ -13,10 +13,10 @@
import org.junit.Test;

/**
* Tests for {@link RDFTypes}
* Tests for {@link ResourcePackages}
* @author rherrera
*/
public class RDFTypesTests {
public class ResourcePackagesTests {

private Resource resource;

Expand All @@ -28,45 +28,45 @@ public void init() {

@Test
public void testMapPackage() {
RDFTypes.mapPackage(Pet.class.getPackage());
Assert.assertEquals(1, RDFTypes.SCANNED_PACKAGES.size());
Assert.assertEquals(6, RDFTypes.TYPES_MAPPINGS.keySet().size());
ResourcePackages.mapPackage(Pet.class.getPackage());
Assert.assertEquals(1, ResourcePackages.SCANNED_PACKAGES.size());
Assert.assertEquals(6, ResourcePackages.TYPES_MAPPINGS.keySet().size());
}

@Test
public void testGetClassOf_noMapping() {
Assert.assertEquals(false, RDFTypes.getClassOf(resource).isPresent());
Assert.assertEquals(false, ResourcePackages.getClassOf(resource).isPresent());
}

@Test
public void testGetClassOf_noResourceType() {
RDFTypes.mapPackage(Pet.class.getPackage());
Assert.assertEquals(false, RDFTypes.getClassOf(resource).isPresent());
ResourcePackages.mapPackage(Pet.class.getPackage());
Assert.assertEquals(false, ResourcePackages.getClassOf(resource).isPresent());
}

@Test
public void testGetClassOf_simpleResourceType() {
RDFTypes.mapPackage(Pet.class.getPackage());
ResourcePackages.mapPackage(Pet.class.getPackage());
resource.addProperty(RDF.type, ResourceFactory.createResource("http://locahost:7001/vocabulary/Cat"));
Optional<Class<?>> mappedClass = RDFTypes.getClassOf(resource);
Optional<Class<?>> mappedClass = ResourcePackages.getClassOf(resource);
Assert.assertEquals(true, mappedClass.isPresent());
Assert.assertEquals(Cat.class, mappedClass.get());
}

@Test(expected = IllegalStateException.class)
public void testGetClassOf_multipleResourceTypes() {
RDFTypes.mapPackage(Pet.class.getPackage());
ResourcePackages.mapPackage(Pet.class.getPackage());
resource.addProperty(RDF.type, ResourceFactory.createResource("http://locahost:7001/vocabulary/Cat"));
resource.addProperty(RDF.type, ResourceFactory.createResource("http://locahost:7001/vocabulary/Dog"));
RDFTypes.getClassOf(resource);
ResourcePackages.getClassOf(resource);
}

@Test
public void testGetClassOf_mostConcreteResourceType() {
RDFTypes.mapPackage(Pet.class.getPackage());
ResourcePackages.mapPackage(Pet.class.getPackage());
resource.addProperty(RDF.type, ResourceFactory.createResource("http://locahost:7001/vocabulary/Cat"));
resource.addProperty(RDF.type, ResourceFactory.createResource("http://locahost:7001/vocabulary/Animal"));
Optional<Class<?>> mappedClass = RDFTypes.getClassOf(resource);
Optional<Class<?>> mappedClass = ResourcePackages.getClassOf(resource);
Assert.assertEquals(true, mappedClass.isPresent());
Assert.assertEquals(Cat.class, mappedClass.get());
}
Expand Down

0 comments on commit 6abb6c9

Please sign in to comment.