Enabled tests for REST API to get Deployments for environment ident
References #169
This commit is contained in:
parent
87791a38e3
commit
3954d8c1b9
|
@ -74,7 +74,7 @@ Feature: Environment READ APIs
|
|||
Then the response should be 404
|
||||
|
||||
|
||||
@freezetime @wip
|
||||
@freezetime
|
||||
Scenario: Fetching all deployments in the environment
|
||||
|
||||
Given there is a deployment
|
||||
|
@ -107,11 +107,11 @@ Feature: Environment READ APIs
|
|||
"""
|
||||
|
||||
|
||||
@freezetime @wip
|
||||
@freezetime
|
||||
Scenario: Fetching all deployments in the environment by the pageNumber and perPageSize
|
||||
|
||||
Given there are deployments
|
||||
When I GET "/api/environments/pre-prod/deployments?pageNumber=0&perPageSize=5""
|
||||
When I GET "/api/environments/pre-prod/deployments?pageNumber=0&perPageSize=5"
|
||||
Then the response should be 200
|
||||
And the body should be JSON:
|
||||
"""
|
||||
|
@ -161,7 +161,7 @@ Feature: Environment READ APIs
|
|||
}]
|
||||
"""
|
||||
|
||||
@wip
|
||||
|
||||
Scenario: Fetching deployments for an environment that doesn't exist
|
||||
|
||||
When I GET "/api/environments/pre-prod/deployments"
|
||||
|
|
|
@ -3,11 +3,9 @@ package deploydb.resources
|
|||
import com.codahale.metrics.annotation.Timed
|
||||
import deploydb.WorkFlow
|
||||
import deploydb.models.Deployment
|
||||
import deploydb.models.Environment
|
||||
import io.dropwizard.hibernate.UnitOfWork
|
||||
import io.dropwizard.jersey.params.IntParam
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
import javax.ws.rs.Consumes
|
||||
import javax.ws.rs.DefaultValue
|
||||
import javax.ws.rs.GET
|
||||
|
@ -18,9 +16,9 @@ import javax.ws.rs.QueryParam
|
|||
import javax.ws.rs.WebApplicationException
|
||||
import javax.ws.rs.core.MediaType
|
||||
import javax.ws.rs.core.Response
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
import deploydb.registry.ModelRegistry
|
||||
import deploydb.models.Environment
|
||||
|
||||
/**
|
||||
* EnvironmentResource class registered with JettyClient for servicing REST request
|
||||
|
|
|
@ -3,13 +3,12 @@ package deploydb.dao
|
|||
import deploydb.IntegrationModelHelper
|
||||
import deploydb.IntegrationTestAppHelper
|
||||
import deploydb.WebhooksModelConfigHelper
|
||||
import deploydb.models.Deployment
|
||||
import org.hibernate.Criteria
|
||||
import org.hibernate.SessionFactory
|
||||
import spock.lang.*
|
||||
|
||||
class DeploymentDAOSpec extends Specification {
|
||||
private DeploymentDAO dao
|
||||
private SessionFactory sessionFactory = Mock(SessionFactory)
|
||||
IntegrationTestAppHelper integAppHelper = new IntegrationTestAppHelper()
|
||||
IntegrationModelHelper integModelHelper = new IntegrationModelHelper(integAppHelper)
|
||||
private WebhooksModelConfigHelper mcfgHelper = new WebhooksModelConfigHelper()
|
||||
|
@ -26,11 +25,8 @@ class DeploymentDAOSpec extends Specification {
|
|||
}
|
||||
|
||||
def "ensure the constructor works"() {
|
||||
given:
|
||||
DeploymentDAO dao
|
||||
|
||||
when:
|
||||
dao = new DeploymentDAO(sessionFactory)
|
||||
DeploymentDAO dao = new DeploymentDAO(integAppHelper.sessionFactory)
|
||||
|
||||
then:
|
||||
dao instanceof DeploymentDAO
|
||||
|
@ -38,6 +34,7 @@ class DeploymentDAOSpec extends Specification {
|
|||
|
||||
def "getByArtifactId() should return null if there are no deployments"() {
|
||||
given:
|
||||
SessionFactory sessionFactory = Mock(SessionFactory)
|
||||
DeploymentDAO dao = Spy(DeploymentDAO, constructorArgs: [sessionFactory])
|
||||
def criteria = Mock(Criteria)
|
||||
criteria./add|set|addOrder|setMaxResults|setFirstResult/(_) >> criteria
|
||||
|
@ -48,24 +45,22 @@ class DeploymentDAOSpec extends Specification {
|
|||
dao.getByArtifactId(1).isEmpty()
|
||||
}
|
||||
|
||||
@Ignore
|
||||
def "getByEnvironmentIdent() should return null if there are no deployments"() {
|
||||
given:
|
||||
DeploymentDAO dao = new DeploymentDAO(integAppHelper.runner.getApplication().sessionFactory)
|
||||
when:
|
||||
List<Deployment> deploymentsByEnv
|
||||
integAppHelper.withSession {
|
||||
deploymentsByEnv = integAppHelper.runner.getApplication().workFlow.deploymentDAO
|
||||
.getByEnvironmentIdent("basicEnv", 0, 20)
|
||||
}
|
||||
|
||||
expect:
|
||||
integAppHelper.runner.getApplication().workflow.deploymentDAO
|
||||
.getByEnvironmentIdent("basicEnv", 1, 20).isEmpty()
|
||||
then:
|
||||
deploymentsByEnv.isEmpty() == true
|
||||
}
|
||||
|
||||
@Ignore
|
||||
def "getByEnvironmentIdent() should returns deployments for the environment ident"() {
|
||||
given:
|
||||
DeploymentDAO dao = new DeploymentDAO(integAppHelper.runner.getApplication().sessionFactory)
|
||||
|
||||
// Create the required config
|
||||
mcfgHelper.createServicePromoitionPipelineModelsConfigFiles()
|
||||
mcfgHelper.createDeploymentCompletedWebhookConfigFile()
|
||||
mcfgHelper.createEnvironmentNoWebhooksConfigFile()
|
||||
|
||||
// load up the configuration
|
||||
|
@ -74,14 +69,22 @@ class DeploymentDAOSpec extends Specification {
|
|||
// setup the deployment for completed trigger
|
||||
integModelHelper.sendCreateArtifact()
|
||||
|
||||
expect:
|
||||
integAppHelper.runner.getApplication().workflow.deploymentDAO
|
||||
.getByEnvironmentIdent("basicEnv", 1, 20).size() == 1
|
||||
integAppHelper.runner.getApplication().workflow.deploymentDAO
|
||||
.getByPage(1, 20) ==
|
||||
integAppHelper.runner.getApplication().workflow.deploymentDAO
|
||||
.getByEnvironmentIdent("basicEnv", 1, 20).size() == 1
|
||||
integAppHelper.runner.getApplication().workflow.deploymentDAO
|
||||
.getByEnvironmentIdent("integ", 1, 20).isEmpty()
|
||||
when:
|
||||
List<Deployment> deploymentsByEnv
|
||||
List<Deployment> allDeployments
|
||||
List<Deployment> deploymentsByUnknownEnv
|
||||
integAppHelper.withSession {
|
||||
deploymentsByEnv = integAppHelper.runner.getApplication().workFlow.deploymentDAO
|
||||
.getByEnvironmentIdent("basicEnv", 0, 20)
|
||||
allDeployments = integAppHelper.runner.getApplication().workFlow.deploymentDAO
|
||||
.getByPage(0, 20)
|
||||
deploymentsByUnknownEnv = integAppHelper.runner.getApplication().workFlow.deploymentDAO
|
||||
.getByEnvironmentIdent("integ", 0, 20)
|
||||
}
|
||||
|
||||
then:
|
||||
deploymentsByEnv.size() == 1
|
||||
deploymentsByEnv == allDeployments
|
||||
deploymentsByUnknownEnv.isEmpty()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,22 @@
|
|||
package deploydb.resources
|
||||
|
||||
import io.dropwizard.testing.junit.ResourceTestRule
|
||||
import javax.ws.rs.client.Client
|
||||
import org.junit.Rule
|
||||
import spock.lang.*
|
||||
|
||||
import deploydb.DeployDBApp
|
||||
import deploydb.WorkFlow
|
||||
import deploydb.models.Environment
|
||||
import deploydb.registry.ModelRegistry
|
||||
import io.dropwizard.testing.junit.ResourceTestRule
|
||||
import javax.ws.rs.client.Client
|
||||
import spock.lang.*
|
||||
import org.junit.Rule
|
||||
|
||||
|
||||
class EnvironmentResourceSpec extends Specification {
|
||||
private ModelRegistry<Environment> environmentRegistry = Mock(ModelRegistry)
|
||||
private DeployDBApp app = new DeployDBApp()
|
||||
private WorkFlow workFlow = new WorkFlow(app)
|
||||
|
||||
@Rule
|
||||
ResourceTestRule dropwizard = ResourceTestRule.builder()
|
||||
.addResource(new EnvironmentResource(environmentRegistry)).build();
|
||||
.addResource(new EnvironmentResource(workFlow)).build();
|
||||
|
||||
def "EnvironmentResource byName returns valid item when exists"() {
|
||||
given:
|
||||
|
@ -21,14 +24,14 @@ class EnvironmentResourceSpec extends Specification {
|
|||
String environmentIdent = 'integ'
|
||||
Environment environment = new Environment()
|
||||
environment.ident = environmentIdent
|
||||
Environment fetched = null
|
||||
1 * environmentRegistry.get(environmentIdent) >> environment
|
||||
workFlow.environmentRegistry = new ModelRegistry<Environment>()
|
||||
workFlow.environmentRegistry.put(environmentIdent, environment)
|
||||
|
||||
when:
|
||||
fetched = client.target(dropwizard.jerseyTest.baseUri)
|
||||
.path("/api/environments/${environmentIdent}")
|
||||
.request()
|
||||
.get(Environment.class)
|
||||
Environment fetched = client.target(dropwizard.jerseyTest.baseUri)
|
||||
.path("/api/environments/${environmentIdent}")
|
||||
.request()
|
||||
.get(Environment.class)
|
||||
|
||||
then:
|
||||
fetched == environment
|
||||
|
|
Loading…
Reference in New Issue