-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Cognifide/feature/add-resource-unit-tests
Fixed resource tests
- Loading branch information
Showing
5 changed files
with
169 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
core/src/test/kotlin/com/cognifide/apmt/tests/resource/ApmtCreateResourceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.cognifide.apmt.tests.resource | ||
|
||
import com.cognifide.apmt.actions.CSRF_TOKEN | ||
import com.cognifide.apmt.tests.APMT_TEXT | ||
import com.cognifide.apmt.tests.ApmtUsers | ||
import com.cognifide.apmt.tests.testCase | ||
import com.cognifide.apmt.util.AemStub | ||
import com.cognifide.apmt.util.AemStubExtension.Companion.registerUser | ||
import com.cognifide.apmt.util.AemStubExtension.Companion.registerUsers | ||
import com.github.tomakehurst.wiremock.client.WireMock.* | ||
import org.junit.jupiter.api.BeforeEach | ||
|
||
@AemStub | ||
class ApmtCreateResourceTest : CreateResourceTest( | ||
testCase { | ||
paths( | ||
"/content/my-site/de_de/home/text" | ||
) | ||
allowedUsers( | ||
ApmtUsers.AUTHOR, | ||
ApmtUsers.SUPER_AUTHOR | ||
) | ||
}, | ||
resource = { | ||
jcrPrimaryType = "nt:unstructured" | ||
slingResourceType = APMT_TEXT | ||
"value" set "Hello World!" | ||
} | ||
) { | ||
|
||
@BeforeEach | ||
fun beforeEach() { | ||
registerUser("admin", "admin") | ||
registerUsers(*ApmtUsers.values()) | ||
|
||
stubFor( | ||
post(urlPathEqualTo("/content/my-site/de_de/home/text")) | ||
.withHeader(CSRF_TOKEN, matching("author|super-author")) | ||
.willReturn(aResponse().withStatus(201)) | ||
) | ||
|
||
stubFor( | ||
post(urlPathEqualTo("/content/my-site/de_de/home/text")) | ||
.withHeader(CSRF_TOKEN, equalTo("user")) | ||
.willReturn(aResponse().withStatus(500)) | ||
) | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
core/src/test/kotlin/com/cognifide/apmt/tests/resource/ApmtEditResourceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.cognifide.apmt.tests.resource | ||
|
||
import com.cognifide.apmt.actions.CSRF_TOKEN | ||
import com.cognifide.apmt.tests.APMT_TEXT | ||
import com.cognifide.apmt.tests.ApmtUsers | ||
import com.cognifide.apmt.tests.testCase | ||
import com.cognifide.apmt.util.AemStub | ||
import com.cognifide.apmt.util.AemStubExtension.Companion.registerUser | ||
import com.cognifide.apmt.util.AemStubExtension.Companion.registerUsers | ||
import com.github.tomakehurst.wiremock.client.WireMock.* | ||
import org.junit.jupiter.api.BeforeEach | ||
|
||
@AemStub | ||
class ApmtEditResourceTest : EditResourceTest( | ||
testCase { | ||
paths( | ||
"/content/my-site/de_de/home/text" | ||
) | ||
allowedUsers( | ||
ApmtUsers.AUTHOR, | ||
ApmtUsers.SUPER_AUTHOR | ||
) | ||
}, | ||
createdResource = { | ||
jcrPrimaryType = "nt:unstructured" | ||
slingResourceType = APMT_TEXT | ||
"value" set "Hello World!" | ||
}, | ||
editedResource = { | ||
jcrPrimaryType = "nt:unstructured" | ||
slingResourceType = APMT_TEXT | ||
"value" set "Hello edited World!" | ||
} | ||
) { | ||
|
||
@BeforeEach | ||
fun beforeEach() { | ||
registerUser("admin", "admin") | ||
registerUsers(*ApmtUsers.values()) | ||
|
||
// apmt user creates resource first | ||
stubFor( | ||
post(urlPathEqualTo("/content/my-site/de_de/home/text")) | ||
.withHeader(CSRF_TOKEN, equalTo("admin")) | ||
.willReturn(aResponse().withStatus(201)) | ||
) | ||
|
||
stubFor( | ||
post(urlPathEqualTo("/content/my-site/de_de/home/text")) | ||
.withHeader(CSRF_TOKEN, matching("author|super-author")) | ||
.willReturn(aResponse().withStatus(200)) | ||
) | ||
|
||
stubFor( | ||
post(urlPathEqualTo("/content/my-site/de_de/home/text")) | ||
.withHeader(CSRF_TOKEN, equalTo("user")) | ||
.willReturn(aResponse().withStatus(500)) | ||
) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
core/src/test/kotlin/com/cognifide/apmt/tests/resource/ApmtRemoveResourceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.cognifide.apmt.tests.resource | ||
|
||
import com.cognifide.apmt.actions.CSRF_TOKEN | ||
import com.cognifide.apmt.tests.APMT_TEXT | ||
import com.cognifide.apmt.tests.ApmtUsers | ||
import com.cognifide.apmt.tests.testCase | ||
import com.cognifide.apmt.util.AemStub | ||
import com.cognifide.apmt.util.AemStubExtension.Companion.registerUser | ||
import com.cognifide.apmt.util.AemStubExtension.Companion.registerUsers | ||
import com.github.tomakehurst.wiremock.client.WireMock.* | ||
import org.junit.jupiter.api.BeforeEach | ||
|
||
@AemStub | ||
class ApmtRemoveResourceTest : RemoveResourceTest( | ||
testCase { | ||
paths( | ||
"/content/my-site/de_de/home/text" | ||
) | ||
allowedUsers( | ||
ApmtUsers.AUTHOR, | ||
ApmtUsers.SUPER_AUTHOR | ||
) | ||
}, | ||
resource = { | ||
jcrPrimaryType = "nt:unstructured" | ||
slingResourceType = APMT_TEXT | ||
"value" set "Hello World!" | ||
} | ||
) { | ||
@BeforeEach | ||
fun beforeEach() { | ||
registerUser("admin", "admin") | ||
registerUsers(*ApmtUsers.values()) | ||
|
||
// apmt user creates resource first | ||
stubFor( | ||
post(urlPathEqualTo("/content/my-site/de_de/home/text")) | ||
.withHeader(CSRF_TOKEN, equalTo("admin")) | ||
.willReturn(aResponse().withStatus(201)) | ||
) | ||
|
||
stubFor( | ||
delete(urlPathEqualTo("/content/my-site/de_de/home/text")) | ||
.withHeader(CSRF_TOKEN, matching("author|super-author")) | ||
.willReturn(aResponse().withStatus(204)) | ||
) | ||
|
||
stubFor( | ||
delete(urlPathEqualTo("/content/my-site/de_de/home/text")) | ||
.withHeader(CSRF_TOKEN, equalTo("user")) | ||
.willReturn(aResponse().withStatus(500)) | ||
) | ||
} | ||
} |