1
|
package test;
|
2
|
|
3
|
import static org.junit.Assert.assertArrayEquals;
|
4
|
import static org.junit.Assert.assertEquals;
|
5
|
import static org.junit.Assert.assertTrue;
|
6
|
|
7
|
import java.time.DayOfWeek;
|
8
|
import java.time.LocalDate;
|
9
|
import java.util.ArrayList;
|
10
|
import java.util.Arrays;
|
11
|
import java.util.Calendar;
|
12
|
import java.util.Date;
|
13
|
|
14
|
import org.apache.log4j.BasicConfigurator;
|
15
|
import org.apache.log4j.Level;
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.junit.Before;
|
18
|
import org.junit.BeforeClass;
|
19
|
import org.junit.Test;
|
20
|
|
21
|
import data.Bitmap;
|
22
|
import data.DataReader;
|
23
|
|
24
|
public class testBitmap {
|
25
|
private static final Logger log = Logger.getLogger(testJDFCaskodyRecord.class);
|
26
|
private static Bitmap bitmap;
|
27
|
private static LocalDate dateFrom;
|
28
|
private static LocalDate dateTo;
|
29
|
private char[] hardCodesChar;
|
30
|
|
31
|
@BeforeClass
|
32
|
public static void setUpBeforeClass() {
|
33
|
|
34
|
BasicConfigurator.configure();
|
35
|
Logger.getRootLogger().setLevel(Level.INFO);
|
36
|
|
37
|
|
38
|
|
39
|
}
|
40
|
|
41
|
@Before
|
42
|
public void setUpBefore() {
|
43
|
|
44
|
dateFrom = LocalDate.of(2019, 5, 1);
|
45
|
dateTo = LocalDate.of(2019, 5, 31);
|
46
|
|
47
|
|
48
|
|
49
|
bitmap = new Bitmap(dateFrom, dateTo, "143440","1","34", "5", "1");
|
50
|
hardCodesChar = bitmap.getHardCodes().toCharArray();
|
51
|
|
52
|
}
|
53
|
|
54
|
|
55
|
@Test
|
56
|
public void testgetDateRange(){
|
57
|
assertEquals(31,bitmap.getDateRange());
|
58
|
}
|
59
|
|
60
|
@Test
|
61
|
public void testsetDay() {
|
62
|
LocalDate date = LocalDate.of(2019, 5, 3);
|
63
|
bitmap.setDay(date, 1);
|
64
|
date = LocalDate.of(2019, 5, 4);
|
65
|
bitmap.setDay(date, 1);
|
66
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
67
|
}
|
68
|
|
69
|
@Test
|
70
|
public void testgetDatePosition() {
|
71
|
LocalDate date = LocalDate.of(2019, 5, 3);
|
72
|
long position = bitmap.getDatePosition(date);
|
73
|
assertEquals(2,position);
|
74
|
|
75
|
}
|
76
|
|
77
|
@Test
|
78
|
public void testsetWorkdays() {
|
79
|
bitmap.setWorkdays(1);
|
80
|
// Přidáný svátky
|
81
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1]"));
|
82
|
}
|
83
|
|
84
|
@Test
|
85
|
public void testsetWorkdaysInRange(){
|
86
|
bitmap.setWorkdaysInRange(LocalDate.of(2019, 5, 1), LocalDate.of(2019, 5, 15), 1);
|
87
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
88
|
}
|
89
|
|
90
|
@Test
|
91
|
public void testsetSundaysAndHolidays() {
|
92
|
bitmap.setSundaysAndHolidays(1);
|
93
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1]"));
|
94
|
}
|
95
|
|
96
|
@Test
|
97
|
public void testsetSundaysAndHolidays2() {
|
98
|
bitmap.setSundaysAndHolidays(LocalDate.of(2019, 5, 1), LocalDate.of(2019, 5, 15),1);
|
99
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
100
|
}
|
101
|
|
102
|
|
103
|
@Test
|
104
|
public void testsetOneDayOnly() {
|
105
|
LocalDate date = LocalDate.of(2019, 5, 3);
|
106
|
bitmap.setOneDayOnly(date);
|
107
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
108
|
|
109
|
}
|
110
|
|
111
|
@Test
|
112
|
public void testsetDaysInRange() {
|
113
|
LocalDate date1 = LocalDate.of(2019, 5, 3);
|
114
|
LocalDate date2 = LocalDate.of(2019,5,5);
|
115
|
bitmap.setDaysInRange(date1,date2, 1);
|
116
|
// Opravdu chyba (poslední den včetně) - Opraveno
|
117
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
118
|
}
|
119
|
|
120
|
@Test
|
121
|
public void unsetDaysInRange() {
|
122
|
bitmap.setWorkdays(1);
|
123
|
bitmap.unsetDaysInRange(LocalDate.of(2019, 5, 1), LocalDate.of(2019, 5, 15));
|
124
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1]"));
|
125
|
}
|
126
|
|
127
|
@Test
|
128
|
public void testsetDaysInWeek(){
|
129
|
bitmap.setDaysInWeek(DayOfWeek.MONDAY, 1); //kazde pondeli ... pondeli - 2
|
130
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]"));
|
131
|
|
132
|
}
|
133
|
|
134
|
@Test
|
135
|
public void testsetDaysInWeek2(){
|
136
|
bitmap.setDaysInWeek(LocalDate.of(2019, 5, 1), LocalDate.of(2019, 5, 15),DayOfWeek.MONDAY, 1); //kazde pondeli ... pondeli - 2
|
137
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
138
|
}
|
139
|
|
140
|
@Test
|
141
|
public void testsetWeeks(){
|
142
|
bitmap.setWeeks(1, 1);
|
143
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]"));
|
144
|
|
145
|
}
|
146
|
|
147
|
@Test
|
148
|
public void testsetWeeksInRange(){
|
149
|
LocalDate date1 = LocalDate.of(2019, 5, 1);
|
150
|
LocalDate date2 = LocalDate.of(2019, 5, 13);
|
151
|
bitmap.setWeeksInRange(date1,date2, 1, 1);
|
152
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
153
|
|
154
|
}
|
155
|
|
156
|
@Test
|
157
|
public void setHolidays() {
|
158
|
bitmap.setHolidays(1);
|
159
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
160
|
}
|
161
|
|
162
|
@Test
|
163
|
public void setHardCodeDays() {
|
164
|
bitmap.setHardCodeDays(LocalDate.of(2019, 5, 1), LocalDate.of(2019, 5, 15), 1);
|
165
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
166
|
|
167
|
}
|
168
|
|
169
|
|
170
|
@Test
|
171
|
public void setHardCodeWeeks() {
|
172
|
bitmap.setHardCodeWeeks(1,1);
|
173
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0]"));
|
174
|
|
175
|
}
|
176
|
|
177
|
|
178
|
@Test
|
179
|
public void setHardCodeWeeksInRange() {
|
180
|
bitmap.setHardCodeWeeksInRange(LocalDate.of(2019, 5, 1), LocalDate.of(2019, 5, 15),1,1);
|
181
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
182
|
|
183
|
}
|
184
|
|
185
|
@Test
|
186
|
public void testisHardCodeDay(){
|
187
|
assertTrue(bitmap.isHardCodeDay(LocalDate.of(2019, 5, 10), hardCodesChar[0]));
|
188
|
}
|
189
|
|
190
|
@Test
|
191
|
public void isBankHoliday() {
|
192
|
assertTrue(bitmap.isBankHoliday(LocalDate.of(2019, 5, 1)));
|
193
|
}
|
194
|
|
195
|
/* @Test
|
196
|
public void getEasterHolidays() {
|
197
|
bitmap.getEasterHolidays(2019);
|
198
|
bitmap.;
|
199
|
} */
|
200
|
|
201
|
@Test
|
202
|
public void getBitmapString() {
|
203
|
bitmap.setWorkdays(1);
|
204
|
assertEquals(0,bitmap.getBitmapString().compareToIgnoreCase("0110011011001111100111110011111"));
|
205
|
}
|
206
|
|
207
|
@Test
|
208
|
public void testfillWithZeros(){
|
209
|
bitmap.fillWithZeros();
|
210
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
211
|
|
212
|
}
|
213
|
|
214
|
@Test
|
215
|
public void testvalidateValue(){
|
216
|
int value = -1;
|
217
|
int exceptedZero = Bitmap.validateValue(value);
|
218
|
assertEquals(0,exceptedZero);
|
219
|
value = 0;
|
220
|
exceptedZero = Bitmap.validateValue(value);
|
221
|
assertEquals(0,exceptedZero);
|
222
|
value = 1;
|
223
|
int exceptedOne = Bitmap.validateValue(value);
|
224
|
assertEquals(1,exceptedOne);
|
225
|
value = 2;
|
226
|
exceptedOne = Bitmap.validateValue(value);
|
227
|
assertEquals(1,exceptedOne);
|
228
|
}
|
229
|
|
230
|
|
231
|
@Test
|
232
|
public void testgetDateFrom(){
|
233
|
assertEquals(0,bitmap.getDateFrom().toString().compareToIgnoreCase("2019-05-01"));
|
234
|
}
|
235
|
|
236
|
@Test
|
237
|
public void testsetDateFrom(){
|
238
|
dateFrom = LocalDate.of(2019, 5, 2);
|
239
|
bitmap.setDateFrom(dateFrom);
|
240
|
assertEquals(0,bitmap.getDateFrom().toString().compareToIgnoreCase("2019-05-02"));
|
241
|
}
|
242
|
|
243
|
@Test
|
244
|
public void testgetDateTo() {
|
245
|
assertEquals(0,bitmap.getDateTo().toString().compareToIgnoreCase("2019-05-31"));
|
246
|
}
|
247
|
|
248
|
@Test
|
249
|
public void testsetDateTo() {
|
250
|
dateTo = LocalDate.of(2019, 5, 30);
|
251
|
bitmap.setDateTo(dateTo);
|
252
|
assertEquals(0,bitmap.getDateTo().toString().compareToIgnoreCase("2019-05-30"));
|
253
|
}
|
254
|
|
255
|
@Test
|
256
|
public void testgetLineNumber() {
|
257
|
assertEquals(0,bitmap.getLineNumber().compareToIgnoreCase("143440"));
|
258
|
}
|
259
|
|
260
|
@Test
|
261
|
public void testsetLineNumber() {
|
262
|
bitmap.setLineNumber("143441");
|
263
|
assertEquals(0,bitmap.getLineNumber().compareToIgnoreCase("143441"));
|
264
|
}
|
265
|
|
266
|
@Test
|
267
|
public void testgetBitmap() {
|
268
|
int[] array = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
269
|
assertArrayEquals(array, bitmap.getBitmap());
|
270
|
}
|
271
|
|
272
|
@Test
|
273
|
public void testsetBitmap() {
|
274
|
int[] array = new int[] {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
275
|
int[] newBitmap = new int[] {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
276
|
bitmap.setBitmap(newBitmap);
|
277
|
assertArrayEquals(array, bitmap.getBitmap());
|
278
|
this.bitmap = bitmap;
|
279
|
}
|
280
|
|
281
|
@Test
|
282
|
public void testtoString() {
|
283
|
assertEquals(0,bitmap.bitmapToString().compareToIgnoreCase("[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
284
|
}
|
285
|
|
286
|
|
287
|
}
|