code.onehippo.org is currently readonly. We are migrating to code.bloomreach.com, please continue working there on Monday 14/12. See: https://docs.bloomreach.com/display/engineering/GitLab

Commit 1e446d35 authored by Jasper Floor's avatar Jasper Floor

ESSCOM-14 test for buildQuery, now complete

parent 0d7d7585
......@@ -76,6 +76,36 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-repository-testutils</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.onehippo.cms7.hst</groupId>
<artifactId>hst-mock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-repository-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-repository-config</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.onehippo.cms7.hst</groupId>
<artifactId>hst-test</artifactId>
<type>pom</type>
</dependency>
</dependencies>
<build>
......
/*
* Copyright 2008-2013 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hippoecm.hst;
import org.hippoecm.hst.content.beans.manager.ObjectConverter;
import org.hippoecm.hst.content.beans.standard.HippoBean;
import org.hippoecm.hst.util.ObjectConverterUtils;
import org.onehippo.cms7.essentials.beans.BaseDocument;
import org.onehippo.cms7.essentials.beans.ContentDocument;
import org.onehippo.cms7.essentials.beans.NewsDocument;
import org.onehippo.repository.testutils.RepositoryTestCase;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public abstract class AbstractBeanTestCase extends RepositoryTestCase {
protected ObjectConverter getObjectConverter() {
return ObjectConverterUtils.createObjectConverter(getAnnotatedClasses(), true);
}
protected Collection<Class<? extends HippoBean>> getAnnotatedClasses() {
List<Class<? extends HippoBean>> annotatedClasses = new ArrayList<Class<? extends HippoBean>>();
annotatedClasses.add(BaseDocument.class);
annotatedClasses.add(ContentDocument.class);
annotatedClasses.add(NewsDocument.class);
return annotatedClasses;
}
}
package org.onehippo.cms7.essentials.beans;
import org.hippoecm.hst.content.beans.Node;
import org.hippoecm.hst.content.beans.standard.HippoDocument;
@Node(jcrType="myhippoproject:basedocument")
public class BaseDocument extends HippoDocument {
}
package org.onehippo.cms7.essentials.beans;
/*
* Copyright 2014-2015 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.hippoecm.hst.content.beans.Node;
import org.hippoecm.hst.content.beans.standard.HippoHtml;
import java.util.Calendar;
@Node(jcrType = "myhippoproject:contentdocument")
public class ContentDocument extends BaseDocument {
public String getIntroduction() {
return getProperty("myhippoproject:introduction");
}
public String getTitle() {
return getProperty("myhippoproject:title");
}
public HippoHtml getContent() {
return getHippoHtml("myhippoproject:content");
}
public Calendar getPublicationDate() {
return getProperty("myhippoproject:publicationdate");
}
}
package org.onehippo.cms7.essentials.beans;
/*
* Copyright 2014 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.hippoecm.hst.content.beans.Node;
import org.hippoecm.hst.content.beans.standard.HippoDocument;
import org.hippoecm.hst.content.beans.standard.HippoGalleryImageSet;
import org.hippoecm.hst.content.beans.standard.HippoHtml;
import java.util.Calendar;
@Node(jcrType="myhippoproject:newsdocument")
public class NewsDocument extends HippoDocument {
/**
* The document type of the news document.
*/
public final static String DOCUMENT_TYPE = "myhippoproject:newsdocument";
private final static String TITLE = "myhippoproject:title";
private final static String DATE = "myhippoproject:date";
private final static String INTRODUCTION = "myhippoproject:introduction";
private final static String IMAGE = "myhippoproject:image";
private final static String CONTENT = "myhippoproject:content";
private final static String LOCATION = "myhippoproject:location";
private final static String AUTHOR = "myhippoproject:author";
private final static String SOURCE = "myhippoproject:source";
/**
* Get the title of the document.
*
* @return the title
*/
public String getTitle() {
return getProperty(TITLE);
}
/**
* Get the date of the document.
*
* @return the date
*/
public Calendar getDate() {
return getProperty(DATE);
}
/**
* Get the introduction of the document.
*
* @return the introduction
*/
public String getIntroduction() {
return getProperty(INTRODUCTION);
}
/**
* Get the image of the document.
*
* @return the image
*/
public HippoGalleryImageSet getImage() {
return getLinkedBean(IMAGE, HippoGalleryImageSet.class);
}
/**
* Get the main content of the document.
*
* @return the content
*/
public HippoHtml getContent() {
return getHippoHtml(CONTENT);
}
/**
* Get the location of the document.
*
* @return the location
*/
public String getLocation() {
return getProperty(LOCATION);
}
/**
* Get the author of the document.
*
* @return the author
*/
public String getAuthor() {
return getProperty(AUTHOR);
}
/**
* Get the source of the document.
*
* @return the source
*/
public String getSource() {
return getProperty(SOURCE);
}
}
package org.onehippo.cms7.essentials.components;
import org.hippoecm.hst.AbstractHstQueryTest;
import org.hippoecm.hst.content.beans.ObjectBeanManagerException;
import org.hippoecm.hst.content.beans.manager.ObjectBeanManager;
import org.hippoecm.hst.content.beans.manager.ObjectBeanManagerImpl;
import org.hippoecm.hst.content.beans.manager.ObjectConverter;
import org.hippoecm.hst.content.beans.query.HstQuery;
import org.hippoecm.hst.content.beans.query.HstQueryResult;
import org.hippoecm.hst.content.beans.query.exceptions.QueryException;
import org.hippoecm.hst.content.beans.standard.HippoFolder;
import org.hippoecm.hst.core.container.ComponentManager;
import org.hippoecm.hst.mock.core.component.MockHstRequest;
import org.hippoecm.hst.site.HstServices;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.onehippo.cms7.essentials.components.ext.DoBeforeRenderExtension;
import org.onehippo.cms7.essentials.components.info.EssentialsListComponentInfo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class EssentialsListComponentTest extends AbstractHstQueryTest {
private static final String NEWS_FOLDER_PATH = "/content/documents/myhippoproject/news";
private static final String MYHIPPOPROJECT_NEWSDOCUMENT = "myhippoproject:newsdocument";
ObjectConverter objectConverter;
ObjectBeanManager obm;
@Mock
ComponentManager componentManager;
@Mock
EssentialsListComponentInfo essentialsListComponentInfo;
@Before
public void setUp() throws Exception {
super.setUp();
objectConverter = getObjectConverter();
obm = new ObjectBeanManagerImpl(session, objectConverter);
when(essentialsListComponentInfo.getIncludeSubtypes()).thenReturn(Boolean.FALSE);
when(componentManager.getComponent(DoBeforeRenderExtension.class.getName())).thenReturn(null);
HstServices.setComponentManager(componentManager);
}
@After
public void tearDown() throws Exception {
HstServices.setComponentManager(null);
super.tearDown();
}
@Test
public void testBuildHstQuery() throws ObjectBeanManagerException, QueryException {
when(essentialsListComponentInfo.getDocumentTypes()).thenReturn(MYHIPPOPROJECT_NEWSDOCUMENT);
HippoFolder scope = (HippoFolder) obm.getObject(NEWS_FOLDER_PATH);
EssentialsListComponent essentialsListComponent = new EssentialsListComponent();
MockHstRequest hstRequest = new MockHstRequest();
HstQuery hstQuery = essentialsListComponent.buildQuery(hstRequest, essentialsListComponentInfo, scope);
HstQueryResult hstQueryResult = hstQuery.execute();
assertTrue(hstQuery.getQueryAsString(true) != null);
assertEquals(3, hstQueryResult.getSize());
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<sv:node xmlns:sv="http://www.jcp.org/jcr/sv/1.0" sv:name="content">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hippostd:folder</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>mix:referenceable</sv:value>
</sv:property>
<sv:property sv:name="hippostd:foldertype" sv:type="String">
<sv:value>new-document</sv:value>
<sv:value>new-folder</sv:value>
</sv:property>
<sv:node sv:name="documents" xmlns:sv="http://www.jcp.org/jcr/sv/1.0">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hippostd:folder</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>mix:referenceable</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>2c21a29c-a5d1-4e84-aec4-594e5bf93b25</sv:value>
</sv:property>
<sv:property sv:name="hippostd:foldertype" sv:type="String">
<sv:value>new-folder</sv:value>
<sv:value>new-translated-folder</sv:value>
</sv:property>
</sv:node>
</sv:node>
<?xml version="1.0" encoding="UTF-8"?>
<sv:node
xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
sv:name="myhippoproject">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hippostd:folder</sv:value>
</sv:property>
<sv:property sv:name="jcr:uuid" sv:type="String">
<sv:value>996bcac5-86cf-49b5-a7a3-16a74863e814</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>mix:referenceable</sv:value>
<sv:value>hippotranslation:translated</sv:value>
</sv:property>
<sv:property sv:name="hippotranslation:locale" sv:type="String">
<sv:value>en</sv:value>
</sv:property>
<sv:property sv:name="hippotranslation:id" sv:type="String">
<!-- same for all 'root' language nodes: do not change -->
<sv:value>996bcac5-86cf-49b5-a7a3-16a74863e814</sv:value>
</sv:property>
<sv:property sv:name="hippostd:foldertype" sv:type="String">
<sv:value>new-translated-folder</sv:value>
<sv:value>new-document</sv:value>
</sv:property>
</sv:node>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<sv:node xmlns:ae="http://www.onehippo.org/jcr/autoexport/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" ae:id="myhippoproject" sv:name="hippo:initialize">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hippo:initializefolder</sv:value>
</sv:property>
<!-- Document types -->
<sv:node sv:name="myhippoproject">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hippo:initializeitem</sv:value>
</sv:property>
<sv:property sv:name="hippo:sequence" sv:type="Double">
<sv:value>30000.1</sv:value>
</sv:property>
<sv:property sv:name="hippo:namespace" sv:type="String">
<sv:value>http://www.onehippo.org/myhippoproject/nt/1.0</sv:value>
</sv:property>
<sv:property sv:name="hippo:nodetypesresource" sv:type="String">
<sv:value>namespaces/myhippoproject.cnd</sv:value>
</sv:property>
</sv:node>
<sv:node sv:name="myhippoproject-namespace">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hippo:initializeitem</sv:value>
</sv:property>
<sv:property sv:name="hippo:sequence" sv:type="Double">
<sv:value>30051</sv:value>
</sv:property>
<sv:property sv:name="hippo:contentresource" sv:type="String">
<sv:value>namespaces/myhippoproject.xml</sv:value>
</sv:property>
<sv:property sv:name="hippo:contentroot" sv:type="String">
<sv:value>/hippo:namespaces</sv:value>
</sv:property>
</sv:node>
<sv:node sv:name="myhippoproject-basedocument-namespace">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hippo:initializeitem</sv:value>
</sv:property>
<sv:property sv:name="hippo:sequence" sv:type="Double">
<sv:value>30051.1</sv:value>
</sv:property>
<sv:property sv:name="hippo:contentresource" sv:type="String">
<sv:value>namespaces/myhippoproject/basedocument.xml</sv:value>
</sv:property>
<sv:property sv:name="hippo:contentroot" sv:type="String">
<sv:value>/hippo:namespaces/myhippoproject</sv:value>
</sv:property>
</sv:node>
<sv:node sv:name="myhippoproject-content">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hippo:initializeitem</sv:value>
</sv:property>
<sv:property sv:name="hippo:sequence" sv:type="Double">
<sv:value>30053</sv:value>
</sv:property>
<sv:property sv:name="hippo:contentresource" sv:type="String">
<sv:value>content/content.xml</sv:value>
</sv:property>
<sv:property sv:name="hippo:contentroot" sv:type="String">
<sv:value>/</sv:value>
</sv:property>
</sv:node>
<!-- Content -->
<sv:node sv:name="myhippoproject-documents">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hippo:initializeitem</sv:value>
</sv:property>
<sv:property sv:name="hippo:sequence" sv:type="Double">
<sv:value>30400</sv:value>
</sv:property>
<sv:property sv:name="hippo:contentresource" sv:type="String">
<sv:value>content/documents/myhippoproject.xml</sv:value>
</sv:property>
<sv:property sv:name="hippo:contentroot" sv:type="String">
<sv:value>/content/documents</sv:value>
</sv:property>
</sv:node>
<sv:node sv:name="myhippoproject-content-documents-myhippoproject-content">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hippo:initializeitem</sv:value>
</sv:property>
<sv:property sv:name="hippo:sequence" sv:type="Double">
<sv:value>30401.0</sv:value>
</sv:property>
<sv:property sv:name="hippo:contentresource" sv:type="String">
<sv:value>content/documents/myhippoproject/content.xml</sv:value>
</sv:property>
<sv:property sv:name="hippo:contentroot" sv:type="String">
<sv:value>/content/documents/myhippoproject</sv:value>
</sv:property>
</sv:node>
<sv:node sv:name="myhippoproject-content-documents-myhippoproject-news">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hippo:initializeitem</sv:value>
</sv:property>
<sv:property sv:name="hippo:sequence" sv:type="Double">
<sv:value>30401.0</sv:value>
</sv:property>
<sv:property sv:name="hippo:contentresource" sv:type="String">
<sv:value>content/documents/myhippoproject/news.xml</sv:value>
</sv:property>
<sv:property sv:name="hippo:contentroot" sv:type="String">
<sv:value>/content/documents/myhippoproject</sv:value>
</sv:property>
</sv:node>
</sv:node>
<'hippo'='http://www.onehippo.org/jcr/hippo/nt/2.0.4'>
<'hippostd'='http://www.onehippo.org/jcr/hippostd/nt/2.0'>
<'hippostdpubwf'='http://www.onehippo.org/jcr/hippostdpubwf/nt/1.0'>
<'hippotranslation'='http://www.onehippo.org/jcr/hippotranslation/nt/1.0'>
<'myhippoproject'='http://www.onehippo.org/myhippoproject/nt/1.0'>
[myhippoproject:basedocument] > hippo:document, hippostd:publishableSummary, hippostdpubwf:document
orderable
[myhippoproject:contentdocument] > hippostd:relaxed, hippotranslation:translated, myhippoproject:basedocument
orderable
[myhippoproject:newsdocument] > hippostd:relaxed, hippotranslation:translated, myhippoproject:basedocument
orderable
<?xml version="1.0" encoding="UTF-8"?>
<sv:node sv:name="myhippoproject" xmlns:sv="http://www.jcp.org/jcr/sv/1.0">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hipposysedit:namespace</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>mix:referenceable</sv:value>
</sv:property>
</sv:node>
<?xml version="1.0" encoding="UTF-8"?>
<sv:node sv:name="basedocument" xmlns:sv="http://www.jcp.org/jcr/sv/1.0">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hipposysedit:templatetype</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>mix:referenceable</sv:value>
</sv:property>
<sv:node sv:name="hipposysedit:nodetype">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hippo:handle</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>mix:referenceable</sv:value>
</sv:property>
<sv:node sv:name="hipposysedit:nodetype">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>hipposysedit:nodetype</sv:value>
</sv:property>
<sv:property sv:name="jcr:mixinTypes" sv:type="Name">
<sv:value>hipposysedit:remodel</sv:value>
</sv:property>
<sv:property sv:name="hipposysedit:supertype" sv:type="String">
<sv:value>hippo:document</sv:value>
<sv:value>hippostdpubwf:document</sv:value>
<sv:value>hippostd:publishableSummary</sv:value>
</sv:property>
<sv:property sv:name="hipposysedit:uri" sv:type="String">
<sv:value>http://www.onehippo.org/myhippoproject/nt/1.0</sv:value>
</sv:property>
</sv:node>
</sv:node>
</sv:node>
......@@ -44,6 +44,7 @@
<jsoup.version>1.7.1</jsoup.version>
<rome.version>0.9</rome.version>
<junit.version>4.12</junit.version>
<mockito.version>1.10.19</mockito.version>
</properties>
<scm>
......@@ -135,6 +136,38 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-repository-testutils</artifactId>
<version>${hippo.repository.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>${mockito.version}</version>
</dependency>
<dependency>
<groupId>org.onehippo.cms7.hst</groupId>
<artifactId>hst-mock</artifactId>
<version>${hippo.hst.version}</version>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-repository-config</artifactId>
<version>${hippo.repository.version}</version>
</dependency>
<dependency>
<groupId>org.onehippo.cms7</groupId>
<artifactId>hippo-repository-engine</artifactId>
<version>${hippo.repository.version}</version>
</dependency>
<dependency>
<groupId>org.onehippo.cms7.hst</groupId>
<artifactId>hst-test</artifactId>
<version>${hippo.repository.version}</version>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment