Console integration. UAT needs only service discovery for deploydb.

- Add only health service consul api
  - Fixes #163
This commit is contained in:
Giri Dandu 2015-05-03 17:33:25 -04:00
parent f4f614d8a5
commit 0168dbedab
13 changed files with 215 additions and 13 deletions

View File

@ -18,8 +18,17 @@ class IntegrationModelHelper {
"sourceUrl" : "http://example.com/cucumber.jar"
}
"""
return (integrationRestApiClient.postJsonToPath(path, messageBody, false)).status == 201
Response response = integrationRestApiClient.postJsonToPath(path, messageBody, false)
response.close()
return response.status == 201
}
boolean sendGetApi(String path) {
Response response = integrationRestApiClient.getFromPath(path, false)
response.close()
return response.status == 200
}
boolean sendDeploymentStartedTrigger() {

View File

@ -1,5 +1,6 @@
package dropwizardintegtest
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider
import com.github.mustachejava.DefaultMustacheFactory
import com.github.mustachejava.Mustache
@ -30,6 +31,7 @@ class IntegrationRestApiClient {
if (this.jerseyClient == null) {
ClientConfig clientConfig = new ClientConfig()
clientConfig.connectorProvider(new ApacheConnectorProvider())
clientConfig.register(JacksonJsonProvider.class);
this.jerseyClient = ClientBuilder.newClient(clientConfig)
}
return this.jerseyClient

View File

@ -29,14 +29,15 @@ dependencies {
* allow us to make PATCH requests
*/
compile ('org.glassfish.jersey.connectors:jersey-apache-connector:2.+')
compile('com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.4.1')
compile ('org.spockframework:spock-core:0.7-groovy-2.0')
compile project(':dropwizard-integtest')
}
repositories {
jcenter()
mavenCentral()
mavenCentral()
maven { url 'http://dl.bintray.com/lookout/systems' }
}

1
uat/config.groovy Normal file
View File

@ -0,0 +1 @@
customTestReportDir="./build"

View File

@ -1,20 +1,33 @@
package uat
import spock.lang.*
import dropwizardintegtest.IntegrationModelHelper
import dropwizardintegtest.IntegrationRestApiClient
class ArtifactTriggerSpec {
class ArtifactTriggerSpec extends Specification {
IntegrationRestApiClient integrationRestApiClient = new IntegrationRestApiClient()
IntegrationModelHelper integModelHelper = new IntegrationModelHelper(integrationRestApiClient)
void setup() {
integrationRestApiClient.host = "http://10.32.10.63"
def setup() {
//integrationRestApiClient.host = "http://10.32.10.63"
integrationRestApiClient.host = "http://localhost"
}
void createArtifactShouldReturnSuccess() {
setup()
def "create artifact should return success"() {
when:
boolean success = integModelHelper.sendCreateArtifact()
println("success: ${success}")
then:
success == true
}
def "read artifact should return success"() {
when:
boolean success = integModelHelper.sendGetApi("/api/artifacts/1")
then:
success == true
}
}

View File

@ -0,0 +1,26 @@
package uat
import dropwizardintegtest.IntegrationRestApiClient
import javax.ws.rs.core.Response
import javax.ws.rs.core.GenericType
class ConsulClient {
IntegrationRestApiClient restApiClient = new IntegrationRestApiClient()
List<String> getDeploydbHosts() {
restApiClient.port = 8500
String path = "/v1/health/service/deploydb?passing"
Response response = restApiClient.getFromPath(path, false)
List<String> hosts = new ArrayList()
List<ServiceHealth> serviceHealthList = response.readEntity(new GenericType<List<ServiceHealth>>(){})
serviceHealthList.each {
hosts << it.node.address + ":" + it.service.port
}
return hosts
}
}

View File

@ -0,0 +1,24 @@
package uat
import spock.lang.*
import dropwizardintegtest.IntegrationModelHelper
import dropwizardintegtest.IntegrationRestApiClient
class DeploymentTriggerSpec extends Specification {
IntegrationRestApiClient integrationRestApiClient = new IntegrationRestApiClient()
IntegrationModelHelper integModelHelper = new IntegrationModelHelper(integrationRestApiClient)
def setup() {
//integrationRestApiClient.host = "http://10.32.10.63"
integrationRestApiClient.host = "http://localhost"
}
def "read artifact should return success"() {
when:
boolean success = integModelHelper.sendGetApi("/api/deployments/1")
then:
success == true
}
}

View File

@ -0,0 +1,34 @@
package uat
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
@JsonIgnoreProperties(ignoreUnknown = true)
public class HealthCheck {
@JsonProperty("Node")
private String node
@JsonProperty("CheckID")
private String checkId
@JsonProperty("Name")
private String name
@JsonProperty("Status")
private String status
@JsonProperty("Notes")
private String notes
@JsonProperty("Output")
private String output
@JsonProperty("ServiceID")
private String serviceId
@JsonProperty("ServiceName")
private String serviceName
HealthCheck() { }
}

View File

@ -0,0 +1,16 @@
package uat
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
@JsonIgnoreProperties(ignoreUnknown = true)
public class Node {
@JsonProperty("Node")
private String node
@JsonProperty("Address")
private String address
Node() { }
}

View File

@ -0,0 +1,22 @@
package uat
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
@JsonIgnoreProperties(ignoreUnknown = true)
public class Service {
@JsonProperty("ID")
private String id
@JsonProperty("Service")
private String service
@JsonProperty("Tags")
private String[] tags
@JsonProperty("Port")
private int port
Service() { }
}

View File

@ -0,0 +1,24 @@
package uat
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import java.util.ArrayList
import java.util.List
@JsonIgnoreProperties(ignoreUnknown = true)
public class ServiceHealth {
@JsonProperty("Node")
private Node node
@JsonProperty("Service")
private Service service
@JsonProperty("Checks")
@JsonDeserialize(as = ArrayList.class, contentAs = HealthCheck.class)
private List<HealthCheck> checks
ServiceHealth() { }
}

View File

@ -0,0 +1,23 @@
package uat
import spock.util.EmbeddedSpecRunner
class TestRunner {
private EmbeddedSpecRunner embeddedSpecRunner = new EmbeddedSpecRunner()
private List listOfClasses = new ArrayList()
TestRunner() {
/**
* list of specs to run the tests. I wish there is a better way to
* add classes to run the tests using class loader but given this
* is running in stand alone jar, its not possible
*/
listOfClasses = [ArtifactTriggerSpec, DeploymentTriggerSpec]
}
boolean runTests() {
listOfClasses.each {
embeddedSpecRunner.runClass(it)
}
}
}

View File

@ -1,10 +1,17 @@
package uat
class UatMainApp {
static void main(String[] args) {
import org.codehaus.groovy.testng.TestNgRunner
// run all the tests
ArtifactTriggerSpec artifactTriggerSpec = new ArtifactTriggerSpec()
artifactTriggerSpec.createArtifactShouldReturnSuccess()
class UatMainApp {
static void main(String[] args) {
uat.TestRunner testRunner = new uat.TestRunner()
ConsulClient consulClient = new ConsulClient()
consulClient.getDeploydbHosts()
boolean success = testRunner.runTests()
success ? System.exit(0):System.exit(1)
}
}