lundi 6 avril 2015

Create an unit test mocking a domain with a composite key

I want to create an unit testing where I have to mock a domain. This domain has a composite key. When I save the domain in my test, it's not saved.I suppose it could be problem with the composite key. How can I test a composite key domain?



class FactorConversion implements Serializable{

String codigo
String unidad
float conversion

boolean equals(other) {
if (!(other instanceof FactorConversion)) {
return false
}

other.codigo == codigo && other.unidad == unidad
}

int hashCode() {
def builder = new HashCodeBuilder()
builder.append codigo
builder.append unidad
builder.toHashCode()
}

static mapping = {
//if (Environment.current != Environment.DEVELOPMENT) {
//table name:"Factores", owner:"dbo", catalog:"SedaS"
table name:"Factores"//, owner:"dbo", catalog:"SedaS"

version false
id generator: "assigned", composite: ['codigo', 'unidad']

unidad column:"Factor"
conversion column:"Conversion"

}


My unit test:



@TestFor(ConversionUnidadService)
@Mock(FactorConversion)
class ConversionUnidadServiceSpec extends Specification {

def setup() {
def factor1 = new FactorConversion(codigo:"000000100000006994", unidad:"CAJ", conversion:0.16666666666f).save(flush:true)


Thank you very much.


Aucun commentaire:

Enregistrer un commentaire