-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Normalizing the host values to hostname all the times
- Loading branch information
Showing
13 changed files
with
238 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
dotCMS/src/test/java/com/dotcms/analytics/track/collectors/CustomerEventCollectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.dotcms.analytics.track.collectors; | ||
|
||
import com.dotcms.analytics.track.matchers.RequestMatcher; | ||
import com.dotmarketing.beans.Host; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Test for the CustomerEventCollector class | ||
* @author jsanca | ||
* | ||
*/ | ||
public class CustomerEventCollectorTest { | ||
|
||
/** | ||
* Method to test: CustomerEventCollector#collect | ||
* Given Scenario: Fill the preconditions and check the collect bean is properly filled | ||
* ExpectedResult: the CollectorPayloadBean should be filled properly | ||
*/ | ||
@Test | ||
public void test_collect_easy_path() throws IOException { | ||
|
||
final CustomerEventCollector customerEventCollector = new CustomerEventCollector(); | ||
final Host host = new Host(); | ||
host.setIdentifier("1"); | ||
host.setHostname("www.dotcms.com"); | ||
final CollectorContextMap collectorContextMap = new CollectorContextMap() { | ||
@Override | ||
public Object get(final String key) { | ||
switch (key) { | ||
case "uri": | ||
return "/test-path"; | ||
case "host": | ||
return "www2.dotcms.com"; | ||
case "currentHost": | ||
return host; | ||
case "lang": | ||
return "en"; | ||
case "eventType": | ||
return null; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public RequestMatcher getRequestMatcher() { | ||
return null; | ||
} | ||
}; | ||
|
||
final CollectorPayloadBean collectorPayloadBean = new ConcurrentCollectorPayloadBean(); | ||
customerEventCollector.collect(collectorContextMap, collectorPayloadBean); | ||
|
||
Assert.assertEquals("/test-path", collectorPayloadBean.get("url")); | ||
Assert.assertEquals("www.dotcms.com", collectorPayloadBean.get("host")); | ||
Assert.assertEquals("en", collectorPayloadBean.get("language")); | ||
Assert.assertEquals("1", collectorPayloadBean.get("site")); | ||
Assert.assertEquals(EventType.CUSTOM_USER_EVENT.getType(), collectorPayloadBean.get("event_type")); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
dotCMS/src/test/java/com/dotcms/analytics/track/collectors/FilesCollectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.dotcms.analytics.track.collectors; | ||
|
||
import com.dotcms.analytics.track.matchers.RequestMatcher; | ||
import com.dotmarketing.beans.Host; | ||
import com.dotmarketing.portlets.contentlet.model.Contentlet; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Test for the FilesCollector class | ||
* @author jsanca | ||
* | ||
*/ | ||
public class FilesCollectorTest { | ||
|
||
/** | ||
* Method to test: FilesCollector#collect | ||
* Given Scenario: Fill the preconditions and check the collect bean is properly filled | ||
* ExpectedResult: the CollectorPayloadBean should be filled properly | ||
*/ | ||
@Test | ||
public void test_collect_easy_path() throws IOException { | ||
|
||
final FilesCollector filesCollector = new FilesCollector() { | ||
@Override | ||
protected Optional<Contentlet> getFileAsset(String uri, Host host, Long languageId) { | ||
final Contentlet contentlet = Mockito.mock(Contentlet.class); | ||
Mockito.when(contentlet.getIdentifier()).thenReturn("1"); | ||
Mockito.when(contentlet.getTitle()).thenReturn("Test"); | ||
return Optional.ofNullable(contentlet); | ||
} | ||
}; | ||
final Host host = new Host(); | ||
host.setIdentifier("1"); | ||
host.setHostname("www.dotcms.com"); | ||
final CollectorContextMap collectorContextMap = new CollectorContextMap() { | ||
@Override | ||
public Object get(final String key) { | ||
switch (key) { | ||
case "uri": | ||
return "/test-path"; | ||
case "host": | ||
return "www2.dotcms.com"; | ||
case "currentHost": | ||
return host; | ||
case "lang": | ||
return "en"; | ||
case "langId": | ||
return 1L; | ||
case "eventType": | ||
return null; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public RequestMatcher getRequestMatcher() { | ||
return null; | ||
} | ||
}; | ||
|
||
final CollectorPayloadBean collectorPayloadBean = new ConcurrentCollectorPayloadBean(); | ||
filesCollector.collect(collectorContextMap, collectorPayloadBean); | ||
|
||
final Map<String, String> fileObject = (Map<String, String>) collectorPayloadBean.get("object"); | ||
Assert.assertNotNull(fileObject); | ||
Assert.assertEquals("1", fileObject.get("id")); | ||
Assert.assertEquals("Test", fileObject.get("title")); | ||
Assert.assertEquals("/test-path", fileObject.get("url")); | ||
Assert.assertEquals("/test-path", collectorPayloadBean.get("url")); | ||
Assert.assertEquals("www.dotcms.com", collectorPayloadBean.get("host")); | ||
Assert.assertEquals("en", collectorPayloadBean.get("language")); | ||
Assert.assertEquals("1", collectorPayloadBean.get("site")); | ||
Assert.assertEquals(EventType.FILE_REQUEST.getType(), collectorPayloadBean.get("event_type")); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
dotCMS/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.dotcms.analytics.track.collectors; | ||
|
||
import com.dotcms.analytics.track.matchers.RequestMatcher; | ||
import com.dotmarketing.beans.Host; | ||
import com.dotmarketing.cms.urlmap.URLMapAPIImpl; | ||
import com.dotmarketing.portlets.contentlet.model.Contentlet; | ||
import com.dotmarketing.portlets.htmlpageasset.business.HTMLPageAssetAPI; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Test for the {@link PagesCollector} class | ||
* @author jsanca | ||
* | ||
*/ | ||
public class PagesCollectorTest { | ||
|
||
/** | ||
* Method to test: PagesCollector#collect | ||
* Given Scenario: Fill the preconditions and check the collect bean is properly filled | ||
* ExpectedResult: the CollectorPayloadBean should be filled properly | ||
*/ | ||
@Test | ||
public void test_collect_easy_path() throws IOException { | ||
|
||
final PagesCollector pagesCollector = new PagesCollector(Mockito.mock(HTMLPageAssetAPI.class), Mockito.mock(URLMapAPIImpl.class)); | ||
final Host host = new Host(); | ||
host.setIdentifier("1"); | ||
host.setHostname("www.dotcms.com"); | ||
final CollectorContextMap collectorContextMap = new CollectorContextMap() { | ||
@Override | ||
public Object get(final String key) { | ||
switch (key) { | ||
case "uri": | ||
return "/test-path"; | ||
case "host": | ||
return "www2.dotcms.com"; | ||
case "currentHost": | ||
return host; | ||
case "lang": | ||
return "en"; | ||
case "langId": | ||
return null; | ||
case "eventType": | ||
return null; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public RequestMatcher getRequestMatcher() { | ||
return null; | ||
} | ||
}; | ||
|
||
|
||
final CollectorPayloadBean collectorPayloadBean = new ConcurrentCollectorPayloadBean(); | ||
pagesCollector.collect(collectorContextMap, collectorPayloadBean); | ||
|
||
Assert.assertEquals("/test-path", collectorPayloadBean.get("url")); | ||
Assert.assertEquals("www.dotcms.com", collectorPayloadBean.get("host")); | ||
Assert.assertEquals("en", collectorPayloadBean.get("language")); | ||
Assert.assertEquals(EventType.PAGE_REQUEST.getType(), collectorPayloadBean.get("event_type")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.