-
Notifications
You must be signed in to change notification settings - Fork 20
/
InfoBrokerPluginSpec.groovy
163 lines (129 loc) · 4.49 KB
/
InfoBrokerPluginSpec.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* Copyright 2014-2019 Netflix, Inc.
*
* 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
*
* http://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 nebula.plugin.info
import nebula.plugin.info.basic.BasicInfoPlugin
import nebula.test.ProjectSpec
import org.gradle.api.NamedDomainObjectContainer
import spock.lang.Ignore
import java.util.concurrent.atomic.AtomicBoolean
class InfoBrokerPluginSpec extends ProjectSpec {
def 'apply plugin'() {
when:
project.apply plugin: 'nebula.info-broker'
then:
noExceptionThrown()
project.plugins.getPlugin(InfoBrokerPlugin) != null
}
@Ignore("Not valid until we add manifest as an extension")
def 'extension can be extended in different ways'() {
when:
project.apply plugin: 'nebula.info-broker'
def basePlugin = project.plugins.getPlugin(InfoBrokerPlugin)
project.manifest {
MyKey { value = 'MyValue' }
}
then:
noExceptionThrown()
NamedDomainObjectContainer container = project.extensions.getByName('manifest')
InfoBrokerPlugin.ManifestEntry entry = container.getByName('MyKey')
entry instanceof InfoBrokerPlugin.ManifestEntry
entry.value == 'MyValue'
entry.valueProvider == null
when:
project.manifest.add( new InfoBrokerPlugin.ManifestEntry('MyKey2', 'MyValue2') )
then:
noExceptionThrown()
container.getByName('MyKey2') != null
container.getByName('MyKey') != null // Still around
when:
project.manifest.add( new InfoBrokerPlugin.ManifestEntry('MyKey3', {"MyValue" + "3"}) )
then:
noExceptionThrown()
InfoBrokerPlugin.ManifestEntry entry3 = container.getByName('MyKey3')
entry3.value == null
entry3.valueProvider instanceof Closure
when:
project.manifest.create('MyKey4') // No name
then:
noExceptionThrown() // We have to allow this because the raw call will do an add before configuring, validation is done in buildManifest
}
def 'build manifest'() {
when:
project.apply plugin: InfoBrokerPlugin
project.apply plugin: BasicInfoPlugin
then:
def basePlugin = project.plugins.getPlugin(InfoBrokerPlugin)
def attrs = basePlugin.buildManifest()
attrs['Manifest-Version'] == '1.0'
when:
basePlugin.add('MyKey', 'MyValue')
then:
def attrs2 = basePlugin.buildManifest()
attrs2['MyKey'] == 'MyValue'
when:
basePlugin.add('MyKey2') { 'MyValue2' }
then:
def attrs3 = basePlugin.buildManifest()
attrs3['MyKey2'] == 'MyValue2'
attrs3['MyKey'] == 'MyValue' // Still around
}
def 'can not add multiple values'() {
when:
InfoBrokerPlugin broker = project.plugins.apply(InfoBrokerPlugin)
broker.add('Key', 'Value')
then:
noExceptionThrown()
when:
broker.add('Key', 'Value2')
then:
def thrown = thrown(IllegalStateException)
thrown.message == 'A entry with the key Key already exists, with the value "Value"'
}
def 'listen for values'() {
when:
def broker = project.plugins.apply(InfoBrokerPlugin)
AtomicBoolean watched = new AtomicBoolean(false)
AtomicBoolean ran = new AtomicBoolean(false)
String watchedValue
broker.watch('Manifest-Version') {
watched.set(true)
watchedValue = it
}
String delayedValue
broker.watch('Delayed') {
ran.set(true)
delayedValue = it
}
then:
ran.get() == false
watched.get() == false
when:
broker.add('Manifest-Version') {
'1.0'
}
then: 'Delayed is not triggered too'
ran.get() == false
watched.get() == true
watchedValue == '1.0'
when:
broker.add('Delayed') {
'2.0'
}
then:
ran.get() == true
delayedValue == '2.0'
}
}