]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
fcd0b7de83d6fbc2b9a33bbae19b27fc08ea1e6f
[tmp/jakarta-migration.git] /
1 /**
2  * This document is a part of the source code and related artifacts
3  * for CollectionSpace, an open source collections management system
4  * for museums and related institutions:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright © 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 package org.collectionspace.services.client.test;
24
25 import org.collectionspace.services.client.CollectionSpaceClient;
26 import org.collectionspace.services.client.PottagClient;
27 import org.collectionspace.services.client.PayloadOutputPart;
28 import org.collectionspace.services.client.PoxPayloadOut;
29 import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils;
30 import org.collectionspace.services.jaxb.AbstractCommonList;
31 import org.collectionspace.services.pottag.PottagsCommon;
32
33 import org.testng.Assert;
34
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37
38 /**
39  * PottagServiceTest, carries out tests against a
40  * deployed and running Pottag (aka Pot Tag) Service.
41  *
42  * $LastChangedRevision$
43  * $LastChangedDate$
44  */
45 public class PottagServiceTest extends AbstractPoxServiceTestImpl<AbstractCommonList, PottagsCommon> {
46
47     /** The logger. */
48     private final String CLASS_NAME = PottagServiceTest.class.getName();
49     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
50     // Instance variables specific to this test.
51     private final static String CURRENT_DATE_UTC = GregorianCalendarDateTimeUtils.currentDateUTC();
52
53     /* (non-Javadoc)
54      * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
55      */
56     @Override
57     protected CollectionSpaceClient getClientInstance() throws Exception {
58         return new PottagClient();
59     }
60
61     @Override
62         protected void compareReadInstances(PottagsCommon original, PottagsCommon pottagCommon) throws Exception {
63         if (logger.isDebugEnabled()) {
64             logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n"
65                     + "UTF-8 data received=" + pottagCommon.getLabelData());
66         }
67
68         Assert.assertEquals(pottagCommon.getLabelData(), getUTF8DataFragment(),
69                 "UTF-8 data retrieved '" + pottagCommon.getLabelData()
70                 + "' does not match expected data '" + getUTF8DataFragment());          
71         }    
72      
73         @Override
74         protected void compareUpdatedInstances(PottagsCommon pottagCommon,
75                         PottagsCommon updatedPottagCommon) throws Exception {
76         // Check selected fields in the updated common part.
77         Assert.assertEquals(updatedPottagCommon.getFamily(), pottagCommon.getFamily(),
78                 "Data in updated object did not match submitted data.");
79
80         if (logger.isDebugEnabled()) {
81             logger.debug("UTF-8 data sent=" + pottagCommon.getLabelData() + "\n"
82                     + "UTF-8 data received=" + updatedPottagCommon.getLabelData());
83         }
84         Assert.assertTrue(updatedPottagCommon.getLabelData().contains(getUTF8DataFragment()),
85                 "UTF-8 data retrieved '" + updatedPottagCommon.getLabelData() + "' does not contain expected data '" + getUTF8DataFragment());
86         Assert.assertEquals(updatedPottagCommon.getLabelData(),
87                 pottagCommon.getLabelData(), "Data in updated object did not match submitted data.");
88         }
89     
90     // ---------------------------------------------------------------
91     // Utility methods used by tests above
92     // ---------------------------------------------------------------
93     
94     @Override
95     public String getServiceName() {
96         return PottagClient.SERVICE_NAME;
97     }
98
99     /* (non-Javadoc)
100      * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
101      */
102     @Override
103     public String getServicePathComponent() {
104         return PottagClient.SERVICE_PATH_COMPONENT;
105     }
106
107     @Override
108     protected PoxPayloadOut createInstance(String identifier) throws Exception {
109         return createPottagInstance(identifier);
110     }
111
112     /**
113      * Creates the pottag instance.
114      *
115      * @param identifier the identifier
116      * @return the multipart output
117      * @throws Exception 
118      */
119     private PoxPayloadOut createPottagInstance(String identifier) throws Exception {
120         return createPottagInstance(
121                 "family-" + identifier,
122                 "returnDate-" + identifier);
123     }
124
125     /**
126      * Creates the pottag instance.
127      *
128      * @param familyName the pottag family
129      * @param returnDate the return date
130      * @return the multipart output
131      * @throws Exception 
132      */
133     private PoxPayloadOut createPottagInstance(String familyName,
134             String returnDate) throws Exception {
135
136         PottagsCommon pottagCommon = new PottagsCommon();
137         pottagCommon.setFamily(familyName);
138         pottagCommon.setLocale("Mexico");
139         pottagCommon.setLabelData(getUTF8DataFragment());
140
141         PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent());
142         PayloadOutputPart commonPart =
143                 multipart.addPart(new PottagClient().getCommonPartName(), pottagCommon);
144
145         if (logger.isDebugEnabled()) {
146             logger.debug("to be created, pottag common");
147             logger.debug(objectAsXmlString(pottagCommon, PottagsCommon.class));
148         }
149
150         return multipart;
151     }
152
153         @Override
154         public void CRUDTests(String testName) {
155                 // TODO Auto-generated method stub
156                 
157         }
158
159         @Override
160         protected PoxPayloadOut createInstance(String commonPartName,
161                         String identifier) throws Exception {
162         PoxPayloadOut result = createPottagInstance(identifier);
163         return result;
164         }
165
166         @Override
167         protected PottagsCommon updateInstance(PottagsCommon commonPartObject) {
168                 // TODO Auto-generated method stub
169                 return null;
170         }
171
172         @Override
173         protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) throws Exception {
174                 // TODO Auto-generated method stub
175                 return null;
176         }
177 }