Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Use basePath rather than inventoryEndpoint as a name for
Browse files Browse the repository at this point in the history
"/hawkular/inventory" constant
  • Loading branch information
ppalaga committed Jul 14, 2015
1 parent 640b86a commit b02bcd6
Showing 1 changed file with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import static org.junit.Assert.assertEquals
* @author jkremser
*/
class InventoryITest extends AbstractTestBase {
private static final String inventoryEndpoint = "/hawkular/inventory"
private static final String basePath = "/hawkular/inventory"

private static final String urlTypeId = "URL"
private static final String testEnvId = "test"
Expand Down Expand Up @@ -91,7 +91,7 @@ class InventoryITest extends AbstractTestBase {
* who may have triggered the same initial tasks in Inventory.
* A successfull GET to /hawkular/inventory/environments/test
* should mean that all initial tasks are over */
path = "$inventoryEndpoint/environments/$testEnvId"
path = "$basePath/environments/$testEnvId"
for (int i = 0; i < attemptCount; i++) {
try {
response = client.get(path: path)
Expand All @@ -111,35 +111,35 @@ class InventoryITest extends AbstractTestBase {
/* Create an environment that will be used exclusively by this test */
response = postDeletable(path: "environments", body: [id : environmentId])
assertEquals(201, response.status)
assertEquals(baseURI + "$inventoryEndpoint/environments/$environmentId", response.headers.Location)
assertEquals(baseURI + "$basePath/environments/$environmentId", response.headers.Location)

/* URL resource type should have been autocreated */
response = client.get(path: "$inventoryEndpoint/resourceTypes/$urlTypeId")
response = client.get(path: "$basePath/resourceTypes/$urlTypeId")
assertEquals(200, response.status)
assertEquals(urlTypeId, response.data.id)

/* Create a custom resource type */
response = postDeletable(path: "resourceTypes", body: [id : pingableHostRTypeId, version : typeVersion])
assertEquals(201, response.status)
assertEquals(baseURI + "$inventoryEndpoint/resourceTypes/$pingableHostRTypeId", response.headers.Location)
assertEquals(baseURI + "$basePath/resourceTypes/$pingableHostRTypeId", response.headers.Location)

/* Create another resource type */
response = postDeletable(path: "resourceTypes", body: [id : roomRTypeId, version : typeVersion])
assertEquals(201, response.status)
assertEquals(baseURI + "$inventoryEndpoint/resourceTypes/$roomRTypeId", response.headers.Location)
assertEquals(baseURI + "$basePath/resourceTypes/$roomRTypeId", response.headers.Location)

/* Create a metric type */
response = postDeletable(path: "metricTypes", body: [id : responseTimeMTypeId, unit : "MILLI_SECOND"])
assertEquals(201, response.status)
assertEquals(baseURI + "$inventoryEndpoint/metricTypes/$responseTimeMTypeId", response.headers.Location)
assertEquals(baseURI + "$basePath/metricTypes/$responseTimeMTypeId", response.headers.Location)

/* Create another metric type */
response = postDeletable(path: "metricTypes", body: [id : responseStatusCodeMTypeId, unit : "NONE"])
assertEquals(201, response.status)
assertEquals(baseURI + "$inventoryEndpoint/metricTypes/$responseStatusCodeMTypeId", response.headers.Location)
assertEquals(baseURI + "$basePath/metricTypes/$responseStatusCodeMTypeId", response.headers.Location)

/* link pingableHostRTypeId with responseTimeMTypeId and responseStatusCodeMTypeId */
path = "$inventoryEndpoint/resourceTypes/$pingableHostRTypeId/metricTypes"
path = "$basePath/resourceTypes/$pingableHostRTypeId/metricTypes"
response = client.post(path: path,
body : [responseTimeMTypeId, responseStatusCodeMTypeId])
assertEquals(204, response.status)
Expand All @@ -150,34 +150,34 @@ class InventoryITest extends AbstractTestBase {
response = postDeletable(path: "$environmentId/metrics",
body: [ id : responseTimeMetricId, metricTypeId : responseTimeMTypeId ]);
assertEquals(201, response.status)
assertEquals(baseURI + "$inventoryEndpoint/$environmentId/metrics/$responseTimeMetricId", response.headers.Location)
assertEquals(baseURI + "$basePath/$environmentId/metrics/$responseTimeMetricId", response.headers.Location)

/* add another metric */
response = postDeletable(path: "$environmentId/metrics",
body: [ id : responseStatusCodeMetricId, metricTypeId : responseStatusCodeMTypeId ]);
assertEquals(201, response.status)
assertEquals(baseURI + "$inventoryEndpoint/$environmentId/metrics/$responseStatusCodeMetricId", response.headers.Location)
assertEquals(baseURI + "$basePath/$environmentId/metrics/$responseStatusCodeMetricId", response.headers.Location)

/* add a resource */
response = postDeletable(path: "$environmentId/resources",
body: [ id : host1ResourceId, resourceTypeId: pingableHostRTypeId ])
assertEquals(201, response.status)
assertEquals(baseURI + "$inventoryEndpoint/$environmentId/resources/$host1ResourceId", response.headers.Location)
assertEquals(baseURI + "$basePath/$environmentId/resources/$host1ResourceId", response.headers.Location)

/* add another resource */
response = postDeletable(path: "$environmentId/resources",
body: [ id : host2ResourceId, resourceTypeId: pingableHostRTypeId ])
assertEquals(201, response.status)
assertEquals(baseURI + "$inventoryEndpoint/$environmentId/resources/$host2ResourceId", response.headers.Location)
assertEquals(baseURI + "$basePath/$environmentId/resources/$host2ResourceId", response.headers.Location)

/* add a room resource */
response = postDeletable(path: "$environmentId/resources",
body: [ id : room1ResourceId, resourceTypeId: roomRTypeId ])
assertEquals(201, response.status)
assertEquals(baseURI + "$inventoryEndpoint/$environmentId/resources/$room1ResourceId", response.headers.Location)
assertEquals(baseURI + "$basePath/$environmentId/resources/$room1ResourceId", response.headers.Location)

/* link the metric to resource */
path = "$inventoryEndpoint/$environmentId/resources/$host1ResourceId/metrics"
path = "$basePath/$environmentId/resources/$host1ResourceId/metrics"
response = client.post(path: path,
body: [responseTimeMetricId, responseStatusCodeMetricId]);
assertEquals(204, response.status)
Expand All @@ -187,7 +187,7 @@ class InventoryITest extends AbstractTestBase {
/* add a feed */
response = postDeletable(path: "$environmentId/feeds", body: [id: feedId])
assertEquals(201, response.status)
assertEquals(baseURI + "$inventoryEndpoint/$environmentId/feeds/$feedId", response.headers.Location)
assertEquals(baseURI + "$basePath/$environmentId/feeds/$feedId", response.headers.Location)

/* add a custom relationship, no need to clean up, it'll be deleted together with the resources */
def relation = [id : 42, // it's ignored anyway
Expand All @@ -198,7 +198,7 @@ class InventoryITest extends AbstractTestBase {
from : "2000-01-01",
confidence: "90%"
]]
response = client.post(path: "$inventoryEndpoint/$environmentId/resources/$host2ResourceId/relationships",
response = client.post(path: "$basePath/$environmentId/resources/$host2ResourceId/relationships",
body: relation)
assertEquals(201, response.status)

Expand All @@ -208,7 +208,7 @@ class InventoryITest extends AbstractTestBase {
static void deleteEverything() {
/* the following would delete all data of the present user. We cannot do that as long as we do not have
* a dedicated user for running this very single test class. */
// def response = client.delete(path : "$inventoryEndpoint/tenant")
// def response = client.delete(path : "$basePath/tenant")
// assertEquals(204, response.status)

/* Let's delete the entities one after another in the reverse order as we created them */
Expand Down Expand Up @@ -281,11 +281,11 @@ class InventoryITest extends AbstractTestBase {

@Test
void testResourcesFilters() {
def response = client.get(path: "$inventoryEndpoint/$environmentId/resources",
def response = client.get(path: "$basePath/$environmentId/resources",
query: [type: pingableHostRTypeId, typeVersion: typeVersion])
assertEquals(2, response.data.size())

response = client.get(path: "$inventoryEndpoint/$environmentId/resources",
response = client.get(path: "$basePath/$environmentId/resources",
query: [type: roomRTypeId, typeVersion: typeVersion])
assertEquals(1, response.data.size())

Expand All @@ -306,7 +306,7 @@ class InventoryITest extends AbstractTestBase {

@Test
void testPaging() {
String path = "$inventoryEndpoint/$environmentId/resources"
String path = "$basePath/$environmentId/resources"
def response = client.get(path: path, query: [type: pingableHostRTypeId, typeVersion: typeVersion, page: 0, per_page: 2, sort: "id"])
assertEquals(2, response.data.size())

Expand Down Expand Up @@ -515,13 +515,13 @@ class InventoryITest extends AbstractTestBase {
}

private static void assertEntityExists(path, id) {
def response = client.get(path: "$inventoryEndpoint/$path")
def response = client.get(path: "$basePath/$path")
assertEquals(200, response.status)
assertEquals(id, response.data.id)
}

private static void assertEntitiesExist(path, ids) {
def response = client.get(path: "$inventoryEndpoint/$path")
def response = client.get(path: "$basePath/$path")

//noinspection GroovyAssignabilityCheck
def expectedIds = new ArrayList<>(ids)
Expand All @@ -533,7 +533,7 @@ class InventoryITest extends AbstractTestBase {
}

private static void assertRelationshipJsonldExists(path, source, label, target) {
def response = client.get(path: "$inventoryEndpoint/$path", query: [jsonld: true])
def response = client.get(path: "$basePath/$path", query: [jsonld: true])
def needle = new Tuple(source, label, target);
def haystack = response.data.collect{ new Tuple(it["source"]["shortId"], it["name"],
it["target"]["shortId"]) }
Expand All @@ -542,7 +542,7 @@ class InventoryITest extends AbstractTestBase {
}

private static void assertRelationshipExists(path, source, label, target, query = [:]) {
def response = client.get(path: "$inventoryEndpoint/$path", query: query)
def response = client.get(path: "$basePath/$path", query: query)
def needle = new Tuple(source, label, target);
def haystack = response.data.collect{ new Tuple(it["source"], it["name"],
it["target"]) }
Expand All @@ -557,9 +557,9 @@ class InventoryITest extends AbstractTestBase {
postDeletable(args, getVerificationPath)
}
private static Object postDeletable(Map args, String getVerificationPath) {
args.path = inventoryEndpoint + "/" + args.path
args.path = basePath + "/" + args.path
String path = args.path + "/" + args.body.id
pathsToDelete.put(path, inventoryEndpoint + "/" + getVerificationPath)
pathsToDelete.put(path, basePath + "/" + getVerificationPath)
return client.post(args)
}
}

0 comments on commit b02bcd6

Please sign in to comment.