-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAppTest.java
More file actions
242 lines (213 loc) · 8.66 KB
/
AppTest.java
File metadata and controls
242 lines (213 loc) · 8.66 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import collections.Pair;
import com.google.gson.JsonObject;
import context.ContextStore;
import enums.ZoneIds;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import utils.*;
import utils.arrays.ArrayUtilities;
import utils.email.EmailUtilities;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.regex.Pattern;
import static utils.arrays.ArrayUtilities.*;
import static utils.email.EmailUtilities.Inbox.EmailField.*;
import static utils.StringUtilities.contextCheck;
public class AppTest {
static Printer printer = new Printer(AppTest.class);
@Before
public void before(){
ContextStore.loadProperties("test.properties", "secret.properties");
}
@Test
public void getRandomItemTest() {
List<Integer> numList = List.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
int randomNumber = ArrayUtilities.getRandomItemFrom(numList);
Assert.assertTrue(String.format("Random number %d is not part of the list!", randomNumber), numList.contains(randomNumber));
printer.success("getRandomItemTest successful!");
}
@Test
public void localisationCapabilityTest() {
JsonObject localisationJson = FileUtilities.Json.parseJsonFile("src/test/resources/localisation.json");
ContextStore.put("localisation-json", localisationJson);
ContextStore.put("localised-elements", true);
assert localisationJson != null;
for (String key : localisationJson.keySet()) {
Assert.assertEquals(
"Translation does not match the expected value!",
localisationJson.get(key).getAsString(),
contextCheck(key)
);
}
printer.success("The localisationCapabilityTest() test passed!");
}
@Test
public void getPDFFileTextTest() throws IOException {
URL url = new URL("https://sandbox.mabl.com/downloads/mabl_dash.pdf");
String fileDestinationPath = "src/test/resources/filePDF.pdf";
String pdfText = FileUtilities.getPDFFileText(url, fileDestinationPath);
assert pdfText != null;
Assert.assertTrue(
"PDF text does not contain the expected value!",
pdfText.contains("Run Settings")
);
printer.success("The getPDFFileTextTest() test passed!" + pdfText);
}
@Test
public void getSimpleDateStringFromTest() {
String offsetDateTimeString = "2024-01-25T14:00:00+01:00";
String dateFormat = "yyyy-MM-dd";
String simpleDateFormatString = DateUtilities.getSimpleDateStringFrom(offsetDateTimeString, dateFormat);
Assert.assertEquals(
"Date string does not match the expected value!",
"2024-01-25",
simpleDateFormatString
);
printer.success("The getSimpleDateFormatStringFromTest() test passed!");
}
@Test
public void getCurrentDateTest() {
String simpleDateFormatString = DateUtilities.getCurrentDate(ZoneIds.EUROPE_PARIS);
Assert.assertTrue(
"Date string does not match!",
Pattern.matches("(20)\\d{2}-(0[1-9]|1[1,2])-(0[1-9]|[12][0-9]|3[01])", simpleDateFormatString)
);
printer.success("The getSimpleDateFormatStringFromTest() test passed!");
}
@Test
public void cleanEmailTest() {
EmailUtilities.Inbox inbox = new EmailUtilities.Inbox("imap.gmail.com",
"993",
ContextStore.get("test-email"),
ContextStore.get("test-email-application-password"),
"ssl",
EmailUtilities.Inbox.EmailProtocol.IMAP
);
inbox.clearInbox();
String emailTestContent = "username:xyz";
String emailSubject = "Test subject of email for deletion";
EmailUtilities emailUtilities = new EmailUtilities(ContextStore.get("host"));
emailUtilities.sendEmail(
emailSubject,
emailTestContent,
ContextStore.get("test-email"),
ContextStore.get("sender-test-email"),
ContextStore.get("test-email-master-password"),
null);
inbox.load(
60,
1,
false,
false,
false,
List.of(Pair.of(SUBJECT, emailSubject))
);
Assert.assertEquals("Unexpected number of emails found!", 1, inbox.getMessages().size());
inbox.clearInbox();
EmailUtilities.Inbox newInbox = new EmailUtilities.Inbox("pop.gmail.com",
"995",
ContextStore.get("test-email"),
ContextStore.get("test-email-application-password"),
"ssl"
);
newInbox.load(SUBJECT, emailSubject, false, true, true);
Assert.assertEquals("Unexpected number of emails found!", 0, newInbox.getMessages().size());
printer.success("cleanEmailTest() is successful!");
}
@Test
public void filterEmailTest() {
EmailUtilities.Inbox inbox = new EmailUtilities.Inbox("imap.gmail.com",
"993",
ContextStore.get("test-email"),
ContextStore.get("test-email-application-password"),
"ssl",
EmailUtilities.Inbox.EmailProtocol.IMAP
);
inbox.clearInbox();
String emailTestContent = "username:xyz";
EmailUtilities emailUtilities = new EmailUtilities(ContextStore.get("host"));
emailUtilities.sendEmail(
"Test filter banana",
emailTestContent,
ContextStore.get("test-email"),
ContextStore.get("sender-test-email"),
ContextStore.get("test-email-master-password"),
null
);
emailUtilities.sendEmail(
"Test filter apple",
emailTestContent,
ContextStore.get("test-email"),
ContextStore.get("sender-test-email"),
ContextStore.get("test-email-master-password"),
null
);
emailUtilities.sendEmail(
"Test filter orange",
"test",
ContextStore.get("test-email"),
ContextStore.get("sender-test-email"),
ContextStore.get("test-email-master-password"),
null
);
inbox.load(
60,
2,
true,
true,
false,
List.of(Pair.of(SUBJECT, "Test filter"), Pair.of(CONTENT, emailTestContent))
);
Assert.assertEquals("Unexpected number of emails found!", 2, inbox.getMessages().size());
Assert.assertTrue("Unexpected content!", inbox.getMessageBy(SUBJECT, "Test filter banana").getContent().contains(emailTestContent));
Assert.assertTrue("Unexpected content!", inbox.getMessageBy(SUBJECT, "Test filter apple").getContent().contains(emailTestContent));
printer.success("Sending and receiving emails tests are successful!");
}
@Test
public void lastItemOfTest() {
List<Integer> integers = List.of(1, 2, 3, 4, 5);
Assert.assertTrue("Integer was not the last member!", isLastMemberOf(integers, 5));
printer.success("The lastItemOfTest() test pass!");
}
@Test
public void partitionTest() {
List<Integer> integers = List.of(1, 2, 3, 4, 5);
List<List<Integer>> partitionLists = List.of(
List.of(1,2),
List.of(3,4),
List.of(5)
);
for (int i = 0; i < getPartitionCount(integers.size(), 2); i++) {
List<Integer> partition = getListPartition(integers, 2, i);
Assert.assertEquals(
"getListPartition() returned an unexpected partition!",
partition,
partitionLists.get(i)
);
}
printer.success("The partitionTest() test pass!");
}
@Test
public void partitionCountTest() {
List<Integer> integers = List.of(1, 2, 3, 4, 5);
Assert.assertEquals(
"The getPartitionCount() method returns an incorrect value!",
3,
getPartitionCount(integers.size(), 2)
);
printer.success("The partitionCountTest() test pass!");
}
@Test
public void dateFormatTest() {
String date = "2025-6-20";
String expectedDate = "2025-06-20";
Assert.assertEquals(
"Fixed date format did not match the expected one!",
expectedDate,
DateUtilities.reformatDateString(date, "yyyy-MM-dd")
);
printer.success("The dateFormatTest() test pass!");
}
}