Author: tpalsulich
Date: Mon Dec 29 20:35:23 2014
New Revision: 1648419
URL: http://svn.apache.org/r1648419
Log:
OODT-762. Migrate profile test resources.
Added:
oodt/trunk/profile/src/test/java/
oodt/trunk/profile/src/test/java/org/
oodt/trunk/profile/src/test/java/org/apache/
oodt/trunk/profile/src/test/java/org/apache/oodt/
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/EnumeratedProfileElementTest.java
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ProfileAttributesTest.java
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ProfileElementTestCase.java
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ProfileTest.java
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/RangedProfileElementTest.java
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ResourceAttributesTest.java
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/handlers/
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/handlers/lightweight/
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/handlers/lightweight/LightweightProfileServerTest.java
oodt/trunk/profile/src/test/resources/
oodt/trunk/profile/src/test/resources/lightweightTest.xml
oodt/trunk/profile/src/test/resources/test.xml
Removed:
oodt/trunk/profile/src/test/org/
oodt/trunk/profile/src/testdata/
Modified:
oodt/trunk/profile/pom.xml
Modified: oodt/trunk/profile/pom.xml
URL:
http://svn.apache.org/viewvc/oodt/trunk/profile/pom.xml?rev=1648419&r1=1648418&r2=1648419&view=diff
==============================================================================
--- oodt/trunk/profile/pom.xml (original)
+++ oodt/trunk/profile/pom.xml Mon Dec 29 20:35:23 2014
@@ -19,7 +19,7 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.oodt</groupId>
- <artifactId>oodt-core</artifactId>
+ <artifactId>oodt-core</artifactId
<version>0.9-SNAPSHOT</version>
<relativePath>../core/pom.xml</relativePath>
</parent>
@@ -42,23 +42,6 @@
<directory>${basedir}/src/main/dtd</directory>
</resource>
</resources>
- <testResources>
- <testResource>
- <targetPath>org/apache/oodt/profile</targetPath>
- <directory>${basedir}/src/testdata</directory>
- <includes>
- <include>test.rdf</include>
- <include>test.xml</include>
- </includes>
- </testResource>
- <testResource>
- <targetPath>org/apache/oodt/profile/handlers/lightweight</targetPath>
- <directory>${basedir}/src/testdata</directory>
- <includes>
- <include>lightweightTest.xml</include>
- </includes>
- </testResource>
- </testResources>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
Added:
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/EnumeratedProfileElementTest.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/profile/src/test/java/org/apache/oodt/profile/EnumeratedProfileElementTest.java?rev=1648419&view=auto
==============================================================================
---
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/EnumeratedProfileElementTest.java
(added)
+++
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/EnumeratedProfileElementTest.java
Mon Dec 29 20:35:23 2014
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.oodt.profile;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.xml.sax.SAXException;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import org.apache.oodt.commons.io.NullOutputStream;
+import org.apache.oodt.commons.util.XML;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * Unit test the {@link EnumeratedProfileElement} class.
+ *
+ * @author Kelly
+ */
+public class EnumeratedProfileElementTest extends ProfileElementTestCase {
+ /**
+ * Construct the test case for the {@link EnumeratedProfileElement}
class.
+ */
+ public EnumeratedProfileElementTest(String name) {
+ super(name);
+ }
+
+ protected ProfileElement createProfileElement() {
+ return new EnumeratedProfileElement(ProfileTest.TEST_PROFILE,
"name", "id", "desc", "type", "unit",
+ /*synonyms*/ new ArrayList(), /*obligation*/false,
/*maxOccurrence*/1, "comment", VALUES);
+ }
+
+ public void testIt() {
+ ProfileElement element = createProfileElement();
+ List values = element.getValues();
+ assertEquals(3, values.size());
+ assertEquals("1", values.get(0));
+ assertEquals("2", values.get(1));
+ assertEquals("3", values.get(2));
+ }
+
+ public void testNulls() {
+ try {
+ EnumeratedProfileElement element = new
EnumeratedProfileElement(createProfileElement().getProfile(),
+ "test", "test", "test", "test", "test",
Collections.EMPTY_LIST, /*obligation*/true, /*maxOccur*/1,
+ "comment", Collections.singletonList(null));
+ fail("Null values must not be allowed as values in
enumerated elements.");
+ } catch (IllegalArgumentException good) {}
+ }
+
+ protected void checkEnumFlag(String text) {
+ assertEquals("T", text);
+ }
+
+ protected void checkValue(String text) {
+ assertTrue(VALUES.contains(text));
+ }
+
+ protected void checkMaxValue(String text) {
+ fail("Enumerated profile element shouldn't have a maximum
value");
+ }
+
+ protected void checkMinValue(String text) {
+ fail("Enumerated profile element shouldn't have a minimum
value");
+ }
+
+ /**
+ * Test to see if spaces are preserved in XML generation and parsing.
+ *
+ * @throws SAXException if an error occurs.
+ */
+ public void testSpacePreserving() throws SAXException {
+ Profile p = new Profile();
+ ProfileAttributes pa = new ProfileAttributes("1", "1",
"profile", "active", "1", "1",
+ /*children*/Collections.EMPTY_LIST, "1",
/*revNotes*/Collections.EMPTY_LIST);
+ p.setProfileAttributes(pa);
+ ResourceAttributes ra = new ResourceAttributes(p, "id",
"title", /*formats*/Collections.EMPTY_LIST, "description",
+ /*creators*/Collections.EMPTY_LIST,
/*subjects*/Collections.EMPTY_LIST, /*publishers*/Collections.EMPTY_LIST,
+ /*contributors*/Collections.EMPTY_LIST,
/*dates*/Collections.EMPTY_LIST, /*types*/Collections.EMPTY_LIST,
+ /*sources*/Collections.EMPTY_LIST,
/*languages*/Collections.EMPTY_LIST, /*relations*/Collections.EMPTY_LIST,
+ /*coverages*/Collections.EMPTY_LIST,
/*rights*/Collections.EMPTY_LIST, Collections.singletonList("context"),
+ "granule", "grainy",
Collections.singletonList("file:/dev/null"));
+ p.setResourceAttributes(ra);
+ EnumeratedProfileElement e = new EnumeratedProfileElement(p,
"mode", "mode", "Mode", "string", "mode",
+ /*synonyms*/Collections.EMPTY_LIST,
/*obligation*/false, /*maxOccurrence*/1, "No comment",
+ Collections.singletonList("The current\n mode setting\n
is set to indent\n\n a\n\n"
+ + " number of increasing\n times."));
+ p.getProfileElements().put("mode", e);
+
+ Profile q = new Profile(p.toString());
+ e = (EnumeratedProfileElement)
q.getProfileElements().values().iterator().next();
+ assertEquals("The current\n mode setting\n is set to
indent\n\n a\n\n"
+ + " number of increasing\n times.",
e.getValues().get(0));
+ }
+
+ public void testXMLSerialization() throws Exception {
+ Profile p = new Profile();
+ EnumeratedProfileElement e = new EnumeratedProfileElement(p);
+ Document doc = XML.createDocument();
+ Node root = e.toXML(doc);
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer t = tf.newTransformer();
+ DOMSource s = new DOMSource(root);
+ StreamResult r = new StreamResult(new NullOutputStream());
+ t.transform(s, r);
+ }
+
+ /** Enumerated values for the test element. */
+ private static final List VALUES = Arrays.asList(new String[]{"1", "2",
"3"});
+}
Added:
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ProfileAttributesTest.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ProfileAttributesTest.java?rev=1648419&view=auto
==============================================================================
---
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ProfileAttributesTest.java
(added)
+++
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ProfileAttributesTest.java
Mon Dec 29 20:35:23 2014
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.oodt.profile;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import org.apache.oodt.commons.io.NullOutputStream;
+import org.apache.oodt.commons.util.XML;
+import junit.framework.TestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Unit test the {@link ProfileAttributes} class.
+ *
+ * @author Kelly
+ */
+public class ProfileAttributesTest extends TestCase {
+ /** Construct the test case for the {@link ProfileAttributes} class. */
+ public ProfileAttributesTest(String name) {
+ super(name);
+ }
+
+ public void testNoArgsCtor() {
+ ProfileAttributes blank = new ProfileAttributes();
+ assertEquals("UNKNOWN", blank.getID());
+ assertEquals(0, blank.getChildren().size());
+ }
+
+ public void testCtor() {
+ assertEquals("id", TEST_PROFILE_ATTRIBUTES.getID());
+ assertEquals("version", TEST_PROFILE_ATTRIBUTES.getVersion());
+ assertEquals("type", TEST_PROFILE_ATTRIBUTES.getType());
+ assertEquals("statusID", TEST_PROFILE_ATTRIBUTES.getStatusID());
+ assertEquals("securityType",
TEST_PROFILE_ATTRIBUTES.getSecurityType());
+ assertEquals("parent", TEST_PROFILE_ATTRIBUTES.getParent());
+ assertEquals(2, TEST_PROFILE_ATTRIBUTES.getChildren().size());
+ assertEquals("child1",
TEST_PROFILE_ATTRIBUTES.getChildren().get(0));
+ assertEquals("child2",
TEST_PROFILE_ATTRIBUTES.getChildren().get(1));
+ assertEquals("regAuthority",
TEST_PROFILE_ATTRIBUTES.getRegAuthority());
+ assertEquals(2,
TEST_PROFILE_ATTRIBUTES.getRevisionNotes().size());
+ assertEquals("note1",
TEST_PROFILE_ATTRIBUTES.getRevisionNotes().get(0));
+ assertEquals("note2",
TEST_PROFILE_ATTRIBUTES.getRevisionNotes().get(1));
+ }
+
+ public void testObjectMethods() {
+ ProfileAttributes q1 = new ProfileAttributes("1", "2", "3",
"4", "5", "6", Collections.EMPTY_LIST, "7",
+ Collections.EMPTY_LIST);
+ ProfileAttributes q2 = new ProfileAttributes("1", "2", "3",
"4", "5", "6", Collections.EMPTY_LIST, "7",
+ Collections.EMPTY_LIST);
+ ProfileAttributes q3 = new ProfileAttributes("2", "3", "4",
"5", "6", "7", Collections.EMPTY_LIST, "8",
+ Collections.EMPTY_LIST);
+ assertEquals(q1, q1);
+ assertEquals(q1, q2);
+ assertTrue(!q1.equals(q3));
+ ProfileAttributes q4 = (ProfileAttributes) q3.clone();
+ assertEquals(q3, q4);
+ assertTrue(q3 != q4);
+ }
+
+ public void testSetters() {
+ ProfileAttributes q = (ProfileAttributes)
TEST_PROFILE_ATTRIBUTES.clone();
+
+ assertEquals("id", q.getID());
+ q.setID("newId");
+ assertEquals("newId", q.getID());
+
+ assertEquals("version", q.getVersion());
+ q.setVersion("newVersion");
+ assertEquals("newVersion", q.getVersion());
+
+ assertEquals("type", q.getType());
+ q.setType("newType");
+ assertEquals("newType", q.getType());
+
+ assertEquals("statusID", q.getStatusID());
+ q.setStatusID("newStatusid");
+ assertEquals("newStatusid", q.getStatusID());
+
+ assertEquals("securityType", q.getSecurityType());
+ q.setSecurityType("newSecuritytype");
+ assertEquals("newSecuritytype", q.getSecurityType());
+
+ assertEquals("regAuthority", q.getRegAuthority());
+ q.setRegAuthority("newRegAuthority");
+ assertEquals("newRegAuthority", q.getRegAuthority());
+ }
+
+ public void testXML() throws Exception {
+ Document doc = XML.createDocument();
+ Node root = TEST_PROFILE_ATTRIBUTES.toXML(doc);
+ assertEquals("profAttributes", root.getNodeName());
+ NodeList children = root.getChildNodes();
+ for (int i = 0; i < children.getLength(); ++i) {
+ Node child = children.item(i);
+ String name = child.getNodeName();
+ if ("profId".equals(name)) {
+ assertEquals("id", XML.text(child));
+ } else if ("profVersion".equals(name)) {
+ assertEquals("version", XML.text(child));
+ } else if ("profType".equals(name)) {
+ assertEquals("type", XML.text(child));
+ } else if ("profStatusId".equals(name)) {
+ assertEquals("statusID", XML.text(child));
+ } else if ("profSecurityType".equals(name)) {
+ assertEquals("securityType", XML.text(child));
+ } else if ("profParentId".equals(name)) {
+ assertEquals("parent", XML.text(child));
+ } else if ("profChildId".equals(name)) {
+ ; // ignore, list serialization tested in
XMLTest
+ } else if ("profRegAuthority".equals(name)) {
+ assertEquals("regAuthority", XML.text(child));
+ } else if ("profRevisionNote".equals(name)) {
+ ; // ignore, list serialization tested in
XMLTest
+ } else fail("Unknown node \"" + name + "\" in XML
result");
+ }
+ ProfileAttributes p = new ProfileAttributes(root);
+ assertEquals(TEST_PROFILE_ATTRIBUTES, p);
+ }
+
+ public void testXMLSerialization() throws Exception {
+ ProfileAttributes p = new ProfileAttributes();
+ Document doc = XML.createDocument();
+ Node root = p.toXML(doc);
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer t = tf.newTransformer();
+ DOMSource s = new DOMSource(root);
+ StreamResult r = new StreamResult(new NullOutputStream());
+ t.transform(s, r);
+ }
+
+ static final ProfileAttributes TEST_PROFILE_ATTRIBUTES;
+
+ static {
+ List parents = Collections.singletonList("parent");
+ List children = new ArrayList();
+ children.add("child1");
+ children.add("child2");
+ List revisionNotes = new ArrayList();
+ revisionNotes.add("note1");
+ revisionNotes.add("note2");
+ TEST_PROFILE_ATTRIBUTES = new ProfileAttributes("id",
"version", "type", "statusID",
+ "securityType", "parent", children, "regAuthority",
revisionNotes);
+ }
+}
Added:
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ProfileElementTestCase.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ProfileElementTestCase.java?rev=1648419&view=auto
==============================================================================
---
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ProfileElementTestCase.java
(added)
+++
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ProfileElementTestCase.java
Mon Dec 29 20:35:23 2014
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.oodt.profile;
+
+import junit.framework.TestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.apache.oodt.commons.util.XML;
+
+/**
+ * Test case for profile elements.
+ *
+ * @author Kelly
+ */
+public abstract class ProfileElementTestCase extends TestCase {
+ /** Construct the test case for the {@link ProfileElement} superclass.
*/
+ public ProfileElementTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * Create a profile element object to test.
+ *
+ * The element returned must have as its owning profile the
+ * <code>ProfileTest.TEST_PROFILE</code>, be named "name", have "id" as
its ID,
+ * have "desc" as its description, must be of type "type", have "unit"
units, have
+ * no synonyms, not be obligatory, may occur once, and have "comment"
as its
+ * comment.
+ *
+ * @return A profile element.
+ */
+ protected abstract ProfileElement createProfileElement();
+
+ /**
+ * Check if the given enumeration flag is valid.
+ *
+ * This method merely asserts that it's valid for the profile element
in question.
+ *
+ * @param text Text to check.
+ */
+ protected abstract void checkEnumFlag(String text);
+
+ /**
+ * Check that the given value is valid.
+ *
+ * This method merely asserts that it's valid for the profile element
in question.
+ *
+ * @param text Text to check.
+ */
+ protected abstract void checkValue(String text);
+
+ /**
+ * Check that the given maximum value is valid.
+ *
+ * This method merely asserts that it's valid for the profile element
in question.
+ *
+ * @param text Text to check.
+ */
+ protected abstract void checkMaxValue(String text);
+
+ /**
+ * Check that the given minimum value is valid.
+ *
+ * This method merely asserts that it's valid for the profile element
in question.
+ *
+ * @param text Text to check.
+ */
+ protected abstract void checkMinValue(String text);
+
+ public void testCharacteristics() {
+ ProfileElement element = createProfileElement();
+ assertEquals(ProfileTest.TEST_PROFILE, element.getProfile());
+
+ assertEquals("name", element.getName());
+ element.setName("newName");
+ assertEquals("newName", element.getName());
+
+ assertEquals("id", element.getID());
+ element.setID("newID");
+ assertEquals("newID", element.getID());
+
+ assertEquals("desc", element.getDescription());
+ element.setDescription("newDesc");
+ assertEquals("newDesc", element.getDescription());
+
+ assertEquals("type", element.getType());
+ element.setType("newType");
+ assertEquals("newType", element.getType());
+
+ assertEquals("unit", element.getUnit());
+ element.setUnit("newUnit");
+ assertEquals("newUnit", element.getUnit());
+
+ assertEquals(0, element.getSynonyms().size());
+ element.getSynonyms().add("synonym");
+ assertEquals(1, element.getSynonyms().size());
+ assertEquals("synonym", element.getSynonyms().get(0));
+
+ assertTrue(!element.isObligatory());
+ element.setObligation(true);
+ assertTrue(element.isObligatory());
+
+ assertEquals(1, element.getMaxOccurrence());
+ element.setMaxOccurrence(2);
+ assertEquals(2, element.getMaxOccurrence());
+
+ assertEquals("comment", element.getComments());
+ element.setComments("newComment");
+ assertEquals("newComment", element.getComments());
+ }
+
+ public void testObjectMethods() {
+ ProfileElement elem1 = createProfileElement();
+ ProfileElement elem2 = createProfileElement();
+ ProfileElement elem3 = createProfileElement();
+ elem3.setName("newName");
+ assertEquals(elem1, elem1);
+ assertEquals(elem1, elem2);
+ assertTrue(!elem1.equals(elem3));
+ ProfileElement elem4 = (ProfileElement) elem3.clone();
+ assertEquals(elem3, elem4);
+ assertTrue(elem3 != elem4);
+ }
+
+ public void testXML() {
+ ProfileElement element = createProfileElement();
+ Document doc = XML.createDocument();
+ Node root = element.toXML(doc);
+ assertEquals("profElement", root.getNodeName());
+ NodeList children = root.getChildNodes();
+ boolean foundName = false;
+ boolean foundEnumFlag = false;
+ for (int i = 0; i < children.getLength(); ++i) {
+ Node child = children.item(i);
+ String name = child.getNodeName();
+ String text = ProfileElement.text(child);
+ if ("elemId".equals(name)) {
+ assertEquals("id", text);
+ } else if ("elemName".equals(name)) {
+ assertEquals("name", text);
+ foundName = true;
+ } else if ("elemDesc".equals(name)) {
+ assertEquals("desc", text);
+ } else if ("elemType".equals(name)) {
+ assertEquals("type", text);
+ } else if ("elemUnit".equals(name)) {
+ assertEquals("unit", text);
+ } else if ("elemEnumFlag".equals(name)) {
+ checkEnumFlag(text);
+ foundEnumFlag = true;
+ } else if ("elemValue".equals(name)) {
+ checkValue(text);
+ } else if ("elemMinValue".equals(name)) {
+ checkMinValue(text);
+ } else if ("elemMaxValue".equals(name)) {
+ checkMaxValue(text);
+ } else if ("elemSynonym".equals(name)) {
+ ; // ignore
+ } else if ("elemObligation".equals(name)) {
+ assertEquals("Optional", text);
+ } else if ("elemMaxOccurrence".equals(name)) {
+ assertEquals("1", text);
+ } else if ("elemComment".equals(name)) {
+ assertEquals("comment", text);
+ } else fail("Unknown node <" + name + "> under
<profElement>");
+ }
+ assertTrue("Required <elemName> missing", foundName);
+ assertTrue("Required <elemEnumFlag> missing", foundEnumFlag);
+ }
+}
Added: oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ProfileTest.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ProfileTest.java?rev=1648419&view=auto
==============================================================================
--- oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ProfileTest.java
(added)
+++ oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ProfileTest.java
Mon Dec 29 20:35:23 2014
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.oodt.profile;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.util.Map;
+import org.apache.oodt.commons.util.XML;
+import junit.framework.TestCase;
+import org.w3c.dom.Document;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Resource;
+import java.io.FileWriter;
+import java.io.IOException;
+
+/**
+ * Unit test the Profile class.
+ *
+ * @author Kelly
+ */
+public class ProfileTest extends TestCase {
+ /** Construct the test case for the Profile class. */
+ public ProfileTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ oldProfNS = System.getProperty("jpl.rdf.ns");
+ System.setProperty("jpl.rdf.ns",
"http://enterprise.jpl.nasa.gov/rdfs/prof.rdf#");
+
+ StringBuffer buffer = new StringBuffer("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n");
+ buffer.append("<!DOCTYPE profile PUBLIC
\"").append(Profile.PROFILES_DTD_FPI).append("\" \"")
+ .append(Profile.PROFILES_DTD_URL).append("\">\n");
+ BufferedReader reader = new BufferedReader(new
InputStreamReader(getClass().getResourceAsStream("test.xml")));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ buffer.append(line);
+ buffer.append('\n');
+ }
+ reader.close();
+ Document doc = XML.parse(buffer.toString());
+ profile1 = new Profile(buffer.toString());
+ profile2 = new Profile(doc.getDocumentElement());
+ }
+
+ protected void tearDown() throws Exception {
+ if (oldProfNS != null)
+ System.setProperty("jpl.rdf.ns", oldProfNS);
+ else
+ System.getProperties().remove("jpl.rdf.ns");
+ }
+
+ public void testQueries() {
+ // We test both profile1 (built from a string) and profile2
(from an XML
+ // document node); they should yield the same results because
they
+ // represent the same document.
+
+ // Test the getResourceAttribute method.
+ assertEquals("PDS_PROFILE_SERVER",
profile1.getResourceAttributes().getIdentifier());
+ assertEquals("PDS_PROFILE_SERVER",
profile2.getResourceAttributes().getIdentifier());
+ assertEquals("text/html",
profile1.getResourceAttributes().getFormats().get(0));
+ assertEquals("text/html",
profile2.getResourceAttributes().getFormats().get(0));
+
+ // Test the getProfileID method.
+ assertEquals("OODT_PDS_PROFILE_SERVER",
profile1.getProfileAttributes().getID());
+ assertEquals("OODT_PDS_PROFILE_SERVER",
profile2.getProfileAttributes().getID());
+
+ // Test the getProfileAttribute method
+ assertEquals("profile",
profile1.getProfileAttributes().getType());
+ assertEquals("profile",
profile2.getProfileAttributes().getType());
+ assertEquals("NULL",
profile1.getProfileAttributes().getSecurityType());
+ assertEquals("NULL",
profile2.getProfileAttributes().getSecurityType());
+
+ // Test the getProfileElementItem method.
+ Map elements1 = profile1.getProfileElements();
+ Map elements2 = profile2.getProfileElements();
+ assertEquals(3, elements1.size());
+ assertEquals(3, elements2.size());
+ assertTrue(elements1.containsKey("TEST"));
+ assertTrue(elements2.containsKey("TEST"));
+ assertTrue(!elements1.containsKey("does-not-exist"));
+ assertTrue(!elements2.containsKey("does-not-exist"));
+ ProfileElement element1 = (ProfileElement)
elements1.get("TEST2");
+ ProfileElement element2 = (ProfileElement)
elements2.get("TEST2");
+ assertEquals("Testing", element1.getType());
+ assertEquals("Testing", element2.getType());
+
+ // Test the toString and getProfileString methods ... NB: this
test should
+ // actually check value, not just see if they're equal.
+ assertEquals(profile1.toString(), profile2.toString());
+
+ // Test some miscellaneous query methods
+ assertEquals("Planetary Data System (PDS) - Profile Server
V1.0", profile1.getResourceAttributes().getTitle());
+ assertEquals("iiop://oodt.jpl.nasa.gov:10000/JPL.PDS.PROFILE",
profile1.getResourceAttributes().getResLocations()
+ .get(0));
+ assertEquals("system.profileServer",
profile1.getResourceAttributes().getResClass());
+ assertEquals("Planetary Data System (PDS) - Profile Server
V1.0", profile2.getResourceAttributes().getTitle());
+ assertEquals("iiop://oodt.jpl.nasa.gov:10000/JPL.PDS.PROFILE",
profile2.getResourceAttributes().getResLocations()
+ .get(0));
+ assertEquals("system.profileServer",
profile2.getResourceAttributes().getResClass());
+ }
+
+ /** A test profile, built from a string. */
+ private Profile profile1;
+
+ /** Another test profile, built from an XML document node. */
+ private Profile profile2;
+
+ /** Previous value of the JPL RDF namespace in the system properties. */
+ private String oldProfNS;
+
+ /** Another (static) test profile, for use by other test cases. */
+ static Profile TEST_PROFILE = new
Profile(ProfileAttributesTest.TEST_PROFILE_ATTRIBUTES,
+ ResourceAttributesTest.TEST_RESOURCE_ATTRIBUTES);
+}
Added:
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/RangedProfileElementTest.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/profile/src/test/java/org/apache/oodt/profile/RangedProfileElementTest.java?rev=1648419&view=auto
==============================================================================
---
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/RangedProfileElementTest.java
(added)
+++
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/RangedProfileElementTest.java
Mon Dec 29 20:35:23 2014
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.oodt.profile;
+
+import java.util.ArrayList;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import org.apache.oodt.commons.io.NullOutputStream;
+import org.apache.oodt.commons.util.XML;
+import junit.framework.TestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * Unit test the {@link RangedProfileElement} class.
+ *
+ * @author Kelly
+ */
+public class RangedProfileElementTest extends ProfileElementTestCase {
+ /** Construct the test case for the {@link RangedProfileElement} class.
*/
+ public RangedProfileElementTest(String name) {
+ super(name);
+ }
+
+ protected ProfileElement createProfileElement() {
+ return new RangedProfileElement(ProfileTest.TEST_PROFILE,
"name", "id", "desc", "type", "unit",
+ /*synonyms*/ new ArrayList(), /*obligation*/false,
/*maxOccurrence*/1, "comment", /*min*/"-100.0",
+ /*max*/"100.0");
+ }
+
+ public void testIt() {
+ ProfileElement element = createProfileElement();
+ assertEquals("100.0", element.getMaxValue());
+ assertEquals("-100.0", element.getMinValue());
+ assertEquals(0, element.getValues().size());
+ }
+
+ public void testXMLSerialization() throws Exception {
+ Profile p = new Profile();
+ RangedProfileElement e = new RangedProfileElement(p);
+ Document doc = XML.createDocument();
+ Node root = e.toXML(doc);
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer t = tf.newTransformer();
+ DOMSource s = new DOMSource(root);
+ StreamResult r = new StreamResult(new NullOutputStream());
+ t.transform(s, r);
+ }
+
+ protected void checkEnumFlag(String text) {
+ assertEquals("F", text);
+ }
+
+ protected void checkValue(String text) {
+ fail("Ranged profile element shouldn't have an enumerated
value");
+ }
+
+ protected void checkMaxValue(String text) {
+ assertEquals("100.0", text);
+ }
+
+ protected void checkMinValue(String text) {
+ assertEquals("-100.0", text);
+ }
+}
Added:
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ResourceAttributesTest.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ResourceAttributesTest.java?rev=1648419&view=auto
==============================================================================
---
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ResourceAttributesTest.java
(added)
+++
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/ResourceAttributesTest.java
Mon Dec 29 20:35:23 2014
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.oodt.profile;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import org.apache.oodt.commons.io.NullOutputStream;
+import org.apache.oodt.commons.util.XML;
+import junit.framework.TestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Unit test the {@link ResourceAttributes} class.
+ *
+ * @author Kelly
+ */
+public class ResourceAttributesTest extends TestCase {
+ /** Construct the test case for the {@link ResourceAttributes} class. */
+ public ResourceAttributesTest(String name) {
+ super(name);
+ }
+
+ public void testNoArgsCtor() {
+ ResourceAttributes blank = new ResourceAttributes();
+ assertEquals("UNKNOWN", blank.getIdentifier());
+ assertEquals(0, blank.getFormats().size());
+ assertEquals(0, blank.getCreators().size());
+ assertEquals(0, blank.getSubjects().size());
+ assertEquals(0, blank.getPublishers().size());
+ assertEquals(0, blank.getContributors().size());
+ assertEquals(0, blank.getDates().size());
+ assertEquals(0, blank.getTypes().size());
+ assertEquals(0, blank.getSources().size());
+ assertEquals(0, blank.getLanguages().size());
+ assertEquals(0, blank.getRelations().size());
+ assertEquals(0, blank.getCoverages().size());
+ assertEquals(0, blank.getRights().size());
+ assertEquals(0, blank.getResContexts().size());
+ assertEquals(0, blank.getResLocations().size());
+ }
+
+ public void testObjectMethods() {
+ List contexts = new ArrayList();
+ contexts.add("context");
+ ResourceAttributes r1 = new ResourceAttributes(null, "1",
"title", Collections.EMPTY_LIST, "desc",
+ Collections.EMPTY_LIST, Collections.EMPTY_LIST,
Collections.EMPTY_LIST,
+ Collections.EMPTY_LIST, Collections.EMPTY_LIST,
Collections.EMPTY_LIST, Collections.EMPTY_LIST,
+ Collections.EMPTY_LIST, Collections.EMPTY_LIST,
Collections.EMPTY_LIST, Collections.EMPTY_LIST,
+ contexts, "aggregation", "class",
Collections.EMPTY_LIST);
+ ResourceAttributes r2 = new ResourceAttributes(null, "1",
"title", Collections.EMPTY_LIST, "desc",
+ Collections.EMPTY_LIST, Collections.EMPTY_LIST,
Collections.EMPTY_LIST,
+ Collections.EMPTY_LIST, Collections.EMPTY_LIST,
Collections.EMPTY_LIST, Collections.EMPTY_LIST,
+ Collections.EMPTY_LIST, Collections.EMPTY_LIST,
Collections.EMPTY_LIST, Collections.EMPTY_LIST,
+ contexts, "aggregation", "class",
Collections.EMPTY_LIST);
+ ResourceAttributes r3 = new ResourceAttributes(null, "2",
"title2", Collections.EMPTY_LIST, "desc2",
+ Collections.EMPTY_LIST, Collections.EMPTY_LIST,
Collections.EMPTY_LIST,
+ Collections.EMPTY_LIST, Collections.EMPTY_LIST,
Collections.EMPTY_LIST, Collections.EMPTY_LIST,
+ Collections.EMPTY_LIST, Collections.EMPTY_LIST,
Collections.EMPTY_LIST, Collections.EMPTY_LIST,
+ contexts, "aggregation2", "class2",
Collections.EMPTY_LIST);
+ assertEquals(r1, r1);
+ assertEquals(r1, r2);
+ assertTrue(!r1.equals(r3));
+ ResourceAttributes r4 = (ResourceAttributes) r3.clone();
+ assertEquals(r3, r4);
+ assertTrue(r3 != r4);
+ }
+
+ public void testSetters() {
+ ResourceAttributes q = (ResourceAttributes)
TEST_RESOURCE_ATTRIBUTES.clone();
+
+ assertEquals("identifier", q.getIdentifier());
+ q.setIdentifier("newIdentifier");
+ assertEquals("newIdentifier", q.getIdentifier());
+
+ assertEquals("aggregation", q.getResAggregation());
+ q.setResAggregation("newAggergation");
+ assertEquals("newAggergation", q.getResAggregation());
+
+ assertEquals("class", q.getResClass());
+ q.setResClass("newClass");
+ assertEquals("newClass", q.getResClass());
+ }
+
+ public void testXML() throws Exception {
+ Document doc = XML.createDocument();
+ Node root = TEST_RESOURCE_ATTRIBUTES.toXML(doc);
+ assertEquals("resAttributes", root.getNodeName());
+ NodeList children = root.getChildNodes();
+ for (int i = 0; i < children.getLength(); ++i) {
+ Node child = children.item(i);
+ String name = child.getNodeName();
+ if ("Identifier".equals(name)) {
+ assertEquals("identifier", XML.text(child));
+ } else if ("Title".equals(name)) {
+ assertEquals("title", XML.text(child));
+ } else if ("Format".equals(name)) {
+ ; // ignore
+ } else if ("Description".equals(name)) {
+ assertEquals("desc", XML.text(child));
+ } else if ("Creator".equals(name)) {
+ ; // ignore
+ } else if ("Subject".equals(name)) {
+ ; // ignore
+ } else if ("Publisher".equals(name)) {
+ ; // ignore
+ } else if ("Contributor".equals(name)) {
+ ; // ignore
+ } else if ("Date".equals(name)) {
+ ; // ignore
+ } else if ("Type".equals(name)) {
+ ; // ignore
+ } else if ("Source".equals(name)) {
+ ; // ignore
+ } else if ("Language".equals(name)) {
+ ; // ignore
+ } else if ("Coverage".equals(name)) {
+ ; // ignore
+ } else if ("Rights".equals(name)) {
+ ; // ignore
+ } else if ("resContext".equals(name)) {
+ assertEquals("context", XML.text(child));
+ } else if ("resAggregation".equals(name)) {
+ assertEquals("aggregation", XML.text(child));
+ } else if ("resClass".equals(name)) {
+ assertEquals("class", XML.text(child));
+ } else if ("resLocation".equals(name)) {
+ ; // ignore
+ } else fail("Unknown node \"" + name + "\" in XML
result");
+ }
+ ResourceAttributes q = new ResourceAttributes(null, root);
+ assertEquals(TEST_RESOURCE_ATTRIBUTES, q);
+ }
+
+ public void testXMLSerialization() throws Exception {
+ Profile p = new Profile();
+ ResourceAttributes ra = new ResourceAttributes(p);
+ Document doc = XML.createDocument();
+ Node root = ra.toXML(doc);
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer t = tf.newTransformer();
+ DOMSource s = new DOMSource(root);
+ StreamResult r = new StreamResult(new NullOutputStream());
+ t.transform(s, r);
+ }
+
+ static ResourceAttributes TEST_RESOURCE_ATTRIBUTES; {
+ List contexts = Collections.singletonList("context");
+ List locations = Collections.singletonList("location");
+ TEST_RESOURCE_ATTRIBUTES = new ResourceAttributes(null,
"identifier", "title",
+ Collections.EMPTY_LIST, "desc", Collections.EMPTY_LIST,
Collections.EMPTY_LIST,
+ Collections.EMPTY_LIST, Collections.EMPTY_LIST,
Collections.EMPTY_LIST, Collections.EMPTY_LIST,
+ Collections.EMPTY_LIST, Collections.EMPTY_LIST,
Collections.EMPTY_LIST, Collections.EMPTY_LIST,
+ Collections.EMPTY_LIST, contexts, "aggregation",
"class", locations);
+ }
+}
Added:
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/handlers/lightweight/LightweightProfileServerTest.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/profile/src/test/java/org/apache/oodt/profile/handlers/lightweight/LightweightProfileServerTest.java?rev=1648419&view=auto
==============================================================================
---
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/handlers/lightweight/LightweightProfileServerTest.java
(added)
+++
oodt/trunk/profile/src/test/java/org/apache/oodt/profile/handlers/lightweight/LightweightProfileServerTest.java
Mon Dec 29 20:35:23 2014
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.oodt.profile.handlers.lightweight;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import org.apache.oodt.commons.util.SAXParser;
+import org.apache.oodt.commons.util.XML;
+import org.apache.oodt.profile.ProfileElement;
+import org.apache.oodt.profile.ProfileException;
+import org.apache.oodt.xmlquery.XMLQuery;
+import junit.framework.TestCase;
+import org.w3c.dom.Document;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * Unit test the LightweightProfileServer class.
+ *
+ * @author Kelly
+ */
+public class LightweightProfileServerTest extends TestCase {
+ /** Construct the test case for the LightweightProfileServer class. */
+ public LightweightProfileServerTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ server = new
LightweightProfileServer(getClass().getResource("lightweightTest.xml"),
"testing");
+ }
+
+ /**
+ * Test the getID method.
+ */
+ public void testGetID() {
+ assertEquals("testing", server.getID());
+ }
+
+ /**
+ * Test the searching methods.
+ */
+ public void testSearching() {
+ try {
+ List profiles;
+
+ // Try a positive search.
+ profiles = doSearch("TEST > 2 AND TEST < 30");
+ assertEquals(1, profiles.size());
+ SearchableProfile profile = (SearchableProfile)
profiles.get(0);
+ assertEquals("PROFILE1",
profile.getProfileAttributes().getID());
+ Map elements = profile.getProfileElements();
+ assertEquals(3, elements.size());
+ ProfileElement element = (ProfileElement)
elements.get("TEST");
+ assertNotNull(element);
+ assertEquals("3.14159", element.getID());
+
+ // Now a negative one.
+ profiles = doSearch("NONEXISTENT =
452712917824812123125100884");
+ assertEquals(0, profiles.size());
+
+ // Now one that has multiple elements from one profile
+ profiles = doSearch("TEST <= 14 AND TEST2 >= 10");
+ assertEquals(1, profiles.size());
+ profile = (SearchableProfile) profiles.get(0);
+ assertEquals("PROFILE1",
profile.getProfileAttributes().getID());
+ elements = profile.getProfileElements();
+ assertEquals(3, elements.size());
+ assertTrue(elements.containsKey("TEST"));
+ assertTrue(elements.containsKey("TEST2"));
+
+ // And again, but with OR instead of AND
+ profiles = doSearch("TEST <= 14 OR TEST2 >= 10");
+ assertEquals(1, profiles.size());
+ profile = (SearchableProfile) profiles.get(0);
+ assertEquals("PROFILE1",
profile.getProfileAttributes().getID());
+ elements = profile.getProfileElements();
+ assertEquals(3, elements.size());
+ assertTrue(elements.containsKey("TEST"));
+ assertTrue(elements.containsKey("TEST2"));
+
+ // And again, but with one of the elements being not
found
+ profiles = doSearch("NONEXISTENT = 123456789 OR TEST2
<= 1000000");
+ assertEquals(1, profiles.size());
+ profile = (SearchableProfile) profiles.get(0);
+ assertEquals("PROFILE1",
profile.getProfileAttributes().getID());
+ elements = profile.getProfileElements();
+ assertEquals(3, elements.size());
+ assertTrue(elements.containsKey("TEST2"));
+
+ // And again, but spanning profiles
+ profiles = doSearch("TEST2 = 48 OR TEST4 = 192");
+ assertEquals(2, profiles.size());
+ for (Iterator i = profiles.iterator(); i.hasNext();) {
+ profile = (SearchableProfile) i.next();
+ elements = profile.getProfileElements();
+ assertEquals(3, elements.size());
+ if
(profile.getProfileAttributes().getID().equals("PROFILE1")) {
+
assertTrue(elements.containsKey("TEST2"));
+ } else if
(profile.getProfileAttributes().getID().equals("PROFILE2")) {
+
assertTrue(elements.containsKey("TEST4"));
+ } else fail("Profile \"" +
profile.getProfileAttributes().getID() + "\" matched, but shouldn't");
+ }
+
+ // And again, but with a query on the "from" part.
+ profiles = doSearch("( TEST2 = 48 OR TEST4 = 192 ) AND
Creator = Alice");
+ assertEquals(1, profiles.size());
+ profile = (SearchableProfile) profiles.get(0);
+ assertEquals("PROFILE1",
profile.getProfileAttributes().getID());
+
+ // And again, but on a nonenumerated element with no
min/max values.
+ profiles = doSearch("TEST5 = GEEBA");
+ assertEquals(1, profiles.size());
+ profile = (SearchableProfile) profiles.get(0);
+ assertEquals("PROFILE2",
profile.getProfileAttributes().getID());
+
+ // And again, but with "RETURN =" parts.
+ //fail("Not yet implemented");
+
+ } catch (ProfileException ex) {
+ fail("Profile server failed with excepton: " +
ex.getMessage());
+ }
+ }
+
+ /**
+ * Execute the given search.
+ *
+ * @param expr The search experssion.
+ * @return List of matching profiles.
+ * @throws ProfileException If the profile server fails.
+ */
+ private List doSearch(String expr) throws ProfileException {
+ XMLQuery query = new XMLQuery(expr, "test1",
"LightweightProfileServerTest",
+ "This query is to test the LightweightProfileServer",
/*ddId*/null, /*resultModeId*/null,
+ /*propType*/null, /*propLevels*/null,
XMLQuery.DEFAULT_MAX_RESULTS);
+ return server.findProfiles(query);
+ }
+
+
+ /** The lightweight profile server being tested. */
+ private LightweightProfileServer server;
+}
Added: oodt/trunk/profile/src/test/resources/lightweightTest.xml
URL:
http://svn.apache.org/viewvc/oodt/trunk/profile/src/test/resources/lightweightTest.xml?rev=1648419&view=auto
==============================================================================
--- oodt/trunk/profile/src/test/resources/lightweightTest.xml (added)
+++ oodt/trunk/profile/src/test/resources/lightweightTest.xml Mon Dec 29
20:35:23 2014
@@ -0,0 +1,111 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright 2000-2002 California Institute of Technology. ALL RIGHTS
+RESERVED. U.S. Government Sponsorship acknowledged.
+
+$Id: lightweightTest.xml,v 1.2 2004/06/14 16:13:02 kelly Exp $
+-->
+<!DOCTYPE profiles PUBLIC "-//JPL//DTD EDA Profile 1.1//EN"
"http://oodt.jpl.nasa.gov/grid-profile/dtd/prof.dtd">
+<profiles>
+ <profile>
+ <profAttributes>
+ <profId>PROFILE1</profId>
+ <profType>profile</profType>
+ <profStatusId>active</profStatusId>
+ <profSecurityType>NULL</profSecurityType>
+ <profRevisionNote>1.0</profRevisionNote>
+ </profAttributes>
+ <resAttributes>
+ <Identifier>TEST_PROFILE_1</Identifier>
+ <Title>Test profile number 1</Title>
+ <Format>text/html</Format>
+ <Creator>Alice</Creator>
+ <resContext>TEST</resContext>
+ <resAggregation>N/A</resAggregation>
+ <resClass>system.profileServer</resClass>
+ <resLocation>iiop://oodt.jpl.nasa.gov:10000/Test.Profile</resLocation>
+ </resAttributes>
+ <profElement>
+ <elemId>3.14159</elemId>
+ <elemName>TEST</elemName>
+ <elemDesc>This is a test element</elemDesc>
+ <elemType>Testing</elemType>
+ <elemUnit>fortnights-per-furlong</elemUnit>
+ <elemEnumFlag>F</elemEnumFlag>
+ <elemMinValue>0</elemMinValue>
+ <elemMaxValue>32</elemMaxValue>
+ <elemComment>Testing only.</elemComment>
+ </profElement>
+ <profElement>
+ <elemId>3.2</elemId>
+ <elemName>TEST2</elemName>
+ <elemDesc>This is another test element</elemDesc>
+ <elemType>Testing</elemType>
+ <elemUnit>fleas-per-tick</elemUnit>
+ <elemEnumFlag>F</elemEnumFlag>
+ <elemMinValue>32</elemMinValue>
+ <elemMaxValue>64</elemMaxValue>
+ <elemComment>More testing.</elemComment>
+ </profElement>
+ <profElement>
+ <elemId>3.5</elemId>
+ <elemName>TEST3</elemName>
+ <elemDesc>Yet another test element</elemDesc>
+ <elemType>Testing</elemType>
+ <elemEnumFlag>T</elemEnumFlag>
+ <elemValue>alpha</elemValue>
+ <elemValue>beta</elemValue>
+ <elemValue>gamma</elemValue>
+ <elemValue>delta</elemValue>
+ <elemComment>A bunch of greek letters, eh?</elemComment>
+ </profElement>
+ </profile>
+
+ <profile>
+ <profAttributes>
+ <profId>PROFILE2</profId>
+ <profType>profile</profType>
+ <profStatusId>active</profStatusId>
+ <profSecurityType>NULL</profSecurityType>
+ <profRevisionNote>1.0</profRevisionNote>
+ </profAttributes>
+ <resAttributes>
+ <Identifier>TEST_PROFILE_2</Identifier>
+ <Title>Test profile number 2</Title>
+ <Format>text/html</Format>
+ <Creator>Bill</Creator>
+ <resContext>TEST</resContext>
+ <resAggregation>N/A</resAggregation>
+ <resClass>system.profileServer</resClass>
+ <resLocation>iiop://oodt.jpl.nasa.gov:10000/Test.Profile</resLocation>
+ </resAttributes>
+ <profElement>
+ <elemId>3.5</elemId>
+ <elemName>TEST3</elemName>
+ <elemDesc>Yet another test element</elemDesc>
+ <elemType>Testing</elemType>
+ <elemEnumFlag>T</elemEnumFlag>
+ <elemValue>alpha</elemValue>
+ <elemValue>beta</elemValue>
+ <elemValue>gamma</elemValue>
+ <elemValue>delta</elemValue>
+ <elemComment>A bunch of greek letters, eh?</elemComment>
+ </profElement>
+ <profElement>
+ <elemId>3.6</elemId>
+ <elemName>TEST4</elemName>
+ <elemDesc>And still another test element</elemDesc>
+ <elemType>Testing</elemType>
+ <elemEnumFlag>F</elemEnumFlag>
+ <elemMinValue>128</elemMinValue>
+ <elemMaxValue>256</elemMaxValue>
+ </profElement>
+ <profElement>
+ <elemId>3.7</elemId>
+ <elemName>TEST5</elemName>
+ <elemDesc>This is a nonenumerated field with no min/max values, meaning
it should always match.</elemDesc>
+ <elemType>char</elemType>
+ <elemEnumFlag>F</elemEnumFlag>
+ </profElement>
+ </profile>
+</profiles>
Added: oodt/trunk/profile/src/test/resources/test.xml
URL:
http://svn.apache.org/viewvc/oodt/trunk/profile/src/test/resources/test.xml?rev=1648419&view=auto
==============================================================================
--- oodt/trunk/profile/src/test/resources/test.xml (added)
+++ oodt/trunk/profile/src/test/resources/test.xml Mon Dec 29 20:35:23 2014
@@ -0,0 +1,57 @@
+<!-- DO NOT put the XML processing instruction or DOCTYPE decl in this -->
+<!-- file! They're added by the unit test automatically. -->
+<!-- Copyright 2000-2002 California Institute of Technology. ALL -->
+<!-- RIGHTS RESERVED. U.S. Government Sponsorship acknowledged. -->
+<!-- $Id: test.xml,v 1.1.1.1 2004/03/02 20:53:39 kelly Exp $ -->
+<profile>
+ <profAttributes>
+ <profId>OODT_PDS_PROFILE_SERVER</profId>
+ <profType>profile</profType>
+ <profStatusId>active</profStatusId>
+ <profSecurityType>NULL</profSecurityType>
+ <profRevisionNote>1999-09-30</profRevisionNote>
+ </profAttributes>
+ <resAttributes>
+ <Identifier>PDS_PROFILE_SERVER</Identifier>
+ <Title>Planetary Data System (PDS) - Profile Server V1.0</Title>
+ <Format>text/html</Format>
+ <resContext>PDS</resContext>
+ <resAggregation>N/A</resAggregation>
+ <resClass>system.profileServer</resClass>
+ <resLocation>iiop://oodt.jpl.nasa.gov:10000/JPL.PDS.PROFILE</resLocation>
+ </resAttributes>
+ <profElement>
+ <elemId>3.14159</elemId>
+ <elemName>TEST</elemName>
+ <elemDesc>This is a test element</elemDesc>
+ <elemType>Testing</elemType>
+ <elemUnit>fortnights-per-furlong</elemUnit>
+ <elemEnumFlag>F</elemEnumFlag>
+ <elemMinValue>0</elemMinValue>
+ <elemMaxValue>32</elemMaxValue>
+ <elemComment>Testing only.</elemComment>
+ </profElement>
+ <profElement>
+ <elemId>3.2</elemId>
+ <elemName>TEST2</elemName>
+ <elemDesc>This is another test element</elemDesc>
+ <elemType>Testing</elemType>
+ <elemUnit>fleas-per-tick</elemUnit>
+ <elemEnumFlag>F</elemEnumFlag>
+ <elemMinValue>32</elemMinValue>
+ <elemMaxValue>64</elemMaxValue>
+ <elemComment>More testing.</elemComment>
+ </profElement>
+ <profElement>
+ <elemId>3.5</elemId>
+ <elemName>TEST3</elemName>
+ <elemDesc>Yet another test element</elemDesc>
+ <elemType>Testing</elemType>
+ <elemEnumFlag>T</elemEnumFlag>
+ <elemValue>alpha</elemValue>
+ <elemValue>beta</elemValue>
+ <elemValue>gamma</elemValue>
+ <elemValue>delta</elemValue>
+ <elemComment>A bunch of greek letters, eh?</elemComment>
+ </profElement>
+</profile>