summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornegrello2013-11-06 15:29:56 (EST)
committer negrello2013-11-06 15:29:56 (EST)
commit90cd085cb2709e72aa2d15344ffe25922890e416 (patch)
tree661588b6bfbcea178dc30e9369cce010a48fda62
parent2157883a609b4e6db8a021e25ab37ce6af8abc4e (diff)
downloadorg.eclipse.lyo.core-90cd085cb2709e72aa2d15344ffe25922890e416.zip
org.eclipse.lyo.core-90cd085cb2709e72aa2d15344ffe25922890e416.tar.gz
org.eclipse.lyo.core-90cd085cb2709e72aa2d15344ffe25922890e416.tar.bz2
Bug 421112: do not include default rdf type if OslcName value is emptyrefs/changes/31/18131/3
string Change-Id: I68f9913ffe6ec432839d8c3aba6b89204dc15f8e Signed-off-by: negrello <fnegre@br.ibm.com>
-rw-r--r--org.eclipse.lyo.oslc4j.core/src/main/java/org/eclipse/lyo/oslc4j/core/model/TypeFactory.java36
-rw-r--r--org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java8
-rw-r--r--org.eclipse.lyo.oslc4j.provider.jena/src/test/java/org/eclipse/lyo/oslc4j/provider/jena/test/JenaOslcNameTest.java140
-rw-r--r--org.eclipse.lyo.oslc4j.provider.jena/src/test/java/org/eclipse/lyo/oslc4j/provider/jena/test/resources/EmptyNameResource.java29
-rw-r--r--org.eclipse.lyo.oslc4j.provider.jena/src/test/java/org/eclipse/lyo/oslc4j/provider/jena/test/resources/UnnamedResource.java27
-rw-r--r--org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/JsonHelper.java11
-rw-r--r--org.eclipse.lyo.oslc4j.provider.json4j/src/test/java/org/eclipse/lyo/oslc4j/provider/json4j/test/JsonOslcNameTest.java162
-rw-r--r--org.eclipse.lyo.oslc4j.provider.json4j/src/test/java/org/eclipse/lyo/oslc4j/provider/json4j/test/resources/EmptyNameResource.java29
-rw-r--r--org.eclipse.lyo.oslc4j.provider.json4j/src/test/java/org/eclipse/lyo/oslc4j/provider/json4j/test/resources/UnnamedResource.java27
9 files changed, 458 insertions, 11 deletions
diff --git a/org.eclipse.lyo.oslc4j.core/src/main/java/org/eclipse/lyo/oslc4j/core/model/TypeFactory.java b/org.eclipse.lyo.oslc4j.core/src/main/java/org/eclipse/lyo/oslc4j/core/model/TypeFactory.java
index 05cbb86..4ae5e98 100644
--- a/org.eclipse.lyo.oslc4j.core/src/main/java/org/eclipse/lyo/oslc4j/core/model/TypeFactory.java
+++ b/org.eclipse.lyo.oslc4j.core/src/main/java/org/eclipse/lyo/oslc4j/core/model/TypeFactory.java
@@ -28,10 +28,18 @@ public final class TypeFactory
super();
}
+ /**
+ * Returns the qualified name if the unqualified name is not null, otherwise
+ * returns null.
+ *
+ * @param objectClass
+ * object class.
+ * @return the qualified name.
+ */
public static String getQualifiedName(final Class<?> objectClass)
{
- return getNamespace(objectClass) +
- getName(objectClass);
+ String name = getName(objectClass);
+ return name != null ? getNamespace(objectClass) + name : null;
}
public static String getNamespace(final Class<?> objectClass)
@@ -41,10 +49,30 @@ public final class TypeFactory
return oslcNamespaceAnnotation != null ? oslcNamespaceAnnotation.value() : OslcConstants.OSLC_DATA_NAMESPACE;
}
+ /**
+ * If the annotation {@linkplain OslcName} is defined and it is different
+ * from empty string, returns it. Otherwise returns the class simple name.
+ * If the value of the annotation is an empty string, returns null.
+ *
+ * @param objectClass
+ * object class.
+ * @return the Oslc name.
+ */
public static String getName(final Class<?> objectClass)
{
final OslcName oslcNameAnnotation = objectClass.getAnnotation(OslcName.class);
-
- return oslcNameAnnotation != null ? oslcNameAnnotation.value() : objectClass.getSimpleName();
+ String name = null;
+ if (oslcNameAnnotation != null)
+ {
+ String annotationValue = oslcNameAnnotation.value();
+ if (!"".equals(annotationValue))
+ {
+ name = annotationValue;
+ }
+ }
+ else {
+ name = objectClass.getSimpleName();
+ }
+ return name;
}
}
diff --git a/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java b/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java
index c56357d..e60e6a3 100644
--- a/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java
+++ b/org.eclipse.lyo.oslc4j.provider.jena/src/main/java/org/eclipse/lyo/oslc4j/provider/jena/JenaModelHelper.java
@@ -306,9 +306,11 @@ public final class JenaModelHelper
if (objectClass.getAnnotation(OslcResourceShape.class) != null)
{
- final String namespace = TypeFactory.getNamespace(objectClass);
- final String name = TypeFactory.getName(objectClass);
- mainResource.addProperty(RDF.type, model.createResource(namespace + name));
+ String qualifiedName = TypeFactory.getQualifiedName(objectClass);
+ if (qualifiedName != null)
+ {
+ mainResource.addProperty(RDF.type, model.createResource(qualifiedName));
+ }
}
buildResource(object,
diff --git a/org.eclipse.lyo.oslc4j.provider.jena/src/test/java/org/eclipse/lyo/oslc4j/provider/jena/test/JenaOslcNameTest.java b/org.eclipse.lyo.oslc4j.provider.jena/src/test/java/org/eclipse/lyo/oslc4j/provider/jena/test/JenaOslcNameTest.java
new file mode 100644
index 0000000..23ca8c4
--- /dev/null
+++ b/org.eclipse.lyo.oslc4j.provider.jena/src/test/java/org/eclipse/lyo/oslc4j/provider/jena/test/JenaOslcNameTest.java
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Fabio Negrello - initial implementation
+ *******************************************************************************/
+package org.eclipse.lyo.oslc4j.provider.jena.test;
+
+import static org.eclipse.lyo.oslc4j.core.test.customnamespace.CustomNamespaceConstants.TEST1_URL;
+import static org.eclipse.lyo.oslc4j.core.test.customnamespace.CustomNamespaceConstants.TEST2_URL;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Assert;
+
+import org.eclipse.lyo.oslc4j.core.model.AbstractResource;
+import org.eclipse.lyo.oslc4j.provider.jena.JenaModelHelper;
+import org.eclipse.lyo.oslc4j.provider.jena.test.resources.EmptyNameResource;
+import org.eclipse.lyo.oslc4j.provider.jena.test.resources.TestResource;
+import org.eclipse.lyo.oslc4j.provider.jena.test.resources.UnnamedResource;
+import org.junit.Test;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.vocabulary.RDF;
+
+/**
+ * Tests Jena working with different combinations of OslcName annotation.
+ *
+ * @author Fabio Negrello
+ *
+ */
+public class JenaOslcNameTest {
+
+ private final String NAME_LOCAL_PART = "name";
+ private final String DESCRIPTION_LOCAL_PART = "description";
+
+ /**
+ * Checks that OslcName annotation with empty string does not add RDF type
+ * to the resource.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testJenaOslcNameEmptyString() throws Exception {
+ EmptyNameResource resource = createResource(EmptyNameResource.class);
+ Model model = JenaModelHelper.createJenaModel(new Object[] { resource });
+ List<RDFNode> rdfTypes = model.listObjectsOfProperty(RDF.type).toList();
+ Assert.assertTrue("Model should not contain RDF type as OslcName is empty", rdfTypes.isEmpty());
+ }
+
+ /**
+ * Checks that OslcName annotation with empty string does not add default
+ * RDF type to the resource but adds the ones specified by addTypes method.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testJenaOslcNameEmptyStringAndOtherTypes() throws Exception {
+ EmptyNameResource resource = createResource(EmptyNameResource.class);
+ String typeToAdd = "http://about.oslc.test/addedType";
+ resource.getTypes().add(URI.create(typeToAdd));
+ Model model = JenaModelHelper.createJenaModel(new Object[] { resource });
+ List<RDFNode> rdfTypes = model.listObjectsOfProperty(RDF.type).toList();
+ Assert.assertEquals("Model should contain only added RDF type", rdfTypes.size(), 1);
+ verifyRDFTypes(new String[] { typeToAdd }, rdfTypes);
+ }
+
+ /**
+ * Checks that OslcName annotation adds RDF type to the resource.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testJenaRegularOslcName() throws Exception {
+ TestResource resource = createResource(TestResource.class);
+ Model model = JenaModelHelper.createJenaModel(new Object[] { resource });
+ List<RDFNode> rdfTypes = model.listObjectsOfProperty(RDF.type).toList();
+ Assert.assertFalse("Model should contain RDF types", rdfTypes.isEmpty());
+ verifyRDFTypes(new String[] { TestResource.TEST_NAMESPACE + "Test" }, rdfTypes);
+ }
+
+ /**
+ * Checks that the absence of OslcName annotation adds default RDF type to
+ * the resource.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testJenaDefaultOslcName() throws Exception {
+ UnnamedResource resource = createResource(UnnamedResource.class);
+ Model model = JenaModelHelper.createJenaModel(new Object[] { resource });
+ List<RDFNode> rdfTypes = model.listObjectsOfProperty(RDF.type).toList();
+ Assert.assertFalse("Model should contain RDF types", rdfTypes.isEmpty());
+ verifyRDFTypes(new String[] { TestResource.TEST_NAMESPACE + "UnnamedResource" }, rdfTypes);
+ }
+
+ private void verifyRDFTypes(String[] expectedRDFTypes, List<RDFNode> actualRDFTypes) {
+ List<String> actualRdfTypesList = new ArrayList<String>();
+ for (RDFNode node : actualRDFTypes) {
+ actualRdfTypesList.add(node.toString());
+ }
+ for (String expectedRdfType : expectedRDFTypes) {
+ Assert.assertTrue("Resource should contain RDF type " + expectedRdfType,
+ actualRdfTypesList.contains(expectedRdfType));
+ }
+ }
+
+ /**
+ * Creates a new instance adding some test values.
+ *
+ * @param resource
+ * class.
+ * @return new instance
+ */
+ private <T extends AbstractResource> T createResource(Class<T> resourceClass) throws Exception {
+ T resource = resourceClass.newInstance();
+ URI resourceAbout = URI.create("http://about.oslc.test/001");
+ resource.setAbout(resourceAbout);
+ QName qName = new QName(TEST1_URL, NAME_LOCAL_PART);
+ resource.getExtendedProperties().put(qName, "Some Name");
+ qName = new QName(TEST2_URL, DESCRIPTION_LOCAL_PART);
+ resource.getExtendedProperties().put(qName, "Any Description");
+ return resource;
+ }
+
+}
diff --git a/org.eclipse.lyo.oslc4j.provider.jena/src/test/java/org/eclipse/lyo/oslc4j/provider/jena/test/resources/EmptyNameResource.java b/org.eclipse.lyo.oslc4j.provider.jena/src/test/java/org/eclipse/lyo/oslc4j/provider/jena/test/resources/EmptyNameResource.java
new file mode 100644
index 0000000..915a856
--- /dev/null
+++ b/org.eclipse.lyo.oslc4j.provider.jena/src/test/java/org/eclipse/lyo/oslc4j/provider/jena/test/resources/EmptyNameResource.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Fabio Negrello - initial implementation
+ *******************************************************************************/
+package org.eclipse.lyo.oslc4j.provider.jena.test.resources;
+
+import org.eclipse.lyo.oslc4j.core.annotation.OslcName;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcNamespace;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcResourceShape;
+import org.eclipse.lyo.oslc4j.core.model.AbstractResource;
+
+@OslcName("")
+@OslcNamespace(EmptyNameResource.TEST_NAMESPACE)
+@OslcResourceShape(title = "Test Resource", describes = EmptyNameResource.TEST_RESOURCE_TYPE)
+public class EmptyNameResource extends AbstractResource {
+ public final static String TEST_NAMESPACE = "http://example.com/ns#";
+ public final static String TEST_RESOURCE_TYPE = TEST_NAMESPACE + "Test";
+}
diff --git a/org.eclipse.lyo.oslc4j.provider.jena/src/test/java/org/eclipse/lyo/oslc4j/provider/jena/test/resources/UnnamedResource.java b/org.eclipse.lyo.oslc4j.provider.jena/src/test/java/org/eclipse/lyo/oslc4j/provider/jena/test/resources/UnnamedResource.java
new file mode 100644
index 0000000..bd00be6
--- /dev/null
+++ b/org.eclipse.lyo.oslc4j.provider.jena/src/test/java/org/eclipse/lyo/oslc4j/provider/jena/test/resources/UnnamedResource.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Fabio Negrello - initial implementation
+ *******************************************************************************/
+package org.eclipse.lyo.oslc4j.provider.jena.test.resources;
+
+import org.eclipse.lyo.oslc4j.core.annotation.OslcNamespace;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcResourceShape;
+import org.eclipse.lyo.oslc4j.core.model.AbstractResource;
+
+@OslcNamespace(UnnamedResource.TEST_NAMESPACE)
+@OslcResourceShape(title = "Test Resource", describes = UnnamedResource.TEST_RESOURCE_TYPE)
+public class UnnamedResource extends AbstractResource {
+ public final static String TEST_NAMESPACE = "http://example.com/ns#";
+ public final static String TEST_RESOURCE_TYPE = TEST_NAMESPACE + "Test";
+}
diff --git a/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/JsonHelper.java b/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/JsonHelper.java
index 5885471..1270727 100644
--- a/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/JsonHelper.java
+++ b/org.eclipse.lyo.oslc4j.provider.json4j/src/main/java/org/eclipse/lyo/oslc4j/provider/json4j/JsonHelper.java
@@ -690,10 +690,13 @@ public final class JsonHelper
final String qualifiedName;
if (objectClass.getAnnotation(OslcResourceShape.class) != null)
{
- qualifiedName = TypeFactory.getQualifiedName(objectClass);
- addType(rdfPrefix,
- rdfTypesJSONArray,
- qualifiedName);
+ qualifiedName = TypeFactory.getQualifiedName(objectClass);
+ if (qualifiedName != null)
+ {
+ addType(rdfPrefix,
+ rdfTypesJSONArray,
+ qualifiedName);
+ }
}
else
{
diff --git a/org.eclipse.lyo.oslc4j.provider.json4j/src/test/java/org/eclipse/lyo/oslc4j/provider/json4j/test/JsonOslcNameTest.java b/org.eclipse.lyo.oslc4j.provider.json4j/src/test/java/org/eclipse/lyo/oslc4j/provider/json4j/test/JsonOslcNameTest.java
new file mode 100644
index 0000000..0317af0
--- /dev/null
+++ b/org.eclipse.lyo.oslc4j.provider.json4j/src/test/java/org/eclipse/lyo/oslc4j/provider/json4j/test/JsonOslcNameTest.java
@@ -0,0 +1,162 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Fabio Negrello - initial implementation
+ *******************************************************************************/
+package org.eclipse.lyo.oslc4j.provider.json4j.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.xml.namespace.QName;
+
+import org.apache.wink.json4j.JSONArray;
+import org.apache.wink.json4j.JSONException;
+import org.apache.wink.json4j.JSONObject;
+import org.apache.wink.json4j.OrderedJSONObject;
+import org.eclipse.lyo.oslc4j.core.model.AbstractResource;
+import org.eclipse.lyo.oslc4j.provider.json4j.OslcRdfJsonProvider;
+import org.eclipse.lyo.oslc4j.provider.json4j.test.resources.EmptyNameResource;
+import org.eclipse.lyo.oslc4j.provider.json4j.test.resources.TestResource;
+import org.eclipse.lyo.oslc4j.provider.json4j.test.resources.UnnamedResource;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests Json working with different combinations of OslcName annotation.
+ *
+ * @author Fabio Negrello
+ *
+ */
+public class JsonOslcNameTest {
+
+ private final String NAME_LOCAL_PART = "name";
+ private final String DESCRIPTION_LOCAL_PART = "description";
+ private final String TEST1_URL = "http://test1.oslc4j.com#";
+ private final String TEST2_URL = "http://test2.oslc4j.com#";
+
+ /**
+ * Checks that OslcName annotation with empty string does not add RDF type
+ * to the resource.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testJenaOslcNameEmptyString() throws Exception {
+ EmptyNameResource resource = createResource(EmptyNameResource.class);
+ final OslcRdfJsonProvider oslcRdfJsonProvider = new OslcRdfJsonProvider();
+ JSONObject jsonObject = getJSONObject(resource, oslcRdfJsonProvider);
+ JSONArray rdfTypes = jsonObject.getJSONArray("rdf:type");
+ Assert.assertTrue("Model should not contain RDF type as OslcName is empty", rdfTypes.isEmpty());
+ }
+
+ private JSONObject getJSONObject(Object resource, final OslcRdfJsonProvider oslcRdfJsonProvider)
+ throws IOException, WebApplicationException, JSONException {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ oslcRdfJsonProvider.writeTo(resource, resource.getClass(), resource.getClass(), new Annotation[0],
+ MediaType.APPLICATION_JSON_TYPE, null, outputStream);
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
+ JSONObject jsonObject = new JSONObject(inputStream);
+ return jsonObject;
+ }
+
+ /**
+ * Checks that OslcName annotation with empty string does not add default
+ * RDF type to the resource but adds the ones specified by addTypes method.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testJenaOslcNameEmptyStringAndOtherTypes() throws Exception {
+ EmptyNameResource resource = createResource(EmptyNameResource.class);
+ String typeToAdd = "http://about.oslc.test/addedType";
+ resource.getTypes().add(URI.create(typeToAdd));
+ final OslcRdfJsonProvider oslcRdfJsonProvider = new OslcRdfJsonProvider();
+ JSONObject jsonObject = getJSONObject(resource, oslcRdfJsonProvider);
+ JSONArray rdfTypes = jsonObject.getJSONArray("rdf:type");
+ Assert.assertEquals("Model should contain only added RDF type", rdfTypes.size(), 1);
+ verifyRDFTypes(new String[] { typeToAdd }, rdfTypes);
+ }
+
+ /**
+ * Checks that OslcName annotation adds RDF type to the resource.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testJenaRegularOslcName() throws Exception {
+ TestResource resource = createResource(TestResource.class);
+ final OslcRdfJsonProvider oslcRdfJsonProvider = new OslcRdfJsonProvider();
+ JSONObject jsonObject = getJSONObject(resource, oslcRdfJsonProvider);
+ JSONArray rdfTypes = jsonObject.getJSONArray("rdf:type");
+ Assert.assertEquals("Model should contain default RDF type", rdfTypes.size(), 1);
+ verifyRDFTypes(new String[] { TestResource.TEST_NAMESPACE + "Test" }, rdfTypes);
+ }
+
+ /**
+ * Checks that the absence of OslcName annotation adds default RDF type to
+ * the resource.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testJenaDefaultOslcName() throws Exception {
+ UnnamedResource resource = createResource(UnnamedResource.class);
+ String typeToAdd = "http://about.oslc.test/addedType";
+ resource.getTypes().add(URI.create(typeToAdd));
+ final OslcRdfJsonProvider oslcRdfJsonProvider = new OslcRdfJsonProvider();
+ JSONObject jsonObject = getJSONObject(resource, oslcRdfJsonProvider);
+ JSONArray rdfTypes = jsonObject.getJSONArray("rdf:type");
+ Assert.assertFalse("Model should contain RDF types", rdfTypes.isEmpty());
+ verifyRDFTypes(new String[] { typeToAdd, TestResource.TEST_NAMESPACE + "UnnamedResource" }, rdfTypes);
+ }
+
+ private void verifyRDFTypes(String[] expectedRDFTypes, JSONArray rdfTypes) throws JSONException {
+ List<String> actualRdfTypesList = new ArrayList<String>();
+ for (Object node : rdfTypes) {
+ OrderedJSONObject obj = (OrderedJSONObject) node;
+ String type = obj.values().iterator().next().toString();
+ actualRdfTypesList.add(type);
+ }
+ for (String expectedRdfType : expectedRDFTypes) {
+ Assert.assertTrue("Resource should contain RDF type " + expectedRdfType,
+ actualRdfTypesList.contains(expectedRdfType));
+ }
+ }
+
+ /**
+ * Creates a new instance adding some test values.
+ *
+ * @param resource
+ * class.
+ * @return new instance
+ */
+ private <T extends AbstractResource> T createResource(Class<T> resourceClass) throws Exception {
+ T resource = resourceClass.newInstance();
+ URI resourceAbout = URI.create("http://about.oslc.test/001");
+ resource.setAbout(resourceAbout);
+ QName qName = new QName(TEST1_URL, NAME_LOCAL_PART);
+ resource.getExtendedProperties().put(qName, "Some Name");
+ qName = new QName(TEST2_URL, DESCRIPTION_LOCAL_PART);
+ resource.getExtendedProperties().put(qName, "Any Description");
+ return resource;
+ }
+
+}
diff --git a/org.eclipse.lyo.oslc4j.provider.json4j/src/test/java/org/eclipse/lyo/oslc4j/provider/json4j/test/resources/EmptyNameResource.java b/org.eclipse.lyo.oslc4j.provider.json4j/src/test/java/org/eclipse/lyo/oslc4j/provider/json4j/test/resources/EmptyNameResource.java
new file mode 100644
index 0000000..3b3c007
--- /dev/null
+++ b/org.eclipse.lyo.oslc4j.provider.json4j/src/test/java/org/eclipse/lyo/oslc4j/provider/json4j/test/resources/EmptyNameResource.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Fabio Negrello - initial implementation
+ *******************************************************************************/
+package org.eclipse.lyo.oslc4j.provider.json4j.test.resources;
+
+import org.eclipse.lyo.oslc4j.core.annotation.OslcName;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcNamespace;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcResourceShape;
+import org.eclipse.lyo.oslc4j.core.model.AbstractResource;
+
+@OslcName("")
+@OslcNamespace(EmptyNameResource.TEST_NAMESPACE)
+@OslcResourceShape(title = "Test Resource", describes = EmptyNameResource.TEST_RESOURCE_TYPE)
+public class EmptyNameResource extends AbstractResource {
+ public final static String TEST_NAMESPACE = "http://example.com/ns#";
+ public final static String TEST_RESOURCE_TYPE = TEST_NAMESPACE + "Test";
+}
diff --git a/org.eclipse.lyo.oslc4j.provider.json4j/src/test/java/org/eclipse/lyo/oslc4j/provider/json4j/test/resources/UnnamedResource.java b/org.eclipse.lyo.oslc4j.provider.json4j/src/test/java/org/eclipse/lyo/oslc4j/provider/json4j/test/resources/UnnamedResource.java
new file mode 100644
index 0000000..80adb49
--- /dev/null
+++ b/org.eclipse.lyo.oslc4j.provider.json4j/src/test/java/org/eclipse/lyo/oslc4j/provider/json4j/test/resources/UnnamedResource.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Fabio Negrello - initial implementation
+ *******************************************************************************/
+package org.eclipse.lyo.oslc4j.provider.json4j.test.resources;
+
+import org.eclipse.lyo.oslc4j.core.annotation.OslcNamespace;
+import org.eclipse.lyo.oslc4j.core.annotation.OslcResourceShape;
+import org.eclipse.lyo.oslc4j.core.model.AbstractResource;
+
+@OslcNamespace(UnnamedResource.TEST_NAMESPACE)
+@OslcResourceShape(title = "Test Resource", describes = UnnamedResource.TEST_RESOURCE_TYPE)
+public class UnnamedResource extends AbstractResource {
+ public final static String TEST_NAMESPACE = "http://example.com/ns#";
+ public final static String TEST_RESOURCE_TYPE = TEST_NAMESPACE + "Test";
+}