Skip to content

Commit

Permalink
Add RemoveTag action (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrzyzanowski committed May 17, 2019
1 parent 44138e8 commit 87b77c0
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
23 changes: 23 additions & 0 deletions core/src/main/kotlin/com/cognifide/apmt/actions/tags/RemoveTag.kt
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
}
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))
)
}
}

0 comments on commit 87b77c0

Please sign in to comment.