From: Richard Millet Date: Mon, 2 Jan 2012 20:21:08 +0000 (+0000) Subject: CSPACE-4748, CSPACE-4750: Added a new class to the http client hierarchy to consolida... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=6ce33551ad1539aa9462ceff52c6cacf4536df78;p=tmp%2Fjakarta-migration.git CSPACE-4748, CSPACE-4750: Added a new class to the http client hierarchy to consolidate/share existing code that deals with loading/creating xml payloads for the tests. --- 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 index 000000000..5352d35b9 --- /dev/null +++ b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractGenericServiceTestImpl.java @@ -0,0 +1,49 @@ +package org.collectionspace.services.client.test; + +import org.collectionspace.services.client.CollectionSpaceClient; +import org.collectionspace.services.client.CollectionSpaceCommonListPoxProxy; +import org.collectionspace.services.client.PayloadInputPart; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.jboss.resteasy.client.ClientResponse; +import org.testng.Assert; + +/* + * CPT - Common Part Type + */ +public abstract class AbstractGenericServiceTestImpl extends AbstractServiceTestImpl { + public CPT getCommonTypeInstance() { + CPT result = null; + return result; + } + + public CPT extractCommonPartValue(ClientResponse res) + throws Exception { + CollectionSpaceClient client = this.getClientInstance(); + PayloadInputPart payloadInputPart = extractPart(res, client.getCommonPartName()); + Object obj = null; + if (payloadInputPart != null) { + obj = payloadInputPart.getBody(); + } + Assert.assertNotNull(obj, + "Body of " + client.getCommonPartName() + " part was unexpectedly null."); + CPT commonPartTypeInstance = (CPT) obj; + Assert.assertNotNull(commonPartTypeInstance, + client.getCommonPartName() + " part was unexpectedly null."); + return commonPartTypeInstance; + } + + private PayloadInputPart extractPart(ClientResponse res, String partLabel) + throws Exception { + if (getLogger().isDebugEnabled()) { + getLogger().debug("Reading part " + partLabel + " ..."); + } + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PayloadInputPart payloadInputPart = input.getPart(partLabel); + Assert.assertNotNull(payloadInputPart, + "Part " + partLabel + " was unexpectedly null."); + return payloadInputPart; + } + + +}