Skip to content

Commit

Permalink
Merge pull request #538 from michaeljs1990/add_classifier
Browse files Browse the repository at this point in the history
Add Classification to asset API
  • Loading branch information
byxorna authored May 18, 2017
2 parents 2683135 + ad0b400 commit 4691ca5
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/collins/models/asset/AllAttributes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ case class AllAttributes(
val outSeq = Seq(
"ASSET" -> asset.toJsValue,
"HARDWARE" -> lshw.toJsValue,
"CLASSIFICATION" -> Json.toJson(asset.nodeClass),
"LLDP" -> lldp.toJsValue,
"IPMI" -> Json.toJson(ipmi),
"ADDRESSES" -> Json.toJson(addresses),
Expand Down
75 changes: 75 additions & 0 deletions test/collins/controllers/AssetApiSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.specs2.mutable

import play.api.libs.json.JsString
import play.api.libs.json.Json
import play.api.mvc.AnyContentAsFormUrlEncoded
import play.api.test.FakeApplication
import play.api.test.WithApplication

Expand Down Expand Up @@ -45,6 +46,80 @@ class AssetApiSpec extends mutable.Specification with ControllerSpec with Resour
}
}

"Supports Node Classifier in API" in {
"create a configuration asset and check that an asset matches" in new WithApplication(FakeApplication(
additionalConfiguration = Map(
"solr.enabled" -> false))) with AssetApiHelper {
override val assetTag = "node_classy"
override def assetUrl = "/api/asset/%s".format(assetTag)
val req = FakeRequest("PUT", assetUrl + "?type=CONFIGURATION")
val result = Extract.from(api.createAsset(assetTag).apply(req))

result must haveStatus(201)
result must haveJsonData.which { s =>
s must /("data") */ ("ASSET") / ("TAG" -> "node_classy")
}

// make asset a nodeclass configuration
val requestBody = AnyContentAsFormUrlEncoded(Map(
"attribute" -> Seq("IS_NODECLASS;true")))
val req_att = FakeRequest("POST", assetUrl, requestBody)
val result_att = Extract.from(api.updateAsset(assetTag).apply(req_att))

result_att must haveStatus(200)
result_att must haveJsonData.which { s =>
s must /("data") */ ("SUCCESS" -> true)
}

// create asset
var node_asset_tag = "U01234"
val req_node = FakeRequest("PUT", "/api/asset/" + node_asset_tag)
val result_node = Extract.from(api.createAsset(node_asset_tag).apply(req_node))

result_node must haveStatus(201)
result_node must haveJsonData.which { s =>
s must /("data") */ ("ASSET") / ("TAG" -> node_asset_tag)
}

// get all node attributes
val req_node_att = FakeRequest("GET", "/api/asset/" + node_asset_tag)
val result_node_att = Extract.from(api.getAsset(node_asset_tag).apply(req_node_att))

result_node_att must haveStatus(200)
result_node_att must haveJsonData.which { s =>
s must /("data") */ ("CLASSIFICATION") / ("TAG" -> "node_classy")
s must /("data") */ ("CLASSIFICATION") / ("STATUS" -> "Incomplete")
s must /("data") */ ("CLASSIFICATION") / ("TYPE" -> "CONFIGURATION")
s must /("data") */ ("CLASSIFICATION") / ("DELETED" -> null)
}

}
"Make sure nil classification is returned when no configuration is defined" in new WithApplication(FakeApplication(
additionalConfiguration = Map(
"solr.enabled" -> false))) with AssetApiHelper {

override val assetTag = "U01235"
val req_node = FakeRequest("PUT", "/api/asset/" + assetTag)
val result_node = Extract.from(api.createAsset(assetTag).apply(req_node))

result_node must haveStatus(201)
result_node must haveJsonData.which { s =>
s must /("data") */ ("ASSET") / ("TAG" -> assetTag)
}

// get all node attributes
val req_node_att = FakeRequest("GET", "/api/asset/" + assetTag)
val result_node_att = Extract.from(api.getAsset(assetTag).apply(req_node_att))

result_node_att must haveStatus(200)
result_node_att must haveJsonData.which { s =>
// I can't get this to work with the normal "s must" style of testing
Json.parse(s) \ "data" \ "CLASSIFICATION" mustEqual play.api.libs.json.JsNull
}
}
}


"Support Multi-step intake" in {
"Create an asset via a PUT" in new WithApplication(FakeApplication(
additionalConfiguration = Map(
Expand Down

0 comments on commit 4691ca5

Please sign in to comment.