summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-05-24 12:32:31 (EDT)
committer pelder2006-05-24 12:32:31 (EDT)
commit06878ec7852c0d73d0e8cffaa70350d77fe6751c (patch)
tree50ebfea956783b56cc11e5844c4449bcf1d58d23
parent3bcb52ae4b7111db586f930fa067e61b7f2a342c (diff)
downloadorg.eclipse.jet-06878ec7852c0d73d0e8cffaa70350d77fe6751c.zip
org.eclipse.jet-06878ec7852c0d73d0e8cffaa70350d77fe6751c.tar.gz
org.eclipse.jet-06878ec7852c0d73d0e8cffaa70350d77fe6751c.tar.bz2
[143509] JUnits for model loader and inspector to allow JET to naviate the Eclipse workspace.
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AllTests.java40
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EMFResourceInspectorTests.java116
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/ResourceAttributeInspectorTests.java406
-rw-r--r--tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/ResourceInspectorTests.java488
4 files changed, 969 insertions, 81 deletions
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AllTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AllTests.java
index 1dbb92a..4d7e201 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AllTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/AllTests.java
@@ -8,31 +8,33 @@ public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("Test for org.eclipse.jet.tests.xpath");
//$JUnit-BEGIN$
- suite.addTestSuite(AttributeStepTests.class);
- suite.addTestSuite(XPathOverDOMTests.class);
- suite.addTestSuite(StringFunctionTests.class);
- suite.addTestSuite(ResourceInspectorTests.class);
- suite.addTestSuite(XPathOverEmfXmlXsdTests.class);
- suite.addTestSuite(BooleanFunctionTests.class);
- suite.addTestSuite(RelOpTests.class);
suite.addTestSuite(XPathParserTests.class);
+ suite.addTestSuite(EStructuralFeatureSettingTests.class);
+ suite.addTestSuite(VariableTests.class);
+ suite.addTestSuite(RelOpTests.class);
+ suite.addTest(ResourceAttributeInspectorTests.suite());
+ suite.addTestSuite(SelfStepTests.class);
+ suite.addTestSuite(ParentStepTests.class);
+ suite.addTestSuite(LogicalOpTests.class);
+ suite.addTestSuite(DOMInspectorTests.class);
suite.addTestSuite(ExpandedNameTests.class);
- suite.addTestSuite(XPathTokenScannerTests.class);
- suite.addTestSuite(NumberFunctionTests.class);
+ suite.addTestSuite(XPathOverDOMTests.class);
+ suite.addTestSuite(BooleanFunctionTests.class);
+ suite.addTestSuite(EMFResourceInspectorTests.class);
suite.addTestSuite(NumberBinaryOpTests.class);
- suite.addTestSuite(SelfStepTests.class);
+ suite.addTest(ResourceInspectorTests.suite());
+ suite.addTestSuite(StringFunctionTests.class);
suite.addTestSuite(BuiltinStringFunctionsTests.class);
- suite.addTestSuite(XPathInspectorManagerTests.class);
- suite.addTestSuite(EObjectInspectorTests.class);
- suite.addTestSuite(DOMInspectorTests.class);
- suite.addTestSuite(LogicalOpTests.class);
- suite.addTestSuite(XPathOverEcoreTests.class);
- suite.addTestSuite(EStructuralFeatureSettingTests.class);
+ suite.addTestSuite(NumberFunctionTests.class);
+ suite.addTestSuite(XPathOverEmfXmlXsdTests.class);
+ suite.addTestSuite(XPathParserDefects.class);
suite.addTestSuite(ChildStepTests.class);
- suite.addTestSuite(ParentStepTests.class);
+ suite.addTestSuite(AttributeStepTests.class);
+ suite.addTestSuite(XPathOverEcoreTests.class);
+ suite.addTestSuite(EObjectInspectorTests.class);
+ suite.addTestSuite(XPathInspectorManagerTests.class);
+ suite.addTestSuite(XPathTokenScannerTests.class);
suite.addTestSuite(RootTests.class);
- suite.addTestSuite(XPathParserDefects.class);
- suite.addTestSuite(VariableTests.class);
//$JUnit-END$
return suite;
}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EMFResourceInspectorTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EMFResourceInspectorTests.java
new file mode 100644
index 0000000..3eb0f90
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/EMFResourceInspectorTests.java
@@ -0,0 +1,116 @@
+package org.eclipse.jet.tests.xpath;
+
+import junit.framework.TestCase;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.Resource.Factory;
+import org.eclipse.jet.internal.xpath.inspectors.EMFResourceInspector;
+import org.eclipse.jet.xpath.inspector.ExpandedName;
+import org.eclipse.jet.xpath.inspector.INodeInspector.NodeKind;
+
+public class EMFResourceInspectorTests extends TestCase {
+
+ protected Resource resource;
+ protected EObject root;
+ protected EMFResourceInspector inspector;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ URI fileURI = URI.createURI("platform:/plugin/org.eclipse.jet.tests/data/sample.dataaccess");
+ Factory factory = Resource.Factory.Registry.INSTANCE.getFactory(fileURI);
+
+ resource = factory.createResource(fileURI);
+ resource.load(null);
+
+ root = (EObject) resource.getContents().get(0);
+
+ inspector = new EMFResourceInspector();
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.getNamedChildren(Object, ExpandedName)'
+ */
+ public void testGetNamedChildren_contents() {
+ Object[] namedChildren = inspector.getNamedChildren(resource, new ExpandedName("contents"));
+ assertEquals(1, namedChildren.length);
+ assertEquals(root, namedChildren[0]);
+ }
+
+ public void testGetNamedChildren_eClass() {
+ Object[] namedChildren = inspector.getNamedChildren(resource, new ExpandedName("Employee"));
+ assertEquals(1, namedChildren.length);
+ assertEquals(root, namedChildren[0]);
+
+ }
+
+ public void testGetNamedChildren_invalid() {
+ Object[] namedChildren = inspector.getNamedChildren(resource, new ExpandedName("Customer"));
+ assertEquals(0, namedChildren.length);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.getNodeKind(Object)'
+ */
+ public void testGetNodeKind() {
+ NodeKind nodeKind = inspector.getNodeKind(resource);
+ assertEquals(NodeKind.ROOT, nodeKind);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.getParent(Object)'
+ */
+ public void testGetParent() {
+ Object result = inspector.getParent(resource);
+ assertNull(result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.stringValueOf(Object)'
+ */
+ public void testStringValueOf() {
+ String result = inspector.stringValueOf(resource);
+ assertEquals("", result);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.expandedNameOf(Object)'
+ */
+ public void testExpandedNameOf() {
+ ExpandedName expandedName = inspector.expandedNameOf(resource);
+
+ assertNull(expandedName);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.getDocumentRoot(Object)'
+ */
+ public void testGetDocumentRoot() {
+ Object documentRoot = inspector.getDocumentRoot(resource);
+
+ assertEquals(resource, documentRoot);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.getChildren(Object)'
+ */
+ public void testGetChildren() {
+ Object[] children = inspector.getChildren(resource);
+
+ assertNotNull(children);
+ assertEquals(1, children.length);
+ assertEquals(root, children[0]);
+ }
+
+ /*
+ * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.nameOf(Object)'
+ */
+ public void testNameOf() {
+ String nameOf = inspector.nameOf(resource);
+
+ assertNull(nameOf);
+ }
+
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/ResourceAttributeInspectorTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/ResourceAttributeInspectorTests.java
new file mode 100644
index 0000000..fba11ee
--- /dev/null
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/ResourceAttributeInspectorTests.java
@@ -0,0 +1,406 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+
+package org.eclipse.jet.tests.xpath;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jet.JET2Platform;
+import org.eclipse.jet.internal.xpath.inspectors.IWrappedAttribute;
+import org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector;
+import org.eclipse.jet.internal.xpath.inspectors.ResourceInspector;
+import org.eclipse.jet.xpath.inspector.ExpandedName;
+import org.eclipse.jet.xpath.inspector.INodeInspector.NodeKind;
+
+/**
+ * @author pelder
+ *
+ */
+public class ResourceAttributeInspectorTests extends TestCase {
+
+ private static String TEST_PROJECT_NAME = ResourceAttributeInspectorTests.class.getName();
+
+ public static Test suite() {
+ TestSetup setup = new TestSetup(new TestSuite(ResourceAttributeInspectorTests.class)) {
+ protected void setUp() throws Exception {
+ JET2Platform.runTransformOnString("org.eclipse.jet.transforms.newproject",
+ "<newProjectModel><project name=\"" + TEST_PROJECT_NAME + "\"/></newProjectModel>",
+ new NullProgressMonitor());
+ }
+
+ protected void tearDown() throws Exception {
+ ResourcesPlugin.getWorkspace().getRoot().getProject(TEST_PROJECT_NAME).delete(true, true, new NullProgressMonitor());
+ }
+ };
+
+ return setup;
+ }
+
+ private IWorkspaceRoot workspaceRoot;
+ private IProject project;
+ private IFolder templatesFolder;
+ private IFile mainJETFile;
+ private ResourceInspector resourceInspector;
+ private WrappedAttributeInspector resourceAttributeInspector;
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ project = workspaceRoot.getProject(TEST_PROJECT_NAME);
+ templatesFolder = project.getFolder("templates");
+ mainJETFile = templatesFolder.getFile("main.jet");
+
+ resourceInspector = new ResourceInspector();
+ resourceAttributeInspector = new WrappedAttributeInspector();
+ }
+
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#expandedNameOf(java.lang.Object)}.
+ */
+ public void testExpandedNameOf_root() {
+ doExpandedNameTests(workspaceRoot);
+ }
+
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#expandedNameOf(java.lang.Object)}.
+ */
+ public void testExpandedNameOf_project() {
+ doExpandedNameTests(project);
+ }
+
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#expandedNameOf(java.lang.Object)}.
+ */
+ public void testExpandedNameOf_folder() {
+ doExpandedNameTests(templatesFolder);
+ }
+
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#expandedNameOf(java.lang.Object)}.
+ */
+ public void testExpandedNameOf_file() {
+ doExpandedNameTests(mainJETFile);
+ }
+
+
+ /**
+ * @param object
+ */
+ private void doExpandedNameTests(Object object) {
+ Object[] attributes = resourceInspector.getAttributes(object);
+
+ for (int i = 0; i < attributes.length; i++) {
+ IWrappedAttribute resAttr = (IWrappedAttribute) attributes[i];
+
+ assertEquals(new ExpandedName(resAttr.getName()), resourceAttributeInspector.expandedNameOf(resAttr));
+ }
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getChildren(java.lang.Object)}.
+ */
+ public void testGetChildren_root() {
+ doGetChildrenTests(workspaceRoot);
+ }
+
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getChildren(java.lang.Object)}.
+ */
+ public void testGetChildren_project() {
+ doGetChildrenTests(project);
+ }
+
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getChildren(java.lang.Object)}.
+ */
+ public void testGetChildren_folder() {
+ doGetChildrenTests(templatesFolder);
+ }
+
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getChildren(java.lang.Object)}.
+ */
+ public void testGetChildren_file() {
+ doGetChildrenTests(mainJETFile);
+ }
+
+
+ /**
+ * @param object
+ */
+ private void doGetChildrenTests(Object object) {
+ Object[] children = resourceAttributeInspector.getChildren(object);
+ assertNotNull(children);
+ assertEquals(0, children.length);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getDocumentRoot(java.lang.Object)}.
+ */
+ public void testGetDocumentRoot_root() {
+ doGetDocumentRootTests(workspaceRoot);
+ }
+
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getDocumentRoot(java.lang.Object)}.
+ */
+ public void testGetDocumentRoot_project() {
+ doGetDocumentRootTests(project);
+ }
+
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getDocumentRoot(java.lang.Object)}.
+ */
+ public void testGetDocumentRoot_folder() {
+ doGetDocumentRootTests(templatesFolder);
+ }
+
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getDocumentRoot(java.lang.Object)}.
+ */
+ public void testGetDocumentRoot_file() {
+ doGetDocumentRootTests(mainJETFile);
+ }
+
+
+ /**
+ * @param object
+ */
+ private void doGetDocumentRootTests(Object object) {
+ Object[] attributes = resourceInspector.getAttributes(object);
+
+ for (int i = 0; i < attributes.length; i++) {
+ IWrappedAttribute resAttr = (IWrappedAttribute) attributes[i];
+
+ assertEquals(workspaceRoot, resourceAttributeInspector.getDocumentRoot(resAttr));
+ }
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getNodeKind(java.lang.Object)}.
+ */
+ public void testGetNodeKind_root() {
+ doGetNodeKindTests(workspaceRoot);
+ }
+
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getNodeKind(java.lang.Object)}.
+ */
+ public void testGetNodeKind_project() {
+ doGetNodeKindTests(project);
+ }
+
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getNodeKind(java.lang.Object)}.
+ */
+ public void testGetNodeKind_folder() {
+ doGetNodeKindTests(templatesFolder);
+ }
+
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getNodeKind(java.lang.Object)}.
+ */
+ public void testGetNodeKind_file() {
+ doGetNodeKindTests(mainJETFile);
+ }
+
+
+ /**
+ * @param object
+ */
+ private void doGetNodeKindTests(Object object) {
+ Object[] attributes = resourceInspector.getAttributes(object);
+
+ for (int i = 0; i < attributes.length; i++) {
+ IWrappedAttribute resAttr = (IWrappedAttribute) attributes[i];
+
+ assertEquals(NodeKind.ATTRIBUTE, resourceAttributeInspector.getNodeKind(resAttr));
+ }
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getParent(java.lang.Object)}.
+ */
+ public void testGetParent_root() {
+ doGetParentTests(workspaceRoot);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getParent(java.lang.Object)}.
+ */
+ public void testGetParent_project() {
+ doGetParentTests(project);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getParent(java.lang.Object)}.
+ */
+ public void testGetParent_folder() {
+ doGetParentTests(templatesFolder);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#getParent(java.lang.Object)}.
+ */
+ public void testGetParent_file() {
+ doGetParentTests(mainJETFile);
+ }
+
+ /**
+ * @param object
+ */
+ private void doGetParentTests(Object object) {
+ Object[] attributes = resourceInspector.getAttributes(object);
+
+ for (int i = 0; i < attributes.length; i++) {
+ IWrappedAttribute resAttr = (IWrappedAttribute) attributes[i];
+
+ assertEquals(object, resourceAttributeInspector.getParent(resAttr));
+ }
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#nameOf(java.lang.Object)}.
+ */
+ public void testNameOf() {
+ doNameOfTests(workspaceRoot);
+ doNameOfTests(project);
+ doNameOfTests(templatesFolder);
+ doNameOfTests(mainJETFile);
+ }
+
+ /**
+ * @param object
+ */
+ private void doNameOfTests(Object object) {
+ Object[] attributes = resourceInspector.getAttributes(object);
+
+ for (int i = 0; i < attributes.length; i++) {
+ IWrappedAttribute resAttr = (IWrappedAttribute) attributes[i];
+
+ assertEquals(resAttr.getName(), resourceAttributeInspector.nameOf(resAttr));
+ }
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#stringValueOf(java.lang.Object)}.
+ */
+ public void testStringValueOf_root() {
+ doStringValueOfTests(workspaceRoot);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#stringValueOf(java.lang.Object)}.
+ */
+ public void testStringValueOf_project() {
+ doStringValueOfTests(project);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#stringValueOf(java.lang.Object)}.
+ */
+ public void testStringValueOf_folder() {
+ doStringValueOfTests(templatesFolder);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#stringValueOf(java.lang.Object)}.
+ */
+ public void testStringValueOf_file() {
+ doStringValueOfTests(mainJETFile);
+ }
+
+ /**
+ * @param object
+ */
+ private void doStringValueOfTests(Object object) {
+ Object[] attributes = resourceInspector.getAttributes(object);
+
+ for (int i = 0; i < attributes.length; i++) {
+ IWrappedAttribute resAttr = (IWrappedAttribute) attributes[i];
+
+ assertEquals(resAttr.getName(), resAttr.getStringValue(), resourceAttributeInspector.stringValueOf(resAttr));
+ }
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#testExpandedName(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName)}.
+ */
+ public void testTestExpandedName_root() {
+ doTestExpandedNameTests(workspaceRoot);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#testExpandedName(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName)}.
+ */
+ public void testTestExpandedName_project() {
+ doTestExpandedNameTests(project);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#testExpandedName(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName)}.
+ */
+ public void testTestExpandedName_folder() {
+ doTestExpandedNameTests(templatesFolder);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.WrappedAttributeInspector#testExpandedName(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName)}.
+ */
+ public void testTestExpandedName_file() {
+ doTestExpandedNameTests(mainJETFile);
+ }
+
+ /**
+ * @param object
+ */
+ private void doTestExpandedNameTests(Object object) {
+ Object[] attributes = resourceInspector.getAttributes(object);
+
+ for (int i = 0; i < attributes.length; i++) {
+ IWrappedAttribute resAttr = (IWrappedAttribute) attributes[i];
+
+ assertTrue(resAttr.getName(), resourceAttributeInspector.testExpandedName(resAttr, new ExpandedName(resAttr.getName())));
+ assertFalse(resAttr.getName(), resourceAttributeInspector.testExpandedName(resAttr, new ExpandedName("X" + resAttr.getName())));
+ }
+ }
+
+}
diff --git a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/ResourceInspectorTests.java b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/ResourceInspectorTests.java
index 24b7fde..d11b62a 100644
--- a/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/ResourceInspectorTests.java
+++ b/tests/org.eclipse.jet.tests/src/org/eclipse/jet/tests/xpath/ResourceInspectorTests.java
@@ -1,116 +1,480 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ *
+ * </copyright>
+ *
+ * $Id$
+ */
+
package org.eclipse.jet.tests.xpath;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
import junit.framework.TestCase;
+import junit.framework.TestSuite;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.Resource.Factory;
-import org.eclipse.jet.internal.xpath.inspectors.EMFResourceInspector;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jet.JET2Platform;
+import org.eclipse.jet.internal.xpath.inspectors.IWrappedAttribute;
+import org.eclipse.jet.internal.xpath.inspectors.ResourceInspector;
+import org.eclipse.jet.xpath.inspector.AddElementException;
+import org.eclipse.jet.xpath.inspector.CopyElementException;
import org.eclipse.jet.xpath.inspector.ExpandedName;
+import org.eclipse.jet.xpath.inspector.IElementInspector;
+import org.eclipse.jet.xpath.inspector.INodeInspector;
+import org.eclipse.jet.xpath.inspector.InspectorManager;
+import org.eclipse.jet.xpath.inspector.InvalidChildException;
+import org.eclipse.jet.xpath.inspector.SimpleElementRequiresValueException;
import org.eclipse.jet.xpath.inspector.INodeInspector.NodeKind;
+/**
+ * @author pelder
+ *
+ */
public class ResourceInspectorTests extends TestCase {
- protected Resource resource;
- protected EObject root;
- protected EMFResourceInspector inspector;
+ private static String TEST_PROJECT_NAME = ResourceInspectorTests.class.getName();
+
+ public static Test suite() {
+ TestSetup setup = new TestSetup(new TestSuite(ResourceInspectorTests.class)) {
+ protected void setUp() throws Exception {
+ JET2Platform.runTransformOnString("org.eclipse.jet.transforms.newproject",
+ "<newProjectModel><project name=\"" + TEST_PROJECT_NAME + "\"/></newProjectModel>",
+ new NullProgressMonitor());
+ }
+
+ protected void tearDown() throws Exception {
+ ResourcesPlugin.getWorkspace().getRoot().getProject(TEST_PROJECT_NAME).delete(true, true, new NullProgressMonitor());
+ }
+ };
+
+ return setup;
+ }
+
+ private IWorkspaceRoot workspaceRoot;
+ private IProject project;
+ private IFolder templatesFolder;
+ private IFile mainJETFile;
+ private ResourceInspector resourceInspector;
+ private List expectedAttributeNames;
protected void setUp() throws Exception {
super.setUp();
- URI fileURI = URI.createURI("platform:/plugin/org.eclipse.jet.tests/data/sample.dataaccess");
- Factory factory = Resource.Factory.Registry.INSTANCE.getFactory(fileURI);
-
- resource = factory.createResource(fileURI);
- resource.load(null);
+ workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ project = (IProject) workspaceRoot.findMember(TEST_PROJECT_NAME);
+ templatesFolder = (IFolder) project.findMember("templates");
+ mainJETFile = (IFile) templatesFolder.findMember("main.jet");
+
+ resourceInspector = new ResourceInspector();
+
+ expectedAttributeNames = Arrays.asList(new String[] {
+ "fileExtension",
+ "fullPath",
+ "localTimeStamp",
+ "location",
+ "locationURI",
+ "modificationStamp",
+ "name",
+ "project",
+ "projectRelativePath",
+ "rawLocation",
+ "rawLocationURI",
+ "derived",
+ "linked",
+ "phantom",
+ "readOnly",
+ "teamPrivateMember",
+ });
+ }
+
+ public void testGetInspector_root() {
+ doGetInspectorTest(workspaceRoot);
+ }
+
+ public void testGetInspector_project() {
+ doGetInspectorTest(project);
+ }
+
+ public void testGetInspector_folder() {
+ doGetInspectorTest(templatesFolder);
+ }
+
+ public void testGetInspector_file() {
+ doGetInspectorTest(mainJETFile);
+ }
+
+ /**
+ * @param object
+ */
+ private void doGetInspectorTest(Object object) {
+ INodeInspector inspector = InspectorManager.getInstance().getInspector(object);
- root = (EObject) resource.getContents().get(0);
+ assertTrue("instanceof ResourceInspector", inspector instanceof ResourceInspector);
- inspector = new EMFResourceInspector();
+ assertTrue("instanceof IElementInspector", inspector instanceof IElementInspector);
}
- /*
- * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.getNamedChildren(Object, ExpandedName)'
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#expandedNameOf(java.lang.Object)}.
*/
- public void testGetNamedChildren_contents() {
- Object[] namedChildren = inspector.getNamedChildren(resource, new ExpandedName("contents"));
- assertEquals(1, namedChildren.length);
- assertEquals(root, namedChildren[0]);
+ public void testExpandedNameOf_root() {
+ ExpandedName en = resourceInspector.expandedNameOf(workspaceRoot);
+ assertEquals(new ExpandedName("root"), en);
}
- public void testGetNamedChildren_eClass() {
- Object[] namedChildren = inspector.getNamedChildren(resource, new ExpandedName("Employee"));
- assertEquals(1, namedChildren.length);
- assertEquals(root, namedChildren[0]);
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#expandedNameOf(java.lang.Object)}.
+ */
+ public void testExpandedNameOf_project() {
+ ExpandedName en = resourceInspector.expandedNameOf(project);
+ assertEquals(new ExpandedName("project"), en);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#expandedNameOf(java.lang.Object)}.
+ */
+ public void testExpandedNameOf_folder() {
+ ExpandedName en = resourceInspector.expandedNameOf(templatesFolder);
+ assertEquals(new ExpandedName("folder"), en);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#expandedNameOf(java.lang.Object)}.
+ */
+ public void testExpandedNameOf_file() {
+ ExpandedName en = resourceInspector.expandedNameOf(mainJETFile);
+ assertEquals(new ExpandedName("file"), en);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#getChildren(java.lang.Object)}.
+ * @throws CoreException
+ */
+ public void testGetChildren_root() throws CoreException {
+ Object[] children = doGetChildrenTests(workspaceRoot);
+ assertTrue("children.length > 0", children.length > 0);
}
- public void testGetNamedChildren_invalid() {
- Object[] namedChildren = inspector.getNamedChildren(resource, new ExpandedName("Customer"));
- assertEquals(0, namedChildren.length);
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#getChildren(java.lang.Object)}.
+ * @throws CoreException
+ */
+ public void testGetChildren_project() throws CoreException {
+ Object[] children = doGetChildrenTests(project);
+ assertTrue("children.length > 0", children.length > 0);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#getChildren(java.lang.Object)}.
+ * @throws CoreException
+ */
+ public void testGetChildren_folder() throws CoreException {
+ Object[] children = doGetChildrenTests(templatesFolder);
+ assertTrue("children.length > 0", children.length > 0);
}
- /*
- * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.getNodeKind(Object)'
+ /**
+ * @param object
+ * @throws CoreException
+ */
+ private Object[] doGetChildrenTests(IContainer object) throws CoreException {
+ Object[] children = resourceInspector.getChildren(object);
+ assertNotNull(children);
+
+ IResource[] expected = object.members();
+
+ assertEquals(expected.length, children.length);
+ for (int i = 0; i < expected.length; i++) {
+ assertEquals("Child " + i, expected[i], children[i]);
+ }
+
+ return children;
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#getChildren(java.lang.Object)}.
+ * @throws CoreException
+ */
+ public void testGetChildren_file() throws CoreException {
+ Object[] children = resourceInspector.getChildren(mainJETFile);
+ assertNotNull(children);
+ assertEquals(0, children.length);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#getDocumentRoot(java.lang.Object)}.
+ */
+ public void testGetDocumentRoot() {
+ assertEquals(workspaceRoot, resourceInspector.getDocumentRoot(workspaceRoot));
+ assertEquals(workspaceRoot, resourceInspector.getDocumentRoot(project));
+ assertEquals(workspaceRoot, resourceInspector.getDocumentRoot(templatesFolder));
+ assertEquals(workspaceRoot, resourceInspector.getDocumentRoot(mainJETFile));
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#getNodeKind(java.lang.Object)}.
*/
public void testGetNodeKind() {
- NodeKind nodeKind = inspector.getNodeKind(resource);
- assertEquals(NodeKind.ROOT, nodeKind);
+ assertEquals(NodeKind.ELEMENT, resourceInspector.getNodeKind(workspaceRoot));
+ assertEquals(NodeKind.ELEMENT, resourceInspector.getNodeKind(project));
+ assertEquals(NodeKind.ELEMENT, resourceInspector.getNodeKind(templatesFolder));
+ assertEquals(NodeKind.ELEMENT, resourceInspector.getNodeKind(mainJETFile));
}
- /*
- * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.getParent(Object)'
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#getParent(java.lang.Object)}.
*/
public void testGetParent() {
- Object result = inspector.getParent(resource);
- assertNull(result);
+ assertEquals(null, resourceInspector.getParent(workspaceRoot));
+ assertEquals(workspaceRoot, resourceInspector.getParent(project));
+ assertEquals(project, resourceInspector.getParent(templatesFolder));
+ assertEquals(templatesFolder, resourceInspector.getParent(mainJETFile));
}
- /*
- * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.stringValueOf(Object)'
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#nameOf(java.lang.Object)}.
+ */
+ public void testNameOf() {
+ assertEquals("root", resourceInspector.nameOf(workspaceRoot));
+ assertEquals("project", resourceInspector.nameOf(project));
+ assertEquals("folder", resourceInspector.nameOf(templatesFolder));
+ assertEquals("file", resourceInspector.nameOf(mainJETFile));
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#stringValueOf(java.lang.Object)}.
*/
public void testStringValueOf() {
- String result = inspector.stringValueOf(resource);
- assertEquals("", result);
+ assertEquals("", resourceInspector.stringValueOf(workspaceRoot));
+ assertEquals("", resourceInspector.stringValueOf(project));
+ assertEquals("", resourceInspector.stringValueOf(templatesFolder));
+ assertEquals("", resourceInspector.stringValueOf(mainJETFile));
}
- /*
- * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.expandedNameOf(Object)'
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#testExpandedName(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName)}.
*/
- public void testExpandedNameOf() {
- ExpandedName expandedName = inspector.expandedNameOf(resource);
+ public void testTestExpandedName() {
+ ExpandedName enRoot = new ExpandedName("root");
+ ExpandedName enProject = new ExpandedName("project");
+ ExpandedName enFolder = new ExpandedName("folder");
+ ExpandedName enFile = new ExpandedName("file");
+ assertTrue(resourceInspector.testExpandedName(workspaceRoot, enRoot));
+ assertFalse(resourceInspector.testExpandedName(workspaceRoot, enProject));
+ assertFalse(resourceInspector.testExpandedName(workspaceRoot, enFolder));
+ assertFalse(resourceInspector.testExpandedName(workspaceRoot, enFile));
+
+ assertFalse(resourceInspector.testExpandedName(project, enRoot));
+ assertTrue(resourceInspector.testExpandedName(project, enProject));
+ assertFalse(resourceInspector.testExpandedName(project, enFolder));
+ assertFalse(resourceInspector.testExpandedName(project, enFile));
- assertNull(expandedName);
+ assertFalse(resourceInspector.testExpandedName(templatesFolder, enRoot));
+ assertFalse(resourceInspector.testExpandedName(templatesFolder, enProject));
+ assertTrue(resourceInspector.testExpandedName(templatesFolder, enFolder));
+ assertFalse(resourceInspector.testExpandedName(templatesFolder, enFile));
+
+ assertFalse(resourceInspector.testExpandedName(mainJETFile, enRoot));
+ assertFalse(resourceInspector.testExpandedName(mainJETFile, enProject));
+ assertFalse(resourceInspector.testExpandedName(mainJETFile, enFolder));
+ assertTrue(resourceInspector.testExpandedName(mainJETFile, enFile));
}
- /*
- * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.getDocumentRoot(Object)'
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#addElement(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName, java.lang.Object)}.
+ * @throws InvalidChildException
+ * @throws SimpleElementRequiresValueException
*/
- public void testGetDocumentRoot() {
- Object documentRoot = inspector.getDocumentRoot(resource);
+ public void testAddElement() throws SimpleElementRequiresValueException, InvalidChildException {
+ try {
+ resourceInspector.addElement(null, null, null);
+ fail("Unexpected success");
+ } catch(UnsupportedOperationException e) {
+ // success
+ }
+ }
- assertEquals(resource, documentRoot);
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#addTextElement(java.lang.Object, java.lang.String, java.lang.String, boolean)}.
+ * @throws AddElementException
+ */
+ public void testAddTextElement() throws AddElementException {
+ try {
+ resourceInspector.addTextElement(null, null, null, false);
+ fail("Unexpected success");
+ } catch(UnsupportedOperationException e) {
+ // success
+ }
}
- /*
- * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.getChildren(Object)'
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#copyElement(java.lang.Object, java.lang.Object, java.lang.String, boolean)}.
+ * @throws CopyElementException
*/
- public void testGetChildren() {
- Object[] children = inspector.getChildren(resource);
+ public void testCopyElement() throws CopyElementException {
+ try {
+ resourceInspector.copyElement(null, null, null, false);
+ fail("Unexpected success");
+ } catch(UnsupportedOperationException e) {
+ // success
+ }
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#createAttribute(java.lang.Object, java.lang.String, java.lang.String)}.
+ */
+ public void testCreateAttribute() {
+ try {
+ resourceInspector.createAttribute(null, null, null);
+ fail("Unexpected success");
+ } catch(UnsupportedOperationException e) {
+ // success
+ }
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#getAttributes(java.lang.Object)}.
+ */
+ public void testGetAttributes_root() {
+ doGetAttributesTest(workspaceRoot);
- assertNotNull(children);
- assertEquals(1, children.length);
- assertEquals(root, children[0]);
}
- /*
- * Test method for 'org.eclipse.jet.internal.xpath.ResourceInspector.nameOf(Object)'
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#getAttributes(java.lang.Object)}.
*/
- public void testNameOf() {
- String nameOf = inspector.nameOf(resource);
+ public void testGetAttributes_project() {
+ doGetAttributesTest(project);
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#getAttributes(java.lang.Object)}.
+ */
+ public void testGetAttributes_folder() {
+ doGetAttributesTest(templatesFolder);
+
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#getAttributes(java.lang.Object)}.
+ */
+ public void testGetAttributes_file() {
+ doGetAttributesTest(mainJETFile);
+
+ }
+
+ /**
+ * @param object
+ */
+ private void doGetAttributesTest(Object object) {
+ Object[] attributes = resourceInspector.getAttributes(object);
+
+ assertNotNull(attributes);
+
+ assertEquals(expectedAttributeNames.size(), attributes.length);
+
+ Set actualNames = new HashSet(attributes.length);
+ for (int i = 0; i < attributes.length; i++) {
+ assertTrue("attribute[" + i + "] instanceof IResourceAttribute", attributes[i] instanceof IWrappedAttribute);
+ IWrappedAttribute resAttr = (IWrappedAttribute) attributes[i];
+ actualNames.add(resAttr.getName());
+ }
- assertNull(nameOf);
+ assertTrue(actualNames.containsAll(expectedAttributeNames));
+ actualNames.removeAll(expectedAttributeNames);
+ assertEquals(0, actualNames.size());
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#getNamedAttribute(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName)}.
+ */
+ public void testGetNamedAttribute_root() {
+ doGetNamedAttributeTests(workspaceRoot);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#getNamedAttribute(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName)}.
+ */
+ public void testGetNamedAttribute_project() {
+ doGetNamedAttributeTests(project);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#getNamedAttribute(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName)}.
+ */
+ public void testGetNamedAttribute_folder() {
+ doGetNamedAttributeTests(templatesFolder);
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#getNamedAttribute(java.lang.Object, org.eclipse.jet.xpath.inspector.ExpandedName)}.
+ */
+ public void testGetNamedAttribute_file() {
+ doGetNamedAttributeTests(mainJETFile);
+ }
+
+ /**
+ * @param object
+ */
+ private void doGetNamedAttributeTests(Object object) {
+ for (Iterator i = expectedAttributeNames.iterator(); i.hasNext();) {
+ String name = (String) i.next();
+
+ IWrappedAttribute attr = (IWrappedAttribute) resourceInspector.getNamedAttribute(object, new ExpandedName(name));
+ assertNotNull(name, attr);
+ assertEquals(name, attr.getName());
+
+ }
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#removeAttribute(java.lang.Object, java.lang.String)}.
+ */
+ public void testRemoveAttribute() {
+ try {
+ resourceInspector.removeAttribute(null, null);
+ fail("Unexpected success");
+ } catch(UnsupportedOperationException e) {
+ // success
+ }
+ }
+
+ /**
+ * Test method for {@link org.eclipse.jet.internal.xpath.inspectors.ResourceInspector#removeElement(java.lang.Object)}.
+ */
+ public void testRemoveElement() {
+ try {
+ resourceInspector.removeElement(null);
+ fail("Unexpected success");
+ } catch(UnsupportedOperationException e) {
+ // success
+ }
}
}