From: <jes...@us...> - 2011-01-14 08:56:43
|
Revision: 7153 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=7153&view=rev Author: jesseeichar Date: 2011-01-14 08:56:36 +0000 (Fri, 14 Jan 2011) Log Message: ----------- format test cleans up after itself Modified Paths: -------------- sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/Config.scala sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/DeleteTestData.scala sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/debug/Misc.scala sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/request-framework.scala sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/spec/SharedObjectSpec.scala Added Paths: ----------- sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/request-format.scala Modified: sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/Config.scala =================================================================== --- sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/Config.scala 2011-01-14 07:43:45 UTC (rev 7152) +++ sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/Config.scala 2011-01-14 08:56:36 UTC (rev 7153) @@ -181,7 +181,7 @@ val DeleteNewKeywords = DeleteCreated(SharedObjectTypes.keywords,startKeywords) val DeleteNewDeleted = DeleteCreated(SharedObjectTypes.deleted,startDeleted) try { - (adminLogin then DeleteMetadata then DeleteGroup(groupId,true) then DeleteNewContacts then DeleteNewExtents then DeleteNewExtents then DeleteNewKeywords then DeleteNewDeleted){ + (adminLogin then DeleteMetadata then DeleteGroup(groupId,true) then DeleteTestFormats() then DeleteNewContacts then DeleteNewExtents then DeleteNewExtents then DeleteNewKeywords then DeleteNewDeleted){ case response if response.responseCode > 200 => System.err.println("Error occurred during teardown. Group was not deleted. ResponseCode = "+response.responseCode) case _ => () } @@ -201,6 +201,16 @@ } } +object DeleteTestFormats { + def apply() = ListFormats(Config.TEST_TAG) then { res:Response => + res match { + case r:ListFormatResponse => + val deleteRequests = r.list map {f => DeleteFormat(f.id)} + Request.chain(deleteRequests) + case r => throw new IllegalStateException("needed to follow a ListFormats Request") + } + } +} object DeleteCreated { def apply(objType:SharedObjectTypes.SharedObjectType,startValues:List[SharedObject]) = { def DeleteOrRejectCommand(obj:SharedObject) = { Modified: sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/DeleteTestData.scala =================================================================== --- sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/DeleteTestData.scala 2011-01-14 07:43:45 UTC (rev 7152) +++ sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/DeleteTestData.scala 2011-01-14 08:56:36 UTC (rev 7153) @@ -37,8 +37,8 @@ val DeleteNewKeywords = DeleteCreated(SharedObjectTypes.keywords,Nil) val DeleteNewDeleted = DeleteCreated(SharedObjectTypes.deleted,Nil) - (Config.adminLogin then DeleteMds then DeleteGroups then DeleteSharedContacts then DeleteNewExtents then DeleteNewFormats then - DeleteNewKeywords then DeleteNewDeleted ) {response => + (Config.adminLogin then DeleteMds then DeleteGroups then DeleteTestFormats() then DeleteNewFormats then DeleteSharedContacts + then DeleteNewExtents then DeleteNewKeywords then DeleteNewDeleted) {response => require(response.responseCode == 200, "Obtained a "+response.responseCode+" responseCode when deleting group") } } Modified: sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/debug/Misc.scala =================================================================== --- sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/debug/Misc.scala 2011-01-14 07:43:45 UTC (rev 7152) +++ sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/debug/Misc.scala 2011-01-14 08:56:36 UTC (rev 7153) @@ -10,5 +10,7 @@ */ object Misc extends Application { - println(AddSites.extent.toString) + (Config.adminLogin then ListFormats()) { + case r:ListFormatResponse => println(r.list) + } } Added: sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/request-format.scala =================================================================== --- sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/request-format.scala (rev 0) +++ sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/request-format.scala 2011-01-14 08:56:36 UTC (rev 7153) @@ -0,0 +1,26 @@ +package org.fao.geonet + +case class Format(id:Int, name:String, version:String) +class ListFormatResponse(response:Response) extends DecoratingResponse(response) with XmlResponse { + private val Parser = """(.*?)\[(.*?)\]""".r + lazy val list = withXml {xml=> + (xml \\ "li").toList map {li => + val id = XLink.id(li).get.toInt + val text = li.text.trim + + val (name,version) = text match { + case Parser(name,version) => name -> version + case name => name -> "" + } + val validated = (li \\ "@alt" text).trim.nonEmpty + Format(id,name.trim,version.trim) + } + } +} +case class ListFormats(searchParam:String="") + extends GetRequest("xml.format.list", new SelfResponseFactory[ListFormatResponse](), "name" -> searchParam) +with ResponseFactory[ListFormatResponse] { + def wrapResponse(basicResponse: Response) = new ListFormatResponse(basicResponse) +} + +case class DeleteFormat(id:Int) extends GetRequest("format", XmlResponseFactory, "action" -> "DELETE", "id" -> id.toString) Modified: sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/request-framework.scala =================================================================== --- sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/request-framework.scala 2011-01-14 07:43:45 UTC (rev 7152) +++ sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/request-framework.scala 2011-01-14 08:56:36 UTC (rev 7153) @@ -11,6 +11,11 @@ } import RequestMethods._ +object Request { + def chain(requests:TraversableOnce[Request]) = ((NoRequest:Request) /: requests) { + case (req,next) => req then next + } +} trait Request extends Function0[Response]{ def assertPassed() = apply{ case response if response.responseCode > 200 => throw new AssertionError(toString+" did not complete correctly, reponseCode="+response.responseCode) Modified: sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/spec/SharedObjectSpec.scala =================================================================== --- sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/spec/SharedObjectSpec.scala 2011-01-14 07:43:45 UTC (rev 7152) +++ sandbox/geocat.ch/trunk/test/integration/src/test/scala/org/fao/geonet/spec/SharedObjectSpec.scala 2011-01-14 08:56:36 UTC (rev 7153) @@ -32,7 +32,7 @@ } val xlinks = XLink.findAll(originalXml,AddSites.distributionFormat) xlinks must haveSize (3) - xlinks foreach (i=> println("'"+i.formatVersion+"'")) + val formatId = xlinks.find{_.formatVersion == "2"}.get.id.toInt (Config.adminLogin then ValidateSharedObject(formatId,SharedObjectTypes.formats) then GetMetadataXml(id,OutputSchemas.CheRecord)) { case response:XmlResponse => withXml(response) { xml => @@ -43,7 +43,11 @@ val validated = newXlinks collect { case xlink if xlink.isValidated => xlink } - validated must haveSize (1) + validated must haveSize (2) + val invalidated = newXlinks collect { + case xlink if xlink.nonValidated => xlink + } + invalidated must haveSize (1) () } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |