-
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.
- Loading branch information
1 parent
44138e8
commit 87b77c0
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
core/src/main/kotlin/com/cognifide/apmt/actions/tags/RemoveTag.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,23 @@ | ||
package com.cognifide.apmt.actions.tags | ||
|
||
import com.cognifide.apmt.User | ||
import com.cognifide.apmt.actions.Action | ||
import com.cognifide.apmt.config.Instance | ||
import io.restassured.response.Response | ||
|
||
|
||
class RemoveTag(override val instance: Instance, override val user: User, override val path: String) : Action { | ||
override fun prepare(): Response? { | ||
return CreateTag(instance, instance.adminUser, path).execute() | ||
} | ||
|
||
override fun execute(): Response? { | ||
return CreateTag(instance, user, path).undo() | ||
} | ||
|
||
override fun undo(): Response? = null | ||
|
||
override fun successCode(): Int = 204 | ||
|
||
override fun failureCode(): Int = 500 | ||
} |
64 changes: 64 additions & 0 deletions
64
core/src/test/kotlin/com/cognifide/apmt/actions/tags/RemoveTagTest.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,64 @@ | ||
package com.cognifide.apmt.actions.tags | ||
|
||
import com.cognifide.apmt.MOCK_SERVER | ||
import com.cognifide.apmt.TEST_ADMIN | ||
import com.cognifide.apmt.TEST_USER | ||
import com.cognifide.apmt.util.AemStub | ||
import com.cognifide.apmt.util.HumanReadableCamelCase | ||
import com.github.tomakehurst.wiremock.client.BasicCredentials | ||
import com.github.tomakehurst.wiremock.client.WireMock.* | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertNull | ||
import org.junit.jupiter.api.DisplayNameGeneration | ||
import org.junit.jupiter.api.Test | ||
|
||
const val TAG_PATH = "/removed-tag" | ||
|
||
@DisplayNameGeneration(HumanReadableCamelCase::class) | ||
class RemoveTagTest { | ||
private val removeTag = RemoveTag(MOCK_SERVER, TEST_USER, TAG_PATH) | ||
|
||
@Test | ||
fun onSuccessReturns204() { | ||
assertEquals(204, removeTag.successCode()) | ||
} | ||
|
||
@Test | ||
fun onFailureReturns500() { | ||
assertEquals(500, removeTag.failureCode()) | ||
} | ||
|
||
@Test | ||
fun callingUndoDoesNothing() { | ||
assertNull(removeTag.undo()) | ||
} | ||
|
||
@Test | ||
@AemStub | ||
fun callingExecutePerformsDelete() { | ||
stubFor( | ||
delete(urlPathEqualTo(TAG_PATH)) | ||
.willReturn(ok()) | ||
) | ||
|
||
removeTag.execute() | ||
|
||
verify(deleteRequestedFor(urlPathEqualTo(TAG_PATH))) | ||
} | ||
|
||
@Test | ||
@AemStub | ||
fun callingPrepareCreatesTagWithAdminSession() { | ||
stubFor( | ||
post(urlPathEqualTo(TAG_PATH)) | ||
.willReturn(ok()) | ||
) | ||
|
||
removeTag.prepare() | ||
|
||
verify( | ||
postRequestedFor(urlPathEqualTo(TAG_PATH)) | ||
.withBasicAuth(BasicCredentials(TEST_ADMIN.username, TEST_ADMIN.password)) | ||
) | ||
} | ||
} |