forked from eclipsesource/tabris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds custom event handling to Piwik Tracker.
Change-Id: I038be238c17f7e137a7d39c911100d99a1f3ec7e
- Loading branch information
Christian Petrov
authored and
hstaudacher
committed
Jun 10, 2014
1 parent
62f45de
commit 1f11be1
Showing
7 changed files
with
191 additions
and
0 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
...st/src/com/eclipsesource/tabris/tracking/internal/piwik/model/action/EventActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2014 EclipseSource and others. All rights reserved. This | ||
* program and the accompanying materials are made available under the terms of | ||
* the Eclipse Public License v1.0 which accompanies this distribution, and is | ||
* available at http://www.eclipse.org/legal/epl-v10.html Contributors: | ||
* EclipseSource - initial API and implementation | ||
******************************************************************************/ | ||
package com.eclipsesource.tabris.tracking.internal.piwik.model.action; | ||
|
||
import static com.eclipsesource.tabris.tracking.internal.piwik.request.RequestKeyProvider.getRequestKey; | ||
import static com.eclipsesource.tabris.tracking.internal.piwik.request.RequestKeys.EVENT_ACTION; | ||
import static com.eclipsesource.tabris.tracking.internal.piwik.request.RequestKeys.EVENT_CATEGORY; | ||
import static com.eclipsesource.tabris.tracking.internal.piwik.request.RequestKeys.EVENT_NAME; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
|
||
public class EventActionTest { | ||
|
||
@Test( expected = IllegalArgumentException.class ) | ||
public void testFailsWithNullCategory() { | ||
EventAction eventAction = new EventAction( "foo" ); | ||
|
||
eventAction.setCategory( null ); | ||
} | ||
|
||
@Test( expected = IllegalArgumentException.class ) | ||
public void testFailsWithEmptyCategory() { | ||
EventAction eventAction = new EventAction( "foo" ); | ||
|
||
eventAction.setCategory( "" ); | ||
} | ||
|
||
@Test | ||
public void testAddsCategoryToParameter() throws Exception { | ||
EventAction eventAction = new EventAction( "foo" ).setCategory( "baz" ); | ||
|
||
assertEquals( "baz", eventAction.getParameter().get( getRequestKey( EVENT_CATEGORY ) ) ); | ||
} | ||
|
||
@Test( expected = IllegalArgumentException.class ) | ||
public void testFailsWithNullAction() { | ||
EventAction eventAction = new EventAction( "foo" ); | ||
|
||
eventAction.setAction( null ); | ||
} | ||
|
||
@Test( expected = IllegalArgumentException.class ) | ||
public void testFailsWithEmptyAction() { | ||
EventAction eventAction = new EventAction( "foo" ); | ||
|
||
eventAction.setAction( "" ); | ||
} | ||
|
||
@Test | ||
public void testAddsActionToParameter() throws Exception { | ||
EventAction eventAction = new EventAction( "foo" ).setAction( "baz" ); | ||
|
||
assertEquals( "baz", eventAction.getParameter().get( getRequestKey( EVENT_ACTION ) ) ); | ||
} | ||
|
||
@Test( expected = IllegalArgumentException.class ) | ||
public void testFailsWithNullName() { | ||
EventAction eventAction = new EventAction( "foo" ); | ||
|
||
eventAction.setEventName( null ); | ||
} | ||
|
||
@Test( expected = IllegalArgumentException.class ) | ||
public void testFailsWithEmptyName() { | ||
EventAction eventAction = new EventAction( "foo" ); | ||
|
||
eventAction.setEventName( "" ); | ||
} | ||
|
||
@Test | ||
public void testAddsNameToParameter() throws Exception { | ||
EventAction eventAction = new EventAction( "foo" ).setEventName( "baz" ); | ||
|
||
assertEquals( "baz", eventAction.getParameter().get( getRequestKey( EVENT_NAME ) ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...acking/src/com/eclipsesource/tabris/tracking/internal/piwik/model/action/EventAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2014 EclipseSource and others. All rights reserved. This | ||
* program and the accompanying materials are made available under the terms of | ||
* the Eclipse Public License v1.0 which accompanies this distribution, and is | ||
* available at http://www.eclipse.org/legal/epl-v10.html Contributors: | ||
* EclipseSource - initial API and implementation | ||
******************************************************************************/ | ||
package com.eclipsesource.tabris.tracking.internal.piwik.model.action; | ||
|
||
import static com.eclipsesource.tabris.internal.Clauses.when; | ||
import static com.eclipsesource.tabris.internal.Clauses.whenNull; | ||
import static com.eclipsesource.tabris.tracking.internal.piwik.request.RequestKeyProvider.getRequestKey; | ||
import static com.eclipsesource.tabris.tracking.internal.piwik.request.RequestKeys.EVENT_ACTION; | ||
import static com.eclipsesource.tabris.tracking.internal.piwik.request.RequestKeys.EVENT_CATEGORY; | ||
import static com.eclipsesource.tabris.tracking.internal.piwik.request.RequestKeys.EVENT_NAME; | ||
|
||
|
||
@SuppressWarnings("restriction") | ||
public class EventAction extends Action { | ||
|
||
public EventAction( String actionUrl ) { | ||
super( actionUrl ); | ||
} | ||
|
||
public EventAction setCategory( String category ) { | ||
whenNull( category ).throwIllegalArgument( "Category must not be null." ); | ||
when( category.isEmpty() ).throwIllegalArgument( "Category must not be empty." ); | ||
addParameter( getRequestKey( EVENT_CATEGORY ), category ); | ||
return this; | ||
} | ||
|
||
public EventAction setAction( String action ) { | ||
whenNull( action ).throwIllegalArgument( "Action must not be null." ); | ||
when( action.isEmpty() ).throwIllegalArgument( "Action must not be empty." ); | ||
addParameter( getRequestKey( EVENT_ACTION ), action ); | ||
return this; | ||
} | ||
|
||
public EventAction setEventName( String name ) { | ||
whenNull( name ).throwIllegalArgument( "Name must not be null." ); | ||
when( name.isEmpty() ).throwIllegalArgument( "Name must not be empty." ); | ||
addParameter( getRequestKey( EVENT_NAME ), name ); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters