Skip to content
This repository has been archived by the owner on Oct 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #110 from MITLibraries/109_test_coverage
Browse files Browse the repository at this point in the history
109 test coverage
  • Loading branch information
JPrevost committed Mar 19, 2015
2 parents 9510eb1 + 20796ef commit 39f98d2
Show file tree
Hide file tree
Showing 11 changed files with 930 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ env:
- MAILGUN_API_KEY=notarealkey DATABASE_URL=jdbc:postgresql://localhost/travis_ci_test
addons:
postgresql: "9.3"

script: "sbt clean coverage test"
after_success: "sbt coveralls"
before_script:
- psql -c 'create database travis_ci_test;' -U postgres
5 changes: 0 additions & 5 deletions README

This file was deleted.

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SCOAP3 TopicHub
=================================

This is a web application to allow users to discover, subscribe to,
and obtain automatic delivery of, aggregations of article content from the SCOAP3 repository.

[![Build Status](https://travis-ci.org/MITLibraries/scoap3hub.svg?branch=107_sub_status_in_search_results)](https://travis-ci.org/MITLibraries/scoap3hub) [![Coverage Status](https://coveralls.io/repos/MITLibraries/scoap3hub/badge.svg?branch=item_model_tests)](https://coveralls.io/r/MITLibraries/scoap3hub?branch=item_model_tests)
16 changes: 8 additions & 8 deletions app/models/Item.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ case class Item(id: Int, // DB key
}

def filename(uri: String) = {
if( uri.endsWith("pdf") ) {
if( uri.endsWith("pdf") && hasMetadata("doi") ) {
metadataValue("doi").split("/").last + ".pdf"
} else if( uri.endsWith("pdfa") ) {
} else if( uri.endsWith("pdfa") && hasMetadata("doi") ) {
metadataValue("doi").split("/").last + "_pdfa.pdf"
} else if( uri.endsWith("xml") ) {
} else if( uri.endsWith("xml") && hasMetadata("doi") ) {
metadataValue("doi").split("/").last + ".xml"
} else {
"filename_error"
Expand All @@ -119,7 +119,7 @@ case class Item(id: Int, // DB key
def toMets = {
<mets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.loc.gov/METS/"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xlink="http://www.w3.org/1999/xlink"
xsi:schemaLocation="http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd"
OBJID="sword-mets"
LABEL="DSpace SWORD Item"
Expand Down Expand Up @@ -170,20 +170,20 @@ case class Item(id: Int, // DB key
}
}

{ if( hasMetadata("abstract") )
{ if( hasMetadata("abstract") )
<epdcx:statement epdcx:propertyURI="http://purl.org/dc/terms/abstract">
<epdcx:valueString>{ metadataValue("abstract") }</epdcx:valueString>
</epdcx:statement>
}

<epdcx:statement epdcx:propertyURI="http://purl.org/eprint/terms/isExpressedAs" epdcx:valueRef="sword-mets-expr-1"/>
</epdcx:description>

<epdcx:description epdcx:resourceId="sword-mets-expr-1">
<epdcx:statement epdcx:propertyURI="http://purl.org/dc/elements/1.1/type" epdcx:valueURI="http://purl.org/eprint/entityType/Expression"/>

<epdcx:statement epdcx:propertyURI="http://purl.org/dc/elements/1.1/type" epdcx:vesURI="http://purl.org/eprint/terms/Type" epdcx:valueURI="http://purl.org/eprint/type/JournalArticle"/>

{ if( hasMetadata("publisher") )
<epdcx:statement epdcx:propertyURI="http://purl.org/dc/elements/1.1/publisher">
<epdcx:valueString>{ metadataValue("publisher") }</epdcx:valueString>
Expand Down Expand Up @@ -319,7 +319,7 @@ object Item {

def deleteBefore(date: Date) {
DB.withConnection { implicit c =>
val rows = SQL("select id from item where created < {created}").on('created -> date)
val rows = SQL("select id from item where created <= {created}").on('created -> date)
rows().map(row => row[Int]("id")).toList.foreach(delete)
}
}
Expand Down
6 changes: 6 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.0.0")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.0.4")

addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.0.0.BETA1")

resolvers += Classpaths.sbtPluginReleases
141 changes: 141 additions & 0 deletions test/unit/CollectionSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import org.specs2.mutable._

import play.api.test._
import play.api.test.Helpers._
import models.Item
import models.Collection
import models.Publisher
import models.User
import models.ContentType
import models.ResourceMap
import models.Scheme
import models.Topic
import java.util.Date

class CollectionSpec extends Specification {

"Collection model" should {

"#create" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
User.create("bob", "bob@example.com", "pass", "roley")
ContentType.create("tag", "label", "desc", Some("logo"))
ResourceMap.create("tag", "desc", Some("swordurl"))
Publisher.create(1, "pubtag", "pubname", "pubdesc", "pubcat", "pubstatus", Some(""), Some(""))

Collection.findAll must haveSize(0)
Collection.create(1, 1, 1, "coll", "desc", "open")
Collection.findAll must haveSize(1)
}
}

"#make" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
User.create("bob", "bob@example.com", "pass", "roley")
ContentType.create("tag", "label", "desc", Some("logo"))
ResourceMap.create("tag", "desc", Some("swordurl"))
Publisher.create(1, "pubtag", "pubname", "pubdesc", "pubcat", "pubstatus", Some(""), Some(""))

Collection.findAll must haveSize(0)
var c = Collection.make(1, 1, 1, "coll", "desc", "open")
Collection.findAll must haveSize(1)
c must equalTo(Collection.findById(1).get)
}
}

"#findByPublisher" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
User.create("bob", "bob@example.com", "pass", "roley")
ContentType.create("tag", "label", "desc", Some("logo"))
ResourceMap.create("tag", "desc", Some("swordurl"))
Publisher.create(1, "pubtag", "pubname", "pubdesc", "pubcat", "pubstatus", Some(""), Some(""))
Publisher.create(1, "pubtag2", "pubname2", "pubdesc2", "pubcat2", "pubstatus2", Some(""), Some(""))

var c1 = Collection.make(1, 1, 1, "coll1", "desc", "open")
var c2 = Collection.make(1, 1, 1, "coll2", "desc", "open")
var c3 = Collection.make(2, 1, 1, "coll3", "desc", "open")

var cols = Collection.findByPublisher(1)
cols.contains(c1) must equalTo(true)
cols.contains(c2) must equalTo(true)
cols.contains(c3) must equalTo(false)
}
}

"#findByTag" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
User.create("bob", "bob@example.com", "pass", "roley")
ContentType.create("tag", "label", "desc", Some("logo"))
ResourceMap.create("tag", "desc", Some("swordurl"))
Publisher.create(1, "pubtag", "pubname", "pubdesc", "pubcat", "pubstatus", Some(""), Some(""))
Publisher.create(1, "pubtag2", "pubname2", "pubdesc2", "pubcat2", "pubstatus2", Some(""), Some(""))

var c1 = Collection.make(1, 1, 1, "coll1", "desc", "open")
var c2 = Collection.make(1, 1, 1, "coll2", "desc", "open")
var c3 = Collection.make(2, 1, 1, "coll3", "desc", "open")

var cols = Collection.findByTag("coll1")
cols.contains(c1) must equalTo(true)
cols.contains(c2) must equalTo(false)
cols.contains(c3) must equalTo(false)
}
}

"#findById" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
User.create("bob", "bob@example.com", "pass", "roley")
ContentType.create("tag", "label", "desc", Some("logo"))
ResourceMap.create("tag", "desc", Some("swordurl"))
Publisher.create(1, "pubtag", "pubname", "pubdesc", "pubcat", "pubstatus", Some(""), Some(""))
Publisher.create(1, "pubtag2", "pubname2", "pubdesc2", "pubcat2", "pubstatus2", Some(""), Some(""))

var c1 = Collection.make(1, 1, 1, "coll1", "desc", "open")
var c2 = Collection.make(1, 1, 1, "coll2", "desc", "open")
var c3 = Collection.make(2, 1, 1, "coll3", "desc", "open")

var cols = Collection.findById(1)
cols.contains(c1) must equalTo(true)
cols.contains(c2) must equalTo(false)
cols.contains(c3) must equalTo(false)
}
}

"#findAll" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
User.create("bob", "bob@example.com", "pass", "roley")
ContentType.create("tag", "label", "desc", Some("logo"))
ResourceMap.create("tag", "desc", Some("swordurl"))
Publisher.create(1, "pubtag", "pubname", "pubdesc", "pubcat", "pubstatus", Some(""), Some(""))
Publisher.create(1, "pubtag2", "pubname2", "pubdesc2", "pubcat2", "pubstatus2", Some(""), Some(""))

var c1 = Collection.make(1, 1, 1, "coll1", "desc", "open")
var c2 = Collection.make(1, 1, 1, "coll2", "desc", "open")
var c3 = Collection.make(2, 1, 1, "coll3", "desc", "open")

var cols = Collection.findAll
cols must haveSize(3)
cols.contains(c1) must equalTo(true)
cols.contains(c2) must equalTo(true)
cols.contains(c3) must equalTo(true)
}
}

"#recordDeposit" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
User.create("bob", "bob@example.com", "pass", "roley")
ContentType.create("tag", "label", "desc", Some("logo"))
ResourceMap.create("tag", "desc", Some("swordurl"))
Publisher.create(1, "pubtag", "pubname", "pubdesc", "pubcat", "pubstatus", Some(""), Some(""))
Publisher.create(1, "pubtag2", "pubname2", "pubdesc2", "pubcat2", "pubstatus2", Some(""), Some(""))

var c1 = Collection.make(1, 1, 1, "coll1", "desc", "open")

c1.deposits must equalTo(0)
c1.recordDeposit
// necessary to reload to check updated value
Collection.findById(c1.id).get.deposits must equalTo(1)
}
}

}
}
64 changes: 64 additions & 0 deletions test/unit/ContentFormat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import org.specs2.mutable._

import play.api.test._
import play.api.test.Helpers._
import models.ContentFormat
import java.util.Date

class ContentFormatSpec extends Specification {

"ContentFormat model" should {

"#create" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
ContentFormat.all must haveSize(0)
ContentFormat.create("tag", "label", "desc", "http://www.example.com", "mimetype", Some("logo"))
ContentFormat.all must haveSize(1)
}
}

"#all" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
ContentFormat.all must haveSize(0)
ContentFormat.create("tag", "label", "desc", "http://www.example.com", "mimetype", Some("logo"))
ContentFormat.create("tag2", "label", "desc", "http://www.example.com", "mimetype", Some("logo"))
val cf = ContentFormat.all
cf must haveSize(2)
cf.contains(ContentFormat.findById(1).get) must equalTo(true)
cf.contains(ContentFormat.findById(2).get) must equalTo(true)
}
}

"#findById" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
ContentFormat.all must haveSize(0)
ContentFormat.create("tag", "label", "desc", "http://www.example.com", "mimetype", Some("logo"))
ContentFormat.create("tag2", "label", "desc", "http://www.example.com", "mimetype", Some("logo"))
ContentFormat.all must haveSize(2)
ContentFormat.findById(1).get.tag must equalTo("tag")
}
}

"#findByTag" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
ContentFormat.all must haveSize(0)
ContentFormat.create("tag", "label", "desc", "http://www.example.com", "mimetype", Some("logo"))
ContentFormat.create("tag2", "label", "desc", "http://www.example.com", "mimetype", Some("logo"))
ContentFormat.all must haveSize(2)
ContentFormat.findByTag("tag").get.id must equalTo(1)
}
}

"#mapView" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
ContentFormat.all must haveSize(0)
ContentFormat.create("tag", "label", "desc", "http://www.example.com", "mimetype", Some("logo"))
ContentFormat.create("tag2", "label", "desc", "http://www.example.com", "mimetype", Some("logo"))
ContentFormat.all must haveSize(2)
val map = ContentFormat.mapView
map must havePair("1" -> "tag")
map must havePair("2" -> "tag2")
}
}
}
}
87 changes: 87 additions & 0 deletions test/unit/ContentTypeSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import org.specs2.mutable._
import org.specs2.matcher._
import org.specs2.matcher.MatchResult

import play.api.test._
import play.api.test.Helpers._
import models.ContentType
import models.Scheme
import java.util.Date

class ContentTypeSpec extends Specification {

"ContentType model" should {

"#create" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
ContentType.all must haveSize(0)
ContentType.create("tag", "label", "desc", Some("logo"))
ContentType.all must haveSize(1)
}
}

"#all" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
ContentType.create("tag", "label", "desc", Some("logo"))
ContentType.create("tag2", "label", "desc", Some("logo"))
ContentType.create("tag3", "label", "desc", Some("logo"))
val all = ContentType.all
all must haveSize(3)
all.contains(ContentType.findByTag("tag").get) must equalTo(true)
all.contains(ContentType.findByTag("tag2").get) must equalTo(true)
all.contains(ContentType.findByTag("tag3").get) must equalTo(true)
}
}

"#findById" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
ContentType.create("tag", "label", "desc", Some("logo"))
ContentType.create("tag2", "label", "desc", Some("logo"))
ContentType.create("tag3", "label", "desc", Some("logo"))
ContentType.all must haveSize(3)

ContentType.findById(1) must equalTo(ContentType.findByTag("tag"))
ContentType.findById(1) must not equalTo(ContentType.findByTag("tag2"))
}
}

"#findByTag" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
ContentType.create("tag", "label", "desc", Some("logo"))
ContentType.create("tag2", "label", "desc", Some("logo"))
ContentType.create("tag3", "label", "desc", Some("logo"))
ContentType.all must haveSize(3)

ContentType.findByTag("tag") must equalTo(ContentType.findById(1))
ContentType.findByTag("tag") must not equalTo(ContentType.findById(2))
}
}

"#mapView" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
ContentType.create("tag", "label", "desc", Some("logo"))
ContentType.create("tag2", "label", "desc", Some("logo"))
ContentType.create("tag3", "label", "desc", Some("logo"))
ContentType.all must haveSize(3)

val map = ContentType.mapView
map must havePair("1" -> "tag")
map must havePair("2" -> "tag2")
map must havePair("3" -> "tag3")
}
}

"#schemes" in {
running(FakeApplication(additionalConfiguration = inMemoryDatabase())) {
Scheme.create("tag", "gentype", "cat", "desc", Some("link"), Some("logo"))
ContentType.create("tag", "label", "desc", Some("logo"))
val ct = ContentType.findById(1)
ct.get.schemes("relation") must haveSize(0)
ct.get.addScheme(Scheme.findById(1).get, "relation")
ct.get.schemes("relation") must haveSize(1)
ct.get.removeScheme(Scheme.findById(1).get, "relation")
ct.get.schemes("relation") must haveSize(0)
}
}
}
}
Loading

0 comments on commit 39f98d2

Please sign in to comment.