-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
889 additions
and
12 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
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,20 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2018-2022 Agorapulse. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
dependencies { | ||
api project(':gru') | ||
} |
130 changes: 130 additions & 0 deletions
130
kotlin-libs/gru-kotlin/src/main/kotlin/com/agorapulse/gru/kotlin/Gru.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,130 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2018-2022 Agorapulse. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.agorapulse.gru.kotlin | ||
|
||
import com.agorapulse.gru.* | ||
import com.agorapulse.gru.minions.Minion | ||
import java.io.Closeable | ||
import com.agorapulse.gru.Gru as JavaGru | ||
|
||
fun create(client: Client): Gru { | ||
return Gru(JavaGru.create(client)) | ||
} | ||
|
||
/** | ||
* Gru steals the controller's unit test to verify controller's actions in context. | ||
* | ||
* | ||
*/ | ||
class Gru constructor(private val delegate: JavaGru) : Closeable { | ||
|
||
/** | ||
* Prepare every test with following configuration. | ||
* | ||
* @param configuration configuration applied to every feature method | ||
* @return self | ||
*/ | ||
fun prepare( | ||
configuration: TestDefinitionBuilder.() -> TestDefinitionBuilder | ||
): Gru { | ||
delegate.prepare { configuration(TestDefinitionBuilder(it)) } | ||
return this | ||
} | ||
|
||
/** | ||
* Prepare tests with given base URI. | ||
* | ||
* @param baseUri the base URI for the test calls | ||
* @return self | ||
*/ | ||
fun prepare(baseUri: String): Gru { | ||
delegate.prepare(baseUri) | ||
return this | ||
} | ||
|
||
/** | ||
* Adds minion to the squad for current test. | ||
* | ||
* @param minion minion to be added to the squad | ||
* @return self | ||
*/ | ||
fun engage(minion: Minion): Gru { | ||
delegate.engage(minion) | ||
return this | ||
} | ||
|
||
/** | ||
* Checks if the expectations has been verified and resets the internal state. | ||
*/ | ||
override fun close() { | ||
delegate.close() | ||
} | ||
|
||
/** | ||
* Defines and verifies API test and runs the controller initialization and the action under test. | ||
* | ||
* | ||
* | ||
* @param expectation test definition | ||
*/ | ||
@Throws(Throwable::class) | ||
fun verify(expectation: TestDefinitionBuilder.() -> TestDefinitionBuilder) { | ||
delegate.verify { expectation(TestDefinitionBuilder(it)) } | ||
} | ||
|
||
/** | ||
* Defines API test and runs the controller initialization and the action under test. | ||
* | ||
* | ||
* Use this method either in when or expect block. | ||
* | ||
* @param expectation test definition | ||
* @return self, note that when Groovy Truth is evaluated, `verify` method is called automatically | ||
*/ | ||
fun test(expectation: TestDefinitionBuilder.() -> TestDefinitionBuilder): Gru { | ||
delegate.test { expectation(TestDefinitionBuilder(it)) } | ||
return this | ||
} | ||
|
||
/** | ||
* Verifies all expectations. | ||
* | ||
* @return true if all verifications are successful | ||
* @throws AssertionError if any verification fails | ||
*/ | ||
@Throws(Throwable::class) | ||
fun verify(): Boolean { | ||
return delegate.verify() | ||
} | ||
|
||
|
||
/** | ||
* Reset the internal state. This is done by the rule automatically. | ||
* | ||
* @param resetConfigurations also clear the configurations created using [.prepare] method | ||
*/ | ||
/** | ||
* Reset the internal state. This is done by the rule automatically. | ||
*/ | ||
@JvmOverloads | ||
fun reset(resetConfigurations: Boolean = true): Gru { | ||
delegate.reset(resetConfigurations) | ||
return this | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
...n-libs/gru-kotlin/src/main/kotlin/com/agorapulse/gru/kotlin/MultipartDefinitionBuilder.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,57 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2018-2022 Agorapulse. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.agorapulse.gru.kotlin | ||
|
||
import com.agorapulse.gru.Content | ||
import com.agorapulse.gru.WithContentSupport | ||
import com.agorapulse.gru.content.FileContent | ||
import org.intellij.lang.annotations.Language | ||
import java.util.* | ||
import com.agorapulse.gru.MultipartDefinitionBuilder as JavaMultipartDefinitionBuilder | ||
|
||
class MultipartDefinitionBuilder(private val delegate: JavaMultipartDefinitionBuilder) : WithContentSupport { | ||
|
||
fun params(params: Map<String, Any>): MultipartDefinitionBuilder { | ||
delegate.params(params) | ||
return this | ||
} | ||
|
||
fun param(name: String, value: Any): MultipartDefinitionBuilder { | ||
return params(Collections.singletonMap(name, value)) | ||
} | ||
|
||
fun file( | ||
parameterName: String, | ||
filename: String, | ||
content: Content, | ||
@Language("mime-type-reference") contentType: String | ||
): MultipartDefinitionBuilder { | ||
delegate.file(parameterName, filename, content, contentType) | ||
return this | ||
} | ||
|
||
fun file( | ||
parameterName: String, | ||
filename: String, | ||
relativePath: String, | ||
@Language("mime-type-reference") contentType: String | ||
): MultipartDefinitionBuilder { | ||
return file(parameterName, filename, FileContent.create(relativePath), contentType) | ||
} | ||
|
||
} |
Oops, something went wrong.