Skip to content

Instantly share code, notes, and snippets.

@d10xa
Last active September 25, 2015 09:07
Show Gist options
  • Save d10xa/c9ce30139b7dfeac0702 to your computer and use it in GitHub Desktop.
Save d10xa/c9ce30139b7dfeac0702 to your computer and use it in GitHub Desktop.
package ru.d10xa.hibernate
import org.springframework.data.repository.CrudRepository
import javax.persistence.*
@Entity
class Language {
@Id @GeneratedValue Long id;
String name
Integer year
}
interface LanguageRepository
extends CrudRepository<Language, Long> {
Language findByName(String name)
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.5.RELEASE")
}
}
apply plugin: 'groovy'
apply plugin: 'spring-boot'
repositories {
mavenCentral()
maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.4'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'com.h2database:h2'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'org.spockframework:spock-core:0.7-groovy-2.0'
testCompile 'org.spockframework:spock-spring:0.7-groovy-2.0'
}
sourceSets.test.groovy {
srcDir projectDir.absolutePath
}
test.outputs.upToDateWhen { false }
package ru.d10xa.hibernate
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.test.SpringApplicationContextLoader
import org.springframework.test.context.ContextConfiguration
import org.springframework.transaction.annotation.EnableTransactionManagement
import org.springframework.transaction.annotation.Transactional
import spock.lang.Specification
import spock.lang.Unroll
@ContextConfiguration(loader = SpringApplicationContextLoader, classes = Spec)
@EnableTransactionManagement
@Transactional
@SpringBootApplication
@Unroll
public class Spec extends Specification {
@Autowired
LanguageRepository repo;
def '#name appeared in #year'() {
given:
repo.save([name: 'java', year: 1995] as Language)
repo.save([name: 'groovy', year: 2003] as Language)
repo.save([name: 'javascript', year: 1995] as Language)
when:
def language = repo.findByName(name)
then:
language.year == year
where:
name | year
'java' | 1995
'groovy' | 2003
'javascript' | 1995
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment