Changed package name to lowercase and added validation for classname in type variable.
References #162
This commit is contained in:
parent
60844705ae
commit
f921b14c8b
|
@ -1,2 +1,2 @@
|
|||
type: deploydb.models.Promotion.BasicPromotionImpl
|
||||
type: deploydb.models.promotion.BasicPromotionImpl
|
||||
description: "Basic Smoke test for the Basic Service"
|
||||
|
|
|
@ -8,7 +8,7 @@ Feature: Promotion READ APIs
|
|||
|
||||
Given a promotion configuration name "basic":
|
||||
"""
|
||||
type: deploydb.models.Promotion.BasicPromotionImpl
|
||||
type: deploydb.models.promotion.BasicPromotionImpl
|
||||
description: "Smoke test the Fun as a Service service"
|
||||
"""
|
||||
When I GET "/api/promotions"
|
||||
|
@ -17,7 +17,7 @@ Feature: Promotion READ APIs
|
|||
"""
|
||||
[{
|
||||
"ident" : "basic",
|
||||
"type" : "deploydb.models.Promotion.BasicPromotionImpl",
|
||||
"type" : "deploydb.models.promotion.BasicPromotionImpl",
|
||||
"description" : "Smoke test the Fun as a Service service",
|
||||
"attributes" : null
|
||||
}]
|
||||
|
@ -28,7 +28,7 @@ Feature: Promotion READ APIs
|
|||
|
||||
Given a promotion configuration name "basic":
|
||||
"""
|
||||
type: deploydb.models.Promotion.BasicPromotionImpl
|
||||
type: deploydb.models.promotion.BasicPromotionImpl
|
||||
description: "Smoke test the Fun as a Service service"
|
||||
"""
|
||||
When I GET "/api/promotions/basic"
|
||||
|
@ -37,7 +37,7 @@ Feature: Promotion READ APIs
|
|||
"""
|
||||
{
|
||||
"ident" : "basic",
|
||||
"type" : "deploydb.models.Promotion.BasicPromotionImpl",
|
||||
"type" : "deploydb.models.promotion.BasicPromotionImpl",
|
||||
"description" : "Smoke test the Fun as a Service service",
|
||||
"attributes" : null
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package deploydb.cucumber
|
|||
|
||||
import deploydb.models.Artifact
|
||||
import deploydb.models.Deployment
|
||||
import deploydb.models.Promotion.Promotion
|
||||
import deploydb.models.promotion.Promotion
|
||||
import deploydb.models.Service
|
||||
import deploydb.models.Webhook.Webhook
|
||||
import deploydb.models.pipeline.Pipeline
|
||||
|
@ -43,19 +43,19 @@ class ModelHelper {
|
|||
*/
|
||||
Promotion samplePromotion1() {
|
||||
return new Promotion('status-check',
|
||||
'deploydb.models.Promotion.BasicPromotionImpl',
|
||||
'deploydb.models.promotion.BasicPromotionImpl',
|
||||
'Status Check for Fun as a Service')
|
||||
}
|
||||
|
||||
Promotion samplePromotion2() {
|
||||
return new Promotion('jenkins-smoke',
|
||||
'deploydb.models.Promotion.BasicPromotionImpl',
|
||||
'deploydb.models.promotion.BasicPromotionImpl',
|
||||
'jenkins-smoke for Fun as a Service')
|
||||
}
|
||||
|
||||
Promotion sampleManualLDAPPromotion() {
|
||||
Promotion promotion = new Promotion("manual-promotion",
|
||||
"deploydb.models.Promotion.ManualLDAPPromotionImpl",
|
||||
"deploydb.models.promotion.ManualLDAPPromotionImpl",
|
||||
"Manual Promotion smoke test")
|
||||
promotion.attributes = ["allowedGroup":"fox"]
|
||||
return promotion
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
this.metaClass.mixin(cucumber.api.groovy.EN)
|
||||
|
||||
import deploydb.ModelLoader
|
||||
import deploydb.models.Promotion.Promotion
|
||||
import deploydb.models.promotion.Promotion
|
||||
import deploydb.registry.ModelRegistry
|
||||
|
||||
|
||||
|
|
|
@ -13,12 +13,12 @@ class BreakLoopException extends Exception{}
|
|||
|
||||
class WorkFlow {
|
||||
private final DeployDBApp deployDBApp
|
||||
private registry.ModelRegistry<models.Promotion.Promotion> promotionRegistry
|
||||
private registry.ModelRegistry<models.promotion.Promotion> promotionRegistry
|
||||
private registry.ModelRegistry<models.Environment> environmentRegistry
|
||||
private registry.ModelRegistry<models.pipeline.Pipeline> pipelineRegistry
|
||||
private registry.ModelRegistry<models.Service> serviceRegistry
|
||||
private models.Webhook.Webhook globalWebhook
|
||||
private ModelLoader<models.Promotion.Promotion> promotionLoader
|
||||
private ModelLoader<models.promotion.Promotion> promotionLoader
|
||||
private ModelLoader<models.Environment> environmentLoader
|
||||
private ModelLoader<models.pipeline.Pipeline> pipelineLoader
|
||||
private ModelLoader<models.Service> serviceLoader
|
||||
|
@ -49,7 +49,7 @@ class WorkFlow {
|
|||
/**
|
||||
* Instantiate registries for in memory storage
|
||||
*/
|
||||
promotionRegistry = new registry.ModelRegistry<models.Promotion.Promotion>()
|
||||
promotionRegistry = new registry.ModelRegistry<models.promotion.Promotion>()
|
||||
environmentRegistry = new registry.ModelRegistry<models.Environment>()
|
||||
pipelineRegistry = new registry.ModelRegistry<models.pipeline.Pipeline>()
|
||||
serviceRegistry = new registry.ModelRegistry<models.Service>()
|
||||
|
@ -57,7 +57,7 @@ class WorkFlow {
|
|||
/**
|
||||
* Instantiate in memory loaders for yaml parsing
|
||||
*/
|
||||
promotionLoader = new ModelLoader<>(models.Promotion.Promotion.class)
|
||||
promotionLoader = new ModelLoader<>(models.promotion.Promotion.class)
|
||||
environmentLoader = new ModelLoader<>(models.Environment.class)
|
||||
pipelineLoader = new ModelLoader<>(models.pipeline.Pipeline.class)
|
||||
serviceLoader = new ModelLoader<>(models.Service.class)
|
||||
|
@ -146,8 +146,8 @@ class WorkFlow {
|
|||
* Instantiate new registries for in memory storage. We will overwrite the
|
||||
* older registries in the end
|
||||
*/
|
||||
registry.ModelRegistry<models.Promotion.Promotion> tmpPromotionRegistry =
|
||||
new registry.ModelRegistry<models.Promotion.Promotion>()
|
||||
registry.ModelRegistry<models.promotion.Promotion> tmpPromotionRegistry =
|
||||
new registry.ModelRegistry<models.promotion.Promotion>()
|
||||
registry.ModelRegistry<models.Environment> tmpEnvironmentRegistry =
|
||||
new registry.ModelRegistry<models.Environment>()
|
||||
registry.ModelRegistry<models.pipeline.Pipeline> tmpPipelineRegistry =
|
||||
|
@ -162,7 +162,7 @@ class WorkFlow {
|
|||
String promotionsDirName = this.deployDBApp.configDirectory + "/promotions"
|
||||
loadConfigModelsCommon(promotionsDirName, ModelType.PROMOTION,
|
||||
tmpPromotionRegistry, this.promotionLoader,
|
||||
inputStreams, modelConfigList) { models.Promotion.Promotion promotion ->
|
||||
inputStreams, modelConfigList) { models.promotion.Promotion promotion ->
|
||||
logger.debug("Loaded promotions model: ${promotion.ident}")
|
||||
}
|
||||
|
||||
|
@ -353,7 +353,7 @@ class WorkFlow {
|
|||
* @param deployment
|
||||
* @return Promotion
|
||||
*/
|
||||
models.Promotion.Promotion retrievePromotion(models.Deployment deployment, String promotionIdent) {
|
||||
models.promotion.Promotion retrievePromotion(models.Deployment deployment, String promotionIdent) {
|
||||
|
||||
/**
|
||||
* If configuration is changed since the flow creation, then retrieve and
|
||||
|
@ -365,7 +365,7 @@ class WorkFlow {
|
|||
this.modelConfigDAO.findModelConfig(ModelType.PROMOTION,
|
||||
promotionIdent, deployment.flow.configChecksum)
|
||||
if (promotionConfig) {
|
||||
models.Promotion.Promotion promotion =
|
||||
models.promotion.Promotion promotion =
|
||||
this.promotionLoader.loadFromString(promotionConfig.contents)
|
||||
return promotion
|
||||
} else {
|
||||
|
@ -457,7 +457,7 @@ class WorkFlow {
|
|||
}
|
||||
|
||||
/* Get all promotions in service & pipelines */
|
||||
List<models.Promotion.Promotion> promotions = service.getPromotions().collect() { String promotionIdent ->
|
||||
List<models.promotion.Promotion> promotions = service.getPromotions().collect() { String promotionIdent ->
|
||||
this.promotionRegistry.get(promotionIdent)
|
||||
}
|
||||
promotions.addAll(pipelinePromotions)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package deploydb.models.Promotion
|
||||
package deploydb.models.promotion
|
||||
|
||||
import deploydb.auth.User
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package deploydb.models.Promotion
|
||||
package deploydb.models.promotion
|
||||
|
||||
import deploydb.auth.User
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
package deploydb.models.Promotion
|
||||
package deploydb.models.promotion
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import deploydb.auth.User
|
||||
import io.dropwizard.validation.ValidationMethod
|
||||
import org.hibernate.validator.constraints.NotEmpty
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
|
@ -23,12 +25,27 @@ class Promotion {
|
|||
String ident
|
||||
|
||||
/**
|
||||
* Type of the promotion
|
||||
*
|
||||
* Type (i.e.) full class name for the impl class
|
||||
*/
|
||||
@NotEmpty
|
||||
@JsonProperty
|
||||
String type
|
||||
|
||||
/**
|
||||
* Validate contents of "type" using following annotation
|
||||
*
|
||||
* @return true if its a valid class name
|
||||
*/
|
||||
@ValidationMethod(message = "Promotion does not have a valid class name in \"type\"")
|
||||
boolean isType() {
|
||||
try {
|
||||
PromotionImpl impl = getPromotionImpl()
|
||||
} catch (all) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Description of this promotion
|
||||
*/
|
||||
|
@ -107,13 +124,11 @@ class Promotion {
|
|||
Objects.equals(this.description, that.description)
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
int hashCode() {
|
||||
return Objects.hash(this.ident, this.type, this.description)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stringy the promotion
|
||||
*/
|
|
@ -1,4 +1,4 @@
|
|||
package deploydb.models.Promotion
|
||||
package deploydb.models.promotion
|
||||
|
||||
import deploydb.auth.User
|
||||
|
|
@ -6,7 +6,7 @@ import deploydb.WorkFlow
|
|||
import deploydb.auth.User
|
||||
import deploydb.mappers.PromotionResultAddMapper
|
||||
import deploydb.models.Deployment
|
||||
import deploydb.models.Promotion.Promotion
|
||||
import deploydb.models.promotion.Promotion
|
||||
import deploydb.models.PromotionResult
|
||||
import deploydb.mappers.DeploymentUpdateMapper
|
||||
import io.dropwizard.auth.Auth
|
||||
|
|
|
@ -2,7 +2,7 @@ package deploydb.resources
|
|||
|
||||
import com.codahale.metrics.annotation.Timed
|
||||
import com.sun.research.ws.wadl.Response
|
||||
import deploydb.models.Promotion.Promotion
|
||||
import deploydb.models.promotion.Promotion
|
||||
import deploydb.registry.ModelRegistry
|
||||
import io.dropwizard.hibernate.UnitOfWork
|
||||
import org.slf4j.Logger
|
||||
|
|
|
@ -42,7 +42,7 @@ class workFlowWithArgsSpec extends Specification {
|
|||
|
||||
def createPromotionConfigFile() {
|
||||
String fileContents = """
|
||||
type: deploydb.models.Promotion.BasicPromotionImpl
|
||||
type: deploydb.models.promotion.BasicPromotionImpl
|
||||
description: "Basic Smoke test for the Basic Service"
|
||||
"""
|
||||
/* Create temp file */
|
||||
|
@ -57,8 +57,8 @@ description: "Basic Smoke test for the Basic Service"
|
|||
|
||||
def createAnotherPromotionConfigFile() {
|
||||
String fileContents = """
|
||||
type: deploydb.models.Promotion.AdvancedPromotionImpl
|
||||
description: "Advanced Smoke test for the Basic Service"
|
||||
type: deploydb.models.promotion.ManualLDAPPromotionImpl
|
||||
description: "Manual LDAP Promotion"
|
||||
"""
|
||||
/* Create temp file */
|
||||
File promotionsDir = new File("${baseCfgDirName}/promotions")
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
package deploydb.models.Promotion
|
||||
package deploydb.models.promotion
|
||||
|
||||
import deploydb.ModelLoader
|
||||
import deploydb.auth.User
|
||||
import deploydb.registry.ModelRegistry
|
||||
import io.dropwizard.configuration.ConfigurationParsingException
|
||||
import io.dropwizard.configuration.ConfigurationValidationException
|
||||
import spock.lang.Ignore
|
||||
import spock.lang.Specification
|
||||
|
||||
|
@ -26,14 +27,14 @@ class PromotionWithArgsSpec extends Specification {
|
|||
def "Loading of valid basic promotion config content succeeds"() {
|
||||
given:
|
||||
Promotion promotion = promotionLoader.loadFromString("""
|
||||
type: deploydb.models.Promotion.BasicPromotionImpl
|
||||
type: deploydb.models.promotion.BasicPromotionImpl
|
||||
description: Basic Promotion Smoke Test
|
||||
""")
|
||||
promotion.ident = "basic"
|
||||
promotionRegistry.put(promotion.ident, promotion)
|
||||
|
||||
expect:
|
||||
promotion.type == 'deploydb.models.Promotion.BasicPromotionImpl'
|
||||
promotion.type == 'deploydb.models.promotion.BasicPromotionImpl'
|
||||
promotion.description == "Basic Promotion Smoke Test"
|
||||
promotion.attributes == null
|
||||
promotionRegistry.get("basic") == promotion
|
||||
|
@ -42,11 +43,10 @@ description: Basic Promotion Smoke Test
|
|||
promotion.validate(user) == true
|
||||
}
|
||||
|
||||
|
||||
def "When allowedGroup matches with User authorized groups, then validation succeeds"() {
|
||||
given:
|
||||
Promotion promotion = promotionLoader.loadFromString("""
|
||||
type: deploydb.models.Promotion.ManualLDAPPromotionImpl
|
||||
type: deploydb.models.promotion.ManualLDAPPromotionImpl
|
||||
description: Manual LDAP Promotion Smoke Test
|
||||
attributes:
|
||||
allowedGroup : "fooGroup"
|
||||
|
@ -55,7 +55,7 @@ attributes:
|
|||
promotionRegistry.put(promotion.ident, promotion)
|
||||
|
||||
expect:
|
||||
promotion.type == 'deploydb.models.Promotion.ManualLDAPPromotionImpl'
|
||||
promotion.type == 'deploydb.models.promotion.ManualLDAPPromotionImpl'
|
||||
promotion.description == "Manual LDAP Promotion Smoke Test"
|
||||
promotion.attributes.size() == 1
|
||||
promotion.attributes["allowedGroup"] == "fooGroup"
|
||||
|
@ -69,13 +69,13 @@ attributes:
|
|||
def "When allowedGroup is NOT part of User authorized groups, then validation fails"() {
|
||||
given:
|
||||
Promotion promotion = promotionLoader.loadFromString("""
|
||||
type: deploydb.models.Promotion.ManualLDAPPromotionImpl
|
||||
type: deploydb.models.promotion.ManualLDAPPromotionImpl
|
||||
description: Manual LDAP Promotion Smoke Test
|
||||
attributes:
|
||||
allowedGroup : "fooGroup"
|
||||
""")
|
||||
expect:
|
||||
promotion.type == 'deploydb.models.Promotion.ManualLDAPPromotionImpl'
|
||||
promotion.type == 'deploydb.models.promotion.ManualLDAPPromotionImpl'
|
||||
promotion.attributes.size() == 1
|
||||
promotion.attributes["allowedGroup"] == "fooGroup"
|
||||
User user = new User("foo", [ "barGroup" ] as Set)
|
||||
|
@ -86,11 +86,11 @@ attributes:
|
|||
def "When no allowedGroup is configured, then validation fails"() {
|
||||
given:
|
||||
Promotion promotion = promotionLoader.loadFromString("""
|
||||
type: deploydb.models.Promotion.ManualLDAPPromotionImpl
|
||||
type: deploydb.models.promotion.ManualLDAPPromotionImpl
|
||||
description: Manual LDAP Promotion Smoke Test
|
||||
""")
|
||||
expect:
|
||||
promotion.type == 'deploydb.models.Promotion.ManualLDAPPromotionImpl'
|
||||
promotion.type == 'deploydb.models.promotion.ManualLDAPPromotionImpl'
|
||||
promotion.attributes == null
|
||||
User user = new User("foo", [ "fooGroup" ] as Set)
|
||||
promotion.validate(user) == false
|
||||
|
@ -100,14 +100,14 @@ description: Manual LDAP Promotion Smoke Test
|
|||
def "If multiple allowedGroup(s) are configured, last entry superscedes and validation fails"() {
|
||||
given:
|
||||
Promotion promotion = promotionLoader.loadFromString("""
|
||||
type: deploydb.models.Promotion.ManualLDAPPromotionImpl
|
||||
type: deploydb.models.promotion.ManualLDAPPromotionImpl
|
||||
description: Manual LDAP Promotion Smoke Test
|
||||
attributes:
|
||||
allowedGroup : "fooGroup"
|
||||
allowedGroup : "barGroup"
|
||||
""")
|
||||
expect:
|
||||
promotion.type == 'deploydb.models.Promotion.ManualLDAPPromotionImpl'
|
||||
promotion.type == 'deploydb.models.promotion.ManualLDAPPromotionImpl'
|
||||
promotion.attributes.size() == 1
|
||||
promotion.attributes["allowedGroup"] == "barGroup"
|
||||
User user = new User("foo", [ "fooGroup" ] as Set)
|
||||
|
@ -118,13 +118,13 @@ attributes:
|
|||
def "The allowedGroup is configured, but authentication is not, hence validate fails"() {
|
||||
given:
|
||||
Promotion promotion = promotionLoader.loadFromString("""
|
||||
type: deploydb.models.Promotion.ManualLDAPPromotionImpl
|
||||
type: deploydb.models.promotion.ManualLDAPPromotionImpl
|
||||
description: Manual LDAP Promotion Smoke Test
|
||||
attributes:
|
||||
allowedGroup : "fooGroup"
|
||||
""")
|
||||
expect:
|
||||
promotion.type == 'deploydb.models.Promotion.ManualLDAPPromotionImpl'
|
||||
promotion.type == 'deploydb.models.promotion.ManualLDAPPromotionImpl'
|
||||
promotion.attributes.size() == 1
|
||||
promotion.attributes["allowedGroup"] == "fooGroup"
|
||||
User user = null
|
||||
|
@ -135,11 +135,11 @@ attributes:
|
|||
def "Neither allowedGroup, nor authentication is configured, hence validate fails"() {
|
||||
given:
|
||||
Promotion promotion = promotionLoader.loadFromString("""
|
||||
type: deploydb.models.Promotion.ManualLDAPPromotionImpl
|
||||
type: deploydb.models.promotion.ManualLDAPPromotionImpl
|
||||
description: Manual LDAP Promotion Smoke Test
|
||||
""")
|
||||
expect:
|
||||
promotion.type == 'deploydb.models.Promotion.ManualLDAPPromotionImpl'
|
||||
promotion.type == 'deploydb.models.promotion.ManualLDAPPromotionImpl'
|
||||
promotion.attributes == null
|
||||
User user = null
|
||||
promotion.validate(user) == false
|
||||
|
@ -161,14 +161,23 @@ description: Manual LDAP Promotion Smoke Test
|
|||
thrown(ConfigurationParsingException)
|
||||
}
|
||||
|
||||
def "Loading a empty model promotion config succeeds"(){
|
||||
given:
|
||||
def "Loading a empty model promotion config throws validation exception"(){
|
||||
when:
|
||||
Promotion promotion = promotionLoader.loadFromString("type:\n"+
|
||||
"description:\n")
|
||||
|
||||
expect:
|
||||
promotion.type == ""
|
||||
promotion.description == ""
|
||||
then:
|
||||
thrown(ConfigurationValidationException)
|
||||
}
|
||||
|
||||
def "Loading a promotion config with invalid type throws a validation exception"() {
|
||||
when:
|
||||
Promotion promotion = promotionLoader.loadFromString("""
|
||||
type: deploydb.invalid.promotion.classname.BasicPromotionImpl
|
||||
description: Basic Promotion Smoke Test
|
||||
""")
|
||||
then:
|
||||
thrown(ConfigurationValidationException)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue