Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Lyo/LDPTestSuiteExploration"

< Lyo
(References)
(Options being explored)
Line 7: Line 7:
  
 
<code><pre>
 
<code><pre>
@Test(groups = { MUST }, dependsOnMethods = { "testCreateResource" } )  
+
@Test(groups = { MUST }, dataProvider = MediaTypeDataProvider.NAME, dataProviderClass = MediaTypeDataProvider.class)
public void testResourceHasLdpLinkHeader() throws URISyntaxException {
+
public void testCreateResource(String mediaType) throws URISyntaxException {
RestAssured.given()
+
Model model = ModelFactory.createDefaultModel();
.header(ACCEPT, TEXT_TURTLE)
+
Resource resource = model.createResource("", model.createResource("http://example.com/ns#Bug"));
.expect().statusCode(HttpStatus.SC_OK).header(LINK, LDPR_LINK_HEADER_VALUE)
+
resource.addProperty(model.createProperty("http://example.com/ns#severity"), "High");
.when().get(new URI(uri));
+
resource.addProperty(DC.title, "A very serious bug.");
}
+
resource.addProperty(DC.description, "Server won't start.");
 +
 
 +
Response postResponse = RestAssured
 +
        .given().contentType(mediaType).body(model, new RdfObjectMapper())
 +
        .expect().statusCode(HttpStatus.SC_CREATED)
 +
        .when().post(new URI(containerUri));
 +
 
 +
String location = postResponse.getHeader(LOCATION);
 +
assertNotNull(location);
 +
 
 +
// Test it's a valid URI. Throws a URISyntaxException if not.
 +
new URI(location);
 +
}
 
</pre></code>
 
</pre></code>
  
* [http://frisbyjs.com/ Frisby.js] + [https://github.com/mhevery/jasmine-node jasmine-node] + [http://nodejs.org/ node.js]
+
* [http://frisbyjs.com/ Frisby.js] + [https://github.com/mhevery/jasmine-node jasmine-node] + [https://github.com/antoniogarrote/rdfstore-js rdfstore-js] + [http://nodejs.org/ node.js]
  
 
Sample test:
 
Sample test:
  
 
<code><pre>
 
<code><pre>
frisby.create('MUST: Test Link header on LDPR')
+
    frisby.create('MUST: POST new resource in text/turtle')
      .addHeader('Accept', 'text/turtle')
+
        .addHeader('Content-Type', 'text/turtle')
      .head(resourceURI)
+
        .post(containerURI, null, {body: bugTurtle})
      .expectStatus(200)
+
        .expectStatus(201)
      .expectHeaderContains('Link', '<http://www.w3.org/ns/ldp#Resource>; rel="type"')
+
        .after(function(err, res, body) {
      .toss();
+
            createdResourceURI = res.headers['location'];
 +
            expect(createdResourceURI).toBeDefined();
 +
        })
 +
    .toss();
 
</pre></code>
 
</pre></code>
  

Revision as of 12:08, 24 March 2014

Page will gather various notes about how a LDP test suite may be implemented, with looking not just at the general needs of LDP server implementations but also how it can be leveraged for OSLC needs.

Options being explored

Sample test:

	@Test(groups = { MUST }, dataProvider = MediaTypeDataProvider.NAME, dataProviderClass = MediaTypeDataProvider.class)
	public void testCreateResource(String mediaType) throws URISyntaxException {
		Model model = ModelFactory.createDefaultModel();
		Resource resource = model.createResource("", model.createResource("http://example.com/ns#Bug"));
		resource.addProperty(model.createProperty("http://example.com/ns#severity"), "High");
		resource.addProperty(DC.title, "A very serious bug.");
		resource.addProperty(DC.description, "Server won't start.");

		Response postResponse = RestAssured
		        .given().contentType(mediaType).body(model, new RdfObjectMapper())
		        .expect().statusCode(HttpStatus.SC_CREATED)
		        .when().post(new URI(containerUri));

		String location = postResponse.getHeader(LOCATION);
		assertNotNull(location);

		// Test it's a valid URI. Throws a URISyntaxException if not.
		new URI(location);
	}

Sample test:

    frisby.create('MUST: POST new resource in text/turtle')
        .addHeader('Content-Type', 'text/turtle')
        .post(containerURI, null, {body: bugTurtle})
        .expectStatus(201)
        .after(function(err, res, body) {
            createdResourceURI = res.headers['location'];
            expect(createdResourceURI).toBeDefined();
        })
    .toss();

References

Back to the top