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.
Difference between revisions of "Lyo/LDPTestSuiteExploration"
< Lyo
(→References) |
(→Options being explored) |
||
Line 7: | Line 7: | ||
<code><pre> | <code><pre> | ||
− | @Test(groups = { MUST }, | + | @Test(groups = { MUST }, dataProvider = MediaTypeDataProvider.NAME, dataProviderClass = MediaTypeDataProvider.class) |
− | public void | + | 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"); |
− | .when(). | + | 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: | + | 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(); | ||
</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();