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

Commit

Permalink
Adding the test for escaped chars in the URL/JSON when querying the i…
Browse files Browse the repository at this point in the history
…nventory REST api. note: the dependency on the snapshot version is temporal
  • Loading branch information
jkremser committed Jul 27, 2015
1 parent 9e46402 commit 8162320
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import org.hawkular.integration.test.AbstractTestBase
import org.junit.AfterClass
import org.junit.Assert
import org.junit.BeforeClass
import org.junit.Ignore
import org.junit.Test

import static java.net.URLEncoder.encode
import static org.hawkular.inventory.api.Relationships.WellKnown.*
import static org.junit.Assert.assertEquals

Expand Down Expand Up @@ -226,11 +228,12 @@ class InventoryITest extends AbstractTestBase {
assertEquals(baseURI + "$basePath/$environmentId/resources/$copyMachine2ResourceId", response.headers.Location)

/* add a child resource */
response = postDeletable(path: "$environmentId/resources/$room1ResourceId",
body: [id: "table", resourceTypePath: "/" + roomRTypeId])
assertEquals(201, response.status)
assertEquals(baseURI + "$basePath/$environmentId/resources/$room1ResourceId/table",
response.headers.Location)
// todo: uncomment this once the inventory backend is ready for escaped ids and resource hierarchies
// response = postDeletable(path: "$environmentId/resources/$room1ResourceId",
// body: [id: "table", resourceTypePath: "/" + roomRTypeId])
// assertEquals(201, response.status)
// assertEquals(baseURI + "$basePath/$environmentId/resources/$room1ResourceId/table",
// response.headers.Location)

/* link the metric to resource */
path = "$basePath/$environmentId/resources/$host1ResourceId/metrics"
Expand Down Expand Up @@ -427,6 +430,58 @@ class InventoryITest extends AbstractTestBase {
assertEquals(first, response.data.get(0))
}

@Test
@Ignore("This currently fails the REST api has problem with escaped chars.")
// todo: Don't forget to uncomment lines 230-235 once this is passing
void testEntitiesWithEscapedCharacters() {
String escResourceType = "WildFly\\/Ser\\;ver"
String escResourceTypeUrl = encode(escResourceType)
String escMetricType = "WildFly\\/Memory Metrics\\;Heap Committed"
String escMetricTypeUrl = encode(escMetricType)
String escResource = "[localhost\\;Local~\\/"
String escResourceUrl = encode(escResource)
String escMetric = "MI~R~[localhost~Local~\\/]~MT~WildFly Memory Metrics\\;Heap Committed"
String escMetricUrl = encode(escMetric)

// 1. create resource type
simplePost(path: "resourceTypes", body: [id : escResourceType])

// 2. create metric type
simplePost(path: "metricTypes", body: [id : escMetricType, unit: "NONE", type: "GAUGE"])

// 3. associate (1.) and (2.)
// note: it fails here (the resource-metric association will be failing too):
// posting [path:/hawkular/inventory/resourceTypes, body:[id:WildFly\/Ser\;ver]]
// posting [path:/hawkular/inventory/metricTypes, body:[id:WildFly\/Memory Metrics\;Heap Committed,
// unit:NONE, type:GAUGE]]
// >here< posting [path:/hawkular/inventory/resourceTypes/WildFly%5C%2FSer%5C%3Bver/metricTypes,
// body:[../WildFly\/Memory Metrics\;Heap Committed]]
simplePost(path: "resourceTypes/$escResourceTypeUrl/metricTypes", body: ["../$escMetricType".toString()])

// 4. create resource
simplePost(path: "$environmentId/resources",
body: [id: escResource, resourceTypePath: "../$escResourceType".toString()])

// 5. create metric
simplePost(path: "$environmentId/metrics",
body: [id: escMetric, metricTypePath: "../$escMetricType".toString()])

// 6. associate (4.) and (5.)
simplePost(path: "$environmentId/resources/$escResourceUrl/metrics",
body: ["../$escMetric".toString()])

// 7. create child-resource
simplePost(path: "$environmentId/resources/$escResource",
body: [id: "sub-" + escResource, resourceTypePath: "/$escResourceType".toString()])

// 8. delete everything
simpleDelete("metricTypes/$escMetricTypeUrl")
simpleDelete("resourceTypes/$escResourceTypeUrl")
simpleDelete("$environmentId/resources/$escResourceUrl/sub-$escResourceUrl")
simpleDelete("$environmentId/resources/$escResourceUrl")
simpleDelete("$environmentId/metrics/$escMetricUrl")
}

@Test
void testTenantsContainEnvironments() {
assertRelationshipExists("tenants/$tenantId/relationships",
Expand Down Expand Up @@ -658,4 +713,16 @@ class InventoryITest extends AbstractTestBase {
println "posting $args"
return client.post(args)
}
private static void simplePost(Map args) {
args.path = basePath + "/" + args.path
println "posting $args"
def response = client.post(args)
assertEquals(201, response.status)
}
private static void simpleDelete(String url) {
String path = basePath + "/" + url
println "deleting $path"
def response = client.delete([path: path])
assertEquals(204, response.status)
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<version.org.hawkular.commons>0.1.1.Final</version.org.hawkular.commons>
<version.org.hawkular.console>${project.version}</version.org.hawkular.console>
<version.org.hawkular.metrics>0.5.0.Final</version.org.hawkular.metrics>
<version.org.hawkular.inventory>0.2.0.Alpha2</version.org.hawkular.inventory>
<version.org.hawkular.inventory>0.2.0-SNAPSHOT</version.org.hawkular.inventory>
<version.org.hawkular.nest>0.3.0.Final</version.org.hawkular.nest>
<version.org.hawkular.pinger>${project.version}</version.org.hawkular.pinger>
<version.org.keycloak>1.3.1.Final</version.org.keycloak>
Expand Down

0 comments on commit 8162320

Please sign in to comment.