From 783a7d82c65307c6709f6f7aa5e4e021698c0f44 Mon Sep 17 00:00:00 2001 From: jdotcms Date: Fri, 29 Nov 2024 14:00:01 -0600 Subject: [PATCH] #30411 adding fixes for it test --- .../collectors/PageDetailCollectorTest.java | 27 ++++--- .../track/collectors/PagesCollectorTest.java | 54 ++++++++----- .../collectors/SyncVanitiesCollectorTest.java | 22 +++--- .../WebEventsCollectorServiceImplTest.java | 76 +++++++++++-------- 4 files changed, 107 insertions(+), 72 deletions(-) diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java index a03992d5450b..e0dbd6fa32f2 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PageDetailCollectorTest.java @@ -11,6 +11,7 @@ import com.dotmarketing.beans.Host; import com.dotmarketing.business.APILocator; import com.dotmarketing.exception.DotDataException; +import com.dotmarketing.exception.DotSecurityException; import com.dotmarketing.portlets.contentlet.model.Contentlet; import com.dotmarketing.portlets.contentlet.model.IndexPolicy; import com.dotmarketing.portlets.htmlpageasset.model.HTMLPageAsset; @@ -70,7 +71,7 @@ public static void prepare() throws Exception { * */ @Test - public void testPageDetailCollector() throws DotDataException, UnknownHostException { + public void testPageDetailCollector() throws DotDataException, UnknownHostException, DotSecurityException { final HttpServletResponse response = mock(HttpServletResponse.class); final String requestId = UUIDUtil.uuid(); final HttpServletRequest request = Util.mockHttpRequestObj(response, @@ -100,15 +101,21 @@ public void testPageDetailCollector() throws DotDataException, UnknownHostExcept ContentletDataGen.publish(newsTestContent); final Map expectedDataMap = Map.of( - "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getHostname(), - "language", language.getIsoCode(), - "url", TEST_URL_MAP_DETAIL_PAGE_URL, - "object", Map.of( - "id", testDetailPage.getIdentifier(), - "title", testDetailPage.getTitle(), - "url", TEST_URL_MAP_DETAIL_PAGE_URL, - "detail_page_url", testDetailPage.getURI()) + Collector.EVENT_TYPE, EventType.PAGE_REQUEST.getType(), + Collector.SITE_NAME, testSite.getHostname(), + Collector.LANGUAGE, language.getIsoCode(), + Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL, + Collector.OBJECT, Map.of( + Collector.ID, testDetailPage.getIdentifier(), + Collector.TITLE, testDetailPage.getTitle(), + Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL, + Collector.CONTENT_TYPE_ID, testDetailPage.getContentType().id(), + Collector.CONTENT_TYPE_NAME, testDetailPage.getContentType().name(), + Collector.CONTENT_TYPE_VAR_NAME, testDetailPage.getContentType().variable(), + Collector.BASE_TYPE, testDetailPage.getContentType().baseType().name(), + Collector.LIVE, testDetailPage.isLive(), + Collector.WORKING, testDetailPage.isWorking(), + Collector.DETAIL_PAGE_URL, testDetailPage.getURI()) ); final Collector collector = new PageDetailCollector(); diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java index 934269c23996..515880d80e2e 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/PagesCollectorTest.java @@ -73,7 +73,7 @@ public static void prepare() throws Exception { * */ @Test - public void collectPageData() throws DotDataException, UnknownHostException { + public void collectPageData() throws Exception { final HttpServletResponse response = mock(HttpServletResponse.class); final String requestId = UUIDUtil.uuid(); final HttpServletRequest request = Util.mockHttpRequestObj(response, TEST_PAGE_URL, @@ -82,14 +82,21 @@ public void collectPageData() throws DotDataException, UnknownHostException { final HTMLPageAsset testPage = Util.createTestHTMLPage(testSite, TEST_PAGE_NAME); final Map expectedDataMap = Map.of( - "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getHostname(), - "language", APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), - "url", TEST_PAGE_URL, - "object", Map.of( - "id", testPage.getIdentifier(), - "title", testPage.getTitle(), - "url", testPage.getURI()) + Collector.EVENT_TYPE, EventType.PAGE_REQUEST.getType(), + Collector.SITE_NAME, testSite.getHostname(), + Collector.LANGUAGE, APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), + Collector.URL, TEST_PAGE_URL, + Collector.OBJECT, Map.of( + Collector.ID, testPage.getIdentifier(), + Collector.TITLE, testPage.getTitle(), + Collector.URL, TEST_PAGE_URL, + Collector.CONTENT_TYPE_ID, testPage.getContentType().id(), + Collector.CONTENT_TYPE_NAME, testPage.getContentType().name(), + Collector.CONTENT_TYPE_VAR_NAME, testPage.getContentType().variable(), + Collector.BASE_TYPE, testPage.getContentType().baseType().name(), + Collector.LIVE, testPage.isLive(), + Collector.WORKING, testPage.isWorking(), + Collector.DETAIL_PAGE_URL, testPage.getURI()) ); final Collector collector = new PagesCollector(); @@ -116,7 +123,7 @@ public void collectPageData() throws DotDataException, UnknownHostException { * */ @Test - public void collectUrlMapPageData() throws DotDataException, UnknownHostException { + public void collectUrlMapPageData() throws Exception { final HttpServletResponse response = mock(HttpServletResponse.class); final String requestId = UUIDUtil.uuid(); final HttpServletRequest request = Util.mockHttpRequestObj(response, @@ -148,17 +155,22 @@ public void collectUrlMapPageData() throws DotDataException, UnknownHostExceptio ContentletDataGen.publish(newsTestContent); final Map expectedDataMap = Map.of( - "event_type", EventType.URL_MAP.getType(), - "host", testSite.getHostname(), - "language", APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), - "url", TEST_URL_MAP_DETAIL_PAGE_URL, - "object", Map.of( - "content_type_var_name", urlMappedContentType.variable(), - "content_type_id", urlMappedContentType.id(), - "id", newsTestContent.getIdentifier(), - "content_type_name", urlMappedContentType.name(), - "title", urlTitle, - "url", TEST_URL_MAP_DETAIL_PAGE_URL) + Collector.EVENT_TYPE, EventType.URL_MAP.getType(), + Collector.SITE_NAME, testSite.getHostname(), + Collector.LANGUAGE, APILocator.getLanguageAPI().getDefaultLanguage().getIsoCode(), + Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL, + Collector.OBJECT, Map.of( + Collector.ID, newsTestContent.getIdentifier(), + Collector.TITLE, urlTitle, + Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL, + Collector.CONTENT_TYPE_ID, urlMappedContentType.id(), + Collector.CONTENT_TYPE_NAME, urlMappedContentType.name(), + Collector.CONTENT_TYPE_VAR_NAME, urlMappedContentType.variable(), + Collector.BASE_TYPE, testDetailPage.getContentType().baseType().name(), + Collector.LIVE, newsTestContent.isLive(), + Collector.WORKING, newsTestContent.isWorking(), + Collector.DETAIL_PAGE_URL, testDetailPage.getURI() + ) ); final Collector collector = new PagesCollector(); diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollectorTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollectorTest.java index 636e6cbfe1ab..c0bcb1f3c993 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollectorTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/SyncVanitiesCollectorTest.java @@ -87,17 +87,17 @@ public void collectSyncVanityData() throws DotDataException, IOException, DotSec assertTrue("Resolved vanity url must be present", resolvedVanity.isPresent()); final Map expectedDataMap = Map.of( - "site", testSite.getIdentifier(), - "event_type", EventType.VANITY_REQUEST.getType(), - "language", defaultLanguage.getIsoCode(), - "vanity_url", TEST_PAGE_URL, - "language_id", defaultLanguage.getId(), - "url", URI, - "object", Map.of( - "forward_to", TEST_PAGE_URL, - "response", "200", - "id", resolvedVanity.get().vanityUrlId, - "url", URI) + Collector.SITE_ID, testSite.getIdentifier(), + Collector.EVENT_TYPE, EventType.VANITY_REQUEST.getType(), + Collector.LANGUAGE, defaultLanguage.getIsoCode(), + Collector.VANITY_URL_KEY, TEST_PAGE_URL, + Collector.LANGUAGE_ID, defaultLanguage.getId(), + Collector.URL, URI, + Collector.OBJECT, Map.of( + Collector.FORWARD_TO, TEST_PAGE_URL, + Collector.RESPONSE, "200", + Collector.ID, resolvedVanity.get().vanityUrlId, + Collector.URL, URI) ); final Collector collector = new SyncVanitiesCollector(); diff --git a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java index e80bf21f71bb..a9192473dbb9 100644 --- a/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/analytics/track/collectors/WebEventsCollectorServiceImplTest.java @@ -220,7 +220,7 @@ public void testPagesCollector() throws DotDataException, IOException { * */ @Test - public void testPageDetailCollector() throws DotDataException, IOException { + public void testPageDetailCollector() throws Exception { testDetailPage = null != testDetailPage ? testDetailPage : Util.createTestHTMLPage(testSite, TEST_URL_MAP_PAGE_NAME, PARENT_FOLDER_1_NAME); final String urlTitle = "mynews"; @@ -243,15 +243,24 @@ public void testPageDetailCollector() throws DotDataException, IOException { final Contentlet newsTestContent = contentletDataGen.nextPersisted(); ContentletDataGen.publish(newsTestContent); final Map expectedDataMap = Map.of( - "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getHostname(), - "language", language.getIsoCode(), - "url", TEST_URL_MAP_DETAIL_PAGE_URL, - "object", Map.of( - "id", testDetailPage.getIdentifier(), - "title", testDetailPage.getTitle(), - "url", TEST_URL_MAP_DETAIL_PAGE_URL, - "detail_page_url", testDetailPage.getURI()) + Collector.EVENT_TYPE, EventType.PAGE_REQUEST.getType(), + Collector.SITE_NAME, testSite.getHostname(), + Collector.LANGUAGE, language.getIsoCode(), + Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL, + Collector.OBJECT, Map.of( + Collector.ID, testDetailPage.getIdentifier(), + Collector.TITLE, testDetailPage.getTitle(), + Collector.URL, TEST_URL_MAP_DETAIL_PAGE_URL, + Collector.CONTENT_TYPE_ID, testDetailPage.getContentType().id(), + Collector.CONTENT_TYPE_NAME, testDetailPage.getContentType().name(), + Collector.CONTENT_TYPE_VAR_NAME, testDetailPage.getContentType().variable(), + Collector.BASE_TYPE, testDetailPage.getContentType().baseType().name(), + Collector.LIVE, testDetailPage.isLive(), + Collector.WORKING, testDetailPage.isWorking(), + Collector.DETAIL_PAGE_URL, testDetailPage.getURI() + + + ) ); final TestEventLogSubmitter submitter = new TestEventLogSubmitter(); @@ -293,17 +302,17 @@ public void testSyncVanitiesCollector() throws DotDataException, IOException, Do assertTrue(resolvedVanity.isPresent(), "Test resolved vanity url must be present"); final Map expectedDataMap = Map.of( - "site", testSite.getIdentifier(), - "event_type", EventType.VANITY_REQUEST.getType(), - "language", defaultLanguage.getIsoCode(), - "vanity_url", TEST_PAGE_URL, - "language_id", (int) defaultLanguage.getId(), - "url", URI, - "object", Map.of( - "forward_to", TEST_PAGE_URL, - "response", "200", - "id", resolvedVanity.get().vanityUrlId, - "url", URI) + Collector.SITE_ID, testSite.getIdentifier(), + Collector.EVENT_TYPE, EventType.VANITY_REQUEST.getType(), + Collector.LANGUAGE, defaultLanguage.getIsoCode(), + Collector.VANITY_URL_KEY, TEST_PAGE_URL, + Collector.LANGUAGE_ID, (int) defaultLanguage.getId(), + Collector.URL, URI, + Collector.OBJECT, Map.of( + Collector.FORWARD_TO, TEST_PAGE_URL, + Collector.RESPONSE, "200", + Collector.ID, resolvedVanity.get().vanityUrlId, + Collector.URL, URI) ); final TestEventLogSubmitter submitter = new TestEventLogSubmitter(); @@ -352,15 +361,22 @@ public void testAsyncVanitiesCollector() throws DotDataException, IOException, D assertTrue(resolvedVanity.isPresent(), "Test resolved vanity url must be present"); final Map expectedDataMap = Map.of( - "event_type", EventType.PAGE_REQUEST.getType(), - "host", testSite.getHostname(), - "comeFromVanityURL", true, - "language", defaultLanguage.getIsoCode(), - "url", TEST_PAGE_URL, - "object", Map.of( - "id", testPage.getIdentifier(), - "title", TEST_PAGE_NAME, - "url", TEST_PAGE_URL) + Collector.EVENT_TYPE, EventType.PAGE_REQUEST.getType(), + Collector.SITE_NAME, testSite.getHostname(), + Collector.COME_FROM_VANITY_URL, true, + Collector.LANGUAGE, defaultLanguage.getIsoCode(), + Collector.URL, TEST_PAGE_URL, + Collector.OBJECT, Map.of( + Collector.ID, testPage.getIdentifier(), + Collector.TITLE, TEST_PAGE_NAME, + Collector.URL, TEST_PAGE_URL, + Collector.CONTENT_TYPE_ID, testPage.getContentType().id(), + Collector.CONTENT_TYPE_NAME, testPage.getContentType().name(), + Collector.CONTENT_TYPE_VAR_NAME, testPage.getContentType().variable(), + Collector.BASE_TYPE, testPage.getContentType().baseType().name(), + Collector.LIVE, testPage.isLive(), + Collector.WORKING, testPage.isWorking(), + Collector.DETAIL_PAGE_URL, testPage.getURI()) ); final TestEventLogSubmitter submitter = new TestEventLogSubmitter();