customTrackingParameters = new HashMap<>();
-
- /**
- * Create a new request from the id of the site being tracked and the full
- * url for the current action. This constructor also sets:
- *
- * {@code
- * Required = true
- * Visior Id = random 16 character hex string
- * Random Value = random 20 character hex string
- * API version = 1
- * Response as Image = false
- * }
- *
- * Overwrite these values yourself as desired.
- *
- * @param siteId the id of the website we're tracking a visit/action for
- * @param actionUrl the full URL for the current action
- */
- public PiwikRequest(Integer siteId, URL actionUrl) {
- setParameter(SITE_ID, siteId);
- setBooleanParameter(REQUIRED, true);
- setParameter(ACTION_URL, actionUrl);
- setParameter(VISITOR_ID, getRandomHexString(ID_LENGTH));
- setParameter(RANDOM_VALUE, getRandomHexString(RANDOM_VALUE_LENGTH));
- setParameter(API_VERSION, "1");
- setBooleanParameter(RESPONSE_AS_IMAGE, false);
- }
-
- /**
- * Get the title of the action being tracked
- *
- * @return the title of the action being tracked
- */
-
- public String getActionName() {
- return (String) getParameter(ACTION_NAME);
- }
-
- /**
- * Set the title of the action being tracked. It is possible to
- * use slashes /
- * to set one or several categories for this action.
- * For example, Help / Feedback
- * will create the Action Feedback in the category Help.
- *
- * @param actionName the title of the action to set. A null value will remove this parameter
- */
- public void setActionName(String actionName) {
- setParameter(ACTION_NAME, actionName);
- }
-
- /**
- * Get the amount of time it took the server to generate this action, in milliseconds.
- *
- * @return the amount of time
- */
- public Long getActionTime() {
- return (Long) getParameter(ACTION_TIME);
- }
-
- /**
- * Set the amount of time it took the server to generate this action, in milliseconds.
- * This value is used to process the
- * Page speed report
- * Avg. generation time column in the Page URL and Page Title reports,
- * as well as a site wide running average of the speed of your server.
- *
- * @param actionTime the amount of time to set. A null value will remove this parameter
- */
- public void setActionTime(Long actionTime) {
- setParameter(ACTION_TIME, actionTime);
- }
-
- /**
- * Get the full URL for the current action.
- *
- * @return the full URL
- * @throws TypeConstraintException if the stored Action URL is a string
- */
- public URL getActionUrl() {
- return returnAsUrl(ACTION_URL, "Action URL", "getActionUrlAsString");
- }
-
- /**
- * Get the full URL for the current action.
- *
- * @return the full URL
- * @throws TypeConstraintException if the stored Action URL is a URL
- */
- public String getActionUrlAsString() {
- return returnAsString(ACTION_URL, "Action URL", "getActionUrl");
- }
-
- /**
- * Set the full URL for the current action.
- *
- * @param actionUrl the full URL to set. A null value will remove this parameter
- */
- public void setActionUrl(URL actionUrl) {
- setParameter(ACTION_URL, actionUrl);
- }
-
- /**
- * Set the full URL for the current action.
- *
- * @param actionUrl the full URL to set. A null value will remove this parameter
- */
- public void setActionUrlWithString(String actionUrl) {
- setParameter(ACTION_URL, actionUrl);
- }
-
- /**
- * Get the api version
- *
- * @return the api version
- */
- public String getApiVersion() {
- return (String) getParameter(API_VERSION);
- }
-
- /**
- * Set the api version to use (currently always set to 1)
- *
- * @param apiVersion the api version to set. A null value will remove this parameter
- */
- public void setApiVersion(String apiVersion) {
- setParameter(API_VERSION, apiVersion);
- }
-
- /**
- * Get the authorization key.
- *
- * @return the authorization key
- */
- public String getAuthToken() {
- return (String) getParameter(AUTH_TOKEN);
- }
-
- /**
- * Set the {@value #AUTH_TOKEN_LENGTH} character authorization key used to authenticate the API request.
- *
- * @param authToken the authorization key to set. A null value will remove this parameter
- */
- public void setAuthToken(String authToken) {
- if (authToken != null && authToken.length() != AUTH_TOKEN_LENGTH) {
- throw new IllegalArgumentException(authToken + " is not " + AUTH_TOKEN_LENGTH + " characters long.");
- }
- setParameter(AUTH_TOKEN, authToken);
- }
-
- /**
- * Verifies that AuthToken has been set for this request. Will throw an
- * {@link IllegalStateException} if not.
- */
- public void verifyAuthTokenSet() {
- if (getAuthToken() == null) {
- throw new IllegalStateException("AuthToken must be set before this value can be set.");
- }
- }
-
- /**
- * Get the campaign keyword
- *
- * @return the campaign keyword
- */
- public String getCampaignKeyword() {
- return (String) getParameter(CAMPAIGN_KEYWORD);
- }
-
- /**
- * Set the Campaign Keyword (see
- * Tracking Campaigns).
- * Used to populate the Referrers > Campaigns report (clicking on a
- * campaign loads all keywords for this campaign). Note: this parameter
- * will only be used for the first pageview of a visit.
- *
- * @param campaignKeyword the campaign keyword to set. A null value will remove this parameter
- */
- public void setCampaignKeyword(String campaignKeyword) {
- setParameter(CAMPAIGN_KEYWORD, campaignKeyword);
- }
-
- /**
- * Get the campaign name
- *
- * @return the campaign name
- */
- public String getCampaignName() {
- return (String) getParameter(CAMPAIGN_NAME);
- }
-
- /**
- * Set the Campaign Name (see
- * Tracking Campaigns).
- * Used to populate the Referrers > Campaigns report. Note: this parameter
- * will only be used for the first pageview of a visit.
- *
- * @param campaignName the campaign name to set. A null value will remove this parameter
- */
- public void setCampaignName(String campaignName) {
- setParameter(CAMPAIGN_NAME, campaignName);
- }
-
- /**
- * Get the charset of the page being tracked
- *
- * @return the charset
- */
- public Charset getCharacterSet() {
- return (Charset) getParameter(CHARACTER_SET);
- }
-
- /**
- * The charset of the page being tracked. Specify the charset if the data
- * you send to Piwik is encoded in a different character set than the default
- * utf-8.
- *
- * @param characterSet the charset to set. A null value will remove this parameter
- */
- public void setCharacterSet(Charset characterSet) {
- setParameter(CHARACTER_SET, characterSet);
- }
-
- /**
- * Get the name of the interaction with the content
- *
- * @return the name of the interaction
- */
- public String getContentInteraction() {
- return (String) getParameter(CONTENT_INTERACTION);
- }
-
- /**
- * Set the name of the interaction with the content. For instance a 'click'.
- *
- * @param contentInteraction the name of the interaction to set. A null value will remove this parameter
- */
- public void setContentInteraction(String contentInteraction) {
- setParameter(CONTENT_INTERACTION, contentInteraction);
- }
-
- /**
- * Get the name of the content
- *
- * @return the name
- */
- public String getContentName() {
- return (String) getParameter(CONTENT_NAME);
- }
-
- /**
- * Set the name of the content. For instance 'Ad Foo Bar'.
- *
- * @param contentName the name to set. A null value will remove this parameter
- */
- public void setContentName(String contentName) {
- setParameter(CONTENT_NAME, contentName);
- }
-
- /**
- * Get the content piece.
- *
- * @return the content piece.
- */
- public String getContentPiece() {
- return (String) getParameter(CONTENT_PIECE);
- }
-
- /**
- * Set the actual content piece. For instance the path to an image, video, audio, any text.
- *
- * @param contentPiece the content piece to set. A null value will remove this parameter
- */
- public void setContentPiece(String contentPiece) {
- setParameter(CONTENT_PIECE, contentPiece);
- }
-
- /**
- * Get the content target
- *
- * @return the target
- * @throws TypeConstraintException if the stored Content Target is a string
- */
- public URL getContentTarget() {
- return returnAsUrl(CONTENT_TARGET, "Content Target", "getContentTargetAsString");
- }
-
- /**
- * Get the content target
- *
- * @return the target
- * @throws TypeConstraintException if the stored Content Target is a URL
- */
- public String getContentTargetAsString() {
- return returnAsString(CONTENT_TARGET, "Content Target", "getContentTarget");
- }
-
- /**
- * Set the target of the content. For instance the URL of a landing page.
- *
- * @param contentTarget the target to set. A null value will remove this parameter
- */
- public void setContentTarget(URL contentTarget) {
- setParameter(CONTENT_TARGET, contentTarget);
- }
-
- /**
- * Set the target of the content. For instance the URL of a landing page.
- *
- * @param contentTarget the target to set. A null value will remove this parameter
- */
- public void setContentTargetWithString(String contentTarget) {
- setParameter(CONTENT_TARGET, contentTarget);
- }
-
- /**
- * Get the current hour.
- *
- * @return the current hour
- */
- public Integer getCurrentHour() {
- return (Integer) getParameter(CURRENT_HOUR);
- }
-
- /**
- * Set the current hour (local time).
- *
- * @param currentHour the hour to set. A null value will remove this parameter
- */
- public void setCurrentHour(Integer currentHour) {
- setParameter(CURRENT_HOUR, currentHour);
- }
-
- /**
- * Get the current minute.
- *
- * @return the current minute
- */
- public Integer getCurrentMinute() {
- return (Integer) getParameter(CURRENT_MINUTE);
- }
-
- /**
- * Set the current minute (local time).
- *
- * @param currentMinute the minute to set. A null value will remove this parameter
- */
- public void setCurrentMinute(Integer currentMinute) {
- setParameter(CURRENT_MINUTE, currentMinute);
- }
-
- /**
- * Get the current second
- *
- * @return the current second
- */
- public Integer getCurrentSecond() {
- return (Integer) getParameter(CURRENT_SECOND);
- }
-
- /**
- * Set the current second (local time).
- *
- * @param currentSecond the second to set. A null value will remove this parameter
- */
- public void setCurrentSecond(Integer currentSecond) {
- setParameter(CURRENT_SECOND, currentSecond);
- }
-
- /**
- * Gets the list of objects currently stored at the specified custom tracking
- * parameter. An empty list will be returned if there are no objects set at
- * that key.
- *
- * @param key the key of the parameter whose list of objects to get. Cannot be null
- * @return the list of objects currently stored at the specified key
- */
- public List getCustomTrackingParameter(String key) {
- if (key == null) {
- throw new NullPointerException("Key cannot be null.");
- }
- List l = customTrackingParameters.get(key);
- if (l == null) {
- return new ArrayList(0);
- }
- return new ArrayList(l);
- }
-
- /**
- * Set a custom tracking parameter whose toString() value will be sent to
- * the Piwik server. These parameters are stored separately from named Piwik
- * parameters, meaning it is not possible to overwrite or clear named Piwik
- * parameters with this method. A custom parameter that has the same name
- * as a named Piwik parameter will be sent in addition to that named parameter.
- *
- * @param key the parameter's key. Cannot be null
- * @param value the parameter's value. Removes the parameter if null
- */
- public void setCustomTrackingParameter(String key, Object value) {
- if (key == null) {
- throw new NullPointerException("Key cannot be null.");
- }
- if (value == null) {
- customTrackingParameters.remove(key);
- } else {
- List l = new ArrayList();
- l.add(value);
- customTrackingParameters.put(key, l);
- }
- }
-
- /**
- * Add a custom tracking parameter to the specified key. This allows users
- * to have multiple parameters with the same name and different values,
- * commonly used during situations where list parameters are needed
- *
- * @param key the parameter's key. Cannot be null
- * @param value the parameter's value. Cannot be null
- */
- public void addCustomTrackingParameter(String key, Object value) {
- if (key == null) {
- throw new NullPointerException("Key cannot be null.");
- }
- if (value == null) {
- throw new NullPointerException("Cannot add a null custom tracking parameter.");
- } else {
- List l = customTrackingParameters.get(key);
- if (l == null) {
- l = new ArrayList();
- customTrackingParameters.put(key, l);
- }
- l.add(value);
- }
- }
-
- /**
- * Removes all custom tracking parameters
- */
- public void clearCustomTrackingParameter() {
- customTrackingParameters.clear();
- }
-
- /**
- * Get the resolution of the device
- *
- * @return the resolution
- */
- public String getDeviceResolution() {
- return (String) getParameter(DEVICE_RESOLUTION);
- }
-
- /**
- * Set the resolution of the device the visitor is using, eg 1280x1024.
- *
- * @param deviceResolution the resolution to set. A null value will remove this parameter
- */
- public void setDeviceResolution(String deviceResolution) {
- setParameter(DEVICE_RESOLUTION, deviceResolution);
- }
-
- /**
- * Get the url of a file the user had downloaded
- *
- * @return the url
- * @throws TypeConstraintException if the stored Download URL is a String
- */
- public URL getDownloadUrl() {
- return returnAsUrl(DOWNLOAD_URL, "Download URL", "getDownloadUrlAsString");
- }
-
- /**
- * Get the url of a file the user had downloaded
- *
- * @return the url
- * @throws TypeConstraintException if the stored Download URL is a URL
- */
- public String getDownloadUrlAsString() {
- return returnAsString(DOWNLOAD_URL, "Download URL", "getDownloadUrl");
- }
-
- /**
- * Set the url of a file the user has downloaded. Used for tracking downloads.
- * We recommend to also set the url parameter to this same value.
- *
- * @param downloadUrl the url to set. A null value will remove this parameter
- */
- public void setDownloadUrl(URL downloadUrl) {
- setParameter(DOWNLOAD_URL, downloadUrl);
- }
-
- /**
- * Set the url of a file the user has downloaded. Used for tracking downloads.
- * We recommend to also set the url parameter to this same value.
- *
- * @param downloadUrl the url to set. A null value will remove this parameter
- */
- public void setDownloadUrlWithString(String downloadUrl) {
- setParameter(DOWNLOAD_URL, downloadUrl);
- }
-
- /**
- * Sets idgoal=0 in the request to track an ecommerce interaction:
- * cart update or an ecommerce order.
- */
- public void enableEcommerce() {
- setGoalId(0);
- }
-
- /**
- * Verifies that Ecommerce has been enabled for the request. Will throw an
- * {@link IllegalStateException} if not.
- */
- public void verifyEcommerceEnabled() {
- if (getGoalId() == null || getGoalId() != 0) {
- throw new IllegalStateException("GoalId must be \"0\". Try calling enableEcommerce first before calling this method.");
- }
- }
-
- /**
- * Verifies that Ecommerce has been enabled and that Ecommerce Id and
- * Ecommerce Revenue have been set for the request. Will throw an
- * {@link IllegalStateException} if not.
- */
- public void verifyEcommerceState() {
- verifyEcommerceEnabled();
- if (getEcommerceId() == null) {
- throw new IllegalStateException("EcommerceId must be set before this value can be set.");
- }
- if (getEcommerceRevenue() == null) {
- throw new IllegalStateException("EcommerceRevenue must be set before this value can be set.");
- }
- }
-
- /**
- * Get the discount offered.
- *
- * @return the discount
- */
- public Double getEcommerceDiscount() {
- return (Double) getParameter(ECOMMERCE_DISCOUNT);
- }
-
- /**
- * Set the discount offered. Ecommerce must be enabled, and EcommerceId and
- * EcommerceRevenue must first be set.
- *
- * @param discount the discount to set. A null value will remove this parameter
- */
- public void setEcommerceDiscount(Double discount) {
- if (discount != null) {
- verifyEcommerceState();
- }
- setParameter(ECOMMERCE_DISCOUNT, discount);
- }
-
- /**
- * Get the id of this order.
- *
- * @return the id
- */
- public String getEcommerceId() {
- return (String) getParameter(ECOMMERCE_ID);
- }
-
- /**
- * Set the unique string identifier for the ecommerce order (required when
- * tracking an ecommerce order). Ecommerce must be enabled.
- *
- * @param id the id to set. A null value will remove this parameter
- */
- public void setEcommerceId(String id) {
- if (id != null) {
- verifyEcommerceEnabled();
- }
- setParameter(ECOMMERCE_ID, id);
- }
-
- /**
- * Get the {@link EcommerceItem} at the specified index
- *
- * @param index the index of the {@link EcommerceItem} to return
- * @return the {@link EcommerceItem} at the specified index
- */
- public EcommerceItem getEcommerceItem(int index) {
- return (EcommerceItem) getFromJsonArray(ECOMMERCE_ITEMS, index);
- }
-
- /**
- * Add an {@link EcommerceItem} to this order. Ecommerce must be enabled,
- * and EcommerceId and EcommerceRevenue must first be set.
- *
- * @param item the {@link EcommerceItem} to add. Cannot be null
- */
- public void addEcommerceItem(EcommerceItem item) {
- if (item != null) {
- verifyEcommerceState();
- }
- addToJsonArray(ECOMMERCE_ITEMS, item);
- }
-
- /**
- * Clears all {@link EcommerceItem} from this order.
- */
- public void clearEcommerceItems() {
- removeJsonArray(ECOMMERCE_ITEMS);
- }
-
- /**
- * Get the timestamp of the customer's last ecommerce order
- *
- * @return the timestamp
- */
- public Long getEcommerceLastOrderTimestamp() {
- return (Long) getParameter(ECOMMERCE_LAST_ORDER_TIMESTAMP);
- }
-
- /**
- * Set the UNUX timestamp of this customer's last ecommerce order. This value
- * is used to process the "Days since last order" report. Ecommerce must be
- * enabled, and EcommerceId and EcommerceRevenue must first be set.
- *
- * @param timestamp the timestamp to set. A null value will remove this parameter
- */
- public void setEcommerceLastOrderTimestamp(Long timestamp) {
- if (timestamp != null) {
- verifyEcommerceState();
- }
- setParameter(ECOMMERCE_LAST_ORDER_TIMESTAMP, timestamp);
- }
-
- /**
- * Get the grand total of the ecommerce order.
- *
- * @return the grand total
- */
- public Double getEcommerceRevenue() {
- return (Double) getParameter(ECOMMERCE_REVENUE);
- }
-
- /**
- * Set the grand total of the ecommerce order (required when tracking an
- * ecommerce order). Ecommerce must be enabled.
- *
- * @param revenue the grand total to set. A null value will remove this parameter
- */
- public void setEcommerceRevenue(Double revenue) {
- if (revenue != null) {
- verifyEcommerceEnabled();
- }
- setParameter(ECOMMERCE_REVENUE, revenue);
- }
-
- /**
- * Get the shipping cost of the ecommerce order.
- *
- * @return the shipping cost
- */
- public Double getEcommerceShippingCost() {
- return (Double) getParameter(ECOMMERCE_SHIPPING_COST);
- }
-
- /**
- * Set the shipping cost of the ecommerce order. Ecommerce must be enabled,
- * and EcommerceId and EcommerceRevenue must first be set.
- *
- * @param shippingCost the shipping cost to set. A null value will remove this parameter
- */
- public void setEcommerceShippingCost(Double shippingCost) {
- if (shippingCost != null) {
- verifyEcommerceState();
- }
- setParameter(ECOMMERCE_SHIPPING_COST, shippingCost);
- }
+@Deprecated
+public class PiwikRequest extends MatomoRequest {
/**
- * Get the subtotal of the ecommerce order; excludes shipping.
- *
- * @return the subtotal
- */
- public Double getEcommerceSubtotal() {
- return (Double) getParameter(ECOMMERCE_SUBTOTAL);
- }
-
- /**
- * Set the subtotal of the ecommerce order; excludes shipping. Ecommerce
- * must be enabled and EcommerceId and EcommerceRevenue must first be set.
- *
- * @param subtotal the subtotal to set. A null value will remove this parameter
- */
- public void setEcommerceSubtotal(Double subtotal) {
- if (subtotal != null) {
- verifyEcommerceState();
- }
- setParameter(ECOMMERCE_SUBTOTAL, subtotal);
- }
-
- /**
- * Get the tax amount of the ecommerce order.
- *
- * @return the tax amount
- */
- public Double getEcommerceTax() {
- return (Double) getParameter(ECOMMERCE_TAX);
- }
-
- /**
- * Set the tax amount of the ecommerce order. Ecommerce must be enabled, and
- * EcommerceId and EcommerceRevenue must first be set.
- *
- * @param tax the tax amount to set. A null value will remove this parameter
- */
- public void setEcommerceTax(Double tax) {
- if (tax != null) {
- verifyEcommerceState();
- }
- setParameter(ECOMMERCE_TAX, tax);
- }
-
- /**
- * Get the event action.
- *
- * @return the event action
- */
- public String getEventAction() {
- return getNonEmptyStringParameter(EVENT_ACTION);
- }
-
- /**
- * Set the event action. Must not be empty. (eg. Play, Pause, Duration,
- * Add Playlist, Downloaded, Clicked...).
- *
- * @param eventAction the event action to set. A null value will remove this parameter
- */
- public void setEventAction(String eventAction) {
- setNonEmptyStringParameter(EVENT_ACTION, eventAction);
- }
-
- /**
- * Get the event category.
- *
- * @return the event category
- */
- public String getEventCategory() {
- return getNonEmptyStringParameter(EVENT_CATEGORY);
- }
-
- /**
- * Set the event category. Must not be empty. (eg. Videos, Music, Games...).
- *
- * @param eventCategory the event category to set. A null value will remove this parameter
- */
- public void setEventCategory(String eventCategory) {
- setNonEmptyStringParameter(EVENT_CATEGORY, eventCategory);
- }
-
- /**
- * Get the event name.
- *
- * @return the event name
- */
- public String getEventName() {
- return (String) getParameter(EVENT_NAME);
- }
-
- /**
- * Set the event name. (eg. a Movie name, or Song name, or File name...).
- *
- * @param eventName the event name to set. A null value will remove this parameter
- */
- public void setEventName(String eventName) {
- setParameter(EVENT_NAME, eventName);
- }
-
- /**
- * Get the event value.
- *
- * @return the event value
- */
- public Number getEventValue() {
- return (Number) getParameter(EVENT_VALUE);
- }
-
- /**
- * Set the event value. Must be a float or integer value (numeric), not a string.
- *
- * @param eventValue the event value to set. A null value will remove this parameter
- */
- public void setEventValue(Number eventValue) {
- setParameter(EVENT_VALUE, eventValue);
- }
-
- /**
- * Get the goal id
- *
- * @return the goal id
- */
- public Integer getGoalId() {
- return (Integer) getParameter(GOAL_ID);
- }
-
- /**
- * Set the goal id. If specified, the tracking request will trigger a
- * conversion for the goal of the website being tracked with this id.
- *
- * @param goalId the goal id to set. A null value will remove this parameter
- */
- public void setGoalId(Integer goalId) {
- setParameter(GOAL_ID, goalId);
- }
-
- /**
- * Get the goal revenue.
- *
- * @return the goal revenue
- */
- public Double getGoalRevenue() {
- return (Double) getParameter(GOAL_REVENUE);
- }
-
- /**
- * Set a monetary value that was generated as revenue by this goal conversion.
- * Only used if idgoal is specified in the request.
- *
- * @param goalRevenue the goal revenue to set. A null value will remove this parameter
- */
- public void setGoalRevenue(Double goalRevenue) {
- if (goalRevenue != null && getGoalId() == null) {
- throw new IllegalStateException("GoalId must be set before GoalRevenue can be set.");
- }
- setParameter(GOAL_REVENUE, goalRevenue);
- }
-
- /**
- * Get the Accept-Language HTTP header
- *
- * @return the Accept-Language HTTP header
- */
- public String getHeaderAcceptLanguage() {
- return (String) getParameter(HEADER_ACCEPT_LANGUAGE);
- }
-
- /**
- * Set an override value for the Accept-Language HTTP header
- * field. This value is used to detect the visitor's country if
- * GeoIP is not enabled.
- *
- * @param acceptLangage the Accept-Language HTTP header to set. A null value will remove this parameter
- */
- public void setHeaderAcceptLanguage(String acceptLangage) {
- setParameter(HEADER_ACCEPT_LANGUAGE, acceptLangage);
- }
-
- /**
- * Get the User-Agent HTTP header
- *
- * @return the User-Agent HTTP header
- */
- public String getHeaderUserAgent() {
- return (String) getParameter(HEADER_USER_AGENT);
- }
-
- /**
- * Set an override value for the User-Agent HTTP header field.
- * The user agent is used to detect the operating system and browser used.
- *
- * @param userAgent the User-Agent HTTP header tos et
- */
- public void setHeaderUserAgent(String userAgent) {
- setParameter(HEADER_USER_AGENT, userAgent);
- }
-
- /**
- * Get if this request will force a new visit.
- *
- * @return true if this request will force a new visit
- */
- public Boolean getNewVisit() {
- return getBooleanParameter(NEW_VISIT);
- }
-
- /**
- * If set to true, will force a new visit to be created for this action.
- *
- * @param newVisit if this request will force a new visit
- */
- public void setNewVisit(Boolean newVisit) {
- setBooleanParameter(NEW_VISIT, newVisit);
- }
-
- /**
- * Get the outlink url
- *
- * @return the outlink url
- * @throws TypeConstraintException if the stored Outlink URL is a String
- */
- public URL getOutlinkUrl() {
- return returnAsUrl(OUTLINK_URL, "Outlink URL", "getOutlinkUrlAsString");
- }
-
- /**
- * Get the outlink url
- *
- * @return the outlink url
- * @throws TypeConstraintException if the stored Outlink URL is a URL
- */
- public String getOutlinkUrlAsString() {
- return returnAsString(OUTLINK_URL, "Outlink URL", "getOutlinkUrl");
- }
-
- /**
- * Set an external URL the user has opened. Used for tracking outlink clicks.
- * We recommend to also set the url parameter to this same value.
- *
- * @param outlinkUrl the outlink url to set. A null value will remove this parameter
- */
- public void setOutlinkUrl(URL outlinkUrl) {
- setParameter(OUTLINK_URL, outlinkUrl);
- }
-
- /**
- * Set an external URL the user has opened. Used for tracking outlink clicks.
- * We recommend to also set the url parameter to this same value.
- *
- * @param outlinkUrl the outlink url to set. A null value will remove this parameter
- */
- public void setOutlinkUrlWithString(String outlinkUrl) {
- setParameter(OUTLINK_URL, outlinkUrl);
- }
-
- /**
- * Get the page custom variable at the specified key.
- *
- * @param key the key of the variable to get
- * @return the variable at the specified key, null if key is not present
- * @deprecated Use the {@link #getPageCustomVariable(int)} method instead.
- */
- @Deprecated
- public String getPageCustomVariable(String key) {
- return getCustomVariable(PAGE_CUSTOM_VARIABLE, key);
- }
-
- /**
- * Get the page custom variable at the specified index.
- *
- * @param index the index of the variable to get. Must be greater than 0
- * @return the variable at the specified key, null if nothing at this index
- */
- public CustomVariable getPageCustomVariable(int index) {
- return getCustomVariable(PAGE_CUSTOM_VARIABLE, index);
- }
-
- /**
- * Set a page custom variable with the specified key and value at the first available index.
- * All page custom variables with this key will be overwritten or deleted
- *
- * @param key the key of the variable to set
- * @param value the value of the variable to set at the specified key. A null value will remove this custom variable
- * @deprecated Use the {@link #setPageCustomVariable(CustomVariable, int)} method instead.
- */
- @Deprecated
- public void setPageCustomVariable(String key, String value) {
- if (value == null) {
- removeCustomVariable(PAGE_CUSTOM_VARIABLE, key);
- } else {
- setCustomVariable(PAGE_CUSTOM_VARIABLE, new CustomVariable(key, value), null);
- }
- }
-
- /**
- * Set a page custom variable at the specified index.
- *
- * @param customVariable the CustomVariable to set. A null value will remove the CustomVariable at the specified index
- * @param index the index of he CustomVariable to set
- */
- public void setPageCustomVariable(CustomVariable customVariable, int index) {
- setCustomVariable(PAGE_CUSTOM_VARIABLE, customVariable, index);
- }
-
- /**
- * Check if the visitor has the Director plugin.
- *
- * @return true if visitor has the Director plugin
- */
- public Boolean getPluginDirector() {
- return getBooleanParameter(PLUGIN_DIRECTOR);
- }
-
- /**
- * Set if the visitor has the Director plugin.
- *
- * @param director true if the visitor has the Director plugin
- */
- public void setPluginDirector(Boolean director) {
- setBooleanParameter(PLUGIN_DIRECTOR, director);
- }
-
- /**
- * Check if the visitor has the Flash plugin.
- *
- * @return true if the visitor has the Flash plugin
- */
- public Boolean getPluginFlash() {
- return getBooleanParameter(PLUGIN_FLASH);
- }
-
- /**
- * Set if the visitor has the Flash plugin.
- *
- * @param flash true if the visitor has the Flash plugin
- */
- public void setPluginFlash(Boolean flash) {
- setBooleanParameter(PLUGIN_FLASH, flash);
- }
-
- /**
- * Check if the visitor has the Gears plugin.
- *
- * @return true if the visitor has the Gears plugin
- */
- public Boolean getPluginGears() {
- return getBooleanParameter(PLUGIN_GEARS);
- }
-
- /**
- * Set if the visitor has the Gears plugin.
- *
- * @param gears true if the visitor has the Gears plugin
- */
- public void setPluginGears(Boolean gears) {
- setBooleanParameter(PLUGIN_GEARS, gears);
- }
-
- /**
- * Check if the visitor has the Java plugin.
- *
- * @return true if the visitor has the Java plugin
- */
- public Boolean getPluginJava() {
- return getBooleanParameter(PLUGIN_JAVA);
- }
-
- /**
- * Set if the visitor has the Java plugin.
- *
- * @param java true if the visitor has the Java plugin
- */
- public void setPluginJava(Boolean java) {
- setBooleanParameter(PLUGIN_JAVA, java);
- }
-
- /**
- * Check if the visitor has the PDF plugin.
- *
- * @return true if the visitor has the PDF plugin
- */
- public Boolean getPluginPDF() {
- return getBooleanParameter(PLUGIN_PDF);
- }
-
- /**
- * Set if the visitor has the PDF plugin.
- *
- * @param pdf true if the visitor has the PDF plugin
- */
- public void setPluginPDF(Boolean pdf) {
- setBooleanParameter(PLUGIN_PDF, pdf);
- }
-
- /**
- * Check if the visitor has the Quicktime plugin.
- *
- * @return true if the visitor has the Quicktime plugin
- */
- public Boolean getPluginQuicktime() {
- return getBooleanParameter(PLUGIN_QUICKTIME);
- }
-
- /**
- * Set if the visitor has the Quicktime plugin.
- *
- * @param quicktime true if the visitor has the Quicktime plugin
- */
- public void setPluginQuicktime(Boolean quicktime) {
- setBooleanParameter(PLUGIN_QUICKTIME, quicktime);
- }
-
- /**
- * Check if the visitor has the RealPlayer plugin.
- *
- * @return true if the visitor has the RealPlayer plugin
- */
- public Boolean getPluginRealPlayer() {
- return getBooleanParameter(PLUGIN_REAL_PLAYER);
- }
-
- /**
- * Set if the visitor has the RealPlayer plugin.
- *
- * @param realPlayer true if the visitor has the RealPlayer plugin
- */
- public void setPluginRealPlayer(Boolean realPlayer) {
- setBooleanParameter(PLUGIN_REAL_PLAYER, realPlayer);
- }
-
- /**
- * Check if the visitor has the Silverlight plugin.
- *
- * @return true if the visitor has the Silverlight plugin
- */
- public Boolean getPluginSilverlight() {
- return getBooleanParameter(PLUGIN_SILVERLIGHT);
- }
-
- /**
- * Set if the visitor has the Silverlight plugin.
- *
- * @param silverlight true if the visitor has the Silverlight plugin
- */
- public void setPluginSilverlight(Boolean silverlight) {
- setBooleanParameter(PLUGIN_SILVERLIGHT, silverlight);
- }
-
- /**
- * Check if the visitor has the Windows Media plugin.
- *
- * @return true if the visitor has the Windows Media plugin
- */
- public Boolean getPluginWindowsMedia() {
- return getBooleanParameter(PLUGIN_WINDOWS_MEDIA);
- }
-
- /**
- * Set if the visitor has the Windows Media plugin.
- *
- * @param windowsMedia true if the visitor has the Windows Media plugin
- */
- public void setPluginWindowsMedia(Boolean windowsMedia) {
- setBooleanParameter(PLUGIN_WINDOWS_MEDIA, windowsMedia);
- }
-
- /**
- * Get the random value for this request
- *
- * @return the random value
- */
- public String getRandomValue() {
- return (String) getParameter(RANDOM_VALUE);
- }
-
- /**
- * Set a random value that is generated before each request. Using it helps
- * avoid the tracking request being cached by the browser or a proxy.
- *
- * @param randomValue the random value to set. A null value will remove this parameter
- */
- public void setRandomValue(String randomValue) {
- setParameter(RANDOM_VALUE, randomValue);
- }
-
- /**
- * Get the referrer url
- *
- * @return the referrer url
- * @throws TypeConstraintException if the stored Referrer URL is a String
- */
- public URL getReferrerUrl() {
- return returnAsUrl(REFERRER_URL, "Referrer URL", "getReferrerUrlAsString");
- }
-
- /**
- * Get the referrer url
- *
- * @return the referrer url
- * @throws TypeConstraintException if the stored Referrer URL is a URL
- */
- public String getReferrerUrlAsString() {
- return returnAsString(REFERRER_URL, "Referrer URL", "getReferrerUrl");
- }
-
- /**
- * Set the full HTTP Referrer URL. This value is used to determine how someone
- * got to your website (ie, through a website, search engine or campaign).
- *
- * @param referrerUrl the referrer url to set. A null value will remove this parameter
- */
- public void setReferrerUrl(URL referrerUrl) {
- setParameter(REFERRER_URL, referrerUrl);
- }
-
- /**
- * Set the full HTTP Referrer URL. This value is used to determine how someone
- * got to your website (ie, through a website, search engine or campaign).
- *
- * @param referrerUrl the referrer url to set. A null value will remove this parameter
- */
- public void setReferrerUrlWithString(String referrerUrl) {
- setParameter(REFERRER_URL, referrerUrl);
- }
-
- /**
- * Get the datetime of the request
- *
- * @return the datetime of the request
- */
- public PiwikDate getRequestDatetime() {
- return (PiwikDate) getParameter(REQUEST_DATETIME);
- }
-
- /**
- * Set the datetime of the request (normally the current time is used).
- * This can be used to record visits and page views in the past. The datetime
- * must be sent in UTC timezone. Note: if you record data in the past, you will
- * need to force Piwik to re-process
- * reports for the past dates. If you set the Request Datetime to a datetime
- * older than four hours then Auth Token must be set. If you set
- * Request Datetime with a datetime in the last four hours then you
- * don't need to pass Auth Token.
- *
- * @param datetime the datetime of the request to set. A null value will remove this parameter
- */
- public void setRequestDatetime(PiwikDate datetime) {
- if (datetime != null && new Date().getTime() - datetime.getTime() > REQUEST_DATETIME_AUTH_LIMIT && getAuthToken() == null) {
- throw new IllegalStateException("Because you are trying to set RequestDatetime for a time greater than 4 hours ago, AuthToken must be set first.");
- }
- setParameter(REQUEST_DATETIME, datetime);
- }
-
- /**
- * Get if this request will be tracked.
- *
- * @return true if request will be tracked
- */
- public Boolean getRequired() {
- return getBooleanParameter(REQUIRED);
- }
-
- /**
- * Set if this request will be tracked by the Piwik server.
- *
- * @param required true if request will be tracked
- */
- public void setRequired(Boolean required) {
- setBooleanParameter(REQUIRED, required);
- }
-
- /**
- * Get if the response will be an image.
- *
- * @return true if the response will be an an image
- */
- public Boolean getResponseAsImage() {
- return getBooleanParameter(RESPONSE_AS_IMAGE);
- }
-
- /**
- * Set if the response will be an image. If set to false, Piwik will respond
- * with a HTTP 204 response code instead of a GIF image. This improves performance
- * and can fix errors if images are not allowed to be obtained directly
- * (eg Chrome Apps). Available since Piwik 2.10.0.
- *
- * @param responseAsImage true if the response will be an image
- */
- public void setResponseAsImage(Boolean responseAsImage) {
- setBooleanParameter(RESPONSE_AS_IMAGE, responseAsImage);
- }
-
- /**
- * Get the search category
- *
- * @return the search category
- */
- public String getSearchCategory() {
- return (String) getParameter(SEARCH_CATEGORY);
- }
-
- /**
- * Specify a search category with this parameter. SearchQuery must first be
- * set.
- *
- * @param searchCategory the search category to set. A null value will remove this parameter
- */
- public void setSearchCategory(String searchCategory) {
- if (searchCategory != null && getSearchQuery() == null) {
- throw new IllegalStateException("SearchQuery must be set before SearchCategory can be set.");
- }
- setParameter(SEARCH_CATEGORY, searchCategory);
- }
-
- /**
- * Get the search query.
- *
- * @return the search query
- */
- public String getSearchQuery() {
- return (String) getParameter(SEARCH_QUERY);
- }
-
- /**
- * Set the search query. When specified, the request will not be tracked as
- * a normal pageview but will instead be tracked as a Site Search request.
- *
- * @param searchQuery the search query to set. A null value will remove this parameter
- */
- public void setSearchQuery(String searchQuery) {
- setParameter(SEARCH_QUERY, searchQuery);
- }
-
- /**
- * Get the search results count.
- *
- * @return the search results count
- */
- public Long getSearchResultsCount() {
- return (Long) getParameter(SEARCH_RESULTS_COUNT);
- }
-
- /**
- * We recommend to set the
- * search count to the number of search results displayed on the results page.
- * When keywords are tracked with {@code Search Results Count=0} they will appear in
- * the "No Result Search Keyword" report. SearchQuery must first be set.
- *
- * @param searchResultsCount the search results count to set. A null value will remove this parameter
- */
- public void setSearchResultsCount(Long searchResultsCount) {
- if (searchResultsCount != null && getSearchQuery() == null) {
- throw new IllegalStateException("SearchQuery must be set before SearchResultsCount can be set.");
- }
- setParameter(SEARCH_RESULTS_COUNT, searchResultsCount);
- }
-
- /**
- * Get the id of the website we're tracking.
- *
- * @return the id of the website
- */
- public Integer getSiteId() {
- return (Integer) getParameter(SITE_ID);
- }
-
- /**
- * Set the ID of the website we're tracking a visit/action for.
- *
- * @param siteId the id of the website to set. A null value will remove this parameter
- */
- public void setSiteId(Integer siteId) {
- setParameter(SITE_ID, siteId);
- }
-
- /**
- * Set if bot requests should be tracked
- *
- * @return true if bot requests should be tracked
- */
- public Boolean getTrackBotRequests() {
- return getBooleanParameter(TRACK_BOT_REQUESTS);
- }
-
- /**
- * By default Piwik does not track bots. If you use the Tracking Java API,
- * you may be interested in tracking bot requests. To enable Bot Tracking in
- * Piwik, set Track Bot Requests to true.
- *
- * @param trackBotRequests true if bot requests should be tracked
- */
- public void setTrackBotRequests(Boolean trackBotRequests) {
- setBooleanParameter(TRACK_BOT_REQUESTS, trackBotRequests);
- }
-
- /**
- * Get the visit custom variable at the specified key.
- *
- * @param key the key of the variable to get
- * @return the variable at the specified key, null if key is not present
- * @deprecated Use the {@link #getVisitCustomVariable(int)} method instead.
- */
- @Deprecated
- public String getUserCustomVariable(String key) {
- return getCustomVariable(VISIT_CUSTOM_VARIABLE, key);
- }
-
- /**
- * Get the visit custom variable at the specified index.
- *
- * @param index the index of the variable to get
- * @return the variable at the specified index, null if nothing at this index
- */
- public CustomVariable getVisitCustomVariable(int index) {
- return getCustomVariable(VISIT_CUSTOM_VARIABLE, index);
- }
-
- /**
- * Set a visit custom variable with the specified key and value at the first available index.
- * All visit custom variables with this key will be overwritten or deleted
- *
- * @param key the key of the variable to set
- * @param value the value of the variable to set at the specified key. A null value will remove this parameter
- * @deprecated Use the {@link #setVisitCustomVariable(CustomVariable, int)} method instead.
+ * @deprecated Use {@link MatomoRequest} instead.
*/
@Deprecated
- public void setUserCustomVariable(String key, String value) {
- if (value == null) {
- removeCustomVariable(VISIT_CUSTOM_VARIABLE, key);
- } else {
- setCustomVariable(VISIT_CUSTOM_VARIABLE, new CustomVariable(key, value), null);
- }
- }
-
- /**
- * Set a user custom variable at the specified key.
- *
- * @param customVariable the CustomVariable to set. A null value will remove the custom variable at the specified index
- * @param index the index to set the customVariable at.
- */
- public void setVisitCustomVariable(CustomVariable customVariable, int index) {
- setCustomVariable(VISIT_CUSTOM_VARIABLE, customVariable, index);
- }
-
- /**
- * Get the user id for this request.
- *
- * @return the user id
- */
- public String getUserId() {
- return (String) getParameter(USER_ID);
- }
-
- /**
- * Set the user id for this request.
- * User id is any non empty unique string identifying the user (such as an email
- * address or a username). To access this value, users must be logged-in in your
- * system so you can fetch this user id from your system, and pass it to Piwik.
- * The user id appears in the visitor log, the Visitor profile, and you can
- * Segment
- * reports for one or several user ids. When specified, the user id will be
- * "enforced". This means that if there is no recent visit with this user id,
- * a new one will be created. If a visit is found in the last 30 minutes with
- * your specified user id, then the new action will be recorded to this existing visit.
- *
- * @param userId the user id to set. A null value will remove this parameter
- */
- public void setUserId(String userId) {
- setNonEmptyStringParameter(USER_ID, userId);
- }
-
- /**
- * Get the visitor's city.
- *
- * @return the visitor's city
- */
- public String getVisitorCity() {
- return (String) getParameter(VISITOR_CITY);
- }
-
- /**
- * Set an override value for the city. The name of the city the visitor is
- * located in, eg, Tokyo. AuthToken must first be set.
- *
- * @param city the visitor's city to set. A null value will remove this parameter
- */
- public void setVisitorCity(String city) {
- if (city != null) {
- verifyAuthTokenSet();
- }
- setParameter(VISITOR_CITY, city);
- }
-
- /**
- * Get the visitor's country.
- *
- * @return the visitor's country
- */
- public PiwikLocale getVisitorCountry() {
- return (PiwikLocale) getParameter(VISITOR_COUNTRY);
- }
-
- /**
- * Set an override value for the country. AuthToken must first be set.
- *
- * @param country the visitor's country to set. A null value will remove this parameter
- */
- public void setVisitorCountry(PiwikLocale country) {
- if (country != null) {
- verifyAuthTokenSet();
- }
- setParameter(VISITOR_COUNTRY, country);
- }
-
- /**
- * Get the visitor's custom id.
- *
- * @return the visitor's custom id
- */
- public String getVisitorCustomId() {
- return (String) getParameter(VISITOR_CUSTOM_ID);
- }
-
- /**
- * Set a custom visitor ID for this request. You must set this value to exactly
- * a {@value #ID_LENGTH} character hexadecimal string (containing only characters 01234567890abcdefABCDEF).
- * We recommended to set the UserId rather than the VisitorCustomId.
- *
- * @param visitorCustomId the visitor's custom id to set. A null value will remove this parameter
- */
- public void setVisitorCustomId(String visitorCustomId) {
- if (visitorCustomId != null) {
- if (visitorCustomId.length() != ID_LENGTH) {
- throw new IllegalArgumentException(visitorCustomId + " is not " + ID_LENGTH + " characters long.");
- }
- // Verify visitorID is a 16 character hexadecimal string
- else if (!visitorCustomId.matches("[0-9A-Fa-f]+")) {
- throw new IllegalArgumentException(visitorCustomId + " is not a hexadecimal string.");
- }
- }
- setParameter(VISITOR_CUSTOM_ID, visitorCustomId);
- }
-
- /**
- * Get the timestamp of the visitor's first visit.
- *
- * @return the timestamp of the visitor's first visit
- */
- public Long getVisitorFirstVisitTimestamp() {
- return (Long) getParameter(VISITOR_FIRST_VISIT_TIMESTAMP);
- }
-
- /**
- * Set the UNIX timestamp of this visitor's first visit. This could be set
- * to the date where the user first started using your software/app, or when
- * he/she created an account. This parameter is used to populate the
- * Goals > Days to Conversion report.
- *
- * @param timestamp the timestamp of the visitor's first visit to set. A null value will remove this parameter
- */
- public void setVisitorFirstVisitTimestamp(Long timestamp) {
- setParameter(VISITOR_FIRST_VISIT_TIMESTAMP, timestamp);
- }
-
- /**
- * Get the visitor's id.
- *
- * @return the visitor's id
- */
- public String getVisitorId() {
- return (String) getParameter(VISITOR_ID);
- }
-
- /**
- * Set the unique visitor ID, must be a {@value #ID_LENGTH} characters hexadecimal string.
- * Every unique visitor must be assigned a different ID and this ID must not
- * change after it is assigned. If this value is not set Piwik will still
- * track visits, but the unique visitors metric might be less accurate.
- *
- * @param visitorId the visitor id to set. A null value will remove this parameter
- */
- public void setVisitorId(String visitorId) {
- if (visitorId != null) {
- if (visitorId.length() != ID_LENGTH) {
- throw new IllegalArgumentException(visitorId + " is not " + ID_LENGTH + " characters long.");
- }
- // Verify visitorID is a 16 character hexadecimal string
- else if (!visitorId.matches("[0-9A-Fa-f]+")) {
- throw new IllegalArgumentException(visitorId + " is not a hexadecimal string.");
- }
- }
- setParameter(VISITOR_ID, visitorId);
- }
-
- /**
- * Get the visitor's ip.
- *
- * @return the visitor's ip
- */
- public String getVisitorIp() {
- return (String) getParameter(VISITOR_IP);
- }
-
- /**
- * Set the override value for the visitor IP (both IPv4 and IPv6 notations
- * supported). AuthToken must first be set.
- *
- * @param visitorIp the visitor's ip to set. A null value will remove this parameter
- */
- public void setVisitorIp(String visitorIp) {
- if (visitorIp != null) {
- verifyAuthTokenSet();
- }
- setParameter(VISITOR_IP, visitorIp);
- }
-
- /**
- * Get the visitor's latitude.
- *
- * @return the visitor's latitude
- */
- public Double getVisitorLatitude() {
- return (Double) getParameter(VISITOR_LATITUDE);
- }
-
- /**
- * Set an override value for the visitor's latitude, eg 22.456. AuthToken
- * must first be set.
- *
- * @param latitude the visitor's latitude to set. A null value will remove this parameter
- */
- public void setVisitorLatitude(Double latitude) {
- if (latitude != null) {
- verifyAuthTokenSet();
- }
- setParameter(VISITOR_LATITUDE, latitude);
- }
-
- /**
- * Get the visitor's longitude.
- *
- * @return the visitor's longitude
- */
- public Double getVisitorLongitude() {
- return (Double) getParameter(VISITOR_LONGITUDE);
- }
-
- /**
- * Set an override value for the visitor's longitude, eg 22.456. AuthToken
- * must first be set.
- *
- * @param longitude the visitor's longitude to set. A null value will remove this parameter
- */
- public void setVisitorLongitude(Double longitude) {
- if (longitude != null) {
- verifyAuthTokenSet();
- }
- setParameter(VISITOR_LONGITUDE, longitude);
- }
-
- /**
- * Get the timestamp of the visitor's previous visit.
- *
- * @return the timestamp of the visitor's previous visit
- */
- public Long getVisitorPreviousVisitTimestamp() {
- return (Long) getParameter(VISITOR_PREVIOUS_VISIT_TIMESTAMP);
- }
-
- /**
- * Set the UNIX timestamp of this visitor's previous visit. This parameter
- * is used to populate the report
- * Visitors > Engagement > Visits by days since last visit.
- *
- * @param timestamp the timestamp of the visitor's previous visit to set. A null value will remove this parameter
- */
- public void setVisitorPreviousVisitTimestamp(Long timestamp) {
- setParameter(VISITOR_PREVIOUS_VISIT_TIMESTAMP, timestamp);
- }
-
- /**
- * Get the visitor's region.
- *
- * @return the visitor's region
- */
- public String getVisitorRegion() {
- return (String) getParameter(VISITOR_REGION);
- }
-
- /**
- * Set an override value for the region. Should be set to the two letter
- * region code as defined by
- * MaxMind's GeoIP databases.
- * See here
- * for a list of them for every country (the region codes are located in the
- * second column, to the left of the region name and to the right of the country
- * code).
- *
- * @param region the visitor's region to set. A null value will remove this parameter
- */
- public void setVisitorRegion(String region) {
- if (region != null) {
- verifyAuthTokenSet();
- }
- setParameter(VISITOR_REGION, region);
- }
-
- /**
- * Get the count of visits for this visitor.
- *
- * @return the count of visits for this visitor
- */
- public Integer getVisitorVisitCount() {
- return (Integer) getParameter(VISITOR_VISIT_COUNT);
- }
-
- /**
- * Set the current count of visits for this visitor. To set this value correctly,
- * it would be required to store the value for each visitor in your application
- * (using sessions or persisting in a database). Then you would manually increment
- * the counts by one on each new visit or "session", depending on how you choose
- * to define a visit. This value is used to populate the report
- * Visitors > Engagement > Visits by visit number.
- *
- * @param visitorVisitCount the count of visits for this visitor to set. A null value will remove this parameter
- */
- public void setVisitorVisitCount(Integer visitorVisitCount) {
- setParameter(VISITOR_VISIT_COUNT, visitorVisitCount);
- }
-
- /**
- * Get the query string represented by this object.
- *
- * @return the query string represented by this object
- */
-
- public String getQueryString() {
- StringBuilder sb = new StringBuilder();
- for (Entry parameter : parameters.entrySet()) {
- if (sb.length() > 0) {
- sb.append("&");
- }
- sb.append(parameter.getKey());
- sb.append("=");
- sb.append(parameter.getValue().toString());
- }
- for (Entry customTrackingParameter : customTrackingParameters.entrySet()) {
- for (Object o : customTrackingParameter.getValue()) {
- if (sb.length() > 0) {
- sb.append("&");
- }
- sb.append(customTrackingParameter.getKey());
- sb.append("=");
- sb.append(o.toString());
- }
- }
-
- return sb.toString();
- }
-
- /**
- * Get the url encoded query string represented by this object.
- *
- * @return the url encoded query string represented by this object
- */
- public String getUrlEncodedQueryString() {
- StringBuilder sb = new StringBuilder();
- for (Entry parameter : parameters.entrySet()) {
- if (sb.length() > 0) {
- sb.append("&");
- }
- try {
- StringBuilder sb2 = new StringBuilder();
- sb2.append(parameter.getKey());
- sb2.append("=");
- sb2.append(URLEncoder.encode(parameter.getValue().toString(), "UTF-8"));
- sb.append(sb2);
- } catch (UnsupportedEncodingException e) {
- System.err.println(e.getMessage());
- }
- }
- for (Entry customTrackingParameter : customTrackingParameters.entrySet()) {
- for (Object o : customTrackingParameter.getValue()) {
- if (sb.length() > 0) {
- sb.append("&");
- }
- try {
- StringBuilder sb2 = new StringBuilder();
- sb2.append(URLEncoder.encode(customTrackingParameter.getKey(), "UTF-8"));
- sb2.append("=");
- sb2.append(URLEncoder.encode(o.toString(), "UTF-8"));
- sb.append(sb2);
- } catch (UnsupportedEncodingException e) {
- System.err.println(e.getMessage());
- }
- }
- }
-
- return sb.toString();
- }
-
- /**
- * Get a random hexadecimal string of a specified length.
- *
- * @param length length of the string to produce
- * @return a random string consisting only of hexadecimal characters
- */
- public static String getRandomHexString(int length) {
- byte[] bytes = new byte[length / 2];
- new Random().nextBytes(bytes);
- return DatatypeConverter.printHexBinary(bytes);
- }
-
- /**
- * Get a stored parameter.
- *
- * @param key the parameter's key
- * @return the stored parameter's value
- */
- private Object getParameter(String key) {
- return parameters.get(key);
- }
-
- /**
- * Set a stored parameter.
- *
- * @param key the parameter's key
- * @param value the parameter's value. Removes the parameter if null
- */
- private void setParameter(String key, Object value) {
- if (value == null) {
- parameters.remove(key);
- } else {
- parameters.put(key, value);
- }
- }
-
- /**
- * Get a stored parameter that is a non-empty string.
- *
- * @param key the parameter's key
- * @return the stored parameter's value
- */
- private String getNonEmptyStringParameter(String key) {
- return (String) parameters.get(key);
- }
-
- /**
- * Set a stored parameter and verify it is a non-empty string.
- *
- * @param key the parameter's key
- * @param value the parameter's value. Cannot be the empty. Removes the parameter if null
- * string
- */
- private void setNonEmptyStringParameter(String key, String value) {
- if (value == null) {
- parameters.remove(key);
- } else if (value.length() == 0) {
- throw new IllegalArgumentException("Value cannot be empty.");
- } else {
- parameters.put(key, value);
- }
- }
-
- /**
- * Get a stored parameter that is a boolean.
- *
- * @param key the parameter's key
- * @return the stored parameter's value
- */
- private Boolean getBooleanParameter(String key) {
- Integer i = (Integer) parameters.get(key);
- if (i == null) {
- return null;
- }
- return i.equals(1);
- }
-
- /**
- * Set a stored parameter that is a boolean. This value will be stored as "1"
- * for true and "0" for false.
- *
- * @param key the parameter's key
- * @param value the parameter's value. Removes the parameter if null
- */
- private void setBooleanParameter(String key, Boolean value) {
- if (value == null) {
- parameters.remove(key);
- } else if (value) {
- parameters.put(key, 1);
- } else {
- parameters.put(key, 0);
- }
- }
-
- /**
- * Get a value that is stored in a json object at the specified parameter.
- *
- * @param parameter the parameter to retrieve the json object from
- * @param key the key of the value. Cannot be null
- * @return the value
- */
- private CustomVariable getCustomVariable(String parameter, int index) {
- CustomVariableList cvl = (CustomVariableList) parameters.get(parameter);
- if (cvl == null) {
- return null;
- }
-
- return cvl.get(index);
- }
-
- private String getCustomVariable(String parameter, String key) {
- if (key == null) {
- throw new NullPointerException("Key cannot be null.");
- }
-
- CustomVariableList cvl = (CustomVariableList) parameters.get(parameter);
- if (cvl == null) {
- return null;
- }
-
- return cvl.get(key);
- }
-
- /**
- * Store a value in a json object at the specified parameter.
- *
- * @param parameter the parameter to store the json object at
- * @param key the key of the value. Cannot be null
- * @param value the value. Removes the parameter if null
- */
- private void setCustomVariable(String parameter, CustomVariable customVariable, Integer index) {
- CustomVariableList cvl = (CustomVariableList) parameters.get(parameter);
- if (cvl == null) {
- cvl = new CustomVariableList();
- parameters.put(parameter, cvl);
- }
-
- if (customVariable == null) {
- cvl.remove(index);
- if (cvl.isEmpty()) {
- parameters.remove(parameter);
- }
- } else if (index == null) {
- cvl.add(customVariable);
- } else {
- cvl.add(customVariable, index);
- }
- }
-
- private void removeCustomVariable(String parameter, String key) {
- if (key == null) {
- throw new NullPointerException("Key cannot be null.");
- }
- CustomVariableList cvl = (CustomVariableList) parameters.get(parameter);
- if (cvl != null) {
- cvl.remove(key);
- if (cvl.isEmpty()) {
- parameters.remove(parameter);
- }
- }
- }
-
- /**
- * Get the value at the specified index from the json array at the specified
- * parameter.
- *
- * @param key the key of the json array to access
- * @param index the index of the value in the json array
- * @return the value at the index in the json array
- */
- private JsonValue getFromJsonArray(String key, int index) {
- PiwikJsonArray a = (PiwikJsonArray) parameters.get(key);
- if (a == null) {
- return null;
- }
-
- return a.get(index);
- }
-
- /**
- * Add a value to the json array at the specified parameter
- *
- * @param key the key of the json array to add to
- * @param value the value to add. Cannot be null
- */
- private void addToJsonArray(String key, JsonValue value) {
- if (value == null) {
- throw new NullPointerException("Value cannot be null.");
- }
-
- PiwikJsonArray a = (PiwikJsonArray) parameters.get(key);
- if (a == null) {
- a = new PiwikJsonArray();
- parameters.put(key, a);
- }
- a.add(value);
- }
-
- /**
- * Removes the json array at the specified parameter
- *
- * @param key the key of the json array to remove
- */
- private void removeJsonArray(String key) {
- parameters.remove(key);
- }
-
- private URL returnAsUrl(String parameter, String name, String altMethod) {
- Object obj = getParameter(parameter);
- if (obj == null) {
- return null;
- }
- if (obj instanceof URL) {
- return (URL) obj;
- }
- throw new TypeConstraintException("The stored " + name +
- " is a String, not a URL. Use \"" +
- altMethod + "\" instead.");
- }
-
- private String returnAsString(String parameter, String name, String altMethod) {
- Object obj = getParameter(parameter);
- if (obj == null) {
- return null;
- }
- if (obj instanceof String) {
- return (String) obj;
- }
- throw new TypeConstraintException("The stored " + name +
- " is a URL, not a String. Use \"" +
- altMethod + "\" instead.");
+ public PiwikRequest(int siteId, @NonNull URL actionUrl) {
+ super(siteId, actionUrl.toString());
}
}
diff --git a/src/main/java/org/piwik/java/tracking/PiwikTracker.java b/src/main/java/org/piwik/java/tracking/PiwikTracker.java
index a0ec1201..4e91e0b0 100644
--- a/src/main/java/org/piwik/java/tracking/PiwikTracker.java
+++ b/src/main/java/org/piwik/java/tracking/PiwikTracker.java
@@ -1,297 +1,50 @@
/*
- * Piwik Java Tracker
+ * Matomo Java Tracker
*
- * @link https://github.com/piwik/piwik-java-tracker
- * @license https://github.com/piwik/piwik-java-tracker/blob/master/LICENSE BSD-3 Clause
+ * @link https://github.com/matomo/matomo-java-tracker
+ * @license https://github.com/matomo/matomo-java-tracker/blob/master/LICENSE BSD-3 Clause
*/
package org.piwik.java.tracking;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.concurrent.Future;
-import javax.json.Json;
-import javax.json.JsonArrayBuilder;
-import javax.json.JsonObjectBuilder;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.utils.URIBuilder;
-import org.apache.http.concurrent.FutureCallback;
-import org.apache.http.entity.ContentType;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.matomo.java.tracking.MatomoTracker;
/**
- * A class that sends {@link PiwikRequest}s to a specified Piwik server.
- *
* @author brettcsorba
+ * @deprecated Use {@link MatomoTracker} instead.
*/
-public class PiwikTracker {
- private static final String AUTH_TOKEN = "token_auth";
- private static final String REQUESTS = "requests";
- private static final int DEFAULT_TIMEOUT = 5000;
- private final URIBuilder uriBuilder;
- private final int timeout;
- private final String proxyHost;
- private final int proxyPort;
+@Deprecated
+public class PiwikTracker extends MatomoTracker {
/**
- * Creates a tracker that will send {@link PiwikRequest}s to the specified
- * Tracking HTTP API endpoint.
- *
- * @param hostUrl url endpoint to send requests to. Usually in the format
- * http://your-piwik-domain.tld/piwik.php.
+ * @deprecated Use {@link MatomoTracker} instead.
*/
+ @Deprecated
public PiwikTracker(final String hostUrl) {
- this(hostUrl, DEFAULT_TIMEOUT);
- }
-
- /**
- * Creates a tracker that will send {@link PiwikRequest}s to the specified
- * Tracking HTTP API endpoint.
- *
- * @param hostUrl url endpoint to send requests to. Usually in the format
- * http://your-piwik-domain.tld/piwik.php.
- * @param timeout the timeout of the sent request in milliseconds
- */
- public PiwikTracker(final String hostUrl, final int timeout) {
- uriBuilder = new URIBuilder(URI.create(hostUrl));
- this.timeout = timeout;
- this.proxyHost = null;
- this.proxyPort = 0;
- }
-
- /**
- * Creates a tracker that will send {@link PiwikRequest}s to the specified
- * Tracking HTTP API endpoint via the provided proxy
- *
- * @param hostUrl url endpoint to send requests to. Usually in the format
- * http://your-piwik-domain.tld/piwik.php.
- * @param proxyHost url endpoint for the proxy
- * @param proxyPort proxy server port number
- */
- public PiwikTracker(final String hostUrl, final String proxyHost, final int proxyPort) {
- this(hostUrl, proxyHost, proxyPort, DEFAULT_TIMEOUT);
- }
-
- public PiwikTracker(final String hostUrl, final String proxyHost, final int proxyPort, final int timeout) {
- uriBuilder = new URIBuilder(URI.create(hostUrl));
- this.proxyHost = proxyHost;
- this.proxyPort = proxyPort;
- this.timeout = timeout;
+ super(hostUrl);
}
/**
- * Send a request.
- *
- * @param request request to send
- * @return the response from this request
- * @throws IOException thrown if there was a problem with this connection
- * @deprecated use sendRequestAsync instead
+ * @deprecated Use {@link MatomoTracker} instead.
*/
@Deprecated
- public HttpResponse sendRequest(final PiwikRequest request) throws IOException {
- final HttpClient client = getHttpClient();
- uriBuilder.setCustomQuery(request.getQueryString());
- HttpGet get = null;
-
- try {
- get = new HttpGet(uriBuilder.build());
- return client.execute(get);
- } catch (final URISyntaxException e) {
- throw new IOException(e);
- }
- }
-
- /**
- * Send a request.
- *
- * @param request request to send
- * @return future with response from this request
- * @throws IOException thrown if there was a problem with this connection
- */
- public Future sendRequestAsync(final PiwikRequest request) throws IOException {
- return sendRequestAsync(request, null);
- }
- /**
- * Send a request.
- *
- * @param request request to send
- * @param callback callback that gets executed when response arrives
- * @return future with response from this request
- * @throws IOException thrown if there was a problem with this connection
- */
- public Future sendRequestAsync(final PiwikRequest request, FutureCallback callback) throws IOException {
- final CloseableHttpAsyncClient client = getHttpAsyncClient();
- client.start();
- uriBuilder.setCustomQuery(request.getQueryString());
- HttpGet get = null;
-
- try {
- get = new HttpGet(uriBuilder.build());
- return client.execute(get, callback);
- } catch (final URISyntaxException e) {
- throw new IOException(e);
- }
+ public PiwikTracker(final String hostUrl, final int timeout) {
+ super(hostUrl, timeout);
}
/**
- * Send multiple requests in a single HTTP call. More efficient than sending
- * several individual requests.
- *
- * @param requests the requests to send
- * @return the response from these requests
- * @throws IOException thrown if there was a problem with this connection
- * @deprecated use sendBulkRequestAsync instead
+ * @deprecated Use {@link MatomoTracker} instead.
*/
@Deprecated
- public HttpResponse sendBulkRequest(final Iterable requests) throws IOException {
- return sendBulkRequest(requests, null);
- }
-
- /**
- * Send multiple requests in a single HTTP call. More efficient than sending
- * several individual requests.
- *
- * @param requests the requests to send
- * @return future with response from these requests
- * @throws IOException thrown if there was a problem with this connection
- */
- public Future sendBulkRequestAsync(final Iterable requests) throws IOException {
- return sendBulkRequestAsync(requests, null, null);
- }
-
- /**
- * Send multiple requests in a single HTTP call. More efficient than sending
- * several individual requests.
- *
- * @param requests the requests to send
- * @param callback callback that gets executed when response arrives
- * @return future with response from these requests
- * @throws IOException thrown if there was a problem with this connection
- */
- public Future sendBulkRequestAsync(final Iterable requests, FutureCallback callback) throws IOException {
- return sendBulkRequestAsync(requests, null, callback);
+ public PiwikTracker(final String hostUrl, final String proxyHost, final int proxyPort) {
+ super(hostUrl, proxyHost, proxyPort);
}
/**
- * Send multiple requests in a single HTTP call. More efficient than sending
- * several individual requests. Specify the AuthToken if parameters that require
- * an auth token is used.
- *
- * @param requests the requests to send
- * @param authToken specify if any of the parameters use require AuthToken
- * @return the response from these requests
- * @throws IOException thrown if there was a problem with this connection
- * @deprecated use sendBulkRequestAsync instead
+ * @deprecated Use {@link MatomoTracker} instead.
*/
@Deprecated
- public HttpResponse sendBulkRequest(final Iterable requests, final String authToken) throws IOException {
- if (authToken != null && authToken.length() != PiwikRequest.AUTH_TOKEN_LENGTH) {
- throw new IllegalArgumentException(authToken + " is not " + PiwikRequest.AUTH_TOKEN_LENGTH + " characters long.");
- }
-
- final JsonObjectBuilder ob = Json.createObjectBuilder();
- final JsonArrayBuilder ab = Json.createArrayBuilder();
-
- for (final PiwikRequest request : requests) {
- ab.add("?" + request.getQueryString());
- }
-
- ob.add(REQUESTS, ab);
-
- if (authToken != null) {
- ob.add(AUTH_TOKEN, authToken);
- }
-
- final HttpClient client = getHttpClient();
- HttpPost post = null;
-
- try {
- post = new HttpPost(uriBuilder.build());
- post.setEntity(new StringEntity(ob.build().toString(),
- ContentType.APPLICATION_JSON));
- return client.execute(post);
- } catch (final URISyntaxException e) {
- throw new IOException(e);
- }
- }
-
- /**
- * Send multiple requests in a single HTTP call. More efficient than sending
- * several individual requests. Specify the AuthToken if parameters that require
- * an auth token is used.
- *
- * @param requests the requests to send
- * @param authToken specify if any of the parameters use require AuthToken
- * @return the response from these requests
- * @throws IOException thrown if there was a problem with this connection
- */
- public Future sendBulkRequestAsync(final Iterable requests, final String authToken) throws IOException {
- return sendBulkRequestAsync(requests, authToken, null);
- }
-
- /**
- * Send multiple requests in a single HTTP call. More efficient than sending
- * several individual requests. Specify the AuthToken if parameters that require
- * an auth token is used.
- *
- * @param requests the requests to send
- * @param authToken specify if any of the parameters use require AuthToken
- * @param callback callback that gets executed when response arrives
- * @return the response from these requests
- * @throws IOException thrown if there was a problem with this connection
- */
- public Future sendBulkRequestAsync(final Iterable requests, final String authToken,
- FutureCallback callback) throws IOException {
- if (authToken != null && authToken.length() != PiwikRequest.AUTH_TOKEN_LENGTH) {
- throw new IllegalArgumentException(authToken + " is not " + PiwikRequest.AUTH_TOKEN_LENGTH + " characters long.");
- }
-
- final JsonObjectBuilder ob = Json.createObjectBuilder();
- final JsonArrayBuilder ab = Json.createArrayBuilder();
-
- for (final PiwikRequest request : requests) {
- ab.add("?" + request.getQueryString());
- }
-
- ob.add(REQUESTS, ab);
-
- if (authToken != null) {
- ob.add(AUTH_TOKEN, authToken);
- }
-
- final CloseableHttpAsyncClient client = getHttpAsyncClient();
- client.start();
- HttpPost post = null;
-
- try {
- post = new HttpPost(uriBuilder.build());
- post.setEntity(new StringEntity(ob.build().toString(),
- ContentType.APPLICATION_JSON));
- return client.execute(post, callback);
- } catch (final URISyntaxException e) {
- throw new IOException(e);
- }
- }
-
- /**
- * Get a HTTP client. With proxy if a proxy is provided in the constructor.
- *
- * @return a HTTP client
- */
- protected HttpClient getHttpClient() {
- return HttpClientFactory.getInstanceFor(proxyHost, proxyPort, timeout);
+ public PiwikTracker(final String hostUrl, final String proxyHost, final int proxyPort, final int timeout) {
+ super(hostUrl, proxyHost, proxyPort, timeout);
}
- /**
- * Get an async HTTP client. With proxy if a proxy is provided in the constructor.
- *
- * @return an async HTTP client
- */
- protected CloseableHttpAsyncClient getHttpAsyncClient() {
- return HttpClientFactory.getAsyncInstanceFor(proxyHost, proxyPort, timeout);
- }
}
diff --git a/src/test/java/org/piwik/java/tracking/CustomVariableTest.java b/src/test/java/org/matomo/java/tracking/CustomVariableTest.java
similarity index 84%
rename from src/test/java/org/piwik/java/tracking/CustomVariableTest.java
rename to src/test/java/org/matomo/java/tracking/CustomVariableTest.java
index 4223eaed..9818bc8d 100644
--- a/src/test/java/org/piwik/java/tracking/CustomVariableTest.java
+++ b/src/test/java/org/matomo/java/tracking/CustomVariableTest.java
@@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
-package org.piwik.java.tracking;
+package org.matomo.java.tracking;
import org.junit.Before;
import org.junit.Test;
@@ -28,7 +28,7 @@ public void testConstructorNullKey() {
new CustomVariable(null, null);
fail("Exception should have been throw.");
} catch (NullPointerException e) {
- assertEquals("Key cannot be null.", e.getLocalizedMessage());
+ assertEquals("key is marked non-null but is null", e.getLocalizedMessage());
}
}
@@ -38,7 +38,7 @@ public void testConstructorNullValue() {
new CustomVariable("key", null);
fail("Exception should have been throw.");
} catch (NullPointerException e) {
- assertEquals("Value cannot be null.", e.getLocalizedMessage());
+ assertEquals("value is marked non-null but is null", e.getLocalizedMessage());
}
}
diff --git a/src/test/java/org/matomo/java/tracking/CustomVariablesTest.java b/src/test/java/org/matomo/java/tracking/CustomVariablesTest.java
new file mode 100644
index 00000000..bdc4e8d1
--- /dev/null
+++ b/src/test/java/org/matomo/java/tracking/CustomVariablesTest.java
@@ -0,0 +1,85 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.matomo.java.tracking;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * @author Katie
+ */
+public class CustomVariablesTest {
+ private final CustomVariables customVariables = new CustomVariables();
+
+ @Test
+ public void testAdd_CustomVariable() {
+ CustomVariable a = new CustomVariable("a", "b");
+ CustomVariable b = new CustomVariable("c", "d");
+ CustomVariable c = new CustomVariable("a", "e");
+ CustomVariable d = new CustomVariable("a", "f");
+
+ assertTrue(customVariables.isEmpty());
+ customVariables.add(a);
+ assertFalse(customVariables.isEmpty());
+ assertEquals("b", customVariables.get("a"));
+ assertEquals(a, customVariables.get(1));
+ assertEquals("{\"1\":[\"a\",\"b\"]}", customVariables.toString());
+
+ customVariables.add(b);
+ assertEquals("d", customVariables.get("c"));
+ assertEquals(b, customVariables.get(2));
+ assertEquals("{\"1\":[\"a\",\"b\"],\"2\":[\"c\",\"d\"]}", customVariables.toString());
+
+ customVariables.add(c, 5);
+ assertEquals("b", customVariables.get("a"));
+ assertEquals(c, customVariables.get(5));
+ assertNull(customVariables.get(3));
+ assertEquals("{\"1\":[\"a\",\"b\"],\"2\":[\"c\",\"d\"],\"5\":[\"a\",\"e\"]}", customVariables.toString());
+
+ customVariables.add(d);
+ assertEquals("f", customVariables.get("a"));
+ assertEquals(d, customVariables.get(1));
+ assertEquals(d, customVariables.get(5));
+ assertEquals("{\"1\":[\"a\",\"f\"],\"2\":[\"c\",\"d\"],\"5\":[\"a\",\"f\"]}", customVariables.toString());
+
+ customVariables.remove("a");
+ assertNull(customVariables.get("a"));
+ assertNull(customVariables.get(1));
+ assertNull(customVariables.get(5));
+ assertEquals("{\"2\":[\"c\",\"d\"]}", customVariables.toString());
+
+ customVariables.remove(2);
+ assertNull(customVariables.get("c"));
+ assertNull(customVariables.get(2));
+ assertTrue(customVariables.isEmpty());
+ assertEquals("{}", customVariables.toString());
+ }
+
+ @Test
+ public void testAddCustomVariableIndexLessThan1() {
+ try {
+ customVariables.add(new CustomVariable("a", "b"), 0);
+ fail("Exception should have been throw.");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Index must be greater than 0.", e.getLocalizedMessage());
+ }
+ }
+
+ @Test
+ public void testGetCustomVariableIntegerLessThan1() {
+ try {
+ customVariables.get(0);
+ fail("Exception should have been throw.");
+ } catch (IllegalArgumentException e) {
+ assertEquals("Index must be greater than 0.", e.getLocalizedMessage());
+ }
+ }
+}
diff --git a/src/test/java/org/piwik/java/tracking/EcommerceItemTest.java b/src/test/java/org/matomo/java/tracking/EcommerceItemTest.java
similarity index 75%
rename from src/test/java/org/piwik/java/tracking/EcommerceItemTest.java
rename to src/test/java/org/matomo/java/tracking/EcommerceItemTest.java
index 52dbb9be..986fb305 100644
--- a/src/test/java/org/piwik/java/tracking/EcommerceItemTest.java
+++ b/src/test/java/org/matomo/java/tracking/EcommerceItemTest.java
@@ -1,10 +1,10 @@
/*
- * Piwik Java Tracker
+ * Matomo Java Tracker
*
- * @link https://github.com/piwik/piwik-java-tracker
- * @license https://github.com/piwik/piwik-java-tracker/blob/master/LICENSE BSD-3 Clause
+ * @link https://github.com/matomo/matomo-java-tracker
+ * @license https://github.com/matomo/matomo-java-tracker/blob/master/LICENSE BSD-3 Clause
*/
-package org.piwik.java.tracking;
+package org.matomo.java.tracking;
import org.junit.After;
import org.junit.AfterClass;
@@ -12,8 +12,6 @@
import org.junit.BeforeClass;
import org.junit.Test;
-import javax.json.JsonValue.ValueType;
-
import static org.junit.Assert.assertEquals;
/**
@@ -106,22 +104,5 @@ public void testGetQuantity() {
assertEquals(new Integer(1), ecommerceItem.getQuantity());
}
- /**
- * Test of getValueType method, of class EcommerceItem.
- */
- @Test
- public void testGetValueType() {
- assertEquals(ValueType.ARRAY, ecommerceItem.getValueType());
- }
-
- /**
- * Test of toString method, of class EcommerceItem.
- */
- @Test
- public void testToString() {
- ecommerceItem = new EcommerceItem("sku", "name", "category", 1.0, 1);
-
- assertEquals("[\"sku\",\"name\",\"category\",1.0,1]", ecommerceItem.toString());
- }
}
diff --git a/src/test/java/org/matomo/java/tracking/EcommerceItemsTest.java b/src/test/java/org/matomo/java/tracking/EcommerceItemsTest.java
new file mode 100644
index 00000000..ee76b7ce
--- /dev/null
+++ b/src/test/java/org/matomo/java/tracking/EcommerceItemsTest.java
@@ -0,0 +1,18 @@
+package org.matomo.java.tracking;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class EcommerceItemsTest {
+
+ @Test
+ public void formatsJson() {
+
+ EcommerceItems ecommerceItems = new EcommerceItems();
+ ecommerceItems.add(new EcommerceItem("sku", "name", "category", 1.0, 1));
+
+ assertEquals("[[\"sku\",\"name\",\"category\",1.0,1]]", ecommerceItems.toString());
+
+ }
+}
diff --git a/src/test/java/org/matomo/java/tracking/MatomoRequestBuilderTest.java b/src/test/java/org/matomo/java/tracking/MatomoRequestBuilderTest.java
new file mode 100644
index 00000000..9d2804ed
--- /dev/null
+++ b/src/test/java/org/matomo/java/tracking/MatomoRequestBuilderTest.java
@@ -0,0 +1,49 @@
+package org.matomo.java.tracking;
+
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class MatomoRequestBuilderTest {
+
+ @Test
+ public void buildsRequest() {
+
+ CustomVariable customVariable = new CustomVariable("pageCustomVariableName", "pageCustomVariableValue");
+ MatomoRequest matomoRequest = MatomoRequest.builder()
+ .siteId(42)
+ .actionName("ACTION_NAME")
+ .actionUrl("https://www.your-domain.tld/some/page?query=foo")
+ .referrerUrl("https://referrer.com")
+ .customTrackingParameters(Collections.singletonMap("trackingParameterName", "trackingParameterValue"))
+ .pageCustomVariables(Collections.singletonList(customVariable))
+ .visitCustomVariables(Collections.singletonList(customVariable))
+ .customAction(true)
+ .build();
+
+ Map> parameters = matomoRequest.getParameters();
+ assertThat(parameters.get("idsite"), hasItem(42));
+ assertThat(parameters.get("action_name"), hasItem("ACTION_NAME"));
+ assertThat(parameters.get("apiv"), hasItem("1"));
+ assertThat(parameters.get("url"), hasItem("https://www.your-domain.tld/some/page?query=foo"));
+ assertThat(parameters.get("_id").isEmpty(), is(false));
+ assertThat(parameters.get("rand").isEmpty(), is(false));
+ assertThat(parameters.get("send_image"), hasItem(new MatomoBoolean(false)));
+ assertThat(parameters.get("rec"), hasItem(new MatomoBoolean(true)));
+ assertThat(parameters.get("urlref"), hasItem("https://referrer.com"));
+ assertThat(parameters.get("trackingParameterName"), hasItem("trackingParameterValue"));
+ CustomVariables customVariables = new CustomVariables();
+ customVariables.add(customVariable);
+ assertThat(parameters.get("cvar"), hasItem(customVariables));
+ assertThat(parameters.get("_cvar"), hasItem(customVariables));
+ assertThat(parameters.get("ca"), hasItem(new MatomoBoolean(true)));
+
+ }
+
+}
diff --git a/src/test/java/org/piwik/java/tracking/PiwikDateTest.java b/src/test/java/org/matomo/java/tracking/PiwikDateTest.java
similarity index 79%
rename from src/test/java/org/piwik/java/tracking/PiwikDateTest.java
rename to src/test/java/org/matomo/java/tracking/PiwikDateTest.java
index 1025b5eb..0ba201d5 100644
--- a/src/test/java/org/piwik/java/tracking/PiwikDateTest.java
+++ b/src/test/java/org/matomo/java/tracking/PiwikDateTest.java
@@ -1,12 +1,13 @@
/*
- * Piwik Java Tracker
+ * Matomo Java Tracker
*
- * @link https://github.com/piwik/piwik-java-tracker
- * @license https://github.com/piwik/piwik-java-tracker/blob/master/LICENSE BSD-3 Clause
+ * @link https://github.com/matomo/matomo-java-tracker
+ * @license https://github.com/matomo/matomo-java-tracker/blob/master/LICENSE BSD-3 Clause
*/
-package org.piwik.java.tracking;
+package org.matomo.java.tracking;
import org.junit.Test;
+import org.piwik.java.tracking.PiwikDate;
import java.util.TimeZone;
diff --git a/src/test/java/org/piwik/java/tracking/PiwikLocaleTest.java b/src/test/java/org/matomo/java/tracking/PiwikLocaleTest.java
similarity index 83%
rename from src/test/java/org/piwik/java/tracking/PiwikLocaleTest.java
rename to src/test/java/org/matomo/java/tracking/PiwikLocaleTest.java
index b14c4943..1931e5e6 100644
--- a/src/test/java/org/piwik/java/tracking/PiwikLocaleTest.java
+++ b/src/test/java/org/matomo/java/tracking/PiwikLocaleTest.java
@@ -1,16 +1,17 @@
/*
* Piwik Java Tracker
*
- * @link https://github.com/piwik/piwik-java-tracker
- * @license https://github.com/piwik/piwik-java-tracker/blob/master/LICENSE BSD-3 Clause
+ * @link https://github.com/matomo/matomo-java-tracker
+ * @license https://github.com/matomo/matomo-java-tracker/blob/master/LICENSE BSD-3 Clause
*/
-package org.piwik.java.tracking;
+package org.matomo.java.tracking;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.piwik.java.tracking.PiwikLocale;
import java.util.Locale;
diff --git a/src/test/java/org/piwik/java/tracking/PiwikRequestTest.java b/src/test/java/org/matomo/java/tracking/PiwikRequestTest.java
similarity index 82%
rename from src/test/java/org/piwik/java/tracking/PiwikRequestTest.java
rename to src/test/java/org/matomo/java/tracking/PiwikRequestTest.java
index 6009f7b5..e50fc017 100644
--- a/src/test/java/org/piwik/java/tracking/PiwikRequestTest.java
+++ b/src/test/java/org/matomo/java/tracking/PiwikRequestTest.java
@@ -1,16 +1,18 @@
/*
* Piwik Java Tracker
*
- * @link https://github.com/piwik/piwik-java-tracker
- * @license https://github.com/piwik/piwik-java-tracker/blob/master/LICENSE BSD-3 Clause
+ * @link https://github.com/matomo/matomo-java-tracker
+ * @license https://github.com/matomo/matomo-java-tracker/blob/master/LICENSE BSD-3 Clause
*/
-package org.piwik.java.tracking;
+package org.matomo.java.tracking;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.piwik.java.tracking.PiwikDate;
+import org.piwik.java.tracking.PiwikLocale;
+import org.piwik.java.tracking.PiwikRequest;
-import javax.xml.bind.TypeConstraintException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.List;
@@ -75,32 +77,22 @@ public void testActionTime() {
*/
@Test
public void testActionUrl() throws Exception {
- request.setActionUrl(null);
+ request.setActionUrl((String) null);
assertNull(request.getActionUrl());
assertNull(request.getActionUrlAsString());
URL url = new URL("http://action.com");
request.setActionUrl(url);
assertEquals(url, request.getActionUrl());
- try {
- request.getActionUrlAsString();
- fail("Exception should have been thrown.");
- } catch (TypeConstraintException e) {
- assertEquals("The stored Action URL is a URL, not a String. Use \"getActionUrl\" instead.", e.getLocalizedMessage());
- }
+ assertEquals("http://action.com", request.getActionUrlAsString());
request.setActionUrlWithString(null);
assertNull(request.getActionUrl());
assertNull(request.getActionUrlAsString());
- request.setActionUrlWithString("actionUrl");
- assertEquals("actionUrl", request.getActionUrlAsString());
- try {
- request.getActionUrl();
- fail("Exception should have been thrown.");
- } catch (TypeConstraintException e) {
- assertEquals("The stored Action URL is a String, not a URL. Use \"getActionUrlAsString\" instead.", e.getLocalizedMessage());
- }
+ request.setActionUrlWithString("http://actionstring.com");
+ assertEquals("http://actionstring.com", request.getActionUrlAsString());
+ assertEquals(new URL("http://actionstring.com"), request.getActionUrl());
}
/**
@@ -214,23 +206,12 @@ public void testContentTarget() throws Exception {
URL url = new URL("http://target.com");
request.setContentTarget(url);
assertEquals(url, request.getContentTarget());
+ assertEquals("http://target.com", request.getContentTargetAsString());
- try {
- request.getContentTargetAsString();
- fail("Exception should have been thrown.");
- } catch (TypeConstraintException e) {
- assertEquals("The stored Content Target is a URL, not a String. Use \"getContentTarget\" instead.", e.getLocalizedMessage());
- }
+ request.setContentTargetWithString("http://targetstring.com");
+ assertEquals("http://targetstring.com", request.getContentTargetAsString());
+ assertEquals(new URL("http://targetstring.com"), request.getContentTarget());
- request.setContentTargetWithString("contentTarget");
- assertEquals("contentTarget", request.getContentTargetAsString());
-
- try {
- request.getContentTarget();
- fail("Exception should have been thrown.");
- } catch (TypeConstraintException e) {
- assertEquals("The stored Content Target is a String, not a URL. Use \"getContentTargetAsString\" instead.", e.getLocalizedMessage());
- }
}
/**
@@ -269,7 +250,7 @@ public void testGetCustomTrackingParameter_T() {
request.getCustomTrackingParameter(null);
fail("Exception should have been thrown.");
} catch (NullPointerException e) {
- assertEquals("Key cannot be null.", e.getLocalizedMessage());
+ assertEquals("key is marked non-null but is null", e.getLocalizedMessage());
}
}
@@ -284,7 +265,7 @@ public void testSetCustomTrackingParameter_T() {
request.setCustomTrackingParameter(null, null);
fail("Exception should have been thrown.");
} catch (NullPointerException e) {
- assertEquals("Key cannot be null.", e.getLocalizedMessage());
+ assertEquals("key is marked non-null but is null", e.getLocalizedMessage());
}
}
@@ -311,7 +292,7 @@ public void testAddCustomTrackingParameter_T() {
request.addCustomTrackingParameter(null, null);
fail("Exception should have been thrown.");
} catch (NullPointerException e) {
- assertEquals("Key cannot be null.", e.getLocalizedMessage());
+ assertEquals("key is marked non-null but is null", e.getLocalizedMessage());
}
}
@@ -321,7 +302,7 @@ public void testAddCustomTrackingParameter_FT() {
request.addCustomTrackingParameter("key", null);
fail("Exception should have been thrown.");
} catch (NullPointerException e) {
- assertEquals("Cannot add a null custom tracking parameter.", e.getLocalizedMessage());
+ assertEquals("value is marked non-null but is null", e.getLocalizedMessage());
}
}
@@ -364,23 +345,12 @@ public void testDownloadUrl() throws Exception {
URL url = new URL("http://download.com");
request.setDownloadUrl(url);
assertEquals(url, request.getDownloadUrl());
+ assertEquals("http://download.com", request.getDownloadUrlAsString());
- try {
- request.getDownloadUrlAsString();
- fail("Exception should have been thrown.");
- } catch (TypeConstraintException e) {
- assertEquals("The stored Download URL is a URL, not a String. Use \"getDownloadUrl\" instead.", e.getLocalizedMessage());
- }
-
- request.setDownloadUrlWithString("downloadUrl");
- assertEquals("downloadUrl", request.getDownloadUrlAsString());
+ request.setDownloadUrlWithString("http://downloadstring.com");
+ assertEquals("http://downloadstring.com", request.getDownloadUrlAsString());
+ assertEquals(new URL("http://downloadstring.com"), request.getDownloadUrl());
- try {
- request.getDownloadUrl();
- fail("Exception should have been thrown.");
- } catch (TypeConstraintException e) {
- assertEquals("The stored Download URL is a String, not a URL. Use \"getDownloadUrlAsString\" instead.", e.getLocalizedMessage());
- }
}
/**
@@ -402,7 +372,7 @@ public void testVerifyEcommerceEnabledT() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("GoalId must be \"0\". Try calling enableEcommerce first before calling this method.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -414,7 +384,7 @@ public void testVerifyEcommerceEnabledFT() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("GoalId must be \"0\". Try calling enableEcommerce first before calling this method.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -434,7 +404,7 @@ public void testVerifyEcommerceStateE() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("GoalId must be \"0\". Try calling enableEcommerce first before calling this method.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -446,7 +416,7 @@ public void testVerifyEcommerceStateT() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("EcommerceId must be set before this value can be set.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -459,7 +429,7 @@ public void testVerifyEcommerceStateFT() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("EcommerceRevenue must be set before this value can be set.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -491,7 +461,7 @@ public void testEcommerceDiscountTE() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("GoalId must be \"0\". Try calling enableEcommerce first before calling this method.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -520,7 +490,7 @@ public void testEcommerceIdTE() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("GoalId must be \"0\". Try calling enableEcommerce first before calling this method.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -542,7 +512,7 @@ public void testEcommerceItemE() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("GoalId must be \"0\". Try calling enableEcommerce first before calling this method.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -555,7 +525,7 @@ public void testEcommerceItemE2() {
request.addEcommerceItem(null);
fail("Exception should have been thrown.");
} catch (NullPointerException e) {
- assertEquals("Value cannot be null.", e.getLocalizedMessage());
+ assertEquals("item is marked non-null but is null", e.getLocalizedMessage());
}
}
@@ -595,7 +565,7 @@ public void testEcommerceLastOrderTimestampTE() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("GoalId must be \"0\". Try calling enableEcommerce first before calling this method.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -625,7 +595,7 @@ public void testEcommerceRevenueTE() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("GoalId must be \"0\". Try calling enableEcommerce first before calling this method.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -656,7 +626,7 @@ public void testEcommerceShippingCostTE() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("GoalId must be \"0\". Try calling enableEcommerce first before calling this method.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -687,7 +657,7 @@ public void testEcommerceSubtotalTE() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("GoalId must be \"0\". Try calling enableEcommerce first before calling this method.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -718,7 +688,7 @@ public void testEcommerceTaxTE() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("GoalId must be \"0\". Try calling enableEcommerce first before calling this method.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -797,7 +767,7 @@ public void testGoalRevenueTT() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("GoalId must be set before GoalRevenue can be set.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -853,23 +823,12 @@ public void testOutlinkUrl() throws Exception {
URL url = new URL("http://outlink.com");
request.setOutlinkUrl(url);
assertEquals(url, request.getOutlinkUrl());
+ assertEquals("http://outlink.com", request.getOutlinkUrlAsString());
- try {
- request.getOutlinkUrlAsString();
- fail("Exception should have been thrown.");
- } catch (TypeConstraintException e) {
- assertEquals("The stored Outlink URL is a URL, not a String. Use \"getOutlinkUrl\" instead.", e.getLocalizedMessage());
- }
-
- request.setOutlinkUrlWithString("outlinkUrl");
- assertEquals("outlinkUrl", request.getOutlinkUrlAsString());
+ request.setOutlinkUrlWithString("http://outlinkstring.com");
+ assertEquals("http://outlinkstring.com", request.getOutlinkUrlAsString());
+ assertEquals(new URL("http://outlinkstring.com"), request.getOutlinkUrl());
- try {
- request.getOutlinkUrl();
- fail("Exception should have been thrown.");
- } catch (TypeConstraintException e) {
- assertEquals("The stored Outlink URL is a String, not a URL. Use \"getOutlinkUrlAsString\" instead.", e.getLocalizedMessage());
- }
}
/**
@@ -881,7 +840,7 @@ public void testPageCustomVariableStringStringE() {
request.setPageCustomVariable(null, null);
fail("Exception should have been thrown");
} catch (NullPointerException e) {
- assertEquals("Key cannot be null.", e.getLocalizedMessage());
+ assertEquals("key is marked non-null but is null", e.getLocalizedMessage());
}
}
@@ -891,7 +850,7 @@ public void testPageCustomVariableStringStringE2() {
request.setPageCustomVariable(null, "pageVal");
fail("Exception should have been thrown");
} catch (NullPointerException e) {
- assertEquals("Key cannot be null.", e.getLocalizedMessage());
+ assertEquals("key is marked non-null but is null", e.getLocalizedMessage());
}
}
@@ -901,7 +860,7 @@ public void testPageCustomVariableStringStringE3() {
request.getPageCustomVariable(null);
fail("Exception should have been thrown");
} catch (NullPointerException e) {
- assertEquals("Key cannot be null.", e.getLocalizedMessage());
+ assertEquals("key is marked non-null but is null", e.getLocalizedMessage());
}
}
@@ -1026,23 +985,12 @@ public void testReferrerUrl() throws Exception {
URL url = new URL("http://referrer.com");
request.setReferrerUrl(url);
assertEquals(url, request.getReferrerUrl());
+ assertEquals("http://referrer.com", request.getReferrerUrlAsString());
- try {
- request.getReferrerUrlAsString();
- fail("Exception should have been thrown.");
- } catch (TypeConstraintException e) {
- assertEquals("The stored Referrer URL is a URL, not a String. Use \"getReferrerUrl\" instead.", e.getLocalizedMessage());
- }
-
- request.setReferrerUrlWithString("referrerUrl");
- assertEquals("referrerUrl", request.getReferrerUrlAsString());
+ request.setReferrerUrlWithString("http://referrerstring.com");
+ assertEquals("http://referrerstring.com", request.getReferrerUrlAsString());
+ assertEquals(new URL("http://referrerstring.com"), request.getReferrerUrl());
- try {
- request.getReferrerUrl();
- fail("Exception should have been thrown.");
- } catch (TypeConstraintException e) {
- assertEquals("The stored Referrer URL is a String, not a URL. Use \"getReferrerUrlAsString\" instead.", e.getLocalizedMessage());
- }
}
/**
@@ -1065,7 +1013,7 @@ public void testRequestDatetimeTTF() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("Because you are trying to set RequestDatetime for a time greater than 4 hours ago, AuthToken must be set first.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -1112,7 +1060,7 @@ public void testSearchCategoryTT() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("SearchQuery must be set before SearchCategory can be set.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -1148,7 +1096,7 @@ public void testSearchResultsCountTT() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("SearchQuery must be set before SearchResultsCount can be set.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -1201,22 +1149,22 @@ public void testVisitCustomVariableCustomVariable() {
assertNull(request.getVisitCustomVariable(1));
CustomVariable cv = new CustomVariable("visitKey", "visitVal");
request.setVisitCustomVariable(cv, 1);
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_cvar={\"1\":[\"visitKey\",\"visitVal\"]}&_id=1234567890123456&url=http://test.com", request.getQueryString());
+ assertEquals("idsite=3&rec=1&url=http://test.com&apiv=1&send_image=0&rand=random&_id=1234567890123456&_cvar={\"1\":[\"visitKey\",\"visitVal\"]}", request.getQueryString());
request.setUserCustomVariable("key", "val");
assertEquals(cv, request.getVisitCustomVariable(1));
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_cvar={\"1\":[\"visitKey\",\"visitVal\"],\"2\":[\"key\",\"val\"]}&_id=1234567890123456&url=http://test.com", request.getQueryString());
+ assertEquals("idsite=3&rec=1&url=http://test.com&apiv=1&send_image=0&rand=random&_id=1234567890123456&_cvar={\"1\":[\"visitKey\",\"visitVal\"],\"2\":[\"key\",\"val\"]}", request.getQueryString());
request.setVisitCustomVariable(null, 1);
assertNull(request.getVisitCustomVariable(1));
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_cvar={\"2\":[\"key\",\"val\"]}&_id=1234567890123456&url=http://test.com", request.getQueryString());
+ assertEquals("idsite=3&rec=1&url=http://test.com&apiv=1&send_image=0&rand=random&_id=1234567890123456&_cvar={\"2\":[\"key\",\"val\"]}", request.getQueryString());
request.setVisitCustomVariable(cv, 2);
assertEquals(cv, request.getVisitCustomVariable(2));
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_cvar={\"2\":[\"visitKey\",\"visitVal\"]}&_id=1234567890123456&url=http://test.com", request.getQueryString());
+ assertEquals("idsite=3&rec=1&url=http://test.com&apiv=1&send_image=0&rand=random&_id=1234567890123456&_cvar={\"2\":[\"visitKey\",\"visitVal\"]}", request.getQueryString());
request.setUserCustomVariable("visitKey", null);
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_id=1234567890123456&url=http://test.com", request.getQueryString());
+ assertEquals("idsite=3&rec=1&url=http://test.com&apiv=1&send_image=0&rand=random&_id=1234567890123456", request.getQueryString());
}
/**
@@ -1245,7 +1193,7 @@ public void testVisitorCityTE() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("AuthToken must be set before this value can be set.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -1275,7 +1223,7 @@ public void testVisitorCountryTE() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("AuthToken must be set before this value can be set.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -1296,7 +1244,7 @@ public void testVisitorCustomTT() {
fail("Exception should have been thrown.");
} catch (IllegalArgumentException e) {
assertEquals("1 is not 16 characters long.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -1307,7 +1255,7 @@ public void testVisitorCustomTFT() {
fail("Exception should have been thrown.");
} catch (IllegalArgumentException e) {
assertEquals("1234567890abcdeg is not a hexadecimal string.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -1343,7 +1291,7 @@ public void testVisitorIdTT() {
fail("Exception should have been thrown.");
} catch (IllegalArgumentException e) {
assertEquals("1 is not 16 characters long.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -1354,7 +1302,7 @@ public void testVisitorIdTFT() {
fail("Exception should have been thrown.");
} catch (IllegalArgumentException e) {
assertEquals("1234567890abcdeg is not a hexadecimal string.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -1388,7 +1336,7 @@ public void testVisitorIpTE() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("AuthToken must be set before this value can be set.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -1415,7 +1363,7 @@ public void testVisitorLatitudeTE() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("AuthToken must be set before this value can be set.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -1442,7 +1390,7 @@ public void testVisitorLongitudeTE() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("AuthToken must be set before this value can be set.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -1479,7 +1427,7 @@ public void testGetVisitorRegionTE() {
fail("Exception should have been thrown.");
} catch (IllegalStateException e) {
assertEquals("AuthToken must be set before this value can be set.",
- e.getLocalizedMessage());
+ e.getLocalizedMessage());
}
}
@@ -1506,27 +1454,27 @@ public void testVisitorVisitCount() {
public void testGetQueryString() {
request.setRandomValue("random");
request.setVisitorId("1234567890123456");
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_id=1234567890123456&url=http://test.com", request.getQueryString());
+ assertEquals("idsite=3&rec=1&url=http://test.com&apiv=1&send_image=0&rand=random&_id=1234567890123456", request.getQueryString());
request.setPageCustomVariable("key", "val");
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&cvar={\"1\":[\"key\",\"val\"]}&_id=1234567890123456&url=http://test.com",
- request.getQueryString());
+ assertEquals("idsite=3&rec=1&url=http://test.com&apiv=1&send_image=0&rand=random&_id=1234567890123456&cvar={\"1\":[\"key\",\"val\"]}",
+ request.getQueryString());
request.setPageCustomVariable("key", null);
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_id=1234567890123456&url=http://test.com", request.getQueryString());
+ assertEquals("idsite=3&rec=1&url=http://test.com&apiv=1&send_image=0&rand=random&_id=1234567890123456", request.getQueryString());
request.addCustomTrackingParameter("key", "test");
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_id=1234567890123456&url=http://test.com&key=test", request.getQueryString());
+ assertEquals("idsite=3&rec=1&url=http://test.com&apiv=1&send_image=0&rand=random&_id=1234567890123456&key=test", request.getQueryString());
request.addCustomTrackingParameter("key", "test2");
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_id=1234567890123456&url=http://test.com&key=test&key=test2", request.getQueryString());
+ assertEquals("idsite=3&rec=1&url=http://test.com&apiv=1&send_image=0&rand=random&_id=1234567890123456&key=test&key=test2", request.getQueryString());
request.setCustomTrackingParameter("key2", "test3");
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_id=1234567890123456&url=http://test.com&key2=test3&key=test&key=test2", request.getQueryString());
+ assertEquals("idsite=3&rec=1&url=http://test.com&apiv=1&send_image=0&rand=random&_id=1234567890123456&key=test&key=test2&key2=test3", request.getQueryString());
request.setCustomTrackingParameter("key", "test4");
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_id=1234567890123456&url=http://test.com&key2=test3&key=test4", request.getQueryString());
+ assertEquals("idsite=3&rec=1&url=http://test.com&apiv=1&send_image=0&rand=random&_id=1234567890123456&key2=test3&key=test4", request.getQueryString());
request.setRandomValue(null);
request.setSiteId(null);
request.setRequired(null);
request.setApiVersion(null);
request.setResponseAsImage(null);
request.setVisitorId(null);
- request.setActionUrl(null);
+ request.setActionUrl((String) null);
assertEquals("key2=test3&key=test4", request.getQueryString());
request.clearCustomTrackingParameter();
assertEquals("", request.getQueryString());
@@ -1537,7 +1485,7 @@ public void testGetQueryString2() {
request.setActionUrlWithString("http://test.com");
request.setRandomValue("random");
request.setVisitorId("1234567890123456");
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_id=1234567890123456&url=http://test.com", request.getQueryString());
+ assertEquals("idsite=3&rec=1&apiv=1&send_image=0&url=http://test.com&rand=random&_id=1234567890123456", request.getQueryString());
}
/**
@@ -1547,22 +1495,22 @@ public void testGetQueryString2() {
public void testGetUrlEncodedQueryString() {
request.setRandomValue("random");
request.setVisitorId("1234567890123456");
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_id=1234567890123456&url=http%3A%2F%2Ftest.com", request.getUrlEncodedQueryString());
+ assertEquals("_id=1234567890123456&apiv=1&idsite=3&rand=random&rec=1&send_image=0&url=http%3A%2F%2Ftest.com", request.getUrlEncodedQueryString());
request.addCustomTrackingParameter("ke/y", "te:st");
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_id=1234567890123456&url=http%3A%2F%2Ftest.com&ke%2Fy=te%3Ast", request.getUrlEncodedQueryString());
+ assertEquals("_id=1234567890123456&apiv=1&idsite=3&ke%2Fy=te%3Ast&rand=random&rec=1&send_image=0&url=http%3A%2F%2Ftest.com", request.getUrlEncodedQueryString());
request.addCustomTrackingParameter("ke/y", "te:st2");
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_id=1234567890123456&url=http%3A%2F%2Ftest.com&ke%2Fy=te%3Ast&ke%2Fy=te%3Ast2", request.getUrlEncodedQueryString());
+ assertEquals("_id=1234567890123456&apiv=1&idsite=3&ke%2Fy=te%3Ast&ke%2Fy=te%3Ast2&rand=random&rec=1&send_image=0&url=http%3A%2F%2Ftest.com", request.getUrlEncodedQueryString());
request.setCustomTrackingParameter("ke/y2", "te:st3");
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_id=1234567890123456&url=http%3A%2F%2Ftest.com&ke%2Fy=te%3Ast&ke%2Fy=te%3Ast2&ke%2Fy2=te%3Ast3", request.getUrlEncodedQueryString());
+ assertEquals("_id=1234567890123456&apiv=1&idsite=3&ke%2Fy=te%3Ast&ke%2Fy=te%3Ast2&ke%2Fy2=te%3Ast3&rand=random&rec=1&send_image=0&url=http%3A%2F%2Ftest.com", request.getUrlEncodedQueryString());
request.setCustomTrackingParameter("ke/y", "te:st4");
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_id=1234567890123456&url=http%3A%2F%2Ftest.com&ke%2Fy=te%3Ast4&ke%2Fy2=te%3Ast3", request.getUrlEncodedQueryString());
+ assertEquals("_id=1234567890123456&apiv=1&idsite=3&ke%2Fy=te%3Ast4&ke%2Fy2=te%3Ast3&rand=random&rec=1&send_image=0&url=http%3A%2F%2Ftest.com", request.getUrlEncodedQueryString());
request.setRandomValue(null);
request.setSiteId(null);
request.setRequired(null);
request.setApiVersion(null);
request.setResponseAsImage(null);
request.setVisitorId(null);
- request.setActionUrl(null);
+ request.setActionUrl((String) null);
assertEquals("ke%2Fy=te%3Ast4&ke%2Fy2=te%3Ast3", request.getUrlEncodedQueryString());
request.clearCustomTrackingParameter();
assertEquals("", request.getUrlEncodedQueryString());
@@ -1573,7 +1521,7 @@ public void testGetUrlEncodedQueryString2() {
request.setActionUrlWithString("http://test.com");
request.setRandomValue("random");
request.setVisitorId("1234567890123456");
- assertEquals("rand=random&idsite=3&rec=1&apiv=1&send_image=0&_id=1234567890123456&url=http%3A%2F%2Ftest.com", request.getUrlEncodedQueryString());
+ assertEquals("_id=1234567890123456&apiv=1&idsite=3&rand=random&rec=1&send_image=0&url=http%3A%2F%2Ftest.com", request.getUrlEncodedQueryString());
}
/**
diff --git a/src/test/java/org/piwik/java/tracking/PiwikTrackerTest.java b/src/test/java/org/matomo/java/tracking/PiwikTrackerTest.java
similarity index 85%
rename from src/test/java/org/piwik/java/tracking/PiwikTrackerTest.java
rename to src/test/java/org/matomo/java/tracking/PiwikTrackerTest.java
index f31979cd..b37a9ebc 100644
--- a/src/test/java/org/piwik/java/tracking/PiwikTrackerTest.java
+++ b/src/test/java/org/matomo/java/tracking/PiwikTrackerTest.java
@@ -1,10 +1,10 @@
/*
* Piwik Java Tracker
*
- * @link https://github.com/piwik/piwik-java-tracker
- * @license https://github.com/piwik/piwik-java-tracker/blob/master/LICENSE BSD-3 Clause
+ * @link https://github.com/matomo/matomo-java-tracker
+ * @license https://github.com/matomo/matomo-java-tracker/blob/master/LICENSE BSD-3 Clause
*/
-package org.piwik.java.tracking;
+package org.matomo.java.tracking;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
@@ -22,6 +22,8 @@
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
+import org.piwik.java.tracking.PiwikRequest;
+import org.piwik.java.tracking.PiwikTracker;
import java.io.IOException;
import java.io.InputStream;
@@ -29,12 +31,21 @@
import java.net.InetSocketAddress;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.concurrent.*;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Future;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.doReturn;
@@ -45,6 +56,8 @@
* @author brettcsorba
*/
public class PiwikTrackerTest {
+ private static final Map> PARAMETERS = Collections.singletonMap("parameterName", Collections.singleton("parameterValue"));
+
// https://stackoverflow.com/a/3732328
static class Handler implements HttpHandler {
@Override
@@ -110,9 +123,9 @@ public void testSendRequest() throws Exception {
HttpResponse response = mock(HttpResponse.class);
doReturn(client).when(piwikTracker).getHttpClient();
- doReturn("query").when(request).getQueryString();
+ doReturn(PARAMETERS).when(request).getParameters();
doReturn(response).when(client)
- .execute(argThat(new CorrectGetRequest("http://test.com?query")));
+ .execute(argThat(new CorrectGetRequest("http://test.com?parameterName=parameterValue")));
assertEquals(response, piwikTracker.sendRequest(request));
}
@@ -128,11 +141,11 @@ public void testSendRequestAsync() throws Exception {
Future future = mock(Future.class);
doReturn(client).when(piwikTracker).getHttpAsyncClient();
- doReturn("query").when(request).getQueryString();
+ doReturn(PARAMETERS).when(request).getParameters();
doReturn(response).when(future).get();
doReturn(true).when(future).isDone();
doReturn(future).when(client)
- .execute(argThat(new CorrectGetRequest("http://test.com?query")), any());
+ .execute(argThat(new CorrectGetRequest("http://test.com?parameterName=parameterValue")), any());
assertEquals(response, piwikTracker.sendRequestAsync(request).get());
}
@@ -241,7 +254,7 @@ public boolean matches(HttpGet get) {
* Test of sendBulkRequest method, of class PiwikTracker.
*/
@Test
- public void testSendBulkRequest_Iterable() throws Exception {
+ public void testSendBulkRequest_Iterable() {
List requests = new ArrayList<>();
HttpResponse response = mock(HttpResponse.class);
@@ -254,13 +267,13 @@ public void testSendBulkRequest_Iterable() throws Exception {
* Test of sendBulkRequest method, of class PiwikTracker.
*/
@Test
- public void testSendBulkRequest_Iterable_StringTT() throws Exception {
+ public void testSendBulkRequest_Iterable_StringTT() {
try {
List requests = new ArrayList<>();
HttpClient client = mock(HttpClient.class);
PiwikRequest request = mock(PiwikRequest.class);
- doReturn("query").when(request).getQueryString();
+ doReturn(PARAMETERS).when(request).getParameters();
requests.add(request);
doReturn(client).when(piwikTracker).getHttpClient();
@@ -278,10 +291,10 @@ public void testSendBulkRequest_Iterable_StringFF() throws Exception {
PiwikRequest request = mock(PiwikRequest.class);
HttpResponse response = mock(HttpResponse.class);
- doReturn("query").when(request).getQueryString();
+ doReturn(PARAMETERS).when(request).getParameters();
requests.add(request);
doReturn(client).when(piwikTracker).getHttpClient();
- doReturn(response).when(client).execute(argThat(new CorrectPostRequest("{\"requests\":[\"?query\"]}")));
+ doReturn(response).when(client).execute(argThat(new CorrectPostRequest("{\"requests\":[\"?parameterName=parameterValue\"]}")));
assertEquals(response, piwikTracker.sendBulkRequest(requests, null));
}
@@ -293,11 +306,11 @@ public void testSendBulkRequest_Iterable_StringFT() throws Exception {
PiwikRequest request = mock(PiwikRequest.class);
HttpResponse response = mock(HttpResponse.class);
- doReturn("query").when(request).getQueryString();
+ doReturn(PARAMETERS).when(request).getParameters();
requests.add(request);
doReturn(client).when(piwikTracker).getHttpClient();
doReturn(response).when(client)
- .execute(argThat(new CorrectPostRequest("{\"requests\":[\"?query\"],\"token_auth\":\"12345678901234567890123456789012\"}")));
+ .execute(argThat(new CorrectPostRequest("{\"requests\":[\"?parameterName=parameterValue\"],\"token_auth\":\"12345678901234567890123456789012\"}")));
assertEquals(response, piwikTracker.sendBulkRequest(requests, "12345678901234567890123456789012"));
}
@@ -322,13 +335,13 @@ public void testSendBulkRequestAsync_Iterable() throws Exception {
* Test of sendBulkRequestAsync method, of class PiwikTracker.
*/
@Test
- public void testSendBulkRequestAsync_Iterable_StringTT() throws Exception {
+ public void testSendBulkRequestAsync_Iterable_StringTT() {
try {
List requests = new ArrayList<>();
CloseableHttpAsyncClient client = mock(CloseableHttpAsyncClient.class);
PiwikRequest request = mock(PiwikRequest.class);
- doReturn("query").when(request).getQueryString();
+ doReturn(PARAMETERS).when(request).getParameters();
requests.add(request);
doReturn(client).when(piwikTracker).getHttpAsyncClient();
@@ -349,11 +362,11 @@ public void testSendBulkRequestAsync_Iterable_StringFF() throws Exception {
doReturn(response).when(future).get();
doReturn(true).when(future).isDone();
- doReturn("query").when(request).getQueryString();
+ doReturn(PARAMETERS).when(request).getParameters();
requests.add(request);
doReturn(client).when(piwikTracker).getHttpAsyncClient();
doReturn(future).when(client)
- .execute(argThat(new CorrectPostRequest("{\"requests\":[\"?query\"]}")), any());
+ .execute(argThat(new CorrectPostRequest("{\"requests\":[\"?parameterName=parameterValue\"]}")), any());
assertEquals(response, piwikTracker.sendBulkRequestAsync(requests).get());
}
@@ -368,11 +381,11 @@ public void testSendBulkRequestAsync_Iterable_StringFT() throws Exception {
doReturn(response).when(future).get();
doReturn(true).when(future).isDone();
- doReturn("query").when(request).getQueryString();
+ doReturn(PARAMETERS).when(request).getParameters();
requests.add(request);
doReturn(client).when(piwikTracker).getHttpAsyncClient();
doReturn(future).when(client)
- .execute(argThat(new CorrectPostRequest("{\"requests\":[\"?query\"],\"token_auth\":\"12345678901234567890123456789012\"}")), any());
+ .execute(argThat(new CorrectPostRequest("{\"requests\":[\"?parameterName=parameterValue\"],\"token_auth\":\"12345678901234567890123456789012\"}")), any());
assertEquals(response, piwikTracker.sendBulkRequestAsync(requests, "12345678901234567890123456789012").get());
}
diff --git a/src/test/java/org/piwik/java/tracking/CustomVariableListTest.java b/src/test/java/org/piwik/java/tracking/CustomVariableListTest.java
deleted file mode 100644
index 76b71600..00000000
--- a/src/test/java/org/piwik/java/tracking/CustomVariableListTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package org.piwik.java.tracking;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * @author Katie
- */
-public class CustomVariableListTest {
- private CustomVariableList cvl;
-
- @Before
- public void setUp() {
- cvl = new CustomVariableList();
- }
-
- @Test
- public void testAdd_CustomVariable() {
- CustomVariable a = new CustomVariable("a", "b");
- CustomVariable b = new CustomVariable("c", "d");
- CustomVariable c = new CustomVariable("a", "e");
- CustomVariable d = new CustomVariable("a", "f");
-
- assertTrue(cvl.isEmpty());
- cvl.add(a);
- assertFalse(cvl.isEmpty());
- assertEquals("b", cvl.get("a"));
- assertEquals(a, cvl.get(1));
- assertEquals("{\"1\":[\"a\",\"b\"]}", cvl.toString());
-
- cvl.add(b);
- assertEquals("d", cvl.get("c"));
- assertEquals(b, cvl.get(2));
- assertEquals("{\"1\":[\"a\",\"b\"],\"2\":[\"c\",\"d\"]}", cvl.toString());
-
- cvl.add(c, 5);
- assertEquals("b", cvl.get("a"));
- assertEquals(c, cvl.get(5));
- assertNull(cvl.get(3));
- assertEquals("{\"1\":[\"a\",\"b\"],\"2\":[\"c\",\"d\"],\"5\":[\"a\",\"e\"]}", cvl.toString());
-
- cvl.add(d);
- assertEquals("f", cvl.get("a"));
- assertEquals(d, cvl.get(1));
- assertEquals(d, cvl.get(5));
- assertEquals("{\"1\":[\"a\",\"f\"],\"2\":[\"c\",\"d\"],\"5\":[\"a\",\"f\"]}", cvl.toString());
-
- cvl.remove("a");
- assertNull(cvl.get("a"));
- assertNull(cvl.get(1));
- assertNull(cvl.get(5));
- assertEquals("{\"2\":[\"c\",\"d\"]}", cvl.toString());
-
- cvl.remove(2);
- assertNull(cvl.get("c"));
- assertNull(cvl.get(2));
- assertTrue(cvl.isEmpty());
- assertEquals("{}", cvl.toString());
- }
-
- @Test
- public void testAddCustomVariableIndexLessThan1() {
- try {
- cvl.add(new CustomVariable("a", "b"), 0);
- fail("Exception should have been throw.");
- } catch (IllegalArgumentException e) {
- assertEquals("Index must be greater than 0.", e.getLocalizedMessage());
- }
- }
-
- @Test
- public void testGetCustomVariableIntegerLessThan1() {
- try {
- cvl.get(0);
- fail("Exception should have been throw.");
- } catch (IllegalArgumentException e) {
- assertEquals("Index must be greater than 0.", e.getLocalizedMessage());
- }
- }
-}
diff --git a/src/test/java/org/piwik/java/tracking/PiwikJsonArrayTest.java b/src/test/java/org/piwik/java/tracking/PiwikJsonArrayTest.java
deleted file mode 100644
index bed3d3b1..00000000
--- a/src/test/java/org/piwik/java/tracking/PiwikJsonArrayTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Piwik Java Tracker
- *
- * @link https://github.com/piwik/piwik-java-tracker
- * @license https://github.com/piwik/piwik-java-tracker/blob/master/LICENSE BSD-3 Clause
- */
-package org.piwik.java.tracking;
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import javax.json.JsonValue;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
-
-/**
- * @author brettcsorba
- */
-public class PiwikJsonArrayTest {
- PiwikJsonArray array;
-
- public PiwikJsonArrayTest() {
- }
-
- @BeforeClass
- public static void setUpClass() {
- }
-
- @AfterClass
- public static void tearDownClass() {
- }
-
- @Before
- public void setUp() {
- array = new PiwikJsonArray();
- }
-
- @After
- public void tearDown() {
- }
-
- /**
- * Test of get method, of class PiwikJsonArray.
- */
- @Test
- public void testAddGetSet() {
- JsonValue value = mock(JsonValue.class);
- JsonValue value2 = mock(JsonValue.class);
-
- array.add(value);
- assertEquals(value, array.get(0));
-
- array.set(0, value2);
- assertEquals(value2, array.get(0));
- }
-
- /**
- * Test of toString method, of class PiwikJsonArray.
- */
- @Test
- public void testToString() {
- array.add(JsonValue.TRUE);
- array.add(new EcommerceItem("a", "b", "c", 1.0, 2));
- array.add(JsonValue.FALSE);
-
- assertEquals("[true,[\"a\",\"b\",\"c\",1.0,2],false]", array.toString());
- }
-
-}
diff --git a/src/test/java/org/piwik/java/tracking/PiwikJsonObjectTest.java b/src/test/java/org/piwik/java/tracking/PiwikJsonObjectTest.java
deleted file mode 100644
index 358be490..00000000
--- a/src/test/java/org/piwik/java/tracking/PiwikJsonObjectTest.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Piwik Java Tracker
- *
- * @link https://github.com/piwik/piwik-java-tracker
- * @license https://github.com/piwik/piwik-java-tracker/blob/master/LICENSE BSD-3 Clause
- */
-package org.piwik.java.tracking;
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * @author brettcsorba
- */
-public class PiwikJsonObjectTest {
- PiwikJsonObject obj;
-
- public PiwikJsonObjectTest() {
- }
-
- @BeforeClass
- public static void setUpClass() {
- }
-
- @AfterClass
- public static void tearDownClass() {
- }
-
- @Before
- public void setUp() {
- obj = new PiwikJsonObject();
- }
-
- @After
- public void tearDown() {
- }
-
- /**
- * Test of get method, of class PiwikJsonObject.
- */
- @Test
- public void testMethods() {
- assertTrue(obj.isEmpty());
- assertEquals(0, obj.size());
- assertNull(obj.put("key", "value"));
- assertFalse(obj.isEmpty());
- assertEquals(1, obj.size());
- assertEquals("value", obj.get("key"));
- assertEquals("value", obj.remove("key"));
- assertNull(obj.remove("key"));
- assertTrue(obj.isEmpty());
- assertEquals(0, obj.size());
- }
-
- /**
- * Test of toString method, of class PiwikJsonObject.
- */
- @Test
- public void testToString() {
- obj.put("key", "value");
- obj.put("key2", "value2");
- obj.put("key3", "value3");
- obj.remove("key2");
-
- assertEquals("{\"1\":[\"key\",\"value\"],\"2\":[\"key3\",\"value3\"]}", obj.toString());
- }
-
-}