-
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 #8 from Cognifide/feature/new-approach-of-tests
New approach of tests.
- Loading branch information
Showing
64 changed files
with
1,701 additions
and
141 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ branches: | |
- /^release.*$/ | ||
|
||
jdk: | ||
- oraclejdk8 | ||
- openjdk8 | ||
|
||
before_install: | ||
- chmod +x gradlew |
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
90 changes: 90 additions & 0 deletions
90
core/src/main/kotlin/com/cognifide/apmt/ArgumentsFactory.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,90 @@ | ||
package com.cognifide.apmt | ||
|
||
import org.junit.jupiter.api.Assumptions | ||
import org.junit.jupiter.params.provider.Arguments | ||
|
||
fun createAllowed(testCases: List<TestCaseConfiguration>): List<Arguments> { | ||
return toArguments(testCases.flatMap { createAllowed(it) }.distinct().sorted()) | ||
} | ||
|
||
fun createDenied(testCases: List<TestCaseConfiguration>): List<Arguments> { | ||
return toArguments(testCases.flatMap { createDenied(it) }.distinct().sorted()) | ||
} | ||
|
||
private fun createAllowed(testCase: TestCaseConfiguration): List<UserAndPath> { | ||
return createArguments( | ||
testCase.paths, | ||
testCase.allowedUsers, | ||
testCase.deniedUsers, | ||
testCase.allUsers, | ||
testCase.allowedPairsPredicate, | ||
testCase.deniedPairsPredicate | ||
) | ||
} | ||
|
||
private fun createDenied(testCase: TestCaseConfiguration): List<UserAndPath> { | ||
return createArguments( | ||
testCase.paths, | ||
testCase.deniedUsers, | ||
testCase.allowedUsers, | ||
testCase.allUsers, | ||
testCase.deniedPairsPredicate, | ||
testCase.allowedPairsPredicate | ||
) | ||
} | ||
|
||
private fun createArguments( | ||
paths: List<String>, | ||
users: List<User>, | ||
opposedUsers: List<User>, | ||
allUsers: List<User>, | ||
predicate: ((user: User, path: String) -> Boolean)?, | ||
opposedPredicate: ((user: User, path: String) -> Boolean)? | ||
): List<UserAndPath> { | ||
return when { | ||
users.isNotEmpty() -> pairs(users, paths, predicate) | ||
opposedUsers.isNotEmpty() && allUsers.isNotEmpty() -> { | ||
val allPairs = pairs(allUsers, paths) | ||
allPairs - pairs(opposedUsers, paths, opposedPredicate) | ||
} | ||
else -> listOf() | ||
} | ||
} | ||
|
||
private fun toArguments(usersAndPaths: Collection<UserAndPath>): List<Arguments> { | ||
val arguments = mutableListOf<Arguments>() | ||
usersAndPaths.forEach { arguments.add(Arguments.of(it.user, it.path)) } | ||
|
||
Assumptions.assumeFalse(arguments.isEmpty(), "No arguments") | ||
|
||
return arguments.toList() | ||
} | ||
|
||
private fun pairs( | ||
users: List<User>, | ||
paths: List<String>, | ||
predicate: ((user: User, path: String) -> Boolean)? | ||
): List<UserAndPath> { | ||
val pairs = pairs(users, paths) | ||
if (predicate != null) { | ||
return pairs.filter { predicate(it.user, it.path) } | ||
} | ||
return pairs | ||
} | ||
|
||
private fun pairs(users: List<User>, paths: List<String>): List<UserAndPath> { | ||
val results = mutableListOf<UserAndPath>() | ||
for (user in users) { | ||
for (path in paths) { | ||
results.add(UserAndPath(user, path)) | ||
} | ||
} | ||
return results.toList() | ||
} | ||
|
||
data class UserAndPath(val user: User, val path: String) : Comparable<UserAndPath> { | ||
|
||
override fun compareTo(other: UserAndPath): Int { | ||
return this.user.username.compareTo(other.user.username) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
core/src/main/kotlin/com/cognifide/apmt/PermissionTestsConfiguration.kt
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
core/src/main/kotlin/com/cognifide/apmt/PermissionTestsFactory.kt
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
package com.cognifide.apmt | ||
|
||
interface TestCase { | ||
|
||
fun toTestCaseConfiguration(): TestCaseConfiguration | ||
} |
41 changes: 31 additions & 10 deletions
41
core/src/main/kotlin/com/cognifide/apmt/TestCaseConfiguration.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 |
---|---|---|
@@ -1,19 +1,40 @@ | ||
package com.cognifide.apmt | ||
|
||
import kotlin.reflect.KFunction2 | ||
|
||
class TestCaseConfiguration( | ||
var name: String = "", | ||
var test: KFunction2<String, String, Unit>? = null, | ||
internal val paths: MutableList<String> = mutableListOf(), | ||
internal val users: MutableList<User> = mutableListOf() | ||
class TestCaseConfiguration @JvmOverloads constructor( | ||
internal var allowedUsers: List<User> = listOf(), | ||
internal var deniedUsers: List<User> = listOf(), | ||
internal var paths: List<String> = listOf(), | ||
internal var allUsers: List<User> = listOf(), | ||
internal var allowedPairsPredicate: ((user: User, path: String) -> Boolean)? = null, | ||
internal var deniedPairsPredicate: ((user: User, path: String) -> Boolean)? = null | ||
) { | ||
|
||
fun addPath(path: String) { | ||
paths.add(path) | ||
fun allUsers(allUsers: Array<out User>) { | ||
this.allUsers = allUsers.toList() | ||
} | ||
|
||
fun addUser(user: User) { | ||
users.add(user) | ||
fun allUsers(allUsers: List<User>) { | ||
this.allUsers = allUsers | ||
} | ||
|
||
fun paths(vararg paths: String) { | ||
this.paths = paths.toList() | ||
} | ||
|
||
fun allowedUsers(vararg users: User) { | ||
this.allowedUsers = users.toList() | ||
} | ||
|
||
fun deniedUsers(vararg users: User) { | ||
this.deniedUsers = users.toList() | ||
} | ||
|
||
fun allowedPairsPredicate(predicate: (user: User, path: String) -> Boolean) { | ||
this.allowedPairsPredicate = predicate | ||
} | ||
|
||
fun deniedPairsPredicate(predicate: (user: User, path: String) -> Boolean) { | ||
this.deniedPairsPredicate = predicate | ||
} | ||
} |
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 |
---|---|---|
|
@@ -4,5 +4,5 @@ interface User { | |
|
||
val username: String | ||
val password: String | ||
val groups: List<Group> | ||
|
||
} |
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
31 changes: 31 additions & 0 deletions
31
core/src/main/kotlin/com/cognifide/apmt/actions/asset/CreateAsset.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,31 @@ | ||
package com.cognifide.apmt.actions.asset | ||
|
||
import com.cognifide.apmt.User | ||
import com.cognifide.apmt.actions.Action | ||
import com.cognifide.apmt.actions.ActionContext | ||
import com.cognifide.apmt.config.Instance | ||
import io.restassured.response.Response | ||
|
||
class CreateAsset( | ||
private val instance: Instance, | ||
private val user: User, | ||
private val path: String | ||
) : Action { | ||
|
||
override fun execute(): Response { | ||
return ActionContext.basicRequestSpec(user, instance) | ||
.formParam("jcr:primaryType", "sling:OrderedFolder") | ||
.formParam("jcr:content/jcr:primaryType", "nt:unstructured") | ||
.formParam("jcr:content/jcr:title", "Test Title") | ||
.`when`() | ||
.post(instance.url + path) | ||
} | ||
|
||
override fun undo(): Response? { | ||
return ActionContext.basicRequestSpec(user, instance) | ||
.delete(instance.url + path) | ||
} | ||
|
||
override fun successCode(): Int = 200 | ||
override fun failureCode(): Int = 404 | ||
} |
24 changes: 24 additions & 0 deletions
24
core/src/main/kotlin/com/cognifide/apmt/actions/asset/EditAsset.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,24 @@ | ||
package com.cognifide.apmt.actions.asset | ||
|
||
import com.cognifide.apmt.User | ||
import com.cognifide.apmt.actions.Action | ||
import com.cognifide.apmt.actions.ActionContext | ||
import com.cognifide.apmt.config.Instance | ||
import io.restassured.response.Response | ||
|
||
class EditAsset( | ||
private val instance: Instance, | ||
private val user: User, | ||
private val path: String | ||
) : Action { | ||
|
||
override fun execute(): Response { | ||
return ActionContext.basicRequestSpec(user, instance) | ||
.formParam("jcr:title", "Some Title") | ||
.`when`() | ||
.post(instance.url + path) | ||
} | ||
|
||
override fun successCode(): Int = 200 | ||
override fun failureCode(): Int = 500 | ||
} |
22 changes: 22 additions & 0 deletions
22
core/src/main/kotlin/com/cognifide/apmt/actions/asset/RemoveAsset.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,22 @@ | ||
package com.cognifide.apmt.actions.asset | ||
|
||
import com.cognifide.apmt.User | ||
import com.cognifide.apmt.actions.Action | ||
import com.cognifide.apmt.actions.ActionContext | ||
import com.cognifide.apmt.config.Instance | ||
import io.restassured.response.Response | ||
|
||
class RemoveAsset( | ||
private val instance: Instance, | ||
private val user: User, | ||
private val path: String | ||
) : Action { | ||
|
||
override fun execute(): Response { | ||
return ActionContext.basicRequestSpec(user, instance) | ||
.delete(instance.url + path) | ||
} | ||
|
||
override fun successCode(): Int = 204 | ||
override fun failureCode(): Int = 403 | ||
} |
Oops, something went wrong.