001package org.w3.ldp.testsuite.test; 002 003import com.jayway.restassured.response.Response; 004import org.testng.annotations.BeforeClass; 005import org.testng.annotations.Optional; 006import org.testng.annotations.Parameters; 007import org.testng.annotations.Test; 008import org.w3.ldp.testsuite.LdpTestSuite; 009import org.w3.ldp.testsuite.annotations.SpecTest; 010import org.w3.ldp.testsuite.annotations.SpecTest.METHOD; 011import org.w3.ldp.testsuite.annotations.SpecTest.STATUS; 012import org.w3.ldp.testsuite.exception.SkipException; 013import org.w3.ldp.testsuite.vocab.LDP; 014 015import java.io.IOException; 016 017import static org.testng.Assert.assertTrue; 018import static org.w3.ldp.testsuite.http.HttpHeaders.LINK_REL_TYPE; 019 020public class BasicContainerTest extends CommonContainerTest { 021 022 private String basicContainer; 023 024 @Parameters({"basicContainer", "auth"}) 025 public BasicContainerTest(@Optional String basicContainer, @Optional String auth) throws IOException { 026 super(auth); 027 this.basicContainer = basicContainer; 028 } 029 030 @Test( 031 groups = {MUST}, 032 description = "Each LDP Basic Container MUST also be a " 033 + "conforming LDP Container in section 5.2 Container " 034 + "along with the following restrictions in this section.") 035 @SpecTest( 036 specRefUri = LdpTestSuite.SPEC_URI + "#ldpbc-are-ldpcs", 037 testMethod = METHOD.INDIRECT, 038 approval = STATUS.WG_APPROVED, 039 coveredByTests = {CommonContainerTest.class}, 040 coveredByGroups = {MUST}) 041 public void testConformsBcLdpContainer() { 042 throw new org.testng.SkipException("Covered indirectly by the MUST tests defined in CommonContainerTest class"); 043 } 044 045 @BeforeClass(alwaysRun = true) 046 public void hasBasicContainer() { 047 if (basicContainer == null) { 048 throw new SkipException(Thread.currentThread().getStackTrace()[1].getMethodName(), 049 "No basicContainer parameter provided in testng.xml. Skipping ldp:basicContainer tests.", 050 skipLog); 051 } 052 } 053 054 @Test( 055 groups = {MUST}, 056 description = "LDP servers exposing LDPCs MUST advertise their " 057 + "LDP support by exposing a HTTP Link header with a " 058 + "target URI matching the type of container (see below) " 059 + "the server supports, and a link relation type of type " 060 + "(that is, rel='type') in all responses to requests made " 061 + "to the LDPC's HTTP Request-URI.") 062 @SpecTest( 063 specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-linktypehdr", 064 testMethod = METHOD.AUTOMATED, 065 approval = STATUS.WG_APPROVED, 066 comment = "Covers only part of the specification requirement. " 067 + "DirectContainerTest.testHttpLinkHeader and " 068 + "IndirectContainerTest.testContainerSupportsHttpLinkHeader " 069 + "covers the rest.") 070 public void testContainerSupportsHttpLinkHeader() { 071 Response response = buildBaseRequestSpecification().get(basicContainer); 072 assertTrue( 073 containsLinkHeader( 074 basicContainer, 075 LINK_REL_TYPE, 076 LDP.BasicContainer.stringValue(), 077 basicContainer, 078 response 079 ), 080 "LDP BasicContainers must advertise their LDP support by exposing " + 081 "a HTTP Link header with a URI matching <" 082 + LDP.BasicContainer.stringValue() + "> and rel='type'" 083 ); 084 } 085 086 @Override 087 protected String getResourceUri() { 088 return basicContainer; 089 } 090 091}