Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit bfcba1b

Browse files
committed
Merge pull request #217 from MiguelAraCo/testPostResource
Added IndirectContainer test: testPostResource.
2 parents 3ad28f1 + 2648740 commit bfcba1b

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

src/main/java/org/w3/ldp/testsuite/test/IndirectContainerTest.java

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@
1919
import org.w3.ldp.testsuite.annotations.SpecTest.METHOD;
2020
import org.w3.ldp.testsuite.annotations.SpecTest.STATUS;
2121
import org.w3.ldp.testsuite.exception.SkipException;
22+
import org.w3.ldp.testsuite.http.HttpMethod;
2223
import org.w3.ldp.testsuite.http.LdpPreferences;
2324
import org.w3.ldp.testsuite.mapper.RdfObjectMapper;
2425
import org.w3.ldp.testsuite.vocab.LDP;
2526

2627
import java.io.IOException;
2728

29+
import static org.hamcrest.Matchers.notNullValue;
2830
import static org.testng.Assert.assertTrue;
2931
import static org.w3.ldp.testsuite.http.HttpHeaders.ACCEPT;
3032
import static org.w3.ldp.testsuite.http.HttpHeaders.LINK_REL_TYPE;
33+
import static org.w3.ldp.testsuite.http.HttpHeaders.LOCATION;
3134
import static org.w3.ldp.testsuite.http.HttpHeaders.PREFER;
3235
import static org.w3.ldp.testsuite.http.LdpPreferences.PREFER_MINIMAL_CONTAINER;
3336
import static org.w3.ldp.testsuite.http.MediaTypes.TEXT_TURTLE;
@@ -154,7 +157,7 @@ public void testContainerHasInsertedContentRelation() {
154157

155158
@Test(
156159
groups = {MUST},
157-
enabled = false,
160+
enabled = true,
158161
description = "LDPCs whose ldp:insertedContentRelation triple has an "
159162
+ "object other than ldp:MemberSubject and that create new "
160163
+ "resources MUST add a triple to the container whose subject is "
@@ -165,10 +168,48 @@ public void testContainerHasInsertedContentRelation() {
165168
+ "newly created resource in certain cases.")
166169
@SpecTest(
167170
specRefUri = LdpTestSuite.SPEC_URI + "#ldpic-post-indirectmbrrel",
168-
testMethod = METHOD.NOT_IMPLEMENTED,
171+
testMethod = METHOD.AUTOMATED,
169172
approval = STATUS.WG_PENDING)
170173
public void testPostResource() {
171-
// TODO: Impl testPostResource
174+
skipIfMethodNotAllowed(HttpMethod.POST);
175+
176+
if ( insertedContentRelationProperty != null ) {
177+
if ( insertedContentRelationProperty.getURI().equals(LDP.MemberSubject.stringValue()) ) {
178+
throw new SkipException(Thread.currentThread().getStackTrace()[1].getMethodName(),
179+
"The indirectContainer's ldp:insertedContentRelation triple has ldp:MemberSubject as the object.",
180+
skipLog);
181+
}
182+
}
183+
184+
Model model = postContent();
185+
Response postResponse = buildBaseRequestSpecification()
186+
.contentType(TEXT_TURTLE)
187+
.body(model, new RdfObjectMapper())
188+
.expect()
189+
.statusCode(HttpStatus.SC_CREATED)
190+
.header(LOCATION, notNullValue())
191+
.when()
192+
.post(indirectContainer);
193+
194+
String location = postResponse.getHeader(LOCATION);
195+
196+
Response getResponse = buildBaseRequestSpecification()
197+
.header(ACCEPT, TEXT_TURTLE)
198+
.header(PREFER, include(LdpPreferences.PREFER_CONTAINMENT))
199+
.when()
200+
.get(indirectContainer);
201+
Model containerModel = getResponse.as(Model.class, new RdfObjectMapper(indirectContainer));
202+
Resource container = containerModel.getResource(indirectContainer);
203+
Property contains = ResourceFactory.createProperty(LDP.contains.stringValue());
204+
205+
assertTrue(
206+
container.hasProperty(contains, containerModel.getResource(location)),
207+
"The IndirectContainer <"
208+
+ indirectContainer
209+
+ "> didn't create a triple with the containerURI as a subject, ldp:contains as the predicate "
210+
+ "and the resource's newly created URI as the object."
211+
);
212+
172213
}
173214

174215
private void setInsertedContentRelation() {

0 commit comments

Comments
 (0)