public void testSearch() throws Throwable {
String username = "admin";
Date today = new Date();
Date yesterday = new Date(today.getTime()-86400000);
Date tomorrow = new Date(today.getTime()+86400000);
Message message1 = this._helper.createMessage(null, "mainEditor", "it", today, "MyName", "MySurname", "MyAddress", "MyEmail1@aaaaaaaaaaaa.ittt", "MyNotes");
this._helper.addMessage(message1);
Message message2 = this._helper.createMessage(null, "admin", "it", yesterday, "MyCompany2", "MyAddress2", "MyEmail2@aaaaaaaaaaaa.ittt", "MyNotes");
this._helper.addMessage(message2);
Message message3 = this._helper.createMessage(null, "mainEditor", "it", today, "MyCompany3", "MyAddress3", "MyEmail3@aaaaaaaaaaaa.ittt", "MyNotes");
this._helper.addMessage(message3);
Message message4 = this._helper.createMessage(null, null, "it", tomorrow, "MyCompany4", "MyAddress4", "MyEmail4@aaaaaaaaaaaa.ittt", "MyNotes");
this._helper.addMessage(message4);
Answer answer = this._helper.createAnswer("1", message4.getId(), "mainEditor", new Date(), "text1");
this._helper.addAnswer(answer);
Map<String, String> params = new HashMap<String, String>();
params.put("entityTypeCode", "PER");
String result = this.executeSearch(username, params);
assertEquals(Action.SUCCESS, result);
List<String> messageIds = ((IApsEntityFinderAction) this.getAction()).getSearchResult();
this.checkMessageIds(messageIds, new String[] { message1.getId() });
params.put("entityTypeCode", "COM");
result = this.executeSearch(username, params);
assertEquals(Action.SUCCESS, result);
messageIds = ((IApsEntityFinderAction) this.getAction()).getSearchResult();
this.checkMessageIds(messageIds, new String[] { message2.getId(), message3.getId(), message4.getId() });
params.put("from", DateConverter.getFormattedDate(today, "dd/MM/yyyy"));
result = this.executeSearch(username, params);
assertEquals(Action.SUCCESS, result);
messageIds = ((IApsEntityFinderAction) this.getAction()).getSearchResult();
this.checkMessageIds(messageIds, new String[] { message3.getId(), message4.getId() });
params.put("to", DateConverter.getFormattedDate(yesterday, "dd/MM/yyyy"));
result = this.executeSearch(username, params);
assertEquals(Action.SUCCESS, result);
messageIds = ((IApsEntityFinderAction) this.getAction()).getSearchResult();
this.checkMessageIds(messageIds, new String[] { });
params.put("from", DateConverter.getFormattedDate(yesterday, "dd/MM/yyyy"));
params.put("to", DateConverter.getFormattedDate(today, "dd/MM/yyyy"));
result = this.executeSearch(username, params);
assertEquals(Action.SUCCESS, result);
messageIds = ((IApsEntityFinderAction) this.getAction()).getSearchResult();
this.checkMessageIds(messageIds, new String[] { message2.getId(), message3.getId() });
params.put("to", DateConverter.getFormattedDate(tomorrow, "dd/MM/yyyy"));
result = this.executeSearch(username, params);
assertEquals(Action.SUCCESS, result);
messageIds = ((IApsEntityFinderAction) this.getAction()).getSearchResult();
this.checkMessageIds(messageIds, new String[] { message2.getId(), message3.getId(), message4.getId() });
params.put("answered", "1");
result = this.executeSearch(username, params);
assertEquals(Action.SUCCESS, result);
messageIds = ((IApsEntityFinderAction) this.getAction()).getSearchResult();
this.checkMessageIds(messageIds, new String[] { message4.getId() });
params.put("answered", "0");
result = this.executeSearch(username, params);
assertEquals(Action.SUCCESS, result);
messageIds = ((IApsEntityFinderAction) this.getAction()).getSearchResult();