Skip to content

Commit

Permalink
added unit tests from master and adjusted for grails3
Browse files Browse the repository at this point in the history
  • Loading branch information
dularion committed Jul 4, 2016
1 parent 1cb127e commit 1787028
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/test/groovy/streama/EpisodeSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package streama
import grails.test.mixin.TestFor
import spock.lang.Specification
/**
* See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
*/
@TestFor(Episode)
class EpisodeSpec extends Specification {

void "test episode naming"() {
setup:
def episode0 = Episode.newInstance()
def episode1 = Episode.newInstance()
episode0.season_number = 1
episode0.episode_number = 33
episode0.beforeUpdate()

episode1.season_number = 640
episode1.episode_number = 2
episode1.beforeUpdate()

expect:
episode0.episodeString == "s01e33"
episode1.episodeString == "s640e02"
}
}
31 changes: 31 additions & 0 deletions src/test/groovy/streama/FileSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package streama
import grails.test.mixin.TestFor
import spock.lang.Specification
/**
* See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
*/
@TestFor(File)
class FileSpec extends Specification {
void "test file constraints for sha256Hex and quality"() {
setup:
def file0 = File.newInstance()
def file1 = File.newInstance()
def file2 = File.newInstance()
def file3 = File.newInstance()

//string length 64
file0.sha256Hex = 'TuFk8RjfG4AYQYT0pmK6vaBivF449S2UNmhXQEbE9Sr3FFFX44n4lyPq2jOQkUUv'
//string length 65, too long
file1.sha256Hex = '8iSuxvAT7NGS5lAa1eOIw1MlKZhO14m9p3ZQSQ08VilBGqniVA1EeLvyxKj8MNW3g'
//quality 720p is on the allowed list
file2.quality = '720p'
//quality 721p is not on the allowed list
file3.quality = '721p'

expect:
file0.validate() == true
file1.validate() == false
file2.validate() == true
file3.validate() == false
}
}
23 changes: 23 additions & 0 deletions src/test/groovy/streama/GenreSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package streama

import grails.test.mixin.TestFor
import spock.lang.Specification

/**
* See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
*/
@TestFor(Genre)
class GenreSpec extends Specification {

void "test constraints with null values on apiId and name"() {
setup:
def genre0 = Genre.newInstance()
def genre1 = Genre.newInstance()

genre0.apiId = null
genre1.name = null
expect:
genre0.validate() == false
genre1.validate() == false
}
}
47 changes: 47 additions & 0 deletions src/test/groovy/streama/SettingsControllerSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package streama

import grails.test.mixin.Mock
import grails.test.mixin.TestFor
import spock.lang.Specification

/**
* See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
*/
@TestFor(SettingsController)
@Mock(Settings)
class SettingsControllerSpec extends Specification {

void "test settings instance is null, status 404"() {

when:
def settingsController = SettingsController.newInstance()
request.method = 'POST'
settingsController.save(null)

then:
status == 404
}

void "test settings instance not valid, status 406"() {
when:
def settingsController = SettingsController.newInstance()
def settingsMock = new Settings(settingsKey: null)
request.method = 'POST'
settingsController.save(settingsMock)

then:
status == 406
}

void "test settings instance is valid, status 201"() {
when:
def settingsController = SettingsController.newInstance()
def settingsMock = new Settings(settingsKey: 'abcd')
request.method = 'POST'
settingsController.save(settingsMock)

then:
status == 201
}

}
21 changes: 21 additions & 0 deletions src/test/groovy/streama/SettingsServiceSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package streama

import grails.test.mixin.Mock
import grails.test.mixin.TestFor
import spock.lang.Specification

@TestFor(SettingsService)
@Mock(Settings)
class SettingsServiceSpec extends Specification {
void "test getting base URL"() {
setup:
def settingsService = SettingsService.newInstance()
def settings = [
new Settings(settingsKey: 'Base URL', value: 'http://localhost:8080/streama')
]
settings*.save(flush: true)
def result = settingsService.getBaseUrl()
expect:
result == 'http://localhost:8080/streama'
}
}
25 changes: 25 additions & 0 deletions src/test/groovy/streama/SettingsSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package streama

import grails.test.mixin.TestFor
import spock.lang.Specification

/**
* See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
*/
@TestFor(Settings)
class SettingsSpec extends Specification {

void "test constraints for settingsKey being null"() {
setup:
def settings0 = Settings.newInstance()
def settings1 = Settings.newInstance()
//settingsKey is null, not valid
settings0.settingsKey = null
//settingsKey not null, valid
settings1.settingsKey = 'abcd'

expect:
settings0.validate() == false
settings1.validate() == true
}
}
47 changes: 47 additions & 0 deletions src/test/groovy/streama/TvShowSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package streama

import grails.test.mixin.TestFor
import spock.lang.Shared
import spock.lang.Specification

/**
* See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
*/
@TestFor(TvShow)

class TvShowSpec extends Specification {
@Shared tvshow0, tvshow1, tvshow2
def setup() {
tvshow0 = TvShow.newInstance()
tvshow1 = TvShow.newInstance()
tvshow2 = TvShow.newInstance()
}
void "test tvshow constraints for overview length"() {
setup:
//string length 4, good length
tvshow0.overview = 'asdf'
//String length 5000, good length
tvshow1.overview = 't' * 5000
//String length 5001, too long
tvshow2.overview = 'f' * 5001
//Name is not null
tvshow0.name = 'testname'
tvshow1.name = 'testname'
tvshow2.name = 'testname'

expect:
tvshow0.validate() == true
tvshow1.validate() == true
tvshow2.validate() == false
}
void "test tvshow contraints for name"() {
setup:
//Name is not null
tvshow0.name = 'testname'
//Name is null, not allowed
tvshow1.name = null
expect:
tvshow0.validate() == true
tvshow1.validate() == false
}
}
59 changes: 59 additions & 0 deletions src/test/groovy/streama/UserSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package streama

import grails.test.mixin.TestFor
import spock.lang.Specification

/**
* See the API for {@link grails.test.mixin.support.GrailsUnitTestMixin} for usage instructions
*/
@TestFor(User)
class UserSpec extends Specification {

void "test constraints for username uniqueness"() {
setup:
def user0 = User.newInstance()
def user1 = User.newInstance()

when:
user0.username = 'testuser'

then: 'username is unique'
user0.validate() == true

when:
user1.username = 'testuser2'

then: 'username is unique (for now)'
user1.validate() == true

when:
user1.save(flush: true)
def user2 = new User(username: 'testuser2')

then: 'username is not unique'
user2.validate() == false
}


void "test constraints for username being blank"() {
setup:
def user0 = User.newInstance()

user0.username = ''

expect:
user0.validate() == false
}
void "test constraints for password being blank"() {
setup:
def user0 = User.newInstance()
def user1 = User.newInstance()

user0.password = ''
user1.password = 'testpass'

expect:
user0.validate() == false
user1.validate() == true
}
}
32 changes: 32 additions & 0 deletions src/test/groovy/streama/VideoSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package streama

import grails.test.mixin.TestFor
import spock.lang.Specification

/**
* See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
*/
@TestFor(Video)
class VideoSpec extends Specification {

void "test video constraints for overview size"() {
setup:
def video0 = Video.newInstance()
def video1 = Video.newInstance()
def video2 = Video.newInstance()

//string length 4, good length
video0.overview = 'test'
//String length 5000, good length
video1.overview = 't' * 5000
//String length 5001, too long
video2.overview = 'f' * 5001

video0.dateCreated = null
video0.lastUpdated = null
expect:
video0.validate() == true
video1.validate() == true
video2.validate() == false
}
}

0 comments on commit 1787028

Please sign in to comment.