]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4748, CSPACE-4750: Added a new class to the http client hierarchy to consolida...
authorRichard Millet <richard.millet@berkeley.edu>
Mon, 2 Jan 2012 20:21:08 +0000 (20:21 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Mon, 2 Jan 2012 20:21:08 +0000 (20:21 +0000)
services/client/src/main/java/org/collectionspace/services/client/test/AbstractGenericServiceTestImpl.java [new file with mode: 0644]

diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractGenericServiceTestImpl.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractGenericServiceTestImpl.java
new file mode 100644 (file)
index 0000000..5352d35
--- /dev/null
@@ -0,0 +1,49 @@
+package org.collectionspace.services.client.test;\r
+\r
+import org.collectionspace.services.client.CollectionSpaceClient;\r
+import org.collectionspace.services.client.CollectionSpaceCommonListPoxProxy;\r
+import org.collectionspace.services.client.PayloadInputPart;\r
+import org.collectionspace.services.client.PoxPayloadIn;\r
+import org.collectionspace.services.jaxb.AbstractCommonList;\r
+import org.jboss.resteasy.client.ClientResponse;\r
+import org.testng.Assert;\r
+\r
+/*\r
+ * CPT - Common Part Type\r
+ */\r
+public abstract class AbstractGenericServiceTestImpl<CPT> extends AbstractServiceTestImpl {\r
+       public CPT getCommonTypeInstance() {\r
+               CPT result = null;\r
+               return result;\r
+       }\r
+       \r
+    public CPT extractCommonPartValue(ClientResponse<String> res)\r
+            throws Exception {\r
+               CollectionSpaceClient<AbstractCommonList, CollectionSpaceCommonListPoxProxy> client = this.getClientInstance();\r
+            PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName());\r
+            Object obj = null;\r
+            if (payloadInputPart != null) {\r
+               obj = payloadInputPart.getBody();\r
+            }\r
+            Assert.assertNotNull(obj,\r
+                    "Body of " + client.getCommonPartName() + " part was unexpectedly null.");\r
+            CPT commonPartTypeInstance = (CPT) obj;\r
+            Assert.assertNotNull(commonPartTypeInstance,\r
+                    client.getCommonPartName() + " part was unexpectedly null.");\r
+            return commonPartTypeInstance;\r
+        }\r
+    \r
+    private PayloadInputPart extractPart(ClientResponse<String> res, String partLabel)\r
+            throws Exception {\r
+            if (getLogger().isDebugEnabled()) {\r
+               getLogger().debug("Reading part " + partLabel + " ...");\r
+            }\r
+            PoxPayloadIn input = new PoxPayloadIn(res.getEntity());\r
+            PayloadInputPart payloadInputPart = input.getPart(partLabel);\r
+            Assert.assertNotNull(payloadInputPart,\r
+                    "Part " + partLabel + " was unexpectedly null.");\r
+            return payloadInputPart;\r
+        }\r
+    \r
+       \r
+}\r