Index: components/core/src/test/java/org/hippoecm/hst/mock/MockHstSiteMenus.java =================================================================== --- components/core/src/test/java/org/hippoecm/hst/mock/MockHstSiteMenus.java (revision ) +++ components/core/src/test/java/org/hippoecm/hst/mock/MockHstSiteMenus.java (revision ) @@ -0,0 +1,30 @@ +package org.hippoecm.hst.mock; + +import org.hippoecm.hst.core.sitemenu.HstSiteMenu; +import org.hippoecm.hst.core.sitemenu.HstSiteMenus; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +/** + * Mock implementation of {@link org.hippoecm.hst.core.sitemenu.HstSiteMenus}. + */ +public class MockHstSiteMenus implements HstSiteMenus { + + private final Map menuNamesToSiteMenus = new HashMap(); + + public Map getSiteMenus() { + return Collections.unmodifiableMap(menuNamesToSiteMenus); + } + + public HstSiteMenu getSiteMenu(String name) { + return menuNamesToSiteMenus.get(name); + } + + // Methods supporting org.hippoecm.hst.mock configuration + + public void addSiteMenu(String name, HstSiteMenu menu) { + menuNamesToSiteMenus.put(name, menu); + } +} Index: components/core/src/test/java/org/hippoecm/hst/mock/MockHstLink.java =================================================================== --- components/core/src/test/java/org/hippoecm/hst/mock/MockHstLink.java (revision ) +++ components/core/src/test/java/org/hippoecm/hst/mock/MockHstLink.java (revision ) @@ -0,0 +1,59 @@ +package org.hippoecm.hst.mock; + +import org.hippoecm.hst.configuration.HstSite; +import org.hippoecm.hst.core.component.HstRequest; +import org.hippoecm.hst.core.component.HstResponse; +import org.hippoecm.hst.core.linking.HstLink; + +/** + * Mock implementation of {@link org.hippoecm.hst.core.linking.HstLink}. + */ +public class MockHstLink implements HstLink { + + private String path; + private boolean notFound = false; + + public MockHstLink() { + this(null); + } + + public MockHstLink(String path) { + setPath(path); + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public boolean getContainerResource() { + throw new UnsupportedOperationException("Not implemented"); + } + + public void setContainerResource(boolean containerResource) { + throw new UnsupportedOperationException("Not implemented"); + } + + public String toUrlForm(HstRequest request, HstResponse response, boolean external) { + throw new UnsupportedOperationException("Not implemented"); + } + + public String[] getPathElements() { + throw new UnsupportedOperationException("Not implemented"); + } + + public HstSite getHstSite() { + throw new UnsupportedOperationException("Not implemented"); + } + + public boolean isNotFound() { + return false; + } + + public void setNotFound(boolean notFound) { + this.notFound = notFound; + } +} Index: components/core/src/test/java/org/hippoecm/hst/mock/MockContainerConfiguration.java =================================================================== --- components/core/src/test/java/org/hippoecm/hst/mock/MockContainerConfiguration.java (revision ) +++ components/core/src/test/java/org/hippoecm/hst/mock/MockContainerConfiguration.java (revision ) @@ -0,0 +1,113 @@ +package org.hippoecm.hst.mock; + +import org.hippoecm.hst.core.container.ContainerConfiguration; + +import java.util.*; + +/** + * Mock implementation of (@link ContainerConfiguration). + */ +public class MockContainerConfiguration implements ContainerConfiguration { + + private final Map, Map> properties = new HashMap, Map>(); + + public boolean containsKey(String key) { + for (Class aClass : properties.keySet()) { + if (properties.get(aClass).containsKey(key)) { + return true; + } + } + return false; + } + + public boolean getBoolean(String key) { + return getValue(Boolean.class, key); + } + + public boolean getBoolean(String key, boolean defaultValue) { + return getValue(Boolean.class, key, defaultValue); + } + + public String getString(String key) { + return getValue(String.class, key); + } + + public String getString(String key, String defaultValue) { + return getValue(String.class, defaultValue); + } + + public double getDouble(String key) { + throw new UnsupportedOperationException("Not implemented"); + } + + public double getDouble(String key, double defaultValue) { + throw new UnsupportedOperationException("Not implemented"); + } + + public float getFloat(String key) { + throw new UnsupportedOperationException("Not implemented"); + } + + public float getFloat(String key, float defaultValue) { + throw new UnsupportedOperationException("Not implemented"); + } + + public int getInt(String key) { + return this.getValue(Integer.class, key); + } + + public int getInt(String key, int defaultValue) { + return getValue(Integer.class, key, new Integer(defaultValue)); + } + + public List getList(String key) { + throw new UnsupportedOperationException("Not implemented"); + } + + public long getLong(String key) { + throw new UnsupportedOperationException("Not implemented"); + } + + public long getLong(String key, long defaultValue) { + throw new UnsupportedOperationException("Not implemented"); + } + + public String[] getStringArray(String key) { + throw new UnsupportedOperationException("Not implemented"); + } + + public Iterator getKeys() { + throw new UnsupportedOperationException("Not implemented"); + } + + public boolean isDevelopmentMode() { + throw new UnsupportedOperationException("Not implemented"); + } + + public Properties toProperties() { + throw new UnsupportedOperationException("Not implemented"); + } + + public void setProperty(Class valueClass, String key, Object value) { + Map keysToValues = properties.get(valueClass); + if (keysToValues == null) { + keysToValues = new LinkedHashMap(); + properties.put(valueClass, keysToValues); + } + keysToValues.put(key, value); + } + + private T getValue(Class valueClass, String key, T defaultValue) { + T value = this.getValue(valueClass, key); + return value == null ? defaultValue : value; + } + + private T getValue(Class valueClass, String key) { + Map map = properties.get(valueClass); + if (map == null) { + return null; + } + //noinspection unchecked + return (T) map.get(key); + } +} Index: pom.xml =================================================================== --- pom.xml (revision 24216) +++ pom.xml (revision ) @@ -858,6 +858,18 @@ + + + org.apache.maven.plugins + maven-jar-plugin + + + + test-jar + + + + Index: client/src/test/java/org/hippoecm/hst/mock/MockHstRequestContext.java =================================================================== --- client/src/test/java/org/hippoecm/hst/mock/MockHstRequestContext.java (revision 24160) +++ client/src/test/java/org/hippoecm/hst/mock/MockHstRequestContext.java (revision ) @@ -53,8 +53,8 @@ protected HstSiteMenus siteMenus; protected HstQueryManagerFactory hstQueryManagerFactory; protected Credentials defaultCredentials; - protected ContainerConfiguration containerConfiguration; protected ContextCredentialsProvider contextCredentialsProvider; + protected MockContainerConfiguration containerConfiguration = new MockContainerConfiguration(); public Object getAttribute(String name) { return this.attributes.get(name); @@ -156,7 +156,7 @@ return this.containerConfiguration; } - public void setContainerConfiguration(ContainerConfiguration containerConfiguration) { + public void setContainerConfiguration(MockContainerConfiguration containerConfiguration) { this.containerConfiguration = containerConfiguration; } @@ -193,5 +193,11 @@ public void setContextCredentialsProvider(ContextCredentialsProvider contextCredentialsProvider) { this.contextCredentialsProvider = contextCredentialsProvider; } - + + + // Methods supporting org.hippoecm.hst.mock configuration + + public void setContainerConfigurationProperty(Class valueClass, String key, Object value) { + this.containerConfiguration.setProperty(valueClass, key, value); -} \ No newline at end of file + } +} \ No newline at end of file Index: api/src/main/java/org/hippoecm/hst/core/request/HstRequestContext.java =================================================================== --- api/src/main/java/org/hippoecm/hst/core/request/HstRequestContext.java (revision 24160) +++ api/src/main/java/org/hippoecm/hst/core/request/HstRequestContext.java (revision ) @@ -183,5 +183,5 @@ * @return */ ContextCredentialsProvider getContextCredentialsProvider(); - + } Index: client/src/test/java/org/hippoecm/hst/mock/MockHstRequest.java =================================================================== --- client/src/test/java/org/hippoecm/hst/mock/MockHstRequest.java (revision 18674) +++ client/src/test/java/org/hippoecm/hst/mock/MockHstRequest.java (revision ) @@ -87,5 +87,18 @@ public void setLifecyclePhase(String lifecyclePhase) { this.lifecyclePhase = lifecyclePhase; } - + + // Methods supporting org.hippoecm.hst.mock configuration + + /** + * Set a resolved site map item parameter. + * + * @param parameterName name of the resolved sitemap parameter + * @param parameterValue value of the resolved sitemap parameter + */ + public void setResolvedSiteMapItemParameter(String parameterName, String parameterValue) { + MockResolvedSiteMapItem mockResolvedSiteMapItem = (MockResolvedSiteMapItem) requestContext.getResolvedSiteMapItem(); + mockResolvedSiteMapItem.addParameter(parameterName, parameterValue); -} \ No newline at end of file + } + +} \ No newline at end of file Index: content-beans/src/test/java/org/hippoecm/hst/mock/MockHippoBeanIterator.java =================================================================== --- content-beans/src/test/java/org/hippoecm/hst/mock/MockHippoBeanIterator.java (revision ) +++ content-beans/src/test/java/org/hippoecm/hst/mock/MockHippoBeanIterator.java (revision ) @@ -0,0 +1,63 @@ +package org.hippoecm.hst.mock; + +import org.hippoecm.hst.content.beans.standard.HippoBean; +import org.hippoecm.hst.content.beans.standard.HippoBeanIterator; +import org.springframework.util.Assert; + +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +/** + * Mock implementation of {@link org.hippoecm.hst.content.beans.standard.HippoBeanIterator} for testing purposes. + */ +public class MockHippoBeanIterator implements HippoBeanIterator { + + private final List hippoDocuments; + + private final Iterator iterator; + + private int position; + + public MockHippoBeanIterator() { + this(Collections.emptyList()); + } + + public MockHippoBeanIterator(List hippoDocuments) { + Assert.notNull(hippoDocuments, "HippoDocuments cannot be null"); + this.hippoDocuments = hippoDocuments; + this.iterator = this.hippoDocuments.iterator(); + } + + public HippoBean nextHippoBean() { + position ++; + return iterator.next(); + } + + public void skip(int skipNum) { + for (int i = 0; i < skipNum; i++) { + iterator.next(); + } + position += skipNum; + } + + public long getSize() { + return hippoDocuments.size(); + } + + public long getPosition() { + return position; + } + + public boolean hasNext() { + return iterator.hasNext(); + } + + public HippoBean next() { + return nextHippoBean(); + } + + public void remove() { + iterator.remove(); + } +} Index: components/core/src/test/java/org/hippoecm/hst/mock/MockHstSiteMenuItem.java =================================================================== --- components/core/src/test/java/org/hippoecm/hst/mock/MockHstSiteMenuItem.java (revision ) +++ components/core/src/test/java/org/hippoecm/hst/mock/MockHstSiteMenuItem.java (revision ) @@ -0,0 +1,90 @@ +package org.hippoecm.hst.mock; + +import org.hippoecm.hst.core.component.HstRequest; +import org.hippoecm.hst.core.linking.HstLink; +import org.hippoecm.hst.core.request.ResolvedSiteMapItem; +import org.hippoecm.hst.core.sitemenu.HstSiteMenu; +import org.hippoecm.hst.core.sitemenu.HstSiteMenuItem; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Mock implementation of {@link org.hippoecm.hst.core.sitemenu.HstSiteMenuItem}. + */ +public class MockHstSiteMenuItem implements HstSiteMenuItem { + + private final List siteMenuItems = new ArrayList(); + + private String name; + private boolean isExpanded; + + public MockHstSiteMenuItem(String name) { + this(name, false); + } + + public MockHstSiteMenuItem(String name, boolean isExpanded) { + this.name = name; + this.isExpanded = isExpanded; + } + + public List getChildMenuItems() { + return siteMenuItems; + } + + public HstSiteMenuItem getParentItem() { + throw new UnsupportedOperationException("Not implemented"); + } + + public HstSiteMenu getHstSiteMenu() { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getName() { + return name; + } + + public HstLink getHstLink() { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getExternalLink() { + throw new UnsupportedOperationException("Not implemented"); + } + + public ResolvedSiteMapItem resolveToSiteMapItem(HstRequest request) { + throw new UnsupportedOperationException("Not implemented"); + } + + public boolean isExpanded() { + return isExpanded; + } + + public Map getProperties() { + throw new UnsupportedOperationException("Not implemented"); + } + + public boolean isRepositoryBased() { + throw new UnsupportedOperationException("Not implemented"); + } + + public int getDepth() { + throw new UnsupportedOperationException("Not implemented"); + } + + public boolean isSelected() { + throw new UnsupportedOperationException("Not implemented"); + } + + // Methods supporting org.hippoecm.hst.mock configuration + + public MockHstSiteMenuItem addSiteMenuItem(String name) { + return addSiteMenuItem(new MockHstSiteMenuItem(name, false)); + } + + public MockHstSiteMenuItem addSiteMenuItem(HstSiteMenuItem siteMenuItem) { + this.siteMenuItems.add(siteMenuItem); + return this; + } +} Index: components/core/src/test/java/org/hippoecm/hst/mock/MockHstSiteMenu.java =================================================================== --- components/core/src/test/java/org/hippoecm/hst/mock/MockHstSiteMenu.java (revision ) +++ components/core/src/test/java/org/hippoecm/hst/mock/MockHstSiteMenu.java (revision ) @@ -0,0 +1,60 @@ +package org.hippoecm.hst.mock; + +import org.hippoecm.hst.core.sitemenu.EditableMenu; +import org.hippoecm.hst.core.sitemenu.HstSiteMenu; +import org.hippoecm.hst.core.sitemenu.HstSiteMenuItem; +import org.hippoecm.hst.core.sitemenu.HstSiteMenus; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Mock implementation of {@link org.hippoecm.hst.core.sitemenu.HstSiteMenu}. + * + */ +public class MockHstSiteMenu implements HstSiteMenu { + + private List siteMenuItems = new ArrayList(); + + public HstSiteMenuItem getSelectSiteMenuItem() { + throw new UnsupportedOperationException("Not implemented"); + } + + public List getSiteMenuItems() { + return Collections.unmodifiableList(siteMenuItems); + } + + public HstSiteMenus getHstSiteMenus() { + throw new UnsupportedOperationException("Not implemented"); + } + + public HstSiteMenuItem getDeepestExpandedItem() { + throw new UnsupportedOperationException("Not implemented"); + } + + public EditableMenu getEditableMenu() { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getName() { + throw new UnsupportedOperationException("Not implemented"); + } + + public boolean isExpanded() { + throw new UnsupportedOperationException("Not implemented"); + } + + public MockHstSiteMenu addSiteMenuItem(String name, boolean isExpanded) { + addSiteMenuItem(new MockHstSiteMenuItem(name, isExpanded)); + return this; + } + + public MockHstSiteMenu addSiteMenuItem(String name) { + return addSiteMenuItem(name, false); + } + + public void addSiteMenuItem(HstSiteMenuItem siteMenuItem) { + this.siteMenuItems.add(siteMenuItem); + } +} Index: components/core/src/test/java/org/hippoecm/hst/mock/MockComponentConfiguration.java =================================================================== --- components/core/src/test/java/org/hippoecm/hst/mock/MockComponentConfiguration.java (revision ) +++ components/core/src/test/java/org/hippoecm/hst/mock/MockComponentConfiguration.java (revision ) @@ -0,0 +1,64 @@ +package org.hippoecm.hst.mock; + +import org.hippoecm.hst.core.request.ComponentConfiguration; +import org.hippoecm.hst.core.request.ResolvedSiteMapItem; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Mock implementation of {@link org.hippoecm.hst.core.request.ComponentConfiguration for testing purposes. + */ +public class MockComponentConfiguration implements ComponentConfiguration { + + private final Map rawParameters = new LinkedHashMap(); + + public String getParameter(String name, ResolvedSiteMapItem hstResolvedSiteMapItem) { + throw new UnsupportedOperationException("Not implemented"); + } + + public Map getParameters(ResolvedSiteMapItem hstResolvedSiteMapItem) { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getLocalParameter(String name, ResolvedSiteMapItem hstResolvedSiteMapItem) { + throw new UnsupportedOperationException("Not implemented"); + } + + public Map getLocalParameters(ResolvedSiteMapItem hstResolvedSiteMapItem) { + throw new UnsupportedOperationException("Not implemented"); + } + + public Map getRawParameters() { + return Collections.unmodifiableMap(rawParameters); + } + + public Map getRawLocalParameters() { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getRenderPath() { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getServeResourcePath() { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getCanonicalPath() { + throw new UnsupportedOperationException("Not implemented"); + } + + // Mock specific methods + + /** + * Add a raw parameter. + * + * @param parameterName the parameter name + * @param parameterValue the parameter value + */ + public void addRawParameter(String parameterName, String parameterValue) { + this.rawParameters.put(parameterName, parameterValue); + } +} Index: components/core/src/test/java/org/hippoecm/hst/mock/MockResolvedSiteMapItem.java =================================================================== --- components/core/src/test/java/org/hippoecm/hst/mock/MockResolvedSiteMapItem.java (revision ) +++ components/core/src/test/java/org/hippoecm/hst/mock/MockResolvedSiteMapItem.java (revision ) @@ -0,0 +1,76 @@ +package org.hippoecm.hst.mock; + +import org.hippoecm.hst.configuration.components.HstComponentConfiguration; +import org.hippoecm.hst.configuration.sitemap.HstSiteMapItem; +import org.hippoecm.hst.core.request.ResolvedSiteMapItem; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +/** + * A dummy {@link org.hippoecm.hst.core.request.ResolvedSiteMapItem} for testing purposes. + */ +public class MockResolvedSiteMapItem implements ResolvedSiteMapItem { + + private final Map parameters = new HashMap(); + + public String getRelativeContentPath() { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getPathInfo() { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getParameter(String name) { + return parameters.get(name); + } + + public Properties getParameters() { + throw new UnsupportedOperationException("Not implemented"); + } + + public HstSiteMapItem getHstSiteMapItem() { + throw new UnsupportedOperationException("Not implemented"); + } + + public int getStatusCode() { + throw new UnsupportedOperationException("Not implemented"); + } + + public int getErrorCode() { + throw new UnsupportedOperationException("Not implemented"); + } + + public List getRoles() { + throw new UnsupportedOperationException("Not implemented"); + } + + public boolean isSecured() { + throw new UnsupportedOperationException("Not implemented"); + } + + public HstComponentConfiguration getHstComponentConfiguration() { + throw new UnsupportedOperationException("Not implemented"); + } + + public HstComponentConfiguration getPortletHstComponentConfiguration() { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getLocalParameter(String arg0) { + throw new UnsupportedOperationException("Not implemented"); + } + + public Properties getLocalParameters() { + throw new UnsupportedOperationException("Not implemented"); + } + + // Mock methods + + public void addParameter(String key, String value) { + parameters.put(key, value); + } +} Index: components/core/src/test/java/org/hippoecm/hst/mock/MockHstComponentConfiguration.java =================================================================== --- components/core/src/test/java/org/hippoecm/hst/mock/MockHstComponentConfiguration.java (revision ) +++ components/core/src/test/java/org/hippoecm/hst/mock/MockHstComponentConfiguration.java (revision ) @@ -0,0 +1,101 @@ +package org.hippoecm.hst.mock; + +import org.hippoecm.hst.configuration.components.HstComponentConfiguration; + +import java.util.HashMap; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + + +/** + * Mock implementation of {@link org.hippoecm.hst.configuration.components.HstComponentConfiguration}. + * + */ +public class MockHstComponentConfiguration implements HstComponentConfiguration { + + private String id; + private SortedMap componentConfigs = + new TreeMap(); + private Map parameters = new HashMap(); + + public MockHstComponentConfiguration(String id) { + this.id = id; + } + + public HstComponentConfiguration getChildByName(String arg0) { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getCanonicalStoredLocation() { + throw new UnsupportedOperationException("Not implemented"); + } + + public SortedMap getChildren() { + return componentConfigs; + } + + public MockHstComponentConfiguration addChild(MockHstComponentConfiguration config){ + componentConfigs.put(config.getId(), config); + return config; + } + + public void addChildren(MockHstComponentConfiguration... config){ + for (MockHstComponentConfiguration mockHstComponentConfiguration : config) { + addChild(mockHstComponentConfiguration); + } + } + + public String getLocalParameter(String arg0) { + throw new UnsupportedOperationException("Not implemented"); + } + + public Map getLocalParameters() { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getParameter(String name) { + return parameters.get(name); + } + + public void setParameter(String name, String value) { + parameters.put(name,value); + } + + public Map getParameters() { + throw new UnsupportedOperationException("Not implemented"); + } + + public HstComponentConfiguration getParent() { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getReferenceName() { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getRenderPath() { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getServeResourcePath() { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getComponentClassName() { + throw new UnsupportedOperationException("Not implemented"); + } + + public String getId() { + return id; + } + + public void setId(String id){ + this.id=id; + } + + public String getName() { + throw new UnsupportedOperationException("Not implemented"); + } + +}