Skip to content

Commit

Permalink
#11265 : Merging from master.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcastro-dotcms committed Jan 16, 2018
2 parents d314a04 + 7ee38b2 commit f9e34a3
Show file tree
Hide file tree
Showing 95 changed files with 3,042 additions and 1,229 deletions.
2 changes: 1 addition & 1 deletion dotCMS/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ dependencies {
compile group: 'com.dotcms.lib', name: 'dot.guava', version:'11.0.1_2'
compile group: 'com.dotcms.lib', name: 'dot.hadoop-dev-core', version:'0.20.3_2'
compile group: 'com.dotcms.lib', name: 'dot.hadoop-dev-tools', version:'0.20.3_2'
compile group: 'com.hazelcast', name: 'hazelcast-all', version: '3.8.4'
compile group: 'com.hazelcast', name: 'hazelcast-all', version: '3.9.2'
compile group: 'com.dotcms.lib', name: 'dot.hibernate', version:'2.1.7_2'
compile group: 'com.dotcms.lib', name: 'dot.httpbridge', version:'ukv_2'
compile group: 'com.dotcms.lib', name: 'dot.httpclient', version:'4.2.2_2'
Expand Down
4 changes: 2 additions & 2 deletions dotCMS/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ dotcmsReleaseVersion=4.3.0
coreWebReleaseVersion=latest

tomcatInstallRepo=https://github.com/dotCMS/tomcat.git
tomcatInstallBranch=8.0.18-4.2
tomcatInstallVersion=8.0.18
tomcatInstallBranch=8.5.24
tomcatInstallVersion=8.5.24
tomcatInstallLocation=../../tomcat8

jboss7InstallVersion=7.1.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,60 +68,11 @@ public void createAssets() throws Exception {
HibernateUtil.startTransaction();

// CONTAINER
container = new Container();
container = APILocator.getContainerAPI().find("dde0b865-6cea-4ff0-8582-85e5974cf94f", user, false);

Structure simpleWidgetSt = CacheLocator.getContentTypeCache().getStructureByVelocityVarName("SimpleWidget");

container.setCode( "$!{story}" );
container.setFriendlyName( "newsTestContainer" );
container.setIDate(new Date());
container.setLuceneQuery("");
container.setMaxContentlets(1);
container.setModDate(new Date());
container.setModUser(user.getUserId());
container.setNotes("newsTestContainer");
container.setOwner(user.getUserId());
container.setPostLoop("");
container.setPreLoop("");
container.setShowOnMenu(true);
container.setSortContentletsBy("");
container.setSortOrder(2);
container.setStaticify(true);
container.setTitle("News Test Container");
container.setType(Inode.Type.CONTAINERS.getValue());
container.setUseDiv( true );

List<ContainerStructure> csList = new ArrayList<ContainerStructure>();
ContainerStructure cs = new ContainerStructure();
cs.setStructureId(simpleWidgetSt.getInode());
cs.setCode("$!{story}");
csList.add(cs);

container = APILocator.getContainerAPI().save(container, csList, demoHost, user, false);
APILocator.getVersionableAPI().setLive( container );


// TEMPLATE
template = new Template();

String body = "#parseContainer('" + container.getIdentifier() + "')";
template.setBody( body );
template.setFooter( "" );
template.setFriendlyName( "newsTestTemplate" );
template.setHeader( "" );
template.setIDate( new Date() );
template.setImage( "" );
template.setModDate( new Date() );
template.setModUser( user.getUserId() );
template.setOwner( user.getUserId() );
template.setSelectedimage( "" );
template.setShowOnMenu( true );
template.setSortOrder( 2 );
template.setTitle( "News Test Template" );
template.setType( "template" );

template = APILocator.getTemplateAPI().saveTemplate( template, demoHost, user, false );
APILocator.getVersionableAPI().setLive(template);
template = APILocator.getTemplateAPI().find("941a3f59-0d87-4084-8d9c-aca29a26ec8c",user,false);


// FOLDER
Expand Down Expand Up @@ -327,11 +278,9 @@ public void testURLMaps() throws Exception {

@After
public void deleteAssets() throws Exception {
try{
try{
HibernateUtil.startTransaction();
if(testFolder!=null) APILocator.getFolderAPI().delete(testFolder, user, false);
if(template!=null) APILocator.getTemplateAPI().delete(template, user, false);
if(container!=null) APILocator.getContainerAPI().delete(container, user, false);
if(testSt!=null) APILocator.getStructureAPI().delete(testSt, user);
if(widget!=null) APILocator.getContentletAPI().delete(widget, user, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

import static org.hamcrest.MatcherAssert.assertThat;

import com.dotmarketing.util.UtilMethods;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.dotcms.rest.api.v1.contenttype.ContentTypeForm;
import com.dotcms.util.ConfigTestHelper;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Test;

import com.dotcms.contenttype.exception.NotFoundInDbException;
Expand Down Expand Up @@ -55,20 +56,26 @@ public void testJson(String jsonFile) throws Exception {
List<ContentType> delTypes = new JsonContentTypeTransformer(json).asList();
for(ContentType delType:delTypes){
try {
contentTypeApi.delete(contentTypeApi.find(delType.id()));
if (UtilMethods.isSet(delType.id())){
contentTypeApi.delete(contentTypeApi.find(delType.id()));
}
} catch (NotFoundInDbException e) {

}
try {
contentTypeApi.delete(contentTypeApi.find(delType.variable()));
if (UtilMethods.isSet(delType.variable())){
contentTypeApi.delete(contentTypeApi.find(delType.variable()));
}
} catch (NotFoundInDbException ee) {

}
}

ContentTypeResource resource = new ContentTypeResource();
final ContentTypeResource resource = new ContentTypeResource();

Response response = resource.createType(getHttpRequest(), json);
final ContentTypeForm.ContentTypeFormDeserialize contentTypeFormDeserialize = new ContentTypeForm.ContentTypeFormDeserialize();
ContentTypeForm contentTypeForm = contentTypeFormDeserialize.buildForm(json);
Response response = resource.createType(getHttpRequest(), contentTypeForm);

int x = response.getStatus();
assertThat("result:200 with json " + jsonFile + "got :" + x, x == 200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.liferay.portal.model.User;

import javax.servlet.http.HttpSession;
import org.apache.velocity.context.Context;
import org.apache.velocity.tools.view.context.ViewContext;
import org.junit.Assert;
Expand All @@ -35,7 +36,7 @@ public static void prepare() throws Exception {
public void testPullMultiLanguage() throws Exception { // https://github.com/dotCMS/core/issues/11172

// Test uses Spanish language
long LANGUAGE_ID = 2;
final long languageId = 2;

User user = APILocator.getUserAPI().getSystemUser();

Expand All @@ -45,7 +46,7 @@ public void testPullMultiLanguage() throws Exception { // https://github.com/dot


// Create dummy "News" content in Spanish language
ContentletDataGen contentletDataGen = new ContentletDataGen(contentType.inode()).host(host).languageId(LANGUAGE_ID);
ContentletDataGen contentletDataGen = new ContentletDataGen(contentType.inode()).host(host).languageId(languageId);

contentletDataGen.setProperty("title", "El Titulo");
contentletDataGen.setProperty("byline", "El Sub Titulo");
Expand All @@ -61,11 +62,14 @@ public void testPullMultiLanguage() throws Exception { // https://github.com/dot
ViewContext viewContext = mock(ViewContext.class);
Context velocityContext = mock(Context.class);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpSession session = mock(HttpSession.class);

when(viewContext.getVelocityContext()).thenReturn(velocityContext);
when(viewContext.getRequest()).thenReturn(request);
when(request.getParameter("host_id")).thenReturn(host.getInode());
when(request.getParameter("language_id")).thenReturn(String.valueOf(LANGUAGE_ID));
when(request.getParameter("language_id")).thenReturn(String.valueOf(languageId));
when(request.getSession(false)).thenReturn(session);
when(session.getAttribute(com.dotmarketing.util.WebKeys.CMS_USER)).thenReturn(user);

ContentTool contentTool = new ContentTool();
contentTool.init(viewContext);
Expand All @@ -88,7 +92,7 @@ public void testPullMultiLanguage() throws Exception { // https://github.com/dot
// Ensure that every returned content is in Spanish Language
Assert.assertFalse(results.isEmpty());
for(ContentMap cm : results) {
Assert.assertEquals(cm.getContentObject().getLanguageId(), LANGUAGE_ID);
Assert.assertEquals(cm.getContentObject().getLanguageId(), languageId);
}
} finally {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ public void testMain() throws Exception {
Response response = null;
Map<String, Object> fieldMap = null;

ContentTypeForm.ContentTypeFormDeserialize contentTypeFormDeserialize = new ContentTypeForm.ContentTypeFormDeserialize();

// Test INVALID Content Type Creation
assertResponse_BAD_REQUEST(
response = resource.createType(getHttpRequest(), JSON_CONTENT_TYPE_UPDATE.replace("CONTENT_TYPE_ID", "INVALID_CONTENT_TYPE_ID"))
response = resource.createType(getHttpRequest(), contentTypeFormDeserialize.buildForm(JSON_CONTENT_TYPE_UPDATE.replace("CONTENT_TYPE_ID", "INVALID_CONTENT_TYPE_ID")))
);

// Test Content Type Creation
RestUtilTest.verifySuccessResponse(
response = resource.createType(getHttpRequest(), JSON_CONTENT_TYPE_CREATE)
response = resource.createType(getHttpRequest(), contentTypeFormDeserialize.buildForm(JSON_CONTENT_TYPE_CREATE))
);

try {
Expand Down Expand Up @@ -93,7 +95,7 @@ public void testMain() throws Exception {
assertResponse_BAD_REQUEST(
response = resource.updateType(
(String) fieldMap.get("id"),
JSON_CONTENT_TYPE_UPDATE.replace("CONTENT_TYPE_ID", "INVALID_CONTENT_TYPE_ID"),
contentTypeFormDeserialize.buildForm(JSON_CONTENT_TYPE_UPDATE.replace("CONTENT_TYPE_ID", "INVALID_CONTENT_TYPE_ID")),
getHttpRequest()
)
);
Expand All @@ -102,7 +104,7 @@ public void testMain() throws Exception {
RestUtilTest.verifySuccessResponse(
response = resource.updateType(
(String) fieldMap.get("id"),
JSON_CONTENT_TYPE_UPDATE.replace("CONTENT_TYPE_ID", (String) fieldMap.get("id")),
contentTypeFormDeserialize.buildForm(JSON_CONTENT_TYPE_UPDATE.replace("CONTENT_TYPE_ID", (String) fieldMap.get("id"))),
getHttpRequest()
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import com.dotcms.business.WrapInTransaction;
import com.dotcms.content.business.DotMappingException;
import com.dotcms.content.elasticsearch.business.ESMappingAPIImpl;
import com.dotcms.contenttype.business.ContentTypeAPIImpl;
Expand All @@ -31,6 +32,7 @@
import com.dotcms.datagen.TemplateDataGen;
import com.dotcms.mock.request.MockInternalRequest;
import com.dotcms.mock.response.BaseResponse;
import com.dotcms.rendering.velocity.services.VelocityType;
import com.dotcms.repackage.org.apache.commons.io.FileUtils;
import com.dotcms.repackage.org.apache.commons.lang.time.FastDateFormat;
import com.dotmarketing.beans.Host;
Expand Down Expand Up @@ -72,8 +74,8 @@
import com.dotmarketing.portlets.structure.model.Structure;
import com.dotmarketing.portlets.templates.model.Template;
import com.dotmarketing.tag.model.Tag;
import com.dotmarketing.util.Config;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PageMode;
import com.dotmarketing.util.UUIDGenerator;
import com.dotmarketing.util.UtilMethods;
import com.dotcms.rendering.velocity.util.VelocityUtil;
Expand Down Expand Up @@ -2159,7 +2161,6 @@ public void widgetInvalidateAllLang() throws Exception {
/*
* For every language we should get the same content and contentMap template code
*/
String contentEXT=Config.getStringProperty("VELOCITY_CONTENT_EXTENSION", "content");
VelocityEngine engine = VelocityUtil.getEngine();
SimpleNode contentTester = engine.getRuntimeServices().parse(new StringReader("code:$code"), "tester1");

Expand All @@ -2168,8 +2169,12 @@ public void widgetInvalidateAllLang() throws Exception {
requestProxy.setAttribute(WebKeys.HTMLPAGE_LANGUAGE, "1");
requestProxy.setAttribute(com.liferay.portal.util.WebKeys.USER,APILocator.getUserAPI().getSystemUser());

org.apache.velocity.Template teng1 = engine.getTemplate("/live/"+w.getIdentifier()+"_1."+contentEXT);
org.apache.velocity.Template tesp1 = engine.getTemplate("/live/"+w.getIdentifier()+"_2."+contentEXT);
org.apache.velocity.Template teng1 = engine.getTemplate(
File.separator + PageMode.LIVE.name() + File.separator + w.getIdentifier() + "_1."
+ VelocityType.CONTENT.fileExtension);
org.apache.velocity.Template tesp1 = engine.getTemplate(
File.separator + PageMode.LIVE.name() + File.separator + w.getIdentifier() + "_2."
+ VelocityType.CONTENT.fileExtension);

Context ctx = VelocityUtil.getWebContext(requestProxy, responseProxy);
StringWriter writer=new StringWriter();
Expand All @@ -2189,8 +2194,12 @@ public void widgetInvalidateAllLang() throws Exception {
contentletAPI.isInodeIndexed(w2.getInode(),true);

// now if everything have been cleared correctly those should match again
org.apache.velocity.Template teng3 = engine.getTemplate("/live/"+w.getIdentifier()+"_1."+contentEXT);
org.apache.velocity.Template tesp3 = engine.getTemplate("/live/"+w.getIdentifier()+"_2."+contentEXT);
org.apache.velocity.Template teng3 = engine.getTemplate(
File.separator + PageMode.LIVE.name() + File.separator + w.getIdentifier() + "_1."
+ VelocityType.CONTENT.fileExtension);
org.apache.velocity.Template tesp3 = engine.getTemplate(
File.separator + PageMode.LIVE.name() + File.separator + w.getIdentifier() + "_2."
+ VelocityType.CONTENT.fileExtension);
ctx = VelocityUtil.getWebContext(requestProxy, responseProxy);
writer=new StringWriter();
teng3.merge(ctx, writer);
Expand Down Expand Up @@ -3403,26 +3412,27 @@ public void testCheckin1_ExistingContentWithRels_NullRels_ShouldKeepExistingRels
Contentlet blogContent = null;

try {

blogContent = getBlogContent();

final ContentletRelationships relationships = getACoupleOfRelationships(blogContent);
final Relationship relationship = relationships.getRelationshipsRecords().get(0).getRelationship();
final List<Contentlet> relatedContent = relationships.getRelationshipsRecords().get(0).getRecords();

final List<Category> categories = getACoupleOfCategories();

blogContent = contentletAPI.checkin(blogContent, relationships, categories, null, user,
false);

List<Contentlet> relatedContentFromDB = relationshipAPI.dbRelatedContent(relationship, blogContent);

assertTrue(relatedContentFromDB.containsAll(relatedContent));

Contentlet checkedoutBlogContent = contentletAPI.checkout(blogContent.getInode(), user, false);

Contentlet reCheckedinContent = contentletAPI.checkin(checkedoutBlogContent, (ContentletRelationships) null,
null, null, user, false);

Relationship relationship = relationships.getRelationshipsRecords().get(0).getRelationship();

List<Contentlet> relatedContent = relationships.getRelationshipsRecords().get(0).getRecords();

RelationshipAPI relationshipAPI = APILocator.getRelationshipAPI();

List<Contentlet> existingRelationships = relationshipAPI.dbRelatedContent(relationship, reCheckedinContent);

assertTrue(existingRelationships.containsAll(relatedContent));
Expand Down Expand Up @@ -3698,7 +3708,7 @@ public void testCheckinWithoutVersioning_ExistingContentWithRels_EmptyRels_Shoul
}
}

private ContentletRelationships getACoupleOfRelationships(Contentlet contentlet)
private ContentletRelationships getACoupleOfRelationships(Contentlet contentlet)
throws DotDataException, DotSecurityException {
ContentletRelationships relationships = new ContentletRelationships(contentlet);
final Relationship blogComments = APILocator.getRelationshipAPI().byInode("631a07ea-c840-402d-a330-37ed2826ba30");
Expand All @@ -3714,15 +3724,15 @@ private ContentletRelationships getACoupleOfRelationships(Contentlet contentle
comment1.setStringProperty("email", "email");
comment1.setStringProperty("comment", "comment");

comment1 = contentletAPI.checkin(comment1, user, false);
comment1 = contentletAPI.checkin(comment1, new HashMap<>(), user, false);

Contentlet comment2 = new Contentlet();
comment2.setContentTypeId(commentsType.id());
comment2.setStringProperty("title", "comment2");
comment2.setStringProperty("email", "email");
comment2.setStringProperty("comment", "comment");

comment2 = contentletAPI.checkin(comment2, user, false);
comment2 = contentletAPI.checkin(comment2, new HashMap<>(), user, false);

records.setRecords(Arrays.asList(comment1, comment2));
relationships.setRelationshipsRecords(Collections.singletonList(records));
Expand Down
Loading

0 comments on commit f9e34a3

Please sign in to comment.