30
Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing Albert Guo [email protected]

Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Embed Size (px)

Citation preview

Page 1: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Applied MyEclipse and JUnit to do Hibernate Code Gen and TestingAlbert Guo

[email protected]

Page 2: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Agenda

• High Level Picture

• Hibernate Code Generation

– Code Gen Process

– Generate DAO for the four tables

– Artifacts

– Spring Configuration File

– Sequence Diagram

• Apply JUnit to do DAOs Test

– JUnit Framework

– How to Test with JUnit?

– Simplified Workflow of Applying JUnit

– Testing Process

– Generate Unit Test Result via Ant

2

Page 3: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

High Level Picture

3

Client Layer Business Layer Persistence Layer

Spring – IOC Container

Hibernate Session Mgt.

Business Service Classes

HibernateWindchill Workflow

Data Source / Connection Pool

ApplicationContext

DAO Classes

ApplicationContext.xml Hibernate Mapping files

Page 4: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Code Gen Process

4

including POJOs, DAOs, hibernate mapping files and Spring configuration file

Page 5: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Filled in connection info.

Add MS SQL driver

5

Save password, then you do not need to type in again

Page 6: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Click Test Driver to test database connection

6

If you connect to database successfully, then you can see this popup window

Page 7: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Generate DAO for the four tables

7

Page 8: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

8

Select tables which we would like to do code gen.

Click Hibernate Reverse Engineering

Page 9: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

9

Assign destination

Generate hibernate mapping file

Generate POJO

Generate Spring DAO

Page 10: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

10

Select ID Generator

Page 11: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

11

Page 12: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Artifacts

12

We had generated POJOs, hibernate mapping files, and DAOs

Page 13: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Spring Configuration File

13

Inject webSiteDataSource into sessionFactory

Page 14: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Spring Configuration File – cont.

14

Inject sessionFactory into each DAOs.

Page 15: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Sequence Diagram

15

Page 16: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Apply Junit to do DAOs Test

16

Page 17: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

JUnit Framework

17

run()

<< interface >>Test

fName

setUp()runTest()tearDown()run()

TestCase

run()addTest()

TestSuite

*

TestResult

junit.framework

assertTrue()assertEquals()...

Assert

junit.textui.TestRunner junit.swingui.TestRunner

Page 18: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

How to Test with JUnit?

18

junit

WipPortingDAO

TestCase

exercise1..*

TestRunner

run1..*WipPortingDAOTest

test1

test2

Page 19: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Simplified Workflow of Applying JUnit

19

Class files

Test CasesTest MethodsTest Suites

Test Runner

Page 20: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Testing Process

20

Overrides setUp() and/or tearDown()

Writes test methods, ex.test…()

Uses Assert.assert…()

Writes suite() and/or main()

Page 21: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Create Fixture via MyEclipse

21

Page 22: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Create Fixture via MyEclipse – cont.

22

Page 23: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Create Fixture via MyEclipse – cont.

23

Page 24: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Create Fixture via MyEclipse – cont.

24

Page 25: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Exercise & Verify

25

Page 26: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Exercise & Verify – cont.

26

Page 27: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Suit Management

27

Page 28: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Suit Management

28

Page 29: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Generate Unit Test Result via Ant

29

Build.xml

Page 30: Applied MyEclipse and JUnit to do Hibernate Code Gen and Testing

Generate Unit Test Result via Ant

30