| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.search.solr.internal.job; |
| 21 |
|
|
| 22 |
|
import static org.junit.Assert.*; |
| 23 |
|
import static org.mockito.Mockito.*; |
| 24 |
|
|
| 25 |
|
import java.util.ArrayList; |
| 26 |
|
import java.util.Collections; |
| 27 |
|
import java.util.Iterator; |
| 28 |
|
import java.util.List; |
| 29 |
|
|
| 30 |
|
import org.apache.commons.lang3.tuple.ImmutablePair; |
| 31 |
|
import org.apache.commons.lang3.tuple.Pair; |
| 32 |
|
import org.junit.Test; |
| 33 |
|
import org.xwiki.model.reference.DocumentReference; |
| 34 |
|
import org.xwiki.model.reference.EntityReference; |
| 35 |
|
import org.xwiki.model.reference.WikiReference; |
| 36 |
|
import org.xwiki.search.solr.internal.job.DiffDocumentIterator.Action; |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
@link |
| 40 |
|
|
| 41 |
|
@version |
| 42 |
|
@since |
| 43 |
|
|
| |
|
| 95.2% |
Uncovered Elements: 3 (62) |
Complexity: 8 |
Complexity Density: 0.15 |
|
| 44 |
|
public class DiffDocumentIteratorTest |
| 45 |
|
{ |
| |
|
| 75% |
Uncovered Elements: 3 (12) |
Complexity: 6 |
Complexity Density: 1 |
|
| 46 |
|
public static class DocumentIteratorStub<T> implements DocumentIterator<T> |
| 47 |
|
{ |
| 48 |
|
private int size; |
| 49 |
|
|
| 50 |
|
private Iterator<Pair<DocumentReference, T>> iterator; |
| 51 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 52 |
4 |
public DocumentIteratorStub(List<Pair<DocumentReference, T>> list)... |
| 53 |
|
{ |
| 54 |
4 |
size = list.size(); |
| 55 |
4 |
iterator = list.iterator(); |
| 56 |
|
} |
| 57 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 58 |
27 |
@Override... |
| 59 |
|
public boolean hasNext() |
| 60 |
|
{ |
| 61 |
27 |
return iterator.hasNext(); |
| 62 |
|
} |
| 63 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 64 |
9 |
@Override... |
| 65 |
|
public Pair<DocumentReference, T> next() |
| 66 |
|
{ |
| 67 |
9 |
return iterator.next(); |
| 68 |
|
} |
| 69 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 70 |
0 |
@Override... |
| 71 |
|
public void remove() |
| 72 |
|
{ |
| 73 |
0 |
iterator.remove(); |
| 74 |
|
} |
| 75 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 76 |
0 |
@Override... |
| 77 |
|
public void setRootReference(EntityReference rootReference) |
| 78 |
|
{ |
| 79 |
|
} |
| 80 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 81 |
2 |
@Override... |
| 82 |
|
public long size() |
| 83 |
|
{ |
| 84 |
2 |
return size; |
| 85 |
|
} |
| 86 |
|
} |
| 87 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 2 |
Complexity Density: 0.09 |
1PASS
|
|
| 88 |
1 |
@Test... |
| 89 |
|
public void iterate() |
| 90 |
|
{ |
| 91 |
1 |
List<Pair<DocumentReference, String>> previous = new ArrayList<Pair<DocumentReference, String>>(); |
| 92 |
1 |
previous.add(new ImmutablePair<DocumentReference, String>(new DocumentReference("chess", "B", "M"), "2.3")); |
| 93 |
1 |
previous.add(new ImmutablePair<DocumentReference, String>(new DocumentReference("chess", "E", "A"), "5.1")); |
| 94 |
1 |
previous.add(new ImmutablePair<DocumentReference, String>(new DocumentReference("xwiki", "A", "S"), "1.1")); |
| 95 |
1 |
DocumentIterator<String> previousIterator = new DocumentIteratorStub<String>(previous); |
| 96 |
|
|
| 97 |
1 |
List<Pair<DocumentReference, String>> next = new ArrayList<Pair<DocumentReference, String>>(); |
| 98 |
1 |
next.add(new ImmutablePair<DocumentReference, String>(new DocumentReference("chess", "B", "L"), "1.2")); |
| 99 |
1 |
next.add(new ImmutablePair<DocumentReference, String>(new DocumentReference("chess", "B", "M"), "4.7")); |
| 100 |
1 |
next.add(new ImmutablePair<DocumentReference, String>(new DocumentReference("xwiki", "A", "S"), "1.1")); |
| 101 |
1 |
next.add(new ImmutablePair<DocumentReference, String>(new DocumentReference("xwiki", "B", "P"), "2.4")); |
| 102 |
1 |
DocumentIterator<String> nextIterator = new DocumentIteratorStub<String>(next); |
| 103 |
|
|
| 104 |
1 |
DiffDocumentIterator<String> iterator = new DiffDocumentIterator<String>(previousIterator, nextIterator); |
| 105 |
|
|
| 106 |
1 |
assertEquals(4, iterator.size()); |
| 107 |
|
|
| 108 |
1 |
List<Pair<DocumentReference, Action>> actualResult = new ArrayList<Pair<DocumentReference, Action>>(); |
| 109 |
6 |
while (iterator.hasNext()) { |
| 110 |
5 |
actualResult.add(iterator.next()); |
| 111 |
|
} |
| 112 |
|
|
| 113 |
1 |
List<Pair<DocumentReference, Action>> expectedResult = new ArrayList<Pair<DocumentReference, Action>>(); |
| 114 |
1 |
expectedResult.add(new ImmutablePair<DocumentReference, Action>(next.get(0).getKey(), Action.ADD)); |
| 115 |
1 |
expectedResult.add(new ImmutablePair<DocumentReference, Action>(next.get(1).getKey(), Action.UPDATE)); |
| 116 |
1 |
expectedResult.add(new ImmutablePair<DocumentReference, Action>(previous.get(1).getKey(), Action.DELETE)); |
| 117 |
1 |
expectedResult.add(new ImmutablePair<DocumentReference, Action>(next.get(2).getKey(), Action.SKIP)); |
| 118 |
1 |
expectedResult.add(new ImmutablePair<DocumentReference, Action>(next.get(3).getKey(), Action.ADD)); |
| 119 |
|
|
| 120 |
1 |
assertEquals(expectedResult, actualResult); |
| 121 |
|
} |
| 122 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 2 |
Complexity Density: 0.14 |
1PASS
|
|
| 123 |
1 |
@Test... |
| 124 |
|
public void deleteAll() |
| 125 |
|
{ |
| 126 |
1 |
List<Pair<DocumentReference, String>> previous = new ArrayList<Pair<DocumentReference, String>>(); |
| 127 |
1 |
previous.add(new ImmutablePair<DocumentReference, String>(new DocumentReference("wiki", "A", "B"), "3.1")); |
| 128 |
1 |
previous.add(new ImmutablePair<DocumentReference, String>(new DocumentReference("wiki", "X", "Y"), "5.2")); |
| 129 |
1 |
DocumentIterator<String> previousIterator = new DocumentIteratorStub<String>(previous); |
| 130 |
|
|
| 131 |
1 |
List<Pair<DocumentReference, String>> next = Collections.emptyList(); |
| 132 |
1 |
DocumentIterator<String> nextIterator = new DocumentIteratorStub<String>(next); |
| 133 |
|
|
| 134 |
1 |
DiffDocumentIterator<String> iterator = new DiffDocumentIterator<String>(previousIterator, nextIterator); |
| 135 |
|
|
| 136 |
1 |
List<Pair<DocumentReference, Action>> actualResult = new ArrayList<Pair<DocumentReference, Action>>(); |
| 137 |
3 |
while (iterator.hasNext()) { |
| 138 |
2 |
actualResult.add(iterator.next()); |
| 139 |
|
} |
| 140 |
|
|
| 141 |
1 |
List<Pair<DocumentReference, Action>> expectedResult = new ArrayList<Pair<DocumentReference, Action>>(); |
| 142 |
1 |
expectedResult.add(new ImmutablePair<DocumentReference, Action>(previous.get(0).getKey(), Action.DELETE)); |
| 143 |
1 |
expectedResult.add(new ImmutablePair<DocumentReference, Action>(previous.get(1).getKey(), Action.DELETE)); |
| 144 |
1 |
assertEquals(expectedResult, actualResult); |
| 145 |
|
} |
| 146 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
| 147 |
1 |
@SuppressWarnings("unchecked")... |
| 148 |
|
@Test |
| 149 |
|
public void setRootReference() |
| 150 |
|
{ |
| 151 |
1 |
DocumentIterator<String> previous = mock(DocumentIterator.class, "previous"); |
| 152 |
1 |
DocumentIterator<String> next = mock(DocumentIterator.class, "next"); |
| 153 |
1 |
DiffDocumentIterator<String> iterator = new DiffDocumentIterator<String>(previous, next); |
| 154 |
|
|
| 155 |
1 |
WikiReference rootReference = new WikiReference("foo"); |
| 156 |
1 |
iterator.setRootReference(rootReference); |
| 157 |
|
|
| 158 |
1 |
verify(previous).setRootReference(rootReference); |
| 159 |
1 |
verify(next).setRootReference(rootReference); |
| 160 |
|
} |
| 161 |
|
|
| |
|
| 70% |
Uncovered Elements: 3 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
1PASS
|
|
| 162 |
1 |
@SuppressWarnings("unchecked")... |
| 163 |
|
@Test |
| 164 |
|
public void remove() |
| 165 |
|
{ |
| 166 |
1 |
DocumentIterator<String> previous = mock(DocumentIterator.class, "previous"); |
| 167 |
1 |
DocumentIterator<String> next = mock(DocumentIterator.class, "next"); |
| 168 |
1 |
DiffDocumentIterator<String> iterator = new DiffDocumentIterator<String>(previous, next); |
| 169 |
1 |
try { |
| 170 |
1 |
iterator.remove(); |
| 171 |
0 |
fail(); |
| 172 |
|
} catch (Exception e) { |
| 173 |
1 |
if (!(e instanceof UnsupportedOperationException)) { |
| 174 |
0 |
fail(); |
| 175 |
|
} |
| 176 |
|
} |
| 177 |
|
} |
| 178 |
|
} |