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.notificationstore.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.nullValue;
42
43 import java.util.Collection;
44 import java.util.Iterator;
45
46
47
48
49
50 public class DemandDAOTest extends LuteceTestCase
51 {
52 private static final String CUSTOMER_ID_1 = "CustomerId1";
53 private static final String CUSTOMER_ID_2 = "CustomerId1";
54 private static final String DEMAND_ID_1 = "DemandId1";
55 private static final String DEMAND_ID_2 = "DemandId2";
56 private static final String DEMAND_TYPE_ID_1 = "DemandTypeId1";
57 private static final String DEMAND_TYPE_ID_2 = "DemandTypeId2";
58 private static final String DEMAND_SUBTYPE_ID_1 = "DemandSubtypeId1";
59 private static final String DEMAND_SUBTYPE_ID_2 = "DemandSubtypeId2";
60 private static final String DEMAND_REFERENCE_1 = "DemandReference1";
61 private static final String DEMAND_REFERENCE_2 = "DemandReference2";
62 private static final long DEMAND_CREATION_DATE_1 = 1L;
63 private static final long DEMAND_CREATION_DATE_2 = 2L;
64 private static final long DEMAND_CLOSURE_DATE_1 = 1L;
65 private static final long DEMAND_CLOSURE_DATE_2 = 2L;
66 private static final int DEMAND_MAX_STEPS_1 = 1;
67 private static final int DEMAND_MAX_STEPS_2 = 2;
68 private static final int DEMAND_CURRENT_STEP_1 = 1;
69 private static final int DEMAND_CURRENT_STEP_2 = 2;
70 private final IDemandDAO _demandDao;
71
72
73
74
75 public DemandDAOTest( )
76 {
77 _demandDao = new DemandDAO( );
78 }
79
80
81
82
83 public void testBusiness( )
84 {
85
86 Demand demand = new Demand( );
87 demand.setId( DEMAND_ID_1 );
88 demand.setTypeId( DEMAND_TYPE_ID_1 );
89 demand.setSubtypeId( DEMAND_SUBTYPE_ID_1 );
90 demand.setReference( DEMAND_REFERENCE_1 );
91 demand.setStatusId( EnumGenericStatus.ONGOING.getStatusId( ) );
92
93 Customer customer = new Customer( );
94 customer.setCustomerId( CUSTOMER_ID_1 );
95 demand.setCustomer( customer );
96 demand.setCreationDate( DEMAND_CREATION_DATE_1 );
97 demand.setClosureDate( DEMAND_CLOSURE_DATE_1 );
98 demand.setMaxSteps( DEMAND_MAX_STEPS_1 );
99 demand.setCurrentStep( DEMAND_CURRENT_STEP_1 );
100
101 _demandDao.insert( demand );
102
103 Demand demandStored = _demandDao.loadByDemandIdAndTypeIdAndCustomerId( demand.getId( ), demand.getTypeId( ), demand.getCustomer( ).getCustomerId( ) );
104 assertEquals( demandStored.getId( ), demand.getId( ) );
105 assertEquals( demandStored.getTypeId( ), demand.getTypeId( ) );
106 assertEquals( demandStored.getSubtypeId( ), demand.getSubtypeId( ) );
107 assertEquals( demandStored.getReference( ), demand.getReference( ) );
108 assertEquals( demandStored.getStatusId( ), demand.getStatusId( ) );
109 assertEquals( demandStored.getCustomer( ).getCustomerId( ), demand.getCustomer( ).getCustomerId( ) );
110 assertEquals( demandStored.getCreationDate( ), demand.getCreationDate( ) );
111 assertEquals( demandStored.getClosureDate( ), demand.getClosureDate( ) );
112 assertEquals( demandStored.getMaxSteps( ), demand.getMaxSteps( ) );
113 assertEquals( demandStored.getCurrentStep( ), demand.getCurrentStep( ) );
114
115
116 demand.setId( DEMAND_ID_2 );
117 demand.setTypeId( DEMAND_TYPE_ID_2 );
118 demand.setSubtypeId( DEMAND_SUBTYPE_ID_2 );
119 demand.setReference( DEMAND_REFERENCE_2 );
120 demand.setStatusId( EnumGenericStatus.CLOSED.getStatusId( ) );
121 customer = new Customer( );
122 customer.setCustomerId( CUSTOMER_ID_2 );
123 demand.setCustomer( customer );
124 demand.setCreationDate( DEMAND_CREATION_DATE_2 );
125 demand.setClosureDate( DEMAND_CLOSURE_DATE_2 );
126 demand.setMaxSteps( DEMAND_MAX_STEPS_2 );
127 demand.setCurrentStep( DEMAND_CURRENT_STEP_2 );
128
129 _demandDao.store( demand );
130
131 demandStored = _demandDao.loadByDemandIdAndTypeIdAndCustomerId( demand.getId( ), demand.getTypeId( ), demand.getCustomer( ).getCustomerId( ) );
132 assertNull( demandStored );
133
134 demand.setId( DEMAND_ID_1 );
135 demand.setTypeId( DEMAND_TYPE_ID_1 );
136 demand.setSubtypeId( DEMAND_SUBTYPE_ID_1 );
137 _demandDao.store( demand );
138
139 demandStored = _demandDao.loadByDemandIdAndTypeIdAndCustomerId( demand.getId( ), demand.getTypeId( ), demand.getCustomer( ).getCustomerId( ) );
140 assertEquals( demandStored.getId( ), demand.getId( ) );
141 assertEquals( demandStored.getTypeId( ), demand.getTypeId( ) );
142 assertEquals( demandStored.getSubtypeId( ), demand.getSubtypeId( ) );
143 assertNotSame( demandStored.getReference( ), demand.getReference( ) );
144 assertEquals( demandStored.getStatusId( ), demand.getStatusId( ) );
145 assertEquals( demandStored.getCustomer( ).getCustomerId( ), demand.getCustomer( ).getCustomerId( ) );
146 assertNotSame( demandStored.getCreationDate( ), demand.getCreationDate( ) );
147 assertEquals( demandStored.getClosureDate( ), demand.getClosureDate( ) );
148 assertNotSame( demandStored.getMaxSteps( ), demand.getMaxSteps( ) );
149 assertEquals( demandStored.getCurrentStep( ), demand.getCurrentStep( ) );
150
151
152 Collection<Demand> collectionDemands = _demandDao.loadByCustomerId( CUSTOMER_ID_1 );
153 assertEquals( collectionDemands.size( ), 1 );
154
155 Iterator<Demand> iteratorDemand = collectionDemands.iterator( );
156 demandStored = iteratorDemand.next( );
157 assertEquals( demandStored.getId( ), DEMAND_ID_1 );
158 assertEquals( demandStored.getTypeId( ), DEMAND_TYPE_ID_1 );
159 assertEquals( demandStored.getSubtypeId( ), DEMAND_SUBTYPE_ID_1 );
160
161
162 Collection<Demand> collectionDemands2 = _demandDao.loadByReference( DEMAND_REFERENCE_1 );
163 assertEquals( collectionDemands2.size( ), 1 );
164
165 Iterator<Demand> iteratorDemand2 = collectionDemands2.iterator( );
166 demandStored = iteratorDemand2.next( );
167 assertEquals( demandStored.getId( ), DEMAND_ID_1 );
168 assertEquals( demandStored.getTypeId( ), DEMAND_TYPE_ID_1 );
169 assertEquals( demandStored.getSubtypeId( ), DEMAND_SUBTYPE_ID_1 );
170
171
172 _demandDao.delete( DEMAND_ID_1, DEMAND_TYPE_ID_1, CUSTOMER_ID_1 );
173 demandStored = _demandDao.loadByDemandIdAndTypeIdAndCustomerId( DEMAND_ID_1, DEMAND_TYPE_ID_1, CUSTOMER_ID_1 );
174 assertEquals( demandStored, nullValue( ) );
175 }
176 }