aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Padgett2011-11-09 09:57:50 (EST)
committerMichael Fiedler2011-11-09 09:57:50 (EST)
commitc1445c5a6612f738eb13901fdfab0e62ae0c4040 (patch)
tree9df01d49eb9444bc2d9f260afb169b9f3cb84bf7
parent3b7bd8bfc109a6071c7be3d4f5eaea992d0eb715 (diff)
downloadorg.eclipse.lyo.testsuite-c1445c5a6612f738eb13901fdfab0e62ae0c4040.zip
org.eclipse.lyo.testsuite-c1445c5a6612f738eb13901fdfab0e62ae0c4040.tar.gz
org.eclipse.lyo.testsuite-c1445c5a6612f738eb13901fdfab0e62ae0c4040.tar.bz2
Bug 362495 - Incorrect null checks after Model.getResource()
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ChangeRequestRdfXmlTests.java8
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderCatalogRdfXmlTests.java74
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderRdfXmlTests.java71
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryRdfXmlTests.java101
-rw-r--r--org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/OSLCConstants.java3
5 files changed, 132 insertions, 125 deletions
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ChangeRequestRdfXmlTests.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ChangeRequestRdfXmlTests.java
index 68938e1..da9ee6e 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ChangeRequestRdfXmlTests.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ChangeRequestRdfXmlTests.java
@@ -48,7 +48,8 @@ import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Selector;
import com.hp.hpl.jena.rdf.model.SimpleSelector;
-import com.hp.hpl.jena.rdf.model.StmtIterator;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+import com.hp.hpl.jena.vocabulary.RDF;
/**
@@ -81,8 +82,11 @@ public class ChangeRequestRdfXmlTests extends TestsBase {
fRdfModel.read(response.getEntity().getContent(),
OSLCUtils.absoluteUrlFromRelative(setupBaseUrl, currentUrl),
OSLCConstants.JENA_RDF_XML);
+
+
fResource = (Resource) fRdfModel.getResource(currentUrl);
- assumeNotNull(fResource);
+ assumeTrue(fRdfModel.contains(fResource, RDF.type,
+ fRdfModel.createResource(OSLCConstants.CM_CHANGE_REQUEST_TYPE)));
}
@Before
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderCatalogRdfXmlTests.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderCatalogRdfXmlTests.java
index 836665a..5ef11b8 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderCatalogRdfXmlTests.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderCatalogRdfXmlTests.java
@@ -15,39 +15,39 @@
*******************************************************************************/
package org.eclipse.lyo.testsuite.server.oslcv2tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Properties;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.XPathException;
-import javax.xml.xpath.XPathExpressionException;
-
-
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.http.HttpResponse;
-import org.eclipse.lyo.testsuite.server.util.OSLCConstants;
-import org.eclipse.lyo.testsuite.server.util.OSLCUtils;
-import org.eclipse.lyo.testsuite.server.util.SetupProperties;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runners.Parameterized.Parameters;
-import org.xml.sax.SAXException;
-
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.rdf.model.Property;
-import com.hp.hpl.jena.rdf.model.RDFNode;
-import com.hp.hpl.jena.rdf.model.Resource;
-import com.hp.hpl.jena.rdf.model.Selector;
-import com.hp.hpl.jena.rdf.model.SimpleSelector;
-import com.hp.hpl.jena.rdf.model.Statement;
-import com.hp.hpl.jena.rdf.model.StmtIterator;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Properties;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPathException;
+import javax.xml.xpath.XPathExpressionException;
+
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.http.HttpResponse;
+import org.eclipse.lyo.testsuite.server.util.OSLCConstants;
+import org.eclipse.lyo.testsuite.server.util.OSLCUtils;
+import org.eclipse.lyo.testsuite.server.util.SetupProperties;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runners.Parameterized.Parameters;
+import org.xml.sax.SAXException;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Selector;
+import com.hp.hpl.jena.rdf.model.SimpleSelector;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+import com.hp.hpl.jena.vocabulary.RDF;
public class ServiceProviderCatalogRdfXmlTests extends
ServiceProviderCatalogBaseTests {
@@ -74,9 +74,11 @@ public class ServiceProviderCatalogRdfXmlTests extends
rdfModel.read(response.getEntity().getContent(),
OSLCUtils.absoluteUrlFromRelative(setupBaseUrl, currentUrl),
OSLCConstants.JENA_RDF_XML);
- catalog = (Resource) rdfModel.getResource(currentUrl);
-
- assertNotNull("Failed to read Catalog resource at URI: "+currentUrl, catalog);
+ catalog = (Resource) rdfModel.getResource(currentUrl);
+
+ assertTrue("Failed to read Catalog resource at URI: "+currentUrl,
+ rdfModel.contains(catalog, RDF.type,
+ rdfModel.createResource(OSLCConstants.SERVICE_PROVIDER_CATALOG_TYPE)));
}
@Parameters
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderRdfXmlTests.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderRdfXmlTests.java
index 9c0ecef..00c2015 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderRdfXmlTests.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/ServiceProviderRdfXmlTests.java
@@ -15,39 +15,39 @@
*******************************************************************************/
package org.eclipse.lyo.testsuite.server.oslcv2tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Properties;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.XPathException;
-
-
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.http.HttpResponse;
-import org.apache.http.util.EntityUtils;
-import org.eclipse.lyo.testsuite.server.util.OSLCConstants;
-import org.eclipse.lyo.testsuite.server.util.OSLCUtils;
-import org.eclipse.lyo.testsuite.server.util.SetupProperties;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-import org.xml.sax.SAXException;
-
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.rdf.model.Property;
-import com.hp.hpl.jena.rdf.model.Resource;
-import com.hp.hpl.jena.rdf.model.Statement;
-import com.hp.hpl.jena.rdf.model.StmtIterator;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPathException;
+
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.http.HttpResponse;
+import org.apache.http.util.EntityUtils;
+import org.eclipse.lyo.testsuite.server.util.OSLCConstants;
+import org.eclipse.lyo.testsuite.server.util.OSLCUtils;
+import org.eclipse.lyo.testsuite.server.util.SetupProperties;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.xml.sax.SAXException;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+import com.hp.hpl.jena.vocabulary.RDF;
/**
@@ -81,8 +81,9 @@ public class ServiceProviderRdfXmlTests extends TestsBase {
OSLCConstants.JENA_RDF_XML);
fServiceProvider = (Resource) fRdfModel.getResource(currentUrl);
- assertNotNull("Failed to read ServiceProvider resource at URI: "+currentUrl, fServiceProvider);
-
+ assertTrue("Failed to read ServiceProvider resource at URI: "
+ + currentUrl, fRdfModel.contains(fServiceProvider, RDF.type,
+ fRdfModel.createResource(OSLCConstants.SERVICE_PROVIDER_TYPE)));
}
@Parameters
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryRdfXmlTests.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryRdfXmlTests.java
index d5b471a..0fcf2a2 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryRdfXmlTests.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/oslcv2tests/SimplifiedQueryRdfXmlTests.java
@@ -15,41 +15,42 @@
*******************************************************************************/
package org.eclipse.lyo.testsuite.server.oslcv2tests;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeNotNull;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Properties;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.XPathException;
-
-
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.http.HttpResponse;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Properties;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPathException;
+
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
-import org.eclipse.lyo.testsuite.server.util.OSLCConstants;
-import org.eclipse.lyo.testsuite.server.util.OSLCUtils;
-import org.eclipse.lyo.testsuite.server.util.SetupProperties;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-import org.xml.sax.SAXException;
-
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.rdf.model.Property;
-import com.hp.hpl.jena.rdf.model.RDFNode;
-import com.hp.hpl.jena.rdf.model.Resource;
-import com.hp.hpl.jena.rdf.model.Statement;
-import com.hp.hpl.jena.rdf.model.StmtIterator;
+import org.eclipse.lyo.testsuite.server.util.OSLCConstants;
+import org.eclipse.lyo.testsuite.server.util.OSLCUtils;
+import org.eclipse.lyo.testsuite.server.util.SetupProperties;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.xml.sax.SAXException;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.ResIterator;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+import com.hp.hpl.jena.vocabulary.RDF;
+import com.hp.hpl.jena.vocabulary.RDFS;
/**
* This class provides JUnit tests for the basic validation of query factories
@@ -94,34 +95,32 @@ public class SimplifiedQueryRdfXmlTests extends SimplifiedQueryBaseTests {
OSLCUtils.absoluteUrlFromRelative(setupBaseUrl, currentUrl),
OSLCConstants.JENA_RDF_XML);
EntityUtils.consume(response.getEntity());
- Resource responseInfoRes = (Resource) queryModel.getResource(currentUrl + query);
- assumeNotNull("Expended ResponseInfo/@rdf:about to equal request URL", responseInfoRes);
- Resource resultsRes = (Resource) queryModel.getResource(currentUrl);
- assumeNotNull(resultsRes);
+ Resource resultsRes = queryModel.getResource(currentUrl);
+ assertTrue("Expected a results resource with URI: " + currentUrl,
+ queryModel.contains(resultsRes, null));
// oslc:ResponseInfo if optional, validate it if one exists
Resource respInfoType = queryModel.createResource(OSLCConstants.RESP_INFO_TYPE);
- Property rdfType = queryModel.getProperty(OSLCConstants.RDF_TYPE_PROP);
- StmtIterator stmts = queryModel.listStatements(responseInfoRes, rdfType, respInfoType);
- List<?> stmtsList = stmts.toList();
- if (stmtsList.size() > 0) {
- assertTrue("Expected ResponseInfo type for request URL",
- stmtsList.size() > 0);
-
+ ResIterator resIter = queryModel.listSubjectsWithProperty(RDF.type, respInfoType);
+ while (resIter.hasNext()) {
+ Resource responseInfoRes = resIter.nextResource();
+ assertEquals(
+ "Response info URI should match the request URI (with query parameters)",
+ currentUrl + query, responseInfoRes.getURI());
+
Property countMember = queryModel.getProperty(OSLCConstants.TOTAL_COUNT_PROP);
- stmts = queryModel.listStatements(responseInfoRes, countMember, (RDFNode)null);
- stmtsList = stmts.toList();
- Statement stmt = (Statement) stmtsList.get(0);
+ StmtIterator stmts = responseInfoRes.listProperties(countMember);
+ List<?> stmtsList = stmts.toList();
+ Statement stmt = (Statement) stmtsList.get(0);
assertTrue("Expected oslc:totalCount property", stmtsList.size() == 1);
int totalCount = Integer.parseInt(stmt.getObject().toString());
assertTrue("Expected oslc:totalCount > 0",
totalCount > 0);
- Property rdfsMember = queryModel.getProperty(OSLCConstants.RDFS_MEMBER);
- stmts = queryModel.listStatements(resultsRes, rdfsMember, (RDFNode)null);
+ stmts = queryModel.listStatements(resultsRes, RDFS.member, (RDFNode)null);
stmtsList = stmts.toList();
assertNotNull("Expected > 1 rdfs:member(s)", stmtsList.size() > 0);
- }
+ }
}
@Test
diff --git a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/OSLCConstants.java b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/OSLCConstants.java
index c3d6033..58d34fa 100644
--- a/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/OSLCConstants.java
+++ b/org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/server/util/OSLCConstants.java
@@ -76,7 +76,8 @@ public interface OSLCConstants {
public static final String RESOURCE_SHAPE_PROP = OSLC_V2 + "resourceShape";
- // OSLC CM 2.0
+ // OSLC CM 2.0
+ public static final String CM_CHANGE_REQUEST_TYPE = OSLC_CM_V2 + "ChangeRequest";
public static final String CM_CLOSE_DATE_PROP = OSLC_CM_V2 + "closeDate";
public static final String CM_STATUS_PROP = OSLC_CM_V2 + "status";
public static final String CM_CLOSED_PROP = OSLC_CM_V2 + "closed";