Avinay504 / BACK-END-USING-HIBERNATE

desigining the backend of shopping cart using hibernate and h2db.
0 stars 0 forks source link

Test class i.e categorytestcase is showing success of creating table but not entering data in h2db. #1

Open Avinay504 opened 8 years ago

Avinay504 commented 8 years ago

package com.niit.ShoppingCartBackEnd;

import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import com.niit.shoppingcart.dao.CategoryDAO; import com.niit.shoppingcart.model.Category;

public class CategoryTestCase {

@Autowired
static
AnnotationConfigApplicationContext context;

@Autowired
static
Category category;

@Autowired
static
CategoryDAO categoryDAO;

@BeforeClass    
public static void init(){
    context=new AnnotationConfigApplicationContext();
    context.scan("com.niit.shoppingcart");
    context.refresh();
    category=(Category)context.getBean("category");
    categoryDAO=(CategoryDAO)context.getBean("categoryDAO");

}

@Test
 public void createCategoryTestCase(){

    category.setId("MOB_07");
    category.setName("SAMSUNG");
    category.setDescription("This is the best phone.");

     Boolean status=categoryDAO.save(category);

     Assert.assertEquals("Create Category Test Case",true,status);
 }
 @Test
 public void updateCategoryTestcase(){

     category.setId("3");
     category.setName("ravi");
     category.setDescription("He lives in bengaluru ");

     Boolean status=categoryDAO.update(category); 

     Assert.assertEquals("Update Category Test case", true,status);
 }
 @Test
 public void deleteCategoryTestCase(){
     category.setId("1");
     category.setName("avinay");
     category.setDescription("This is my name");

     Boolean status=categoryDAO.delete(category) ;

     Assert.assertEquals("Update Category Test case", true,status);

 }
 @Test
 public void getCategoryTestCase(){

     Assert.assertEquals("Get Category Test Case",null,categoryDAO.get("avi"));

 }
 @Test
 public void getAllCategoryTestCase(){
      Assert.assertEquals("Get All category Test Case", categoryDAO.list().size());
 }

}

Avinay504 commented 8 years ago

showing error in junit asNov 09, 2016 12:20:34 AM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist Nov 09, 2016 12:20:35 AM org.hibernate.dialect.Dialect <init> INFO: HHH000400: Using dialect: org.hibernate.dialect.H2Dialect Nov 09, 2016 12:20:35 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService INFO: HHH000399: Using default transaction strategy (direct JDBC transactions) Nov 09, 2016 12:20:35 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init> INFO: HHH000397: Using ASTQueryTranslatorFactory Nov 09, 2016 12:20:36 AM org.hibernate.validator.internal.util.Version <clinit> INFO: HV000001: Hibernate Validator 5.3.0.Alpha1 Nov 09, 2016 12:20:39 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000228: Running hbm2ddl schema update Nov 09, 2016 12:20:39 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000102: Fetching database metadata Nov 09, 2016 12:20:39 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000396: Updating schema Nov 09, 2016 12:20:39 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000261: Table found: TEST.PUBLIC.CATEGORY Nov 09, 2016 12:20:39 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000037: Columns: [name, description, id] Nov 09, 2016 12:20:39 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000108: Foreign keys: [] Nov 09, 2016 12:20:39 AM org.hibernate.tool.hbm2ddl.TableMetadata <init> INFO: HHH000126: Indexes: [primary_key_3, constraint_index_3] Nov 09, 2016 12:20:39 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute INFO: HHH000232: Schema update complete Nov 09, 2016 12:20:39 AM org.springframework.orm.hibernate4.HibernateTransactionManager afterPropertiesSet INFO: Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@55182842] of Hibernate SessionFactory for HibernateTransactionManager Hibernate: select category0_.id as id1_0_0_, category0_.description as descript2_0_0_, category0_.name as name3_0_0_ from category category0_ where category0_.id=? Hibernate: select category0_.id as id1_0_0_, category0_.description as descript2_0_0_, category0_.name as name3_0_0_ from category category0_ where category0_.id=? Hibernate: select category_.id, category_.description as descript2_0_, category_.name as name3_0_ from category category_ where category_.id=?

Avinay504 commented 8 years ago

junit error:java lang class exception.