Skip to content

Commit

Permalink
#23276 Test documentation has been added.
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel.colina committed May 19, 2023
1 parent d17ef28 commit dec33fc
Showing 1 changed file with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dotmarketing.filters;

import static com.dotcms.datagen.FileAssetDataGen.createFileAsset;
import static com.dotcms.datagen.TestDataUtils.getDotAssetLikeContentlet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -81,6 +82,8 @@ public static void prepare() throws Exception {
final Folder parent4 = new FolderDataGen().name(parent4Name).title(parent4Name).parent(parent3)
.nextPersisted();

final Contentlet fileAsset = createFileAsset(parent2, "test.txt", "");

final Template template = new TemplateDataGen().nextPersisted();
detailPage1 = new HTMLPageDataGen(parent2, template)
.pageURL("news-detail")
Expand All @@ -92,6 +95,7 @@ public static void prepare() throws Exception {
.title("index")
.nextPersisted();


final HttpServletRequest request = mock(HttpServletRequest.class);
session = mock(HttpSession.class);

Expand All @@ -106,8 +110,13 @@ public void prepareTest() {
cmsUrlUtil = CMSUrlUtil.getInstance();
}

/**
* methodToTest {@link CMSUrlUtil#resolvePageAssetSubtype(String, Host, Long)}
* Given Scenario: A Content Type with a URLMap pattern and a detail page exists
* ExpectedResult: Should return a {@link Tuple2} object with true and IAmSubType.PAGE_URL_MAP
*/
@Test
public void whenResolvePageAssetSubtypeWithUrlMap_shouldReturnATupleWithTrueAndPageUrlMap() throws Exception {
public void shouldReturnATupleWithTrueAndPageUrlMap() throws Exception {

// Given
// Create a Content Type with a URLMap pattern and a detail page
Expand All @@ -129,9 +138,6 @@ public void whenResolvePageAssetSubtypeWithUrlMap_shouldReturnATupleWithTrueAndP
.host(site)
.nextPersisted();

final UrlMapContext context = getUrlMapContext(systemUser, site,
newsPatternPrefix + newsTestContent.getStringProperty(field.variable()));

//When
final Tuple2<Boolean, IAmSubType> pageAssetSubtype =
cmsUrlUtil.resolvePageAssetSubtype(
Expand All @@ -143,8 +149,13 @@ public void whenResolvePageAssetSubtypeWithUrlMap_shouldReturnATupleWithTrueAndP

}

/**
* methodToTest {@link CMSUrlUtil#resolvePageAssetSubtype(String, Host, Long)}
* Given Scenario: A Content Type without a URLMap pattern
* ExpectedResult: Should return a {@link Tuple2} object with false and IAmSubType.NONE
*/
@Test
public void whenResolvePageAssetSubtypeWithContentletType_shouldReturnATupleWithFalseAndNone() {
public void shouldReturnATupleWithFalseAndNone() {
// Given
// Create a Content Type as a Contentlet Type
final String newsPatternPrefix =
Expand All @@ -171,8 +182,13 @@ public void whenResolvePageAssetSubtypeWithContentletType_shouldReturnATupleWith
assertEquals(IAmSubType.NONE, pageAssetSubtype._2());
}

/**
* methodToTest {@link CMSUrlUtil#resolvePageAssetSubtype(String, Host, Long)}
* Given Scenario: A HtmlPage with a detail page and without a URLMap pattern
* ExpectedResult: Should return a {@link Tuple2} object with true and IAmSubType.NONE
*/
@Test
public void whenResolvePageAssetSubtypeWithHtmlPage_shouldReturnATupleWithTrueAndNone() {
public void shouldReturnATupleWithTrueAndNone() {
// Given
final String newsPatternPrefix = "/news-events/news/news-detail";
final Contentlet newsTestContent = getDotAssetLikeContentlet();
Expand All @@ -187,8 +203,13 @@ public void whenResolvePageAssetSubtypeWithHtmlPage_shouldReturnATupleWithTrueAn
assertEquals(IAmSubType.NONE, pageAssetSubtype._2());
}

/**
* methodToTest {@link CMSUrlUtil#resolveResourceType(IAm, String, Host, long)}
* Given Scenario: A Content Type with a URLMap pattern and a detail page exists
* ExpectedResult: Should return a {@link Tuple2} object with IAm.PAGE and IAmSubType.PAGE_URL_MAP
*/
@Test
public void whenResolveResourceTypeWithUrlMap_shouldReturnATupleWithTrueAndPageUrlMap() {
public void whenResolveResourceType_shouldReturnATupleWithPageAndPageUrlMap() {
// Given
// Create a Content Type with a URLMap pattern and a detail page
final String newsPatternPrefix =
Expand Down Expand Up @@ -218,8 +239,13 @@ public void whenResolveResourceTypeWithUrlMap_shouldReturnATupleWithTrueAndPageU

}

/**
* methodToTest {@link CMSUrlUtil#resolveResourceType(IAm, String, Host, long)}
* Given Scenario: A HtmlPage with a detail page and without a URLMap pattern associated
* ExpectedResult: Should return a {@link Tuple2} object with IAm.PAGE and IAmSubType.NONE
*/
@Test
public void whenResolveResourceTypeWithHtmlPage_shouldReturnATupleWithPageAndNone() {
public void whenResolveResourceType_shouldReturnATupleWithPageAndNone() {
// Given
final String newsPatternPrefix = "/news-events/news/news-detail";
final Contentlet newsTestContent = getDotAssetLikeContentlet();
Expand All @@ -233,8 +259,13 @@ public void whenResolveResourceTypeWithHtmlPage_shouldReturnATupleWithPageAndNon
assertEquals(IAmSubType.NONE, type._2());
}

/**
* methodToTest {@link CMSUrlUtil#resolveResourceType(IAm, String, Host, long)}
* Given Scenario: A site with folder structure exists
* ExpectedResult: Should return a {@link Tuple2} object with IAm.FOLDER and IAmSubType.NONE
*/
@Test
public void whenResolveResourceTypeWithFolder_shouldReturnATupleWithFolderAndNone() {
public void whenResolveResourceType_shouldReturnATupleWithFolderAndNone() {
// Given
final String newsPatternPrefix = "/news-events/news/";

Expand All @@ -247,8 +278,13 @@ public void whenResolveResourceTypeWithFolder_shouldReturnATupleWithFolderAndNon
assertEquals(IAmSubType.NONE, type._2());
}

/**
* methodToTest {@link CMSUrlUtil#resolveResourceType(IAm, String, Host, long)}
* Given Scenario: A site with folder structure exists and an index page is inside the folder
* ExpectedResult: Should return a {@link Tuple2} object with IAm.PAGE and IAmSubType.PAGE_INDEX
*/
@Test
public void whenResolveResourceTypeWithPageIndex_shouldReturnATupleWithPageAndPageIndex() {
public void whenResolveResourceType_shouldReturnATupleWithPageAndPageIndex() {
// Given
final String newsPatternPrefix = "/news-events2/news2/";

Expand Down

0 comments on commit dec33fc

Please sign in to comment.