Erro ao refazer teste de classe
Colegas,
minha classe de teste fornecedor esta funcionando perfeitamente. Mas hoje quando fui testar de novo deu o seguinte erro:
MINHA CLASSE DAO
CLASSE DE TESTE
Desde já obrigado!!
minha classe de teste fornecedor esta funcionando perfeitamente. Mas hoje quando fui testar de novo deu o seguinte erro:
Testsuite: treinamento.dao.FornecedorDaoTest addFornecedor Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0,101 sec ------------- Standard Output --------------- addFornecedor ------------- ---------------- --------------- Testcase: testAddFornecedor(treinamento.dao.FornecedorDaoTest): Caused an ERROR (class: treinamento/dao/FornecedorDao, method: <init> signature: ()V) Constructor must call super() or this() java.lang.VerifyError: (class: treinamento/dao/FornecedorDao, method: <init> signature: ()V) Constructor must call super() or this() at treinamento.dao.FornecedorDaoTest.testAddFornecedor(FornecedorDaoTest.java:61) Test treinamento.dao.FornecedorDaoTest FAILED test: Deleting: /tmp/TEST-treinamento.dao.FornecedorDaoTest.xml BUILD SUCCESSFUL (total time: 3 seconds)
MINHA CLASSE DAO
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package treinamento.dao;
import java.util.logging.Level;
import java.util.logging.Logger;
import treinamento.entidade.Fornecedor;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.awt.List;
/**
*
* @author nsouza
*/
public class FornecedorDao extends GenericaDao{
public FornecedorDao(){
}
public void addFornecedor(Fornecedor frn){
try {
String sql = "{ CALL SP_IAD_FORNECEDOR(?,?,?,?,?,?,?,?,?,?,?,?) }";
executePrepered(sql,frn.getIdforn(),frn.getNome(),frn.getEndereco(),frn.getNumero(),frn.getComplemento(),frn.getBairro(),
frn.getCidade(),frn.getInscEstadual(),frn.getTelefone(),frn.getEmail(),frn.getUsuarioInclui(),frn.getOpr());
} catch (SQLException ex) {
Logger.getLogger(FornecedorDao.class.getName()).log(Level.SEVERE, null, ex);
}
}
public Fornecedor getFornecedor(int idForn) throws SQLException {
ResultSet rs = executeQuery("SELECT * FROM Fornecedor WHERE IDForn = ?", idForn);
Fornecedor usr = null;
if (rs.next()) {
usr = populateFornecedorInfo(rs);
}
rs.close();
return usr;
}
public LinkedList<Fornecedor> getAllFornecedor() throws SQLException {
ResultSet rs = executeQuery("SELECT * FROM Fornecedor");
LinkedList<Fornecedor> toReturn = new LinkedList<Fornecedor>();
while (rs.next()) {
toReturn.add(populateFornecedorInfo(rs));
}
rs.close();
return toReturn;
}
public static Fornecedor populateFornecedorInfo(ResultSet rs) throws SQLException {
Fornecedor toReturn = new Fornecedor();
toReturn.setIdforn(rs.getInt("IDFORN"));
toReturn.setNome(rs.getString("NOME"));
toReturn.setEndereco(rs.getString("ENDERECO"));
toReturn.setNumero(rs.getInt("NUMERO"));
toReturn.setComplemento(rs.getString("COMPLEMENTO"));
toReturn.setBairro(rs.getString("BAIRRO"));
toReturn.setCidade(rs.getString("CIDADE"));
toReturn.setInscEstadual(rs.getInt("INSC_ESTADUAL"));
toReturn.setTelefone(rs.getString("TELEFONE"));
toReturn.setEmail(rs.getString("EMAIL"));
return toReturn;
}
}
CLASSE DE TESTE
package treinamento.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import treinamento.entidade.Fornecedor;
/**
*
* @author nsouza
*/
public class FornecedorDaoTest {
public FornecedorDaoTest() {
}
@BeforeClass
public static void setUpClass() throws Exception {
}
@AfterClass
public static void tearDownClass() throws Exception {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of addFornecedor method, of class FornecedorDao.
*/
@Test
public void testAddFornecedor() {
System.out.println("addFornecedor");
Fornecedor forn = new Fornecedor();
forn.setIdforn(8);
forn.setNome("Andorra");
forn.setEndereco("congonhas");
forn.setNumero(221);
forn.setComplemento("apt 999");
forn.setBairro("bairu");
forn.setCidade("Fritas");
forn.setInscEstadual(97143000);
forn.setTelefone("329997756");
forn.setEmail("ado@gmail.com");
forn.setUsuarioInclui(1);
forn.setOpr("U");
FornecedorDao instance = new FornecedorDao();
instance.addFornecedor(forn);
}
//@Test
public void testGetUsuario() throws Exception {
System.out.println("getUsuario");
int idForn = 8;
FornecedorDao instance = new FornecedorDao();
int expResult = 8;
Fornecedor result = instance.getFornecedor(idForn);
assertEquals(expResult,(int) result.getIdforn());
}
}
Desde já obrigado!!
Nilo Souza
Curtidas 0
Respostas
Davi Costa
06/06/2011
A linha que está dando problemas é essa:
Posta essa linha para gente analisar
Seria interessante vc colocar o statckTrace completo, será que não é problema de banco?..vc está testando um id que já existe lá?
att Davi
Posta essa linha para gente analisar
Seria interessante vc colocar o statckTrace completo, será que não é problema de banco?..vc está testando um id que já existe lá?
att Davi
GOSTEI 0
Nilo Souza
06/06/2011
a linha que a ponta para ao problema é essa:
FornecedorDao instance = new FornecedorDao();
e o stack trace é o que mostrei.
FornecedorDao instance = new FornecedorDao();
e o stack trace é o que mostrei.
GOSTEI 0
Nilo Souza
06/06/2011
Não sei explicar mas faltava essa linha:
private static final long serialVersionUID = 1L;
GOSTEI 0
Davi Costa
06/06/2011
Certo vi essa classe e seu construtor default não tina nada, mas ele herda de uma super, mostra o construtor padrão dessa superclasse de FornecedorDAO (GenericaDao)
att Davi
att Davi
GOSTEI 0
Nilo Souza
06/06/2011
SE Entendi foi isso que pediu?
package treinamento.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
public abstract class GenericaDao {
private static final long serialVersionUID = 1L;
public Connection getConnection() {
try {
Class.forName("org.firebirdsql.jdbc.FBDriver");
Connection cx = DriverManager.getConnection("jdbc:firebirdsql:localhost:/var/lib/firebird/2.5/projeto/VENDAS.FDB","SYSDBA","masterkey");
//Connection cx = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","nsouza","oralocal");
return cx;
} catch (Exception ex) {
Logger.getLogger(GenericaDao.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
public Statement getStatement() throws SQLException {
return getConnection().createStatement();
}
public PreparedStatement getPrepared(String st) throws SQLException {
return getConnection().prepareStatement(st);
}
public CallableStatement getCallableStatement(String st) throws SQLException{
return getConnection().prepareCall(st);
}
public ResultSet executeQuery(String query,Object... params) throws SQLException {
PreparedStatement ps = getPrepared(query);
for (int i = 0; i < params.length; i++) {
ps.setObject(i+1, params[i]);
}
return ps.executeQuery();
}
public int executePrepered(String query,Object... params) throws SQLException {
PreparedStatement ps = getCallableStatement(query);
for (int i = 0; i < params.length; i++) {
try {
ps.setObject(i+1, params[i]);
} catch (Exception e) {
System.out.println("Error to try "+i+" with value "+params[i]);
}
}
int result = ps.executeUpdate();
ps.close();
return result;
}
public int executeCommand(String query,Object... params) throws SQLException {
PreparedStatement ps = getPrepared(query);
for (int i = 0; i < params.length; i++) {
try {
ps.setObject(i+1, params[i]);
} catch (Exception e) {
System.out.println("Error to try "+i+" with value "+params[i]);
}
}
int result = ps.executeUpdate();
ps.close();
return result;
}
}
GOSTEI 0
Dyego Carmo
06/06/2011
Tentou alterar:
public FornecedorDao(){
}
para
public FornecedorDao(){
super();
}
?
public FornecedorDao(){
}
para
public FornecedorDao(){
super();
}
?
GOSTEI 0
Davi Costa
06/06/2011
vc tb pode até retirar o :
Pq o JVm criaria o construtor default que implicitamente faruia uma chamada ao super();
att Davi
public FornecedorDAO(){
}
Pq o JVm criaria o construtor default que implicitamente faruia uma chamada ao super();
att Davi
GOSTEI 0