Index: src/main/java/org/modeshape/web/jcr/rest/client/RestClientI18n.java =================================================================== --- src/main/java/org/modeshape/web/jcr/rest/client/RestClientI18n.java (revision 2126) +++ src/main/java/org/modeshape/web/jcr/rest/client/RestClientI18n.java (working copy) @@ -39,6 +39,8 @@ public static I18n unknownHttpRequestMethodMsg; public static I18n workspaceShortDescription; + + public static I18n nodeTypeShortDescription; // JsonRestClient messages @@ -63,6 +65,10 @@ public static I18n unpublishSucceededMsg; public static I18n invalidQueryLanguageMsg; + + public static I18n getNodeTypesFailedMsg; + + public static I18n getNodeTypeFailedMsg; static { try { Index: src/main/java/org/modeshape/web/jcr/rest/client/domain/NodeType.java =================================================================== --- src/main/java/org/modeshape/web/jcr/rest/client/domain/NodeType.java (revision 0) +++ src/main/java/org/modeshape/web/jcr/rest/client/domain/NodeType.java (revision 0) @@ -0,0 +1,212 @@ +/* + * ModeShape (http://www.modeshape.org) + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * See the AUTHORS.txt file in the distribution for a full listing of + * individual contributors. + * + * ModeShape is free software. Unless otherwise indicated, all code in ModeShape + * is licensed to you under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * ModeShape is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.modeshape.web.jcr.rest.client.domain; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Properties; + +import net.jcip.annotations.Immutable; + +import org.modeshape.common.util.HashCode; +import org.modeshape.web.jcr.rest.client.RestClientI18n; + +/** + * The NodeType class is the business object for a ModeShape supported node type. + */ +@Immutable +public class NodeType implements IModeShapeObject { + + // =========================================================================================================================== + // Fields + // =========================================================================================================================== + + /** + * The node type name. + */ + private final String name; + + /** + * The workspace where this node type resides. + */ + private final Workspace workspace; + + private Properties properties = null; + + private NodeType parentNodeType = null; + + private List childrenNodeType = null; + + private List propertyDefinitons = null; + + private List childNodeDefinitons = null; + + // =========================================================================================================================== + // Constructors + // =========================================================================================================================== + + /** + * Constructs a new NodeType. + * + * @param name the node type name (never null) + * @param workspace the workspace where this node type resides (never null) + * @param properties which are the attributes defined for this node type (nullable) + * @throws IllegalArgumentException if the name or workspace argument is null + */ + public NodeType( String name, + Workspace workspace, + Properties properties) { + assert name != null; + assert workspace != null; + this.name = name; + this.workspace = workspace; + this.properties = (properties == null ? new Properties() : properties); + + } + + // =========================================================================================================================== + // Methods + // =========================================================================================================================== + + /** + * {@inheritDoc} + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals( Object obj ) { + if (this == obj) return true; + if ((obj == null) || (getClass() != obj.getClass())) return false; + + NodeType otherNodeType = (NodeType)obj; + return (this.name.equals(otherNodeType.name) && this.workspace.equals(otherNodeType.workspace)); + } + + /** + * {@inheritDoc} + * + * @see org.modeshape.web.jcr.rest.client.domain.IModeShapeObject#getName() + */ + public String getName() { + return this.name; + } + + /** + * @return the server where this workspace is located (never null) + */ + public Workspace getWorkspace() { + return this.workspace; + } + + /** + * @return the node type attributes as a property set. + */ + public Properties getProperties() { + return this.properties; + } + + public void setProperties(Properties properties ){ + this.properties = properties; + } + + public String getProperty(String key) { + return this.properties.getProperty(key); + } + + @SuppressWarnings("unchecked") + public List getChildren() { + return (List) (this.childrenNodeType != null ? this.childrenNodeType : Collections.emptyList()); + } + + public void addChildNodeType(NodeType childNodeType) { + if (this.childrenNodeType == null) this.childrenNodeType = new ArrayList(); + this.childrenNodeType.add(childNodeType); + + childNodeType.setParentNodeType(this); + } + + public void addPropertyDefinitionNodeType(NodeType propertyDefinitionNodeType) { + if (this.propertyDefinitons == null) this.propertyDefinitons = new ArrayList(); + propertyDefinitons.add(propertyDefinitionNodeType); + + propertyDefinitionNodeType.setParentNodeType(this); + } + + public void addChildNodeDefinitionNodeType(NodeType childNodeDefinitionNodeType) { + if (this.childNodeDefinitons == null) this.childNodeDefinitons = new ArrayList(); + childNodeDefinitons.add(childNodeDefinitionNodeType); + + childNodeDefinitionNodeType.setParentNodeType(this); + } + + @SuppressWarnings("unchecked") + public List getPropertyDefinitions() { + return (List) (this.propertyDefinitons != null ? this.propertyDefinitons : Collections.emptyList()); + } + + @SuppressWarnings("unchecked") + public List getChildNodeDefinitions() { + return (List) (this.childNodeDefinitons != null ? this.childNodeDefinitons : Collections.emptyList()); + } + + public NodeType getParentNodeType() { + return this.parentNodeType; + } + + public void setParentNodeType(NodeType parent) { + this.parentNodeType = parent; + } + + + /** + * {@inheritDoc} + * + * @see org.modeshape.web.jcr.rest.client.domain.IModeShapeObject#getShortDescription() + */ + public String getShortDescription() { + return RestClientI18n.nodeTypeShortDescription.text(this.name, this.workspace.getServer()); + } + + /** + * {@inheritDoc} + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return HashCode.compute(this.name, this.workspace); + } + + /** + * {@inheritDoc} + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return getShortDescription(); + } + +} Index: src/main/java/org/modeshape/web/jcr/rest/client/json/JsonRestClient.java =================================================================== --- src/main/java/org/modeshape/web/jcr/rest/client/json/JsonRestClient.java (revision 2126) +++ src/main/java/org/modeshape/web/jcr/rest/client/json/JsonRestClient.java (working copy) @@ -44,6 +44,7 @@ import org.modeshape.web.jcr.rest.client.RestClientI18n; import org.modeshape.web.jcr.rest.client.Status; import org.modeshape.web.jcr.rest.client.Status.Severity; +import org.modeshape.web.jcr.rest.client.domain.NodeType; import org.modeshape.web.jcr.rest.client.domain.QueryRow; import org.modeshape.web.jcr.rest.client.domain.Repository; import org.modeshape.web.jcr.rest.client.domain.Server; @@ -226,8 +227,77 @@ } } } + + /** + * {@inheritDoc} + * + * @see org.modeshape.web.jcr.rest.client.IRestClient#getNodeTypes(org.modeshape.web.jcr.rest.client.domain.Workspace) + */ + @Override + public Collection getNodeTypes(Workspace workspace) + throws Exception { + CheckArg.isNotNull(workspace, "workspace"); + LOGGER.trace("getNodeTypes: workspace={0}", workspace); + + NodeTypeNode nodetypeNode = new NodeTypeNode(workspace, 5); + HttpClientConnection connection = connect(workspace.getServer(), nodetypeNode.getUrl(), RequestMethod.GET); + try { + int responseCode = connection.getResponseCode(); + + if (responseCode == HttpURLConnection.HTTP_OK) { + return nodetypeNode.getNodeTypes(connection.read()); + } + + // not a good response code + LOGGER.error(RestClientI18n.connectionErrorMsg, responseCode, "getNodeTypes"); + String msg = RestClientI18n.getNodeTypesFailedMsg.text(nodetypeNode.getUrl(), + responseCode); + throw new RuntimeException(msg); + } finally { + if (connection != null) { + LOGGER.trace("getNodeTypes: leaving"); + connection.disconnect(); + } + } + } + /** + * {@inheritDoc} + * + * @see org.modeshape.web.jcr.rest.client.IRestClient#getNodeType(Workspace, String) + */ + @Override + public NodeType getNodeType(Workspace workspace, String nodeTypeName) + throws Exception { + CheckArg.isNotNull(workspace, "workspace"); + CheckArg.isNotNull(nodeTypeName, "nodeTypeName"); + LOGGER.trace("getNodeType: workspace={0}, nodetypename={1}", workspace, nodeTypeName); + + NodeTypeNode nodetypeNode = new NodeTypeNode(workspace, nodeTypeName); + HttpClientConnection connection = connect(workspace.getServer(), nodetypeNode.getUrl(), RequestMethod.GET); + + try { + int responseCode = connection.getResponseCode(); + + if (responseCode == HttpURLConnection.HTTP_OK) { + return nodetypeNode.getNodeType(connection.read()); + } + + // not a good response code + LOGGER.error(RestClientI18n.connectionErrorMsg, responseCode, "getNodeType"); + String msg = RestClientI18n.getNodeTypeFailedMsg.text(nodeTypeName, nodetypeNode.getUrl(), + responseCode); + throw new RuntimeException(msg); + } finally { + if (connection != null) { + LOGGER.trace("getNodeTypes: leaving"); + connection.disconnect(); + } + } + } + + /** * {@inheritDoc} * * @see org.modeshape.web.jcr.rest.client.IRestClient#getUrl(java.io.File, java.lang.String, @@ -566,7 +636,8 @@ System.out.println(" " + WORKSPACENAME_PARM + " (default=default)"); System.out.println(" " + USERNAME_PARM + "(default=admin"); System.out.println(" " + PWD_PARM + " (default=admin"); - System.out.println(" " + UNPUBLISH + " with no parameter, will activate"); + System.out.println(" " + UNPUBLISH + " with no parameter, will remove file(s)"); + System.exit(0); } @@ -640,14 +711,7 @@ e.printStackTrace(); System.exit(-1); } - - try { - client.getWorkspaces(repository); - } catch (Exception e) { - e.printStackTrace(); - System.exit(-1); - } - + if (publish) { if (file_name != null) { Index: src/main/java/org/modeshape/web/jcr/rest/client/json/NodeTypeNode.java =================================================================== --- src/main/java/org/modeshape/web/jcr/rest/client/json/NodeTypeNode.java (revision 0) +++ src/main/java/org/modeshape/web/jcr/rest/client/json/NodeTypeNode.java (revision 0) @@ -0,0 +1,352 @@ +/* + * ModeShape (http://www.modeshape.org) + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * See the AUTHORS.txt file in the distribution for a full listing of + * individual contributors. + * + * ModeShape is free software. Unless otherwise indicated, all code in ModeShape + * is licensed to you under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * ModeShape is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.modeshape.web.jcr.rest.client.json; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; + +import net.jcip.annotations.Immutable; + +import org.codehaus.jettison.json.JSONArray; +import org.codehaus.jettison.json.JSONObject; +import org.modeshape.common.util.CheckArg; +import org.modeshape.web.jcr.rest.client.domain.NodeType; +import org.modeshape.web.jcr.rest.client.domain.Workspace; + +/** + * The NodeTypeNode class is responsible for knowing how to obtain a NodeType based + * on the Workspace. + *
+ * + * An example URL to obtain all the node types would look like: + *
+ * {context root}/{repository name}/{workspace name}/items/jcr:system/jcr:nodeTypes" + *
+ * And an example url to obtain a specific node type would look like: + *
+ * {context root}/{repository name}/{workspace name}/items/jcr:system/jcr:nodeTypes/{node type name} + */ +@Immutable +public final class NodeTypeNode extends JsonNode { + + /* the path used to get to the node types */ + private static final String GET_NODE_TYPES_URL = "/jcr:system/jcr:nodeTypes"; + + // =========================================================================================================================== + // Fields + // =========================================================================================================================== + + /** + * The workspace from where the node type is being obtained. + */ + private final Workspace workspace; + + private final String nodeTypeName; + + private final int depth; + + private MapnodeTypeMap = new HashMap(); + + // =========================================================================================================================== + // Constructors + // =========================================================================================================================== + + /** + * Use this constructor if wanting all node types for a workspace + * @param workspace the workspace being used (never null) + * @param depth is the depth of the graph to look + * @throws Exception if there is a problem creating the folder node + */ + public NodeTypeNode( Workspace workspace, int depth) throws Exception { + super(GET_NODE_TYPES_URL); + + CheckArg.isNotNull(workspace, "workspace"); + + this.workspace = workspace; + this.nodeTypeName = null; + this.depth = depth; + } + + /** + * Use this constructor if wanting a specific node type + * @param workspace the workspace being used (never null) + * @param nodeTypeName is the node type to be returned + * @throws Exception if there is a problem creating the folder node + */ + public NodeTypeNode( Workspace workspace, String nodeTypeName) throws Exception { + super(GET_NODE_TYPES_URL); + + CheckArg.isNotNull(workspace, "workspace"); + CheckArg.isNotNull(nodeTypeName, "nodeTypeName"); + + this.workspace = workspace; + this.nodeTypeName = nodeTypeName; + this.depth = 2; + } + + // =========================================================================================================================== + // Methods + // =========================================================================================================================== + + /** + * @return the full path of folder within the workspace + */ + public String getPath() { + return getId(); + } + + /** + * {@inheritDoc} + *

+ * The URL will NOT end in '/'. + * + * @see org.modeshape.web.jcr.rest.client.json.JsonNode#getUrl() + */ + @Override + public URL getUrl() throws Exception { + WorkspaceNode workspaceNode = new WorkspaceNode(this.workspace); + StringBuilder url = new StringBuilder(workspaceNode.getUrl().toString()); + + // make sure path starts with a '/' + String path = getPath(); + + if (!path.startsWith("/")) { + path = '/' + path; + } + + // make sure path does NOT end with a '/' + if (path.endsWith("/")) { + path = path.substring(0, path.length() - 1); + } + + // path needs to be encoded + url.append(JsonUtils.encode(path)); + + // if wanting a specific node type, need to append the node type name and the depth in order to get its properties + if (this.nodeTypeName != null) { + // url.append("/").append(JsonUtils.encode(this.nodeTypeName)).append(JsonUtils.encode("?depth=" + this.depth)); + url.append("/").append((this.nodeTypeName)); + } + url.append(("?depth=" + this.depth)); + + return new URL(url.toString()); + } + + /** + * @param jsonResponse the HTTP connection JSON response (never null) containing the NodeTypes + * @return the node types for this workspace (never null) + * @throws Exception if there is a problem obtaining the node types + */ + public Collection getNodeTypes( String jsonResponse ) throws Exception { + CheckArg.isNotNull(jsonResponse, "jsonResponse"); + Collection nodetypes = new ArrayList(); + JSONObject body = new JSONObject(jsonResponse); + processBody(body, nodetypes, null); + return nodetypes; + } + + @SuppressWarnings("unchecked") + protected void processBody(JSONObject body, Collection nodetypes, NodeType parentNodeType) throws Exception { + NodeType parent = parentNodeType; + + parent = createNodeType(null, body, null); + nodetypes.add(parent); + this.nodeTypeMap.put(parent.getName(), parent); + + if (body.has("children")) { + Object obj = body.get("children"); + + if (obj instanceof JSONObject) { + + JSONObject children = (JSONObject) obj; + for (Iterator itr = children.keys(); itr.hasNext();) { + String key = JsonUtils.decode(itr.next()); + + Object child = children.get(key); + if (child != null) { + + if (child instanceof JSONObject) { + JSONObject jsonchild = (JSONObject) child; + NodeType nodeType = createNodeType(key, jsonchild, parent); + nodetypes.add(nodeType); + processNodeType(nodeType, jsonchild, parent); + + } else if (child instanceof JSONArray) { + JSONArray childarray = (JSONArray) child; + for (int idx=0; idx itr = children.keys(); itr.hasNext();) { + String childkey = JsonUtils.decode(itr.next()); + Object childObj = children.get(childkey); + + if (childObj instanceof JSONObject) { + JSONObject childJson = (JSONObject) childObj; + NodeType childnodeType = createNodeType(childkey, childJson, nodeType); + processNodeType(childnodeType, (JSONObject) childObj, nodeType); + + } else { + throw new Exception("Program Error: class type not handled " + childObj.getClass().getName() ); + } + } + + } else if (obj instanceof JSONArray) { + JSONArray childarray = (JSONArray) obj; + for (int i=0; i itr = jsonProperties.keys(); itr.hasNext();) { + String key = JsonUtils.decode(itr.next()); + Object obj = jsonProperties.get(key); + if (obj != null) { + if (obj instanceof JSONObject) { + // JSONObject child = (JSONObject) obj; + + throw new Exception("Program Error: didnt handle object type: " + obj.getClass().getName()); +// processBody(child, nodetypes, nodeType); + } + properties.put(key, obj.toString()); + } + } + + String nodeName = childkey; + NodeType childnodeType = null; + + if (nodeName == null) { + nodeName = properties.getProperty("jcr:primaryType", childkey); + childnodeType = new NodeType(nodeName, this.workspace, properties); + if (parentNodeType != null) parentNodeType.addChildNodeType(childnodeType); + + } else if (childkey.equalsIgnoreCase("jcr:propertyDefinition")) { + nodeName = properties.getProperty("jcr:name", childkey); + childnodeType = new NodeType(nodeName, this.workspace, properties); + if (parentNodeType != null) parentNodeType.addPropertyDefinitionNodeType(childnodeType); + + } else if (childkey.equalsIgnoreCase("jcr:childNodeDefinition")) { + nodeName = properties.getProperty("jcr:name",childkey); + childnodeType = new NodeType(nodeName, this.workspace, properties); + if (parentNodeType != null) parentNodeType.addChildNodeDefinitionNodeType(childnodeType); + + } else if (properties.getProperty("jcr:nodeTypeName") != null){ + nodeName = properties.getProperty("jcr:nodeTypeName",childkey); + childnodeType = new NodeType(nodeName, this.workspace, properties); + if (parentNodeType != null) parentNodeType.addChildNodeType(childnodeType); + } + + + if (nodeName == null) { + nodeName = (childkey != null ? childkey : "NotDefined"); + } + + CheckArg.isNotNull(nodeName, "nodeName ends up in null state for childkey: " + childkey); + return childnodeType; + + } + + + /** + * @param jsonResponse the HTTP connection JSON response (never null) containing the NodeTypes + * @return the node types for this workspace (never null) + * @throws Exception if there is a problem obtaining the node types + */ + + @SuppressWarnings("unchecked") + public NodeType getNodeType( String jsonResponse ) throws Exception { + CheckArg.isNotNull(jsonResponse, "jsonResponse"); + JSONObject jsonChild = new JSONObject(jsonResponse); + + Properties properties = new Properties(); + + NodeType nodetype = null; + + // keys are the repository names + for (Iterator itr = jsonChild.keys(); itr.hasNext();) { + String name = JsonUtils.decode(itr.next()); + Object obj = jsonChild.get(name); + if (obj != null && obj instanceof JSONObject) { + JSONObject child = (JSONObject) obj; + nodetype = new NodeType(name, this.workspace, properties); + this.processNodeType(nodetype, child, null); + + return nodetype; + } + } + + return null; + } + +} Index: src/main/java/org/modeshape/web/jcr/rest/client/IRestClient.java =================================================================== --- src/main/java/org/modeshape/web/jcr/rest/client/IRestClient.java (revision 2126) +++ src/main/java/org/modeshape/web/jcr/rest/client/IRestClient.java (working copy) @@ -28,6 +28,7 @@ import java.util.Collection; import java.util.List; import org.modeshape.web.jcr.rest.client.Status.Severity; +import org.modeshape.web.jcr.rest.client.domain.NodeType; import org.modeshape.web.jcr.rest.client.domain.QueryRow; import org.modeshape.web.jcr.rest.client.domain.Repository; import org.modeshape.web.jcr.rest.client.domain.Server; @@ -46,6 +47,25 @@ * @throws Exception if there is a problem obtaining the repositories */ Collection getRepositories( Server server ) throws Exception; + + /** + * Obtains the ModeShape node types defined within the specified workspace. + * + * @param workspace whose node types are being requested (never null) + * @return the node types defined within the specified workspace (never null) + * @throws Exception if there is a problem obtaining the node types + */ + Collection getNodeTypes(Workspace workspace) throws Exception; + + /** + * Obtains the ModeShape node type requested by the nodeTypeName within the specified workspace. + * + * @param workspace whose node types are being requested (never null) + * @param nodeTypeName is the specific node type to be returned (never null) + * @return the node type requested by the nodeTypeName (null) + * @throws Exception if there is a problem obtaining the node type + */ + NodeType getNodeType(Workspace workspace, String nodeTypeName) throws Exception; /** * @param file the file whose URL is being requested (never null) Index: src/main/resources/org/modeshape/web/jcr/rest/client/RestClientI18n.properties =================================================================== --- src/main/resources/org/modeshape/web/jcr/rest/client/RestClientI18n.properties (revision 2126) +++ src/main/resources/org/modeshape/web/jcr/rest/client/RestClientI18n.properties (working copy) @@ -31,6 +31,8 @@ workspaceShortDescription = ModeShape Workspace - Name: {0}, Repository: {1} +nodeTypeShortDescription = ModeShape NodeType: {0}, Server: {1} + # JsonRestClient messages connectionErrorMsg = response code={0} method={1} @@ -42,6 +44,8 @@ unpublishFailedMsg = The file "{0}" could not be unpublished in workspace "{1}" at path "{2}". unpublishNeverPublishedMsg = The file "{0}" could not be unpublished in workspace "{1}" at path "{2}" because it could not be found. invalidQueryLanguageMsg = "{0}" is not a valid query language. The valid query languages are: {1} +getNodeTypesFailedMsg = Obtaining the node types from repository "{0}" failed with HTTP response code of "{1}" +getNodeTypeFailedMsg = Failed obtaining node type "{0}" from repository "{1}" with HTTP response code of "{2}" publishSucceededMsg = Successfully published file "{0}" to path "{1}" in workspace "{2}" unpublishSucceededMsg = Successfully unpublished file "{0}" from path "{1}" in workspace "{2}" Index: src/test/java/org/modeshape/web/jcr/rest/client/MockRestClient.java =================================================================== --- src/test/java/org/modeshape/web/jcr/rest/client/MockRestClient.java (revision 2126) +++ src/test/java/org/modeshape/web/jcr/rest/client/MockRestClient.java (working copy) @@ -27,6 +27,8 @@ import java.net.URL; import java.util.Collection; import java.util.List; + +import org.modeshape.web.jcr.rest.client.domain.NodeType; import org.modeshape.web.jcr.rest.client.domain.QueryRow; import org.modeshape.web.jcr.rest.client.domain.Repository; import org.modeshape.web.jcr.rest.client.domain.Server; @@ -121,4 +123,26 @@ return null; } + /** + * {@inheritDoc} + * + * @see org.modeshape.web.jcr.rest.client.IRestClient#getNodeTypes(org.modeshape.web.jcr.rest.client.domain.Workspace) + */ + @Override + public Collection getNodeTypes(Workspace workspace) + throws Exception { + return null; + } + + /** + * {@inheritDoc} + * + * @see org.modeshape.web.jcr.rest.client.IRestClient#getNodeType(org.modeshape.web.jcr.rest.client.domain.Workspace, java.lang.String) + */ + @Override + public NodeType getNodeType(Workspace workspace, String nodeTypeName) + throws Exception { + return null; + } + } Index: src/test/java/org/modeshape/web/jcr/rest/client/json/JsonRestClientTest.java =================================================================== --- src/test/java/org/modeshape/web/jcr/rest/client/json/JsonRestClientTest.java (revision 2126) +++ src/test/java/org/modeshape/web/jcr/rest/client/json/JsonRestClientTest.java (working copy) @@ -27,11 +27,15 @@ import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNull.notNullValue; import static org.junit.Assert.assertThat; + import java.io.File; import java.net.URL; import java.util.Collection; +import java.util.Iterator; import java.util.List; + import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.modeshape.web.jcr.rest.client.IJcrConstants; import org.modeshape.web.jcr.rest.client.IRestClient; @@ -36,6 +40,7 @@ import org.modeshape.web.jcr.rest.client.IJcrConstants; import org.modeshape.web.jcr.rest.client.IRestClient; import org.modeshape.web.jcr.rest.client.Status; +import org.modeshape.web.jcr.rest.client.domain.NodeType; import org.modeshape.web.jcr.rest.client.domain.QueryRow; import org.modeshape.web.jcr.rest.client.domain.Repository; import org.modeshape.web.jcr.rest.client.domain.Server; @@ -49,6 +54,7 @@ * Two containers: mvn -P cargo-1,cargo-2 clean install assembly:assembly */ public final class JsonRestClientTest { + // =========================================================================================================================== // Constants @@ -96,6 +102,39 @@ assertThat(repositories.size(), equalTo(1)); assertThat(repositories.iterator().next(), is(REPOSITORY1)); } + + // Test is not currently working as a unit test, cause it throws an exception when using the default cargo setup + // but does work when pointed at a local jbossas server + // TODO: determine how to add/setup the local cargo server with cnd files + @Ignore + @Test + public void shouldGetNodeTypes() throws Exception { + Collection results = this.restClient.getNodeTypes(WORKSPACE1); + // this is currently the number returned from the default jbossas installation + assertThat(results.size(), is(457)); + + boolean foundNtFile = false; + for (Iterator it=results.iterator(); it.hasNext();) { + NodeType nt = it.next(); + if (nt.getName().equalsIgnoreCase("nt:file")) { + assertThat(nt.getChildNodeDefinitions().size(), equalTo(1)); + foundNtFile = true; + } + } + assertThat(foundNtFile, is(true)); + } + + // Test is not currently working as a unit test, cause it throws an exception when using the default cargo setup + // but does work when pointed at a local jbossas server + // TODO: determine how to add/setup the local cargo server with cnd files + @Ignore + @Test + public void shouldGetNodeType() throws Exception { + Workspace workspace = new Workspace(WORKSPACE_NAME, REPOSITORY1); + NodeType nt = this.restClient.getNodeType(workspace, "nt:propertyDefinition"); + + assertThat(nt, is(notNullValue())); + } @Test public void shouldGetWorkspaces() throws Exception { Index: src/test/java/org/modeshape/web/jcr/rest/client/domain/WorkspaceTest.java =================================================================== --- src/test/java/org/modeshape/web/jcr/rest/client/domain/WorkspaceTest.java (revision 2126) +++ src/test/java/org/modeshape/web/jcr/rest/client/domain/WorkspaceTest.java (working copy) @@ -28,6 +28,7 @@ import static org.hamcrest.core.IsNot.not; import static org.junit.Assert.assertThat; import java.util.HashSet; +import java.util.Properties; import java.util.Set; import org.junit.Test; @@ -40,19 +41,25 @@ // Constants // =========================================================================================================================== - private static final String NAME1 = "name1"; + private static final String NAME1 = "nt:file"; - private static final String NAME2 = "name2"; + private static final String NAME2 = "nt:resource"; private static final Server SERVER1 = new Server("file:/tmp/temp.txt/resources", "user", "pswd"); - private static final Server SERVER2 = new Server("http:www.redhat.com/resources", "user", "pswd"); + // private static final Server SERVER2 = new Server("http:www.redhat.com/resources", "user", "pswd"); private static final Repository REPOSITORY1 = new Repository(NAME1, SERVER1); - private static final Repository REPOSITORY2 = new Repository(NAME2, SERVER2); + // private static final Repository REPOSITORY2 = new Repository(NAME2, SERVER2); private static final Workspace WORKSPACE1 = new Workspace(NAME1, REPOSITORY1); + private static final Workspace WORKSPACE2 = new Workspace(NAME2, REPOSITORY1); + + private static final NodeType NODETYPE1 = new NodeType(NAME1, WORKSPACE1, null); + + private static final NodeType NODETYPE2 = new NodeType(NAME1, WORKSPACE1, new Properties()); + // =========================================================================================================================== // Tests @@ -60,7 +67,7 @@ @Test public void shouldBeEqualIfHavingSameProperies() { - assertThat(WORKSPACE1, equalTo(new Workspace(WORKSPACE1.getName(), WORKSPACE1.getRepository()))); + assertThat(NODETYPE2, equalTo(new NodeType(NAME1, WORKSPACE1, new Properties()))); } @Test @@ -65,30 +72,30 @@ @Test public void shouldHashToSameValueIfEquals() { - Set set = new HashSet(); - set.add(WORKSPACE1); - set.add(new Workspace(WORKSPACE1.getName(), WORKSPACE1.getRepository())); + Set set = new HashSet(); + set.add(NODETYPE1); + set.add(new NodeType("nt:file", WORKSPACE1, null)); assertThat(set.size(), equalTo(1)); } - @Test( expected = RuntimeException.class ) + @Test( expected = java.lang.AssertionError.class ) public void shouldNotAllowNullName() { - new Workspace(null, REPOSITORY1); + new NodeType(null, WORKSPACE1, new Properties()); } - @Test( expected = RuntimeException.class ) + @Test( expected = java.lang.AssertionError.class ) public void shouldNotAllowNullRepository() { - new Workspace(NAME1, null); + new NodeType(NAME1, null, null); } @Test - public void shouldNotBeEqualIfSameNameButDifferentRepository() { - assertThat(WORKSPACE1, is(not(equalTo(new Workspace(WORKSPACE1.getName(), REPOSITORY2))))); + public void shouldNotBeEqualIfSameNameButDifferentWorkspace() { + assertThat(NODETYPE2, is(not(equalTo(new NodeType(NAME1, WORKSPACE2, new Properties()))))); } @Test - public void shouldNotBeEqualIfSameRepositoryButDifferentName() { - assertThat(WORKSPACE1, is(not(equalTo(new Workspace(NAME2, WORKSPACE1.getRepository()))))); + public void shouldNotBeEqualIfSameWorkspaceButDifferentName() { + assertThat(NODETYPE2, is(not(equalTo(new NodeType(NAME2, WORKSPACE1, new Properties()))))); } } Index: src/test/java/org/modeshape/web/jcr/rest/client/domain/NodeTypeTest.java =================================================================== --- src/test/java/org/modeshape/web/jcr/rest/client/domain/NodeTypeTest.java (revision 0) +++ src/test/java/org/modeshape/web/jcr/rest/client/domain/NodeTypeTest.java (revision 0) @@ -0,0 +1,94 @@ +/* + * ModeShape (http://www.modeshape.org) + * See the COPYRIGHT.txt file distributed with this work for information + * regarding copyright ownership. Some portions may be licensed + * to Red Hat, Inc. under one or more contributor license agreements. + * See the AUTHORS.txt file in the distribution for a full listing of + * individual contributors. + * + * ModeShape is free software. Unless otherwise indicated, all code in ModeShape + * is licensed to you under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * ModeShape is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ +package org.modeshape.web.jcr.rest.client.domain; + +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.hamcrest.core.IsNot.not; +import static org.junit.Assert.assertThat; +import java.util.HashSet; +import java.util.Set; +import org.junit.Test; + +/** + * The WorkspaceTest class is a test class for the {@link Workspace workspace} object. + */ +public final class NodeTypeTest { + + // =========================================================================================================================== + // Constants + // =========================================================================================================================== + + private static final String NAME1 = "name1"; + + private static final String NAME2 = "name2"; + + private static final Server SERVER1 = new Server("file:/tmp/temp.txt/resources", "user", "pswd"); + + private static final Server SERVER2 = new Server("http:www.redhat.com/resources", "user", "pswd"); + + private static final Repository REPOSITORY1 = new Repository(NAME1, SERVER1); + + private static final Repository REPOSITORY2 = new Repository(NAME2, SERVER2); + + private static final Workspace WORKSPACE1 = new Workspace(NAME1, REPOSITORY1); + + // =========================================================================================================================== + // Tests + // =========================================================================================================================== + + @Test + public void shouldBeEqualIfHavingSameProperies() { + assertThat(WORKSPACE1, equalTo(new Workspace(WORKSPACE1.getName(), WORKSPACE1.getRepository()))); + } + + @Test + public void shouldHashToSameValueIfEquals() { + Set set = new HashSet(); + set.add(WORKSPACE1); + set.add(new Workspace(WORKSPACE1.getName(), WORKSPACE1.getRepository())); + assertThat(set.size(), equalTo(1)); + } + + @Test( expected = RuntimeException.class ) + public void shouldNotAllowNullName() { + new Workspace(null, REPOSITORY1); + } + + @Test( expected = RuntimeException.class ) + public void shouldNotAllowNullRepository() { + new Workspace(NAME1, null); + } + + @Test + public void shouldNotBeEqualIfSameNameButDifferentRepository() { + assertThat(WORKSPACE1, is(not(equalTo(new Workspace(WORKSPACE1.getName(), REPOSITORY2))))); + } + + @Test + public void shouldNotBeEqualIfSameRepositoryButDifferentName() { + assertThat(WORKSPACE1, is(not(equalTo(new Workspace(NAME2, WORKSPACE1.getRepository()))))); + } + +}