Skip to content

Commit 2413475

Browse files
committed
logicaldoc-core tests updated in document and folder
1 parent 4a80719 commit 2413475

26 files changed

+1377
-171
lines changed

logicaldoc-core/src/main/java/com/logicaldoc/core/document/DigestProcessor.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public DigestProcessor() {
3636
log = LoggerFactory.getLogger(DigestProcessor.class);
3737
}
3838

39-
4039
@Override
4140
public boolean isIndeterminate() {
4241
return false;
@@ -57,15 +56,9 @@ protected void runTask() throws TaskException {
5756
size = documentDao.queryForLong(
5857
"select count(*) from ld_document where ld_deleted = 0 and ld_docref is null and ld_digest is null");
5958

60-
Integer max = config.getProperty("digest.batch") != null
61-
? Integer.parseInt(config.getProperty("digest.batch"))
62-
: null;
63-
64-
if (max != null && max.intValue() < size && max.intValue() > 0)
65-
size = max.intValue();
66-
67-
if (max != null && max.intValue() < 1)
68-
max = null;
59+
int max = config.getInt("digest.batch", (int) size);
60+
if (max < size && max > 0)
61+
size = max;
6962

7063
log.info("Found a total of {} documents to process", size);
7164

logicaldoc-core/src/main/java/com/logicaldoc/core/document/DocumentComparator.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -351,16 +351,4 @@ public static Comparator<AbstractDocument> getComparator(List<DocumentComparator
351351
return 0;
352352
};
353353
}
354-
355-
public static Comparator<AbstractDocument> getComparator(final DocumentComparator... multipleOptions) {
356-
return (d1, d2) -> {
357-
for (DocumentComparator option : multipleOptions) {
358-
int result = option.compare(d1, d2);
359-
if (result != 0) {
360-
return result;
361-
}
362-
}
363-
return 0;
364-
};
365-
}
366354
}

logicaldoc-core/src/main/java/com/logicaldoc/core/document/HibernateBookmarkDAO.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,14 @@ public List<Bookmark> findByUserId(long userId) throws PersistenceException {
3131

3232
@Override
3333
public Bookmark findByUserIdAndDocId(long userId, long docId) throws PersistenceException {
34-
List<Bookmark> list = findByWhere(ENTITY + USER_ID + userId + AND + ENTITY + ".targetId =" + docId + AND
35-
+ ENTITY + ".type=" + Bookmark.TYPE_DOCUMENT, null, null);
36-
37-
if (list.isEmpty())
38-
return null;
39-
else
40-
return list.get(0);
34+
return findByWhere(ENTITY + USER_ID + userId + AND + ENTITY + ".targetId =" + docId + AND
35+
+ ENTITY + ".type=" + Bookmark.TYPE_DOCUMENT, null, null).stream().findFirst().orElse(null);
4136
}
4237

4338
@Override
4439
public Bookmark findByUserIdAndFolderId(long userId, long folderId) throws PersistenceException {
45-
List<Bookmark> list = findByWhere(ENTITY + USER_ID + userId + AND + ENTITY + ".targetId =" + folderId + AND
46-
+ ENTITY + ".type=" + Bookmark.TYPE_FOLDER, null, null);
47-
48-
if (list.isEmpty())
49-
return null;
50-
else
51-
return list.get(0);
40+
return findByWhere(ENTITY + USER_ID + userId + AND + ENTITY + ".targetId =" + folderId + AND
41+
+ ENTITY + ".type=" + Bookmark.TYPE_FOLDER, null, null).stream().findFirst().orElse(null);
5242
}
5343

5444
@Override

logicaldoc-core/src/main/java/com/logicaldoc/core/document/HibernateVersionDAO.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,6 @@ public void updateDigest(Version version) {
169169
}
170170
}
171171

172-
public void setStore(Store store) {
173-
this.store = store;
174-
}
175-
176172
@Override
177173
public void delete(long versionId, int delCode) throws PersistenceException {
178174
if (!checkStoringAspect())
@@ -191,8 +187,4 @@ protected void deleteVersion(Version versionToDelete, int delCode) {
191187
versionToDelete.setVersion(StringUtils.right(versionToDelete.getId() + "." + versionToDelete.getVersion(), 10));
192188
saveOrUpdate(versionToDelete);
193189
}
194-
195-
public void setFolderDAO(FolderDAO folderDAO) {
196-
this.folderDAO = folderDAO;
197-
}
198190
}

logicaldoc-core/src/test/java/com/logicaldoc/core/AbstractCoreTestCase.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ private void prepareStore() throws IOException {
7272

7373
// Store the file of document 3
7474
FileUtil.copyResource("/small.pdf", new File(rootStoreOne.getPath() + "/3/doc/1.3"));
75+
76+
// Store the file of document 8
77+
FileUtil.copyResource("/small.pdf", new File(rootStoreOne.getPath() + "/8/doc/1.0"));
7578
}
7679

7780
@Override
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.logicaldoc.core.document;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertNotNull;
6+
import static org.junit.Assert.assertTrue;
7+
8+
import java.io.IOException;
9+
import java.sql.SQLException;
10+
import java.util.Locale;
11+
12+
import org.junit.Before;
13+
import org.junit.Test;
14+
15+
import com.logicaldoc.core.AbstractCoreTestCase;
16+
import com.logicaldoc.core.task.TaskException;
17+
import com.logicaldoc.util.Context;
18+
import com.logicaldoc.util.plugin.PluginException;
19+
20+
/**
21+
* Test case for <code>DigestProcess</code>
22+
*
23+
* @author Giuseppe Desiato - LogicalDOC
24+
* @since 9.1.1
25+
*/
26+
public class DigestProcessorTest extends AbstractCoreTestCase {
27+
28+
private DigestProcessor testSubject;
29+
30+
@Before
31+
public void setUp() throws IOException, SQLException, PluginException {
32+
super.setUp();
33+
34+
testSubject = Context.get(DigestProcessor.class);
35+
}
36+
37+
@Test
38+
public void testRunTask() throws TaskException {
39+
testSubject.runTask();
40+
41+
Context.get().getProperties().setProperty("digest.batch", "10");
42+
assertEquals("10", Context.get().getProperties().getProperty("digest.batch"));
43+
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"));
49+
50+
assertFalse(testSubject.isIndeterminate());
51+
assertTrue(testSubject.isConcurrent());
52+
}
53+
54+
@Test
55+
public void testPrepareReport() {
56+
assertNotNull(testSubject.prepareReport(Locale.ENGLISH));
57+
}
58+
}

0 commit comments

Comments
 (0)