aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Terry2013-07-11 17:17:56 -0400
committerDavid Terry2013-07-11 17:26:08 -0400
commit9eb06465786cd6ce646269c2bacbb08f7a1f452f (patch)
tree941750c05e4988cd66a5da1cb9ef6107e27daa4d
parent7080de9b1abfc1ad002060121ea3248966b877a7 (diff)
downloadorg.eclipse.lyo.rio-9eb06465786cd6ce646269c2bacbb08f7a1f452f.zip
org.eclipse.lyo.rio-9eb06465786cd6ce646269c2bacbb08f7a1f452f.tar.gz
org.eclipse.lyo.rio-9eb06465786cd6ce646269c2bacbb08f7a1f452f.tar.xz
[412806] Refactor TRS reference application Junits to the Rio project
This change refactors two test classes from the testsuite repository into the Rio repository as they typically are run against the TRS reference application. Change-Id: I7456b812bf25fea37fd8863483b0a2f36430994f Signed-off-by: David Terry <dgterry@us.ibm.com>
-rw-r--r--org.eclipse.lyo.rio.trs.tests/.classpath8
-rw-r--r--org.eclipse.lyo.rio.trs.tests/.project23
-rw-r--r--org.eclipse.lyo.rio.trs.tests/Launch ALL TRS JUnits.launch16
-rw-r--r--org.eclipse.lyo.rio.trs.tests/about.html33
-rw-r--r--org.eclipse.lyo.rio.trs.tests/license/edl-v10.html60
-rw-r--r--org.eclipse.lyo.rio.trs.tests/license/epl-v10.html259
-rw-r--r--org.eclipse.lyo.rio.trs.tests/license/notice.html109
-rw-r--r--org.eclipse.lyo.rio.trs.tests/pom.xml89
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/AllTests.java25
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/ChangeLogCreationTest.java187
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/ChangeLogUpdationTest.java219
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/FetchException.java36
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/FetchUtil.java97
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/HttpErrorHandler.java63
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/HttpResponseUtil.java61
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/ITRSVocabulary.java166
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/InvalidRDFResourceException.java40
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/InvalidTRSException.java36
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/Messages.java56
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/ModelUtil.java200
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/RDFModelResponseHandler.java130
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/SendException.java37
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/SendUtil.java162
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/TestCore.java112
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/messages.properties48
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/resources/config.properties23
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/resources/resourceUpdateContent.json28
-rw-r--r--org.eclipse.lyo.rio.trs.tests/src/main/resources/resourceUpdateContent.xml20
28 files changed, 2343 insertions, 0 deletions
diff --git a/org.eclipse.lyo.rio.trs.tests/.classpath b/org.eclipse.lyo.rio.trs.tests/.classpath
new file mode 100644
index 0000000..19249a9
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/org.eclipse.lyo.rio.trs.tests/.project b/org.eclipse.lyo.rio.trs.tests/.project
new file mode 100644
index 0000000..c431e15
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/.project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.lyo.rio.trs.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.lyo.rio.trs.tests/Launch ALL TRS JUnits.launch b/org.eclipse.lyo.rio.trs.tests/Launch ALL TRS JUnits.launch
new file mode 100644
index 0000000..a400fe6
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/Launch ALL TRS JUnits.launch
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?><launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/AllTests.java"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
+<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
+<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
+<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.lyo.rio.trs.tests.AllTests"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.lyo.rio.trs.tests"/>
+<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
+</launchConfiguration> \ No newline at end of file
diff --git a/org.eclipse.lyo.rio.trs.tests/about.html b/org.eclipse.lyo.rio.trs.tests/about.html
new file mode 100644
index 0000000..e0fbbb2
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/about.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+<title>About</title>
+</head>
+<body lang="EN-US">
+ <h2>About This Content</h2>
+ <p>13 December, 2011</p>
+ <h3>License</h3>
+ <p>
+ The Eclipse Foundation makes available all content in this plug-in
+ (&quot;Content&quot;). Unless otherwise indicated below, the Content
+ is provided to you under the terms and conditions of the Eclipse
+ Public License Version 1.0 (&quot;EPL&quot;) and Eclipse Distribution
+ License Version 1.0 (&quot;EDL&quot;). A copy of the EPL is available
+ at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>
+ and a copy of the EDL is available at <a
+ href="http://www.eclipse.org/org/documents/edl-v10.php">http://www.eclipse.org/org/documents/edl-v10.php</a>.
+ For purposes of the EPL, &quot;Program&quot; will mean the Content.
+ </p>
+ <p>If you did not receive this Content directly from the Eclipse
+ Foundation, the Content is being redistributed by another party
+ (&quot;Redistributor&quot;) and different terms and conditions may
+ apply to your use of any object code in the Content. Check the
+ Redistributor's license that was provided with the Content. If no such
+ license exists, contact the Redistributor. Unless otherwise indicated
+ below, the terms and conditions of the EPL and EDL still apply to any
+ source code in the Content and such source code may be obtained at
+ <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
+</body>
+</html> \ No newline at end of file
diff --git a/org.eclipse.lyo.rio.trs.tests/license/edl-v10.html b/org.eclipse.lyo.rio.trs.tests/license/edl-v10.html
new file mode 100644
index 0000000..26b0770
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/license/edl-v10.html
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+<title>Eclipse Distribution License - Version 1.0</title>
+<style type="text/css">
+ body {
+ size: 8.5in 11.0in;
+ margin: 0.25in 0.5in 0.25in 0.5in;
+ tab-interval: 0.5in;
+ }
+ p {
+ margin-left: auto;
+ margin-top: 0.5em;
+ margin-bottom: 0.5em;
+ }
+ p.list {
+ margin-left: 0.5in;
+ margin-top: 0.05em;
+ margin-bottom: 0.05em;
+ }
+ </style>
+
+</head>
+
+<body lang="EN-US">
+
+<p><b>Eclipse Distribution License - v 1.0</b></p>
+
+<p>Copyright (c) 2007, Eclipse Foundation, Inc. and its licensors. </p>
+
+<p>All rights reserved.</p>
+<p>Redistribution and use in source and binary forms, with or without modification,
+ are permitted provided that the following conditions are met:
+<ul><li>Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer. </li>
+<li>Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution. </li>
+<li>Neither the name of the Eclipse Foundation, Inc. nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission. </li></ul>
+</p>
+<p>THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.</p>
+
+</body>
+
+</html>
+
diff --git a/org.eclipse.lyo.rio.trs.tests/license/epl-v10.html b/org.eclipse.lyo.rio.trs.tests/license/epl-v10.html
new file mode 100644
index 0000000..1107453
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/license/epl-v10.html
@@ -0,0 +1,259 @@
+<!--?xml version="1.0" encoding="ISO-8859-1" ?-->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"><head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Eclipse Public License - Version 1.0</title>
+<style type="text/css">
+ body {
+ size: 8.5in 11.0in;
+ margin: 0.25in 0.5in 0.25in 0.5in;
+ tab-interval: 0.5in;
+ }
+ p {
+ margin-left: auto;
+ margin-top: 0.5em;
+ margin-bottom: 0.5em;
+ }
+ p.list {
+ margin-left: 0.5in;
+ margin-top: 0.05em;
+ margin-bottom: 0.05em;
+ }
+ </style>
+
+</head>
+
+<body lang="EN-US">
+
+<h2>Eclipse Public License - v 1.0</h2>
+
+<p>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
+PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR
+DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS
+AGREEMENT.</p>
+
+<p><b>1. DEFINITIONS</b></p>
+
+<p>"Contribution" means:</p>
+
+<p class="list">a) in the case of the initial Contributor, the initial
+code and documentation distributed under this Agreement, and</p>
+<p class="list">b) in the case of each subsequent Contributor:</p>
+<p class="list">i) changes to the Program, and</p>
+<p class="list">ii) additions to the Program;</p>
+<p class="list">where such changes and/or additions to the Program
+originate from and are distributed by that particular Contributor. A
+Contribution 'originates' from a Contributor if it was added to the
+Program by such Contributor itself or anyone acting on such
+Contributor's behalf. Contributions do not include additions to the
+Program which: (i) are separate modules of software distributed in
+conjunction with the Program under their own license agreement, and (ii)
+are not derivative works of the Program.</p>
+
+<p>"Contributor" means any person or entity that distributes
+the Program.</p>
+
+<p>"Licensed Patents" mean patent claims licensable by a
+Contributor which are necessarily infringed by the use or sale of its
+Contribution alone or when combined with the Program.</p>
+
+<p>"Program" means the Contributions distributed in accordance
+with this Agreement.</p>
+
+<p>"Recipient" means anyone who receives the Program under
+this Agreement, including all Contributors.</p>
+
+<p><b>2. GRANT OF RIGHTS</b></p>
+
+<p class="list">a) Subject to the terms of this Agreement, each
+Contributor hereby grants Recipient a non-exclusive, worldwide,
+royalty-free copyright license to reproduce, prepare derivative works
+of, publicly display, publicly perform, distribute and sublicense the
+Contribution of such Contributor, if any, and such derivative works, in
+source code and object code form.</p>
+
+<p class="list">b) Subject to the terms of this Agreement, each
+Contributor hereby grants Recipient a non-exclusive, worldwide,
+royalty-free patent license under Licensed Patents to make, use, sell,
+offer to sell, import and otherwise transfer the Contribution of such
+Contributor, if any, in source code and object code form. This patent
+license shall apply to the combination of the Contribution and the
+Program if, at the time the Contribution is added by the Contributor,
+such addition of the Contribution causes such combination to be covered
+by the Licensed Patents. The patent license shall not apply to any other
+combinations which include the Contribution. No hardware per se is
+licensed hereunder.</p>
+
+<p class="list">c) Recipient understands that although each Contributor
+grants the licenses to its Contributions set forth herein, no assurances
+are provided by any Contributor that the Program does not infringe the
+patent or other intellectual property rights of any other entity. Each
+Contributor disclaims any liability to Recipient for claims brought by
+any other entity based on infringement of intellectual property rights
+or otherwise. As a condition to exercising the rights and licenses
+granted hereunder, each Recipient hereby assumes sole responsibility to
+secure any other intellectual property rights needed, if any. For
+example, if a third party patent license is required to allow Recipient
+to distribute the Program, it is Recipient's responsibility to acquire
+that license before distributing the Program.</p>
+
+<p class="list">d) Each Contributor represents that to its knowledge it
+has sufficient copyright rights in its Contribution, if any, to grant
+the copyright license set forth in this Agreement.</p>
+
+<p><b>3. REQUIREMENTS</b></p>
+
+<p>A Contributor may choose to distribute the Program in object code
+form under its own license agreement, provided that:</p>
+
+<p class="list">a) it complies with the terms and conditions of this
+Agreement; and</p>
+
+<p class="list">b) its license agreement:</p>
+
+<p class="list">i) effectively disclaims on behalf of all Contributors
+all warranties and conditions, express and implied, including warranties
+or conditions of title and non-infringement, and implied warranties or
+conditions of merchantability and fitness for a particular purpose;</p>
+
+<p class="list">ii) effectively excludes on behalf of all Contributors
+all liability for damages, including direct, indirect, special,
+incidental and consequential damages, such as lost profits;</p>
+
+<p class="list">iii) states that any provisions which differ from this
+Agreement are offered by that Contributor alone and not by any other
+party; and</p>
+
+<p class="list">iv) states that source code for the Program is available
+from such Contributor, and informs licensees how to obtain it in a
+reasonable manner on or through a medium customarily used for software
+exchange.</p>
+
+<p>When the Program is made available in source code form:</p>
+
+<p class="list">a) it must be made available under this Agreement; and</p>
+
+<p class="list">b) a copy of this Agreement must be included with each
+copy of the Program.</p>
+
+<p>Contributors may not remove or alter any copyright notices contained
+within the Program.</p>
+
+<p>Each Contributor must identify itself as the originator of its
+Contribution, if any, in a manner that reasonably allows subsequent
+Recipients to identify the originator of the Contribution.</p>
+
+<p><b>4. COMMERCIAL DISTRIBUTION</b></p>
+
+<p>Commercial distributors of software may accept certain
+responsibilities with respect to end users, business partners and the
+like. While this license is intended to facilitate the commercial use of
+the Program, the Contributor who includes the Program in a commercial
+product offering should do so in a manner which does not create
+potential liability for other Contributors. Therefore, if a Contributor
+includes the Program in a commercial product offering, such Contributor
+("Commercial Contributor") hereby agrees to defend and
+indemnify every other Contributor ("Indemnified Contributor")
+against any losses, damages and costs (collectively "Losses")
+arising from claims, lawsuits and other legal actions brought by a third
+party against the Indemnified Contributor to the extent caused by the
+acts or omissions of such Commercial Contributor in connection with its
+distribution of the Program in a commercial product offering. The
+obligations in this section do not apply to any claims or Losses
+relating to any actual or alleged intellectual property infringement. In
+order to qualify, an Indemnified Contributor must: a) promptly notify
+the Commercial Contributor in writing of such claim, and b) allow the
+Commercial Contributor to control, and cooperate with the Commercial
+Contributor in, the defense and any related settlement negotiations. The
+Indemnified Contributor may participate in any such claim at its own
+expense.</p>
+
+<p>For example, a Contributor might include the Program in a commercial
+product offering, Product X. That Contributor is then a Commercial
+Contributor. If that Commercial Contributor then makes performance
+claims, or offers warranties related to Product X, those performance
+claims and warranties are such Commercial Contributor's responsibility
+alone. Under this section, the Commercial Contributor would have to
+defend claims against the other Contributors related to those
+performance claims and warranties, and if a court requires any other
+Contributor to pay any damages as a result, the Commercial Contributor
+must pay those damages.</p>
+
+<p><b>5. NO WARRANTY</b></p>
+
+<p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
+PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,
+ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
+OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
+responsible for determining the appropriateness of using and
+distributing the Program and assumes all risks associated with its
+exercise of rights under this Agreement , including but not limited to
+the risks and costs of program errors, compliance with applicable laws,
+damage to or loss of data, programs or equipment, and unavailability or
+interruption of operations.</p>
+
+<p><b>6. DISCLAIMER OF LIABILITY</b></p>
+
+<p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
+NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
+WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
+DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</p>
+
+<p><b>7. GENERAL</b></p>
+
+<p>If any provision of this Agreement is invalid or unenforceable under
+applicable law, it shall not affect the validity or enforceability of
+the remainder of the terms of this Agreement, and without further action
+by the parties hereto, such provision shall be reformed to the minimum
+extent necessary to make such provision valid and enforceable.</p>
+
+<p>If Recipient institutes patent litigation against any entity
+(including a cross-claim or counterclaim in a lawsuit) alleging that the
+Program itself (excluding combinations of the Program with other
+software or hardware) infringes such Recipient's patent(s), then such
+Recipient's rights granted under Section 2(b) shall terminate as of the
+date such litigation is filed.</p>
+
+<p>All Recipient's rights under this Agreement shall terminate if it
+fails to comply with any of the material terms or conditions of this
+Agreement and does not cure such failure in a reasonable period of time
+after becoming aware of such noncompliance. If all Recipient's rights
+under this Agreement terminate, Recipient agrees to cease use and
+distribution of the Program as soon as reasonably practicable. However,
+Recipient's obligations under this Agreement and any licenses granted by
+Recipient relating to the Program shall continue and survive.</p>
+
+<p>Everyone is permitted to copy and distribute copies of this
+Agreement, but in order to avoid inconsistency the Agreement is
+copyrighted and may only be modified in the following manner. The
+Agreement Steward reserves the right to publish new versions (including
+revisions) of this Agreement from time to time. No one other than the
+Agreement Steward has the right to modify this Agreement. The Eclipse
+Foundation is the initial Agreement Steward. The Eclipse Foundation may
+assign the responsibility to serve as the Agreement Steward to a
+suitable separate entity. Each new version of the Agreement will be
+given a distinguishing version number. The Program (including
+Contributions) may always be distributed subject to the version of the
+Agreement under which it was received. In addition, after a new version
+of the Agreement is published, Contributor may elect to distribute the
+Program (including its Contributions) under the new version. Except as
+expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
+rights or licenses to the intellectual property of any Contributor under
+this Agreement, whether expressly, by implication, estoppel or
+otherwise. All rights in the Program not expressly granted under this
+Agreement are reserved.</p>
+
+<p>This Agreement is governed by the laws of the State of New York and
+the intellectual property laws of the United States of America. No party
+to this Agreement will bring a legal action under this Agreement more
+than one year after the cause of action arose. Each party waives its
+rights to a jury trial in any resulting litigation.</p>
+
+
+
+</body></html> \ No newline at end of file
diff --git a/org.eclipse.lyo.rio.trs.tests/license/notice.html b/org.eclipse.lyo.rio.trs.tests/license/notice.html
new file mode 100644
index 0000000..80720cd
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/license/notice.html
@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+<title>Eclipse Foundation Software User Agreement</title>
+</head>
+
+<body lang="EN-US">
+<h2>Eclipse Foundation Software User Agreement</h2>
+<p>13 December, 2011</p>
+
+<h3>Usage Of Content</h3>
+
+<p>THE ECLIPSE FOUNDATION MAKES AVAILABLE SOFTWARE, DOCUMENTATION, INFORMATION AND/OR OTHER MATERIALS FOR OPEN SOURCE PROJECTS
+ (COLLECTIVELY &quot;CONTENT&quot;). USE OF THE CONTENT IS GOVERNED BY THE TERMS AND CONDITIONS OF THIS AGREEMENT AND/OR THE TERMS AND
+ CONDITIONS OF LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW. BY USING THE CONTENT, YOU AGREE THAT YOUR USE
+ OF THE CONTENT IS GOVERNED BY THIS AGREEMENT AND/OR THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR
+ NOTICES INDICATED OR REFERENCED BELOW. IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT AND THE TERMS AND
+ CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW, THEN YOU MAY NOT USE THE CONTENT.</p>
+
+<h3>Applicable Licenses</h3>
+
+<p>Unless otherwise indicated, all Content made available by the Eclipse Foundation is provided to you under the terms and conditions of the Eclipse Public License Version 1.0
+ (&quot;EPL&quot;). A copy of the EPL is provided with this Content and is also available at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+ For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>Content includes, but is not limited to, source code, object code, documentation and other files maintained in the Eclipse Foundation source code
+ repository (&quot;Repository&quot;) in software modules (&quot;Modules&quot;) and made available as downloadable archives (&quot;Downloads&quot;).</p>
+
+<ul>
+ <li>Content may be structured and packaged into modules to facilitate delivering, extending, and upgrading the Content. Typical modules may include plug-ins (&quot;Plug-ins&quot;), plug-in fragments (&quot;Fragments&quot;), and features (&quot;Features&quot;).</li>
+ <li>Each Plug-in or Fragment may be packaged as a sub-directory or JAR (Java&trade; ARchive) in a directory named &quot;plugins&quot;.</li>
+ <li>A Feature is a bundle of one or more Plug-ins and/or Fragments and associated material. Each Feature may be packaged as a sub-directory in a directory named &quot;features&quot;. Within a Feature, files named &quot;feature.xml&quot; may contain a list of the names and version numbers of the Plug-ins
+ and/or Fragments associated with that Feature.</li>
+ <li>Features may also include other Features (&quot;Included Features&quot;). Within a Feature, files named &quot;feature.xml&quot; may contain a list of the names and version numbers of Included Features.</li>
+</ul>
+
+<p>The terms and conditions governing Plug-ins and Fragments should be contained in files named &quot;about.html&quot; (&quot;Abouts&quot;). The terms and conditions governing Features and
+Included Features should be contained in files named &quot;license.html&quot; (&quot;Feature Licenses&quot;). Abouts and Feature Licenses may be located in any directory of a Download or Module
+including, but not limited to the following locations:</p>
+
+<ul>
+ <li>The top-level (root) directory</li>
+ <li>Plug-in and Fragment directories</li>
+ <li>Inside Plug-ins and Fragments packaged as JARs</li>
+ <li>Sub-directories of the directory named &quot;src&quot; of certain Plug-ins</li>
+ <li>Feature directories</li>
+</ul>
+
+<p>Note: if a Feature made available by the Eclipse Foundation is installed using the Provisioning Technology (as defined below), you must agree to a license (&quot;Feature Update License&quot;) during the
+installation process. If the Feature contains Included Features, the Feature Update License should either provide you with the terms and conditions governing the Included Features or
+inform you where you can locate them. Feature Update Licenses may be found in the &quot;license&quot; property of files named &quot;feature.properties&quot; found within a Feature.
+Such Abouts, Feature Licenses, and Feature Update Licenses contain the terms and conditions (or references to such terms and conditions) that govern your use of the associated Content in
+that directory.</p>
+
+<p>THE ABOUTS, FEATURE LICENSES, AND FEATURE UPDATE LICENSES MAY REFER TO THE EPL OR OTHER LICENSE AGREEMENTS, NOTICES OR TERMS AND CONDITIONS. SOME OF THESE
+OTHER LICENSE AGREEMENTS MAY INCLUDE (BUT ARE NOT LIMITED TO):</p>
+
+<ul>
+ <li>Eclipse Distribution License Version 1.0 (available at <a href="http://www.eclipse.org/licenses/edl-v10.html">http://www.eclipse.org/licenses/edl-v1.0.html</a>)</li>
+ <li>Common Public License Version 1.0 (available at <a href="http://www.eclipse.org/legal/cpl-v10.html">http://www.eclipse.org/legal/cpl-v10.html</a>)</li>
+ <li>Apache Software License 1.1 (available at <a href="http://www.apache.org/licenses/LICENSE">http://www.apache.org/licenses/LICENSE</a>)</li>
+ <li>Apache Software License 2.0 (available at <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a>)</li>
+ <li>Metro Link Public License 1.00 (available at <a href="http://www.opengroup.org/openmotif/supporters/metrolink/license.html">http://www.opengroup.org/openmotif/supporters/metrolink/license.html</a>)</li>
+ <li>Mozilla Public License Version 1.1 (available at <a href="http://www.mozilla.org/MPL/MPL-1.1.html">http://www.mozilla.org/MPL/MPL-1.1.html</a>)</li>
+</ul>
+
+<p>IT IS YOUR OBLIGATION TO READ AND ACCEPT ALL SUCH TERMS AND CONDITIONS PRIOR TO USE OF THE CONTENT. If no About, Feature License, or Feature Update License is provided, please
+contact the Eclipse Foundation to determine what terms and conditions govern that particular Content.</p>
+
+
+<h3>Use of Provisioning Technology</h3>
+
+<p>The Eclipse Foundation makes available provisioning software, examples of which include, but are not limited to, p2 and the Eclipse
+ Update Manager (&quot;Provisioning Technology&quot;) for the purpose of allowing users to install software, documentation, information and/or
+ other materials (collectively &quot;Installable Software&quot;). This capability is provided with the intent of allowing such users to
+ install, extend and update Eclipse-based products. Information about packaging Installable Software is available at <a
+ href="http://eclipse.org/equinox/p2/repository_packaging.html">http://eclipse.org/equinox/p2/repository_packaging.html</a>
+ (&quot;Specification&quot;).</p>
+
+<p>You may use Provisioning Technology to allow other parties to install Installable Software. You shall be responsible for enabling the
+ applicable license agreements relating to the Installable Software to be presented to, and accepted by, the users of the Provisioning Technology
+ in accordance with the Specification. By using Provisioning Technology in such a manner and making it available in accordance with the
+ Specification, you further acknowledge your agreement to, and the acquisition of all necessary rights to permit the following:</p>
+
+<ol>
+ <li>A series of actions may occur (&quot;Provisioning Process&quot;) in which a user may execute the Provisioning Technology
+ on a machine (&quot;Target Machine&quot;) with the intent of installing, extending or updating the functionality of an Eclipse-based
+ product.</li>
+ <li>During the Provisioning Process, the Provisioning Technology may cause third party Installable Software or a portion thereof to be
+ accessed and copied to the Target Machine.</li>
+ <li>Pursuant to the Specification, you will provide to the user the terms and conditions that govern the use of the Installable
+ Software (&quot;Installable Software Agreement&quot;) and such Installable Software Agreement shall be accessed from the Target
+ Machine in accordance with the Specification. Such Installable Software Agreement must inform the user of the terms and conditions that govern
+ the Installable Software and must solicit acceptance by the end user in the manner prescribed in such Installable Software Agreement. Upon such
+ indication of agreement by the user, the provisioning Technology will complete installation of the Installable Software.</li>
+</ol>
+
+<h3>Cryptography</h3>
+
+<p>Content may contain encryption software. The country in which you are currently may have restrictions on the import, possession, and use, and/or re-export to
+ another country, of encryption software. BEFORE using any encryption software, please check the country's laws, regulations and policies concerning the import,
+ possession, or use, and re-export of encryption software, to see if this is permitted.</p>
+
+<p><small>Java and all Java-based trademarks are trademarks of Oracle Corporation in the United States, other countries, or both.</small></p>
+</body>
+</html>
+
diff --git a/org.eclipse.lyo.rio.trs.tests/pom.xml b/org.eclipse.lyo.rio.trs.tests/pom.xml
new file mode 100644
index 0000000..08058df
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/pom.xml
@@ -0,0 +1,89 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.eclipse.lyo</groupId>
+ <version>2.0-SNAPSHOT</version>
+ <name>TRS Reference Application Test Suite</name>
+ <artifactId>org.eclipse.lyo.rio.trs.tests</artifactId>
+ <description>A set of junit tests to validate that various aspects of the reference application's change log are functioning properly.</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>[4.1.2,)</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.lyo</groupId>
+ <artifactId>oslc-trs</artifactId>
+ <version>[2.0-SNAPSHOT,)</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jena</groupId>
+ <artifactId>jena-arq</artifactId>
+ <version>2.9.1</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <outputDirectory>target/classes</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/java</directory>
+ <includes>
+ <include> **/*.properties</include>
+ <include> **/*.index</include>
+ <include> **/resources</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+
+ <!-- Compiler Plugin -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+
+ <!-- Source Jar Plugin -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <!-- Javadoc Plugin -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+</project> \ No newline at end of file
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/AllTests.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/AllTests.java
new file mode 100644
index 0000000..76e7386
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/AllTests.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Joseph Leong, Sujeet Mishra - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses({ ChangeLogCreationTest.class, ChangeLogUpdationTest.class })
+public class AllTests {}
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/ChangeLogCreationTest.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/ChangeLogCreationTest.java
new file mode 100644
index 0000000..8821b74
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/ChangeLogCreationTest.java
@@ -0,0 +1,187 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Joseph Leong, Sujeet Mishra - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests;
+
+import static org.eclipse.lyo.core.trs.TRSConstants.FileSep;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.Properties;
+
+import org.apache.http.client.HttpClient;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.DefaultedHttpContext;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.SyncBasicHttpContext;
+import org.eclipse.lyo.rio.trs.tests.utils.FetchException;
+import org.eclipse.lyo.rio.trs.tests.utils.ITRSVocabulary;
+import org.eclipse.lyo.rio.trs.tests.utils.InvalidTRSException;
+import org.eclipse.lyo.rio.trs.tests.utils.Messages;
+import org.eclipse.lyo.rio.trs.tests.utils.SendException;
+import org.eclipse.lyo.rio.trs.tests.utils.SendUtil;
+import org.eclipse.lyo.rio.trs.tests.utils.TestCore;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+import com.hp.hpl.jena.vocabulary.RDF;
+
+/**
+ * This test is used to verify that a resource created
+ * through the oslc:creationFactory of an OSLC Provider
+ * which implements the TRS specification includes the
+ * resource and the associated creation event trs:Creation
+ * @author Sujeet Mishra
+ *
+ */
+public class ChangeLogCreationTest extends TestCore{
+ private static Properties prop = null;
+ private static HttpClient httpClient = null;
+ private static Resource trsResource = null;
+ private static HttpContext httpContext = null;
+ private static String createdResourceUrl = null;
+
+ @BeforeClass
+ public static void setupOnce() {
+ try {
+ prop = getConfigPropertiesInstance();
+ String resCreationFactoryUri = prop.getProperty("configResourceCreationFactoryUri");
+ String resCreationContent = (prop.getProperty("configResContentFile").equals("")?prop.getProperty("configResContent"):readFileAsString(new File(RESOURCES + FileSep + prop.getProperty("configResContentFile"))));
+ String resContentType = prop.getProperty("configContentType");
+ String trsEndpoint = prop.getProperty("configTrsEndpoint");
+ String acceptType = prop.getProperty("acceptType");
+
+ httpClient = new DefaultHttpClient();
+ httpContext =
+ new DefaultedHttpContext(new BasicHttpContext(), new SyncBasicHttpContext(null));
+
+ //Create a resource using the resource creation factory.. oslc:CreationFactory
+ createdResourceUrl=SendUtil.createResource(resCreationFactoryUri, httpClient, httpContext, resContentType,resCreationContent);
+
+
+ trsResource = getResource(trsEndpoint, httpClient, httpContext, acceptType);
+ } catch (FileNotFoundException e) {
+ terminateTest(Messages.getServerString("tests.general.config.properties.missing"), e);
+ } catch (InterruptedException e) {
+ terminateTest(null, e);
+ } catch (IOException e) {
+ terminateTest(Messages.getServerString("tests.general.config.properties.unreadable"), e);
+ } catch (FetchException e) {
+ terminateTest(Messages.getServerString("tests.general.trs.fetch.error"), e);
+ } catch (SendException e) {
+ terminateTest(Messages.getServerString("tests.general.trs.send.error"), e);
+ }
+ }
+
+ @Test
+ public void testChangeLogHasChangeProperty() {
+ try {
+ Resource changeLogResource =
+ trsResource.getPropertyResourceValue(ITRSVocabulary.CHANGELOG_PROPERTY);
+
+ if (changeLogResource != null && !changeLogResource.equals(RDF.nil)) {
+ if (!changeLogResource.hasProperty(ITRSVocabulary.CHANGE_PROPERTY)) {
+ throw new InvalidTRSException(
+ Messages.getServerString("validators.missing.trs.change.property")); //$NON-NLS-1$
+ }
+
+ }
+ } catch (InvalidTRSException e) {
+ e.printStackTrace();
+ Assert.fail(e.getLocalizedMessage());
+ } catch (Exception e) {
+ e.printStackTrace();
+ Assert.fail(MessageFormat.format(
+ Messages.getServerString("tests.general.error"),
+ e.getLocalizedMessage()));
+ }
+ }
+
+ @Test
+ public void testChangeLogEventChangedPropertyHasCreatedResource() {
+ boolean matchFound = false;
+ try {
+ // Get the overall model, we will need it to follow trs:change
+ // references in the change log to the actual change event later.
+ Model rdfModel = trsResource.getModel();
+
+ // Get the trs resource's change log
+ Resource changeLogResource =
+ trsResource.getPropertyResourceValue(ITRSVocabulary.CHANGELOG_PROPERTY);
+
+ if (changeLogResource != null && !changeLogResource.equals(RDF.nil)
+ && changeLogResource.hasProperty(ITRSVocabulary.CHANGE_PROPERTY))
+ {
+ // Iterate over all trs:change properties referenced by the change log
+ StmtIterator iter = changeLogResource.listProperties(ITRSVocabulary.CHANGE_PROPERTY);
+
+ while (iter.hasNext()) {
+ Statement trsChangeReference = iter.nextStatement();
+
+ // Obtain the actual change event resource using the URI
+ // mentioned in the change log's trs:change property we are
+ // currently examining
+ Resource changeEvent = rdfModel.getResource(trsChangeReference.getObject().toString());
+
+ if (RDF.nil.getURI().equals(changeEvent.getURI()))
+ break;
+
+ // Now that we have the change event, determine if it matches
+ // the change event created during the test's setup method
+ if (changeEvent.hasProperty(ITRSVocabulary.CHANGED_PROPERTY))
+ {
+ if (changeEvent
+ .getProperty(ITRSVocabulary.CHANGED_PROPERTY)
+ .getObject().toString()
+ .equalsIgnoreCase(createdResourceUrl)) {
+ matchFound=true;
+
+ //Match Found .. now check if the correct event type is present
+ if (!changeEvent.hasProperty(RDF.type,
+ ITRSVocabulary.CREATION_RESOURCE)) {
+ throw new InvalidTRSException(
+ Messages.getServerString("validators.invalid.trs.changed.property")); //$NON-NLS-1$
+ }
+ break;
+ }
+ }
+ }
+ if(!matchFound)
+ {
+ throw new InvalidTRSException(
+ Messages.getServerString("validators.invalid.trs.changed.property")); //$NON-NLS-1$
+ }
+
+ }
+ } catch (InvalidTRSException e) {
+ e.printStackTrace();
+ Assert.fail(e.getLocalizedMessage());
+ } catch (Exception e) {
+ e.printStackTrace();
+ Assert.fail(MessageFormat.format(
+ Messages.getServerString("tests.general.error"),
+ e.getLocalizedMessage()));
+ }
+ }
+}
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/ChangeLogUpdationTest.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/ChangeLogUpdationTest.java
new file mode 100644
index 0000000..fee4c60
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/ChangeLogUpdationTest.java
@@ -0,0 +1,219 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Joseph Leong, Sujeet Mishra - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests;
+
+import static org.eclipse.lyo.core.trs.TRSConstants.FileSep;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.text.MessageFormat;
+import java.util.Properties;
+
+import org.apache.http.client.HttpClient;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.DefaultedHttpContext;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.SyncBasicHttpContext;
+import org.eclipse.lyo.core.trs.HttpConstants;
+import org.eclipse.lyo.rio.trs.tests.utils.FetchException;
+import org.eclipse.lyo.rio.trs.tests.utils.ITRSVocabulary;
+import org.eclipse.lyo.rio.trs.tests.utils.InvalidTRSException;
+import org.eclipse.lyo.rio.trs.tests.utils.Messages;
+import org.eclipse.lyo.rio.trs.tests.utils.SendException;
+import org.eclipse.lyo.rio.trs.tests.utils.SendUtil;
+import org.eclipse.lyo.rio.trs.tests.utils.TestCore;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.RDFList;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+import com.hp.hpl.jena.vocabulary.RDF;
+
+/**
+ * This test is used to verify that a resource updated
+ * through a http PUT call will be listed as one of the
+ * changed entries in the TRS ChangeLog along with the
+ * associated creation event trs:Modification
+ * @author Sujeet Mishra
+ *
+ */
+public class ChangeLogUpdationTest extends TestCore {
+
+ private static Properties prop = null;
+ private static HttpClient httpClient = null;
+ private static Resource trsResource = null;
+ private static HttpContext httpContext = null;
+ private static String createdResourceUrl = null;
+
+ @BeforeClass
+ public static void setupOnce() {
+ try {
+ prop = getConfigPropertiesInstance();
+ String resCreationFactoryUri = prop.getProperty("configResourceCreationFactoryUri");
+ String resCreationContent = (prop.getProperty("configResContentFile").equals("")?prop.getProperty("configResContent"):readFileAsString(new File(RESOURCES + FileSep + prop.getProperty("configResContentFile"))));
+ String resContentType = prop.getProperty("configContentType");
+ String resUpdateContentType = prop.getProperty("configUpdateContentType");
+ String trsEndpoint = prop.getProperty("configTrsEndpoint");
+ String acceptType = prop.getProperty("acceptType");
+
+ httpClient = new DefaultHttpClient();
+ httpContext =
+ new DefaultedHttpContext(new BasicHttpContext(), new SyncBasicHttpContext(null));
+
+ //Create a resource using the resource creation factory.. oslc:CreationFactory
+ createdResourceUrl=SendUtil.createResource(resCreationFactoryUri, httpClient, httpContext, resContentType,resCreationContent);
+
+ //Now Update the resource using a HTTP PUT call
+ String updateContent=readFileAsString(new File(RESOURCES + FileSep + prop.getProperty("configResUpdateFile")));
+
+ //Replace the Update content with the correct resource identifier of the resource created above
+ updateContent = formatUpdateContent(updateContent,resUpdateContentType);
+
+ SendUtil.updateResource(createdResourceUrl, httpClient, httpContext,resUpdateContentType, updateContent);
+
+ trsResource = getResource(trsEndpoint, httpClient, httpContext, acceptType);
+
+
+ } catch (FileNotFoundException e) {
+ terminateTest(Messages.getServerString("tests.general.config.properties.missing"), e);
+ } catch (InterruptedException e) {
+ terminateTest(null, e);
+ } catch (IOException e) {
+ terminateTest(Messages.getServerString("tests.general.config.properties.unreadable"), e);
+ } catch (FetchException e) {
+ terminateTest(Messages.getServerString("tests.general.trs.fetch.error"), e);
+ } catch (SendException e) {
+ terminateTest(Messages.getServerString("tests.general.trs.send.error"), e);
+ }
+ }
+
+ private static String formatUpdateContent(String updateContent,String contentType) {
+ if (contentType.equalsIgnoreCase(HttpConstants.CT_APPLICATION_RDF_XML)) {
+ if (updateContent.contains("rdf:about=\"\"")) {
+ String replacement = "rdf:about=\"" + createdResourceUrl + "\"";
+ updateContent = updateContent.replace("rdf:about=\"\"",
+ replacement);
+ }
+ } else if (contentType
+ .equalsIgnoreCase(HttpConstants.CT_APPLICATION_JSON)) {
+ if (updateContent.contains("\"rdf:about\":\"\"")) {
+ String replacement = "\"rdf:about\":\"" + createdResourceUrl + "\"";
+ updateContent = updateContent.replace("\"rdf:about\":\"\"",
+ replacement);
+ }
+ }
+
+ return updateContent;
+ }
+
+ @Test
+ public void testChangeLogHasChangeProperty() {
+ try {
+ Resource changeLogResource =
+ trsResource.getPropertyResourceValue(ITRSVocabulary.CHANGELOG_PROPERTY);
+
+ if (changeLogResource != null && !changeLogResource.equals(RDF.nil)) {
+ if (!changeLogResource.hasProperty(ITRSVocabulary.CHANGE_PROPERTY)) {
+ throw new InvalidTRSException(
+ Messages.getServerString("validators.missing.trs.change.property")); //$NON-NLS-1$
+ }
+
+ }
+ } catch (InvalidTRSException e) {
+ e.printStackTrace();
+ Assert.fail(e.getLocalizedMessage());
+ } catch (Exception e) {
+ e.printStackTrace();
+ Assert.fail(MessageFormat.format(
+ Messages.getServerString("tests.general.error"),
+ e.getLocalizedMessage()));
+ }
+ }
+
+ @Test
+ public void testChangeLogEventChangedPropertyHasCreatedResource() {
+ boolean matchFound = false;
+ // Get the overall model, we will need it to follow trs:change
+ // references in the change log to the actual change event later.
+ Model rdfModel = trsResource.getModel();
+
+ try {
+ Resource changeLogResource =
+ trsResource.getPropertyResourceValue(ITRSVocabulary.CHANGELOG_PROPERTY);
+
+ if (changeLogResource != null && !changeLogResource.equals(RDF.nil)
+ && changeLogResource.hasProperty(ITRSVocabulary.CHANGE_PROPERTY))
+ {
+ // Iterate over all trs:change properties referenced by the change log
+ StmtIterator iter = changeLogResource.listProperties(ITRSVocabulary.CHANGE_PROPERTY);
+
+ while (iter.hasNext()) {
+ Statement trsChangeReference = iter.nextStatement();
+
+ // Obtain the actual change event resource using the URI
+ // mentioned in the change log's trs:change property we are
+ // currently examining
+ Resource changeEvent = rdfModel.getResource(trsChangeReference.getObject().toString());
+
+ if (RDF.nil.getURI().equals(changeEvent.getURI()))
+ break;
+
+ if (changeEvent.hasProperty(ITRSVocabulary.CHANGED_PROPERTY))
+ {
+ if (changeEvent
+ .getProperty(ITRSVocabulary.CHANGED_PROPERTY)
+ .getObject().toString()
+ .equalsIgnoreCase(createdResourceUrl)) {
+
+ //Possible match found. Check if the correct event type is present
+ if (changeEvent.hasProperty(RDF.type,
+ ITRSVocabulary.MODIFICATION_RESOURCE)) {
+ matchFound=true;
+ break;
+ }
+
+ }
+ }
+ }
+ if(!matchFound)
+ {
+ throw new InvalidTRSException(
+ Messages.getServerString("validators.invalid.trs.changed.property")); //$NON-NLS-1$
+ }
+
+ }
+ } catch (InvalidTRSException e) {
+ e.printStackTrace();
+ Assert.fail(e.getLocalizedMessage());
+ } catch (Exception e) {
+ e.printStackTrace();
+ Assert.fail(MessageFormat.format(
+ Messages.getServerString("tests.general.error"),
+ e.getLocalizedMessage()));
+ }
+
+ }
+
+
+}
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/FetchException.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/FetchException.java
new file mode 100644
index 0000000..019eb2f
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/FetchException.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Joseph Leong, Sujeet Mishra - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests.utils;
+
+/**
+ * A exception that is thrown when fetching a resource encounters an exception
+ */
+public class FetchException extends Exception {
+ private static final long serialVersionUID = -5064491774183615219L;
+
+ public FetchException(String message) {
+ super(message);
+ }
+
+ public FetchException(Throwable th) {
+ super(th);
+ }
+
+ public FetchException(String message, Throwable th) {
+ super(message, th);
+ }
+}
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/FetchUtil.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/FetchUtil.java
new file mode 100644
index 0000000..e96d2a0
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/FetchUtil.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Joseph Leong, Sujeet Mishra - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests.utils;
+
+import java.io.IOException;
+import java.net.URL;
+import java.text.MessageFormat;
+
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.protocol.HttpContext;
+import org.eclipse.lyo.core.trs.HttpConstants;
+
+import com.hp.hpl.jena.rdf.model.Model;
+
+/**
+ * A class that provides a utility methods to fetch HTTP resources as well as
+ * process fetch responses
+ */
+public class FetchUtil {
+ /**
+ * Fetches a resource. In case of success, this method
+ * returns an instance of the {@link Model}.
+ *
+ * @param uri
+ * resource uri to fetch
+ * @param httpClient
+ * client used to fetch the resource
+ * @param httpContext
+ * http context to use for the call
+ * @param acceptType
+ * value to use in the accept header
+ * @throws InterruptedException
+ * if the thread is interrupted
+ * @throws FetchException
+ * if an error occurs while fetching the resource.
+ * @throws IOException
+ * if an error occurs while updating the retryable error
+ * information into the error handler
+ */
+ public static Model fetchResource(String uri, HttpClient httpClient, HttpContext httpContext, String acceptType)
+ throws InterruptedException, FetchException
+ {
+ if (uri == null)
+ throw new IllegalArgumentException(
+ Messages.getServerString("fetch.util.uri.null")); //$NON-NLS-1$
+ if (httpClient == null)
+ throw new IllegalArgumentException(
+ Messages.getServerString("fetch.util.httpclient.null")); //$NON-NLS-1$
+
+ Model model = null;
+
+ try {
+ new URL(uri); // Make sure URL is valid
+
+ HttpGet get = new HttpGet(uri);
+
+ get.setHeader(HttpConstants.ACCEPT, acceptType);
+
+ // Caches must revalidate with origin server. This is to prevent a cache
+ // from serving stale data. We may still get a cached response if the
+ // origin server responds to the revalidation with a 304.
+ // See Unspecified end-to-end revalidation:
+ // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.4
+ get.addHeader(HttpConstants.CACHE_CONTROL, "max-age=0"); //$NON-NLS-1$
+
+ model = httpClient.execute(get, new RDFModelResponseHandler(uri), httpContext);
+ } catch (Exception e) {
+ String uriLocation = Messages.getServerString("fetch.util.uri.unidentifiable"); //$NON-NLS-1$
+
+ if(uri != null && !uri.isEmpty())
+ {
+ uriLocation = uri;
+ }
+
+ throw new FetchException(MessageFormat.format(
+ Messages.getServerString("fetch.util.retrieve.error"), //$NON-NLS-1$
+ uriLocation));
+ }
+
+ return model;
+ }
+}
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/HttpErrorHandler.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/HttpErrorHandler.java
new file mode 100644
index 0000000..1b88801
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/HttpErrorHandler.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Joseph Leong, Sujeet Mishra - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests.utils;
+
+import java.io.IOException;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpResponseException;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.util.EntityUtils;
+
+
+public class HttpErrorHandler {
+
+ /**
+ * Handle a possible HTTP error response.
+ *
+ * @param response
+ * The HTTP response to handle; must not be <code>null</code>
+ * @throws HttpResponseException
+ * if the response status code maps to an exception class
+ */
+ public static void responseToException(HttpResponse response)
+ throws HttpResponseException
+ {
+ if (response == null)
+ throw new IllegalArgumentException(
+ Messages.getServerString("http.error.handler.null.argument")); //$NON-NLS-1$
+
+ Integer status = Integer.valueOf(response.getStatusLine().getStatusCode());
+
+ //Create detail message from response status line and body
+ String reasonPhrase = response.getStatusLine().getReasonPhrase();
+
+ StringBuilder message = new StringBuilder(reasonPhrase == null ? "" : reasonPhrase); //$NON-NLS-1$
+
+ if (response.getEntity() != null) {
+ try {
+ String body = EntityUtils.toString(response.getEntity(), HTTP.UTF_8);
+ if (body != null && body.length() != 0) {
+ message.append('\n');
+ message.append(body);
+ }
+ } catch (IOException e) { } // ignore, since the original error needs to be reported
+ }
+
+ throw new HttpResponseException(status, message.toString());
+ }
+}
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/HttpResponseUtil.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/HttpResponseUtil.java
new file mode 100644
index 0000000..8c9023a
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/HttpResponseUtil.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Joseph Leong, Sujeet Mishra - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+
+
+public class HttpResponseUtil {
+ /**
+ * Marks an HTTP response as final and disposes of any system resources
+ * referenced by the response.
+ * <p>
+ * Clients should aggressively call this method as soon as they no longer need the response to
+ * reduce contention over possibly scarce system resources.
+ * </p>
+ * <p>
+ * Clients should <strong>not</strong> attempt to access the HTTP response after calling this
+ * method.
+ * </p>
+ * @param response the HTTP response to finalize
+ */
+ public static void finalize(final HttpResponse response) {
+ if (response == null)
+ return;
+ HttpEntity entity = response.getEntity();
+ try {
+ if (entity != null) {
+ InputStream is = entity.getContent();
+ if (is != null) {
+ is.close();
+ }
+ }
+ } catch (IOException e) { /* ignored */
+ }
+ }
+
+ private HttpResponseUtil() {
+ super();
+ throw new UnsupportedOperationException(
+ Messages.getServerString("http.response.util.no.instance")); //$NON-NLS-1$
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/ITRSVocabulary.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/ITRSVocabulary.java
new file mode 100644
index 0000000..6b1948f
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/ITRSVocabulary.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Joseph Leong, Sujeet Mishra - Initial implementation
+ * David Terry - Add fields for TRS 2.0 compliance
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests.utils;
+
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.ResourceFactory;
+
+/**
+ * An API to access the vocabulary of the TRS Protocol.
+ * The following namespaces are supported: {@link #TEMPORARILY_SUPPORTED} and {@link #LATEST}
+ */
+public interface ITRSVocabulary {
+
+ // Local names
+ public static final String TRS_PROVIDER_LOCALNAME = "TrackedResourceSetProvider"; //$NON-NLS-1$
+ public static final String TRS_RES_LOCALNAME = "TrackedResourceSet"; //$NON-NLS-1$
+ public static final String TRS_PROP_LOCALNAME = "trackedResourceSet"; //$NON-NLS-1$
+ public static final String BASE_LOCALNAME = "base"; //$NON-NLS-1$
+ public static final String CUTOFFEVENT_LOCALNAME = "cutoffEvent"; //$NON-NLS-1$
+ public static final String NEXT_LOCALNAME = "nextPage"; //$NON-NLS-1$
+ public static final String CHANGELOG_LOCALNAME = "changeLog"; //$NON-NLS-1$
+ public static final String CHANGE_LOCALNAME = "change"; //$NON-NLS-1$
+ public static final String CHANGED_LOCALNAME = "changed"; //$NON-NLS-1$
+ public static final String ORDER_LOCALNAME = "order"; //$NON-NLS-1$
+ public static final String PREVIOUS_LOCALNAME = "previous"; //$NON-NLS-1$
+ public static final String TRSURI_LOCALNAME = "TrackedResourceSetUri"; //$NON-NLS-1$
+ public static final String CREATION_LOCALNAME = "Creation"; //$NON-NLS-1$
+ public static final String MODIFICATION_LOCALNAME = "Modification"; //$NON-NLS-1$
+ public static final String DELETION_LOCALNAME = "Deletion"; //$NON-NLS-1$
+ public static final String AGGREGATE_CONTAINER_LOCALNAME = "AggregateContainer"; //$NON-NLS-1$
+ public static final String PAGE_LOCALNAME = "Page"; //$NON-NLS-1$
+ public static final String PAGE_OF_LOCALNAME = "pageOf"; //$NON-NLS-1$
+
+ /**
+ * The namespace of the vocabulary as a string
+ */
+ public static final String NS = "http://open-services.net/ns/core/trs#"; //$NON-NLS-1$
+
+ /**
+ * Get a specific vocabulary within the TRS provider as a string
+ */
+ public static final String TRS_PROVIDER_URI = NS + TRS_PROVIDER_LOCALNAME;
+
+ /**
+ * Get a specific vocabulary within the TRS property as a string
+ */
+ public static final String TRS_PROP_URI = NS + TRS_PROP_LOCALNAME;
+
+ /**
+ * The resource for the TRS namespace
+ */
+ public static final Resource NAMESPACE = ResourceFactory.createResource(NS);
+
+ /**
+ * The property for the base predicate in a TRS
+ */
+ public static final Property BASE_PROPERTY = ResourceFactory.createProperty(NS, BASE_LOCALNAME);
+
+ /**
+ * The property for the cut off event predicate in a TRS
+ */
+ public static final Property CUTOFFEVENT_PROPERTY = ResourceFactory.createProperty(NS,
+ CUTOFFEVENT_LOCALNAME);
+
+ /**
+ * The property for a change log predicate within a tracked resource set
+ */
+ public static final Property CHANGELOG_PROPERTY = ResourceFactory.createProperty(NS,
+ CHANGELOG_LOCALNAME);
+
+ /**
+ * The property for the change predicate in a TRS
+ */
+ public static final Property CHANGE_PROPERTY = ResourceFactory.createProperty(NS,
+ CHANGE_LOCALNAME);
+
+ /**
+ * The property for the changes predicate of a change log entry
+ */
+ public static final Property CHANGED_PROPERTY = ResourceFactory.createProperty(NS,
+ CHANGED_LOCALNAME);
+
+ /**
+ * The property for the order predicate of a change log entry
+ */
+ public static final Property ORDER_PROPERTY = ResourceFactory.createProperty(NS,
+ ORDER_LOCALNAME);
+
+ /**
+ * The property for the previous predicate in a TRS or base resource
+ */
+ public static final Property PREVIOUS_PROPERTY = ResourceFactory.createProperty(NS,
+ PREVIOUS_LOCALNAME);
+
+ /**
+ * The resource for the set of tracked resources
+ */
+ public static final Resource TRS_RESOURCE = ResourceFactory.createResource(NS
+ + TRS_RES_LOCALNAME);
+
+ /**
+ * The resource for the creation change log type
+ */
+ public static final Resource CREATION_RESOURCE = ResourceFactory.createResource(NS
+ + CREATION_LOCALNAME);
+
+ /**
+ * The resource for the modification change log type
+ */
+ public static final Resource MODIFICATION_RESOURCE = ResourceFactory.createResource(NS
+ + MODIFICATION_LOCALNAME);
+
+ /**
+ * The resource for the deletion change log type
+ */
+ public static final Resource DELETION_RESOURCE = ResourceFactory.createResource(NS
+ + DELETION_LOCALNAME);
+
+ // LDP related namespace, resources, and properties
+ /**
+ * Namespace for the Linked Data Platform
+ */
+ public static final String LDP_NS = "http://www.w3.org/ns/ldp#"; //$NON-NLS-1$
+
+ /**
+ * The AggregateContainer resource type used by the base resource
+ */
+ public static final Resource CONTAINER_RESOURCE = ResourceFactory.createResource(LDP_NS
+ + AGGREGATE_CONTAINER_LOCALNAME);
+
+ /**
+ * The Page resource type used by the base resource to reference the next
+ * page in the base sequence.
+ */
+ public static final Resource PAGE_RESOURCE = ResourceFactory.createResource(LDP_NS
+ + PAGE_LOCALNAME);
+
+ /**
+ * A reference back to the aggregate container this page belongs to
+ */
+ public static final Property PAGE_OF_RESOURCE = ResourceFactory.createProperty(LDP_NS
+ + PAGE_OF_LOCALNAME);
+
+ /**
+ * The property for the next page resource in a base resource
+ */
+ public static final Property NEXT_PAGE_PROPERTY = ResourceFactory.createProperty(LDP_NS,
+ NEXT_LOCALNAME);
+
+} \ No newline at end of file
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/InvalidRDFResourceException.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/InvalidRDFResourceException.java
new file mode 100644
index 0000000..be82d3a
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/InvalidRDFResourceException.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Joseph Leong, Sujeet Mishra - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests.utils;
+
+import org.apache.http.client.ClientProtocolException;
+
+public class InvalidRDFResourceException extends ClientProtocolException {
+ private static final long serialVersionUID = 1L;
+
+ public InvalidRDFResourceException() {
+ super();
+ }
+
+ public InvalidRDFResourceException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidRDFResourceException(String message) {
+ super(message);
+ }
+
+ public InvalidRDFResourceException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/InvalidTRSException.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/InvalidTRSException.java
new file mode 100644
index 0000000..68d867d
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/InvalidTRSException.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Joseph Leong, Sujeet Mishra - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests.utils;
+
+/**
+ * A exception that is thrown when an invalid TRS, TRS Base or Change Log segment is encountered.
+ */
+public class InvalidTRSException extends Exception {
+ private static final long serialVersionUID = -5064491774183615219L;
+
+ public InvalidTRSException(String message) {
+ super(message);
+ }
+
+ public InvalidTRSException(Throwable th) {
+ super(th);
+ }
+
+ public InvalidTRSException(String message, Throwable th) {
+ super(message, th);
+ }
+}
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/Messages.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/Messages.java
new file mode 100644
index 0000000..76fdbd5
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/Messages.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Joseph Leong, Sujeet Mishra - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests.utils;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class Messages {
+ private static final String BUNDLE_NAME = "org.eclipse.lyo.testsuite.server.trsutils.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(Messages.BUNDLE_NAME);
+
+ private Messages() {
+ // DO Nothing
+ }
+
+ public static String getServerString(String key) {
+ try {
+ return Messages.RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ Messages.checkForWrongKey(key);
+ return '!' + key + '!';
+ }
+ }
+
+ private static void checkForWrongKey(String key) {
+ String prefix = "_NoId."; //$NON-NLS-1$
+ boolean prefixExists = key.startsWith(prefix);
+ String newKey = prefixExists == true ? key.substring(prefix.length()) : prefix + key;
+ try {
+ Messages.RESOURCE_BUNDLE.getString(newKey);
+ String error =
+ String.format(
+ "The message key \"%s\" is wrong. It should be \"%s\".", key, newKey); //$NON-NLS-1$
+ System.err.println(error);
+ throw new RuntimeException(error);
+ } catch (MissingResourceException e) {
+ // No-op
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/ModelUtil.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/ModelUtil.java
new file mode 100644
index 0000000..601598d
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/ModelUtil.java
@@ -0,0 +1,200 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Joseph Leong, Sujeet Mishra - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests.utils;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashSet;
+
+
+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 com.hp.hpl.jena.shared.JenaException;
+import com.hp.hpl.jena.util.FileUtils;
+import com.hp.hpl.jena.vocabulary.DC;
+import com.hp.hpl.jena.vocabulary.DCTerms;
+import com.hp.hpl.jena.vocabulary.RDFS;
+
+public class ModelUtil {
+ /**
+ * @param bytes
+ * Serialized RDF/XML model
+ * @return Deserialized RDF model
+ * @throws JenaException
+ */
+ static public Model deserializeModel(byte[] bytes) throws JenaException {
+ if (bytes == null)
+ throw new IllegalArgumentException(
+ Messages.getServerString("model.util.bytes.null")); //$NON-NLS-1$
+
+ return deserializeModel(new ByteArrayInputStream(bytes));
+ }
+
+ /**
+ * @param bytes
+ * Serialized RDF/XML model
+ * @param lang
+ * See
+ * {@link com.hp.hpl.jena.rdf.model.Model#read(java.io.InputStream, String, String)}
+ * @return Deserialized RDF model
+ * @throws JenaException
+ */
+ static public Model deserializeModel(byte[] bytes, String lang) throws JenaException {
+ if (bytes == null)
+ throw new IllegalArgumentException(
+ Messages.getServerString("model.util.bytes.null")); //$NON-NLS-1$
+
+ return deserializeModel(new ByteArrayInputStream(bytes), lang);
+ }
+
+ /**
+ * @param in
+ * Serialized RDF/XML model
+ * @return Deserialized RDF model
+ * @throws JenaException
+ */
+ static public Model deserializeModel(InputStream in) throws JenaException {
+ return deserializeModel(in, null);
+ }
+
+ /**
+ * @param in
+ * Serialized RDF model
+ * @param lang
+ * See
+ * {@link com.hp.hpl.jena.rdf.model.Model#read(java.io.InputStream, String, String)}
+ * @return Deserialized RDF model
+ * @throws JenaException
+ */
+ static public Model deserializeModel(InputStream in, String lang) throws JenaException {
+ if (in == null)
+ throw new IllegalArgumentException(
+ Messages.getServerString("model.util.inputstream.null")); //$NON-NLS-1$
+
+ Model model = ModelUtil.createDefaultModel();
+
+ try {
+ model.read(in, null, lang);
+ } catch (Throwable t) {
+ // Temp ignore - TODO ignore empty stream specifically
+ return model;
+ }
+
+ return model;
+ }
+
+ /**
+ * @param model
+ * Input model
+ * @return Serialized RDF/XML model
+ * @throws JenaException
+ */
+ static public byte[] serializeModel(Model model) throws JenaException {
+ return serializeModel(model, (String) null);
+ }
+
+ /**
+ * @param model
+ * Input Model
+ * @param lang
+ * See
+ * {@link com.hp.hpl.jena.rdf.model.Model#read(java.io.InputStream, String, String)}
+ * @return Serialized model
+ * @throws JenaException
+ */
+ static public byte[] serializeModel(Model model, String lang) throws JenaException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ serializeModel(model, lang, out);
+ return out.toByteArray();
+ }
+
+ /**
+ * @param model
+ * Input model
+ * @param out
+ * Serialized RDF/XML model
+ * @throws JenaException
+ */
+ static public void serializeModel(Model model, OutputStream out) throws JenaException {
+ serializeModel(model, null, out);
+ }
+
+ /**
+ * @param model
+ * Input Model
+ * @param lang
+ * See
+ * {@link com.hp.hpl.jena.rdf.model.Model#read(java.io.InputStream, String, String)}
+ * @param out
+ * Serialized model
+ * @throws JenaException
+ */
+ static public void serializeModel(Model model, String lang, OutputStream out)
+ throws JenaException {
+ if (model == null)
+ throw new IllegalArgumentException(
+ Messages.getServerString("model.util.model.null")); //$NON-NLS-1$
+ if (out == null)
+ throw new IllegalArgumentException(
+ Messages.getServerString("model.util.outputstream.null")); //$NON-NLS-1$
+ // Avoid 'WARN com.hp.hpl.jena.xmloutput.impl.BaseXMLWriter - Namespace prefix 'j.1' is
+ // reserved by Jena.'
+ for (String prefix : new HashSet<String>(model.getNsPrefixMap().keySet())) {
+ model.removeNsPrefix(prefix);
+ }
+ model.write(out, lang);
+ }
+
+ public static Model getLocalModel(String path) {
+ InputStream in = ModelUtil.class.getResourceAsStream(path);
+ Model model = ModelUtil.createDefaultModel();
+ model.read(in, null, FileUtils.guessLang(path, FileUtils.langXML));
+ return model;
+ }
+
+ public static String getVocabularyTitle(Model vocabulary, String uri) {
+ Resource nsResource = vocabulary.createResource(uri);
+ if (nsResource.hasProperty(DCTerms.title)) {
+ return nsResource.getProperty(DCTerms.title).getString();
+ } else if (nsResource.hasProperty(DC.title)) {
+ return nsResource.getProperty(DC.title).getString();
+ } else if (nsResource.hasProperty(RDFS.label))
+ return nsResource.getProperty(RDFS.label).getString();
+ return null;
+ }
+
+ /*
+ * This is a utility method to workaround WAS classloading issues with jena
+ */
+ public static Model createDefaultModel() {
+ Model model = null;
+ // save the current thread class loader (TCCL)
+ ClassLoader ctxClassloader = Thread.currentThread().getContextClassLoader();
+ try {
+ // Get the java class loader to allow jena to use xml/xerces dependencies
+ Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
+ model = ModelFactory.createDefaultModel();
+ } finally {
+ // put it back the way it was
+ Thread.currentThread().setContextClassLoader(ctxClassloader);
+ }
+ return model;
+ }
+}
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/RDFModelResponseHandler.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/RDFModelResponseHandler.java
new file mode 100644
index 0000000..d339f28
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/RDFModelResponseHandler.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Joseph Leong, Sujeet Mishra - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests.utils;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.text.MessageFormat;
+
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.util.EntityUtils;
+import org.eclipse.lyo.core.trs.HttpConstants;
+import org.openjena.riot.ContentType;
+import org.openjena.riot.Lang;
+import org.openjena.riot.WebContent;
+
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ResourceFactory;
+
+public class RDFModelResponseHandler implements ResponseHandler<Model> {
+ final Node base;
+
+ protected int statusCode = 0;
+ protected String reason = null;
+
+ public RDFModelResponseHandler(Node base) {
+ this.base = base;
+ }
+
+ public RDFModelResponseHandler(String base) {
+ this(ResourceFactory.createResource(base).asNode());
+ }
+
+ @Override
+ public Model handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
+ statusCode = response.getStatusLine().getStatusCode();
+ reason = response.getStatusLine().getReasonPhrase();
+ Model model = ModelUtil.createDefaultModel();
+ HttpEntity entity = response.getEntity();
+ try {
+ if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
+ HttpErrorHandler.responseToException(response);
+ }
+
+ if (entity == null)
+
+ throw new InvalidRDFResourceException(
+ MessageFormat.format(
+ Messages.getServerString("rdf.model.response.helper.missing.rdf"), //$NON-NLS-1$
+ base.getURI()));
+
+ String rdfFormat = null;
+ final Header contentTypeHeader = response.getFirstHeader(HttpConstants.CONTENT_TYPE);
+ if (contentTypeHeader != null) {
+ final ContentType contentType = ContentType.parse(contentTypeHeader.getValue());
+ if (contentType != null) {
+ Lang lang = WebContent.contentTypeToLang(contentType.getContentType());
+ if (lang != null) {
+ rdfFormat = lang.getName();
+ } else if (HttpConstants.CT_TEXT_XML.equals(contentType.getContentType())) {
+ rdfFormat = Lang.RDFXML.getName(); // attempt RDF
+ // parsing anyway
+ }
+ }
+ }
+
+ if (rdfFormat == null)
+ throw new ClientProtocolException(
+ MessageFormat.format(
+ Messages.getServerString("rdf.model.response.helper.bad.content.type"), //$NON-NLS-1$
+ base.getURI()));
+
+ String content = EntityUtils.toString(entity, HTTP.UTF_8);
+ try {
+ model.read(new StringReader(content), base.getURI(), rdfFormat);
+ } catch (Exception e) {
+ if (e.getMessage().contains("Interrupt") //$NON-NLS-1$
+ || Thread.currentThread().isInterrupted()) {
+ Thread.currentThread().interrupt();
+ throw (IOException) new IOException().initCause(e);
+ }
+
+ throw new InvalidRDFResourceException(
+ MessageFormat.format(
+ Messages.getServerString("rdf.model.response.helper.unparseable.rdf"), //$NON-NLS-1$
+ base.getURI(),
+ content), e);
+ }
+
+ HttpResponseUtil.finalize(response);
+ } finally {
+ try {
+ if (entity != null) {
+ EntityUtils.consume(entity);
+ }
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ return model;
+ }
+
+ public int getStatusCode() {
+ return statusCode;
+ }
+
+ public String getReasonPhrase() {
+ return reason;
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/SendException.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/SendException.java
new file mode 100644
index 0000000..cb60350
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/SendException.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Joseph Leong, Sujeet Mishra - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests.utils;
+
+/**
+ * A exception that is thrown when creating/updating a resource encounters an exception
+ */
+public class SendException extends Exception {
+
+ private static final long serialVersionUID = -7111348864477190261L;
+
+ public SendException(String message) {
+ super(message);
+ }
+
+ public SendException(Throwable th) {
+ super(th);
+ }
+
+ public SendException(String message, Throwable th) {
+ super(message, th);
+ }
+}
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/SendUtil.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/SendUtil.java
new file mode 100644
index 0000000..706abde
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/SendUtil.java
@@ -0,0 +1,162 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Sujeet Mishra - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests.utils;
+
+import java.io.IOException;
+import java.net.URL;
+import java.text.MessageFormat;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.EntityUtils;
+import org.eclipse.lyo.core.trs.HttpConstants;
+
+/**
+ * This Class contains methods to send data to the server
+ * in the form of HTTP POST or HTTP PUT calls
+ */
+public class SendUtil {
+
+ /**
+ *
+ * @param uri resource uri for creation factory
+ * @param httpClient client used to post to the uri
+ * @param httpContext http context to use for the call
+ * @param contentType content type to be used in the creation
+ * @param content content to be used in the creation
+ * @throws SendException if an error occurs in posting to the uri
+ */
+ public static String createResource(String uri, HttpClient httpClient, HttpContext httpContext, String contentType, String content) throws SendException
+ {
+ String createdResourceUri="";
+ if (uri == null)
+ throw new IllegalArgumentException(
+ Messages.getServerString("send.util.uri.null")); //$NON-NLS-1$
+ if (httpClient == null)
+ throw new IllegalArgumentException(
+ Messages.getServerString("send.util.httpclient.null")); //$NON-NLS-1$
+ try {
+ new URL(uri); // Make sure URL is valid
+
+ HttpPost post = new HttpPost(uri);
+ StringEntity entity = new StringEntity(content);
+ post.setEntity(entity);
+ post.setHeader(HttpConstants.ACCEPT, HttpConstants.CT_APPLICATION_RDF_XML);//$NON-NLS-1$
+ post.addHeader(HttpConstants.CONTENT_TYPE, contentType);
+ post.addHeader(HttpConstants.CACHE_CONTROL, "max-age=0"); //$NON-NLS-1$
+ HttpResponse resp = httpClient.execute(post);
+
+ try {
+ if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) {
+ HttpErrorHandler.responseToException(resp);
+ }
+ createdResourceUri=resp.getFirstHeader(HttpConstants.LOCATION).getValue();
+ HttpResponseUtil.finalize(resp);
+ }finally {
+ try {
+ if (entity != null) {
+ EntityUtils.consume(entity);
+ }
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+
+
+ } catch (Exception e) {
+ String uriLocation = Messages.getServerString("send.util.uri.unidentifiable"); //$NON-NLS-1$
+
+ if(uri != null && !uri.isEmpty())
+ {
+ uriLocation = uri;
+ }
+ throw new SendException(MessageFormat.format(
+ Messages.getServerString("send.util.retrieve.error"), //$NON-NLS-1$
+ uriLocation));
+ }
+
+ return createdResourceUri;
+ }
+
+
+ /**
+ *
+ * @param uri resource uri for update
+ * @param httpClient client used to put data to the uri
+ * @param httpContext http context to use for the call
+ * @param content content to be used in the updation
+ * @throws SendException if an error occurs in putting data to the uri
+ */
+
+ public static boolean updateResource(String uri, HttpClient httpClient, HttpContext httpContext,String contentType, String content) throws SendException
+ {
+ boolean resourceUpdated=false;
+ if (uri == null)
+ throw new IllegalArgumentException(
+ Messages.getServerString("send.util.uri.null")); //$NON-NLS-1$
+ if (httpClient == null)
+ throw new IllegalArgumentException(
+ Messages.getServerString("send.util.httpclient.null")); //$NON-NLS-1$
+ try {
+ new URL(uri); // Make sure URL is valid
+
+ HttpPut put = new HttpPut(uri);
+ StringEntity entity = new StringEntity(content);
+ put.setEntity(entity);
+ put.setHeader(HttpConstants.ACCEPT, HttpConstants.CT_APPLICATION_RDF_XML);
+ put.addHeader(HttpConstants.CONTENT_TYPE, contentType);
+ put.addHeader(HttpConstants.CACHE_CONTROL, "max-age=0"); //$NON-NLS-1$
+ HttpResponse resp = httpClient.execute(put);
+
+ try {
+ if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
+ HttpErrorHandler.responseToException(resp);
+ }
+ resourceUpdated=true;
+ HttpResponseUtil.finalize(resp);
+ }finally {
+ try {
+ if (entity != null) {
+ EntityUtils.consume(entity);
+ }
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+
+
+ } catch (Exception e) {
+ String uriLocation = Messages.getServerString("send.util.uri.unidentifiable"); //$NON-NLS-1$
+
+ if(uri != null && !uri.isEmpty())
+ {
+ uriLocation = uri;
+ }
+ throw new SendException(MessageFormat.format(
+ Messages.getServerString("send.util.retrieve.error"), //$NON-NLS-1$
+ uriLocation));
+ }
+
+ return resourceUpdated;
+ }
+
+}
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/TestCore.java b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/TestCore.java
new file mode 100644
index 0000000..75cb5fd
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/TestCore.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ *
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *
+ * Joseph Leong, Sujeet Mishra - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.lyo.rio.trs.tests.utils;
+
+import static org.eclipse.lyo.core.trs.TRSConstants.FileSep;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.Scanner;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.protocol.HttpContext;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.StmtIterator;
+
+public class TestCore {
+
+ protected static final String RESOURCES =
+ "src" + FileSep + "main" + FileSep + "resources";
+ private static final String CONFIG_PROPERTIES =
+ RESOURCES + FileSep + "config.properties";
+
+ protected static void printResource(Resource resource) {
+ for(Statement stmt : resource.listProperties().toList()) {
+ System.out.println(stmt.getSubject().getLocalName() + " " + stmt.getPredicate().getLocalName() + " " + stmt.getObject().toString());
+ }
+ }
+
+ protected static Resource getResource(String uri, HttpClient httpClient, HttpContext httpContext, String acceptType)
+ throws InterruptedException, FetchException
+ {
+ Model model = FetchUtil.fetchResource(uri, httpClient, httpContext, acceptType);
+
+ return model.createResource(uri);
+ }
+
+ protected static Properties getConfigPropertiesInstance()
+ throws FileNotFoundException, IOException
+ {
+ Properties prop = new Properties();
+
+ prop.load(new FileInputStream(CONFIG_PROPERTIES));
+
+ return prop;
+ }
+
+ protected static void terminateTest(String addlMsg, Exception e) {
+ String errorMsg = Messages.getServerString("tests.core.error");
+
+ if(addlMsg != null) {
+ errorMsg += addlMsg;
+ }
+
+ System.out.println(errorMsg);
+ e.printStackTrace();
+
+ System.exit(1);
+ }
+
+ protected StmtIterator getStatementsForProp(Resource res, Property prop) {
+ return res.listProperties(prop);
+ }
+
+ /**
+ * This method is used to read the contents
+ * of a file as a String
+ * @param f
+ * @return
+ */
+ protected static String readFileAsString(File f) {
+
+ StringBuilder stringBuilder = new StringBuilder();
+ Scanner scanner = null;
+ try {
+ scanner = new Scanner(f);
+ } catch (FileNotFoundException e) {
+ return null;
+ }
+
+ try {
+ while (scanner.hasNextLine()) {
+ stringBuilder.append(scanner.nextLine() + "\n");
+ }
+ } finally {
+ scanner.close();
+ }
+ return stringBuilder.toString();
+ }
+}
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/messages.properties b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/messages.properties
new file mode 100644
index 0000000..46c3185
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/java/org/eclipse/lyo/rio/trs/tests/utils/messages.properties
@@ -0,0 +1,48 @@
+###############################################################################
+ # Copyright (c) 2013 IBM Corporation.
+ #
+ # All rights reserved. This program and the accompanying materials
+ # are made available under the terms of the Eclipse Public License v1.0
+ # and Eclipse Distribution License v. 1.0 which accompanies this distribution.
+ #
+ # The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ # and the Eclipse Distribution License is available at
+ # http://www.eclipse.org/org/documents/edl-v10.php.
+ #
+ # Contributors:
+ #
+ # Joseph Leong, Sujeet Mishra - Initial implementation
+ ###############################################################################
+model.util.bytes.null = bytes must not be null
+model.util.model.null = model must not be null
+model.util.inputstream.null = InputStream must not be null
+model.util.outputstream.null = OutputStream must not be null
+
+fetch.util.uri.null = Argument uri must not be null
+fetch.util.httpclient.null = Argument httpClient must not be null
+fetch.util.uri.unidentifiable = Unable to identify URI Location
+fetch.util.retrieve.error = Unable to Fetch/Parse Resource: {0}
+
+send.util.uri.null = Argument uri must not be null
+send.util.httpclient.null = Argument httpClient must not be null
+send.util.uri.unidentifiable = Unable to identify URI Location
+send.util.retrieve.error = Unable to Fetch/Parse Resource: {0}
+
+tests.general.config.properties.missing = Config Properties File Not Found
+tests.general.config.properties.unreadable = Unable to Read Configuration Properties File
+tests.general.trs.fetch.error = Unable to Fetch and Parse TRS Resource
+tests.general.trs.send.error = Unable to create or update the resource
+tests.general.error = Test Failed for Unexpected Reason: {0}
+tests.core.error = Unrecoverable error: Cannot perform prerequisite setup before tests. Exiting.
+
+rdf.model.response.helper.missing.rdf = Missing RDF content for {0}
+rdf.model.response.helper.bad.content.type = Bad Content-Type header for URL: {0}
+rdf.model.response.helper.unparseable.rdf = Unable to parse RDF for {0}: {1}
+
+http.error.handler.null.argument = The response argument must not be null
+
+http.response.util.no.instance = Instance creation is not supported
+
+validators.invalid.trs.changed.property = Invalid trs:changed property
+validators.invalid.trs.change.property = Invalid trs:change property
+validators.missing.trs.change.property = Missing trs:change property \ No newline at end of file
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/resources/config.properties b/org.eclipse.lyo.rio.trs.tests/src/main/resources/config.properties
new file mode 100644
index 0000000..61c8342
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/resources/config.properties
@@ -0,0 +1,23 @@
+##TRS service configuration Parameters##
+
+#Accept Type for obtaining a REST resource.
+acceptType = text/turtle
+
+#End Point for the TRS Service
+configTrsEndpoint = http://localhost:8082/org.eclipse.lyo.rio.trs/rest/trs
+
+##Resource create configuration Parameters##
+#Creation Factory URI provided by the service provider
+configResourceCreationFactoryUri = http://localhost:8082/org.eclipse.lyo.rio.trs/rest/changeRequests/creator
+#Media/Content type to be used for the Creation Factory
+configContentType = application/x-www-form-urlencoded; charset=utf-8
+#Content to be posted to the creator Uri for resource creation
+configResContent = &title=New Defect&description=Creating New Defect
+#Template file for content to pass to creator
+configResContentFile =
+
+##Resource Update configuration Parameters##
+#Media/Content type to be used for the Update
+configUpdateContentType = application/rdf+xml
+#Content to be posted to the resource for Update
+configResUpdateFile = resourceUpdateContent.xml \ No newline at end of file
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/resources/resourceUpdateContent.json b/org.eclipse.lyo.rio.trs.tests/src/main/resources/resourceUpdateContent.json
new file mode 100644
index 0000000..6fe3733
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/resources/resourceUpdateContent.json
@@ -0,0 +1,28 @@
+{"dcterms:created":"2013-01-15T16:14:08.232+05:30",
+"dcterms:description":"Operating system password required.",
+"dcterms:identifier":"40",
+"dcterms:modified":"2013-01-15T16:14:08.232+05:30",
+"dcterms:title":"Password complexity rules 123",
+"dcterms:type":["Defect"],
+"oslc:shortTitle":"Password complexity rules",
+"oslc_cm:approved":false,
+"oslc_cm:closed":false,
+"oslc_cm:fixed":false,
+"oslc_cm:inprogress":false,
+"oslc_cm:reviewed":false,
+"oslc_cm:severity":"Unclassified",
+"oslc_cm:status":"Submitted",
+"oslc_cm:verified":false,
+"prefixes":{"dcterms":"http://purl.org/dc/terms/",
+"foaf":"http://xmlns.com/foaf/0.1/",
+"oslc":"http://open-services.net/ns/core#",
+"oslc_cm":"http://open-services.net/ns/cm#",
+"oslc_qm":"http://open-services.net/ns/qm#",
+"oslc_rm":"http://open-services.net/ns/rm#",
+"oslc_scm":"http://open-services.net/ns/scm#",
+"rdf":"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+"rdfs":"http://www.w3.org/2000/01/rdf-schema#"
+},
+"rdf:about":"",
+"rdf:type":[{"rdf:resource":"http://open-services.net/ns/cm#ChangeRequest"}]
+} \ No newline at end of file
diff --git a/org.eclipse.lyo.rio.trs.tests/src/main/resources/resourceUpdateContent.xml b/org.eclipse.lyo.rio.trs.tests/src/main/resources/resourceUpdateContent.xml
new file mode 100644
index 0000000..dd117aa
--- /dev/null
+++ b/org.eclipse.lyo.rio.trs.tests/src/main/resources/resourceUpdateContent.xml
@@ -0,0 +1,20 @@
+<rdf:RDF xmlns:dcterms="http://purl.org/dc/terms/" xmlns:oslc="http://open-services.net/ns/core#"
+ xmlns:oslc_cm="http://open-services.net/ns/cm#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+<rdf:Description rdf:about="">
+<oslc_cm:fixed>false</oslc_cm:fixed>
+<oslc_cm:verified>true</oslc_cm:verified>
+<oslc_cm:closed>false</oslc_cm:closed>
+<dcterms:description rdf:datatype="http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral">test defect testing</dcterms:description>
+<oslc_cm:approved>false</oslc_cm:approved>
+<oslc_cm:severity>Unclassified</oslc_cm:severity>
+<dcterms:modified>2013-01-22T11:51:19.631+05:30</dcterms:modified>
+<oslc_cm:reviewed>false</oslc_cm:reviewed>
+<dcterms:type>Defect</dcterms:type>
+<oslc_cm:status>Submitted</oslc_cm:status>
+<oslc:shortTitle rdf:datatype="http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral">test defect test</oslc:shortTitle>
+<rdf:type rdf:resource="http://open-services.net/ns/cm#ChangeRequest"/>
+<dcterms:created>2013-01-21T14:11:41.556+05:30</dcterms:created>
+<dcterms:title rdf:datatype="http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral">test defect test</dcterms:title>
+<oslc_cm:inprogress>false</oslc_cm:inprogress>
+</rdf:Description>
+</rdf:RDF> \ No newline at end of file