Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Groovy by vinicius ( 14 years ago )
package br.com.synchro.gov
import br.com.synchro.gov.test.TestUtils
import grails.test.GrailsUnitTestCase
import groovy.sql.Sql
import org.codehaus.groovy.grails.commons.ConfigurationHolder
import org.junit.BeforeClass
import org.junit.Test
class EmpresaControllerIntegrationTests extends GrailsUnitTestCase {
def static controller
@BeforeClass
public static void setUp() {
def config = ConfigurationHolder.config
def sql = Sql.newInstance(config.dataSource.url, config.dataSource.username, config.dataSource.password, config.dataSource.driverClassName)
TestUtils.apagarBanco(sql)
def pernalonga = new Usuario(nome: "Pernalonga", enabled: true, username:"pernalonga", password:"user", cargo: TipoCargo.DIRETOR).save(flush: true, failOnError: true)
def org = new Org(nome: 'ORG01', administrador: pernalonga).save(flush: true, failOnError: true)
def brasil = new Territorio(sigla: 'Brasil', nome: 'Brasil', esfera: TipoEsfera.FEDERAL).save(flush: true, failOnError: true)
def wonkaInc = new Empresa(nomeFantasia:"Matriz", razaoSocial: "Matriz", cnpj: "04082772000102", raizCnpj: '04082772', responsavel: pernalonga, org: org, territorio: brasil).save(flush:true, failOnError: true)
def wonkaChocDivision = new Empresa(nomeFantasia:"Wonka Choc Division", razaoSocial: "Wonka Choc Division", cnpj: "04082772000103", raizCnpj: '04082772', responsavel: pernalonga, matriz: wonkaInc, org: org, territorio: brasil).save(flush:true, failOnError: true)
controller = new EmpresaController()
controller.springSecurityService = [principal:[id:pernalonga.id]]
}
@Test
void indexRetornaEmpresasDoUsuarioLogado() {
def result = controller.index()
assert result.empresas.size() == 1
}
}
Revise this Paste