--- /dev/null
+<?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>
<?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">
<!--
--- /dev/null
+<?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
--- /dev/null
+<?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>
--- /dev/null
+<?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>
--- /dev/null
+<?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
--- /dev/null
+<?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>
+
<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" />
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);
}
}
+ //
+ // 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);
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
*/
}
}
- /**
- * 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
// ---------------------------------------------------------------
// 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);