4747 */
4848public class EventHandlerRule implements EventHandler , TestRule {
4949
50+ private static final String IMPRESSION_EVENT_NAME = "campaign_activated" ;
51+
5052 private LinkedList <CanonicalEvent > actualEvents ;
5153
5254 @ Override
@@ -76,25 +78,29 @@ private void verify() {
7678 assertTrue (actualEvents .isEmpty ());
7779 }
7880
79- public void expectImpression (String experientId , String variationId , String userId ) throws Exception {
81+ public void expectImpression (String experientId , String variationId , String userId ) {
8082 expectImpression (experientId , variationId , userId , Collections .emptyMap ());
8183 }
8284
83- public void expectImpression (String experientId , String variationId , String userId , Map <String , ?> attributes ) throws Exception {
84- CanonicalEvent expectedEvent = new CanonicalEvent (experientId , variationId , "campaign_activated" , userId , attributes );
85- verify (expectedEvent );
85+ public void expectImpression (String experientId , String variationId , String userId , Map <String , ?> attributes ) {
86+ verify (experientId , variationId , IMPRESSION_EVENT_NAME , userId , attributes , null );
87+ }
88+
89+ public void expectConversion (String eventName , String userId ) {
90+ expectConversion (eventName , userId , Collections .emptyMap ());
8691 }
8792
88- public void expectConversion (String eventName , String userId ) throws Exception {
89- expectConversion (null , null , eventName , userId , Collections .emptyMap ());
93+ public void expectConversion (String eventName , String userId , Map < String , ?> attributes ) {
94+ expectConversion (eventName , userId , attributes , Collections .emptyMap ());
9095 }
9196
92- public void expectConversion (String eventName , String userId , Map <String , ?> attributes ) throws Exception {
93- expectConversion (null , null , eventName , userId , attributes );
97+ public void expectConversion (String eventName , String userId , Map <String , ?> attributes , Map < String , ?> tags ) {
98+ verify (null , null , eventName , userId , attributes , tags );
9499 }
95100
96- public void expectConversion (String experientId , String variationId , String eventName , String userId , Map <String , ?> attributes ) throws Exception {
97- CanonicalEvent expectedEvent = new CanonicalEvent (experientId , variationId , eventName , userId , attributes );
101+ public void verify (String experientId , String variationId , String eventName , String userId ,
102+ Map <String , ?> attributes , Map <String , ?> tags ) {
103+ CanonicalEvent expectedEvent = new CanonicalEvent (experientId , variationId , eventName , userId , attributes , tags );
98104 verify (expectedEvent );
99105 }
100106
@@ -108,7 +114,7 @@ public void verify(CanonicalEvent expected) {
108114 }
109115
110116 @ Override
111- public void dispatchEvent (LogEvent logEvent ) throws Exception {
117+ public void dispatchEvent (LogEvent logEvent ) {
112118 List <Visitor > visitors = logEvent .getEventBatch ().getVisitors ();
113119
114120 if (visitors == null ) {
@@ -135,7 +141,8 @@ public void dispatchEvent(LogEvent logEvent) throws Exception {
135141 visitor .getVisitorId (),
136142 visitor .getAttributes ().stream ()
137143 .filter (attribute -> !attribute .getKey ().startsWith (RESERVED_ATTRIBUTE_PREFIX ))
138- .collect (Collectors .toMap (Attribute ::getKey , Attribute ::getValue ))
144+ .collect (Collectors .toMap (Attribute ::getKey , Attribute ::getValue )),
145+ event .getTags ()
139146 );
140147
141148 actualEvents .add (actual );
@@ -151,13 +158,16 @@ private static class CanonicalEvent {
151158 private String eventName ;
152159 private String visitorId ;
153160 private Map <String , ?> attributes ;
161+ private Map <String , ?> tags ;
154162
155- public CanonicalEvent (String experimentId , String variationId , String eventName , String visitorId , Map <String , ?> attributes ) {
163+ public CanonicalEvent (String experimentId , String variationId , String eventName ,
164+ String visitorId , Map <String , ?> attributes , Map <String , ?> tags ) {
156165 this .experimentId = experimentId ;
157166 this .variationId = variationId ;
158167 this .eventName = eventName ;
159168 this .visitorId = visitorId ;
160169 this .attributes = attributes ;
170+ this .tags = tags ;
161171 }
162172
163173 @ Override
@@ -169,12 +179,13 @@ public boolean equals(Object o) {
169179 Objects .equals (variationId , that .variationId ) &&
170180 Objects .equals (eventName , that .eventName ) &&
171181 Objects .equals (visitorId , that .visitorId ) &&
172- Objects .equals (attributes , that .attributes );
182+ Objects .equals (attributes , that .attributes ) &&
183+ Objects .equals (tags , that .tags );
173184 }
174185
175186 @ Override
176187 public int hashCode () {
177- return Objects .hash (experimentId , variationId , eventName , visitorId , attributes );
188+ return Objects .hash (experimentId , variationId , eventName , visitorId , attributes , tags );
178189 }
179190
180191 @ Override
@@ -185,6 +196,7 @@ public String toString() {
185196 .add ("eventName='" + eventName + "'" )
186197 .add ("visitorId='" + visitorId + "'" )
187198 .add ("attributes=" + attributes )
199+ .add ("tags=" + tags )
188200 .toString ();
189201 }
190202 }
0 commit comments