Revision 52773
Added by Michele Artini almost 6 years ago
modules/dnet-mapreduce-jobs/branches/beta/src/test/java/eu/dnetlib/data/mapreduce/hbase/broker/EventWrapperTest.java | ||
---|---|---|
1 |
package eu.dnetlib.data.mapreduce.hbase.broker; |
|
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 org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
10 |
import org.junit.Ignore; |
|
11 |
import org.junit.Test; |
|
12 |
|
|
13 |
import eu.dnetlib.data.proto.OafProtos.Oaf; |
|
14 |
|
|
15 |
/** |
|
16 |
* Created by claudio on 22/07/16. |
|
17 |
*/ |
|
18 |
@Ignore |
|
19 |
public class EventWrapperTest { |
|
20 |
|
|
21 |
private static final Log log = LogFactory.getLog(EventWrapperTest.class); |
|
22 |
|
|
23 |
private Oaf oaf1_1; |
|
24 |
private Oaf oaf1_2; |
|
25 |
private Oaf oaf2_1; |
|
26 |
private Oaf oaf2_2; |
|
27 |
private Oaf oaf3_1; |
|
28 |
private Oaf oaf3_2; |
|
29 |
|
|
30 |
@Test |
|
31 |
public void testAbstractEvent() throws Exception { |
|
32 |
final String id1 = AbstractEventFactory.process(oaf1_1, oaf1_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
33 |
final String id2 = AbstractEventFactory.process(oaf2_1, oaf2_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
34 |
final String id3 = AbstractEventFactory.process(oaf3_1, oaf3_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
35 |
|
|
36 |
verifyEquals(id1, id2); |
|
37 |
verifyDifferent(id1, id3); |
|
38 |
} |
|
39 |
|
|
40 |
@Test |
|
41 |
public void testOAVersionEvent() throws Exception { |
|
42 |
final String id1 = OAVersionEventFactory.process(oaf1_1, oaf1_2, 1.0f, null).get(0).asBrokerEvent().getEventId(); |
|
43 |
final String id2 = OAVersionEventFactory.process(oaf2_1, oaf2_2, 1.0f, null).get(0).asBrokerEvent().getEventId(); |
|
44 |
final String id3 = OAVersionEventFactory.process(oaf3_1, oaf3_2, 1.0f, null).get(0).asBrokerEvent().getEventId(); |
|
45 |
|
|
46 |
verifyEquals(id1, id2); |
|
47 |
verifyDifferent(id1, id3); |
|
48 |
} |
|
49 |
|
|
50 |
@Test |
|
51 |
public void testPIDEvent() throws Exception { |
|
52 |
final String id1 = PIDEventFactory.process(oaf1_1, oaf1_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
53 |
final String id2 = PIDEventFactory.process(oaf2_1, oaf2_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
54 |
final String id3 = PIDEventFactory.process(oaf3_1, oaf3_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
55 |
|
|
56 |
verifyEquals(id1, id2); |
|
57 |
verifyDifferent(id1, id3); |
|
58 |
} |
|
59 |
|
|
60 |
@Test |
|
61 |
public void testProjectEvent() throws Exception { |
|
62 |
final String id1 = ProjectEventFactory.process(null, oaf1_1, oaf1_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
63 |
final String id2 = ProjectEventFactory.process(null, oaf2_1, oaf2_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
64 |
final String id3 = ProjectEventFactory.process(null, oaf3_1, oaf3_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
65 |
|
|
66 |
verifyEquals(id1, id2); |
|
67 |
verifyDifferent(id1, id3); |
|
68 |
} |
|
69 |
|
|
70 |
@Test |
|
71 |
public void testPublicationDateEvent() throws Exception { |
|
72 |
final String id1 = PublicationDateEventFactory.process(oaf1_1, oaf1_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
73 |
final String id2 = PublicationDateEventFactory.process(oaf2_1, oaf2_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
74 |
final String id3 = PublicationDateEventFactory.process(oaf3_1, oaf3_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
75 |
|
|
76 |
verifyEquals(id1, id2); |
|
77 |
verifyDifferent(id1, id3); |
|
78 |
} |
|
79 |
|
|
80 |
@Test |
|
81 |
public void testSoftwareEventFactory() throws Exception { |
|
82 |
final String id1 = SoftwareEventFactory.process(null, oaf1_1, oaf1_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
83 |
final String id2 = SoftwareEventFactory.process(null, oaf2_1, oaf2_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
84 |
final String id3 = SoftwareEventFactory.process(null, oaf3_1, oaf3_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
85 |
|
|
86 |
verifyEquals(id1, id2); |
|
87 |
verifyDifferent(id1, id3); |
|
88 |
} |
|
89 |
|
|
90 |
@Test |
|
91 |
public void testSubjectEventFactory() throws Exception { |
|
92 |
final String id1 = SubjectEventFactory.process(null, oaf1_1, oaf1_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
93 |
final String id2 = SubjectEventFactory.process(null, oaf2_1, oaf2_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
94 |
final String id3 = SubjectEventFactory.process(null, oaf3_1, oaf3_2, 1.0f).get(0).asBrokerEvent().getEventId(); |
|
95 |
|
|
96 |
verifyEquals(id1, id2); |
|
97 |
verifyDifferent(id1, id3); |
|
98 |
} |
|
99 |
|
|
100 |
private void verifyEquals(final String x, final String y) { |
|
101 |
assertNotNull(x); |
|
102 |
assertNotNull(y); |
|
103 |
assertTrue(x.length() > 10); |
|
104 |
assertTrue(y.length() > 10); |
|
105 |
assertEquals(x, y); |
|
106 |
log.info(String.format("%s = %s", x, y)); |
|
107 |
} |
|
108 |
|
|
109 |
private void verifyDifferent(final String x, final String y) { |
|
110 |
assertNotNull(x); |
|
111 |
assertNotNull(y); |
|
112 |
assertTrue(x.length() > 10); |
|
113 |
assertTrue(y.length() > 10); |
|
114 |
assertFalse(x.equals(y)); |
|
115 |
log.info(String.format("%s != %s", x, y)); |
|
116 |
} |
|
117 |
} |
Also available in: Unified diff
Partial implementation of a unit test