Skip to content

Commit

Permalink
Merge pull request #547 from michaeljs1990/dynamic_enum
Browse files Browse the repository at this point in the history
Dynamic Enum Fix
  • Loading branch information
byxorna authored Jun 8, 2017
2 parents 978bc36 + 0e56e50 commit 35dc51e
Show file tree
Hide file tree
Showing 4 changed files with 1,642 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/collins/models/AssetMeta.scala
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,9 @@ object AssetMeta extends Schema with AnormAdapter[AssetMeta] with AssetMetaKeys
def getLshwValues(): Set[AssetMeta] = {
Set(BaseDescription, BaseProduct, BaseVendor, BaseSerial, GpuProduct, GpuVendor)
}

def getLshwValues(): Set[AssetMeta] = {
Set(BaseDescription, BaseProduct, BaseVendor, BaseSerial)
}
}
}
8 changes: 4 additions & 4 deletions test/collins/controllers/AssetApiHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ trait AssetApiHelper extends ResponseMatchHelpers with JsonMatchers with Control
result
}

def updateHwInfo() = {
def updateHwInfo(lshwXml: String = "lshw-basic.xml", lldpXml: String = "lldpctl-two-nic.xml") = {
// update hw details (lshw / lldp) - cannot proceed without this
val lshwData = getResource("lshw-basic.xml")
val lldpData = getResource("lldpctl-two-nic.xml")
val lshwData = getResource(lshwXml)
val lldpData = getResource(lldpXml)
val dummy = Seq[FilePart[TemporaryFile]]()
val mdf = MultipartFormData(Map(
"lshw" -> Seq(lshwData),
Expand All @@ -73,4 +73,4 @@ trait AssetApiHelper extends ResponseMatchHelpers with JsonMatchers with Control
val request = FakeRequest("GET", assetUrl)
Extract.from(api.getAsset(assetTag).apply(request))
}
}
}
69 changes: 69 additions & 0 deletions test/collins/models/DynamicEnumSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package collins.controllers

import org.specs2.mutable

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

import collins.FakeRequest
import collins.ResourceFinder
import collins.models.Asset
import collins.models.AssetMeta
import collins.models.AssetMetaValue
import collins.models.Status

class DynamicEnumSpec extends mutable.Specification with ControllerSpec with ResourceFinder {

"Dynamic Enum Specification".title

"Should properly update asset" should {

"Has data integrity" in {
"Creating an asset" in new WithApplication(FakeApplication(
additionalConfiguration = Map(
"solr.enabled" -> false))) with AssetApiHelper {
override val assetTag = "A0001"
createAsset() must haveStatus(201)
updateHwInfo() must haveStatus(200)

val result = getAsset()
result must haveStatus(200)
result must haveJsonData.which { s =>
s must /("data") */ ("HARDWARE") */ ("BASE") / ("DESCRIPTION" -> "Rack Mount Chassis")
s must /("data") */ ("HARDWARE") */ ("BASE") / ("PRODUCT" -> "PowerEdge C6105 (N/A)")
s must /("data") */ ("HARDWARE") */ ("BASE") / ("VENDOR" -> "Winbond Electronics")
s must /("data") */ ("HARDWARE") */ ("BASE") / ("SERIAL" -> "FZ22YQ1")
}
}
"Updating an asset" in new WithApplication(FakeApplication(
additionalConfiguration = Map(
"solr.enabled" -> false))) with AssetApiHelper {
override val assetTag = "A0002"
createAsset() must haveStatus(201)
// Update HW info twice to ensure that we are
// overwriting the data from the first intake
updateHwInfo() must haveStatus(200)
updateStatus(Status.Maintenance.get, "refresh lshw") must haveStatus(200)
updateHwInfo("lshw-basic-dynamic-enums.xml") must haveStatus(200)

val asset = Asset.findByTag(assetTag).get
val atts = AssetMetaValue.findByAsset(asset)
atts.count(_.getName() == "BASE_DESCRIPTION") mustEqual 1
atts.count(_.getName() == "BASE_PRODUCT") mustEqual 1
atts.count(_.getName() == "BASE_VENDOR") mustEqual 1
atts.count(_.getName() == "BASE_SERIAL") mustEqual 1

val result = getAsset()
result must haveStatus(200)
result must haveJsonData.which { s =>
s must /("data") */ ("HARDWARE") */ ("BASE") / ("DESCRIPTION" -> "Rack Mount Chassis 2")
s must /("data") */ ("HARDWARE") */ ("BASE") / ("PRODUCT" -> "PowerEdge C6105 2")
s must /("data") */ ("HARDWARE") */ ("BASE") / ("VENDOR" -> "Winbond Electronics 2")
s must /("data") */ ("HARDWARE") */ ("BASE") / ("SERIAL" -> "FZ22YQ2")
}
}
}
}
}
Loading

0 comments on commit 35dc51e

Please sign in to comment.