Skip to content

Commit 152aa0e

Browse files
committed
Updated Tests in folder, document, dashlet and contact
1 parent 61fb988 commit 152aa0e

25 files changed

+610
-75
lines changed

logicaldoc-core/src/main/java/com/logicaldoc/core/dashlet/DashletContent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ private DateFormat getDateFormat() {
127127
private void handleDocumentEvent(boolean showSid, Locale locale, Dashlet dashlet,
128128
Map<String, Object> dashletDictionary, Automation automation, PrintWriter writer)
129129
throws PersistenceException, AutomationException {
130+
130131
if (StringUtils.isNotEmpty(dashlet.getContent())) {
131132
String content = automation.evaluate(dashlet.getContent(), dashletDictionary);
132133
if (StringUtils.isNotEmpty(content))
@@ -355,6 +356,7 @@ private void printField(String fieldName, Object value, PrintWriter writer) {
355356

356357
private void handleDocument(Locale locale, Dashlet dashlet, Map<String, Object> dashletDictionary,
357358
Automation automation, PrintWriter writer) throws PersistenceException, AutomationException {
359+
358360
if (StringUtils.isNotEmpty(dashlet.getContent())) {
359361
String content = automation.evaluate(dashlet.getContent(), dashletDictionary);
360362
if (StringUtils.isNotEmpty(content))

logicaldoc-core/src/main/java/com/logicaldoc/core/document/DuplicateDocumentExeption.java renamed to logicaldoc-core/src/main/java/com/logicaldoc/core/document/DuplicateDocumentException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @author Marco Meschieri - LogicalDOC
77
* @since 6.8
88
*/
9-
public class DuplicateDocumentExeption extends Exception {
9+
public class DuplicateDocumentException extends Exception {
1010

1111
private static final long serialVersionUID = 1L;
1212

@@ -16,12 +16,12 @@ public String getCustomId() {
1616
return customId;
1717
}
1818

19-
public DuplicateDocumentExeption(String customId, Throwable cause) {
19+
public DuplicateDocumentException(String customId, Throwable cause) {
2020
super("Duplicate Document. customid: " + customId, cause);
2121
this.customId = customId;
2222
}
2323

24-
public DuplicateDocumentExeption(String customId) {
24+
public DuplicateDocumentException(String customId) {
2525
this(customId, null);
2626
}
2727
}

logicaldoc-core/src/main/java/com/logicaldoc/core/i18n/Language.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import org.apache.commons.lang.StringUtils;
99
import org.apache.lucene.analysis.Analyzer;
10+
import org.apache.lucene.analysis.CharArraySet;
1011
import org.apache.lucene.analysis.core.SimpleAnalyzer;
1112
import org.slf4j.Logger;
1213
import org.slf4j.LoggerFactory;
@@ -97,9 +98,9 @@ private void initAnalyzer() {
9798
// Try to use constructor (Set<?> stopwords)
9899
if (aClass != null && stopWords != null && (!stopWords.isEmpty())) {
99100
try {
100-
Constructor<?> constructor = aClass.getConstructor(java.util.Set.class);
101+
Constructor<?> constructor = aClass.getConstructor(CharArraySet.class);
101102
if (constructor != null)
102-
analyzer = (Analyzer) constructor.newInstance(stopWords);
103+
analyzer = (Analyzer) constructor.newInstance(new CharArraySet(stopWords, false));
103104
} catch (Exception e) {
104105
log.debug("constructor (Version matchVersion, Set<?> stopwords) not found");
105106
}

logicaldoc-core/src/test/java/com/logicaldoc/core/contact/HibernateContactDAOTest.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.logicaldoc.core.contact;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertNotSame;
46

57
import java.io.IOException;
68
import java.sql.SQLException;
@@ -11,6 +13,7 @@
1113

1214
import com.logicaldoc.core.AbstractCoreTestCase;
1315
import com.logicaldoc.core.PersistenceException;
16+
import com.logicaldoc.util.Context;
1417
import com.logicaldoc.util.plugin.PluginException;
1518

1619
/**
@@ -29,7 +32,7 @@ public void setUp() throws IOException, SQLException, PluginException {
2932
super.setUp();
3033
// Retrieve the instance under test from spring context. Make sure that
3134
// it is an HibernateContactDAO
32-
dao = (ContactDAO) context.getBean("ContactDAO");
35+
dao = Context.get(ContactDAO.class);
3336
}
3437

3538
@Test
@@ -42,5 +45,36 @@ public void testFindByUser() throws PersistenceException {
4245
assertEquals(1, contacts.size());
4346
contacts = dao.findByUser(1L, "xxx");
4447
assertEquals(0, contacts.size());
48+
49+
Contact contact1 = dao.findById(1L);
50+
assertNotNull(contact1);
51+
52+
Contact contact2 = new Contact(contact1);
53+
assertNotNull(contact2);
54+
assertNotSame(null, contact2.getFullName());
55+
assertNotSame(null, contact2.toString());
56+
57+
assertNotSame(contact1.hashCode(), contact2.hashCode());
58+
59+
// test equals()
60+
assertEquals(true, contact1.equals(contact1));
61+
assertEquals(false, contact1.equals(contact2));
62+
63+
Contact contact3 = new Contact();
64+
contact3.setId(contact1.getId());
65+
assertEquals(false, contact1.equals(contact3));
66+
67+
assertEquals(false, contact3.equals(contact1));
68+
69+
contact1.setEmail("[email protected]");
70+
contact1.setId(2);
71+
contact2.setEmail("[email protected]");
72+
contact2.setId(2);
73+
contact2.setUserId(-5L);
74+
75+
assertEquals(false, contact1.equals(contact2));
76+
77+
contact1.setUserId(-3L);
78+
assertEquals(false, contact1.equals(contact2));
4579
}
4680
}

logicaldoc-core/src/test/java/com/logicaldoc/core/dashlet/DashletContentTest.java

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.logicaldoc.core.dashlet;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
45
import static org.junit.Assert.assertTrue;
56

67
import java.io.File;
78
import java.io.IOException;
89
import java.sql.SQLException;
910

11+
import javax.servlet.ServletException;
12+
1013
import org.junit.Before;
1114
import org.junit.Test;
1215
import org.springframework.security.core.context.SecurityContextHolder;
@@ -45,11 +48,15 @@ public class DashletContentTest extends AbstractCoreTestCase {
4548

4649
protected final File responseFile = new File("target/documents.xml");
4750

51+
private DashletDAO dao;
52+
4853
@Before
4954
public void setUp() throws IOException, SQLException, PluginException {
5055
super.setUp();
5156
FileUtil.delete(responseFile);
5257
prepareSession("admin", "admin");
58+
59+
dao = Context.get(DashletDAO.class);
5360
}
5461

5562
@Override
@@ -59,7 +66,7 @@ public void tearDown() throws SQLException {
5966
}
6067

6168
@Test
62-
public void testService() throws IOException {
69+
public void testService() throws IOException, PersistenceException {
6370
MockServletRequest mockRequest = new MockServletRequest(servletSession);
6471
mockRequest.setParameter("locale", "en");
6572
mockRequest.setParameter("dashletId", "21");
@@ -76,13 +83,23 @@ public void testService() throws IOException {
7683
response.flushBuffer();
7784
assertTrue(FileUtil.readFile(responseFile).contains("<id>1</id>"));
7885

86+
// not null content
87+
FileUtil.delete(responseFile);
88+
mockRequest.setParameter("dashletId", "22");
89+
Dashlet dashlet = dao.findById(22);
90+
dashlet.setContent("This is some content");
91+
dao.store(dashlet);
92+
response = new MockServletResponse(responseFile);
93+
testSubject.service(mockRequest, response);
94+
response.flushBuffer();
95+
assertFalse(FileUtil.readFile(responseFile).contains("<id>1</id>"));
96+
7997
FileUtil.delete(responseFile);
8098
mockRequest.setParameter("dashletId", "23");
8199
response = new MockServletResponse(responseFile);
82100
testSubject.service(mockRequest, response);
83101
response.flushBuffer();
84-
System.out.println(FileUtil.readFile(responseFile));
85-
assertEquals("sample content", FileUtil.readFile(responseFile).trim());
102+
assertEquals("sample content", FileUtil.readFile(responseFile).trim());
86103

87104
FileUtil.delete(responseFile);
88105
mockRequest.setParameter("dashletId", "6");
@@ -97,7 +114,35 @@ public void testService() throws IOException {
97114
testSubject.service(mockRequest, response);
98115
response.flushBuffer();
99116
assertEquals("", FileUtil.readFile(responseFile));
117+
118+
FileUtil.delete(responseFile);
119+
mockRequest.setParameter("dashletId", "9");
120+
response = new MockServletResponse(responseFile);
121+
dashlet = dao.findById(9);
122+
dashlet.setType(Dashlet.TYPE_DOCUMENT);
123+
dashlet.setContent("This is some content for dashledId 9");
124+
dao.store(dashlet);
125+
testSubject.service(mockRequest, response);
126+
response.flushBuffer();
127+
assertEquals("This is some content for dashledId 9", FileUtil.readFile(responseFile));
128+
129+
FileUtil.delete(responseFile);
130+
mockRequest.setParameter("dashletId", "9");
131+
response = new MockServletResponse(responseFile);
132+
dashlet = dao.findById(9);
133+
dashlet.setType(Dashlet.TYPE_NOTE);
134+
dashlet.setContent("This is some content for dashledId 9");
135+
dao.store(dashlet);
136+
testSubject.service(mockRequest, response);
137+
response.flushBuffer();
138+
assertEquals("This is some content for dashledId 9", FileUtil.readFile(responseFile));
139+
}
100140

141+
@Test
142+
public void testValidateSession() throws ServletException {
143+
session = null;
144+
MockServletRequest mockRequest = new MockServletRequest(servletSession);
145+
DashletContent.validateSession(mockRequest);
101146
}
102147

103148
protected void prepareSession(String username, String password) throws PersistenceException {

logicaldoc-core/src/test/java/com/logicaldoc/core/dashlet/HibernateDashletDAOTest.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@
22

33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertNotNull;
5+
import static org.junit.Assert.assertNotSame;
56
import static org.junit.Assert.assertNull;
67

78
import java.io.IOException;
89
import java.sql.SQLException;
10+
import java.util.List;
911

1012
import org.junit.Before;
1113
import org.junit.Test;
1214

1315
import com.logicaldoc.core.AbstractCoreTestCase;
1416
import com.logicaldoc.core.PersistenceException;
17+
import com.logicaldoc.core.security.Tenant;
18+
import com.logicaldoc.core.security.TenantDAO;
19+
import com.logicaldoc.util.Context;
1520
import com.logicaldoc.util.plugin.PluginException;
1621

1722
/**
18-
* Test case for <code>HibernateDashletDAO</code>
23+
* Test case for {@link HibernateDashletDAO}
1924
*
2025
* @author Marco Meschieri - LogicalDOC
2126
* @since 8.2.3
@@ -30,7 +35,7 @@ public void setUp() throws IOException, SQLException, PluginException {
3035
super.setUp();
3136
// Retrieve the instance under test from spring context. Make sure that
3237
// it is an HibernateDashletDAO
33-
testSubject = (DashletDAO) context.getBean("DashletDAO");
38+
testSubject = Context.get(DashletDAO.class);
3439
}
3540

3641
@Test
@@ -42,4 +47,44 @@ public void testFindByName() throws PersistenceException {
4247
dashlet = testSubject.findByName("xxxx", 1L);
4348
assertNull(dashlet);
4449
}
50+
51+
@Test
52+
public void testDelete() throws PersistenceException {
53+
Dashlet dashlet = retrieveDashlet().get(9);
54+
assertNotNull(dashlet);
55+
testSubject.delete(dashlet.getId(), 1);
56+
}
57+
58+
@Test
59+
public void testDashletHashCodeAndEquals() throws PersistenceException {
60+
Dashlet dashlet1 = retrieveDashlet().get(0);
61+
Dashlet dashlet2 = retrieveDashlet().get(1);
62+
63+
assertNotSame(dashlet1.hashCode(), dashlet2.hashCode());
64+
65+
assertEquals(dashlet1, dashlet1);
66+
assertEquals(false, dashlet1.equals(dashlet2));
67+
68+
assertEquals(false, dashlet1.equals(new Object()));
69+
70+
dashlet2.setId(dashlet1.getId());
71+
assertEquals(false, dashlet1.equals(dashlet2));
72+
73+
dashlet1.setName(null);
74+
assertEquals(false, dashlet1.equals(dashlet2));
75+
}
76+
77+
private List<Dashlet> retrieveDashlet() throws PersistenceException {
78+
TenantDAO tenantDao = Context.get(TenantDAO.class);
79+
Tenant tenant = tenantDao.findById(1L);
80+
assertNotNull(tenant);
81+
82+
List<Dashlet> dashlets = testSubject.findAll(Tenant.DEFAULT_ID);
83+
for (Dashlet dashlet : dashlets) {
84+
Dashlet newDashlet = new Dashlet(dashlet);
85+
assertNotNull(newDashlet);
86+
assertNotSame(null, newDashlet.toString());
87+
}
88+
return dashlets;
89+
}
4590
}

logicaldoc-core/src/test/java/com/logicaldoc/core/document/DigestProcessorTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import com.logicaldoc.util.plugin.PluginException;
1919

2020
/**
21-
* Test case for <code>DigestProcess</code>
21+
* Test case for {@link DigestProcess}
2222
*
2323
* @author Giuseppe Desiato - LogicalDOC
2424
* @since 9.1.1
@@ -40,12 +40,11 @@ public void testRunTask() throws TaskException {
4040

4141
Context.get().getProperties().setProperty("digest.batch", "10");
4242
assertEquals("10", Context.get().getProperties().getProperty("digest.batch"));
43+
testSubject.runTask();
4344

44-
Context.get().getProperties().setProperty("digest.batch", "2");
45-
assertEquals("2", Context.get().getProperties().getProperty("digest.batch"));
46-
47-
Context.get().getProperties().setProperty("digest.batch", "1000");
48-
assertEquals("1000", Context.get().getProperties().getProperty("digest.batch"));
45+
Context.get().getProperties().setProperty("digest.batch", "1");
46+
assertEquals("1", Context.get().getProperties().getProperty("digest.batch"));
47+
testSubject.runTask();
4948

5049
assertFalse(testSubject.isIndeterminate());
5150
assertTrue(testSubject.isConcurrent());

logicaldoc-core/src/test/java/com/logicaldoc/core/document/DocumentComparatorTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
import com.logicaldoc.util.Context;
2323
import com.logicaldoc.util.plugin.PluginException;
2424

25+
/**
26+
* Test Case for {@link DocumentComparator}
27+
*
28+
* @author Giuseppe Desiato - LogicalDOC
29+
* @since 9.1.1
30+
*/
2531
public class DocumentComparatorTest extends AbstractCoreTestCase {
2632

2733
// Instance under test

logicaldoc-core/src/test/java/com/logicaldoc/core/document/DocumentLinkTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import com.logicaldoc.util.plugin.PluginException;
1919

2020
/**
21-
* Test case for <code>DocumentLink</code>
21+
* Test case for {@link DocumentLink}
2222
*
2323
* @author Giuseppe Desiato - LogicalDOC
2424
* @since 9.1.1

logicaldoc-core/src/test/java/com/logicaldoc/core/document/DocumentListenerManagerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import com.logicaldoc.util.plugin.PluginException;
1515

1616
/**
17-
* Test case for <code>DocumentListenerManager</code>
17+
* Test case for {@link DocumentListenerManager}
1818
*
1919
* @author Giuseppe Desiato - LogicalDOC
2020
* @since 9.1.1

0 commit comments

Comments
 (0)