]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
0ff7ce5fab5e4ab0276d7698a3dfa0706c46a847
[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 (c)) 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
24 package org.collectionspace.services.person.importer;
25
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31
32 import javax.ws.rs.core.MediaType;
33 import javax.ws.rs.core.MultivaluedMap;
34 import javax.ws.rs.core.Response;
35
36 import org.apache.log4j.BasicConfigurator;
37 import org.collectionspace.services.PersonJAXBSchema;
38 import org.collectionspace.services.client.PersonAuthorityClient;
39 import org.collectionspace.services.client.PersonAuthorityClientUtils;
40 import org.collectionspace.services.client.test.ServiceRequestType;
41 import org.collectionspace.services.person.PersonauthoritiesCommon;
42 import org.collectionspace.services.person.PersonauthoritiesCommonList;
43 import org.collectionspace.services.person.PersonsCommon;
44 import org.collectionspace.services.person.PersonsCommonList;
45 import org.jboss.resteasy.client.ClientResponse;
46 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
47 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50
51 /**
52  * PersonAuthorityServiceTest, carries out tests against a
53  * deployed and running PersonAuthority Service.
54  *
55  * $LastChangedRevision: 753 $
56  * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
57  */
58 public class PersonAuthorityBaseImport {
59     private static final Logger logger =
60         LoggerFactory.getLogger(PersonAuthorityBaseImport.class);
61
62     // Instance variables specific to this test.
63     private PersonAuthorityClient client = new PersonAuthorityClient();
64
65     public void createPersonAuthority(String personAuthorityName, 
66                 List<Map<String, String>> personMaps ) {
67
68         // Expected status code: 201 Created
69         int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode();
70         // Type of service request being tested
71         ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE;
72
73         if(logger.isDebugEnabled()){
74                 logger.debug("Import: Create personAuthority: \"" + personAuthorityName +"\"");
75         }
76         String basePersonRefName = 
77                 PersonAuthorityClientUtils.createPersonAuthRefName(
78                                 personAuthorityName);
79         String fullPersonRefName = basePersonRefName+"'"+personAuthorityName+"'";
80         MultipartOutput multipart = 
81                 PersonAuthorityClientUtils.createPersonAuthorityInstance(
82                                 personAuthorityName, fullPersonRefName, client.getCommonPartName());
83         ClientResponse<Response> res = client.create(multipart);
84
85         int statusCode = res.getStatus();
86
87         if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
88                 throw new RuntimeException("Could not create enumeration: \""+personAuthorityName
89                                 +"\" "+ PersonAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
90         }
91         if(statusCode != EXPECTED_STATUS_CODE) {
92                 throw new RuntimeException("Unexpected Status when creating enumeration: \""
93                                 +personAuthorityName +"\", Status:"+ statusCode);
94         }
95
96         // Store the ID returned from this create operation
97         // for additional tests below.
98         String newPersonAuthorityId = PersonAuthorityClientUtils.extractId(res);
99         if(logger.isDebugEnabled()){
100                 logger.debug("Import: Created personAuthorityulary: \"" + personAuthorityName +"\" ID:"
101                                 +newPersonAuthorityId );
102         }
103         for(Map<String,String> personMap : personMaps){
104                 PersonAuthorityClientUtils.createItemInAuthority(
105                                 newPersonAuthorityId, basePersonRefName, personMap, client);
106         }
107     }
108     
109         public static void main(String[] args) {
110                 
111                 BasicConfigurator.configure();
112                 logger.info("PersonAuthorityBaseImport starting...");
113
114                 PersonAuthorityBaseImport pabi = new PersonAuthorityBaseImport();
115                 final String demoPersonAuthorityName = "Demo Person Authority";
116
117                 /* Strings are:  
118                         shortName, longName, nameAdditions, contactName, 
119                 foundingDate, dissolutionDate, foundingPlace, function, description
120          */             
121         Map<String, String> johnWayneMap = new HashMap<String,String>();
122         johnWayneMap.put(PersonJAXBSchema.FORE_NAME, "John");
123         johnWayneMap.put(PersonJAXBSchema.SUR_NAME, "Wayne");
124         johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
125         johnWayneMap.put(PersonJAXBSchema.BIRTH_DATE, "May 26, 1907");
126         johnWayneMap.put(PersonJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
127         johnWayneMap.put(PersonJAXBSchema.DEATH_DATE, "June 11, 1979");
128         johnWayneMap.put(PersonJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
129                         "known by his stage name John Wayne, was an American film actor, director " +
130                         "and producer. He epitomized rugged masculinity and has become an enduring " +
131                         "American icon. He is famous for his distinctive voice, walk and height. " +
132                         "He was also known for his conservative political views and his support in " +
133                         "the 1950s for anti-communist positions.");
134         Map<String, String> patrickSchmitzMap = new HashMap<String,String>();
135         patrickSchmitzMap.put(PersonJAXBSchema.FORE_NAME, "Patrick");
136         patrickSchmitzMap.put(PersonJAXBSchema.SUR_NAME, "Schmitz");
137         patrickSchmitzMap.put(PersonJAXBSchema.GENDER, "male");
138         patrickSchmitzMap.put(PersonJAXBSchema.BIRTH_DATE, "7/15/1960");
139         patrickSchmitzMap.put(PersonJAXBSchema.BIRTH_PLACE, "MI");
140         Map<String, String> janeDoeMap = new HashMap<String,String>();
141         janeDoeMap.put(PersonJAXBSchema.FORE_NAME, "Jane");
142         janeDoeMap.put(PersonJAXBSchema.SUR_NAME, "Doe");
143         janeDoeMap.put(PersonJAXBSchema.GENDER, "female");
144         janeDoeMap.put(PersonJAXBSchema.BIRTH_DATE, "7/04/1901");
145         janeDoeMap.put(PersonJAXBSchema.DEATH_DATE, "4/01/1999");
146         janeDoeMap.put(PersonJAXBSchema.BIRTH_PLACE, "Anytown, USA");
147         janeDoeMap.put(PersonJAXBSchema.BIRTH_PLACE, "Nowheresville, USA");
148         List<Map<String, String>> personsMaps = 
149                 Arrays.asList(johnWayneMap, patrickSchmitzMap, janeDoeMap );
150
151         pabi.createPersonAuthority(demoPersonAuthorityName, personsMaps);
152
153                 logger.info("PersonAuthorityBaseImport complete.");
154         }
155 }