1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.grustoragedb.business;
35
36 import fr.paris.lutece.plugins.grubusiness.business.customer.Customer;
37 import fr.paris.lutece.plugins.grubusiness.business.demand.Demand;
38 import fr.paris.lutece.plugins.grubusiness.business.demand.IDemandDAO;
39 import fr.paris.lutece.plugins.grubusiness.business.web.rs.EnumGenericStatus;
40 import fr.paris.lutece.test.LuteceTestCase;
41 import static org.hamcrest.CoreMatchers.is;
42 import static org.hamcrest.CoreMatchers.not;
43 import static org.hamcrest.CoreMatchers.nullValue;
44 import static org.junit.Assert.assertEquals;
45
46 import java.util.Collection;
47 import java.util.Iterator;
48
49
50
51
52
53 public class DemandDAOTest extends LuteceTestCase
54 {
55 private static final String CUSTOMER_ID_1 = "CustomerId1";
56 private static final String CUSTOMER_ID_2 = "CustomerId1";
57 private static final String DEMAND_ID_1 = "DemandId1";
58 private static final String DEMAND_ID_2 = "DemandId2";
59 private static final String DEMAND_TYPE_ID_1 = "DemandTypeId1";
60 private static final String DEMAND_TYPE_ID_2 = "DemandTypeId2";
61 private static final String DEMAND_SUBTYPE_ID_1 = "DemandSubtypeId1";
62 private static final String DEMAND_SUBTYPE_ID_2 = "DemandSubtypeId2";
63 private static final String DEMAND_REFERENCE_1 = "DemandReference1";
64 private static final String DEMAND_REFERENCE_2 = "DemandReference2";
65 private static final long DEMAND_CREATION_DATE_1 = 1L;
66 private static final long DEMAND_CREATION_DATE_2 = 2L;
67 private static final long DEMAND_CLOSURE_DATE_1 = 1L;
68 private static final long DEMAND_CLOSURE_DATE_2 = 2L;
69 private static final int DEMAND_MAX_STEPS_1 = 1;
70 private static final int DEMAND_MAX_STEPS_2 = 2;
71 private static final int DEMAND_CURRENT_STEP_1 = 1;
72 private static final int DEMAND_CURRENT_STEP_2 = 2;
73 private final IDemandDAO _demandDao;
74
75
76
77
78 public DemandDAOTest( )
79 {
80 _demandDao = new DemandDAO( );
81 }
82
83
84
85
86 public void testBusiness( )
87 {
88
89 Demand demand = new Demand( );
90 demand.setId( DEMAND_ID_1 );
91 demand.setTypeId( DEMAND_TYPE_ID_1 );
92 demand.setSubtypeId( DEMAND_SUBTYPE_ID_1 );
93 demand.setReference( DEMAND_REFERENCE_1 );
94 demand.setStatusId( EnumGenericStatus.ENCOURS.getStatusId( ) );
95
96 Customer customer = new Customer( );
97 customer.setId( CUSTOMER_ID_1 );
98 demand.setCustomer( customer );
99 demand.setCreationDate( DEMAND_CREATION_DATE_1 );
100 demand.setClosureDate( DEMAND_CLOSURE_DATE_1 );
101 demand.setMaxSteps( DEMAND_MAX_STEPS_1 );
102 demand.setCurrentStep( DEMAND_CURRENT_STEP_1 );
103
104 _demandDao.insert( demand );
105
106 Demand demandStored = _demandDao.load( demand.getId( ), demand.getTypeId( ) );
107 assertEquals( demandStored.getId( ), demand.getId( ) );
108 assertEquals( demandStored.getTypeId( ), demand.getTypeId( ) );
109 assertEquals( demandStored.getSubtypeId( ), demand.getSubtypeId( ) );
110 assertEquals( demandStored.getReference( ), demand.getReference( ) );
111 assertEquals( demandStored.getStatusId( ), demand.getStatusId( ) );
112 assertEquals( demandStored.getCustomer( ).getId( ), demand.getCustomer( ).getId( ) );
113 assertEquals( demandStored.getCreationDate( ), demand.getCreationDate( ) );
114 assertEquals( demandStored.getClosureDate( ), demand.getClosureDate( ) );
115 assertEquals( demandStored.getMaxSteps( ), demand.getMaxSteps( ) );
116 assertEquals( demandStored.getCurrentStep( ), demand.getCurrentStep( ) );
117
118
119 demand.setId( DEMAND_ID_2 );
120 demand.setTypeId( DEMAND_TYPE_ID_2 );
121 demand.setSubtypeId( DEMAND_SUBTYPE_ID_2 );
122 demand.setReference( DEMAND_REFERENCE_2 );
123 demand.setStatusId( EnumGenericStatus.TERMINE.getStatusId( ) );
124 customer = new Customer( );
125 customer.setId( CUSTOMER_ID_2 );
126 demand.setCustomer( customer );
127 demand.setCreationDate( DEMAND_CREATION_DATE_2 );
128 demand.setClosureDate( DEMAND_CLOSURE_DATE_2 );
129 demand.setMaxSteps( DEMAND_MAX_STEPS_2 );
130 demand.setCurrentStep( DEMAND_CURRENT_STEP_2 );
131
132 _demandDao.store( demand );
133
134 demandStored = _demandDao.load( demand.getId( ), demand.getTypeId( ) );
135 assertNull( demandStored );
136
137 demand.setId( DEMAND_ID_1 );
138 demand.setTypeId( DEMAND_TYPE_ID_1 );
139 demand.setSubtypeId( DEMAND_SUBTYPE_ID_1 );
140 _demandDao.store( demand );
141
142 demandStored = _demandDao.load( demand.getId( ), demand.getTypeId( ) );
143 assertEquals( demandStored.getId( ), demand.getId( ) );
144 assertEquals( demandStored.getTypeId( ), demand.getTypeId( ) );
145 assertEquals( demandStored.getSubtypeId( ), demand.getSubtypeId( ) );
146 assertNotSame( demandStored.getReference( ), demand.getReference( ) );
147 assertEquals( demandStored.getStatusId( ), demand.getStatusId( ) );
148 assertEquals( demandStored.getCustomer( ).getId( ), demand.getCustomer( ).getId( ) );
149 assertNotSame( demandStored.getCreationDate( ), demand.getCreationDate( ) );
150 assertEquals( demandStored.getClosureDate( ), demand.getClosureDate( ) );
151 assertNotSame( demandStored.getMaxSteps( ), demand.getMaxSteps( ) );
152 assertEquals( demandStored.getCurrentStep( ), demand.getCurrentStep( ) );
153
154
155 Collection<Demand> collectionDemands = _demandDao.loadByCustomerId( CUSTOMER_ID_1 );
156 assertEquals( collectionDemands.size( ), 1 );
157
158 Iterator<Demand> iteratorDemand = collectionDemands.iterator( );
159 demandStored = iteratorDemand.next( );
160 assertEquals( demandStored.getId( ), DEMAND_ID_1 );
161 assertEquals( demandStored.getTypeId( ), DEMAND_TYPE_ID_1 );
162 assertEquals( demandStored.getSubtypeId( ), DEMAND_SUBTYPE_ID_1 );
163
164
165 Collection<Demand> collectionDemands2 = _demandDao.loadByReference( DEMAND_REFERENCE_1 );
166 assertEquals( collectionDemands2.size( ), 1 );
167
168 Iterator<Demand> iteratorDemand2 = collectionDemands2.iterator( );
169 demandStored = iteratorDemand2.next( );
170 assertEquals( demandStored.getId( ), DEMAND_ID_1 );
171 assertEquals( demandStored.getTypeId( ), DEMAND_TYPE_ID_1 );
172 assertEquals( demandStored.getSubtypeId( ), DEMAND_SUBTYPE_ID_1 );
173
174
175 _demandDao.delete( DEMAND_ID_1, DEMAND_TYPE_ID_1 );
176 demandStored = _demandDao.load( DEMAND_ID_1, DEMAND_TYPE_ID_1 );
177 assertEquals( demandStored, nullValue( ) );
178 }
179 }