]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
7f4bc33900d66548f13c397197f98b73514c31c4
[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.location.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.LocationJAXBSchema;
38 import org.collectionspace.services.client.LocationAuthorityClient;
39 import org.collectionspace.services.client.LocationAuthorityClientUtils;
40 import org.collectionspace.services.client.PoxPayloadOut;
41 import org.collectionspace.services.client.test.ServiceRequestType;
42 import org.collectionspace.services.location.LocationauthoritiesCommon;
43 import org.collectionspace.services.location.LocationauthoritiesCommonList;
44 import org.collectionspace.services.location.LocationsCommon;
45 import org.collectionspace.services.location.LocationsCommonList;
46 import org.jboss.resteasy.client.ClientResponse;
47 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50
51 /**
52  * LocationAuthorityServiceTest, carries out tests against a
53  * deployed and running LocationAuthority Service.
54  *
55  * $LastChangedRevision: 753 $
56  * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
57  */
58 public class LocationAuthorityBaseImport {
59     private static final Logger logger =
60         LoggerFactory.getLogger(LocationAuthorityBaseImport.class);
61
62     // Instance variables specific to this test.
63     private LocationAuthorityClient client = new LocationAuthorityClient();
64
65     public void createLocationAuthority(String locationAuthorityName, 
66                 List<Map<String, String>> locationMaps ) {
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 locationAuthority: \"" + locationAuthorityName +"\"");
75         }
76
77
78
79         String displaySuffix = "displayName-" + System.currentTimeMillis(); //TODO: this is just made-up.  Laramie20100728 temp fix, made-up displaySuffix.
80         String baseLocationRefName = LocationAuthorityClientUtils.createLocationAuthRefName(locationAuthorityName, displaySuffix);//TODO: make displaySuffix correct. Laramie20100729 temp fix, made-up displaySuffix.  was (locationAuthorityName, false);
81         String fullLocationRefName = LocationAuthorityClientUtils.createLocationAuthRefName(locationAuthorityName, displaySuffix);//TODO: make displaySuffix correct. Laramie20100729 temp fix, made-up displaySuffix.  was (locationAuthorityName, true);
82
83         PoxPayloadOut multipart =  LocationAuthorityClientUtils.createLocationAuthorityInstance(locationAuthorityName, fullLocationRefName, client.getCommonPartName());
84         ClientResponse<Response> res = client.create(multipart);
85
86         int statusCode = res.getStatus();
87
88         if(!REQUEST_TYPE.isValidStatusCode(statusCode)) {
89                 throw new RuntimeException("Could not create enumeration: \""+locationAuthorityName
90                                 +"\" "+ LocationAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
91         }
92         if(statusCode != EXPECTED_STATUS_CODE) {
93                 throw new RuntimeException("Unexpected Status when creating enumeration: \""
94                                 +locationAuthorityName +"\", Status:"+ statusCode);
95         }
96
97         // Store the ID returned from this create operation
98         // for additional tests below.
99         String newLocationAuthorityId = LocationAuthorityClientUtils.extractId(res);
100         if(logger.isDebugEnabled()){
101                 logger.debug("Import: Created locationAuthorityulary: \"" + locationAuthorityName +"\" ID:"
102                                 +newLocationAuthorityId );
103         }
104         for(Map<String,String> locationMap : locationMaps){
105                 LocationAuthorityClientUtils.createItemInAuthority(
106                                 newLocationAuthorityId, baseLocationRefName, locationMap, client);
107         }
108     }
109     
110         public static void main(String[] args) {
111                 
112                 BasicConfigurator.configure();
113                 logger.info("LocationAuthorityBaseImport starting...");
114
115                 LocationAuthorityBaseImport pabi = new LocationAuthorityBaseImport();
116                 final String demoLocationAuthorityName = "Demo Location Authority";
117
118                 /* Strings are:  
119                         shortName, longName, nameAdditions, contactName, 
120                 foundingDate, dissolutionDate, foundingPlace, function, description
121          */             
122
123
124         /*   TODO: Laramie20100728 This is broken.  Removing for now.
125         Map<String, String> johnWayneMap = new HashMap<String,String>();
126         johnWayneMap.put(LocationJAXBSchema.FORE_NAME, "John");
127         johnWayneMap.put(LocationJAXBSchema.SUR_NAME, "Wayne");
128         johnWayneMap.put(LocationJAXBSchema.GENDER, "male");
129         johnWayneMap.put(LocationJAXBSchema.BIRTH_DATE, "May 26, 1907");
130         johnWayneMap.put(LocationJAXBSchema.BIRTH_PLACE, "Winterset, Iowa");
131         johnWayneMap.put(LocationJAXBSchema.DEATH_DATE, "June 11, 1979");
132         johnWayneMap.put(LocationJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" +
133                         "known by his stage name John Wayne, was an American film actor, director " +
134                         "and producer. He epitomized rugged masculinity and has become an enduring " +
135                         "American icon. He is famous for his distinctive voice, walk and height. " +
136                         "He was also known for his conservative political views and his support in " +
137                         "the 1950s for anti-communist positions.");
138         Map<String, String> patrickSchmitzMap = new HashMap<String,String>();
139         patrickSchmitzMap.put(LocationJAXBSchema.FORE_NAME, "Patrick");
140         patrickSchmitzMap.put(LocationJAXBSchema.SUR_NAME, "Schmitz");
141         patrickSchmitzMap.put(LocationJAXBSchema.GENDER, "male");
142         patrickSchmitzMap.put(LocationJAXBSchema.BIRTH_DATE, "7/15/1960");
143         patrickSchmitzMap.put(LocationJAXBSchema.BIRTH_PLACE, "MI");
144         Map<String, String> janeDoeMap = new HashMap<String,String>();
145         janeDoeMap.put(LocationJAXBSchema.FORE_NAME, "Jane");
146         janeDoeMap.put(LocationJAXBSchema.SUR_NAME, "Doe");
147         janeDoeMap.put(LocationJAXBSchema.GENDER, "female");
148         janeDoeMap.put(LocationJAXBSchema.BIRTH_DATE, "7/04/1901");
149         janeDoeMap.put(LocationJAXBSchema.DEATH_DATE, "4/01/1999");
150         janeDoeMap.put(LocationJAXBSchema.BIRTH_PLACE, "Anytown, USA");
151         janeDoeMap.put(LocationJAXBSchema.BIRTH_PLACE, "Nowheresville, USA");
152         List<Map<String, String>> locationsMaps = 
153                 Arrays.asList(johnWayneMap, patrickSchmitzMap, janeDoeMap );
154
155         pabi.createLocationAuthority(demoLocationAuthorityName, locationsMaps);
156         */
157         logger.info("LocationAuthorityBaseImport test is empty because LocationJAXBSchema had code changes.  See org.collectionspace.services.location.importer.LocationAuthorityBaseImport");
158                 logger.info("LocationAuthorityBaseImport complete.");
159         }
160 }