]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
DRYD-961: Added code to prevent more than one contact per authority term from being...
authorRichard Millet <remillet@gmail.com>
Mon, 12 Apr 2021 15:00:05 +0000 (08:00 -0700)
committerRichard Millet <remillet@gmail.com>
Mon, 12 Apr 2021 15:00:05 +0000 (08:00 -0700)
services/IntegrationTests/src/main/resources/log4j2-surefire.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/authority.xml
services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/contactSubresource.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/personitemWithContact1.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/personitemWithContact2.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/res/contactItems.res.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/res/personItemsWithContact.res.xml [new file with mode: 0644]
services/IntegrationTests/src/test/resources/test-data/xmlreplay/xml-replay-master.xml
services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResourceWithContacts.java
services/person/client/src/test/java/org/collectionspace/services/client/test/PersonAuthorityServiceTest.java

diff --git a/services/IntegrationTests/src/main/resources/log4j2-surefire.xml b/services/IntegrationTests/src/main/resources/log4j2-surefire.xml
new file mode 100644 (file)
index 0000000..bf74484
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+       This config is used by the maven surefire plugin (for tests), as configured in services/pom.xml.
+       For runtime logging config, see services/JaxRsServiceProvider/src/main/resources/log4j2.xml.
+-->
+<Configuration status="WARN">
+       <Properties>
+               <Property name="logPattern">%d %-5p [%t] [%c:%L] %m%n</Property>
+       </Properties>
+
+       <Appenders>
+               <Console name="ConsoleAppender" target="SYSTEM_OUT">
+                       <PatternLayout pattern="${logPattern}" />
+               </Console>
+
+               <File name="LogFileAppender" append="false" fileName="target/test.log">
+                       <PatternLayout pattern="${logPattern}" />
+               </File>
+       </Appenders>
+
+       <Loggers>
+               <Root level="DEBUG">
+                       <AppenderRef ref="ConsoleAppender"/>
+                       <AppenderRef ref="LogFileAppender" />
+               </Root>
+
+               <Logger name="httpclient" level="INFO" />
+               <Logger name="org.apache" level="INFO" />
+               <Logger name="org.collectionspace.services.client.PoxPayloadIn" level="DEBUG" />
+               <Logger name="org.collectionspace.services.client.PoxPayloadOut" level="DEBUG" />
+               <Logger name="org.collectionspace" level="DEBUG" />
+               <Logger name="org.jboss.resteasy" level="INFO" />
+       </Loggers>
+</Configuration>
index 42748c70fc2cb1187de0c4a24c30f8103b0aa9a5..a49b568cfbf997d0e014dab6959c3fa25bac6fac 100644 (file)
@@ -1,11 +1,80 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <xmlReplay>
     
-    <auths>
        <!-- IMPORTANT: THESE ARE STICKY :: THEY STICK AROUND UNTIL RESET, IN EXEC ORDER OF THIS FILE. -->
+    <auths default="admin@core.collectionspace.org">
         <auth ID="admin@core.collectionspace.org">YWRtaW5AY29yZS5jb2xsZWN0aW9uc3BhY2Uub3JnOkFkbWluaXN0cmF0b3I=</auth>
     </auths>
-        
+
+    <testGroup ID="TestAuthorityItemsWithContacts" autoDeletePOSTS="true" expectedCodesStrict="true">
+        <test ID="createPersonAuthority1" auth="admin@core.collectionspace.org">
+            <expectedCodes>201</expectedCodes>
+            <method>POST</method>
+            <uri>/cspace-services/personauthorities</uri>
+            <filename>authority/personauthority.xml</filename>
+            <vars>
+                <!-- Nonsense words to build short identifiers and display -->
+                <!-- names, and to populate text field(s). -->
+                <var ID="word1">word_1111</var>
+                <var ID="word2">word_2222</var>
+                <var ID="word3">word_3333</var>
+                <var ID="word4">word_4444</var>
+                <var ID="word5">word_555</var>
+                <!-- Partial term searches using one or more of those words. -->
+                <var ID="word1PartialTermStem">stem_111</var>
+                <var ID="word2PartialTermStem">stem_222</var>
+                <var ID="word2PartialTermMid">stem_333</var>
+                <!-- Populate the current record with those words. -->
+                <var ID="authDisplayName">display_name2</var>
+                <var ID="authShortIdentifier">short_id_value2</var>
+            </vars>
+        </test>
+        <test ID="personitemWithContact1">
+            <expectedCodes>201</expectedCodes>
+            <method>POST</method>
+            <uri>/cspace-services/personauthorities/${createPersonAuthority1.CSID}/items</uri>
+            <filename>authority/personitemWithContact1.xml</filename>
+            <vars>
+                <var ID="itemDisplayName">${createPersonAuthority1.word1} ${createPersonAuthority1.word2}</var>
+                <var ID="itemShortIdentifier">${createPersonAuthority1.word1}item1</var>
+                <var ID="itemBioNote">A bio note for this Person.</var>
+                <var ID="emailAddress">${createPersonAuthority1.word1}@${createPersonAuthority1.word2}.com</var>
+            </vars>
+        </test>
+        <test ID="getPersonitemWithContact1ContactList">
+            <expectedCodes>200</expectedCodes>
+            <method>GET</method>
+            <uri>/cspace-services/personauthorities/${createPersonAuthority1.CSID}/items/${personitemWithContact1.CSID}/contacts</uri>
+            <response>
+                <expected level="TEXT"/>
+                <filename>authority/res/contactItems.res.xml</filename>
+                <vars>
+                       <var ID="emailAddress">${createPersonAuthority1.word1}@${createPersonAuthority1.word2}.com</var>
+                </vars>
+            </response>
+        </test>
+        <test ID="personitemWithContact2">
+            <expectedCodes>400</expectedCodes>
+            <method>POST</method>
+            <uri>/cspace-services/personauthorities/${createPersonAuthority1.CSID}/items</uri>
+            <filename>authority/personitemWithContact2.xml</filename>
+            <vars>
+                <var ID="itemDisplayName">${createPersonAuthority1.word2} ${createPersonAuthority1.word2}</var>
+                <var ID="itemShortIdentifier">${createPersonAuthority2.word2}item2</var>
+                <var ID="itemBioNote">A bio note for this Person with two contacts.</var>
+            </vars>
+        </test>
+        <test ID="contactSubresource">
+            <expectedCodes>409</expectedCodes>
+            <method>POST</method>
+            <uri>/cspace-services/personauthorities/${createPersonAuthority1.CSID}/items/${personitemWithContact1.CSID}/contacts</uri>
+            <filename>authority/contactSubresource.xml</filename>
+            <vars>
+                <var ID="emailAddress">${createPersonAuthority1.word1}@${createPersonAuthority1.word2}.net</var>
+            </vars>
+        </test>
+       </testGroup>
+       
     <testGroup ID="TestAuthoritiesMultiVocabSearch" autoDeletePOSTS="true">
         
         <!--
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/contactSubresource.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/contactSubresource.xml
new file mode 100644 (file)
index 0000000..243cd36
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="contacts">
+    <ns2:contacts_common xmlns:ns2="http://collectionspace.org/services/contact" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+        <emailGroupList>
+            <emailGroup>
+                <emailType>business</emailType>
+                <email>richard@ronny.com</email>
+            </emailGroup>
+        </emailGroupList>
+    </ns2:contacts_common>
+</document>
\ No newline at end of file
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/personitemWithContact1.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/personitemWithContact1.xml
new file mode 100644 (file)
index 0000000..64a2bbd
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="persons">
+    <ns2:persons_common xmlns:ns2="http://collectionspace.org/services/person" xmlns:ns3="http://collectionspace.org/services/jaxb">
+        <personTermGroupList>
+            <personTermGroup>
+                <termDisplayName>${itemDisplayName}</termDisplayName>
+            </personTermGroup>   
+        </personTermGroupList>
+        <shortIdentifier>${itemShortIdentifier}</shortIdentifier>
+        <bioNote>${itemBioNote}</bioNote>
+        <foreName>${itemDisplayName}</foreName>
+    </ns2:persons_common>
+    <ns2:contacts_common xmlns:ns2="http://collectionspace.org/services/contact">
+        <emailGroupList>
+            <emailGroup>
+                <email>${emailAddress}</email>
+                <emailType>business</emailType>
+            </emailGroup>
+        </emailGroupList>
+    </ns2:contacts_common>
+</document>
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/personitemWithContact2.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/personitemWithContact2.xml
new file mode 100644 (file)
index 0000000..7b7dcfd
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<document name="persons">
+    <ns2:persons_common xmlns:ns2="http://collectionspace.org/services/person" xmlns:ns3="http://collectionspace.org/services/jaxb">
+        <personTermGroupList>
+            <personTermGroup>
+                <termDisplayName>${itemDisplayName}</termDisplayName>
+            </personTermGroup>   
+        </personTermGroupList>
+        <shortIdentifier>${itemShortIdentifier}</shortIdentifier>
+        <bioNote>${itemBioNote}</bioNote>
+        <foreName>${itemDisplayName}</foreName>
+    </ns2:persons_common>
+    <ns2:contacts_common xmlns:ns2="http://collectionspace.org/services/contact">
+        <emailGroupList>
+            <emailGroup>
+                <email>abc@town.com</email>
+                <emailType>business</emailType>
+            </emailGroup>
+        </emailGroupList>
+    </ns2:contacts_common>
+    <ns2:contacts_common xmlns:ns2="http://collectionspace.org/services/contact">
+        <emailGroupList>
+            <emailGroup>
+                <email>def@town.com</email>
+                <emailType>business</emailType>
+            </emailGroup>
+        </emailGroupList>
+    </ns2:contacts_common>    
+</document>
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/res/contactItems.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/res/contactItems.res.xml
new file mode 100644 (file)
index 0000000..ebb7880
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<ns2:abstract-common-list xmlns:ns2="http://collectionspace.org/services/jaxb">
+    <itemsInPage>1</itemsInPage>
+    <fieldsReturned>csid|uri|refName|updatedAt|workflowState|displayName</fieldsReturned>
+    <list-item>
+        <workflowState>project</workflowState>
+        <displayName>${emailAddress}</displayName>
+    </list-item>
+</ns2:abstract-common-list>
\ No newline at end of file
diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/res/personItemsWithContact.res.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authority/res/personItemsWithContact.res.xml
new file mode 100644 (file)
index 0000000..05e038d
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<ns2:abstract-common-list xmlns:ns2="http://collectionspace.org/services/jaxb">
+    <pageNum>0</pageNum>
+    <pageSize>${numItems}</pageSize>
+    <itemsInPage>${numItems}</itemsInPage>
+</ns2:abstract-common-list>
+
index bb69f51264486364b36d16be8697320512bc5160..2ad228c2c0913f257adbcf79670b52f69b0e72b8 100644 (file)
@@ -43,6 +43,7 @@
     <run controlFile="authrefs/authrefsSimple.xml" testGroup="AuthRefsSimple" />
     <run controlFile="authrefs/authrefsComplex.xml" testGroup="AuthRefsComplex" />
     <run controlFile="authority/authority.xml" testGroup="TestAuthoritiesMultiVocabSearch" />
+       <run controlFile="authority/authority.xml" testGroup="TestAuthorityItemsWithContacts" />
     
     <run controlFile="imports/imports.xml" testGroup="importsTestGroup" />
     <run controlFile="imports/imports.xml" testGroup="importsSeparateRepoTestGroup" />
index 7a3aaadaa84d06ac683ae33759db36754a17921c..4bc489c7b54f9da4be0a0eb9017b7d2d1625b3c4 100644 (file)
@@ -134,11 +134,7 @@ public abstract class AuthorityResourceWithContacts<AuthCommon, AuthItemHandler>
             ServiceContext itemCtx = createServiceContext(getItemServiceName());
             String itemcsid = lookupItemCSID(itemCtx, itemspecifier, parentcsid, "createContact(item)", "CREATE_ITEM_CONTACT");
 
-            // Note that we have to create the service context and document
-            // handler for the Contact service, not the main service.
-            ServiceContext ctx = createServiceContext(getContactServiceName(), input);
-            DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid, ui);
-            String csid = getRepositoryClient(ctx).create(ctx, handler);
+            String csid = this.createContact(NULL_CONTEXT, parentcsid, itemcsid, input, ui);
 
             UriBuilder path = UriBuilder.fromResource(resourceClass);
             path.path("" + parentcsid + "/items/" + itemcsid + "/contacts/" + csid);
@@ -163,6 +159,17 @@ public abstract class AuthorityResourceWithContacts<AuthCommon, AuthItemHandler>
             }
         }
         
+        //
+        // CC-1145: Ensure no more than one contact is associated with an authority term.
+        //
+        AbstractCommonList existingContactList = getContactList(ctx, parentCsid, itemCsid, null);
+        if (existingContactList.getTotalItems() > 0) {
+               String errMsg = String.format("Term '%s' in Authority '%s' has an existing contact.  CollectionSpace currently supports no more than one contact for a term.",
+                               itemCsid, parentCsid);
+               logger.error(errMsg);
+               throw new DocumentException(DocumentException.DUPLICATE_RECORD_ERR, DocumentException.DUPLICATE_RECORD_MSG);
+        }
+
         DocumentHandler handler = createContactDocumentHandler(ctx, parentCsid, itemCsid, ui);
         String csid = getRepositoryClient(ctx).create(ctx, handler);
 
index 4b6c1aaa62101e5d3e4f1cf88c657198a3e758f9..c2355dc242ec79d4b9ea960352b445ce95221fd6 100644 (file)
@@ -66,6 +66,9 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
     private final String CLASS_NAME = PersonAuthorityServiceTest.class.getName();
     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
     
+    // number of contacts supported by the Services API
+    private static final int MAX_CONTACTS = 1;
+    
     /**
      * Default constructor.  Used to set the short ID for all tests authority items
      */
@@ -510,21 +513,6 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
         }
     }
 
-    /**
-     * Creates the contact list.
-     *
-     * @param testName the test name
-     * @throws Exception the exception
-     */
-    @Test(dataProvider = "testName", groups = {"createList"},
-               dependsOnMethods = {"org.collectionspace.services.client.test.AbstractAuthorityServiceTest.createItemList"})
-    public void createContactList(String testName) throws Exception {
-        // Add contacts to the initially-created, known item record.
-        for (int j = 0; j < nItemsToCreateInList; j++) {
-            createContact(testName);
-        }
-    }
-
     // ---------------------------------------------------------------
     // CRUD tests : READ tests
     // ---------------------------------------------------------------
@@ -849,7 +837,7 @@ public class PersonAuthorityServiceTest extends AbstractAuthorityServiceTest<Per
         // In addition, there will be 'nItemsToCreateInList'
         // additional items created by the createItemList test,
         // all associated with the same parent resource.
-        int nExpectedItems = nItemsToCreateInList + 1;
+        int nExpectedItems = MAX_CONTACTS;
         if (logger.isDebugEnabled()) {
             logger.debug(testName + ": Expected "
                     + nExpectedItems + " items; got: " + nItemsReturned);