forked from Codearte/gradle-nexus-staging-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RepositoryStateFetcherSpec.groovy
56 lines (47 loc) · 2.35 KB
/
RepositoryStateFetcherSpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package io.codearte.gradle.nexus.logic
import io.codearte.gradle.nexus.exception.UnsupportedRepositoryState
import io.codearte.gradle.nexus.infra.NexusHttpResponseException
import io.codearte.gradle.nexus.infra.SimplifiedHttpJsonRestClient
class RepositoryStateFetcherSpec extends BaseOperationExecutorSpec implements FetcherResponseTrait {
private static final String GET_REPOSITORY_STATE_PATH = "/staging/repository/"
private SimplifiedHttpJsonRestClient client
private RepositoryStateFetcher repoStateFetcher
void setup() {
client = Mock(SimplifiedHttpJsonRestClient)
repoStateFetcher = new RepositoryStateFetcher(client, MOCK_SERVER_HOST)
}
@SuppressWarnings("GrDeprecatedAPIUsage")
def "should return state received from server mapped to enum"() {
given:
client.get(getGetRepositoryStateFullUrlForRepoId(TEST_REPOSITORY_ID)) >> { aRepoInStateAndId(TEST_REPOSITORY_ID, 'closed') }
when:
RepositoryState repoState = repoStateFetcher.getNonTransitioningRepositoryStateById(TEST_REPOSITORY_ID)
then:
repoState == RepositoryState.CLOSED
}
@SuppressWarnings("GrDeprecatedAPIUsage")
def "should throw exception with meaningful message if unsupported or missing state"() {
given:
client.get(getGetRepositoryStateFullUrlForRepoId(TEST_REPOSITORY_ID)) >> { aRepoInStateAndId(TEST_REPOSITORY_ID, unsupportedState) }
when:
repoStateFetcher.getNonTransitioningRepositoryStateById(TEST_REPOSITORY_ID)
then:
UnsupportedRepositoryState e = thrown()
e.unsupportedState == unsupportedState
where:
unsupportedState << ['completely wrong', null]
}
def "should map 404 error from server to NOT_FOUND state"() {
given:
client.get(getGetRepositoryStateFullUrlForRepoId(TEST_REPOSITORY_ID)) >> {
throw new NexusHttpResponseException(404, "404: Not Found, body: ${aNotFoundRepo(TEST_REPOSITORY_ID)}")
}
when:
RepositoryState repoState = repoStateFetcher.getNonTransitioningRepositoryStateById(TEST_REPOSITORY_ID)
then:
repoState == RepositoryState.NOT_FOUND
}
private String getGetRepositoryStateFullUrlForRepoId(String repoId) {
return MOCK_SERVER_HOST + GET_REPOSITORY_STATE_PATH + repoId
}
}