]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-2975: Services tenant bindings configuration now specifies validator handlers...
authorAron Roberts <aron@socrates.berkeley.edu>
Sat, 2 Oct 2010 00:45:59 +0000 (00:45 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Sat, 2 Oct 2010 00:45:59 +0000 (00:45 +0000)
services/common/src/main/config/services/tenant-bindings.xml
services/person/client/src/main/java/org/collectionspace/services/client/PersonAuthorityClientUtils.java
services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java

index fdce5391aaf38677b7dbdb816c6316479478daef..cb5e9f8b3d1e810db13c774271ba954ec251fc86 100644 (file)
             <service:documentHandler xmlns:service='http://collectionspace.org/services/common/service'>
                 org.collectionspace.services.organization.nuxeo.OrgAuthorityDocumentModelHandler
             </service:documentHandler>
+            <service:validatorHandler xmlns:service='http://collectionspace.org/services/common/service'>
+                org.collectionspace.services.organization.nuxeo.OrgAuthorityValidatorHandler
+            </service:validatorHandler>
             <service:object id="1" name="Orgauthority" version="0.1"
                             xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:part id="0" control_group="Managed"
             <service:documentHandler xmlns:service='http://collectionspace.org/services/common/service'>
                 org.collectionspace.services.person.nuxeo.PersonAuthorityDocumentModelHandler
             </service:documentHandler>
+            <service:validatorHandler xmlns:service='http://collectionspace.org/services/common/service'>
+                org.collectionspace.services.person.nuxeo.PersonAuthorityValidatorHandler
+            </service:validatorHandler>
             <service:object id="1" name="Personauthority" version="0.1"
                             xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:part id="0" control_group="Managed"
             <service:documentHandler xmlns:service='http://collectionspace.org/services/common/service'>
                 org.collectionspace.services.location.nuxeo.LocationAuthorityDocumentModelHandler
             </service:documentHandler>
+            <service:validatorHandler xmlns:service='http://collectionspace.org/services/common/service'>
+                org.collectionspace.services.location.nuxeo.LocationAuthorityValidatorHandler
+            </service:validatorHandler>
             <service:object id="1" name="Locationauthority" version="0.1"
                             xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:part id="0" control_group="Managed"
             <service:documentHandler xmlns:service='http://collectionspace.org/services/common/service'>
                 org.collectionspace.services.organization.nuxeo.OrgAuthorityDocumentModelHandler
             </service:documentHandler>
+            <service:validatorHandler xmlns:service='http://collectionspace.org/services/common/service'>
+                org.collectionspace.services.organization.nuxeo.OrgAuthorityValidatorHandler
+            </service:validatorHandler>
             <service:object id="1" name="Orgauthority" version="0.1"
                             xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:part id="0" control_group="Managed"
             <service:documentHandler xmlns:service='http://collectionspace.org/services/common/service'>
                 org.collectionspace.services.person.nuxeo.PersonAuthorityDocumentModelHandler
             </service:documentHandler>
+            <service:validatorHandler xmlns:service='http://collectionspace.org/services/common/service'>
+                org.collectionspace.services.person.nuxeo.PersonAuthorityValidatorHandler
+            </service:validatorHandler>
             <service:object id="1" name="Personauthority" version="0.1"
                             xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:part id="0" control_group="Managed"
             <service:documentHandler xmlns:service='http://collectionspace.org/services/common/service'>
                 org.collectionspace.services.location.nuxeo.LocationAuthorityDocumentModelHandler
             </service:documentHandler>
+            <service:validatorHandler xmlns:service='http://collectionspace.org/services/common/service'>
+                org.collectionspace.services.location.nuxeo.LocationAuthorityValidatorHandler
+            </service:validatorHandler>
             <service:object id="1" name="Locationauthority" version="0.1"
                             xmlns:service='http://collectionspace.org/services/common/service'>
                 <service:part id="0" control_group="Managed"
index 60f1723176b9557d62f30a33b2bd7ab48a3b38b6..903ad2c9a45a31f5469574acdf857a5162b16726 100644 (file)
@@ -252,37 +252,42 @@ public class PersonAuthorityClientUtils {
                person.setBirthPlace(value);\r
         if((value = (String)personInfo.get(PersonJAXBSchema.DEATH_PLACE))!=null)\r
                person.setDeathPlace(value);\r
-        if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.GROUPS))!=null) {\r
-                GroupList groupsList = new GroupList();\r
-                List<String> groups = groupsList.getGroup();\r
-               groups.addAll(values);\r
-                person.setGroups(groupsList);\r
-        }\r
-        if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.NATIONALITIES))!=null) {\r
-                NationalityList nationalitiesList = new NationalityList();\r
-                List<String> nationalities = nationalitiesList.getNationality();\r
-               nationalities.addAll(values);\r
-                person.setNationalities(nationalitiesList);\r
-        }\r
         if((value = (String)personInfo.get(PersonJAXBSchema.GENDER))!=null)\r
                person.setGender(value);\r
-        if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.OCCUPATIONS))!=null) {\r
-                OccupationList occupationsList = new OccupationList();\r
-                List<String> occupations = occupationsList.getOccupation();\r
-               occupations.addAll(values);\r
-                person.setOccupations(occupationsList);\r
-        }\r
-        if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.SCHOOLS_OR_STYLES))!=null) {\r
-                SchoolOrStyleList schoolOrStyleList = new SchoolOrStyleList();\r
-                List<String> schoolsOrStyles = schoolOrStyleList.getSchoolOrStyle();\r
-               schoolsOrStyles.addAll(values);\r
-                person.setSchoolsOrStyles(schoolOrStyleList);\r
-        }\r
-        if((value = (String)personInfo.get(PersonJAXBSchema.BIO_NOTE))!=null)\r
+         if((value = (String)personInfo.get(PersonJAXBSchema.BIO_NOTE))!=null)\r
                person.setBioNote(value);\r
         if((value = (String)personInfo.get(PersonJAXBSchema.NAME_NOTE))!=null)\r
                person.setNameNote(value);\r
         \r
+        if (personRepeatablesInfo != null) {\r
+            if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.GROUPS))!=null) {\r
+                    GroupList groupsList = new GroupList();\r
+                    List<String> groups = groupsList.getGroup();\r
+                    groups.addAll(values);\r
+                    person.setGroups(groupsList);\r
+            }\r
+            if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.NATIONALITIES))!=null) {\r
+                    NationalityList nationalitiesList = new NationalityList();\r
+                    List<String> nationalities = nationalitiesList.getNationality();\r
+                    nationalities.addAll(values);\r
+                    person.setNationalities(nationalitiesList);\r
+            }\r
+\r
+            if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.OCCUPATIONS))!=null) {\r
+                    OccupationList occupationsList = new OccupationList();\r
+                    List<String> occupations = occupationsList.getOccupation();\r
+                    occupations.addAll(values);\r
+                    person.setOccupations(occupationsList);\r
+            }\r
+            if((values = (List<String>)personRepeatablesInfo.get(PersonJAXBSchema.SCHOOLS_OR_STYLES))!=null) {\r
+                    SchoolOrStyleList schoolOrStyleList = new SchoolOrStyleList();\r
+                    List<String> schoolsOrStyles = schoolOrStyleList.getSchoolOrStyle();\r
+                    schoolsOrStyles.addAll(values);\r
+                    person.setSchoolsOrStyles(schoolOrStyleList);\r
+            }\r
+        }\r
+\r
+        \r
         MultipartOutput multipart = new MultipartOutput();\r
         OutputPart commonPart = multipart.addPart(person,\r
             MediaType.APPLICATION_XML_TYPE);\r
@@ -414,6 +419,7 @@ public class PersonAuthorityClientUtils {
      */\r
     public static String extractId(ClientResponse<Response> res) {\r
         MultivaluedMap<String, Object> mvm = res.getMetadata();\r
+        // FIXME: This may throw an NPE if the Location: header isn't present\r
         String uri = (String) ((ArrayList<Object>) mvm.get("Location")).get(0);\r
         if(logger.isDebugEnabled()){\r
                logger.debug("extractId:uri=" + uri);\r
index 5efbc897a502c03f7c5339f4a4c2d0774e356adf..456710a529a75a80b3a81ec6c821a9ff5e1ad9ac 100644 (file)
@@ -223,7 +223,36 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
     }
 
     /**
-     * Creates the item in authority.
+     * Creates the item with an empty short identifier.
+     *
+     * @param testName the test name
+     */
+ /*
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+        groups = {"create"}, dependsOnMethods = {"create"})
+    public void createItemWithEmptyShortId(String testName) {
+        if (logger.isDebugEnabled()) {
+            logger.debug(testBanner(testName, CLASS_NAME));
+        }
+        setupCreate();
+
+        // Fill the property map
+        String shortId = "";
+        Map<String, String> fieldProperties = new HashMap<String,String>();
+        fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
+        fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME, "Rod Beck");
+        fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
+        fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "RodBeck");
+
+        final Map NULL_REPEATABLE_FIELD_PROPERTIES = null;
+        String newID = createItemInAuthority(knownResourceId, knownResourceRefName,
+                shortId, fieldProperties, NULL_REPEATABLE_FIELD_PROPERTIES);
+        allResourceIdsCreated.add(newID);
+    }
+*/
+
+    /**
+     * Creates an item in an authority, using test data.
      *
      * @param vcsid the vcsid
      * @param authRefName the auth ref name
@@ -236,9 +265,6 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
             logger.debug(testName + ":"+vcsid+"...");
         }
 
-        // Submit the request to the service and store the response.
-        PersonAuthorityClient client = new PersonAuthorityClient();
-        
         Map<String, String> johnWayneMap = new HashMap<String,String>();
         //
         // Fill the property map
@@ -249,7 +275,7 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
         johnWayneMap.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
         johnWayneMap.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, "JohnWayne");
         johnWayneMap.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
-        
+
         johnWayneMap.put(PersonJAXBSchema.FORE_NAME, TEST_FORE_NAME);
         johnWayneMap.put(PersonJAXBSchema.SUR_NAME, TEST_SUR_NAME);
         johnWayneMap.put(PersonJAXBSchema.GENDER, "male");
@@ -269,9 +295,33 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
         johnWayneGroups.add("Scottish");
         johnWayneRepeatablesMap.put(PersonJAXBSchema.GROUPS, johnWayneGroups);
 
+        return createItemInAuthority(vcsid, authRefName, shortId, johnWayneMap, johnWayneRepeatablesMap);
+
+    }
+
+    /**
+     * Creates an item in an authority.
+     *
+     * @param vcsid the vcsid
+     * @param authRefName the auth ref name
+     * @param itemFieldProperties a set of properties specifying the values of fields.
+     * @param itemRepeatableFieldProperties a set of properties specifying the values of repeatable fields.
+     * @return the string
+     */
+    private String createItemInAuthority(String vcsid, String authRefName, String shortId,
+            Map itemFieldProperties, Map itemRepeatableFieldProperties) {
+
+        final String testName = "createItemInAuthority";
+        if(logger.isDebugEnabled()){
+            logger.debug(testName + ":"+vcsid+"...");
+        }
+
+        // Submit the request to the service and store the response.
+        PersonAuthorityClient client = new PersonAuthorityClient();
+        
         MultipartOutput multipart = 
-            PersonAuthorityClientUtils.createPersonInstance(vcsid, authRefName, johnWayneMap,
-                johnWayneRepeatablesMap, client.getItemCommonPartName() );
+            PersonAuthorityClientUtils.createPersonInstance(vcsid, authRefName, itemFieldProperties,
+                itemRepeatableFieldProperties, client.getItemCommonPartName() );
 
         String newID = null;
         ClientResponse<Response> res = client.createItem(vcsid, multipart);
@@ -502,6 +552,102 @@ public class PersonAuthorityServiceTest extends AbstractServiceTestImpl {
     }
 */
 
+    /**
+     * Attempts to create an authority with an short identifier that contains
+     * non-word characters.
+     *
+     * @param testName the test name
+     */
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+        groups = {"create", "nonWordCharsInShortId"})
+    public void createWithShortIdNonWordChars(String testName) throws Exception {
+        if (logger.isDebugEnabled()) {
+            logger.debug(testBanner(testName, CLASS_NAME));
+        }
+        EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST;
+        REQUEST_TYPE = ServiceRequestType.CREATE;
+        testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE);
+
+        // Create the payload to be included in the body of the request
+        PersonAuthorityClient client = new PersonAuthorityClient();
+        String shortId = createIdentifier() + "*" + createIdentifier();
+       String displayName = "displayName-" + shortId;
+        MultipartOutput multipart =
+            PersonAuthorityClientUtils.createPersonAuthorityInstance(
+           displayName, shortId, client.getCommonPartName());
+
+        // Submit the request to the service and store the response.
+       ClientResponse<Response> res = client.create(multipart);
+
+       // Check the status code of the response: does it match
+       // the expected response(s)?
+        try {
+            int statusCode = res.getStatus();
+            if(logger.isDebugEnabled()){
+                logger.debug(testName + ": status = " + statusCode);
+            }
+            Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
+                    invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
+            Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
+       } finally {
+               res.releaseConnection();
+       }
+
+    }
+
+    /**
+     * Attempts to create an item with an short identifier that contains
+     * non-word characters.
+     *
+     * @param testName the test name
+     */
+    @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
+        groups = {"create", "nonWordCharsInShortId"}, dependsOnMethods = {"create"})
+    public void createItemWithShortIdNonWordChars(String testName) {
+        if (logger.isDebugEnabled()) {
+            logger.debug(testBanner(testName, CLASS_NAME));
+        }
+        EXPECTED_STATUS_CODE = STATUS_BAD_REQUEST;
+        REQUEST_TYPE = ServiceRequestType.CREATE;
+        testSetup(EXPECTED_STATUS_CODE, REQUEST_TYPE);
+
+         PersonAuthorityClient client = new PersonAuthorityClient();
+
+        // Create the payload to be included in the body of the request
+        String shortId = "7-Eleven";
+        Map<String, String> fieldProperties = new HashMap<String,String>();
+        fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME_COMPUTED, "false");
+        fieldProperties.put(PersonJAXBSchema.DISPLAY_NAME, shortId);
+        fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME_COMPUTED, "false");
+        fieldProperties.put(PersonJAXBSchema.SHORT_DISPLAY_NAME, shortId);
+        fieldProperties.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId);
+        final Map NULL_REPEATABLE_FIELD_PROPERTIES = null;
+        MultipartOutput multipart =
+            PersonAuthorityClientUtils.createPersonInstance(knownResourceId,
+                knownResourceRefName, fieldProperties,
+                NULL_REPEATABLE_FIELD_PROPERTIES, client.getItemCommonPartName());
+        
+        // Send the request and receive a response
+        ClientResponse<Response> res = client.createItem(knownResourceId, multipart);
+
+        // Check the status code of the response: does it match
+       // the expected response(s)?
+        try {
+            int statusCode = res.getStatus();
+            // Check the status code of the response: does it match
+            // the expected response(s)?
+            if(logger.isDebugEnabled()){
+                logger.debug(testName + ": status = " + statusCode);
+            }
+            Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
+                    invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
+            Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
+        } finally {
+               res.releaseConnection();
+
+        }
+    }
+
     // ---------------------------------------------------------------
     // CRUD tests : CREATE LIST tests
     // ---------------------------------------------------------------