Skip to content

Commit

Permalink
#15799 feedback and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jdotcms committed Mar 28, 2019
1 parent bd11d19 commit a560fc1
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.dotcms.contenttype.model.type.ContentTypeBuilder;
import com.dotcms.contenttype.transform.contenttype.StructureTransformer;
import com.dotcms.datagen.*;
import com.dotcms.exception.ExceptionUtil;
import com.dotcms.mock.request.MockInternalRequest;
import com.dotcms.mock.response.BaseResponse;
import com.dotcms.rendering.velocity.services.VelocityResourceKey;
Expand All @@ -24,6 +25,7 @@
import com.dotmarketing.common.model.ContentletSearch;
import com.dotmarketing.db.HibernateUtil;
import com.dotmarketing.db.LocalTransaction;
import com.dotmarketing.exception.DoesNotExistException;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.factories.TreeFactory;
Expand Down Expand Up @@ -4365,6 +4367,70 @@ public void testCheckinWithoutVersioning_ExistingContentWithCats_NullCats_Should
}
}

/**
* Test checkin with a non-existing contentlet identifier, that should fail
*
*/
@Test
public void testCheckin_Non_Existing_Identifier_With_Validate_Should_FAIL()
throws DotDataException, DotSecurityException {
Contentlet newsContent = null;

try {
newsContent = getNewsContent();
newsContent.setIdentifier(UUIDGenerator.generateUuid());

final List<Category> categories = getACoupleOfCategories();

newsContent = contentletAPI.checkin(newsContent, (ContentletRelationships) null, categories,
null, user,false);

fail("Should throw DoesNotExistException for an unexisting id");
} catch (Exception e) {

assertTrue(ExceptionUtil.causedBy(e, DoesNotExistException.class));
// good
} finally {
if(newsContent!=null && UtilMethods.isSet(newsContent.getIdentifier()) && UtilMethods.isSet(newsContent.getInode())) {
contentletAPI.destroy(newsContent, user, false);
}
}
}

/**
* Test checkin with a non-existing contentlet identifier, that should not fail since the non validate is activated
*
*/
@Test
public void testCheckin_Non_Existing_Identifier_With_Not_Validate_Success()
throws DotDataException, DotSecurityException {
Contentlet newsContent = null;

try {
newsContent = getNewsContent();
String identifier = UUIDGenerator.generateUuid();
newsContent.setIdentifier(identifier);
newsContent.setInode(UUIDGenerator.generateUuid());
newsContent.setBoolProperty(Contentlet.DONT_VALIDATE_ME, true);

final List<Category> categories = getACoupleOfCategories();

final Contentlet newsContentReturned = contentletAPI.checkin(newsContent, (ContentletRelationships) null, categories,
null, user,false);

assertNotNull(newsContentReturned);
assertEquals (newsContentReturned.getIdentifier(), identifier);
newsContent = newsContentReturned;
} catch (DoesNotExistException e) {

// good
} finally {
if(newsContent!=null && UtilMethods.isSet(newsContent.getIdentifier())) {
contentletAPI.destroy(newsContent, user, false);
}
}
}

/**
* This one tests the ContentletAPI.checkin with the following signature:
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import com.dotcms.system.event.local.business.LocalSystemEventsAPI;
import com.dotcms.system.event.local.type.content.CommitListenerEvent;
import com.dotcms.util.CollectionsUtils;
import com.dotcms.uuid.shorty.ShortType;
import com.dotcms.uuid.shorty.ShortyId;
import com.dotmarketing.beans.*;
import com.dotmarketing.business.*;
import com.dotmarketing.business.query.GenericQueryFactory.Query;
Expand Down Expand Up @@ -4904,13 +4906,8 @@ private void validateIdentifier(final Contentlet contentlet) {

if (UtilMethods.isSet(contentlet.getIdentifier())) {

boolean isIdentifier = false;

try {
isIdentifier = APILocator.getIdentifierAPI().isIdentifier(contentlet.getIdentifier());
} catch (DotDataException e) {
isIdentifier = false;
}
final Optional<ShortyId> shortyId = APILocator.getShortyAPI().getShorty(contentlet.getIdentifier());
final boolean isIdentifier = shortyId.isPresent() && shortyId.get().subType== ShortType.IDENTIFIER;

if (!isIdentifier) {

Expand Down

0 comments on commit a560fc1

Please sign in to comment.