From cecdf3e202bdc512348fbe88c31e224ad87b6b93 Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Wed, 6 Jan 2010 07:28:20 +0000 Subject: [PATCH] CSPACE-572. Reverted changes to remove inVocabulary from payload, as it broke createItem. Also rewrote tests to ensure that inVocabulary is actually being set correctly, so any future regressions will be detected right away. --- .../client/test/VocabularyServiceTest.java | 30 ++++++++++++++----- .../importer/VocabularyBaseImport.java | 5 ++-- .../services/VocabularyItemJAXBSchema.java | 1 + .../main/resources/vocabularyitem_common.xsd | 1 + .../vocabulary/client/sample/Sample.java | 5 ++-- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java index 4db245618..3f6b37c6c 100644 --- a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java +++ b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java @@ -62,8 +62,10 @@ public class VocabularyServiceTest extends AbstractServiceTest { final String SERVICE_PATH_COMPONENT = "vocabularies"; final String ITEM_SERVICE_PATH_COMPONENT = "items"; private String knownResourceId = null; + private String lastVocabId = null; private String knownResourceRefName = null; private String knownItemResourceId = null; + private int nItemsToCreateInList = 3; private List allResourceIdsCreated = new ArrayList(); private Map allResourceItemIdsCreated = new HashMap(); @@ -112,10 +114,11 @@ public class VocabularyServiceTest extends AbstractServiceTest { // for additional tests below. knownResourceRefName = refName; + lastVocabId = extractId(res); // Store the ID returned from the first resource created // for additional tests below. if (knownResourceId == null){ - knownResourceId = extractId(res); + knownResourceId = lastVocabId; if (logger.isDebugEnabled()) { logger.debug(testName + ": knownResourceId=" + knownResourceId); } @@ -131,7 +134,7 @@ public class VocabularyServiceTest extends AbstractServiceTest { public void createItem(String testName) { setupCreate(testName); - knownItemResourceId = createItemInVocab(knownResourceId); + knownItemResourceId = createItemInVocab(lastVocabId); if(logger.isDebugEnabled()){ logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId); } @@ -186,8 +189,12 @@ public class VocabularyServiceTest extends AbstractServiceTest { public void createList(String testName) throws Exception { for (int i = 0; i < 3; i++) { create(testName); - // Add 3 items to each vocab - for (int j = 0; j < 3; j++) { + knownResourceId = lastVocabId; + if (logger.isDebugEnabled()) { + logger.debug(testName + ": Resetting knownResourceId to" + knownResourceId); + } + // Add nItemsToCreateInList items to each vocab + for (int j = 0; j < nItemsToCreateInList; j++) { createItem(testName); } } @@ -500,11 +507,19 @@ public class VocabularyServiceTest extends AbstractServiceTest { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + List items = + list.getVocabularyitemListItem(); + int nItemsReturned = items.size(); + if(logger.isDebugEnabled()){ + logger.debug(" " + testName + ": Expected " + + nItemsToCreateInList+" items; got: "+nItemsReturned); + } + Assert.assertEquals( nItemsReturned, nItemsToCreateInList); + // Optionally output additional data about list members for debugging. - boolean iterateThroughList = false; + boolean iterateThroughList = true; if (iterateThroughList && logger.isDebugEnabled()) { - List items = - list.getVocabularyitemListItem(); + logger.debug(" " + testName + ": checking items"); int i = 0; for (VocabularyitemsCommonList.VocabularyitemListItem item : items) { logger.debug(" " + testName + ": list-item[" + i + "] csid=" + @@ -1039,6 +1054,7 @@ public class VocabularyServiceTest extends AbstractServiceTest { private MultipartOutput createVocabularyItemInstance(String inVocabulary, String displayName, String refName) { VocabularyitemsCommon vocabularyItem = new VocabularyitemsCommon(); + vocabularyItem.setInVocabulary(inVocabulary); vocabularyItem.setDisplayName(displayName); if(refName!=null) vocabularyItem.setRefName(refName); diff --git a/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java b/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java index c35231967..e448af7d8 100644 --- a/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java +++ b/services/vocabulary/import/src/main/java/org/collectionspace/services/vocabulary/importer/VocabularyBaseImport.java @@ -104,7 +104,7 @@ public class VocabularyBaseImport { if(logger.isDebugEnabled()){ logger.debug("Import: Create Item: \""+itemName+"\" in vocabulary: \"" + vocabName +"\""); } - MultipartOutput multipart = createVocabularyItemInstance(itemName, refName); + MultipartOutput multipart = createVocabularyItemInstance(vcsid, itemName, refName); ClientResponse res = client.createItem(vcsid, multipart); int statusCode = res.getStatus(); @@ -145,8 +145,9 @@ public class VocabularyBaseImport { } private MultipartOutput createVocabularyItemInstance( - String displayName, String refName) { + String inVocabulary, String displayName, String refName) { VocabularyitemsCommon vocabularyItem = new VocabularyitemsCommon(); + vocabularyItem.setInVocabulary(inVocabulary); vocabularyItem.setDisplayName(displayName); vocabularyItem.setRefName(refName); MultipartOutput multipart = new MultipartOutput(); diff --git a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java index 97127893b..584672463 100644 --- a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java +++ b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java @@ -9,6 +9,7 @@ package org.collectionspace.services; */ public interface VocabularyItemJAXBSchema { final static String DISPLAY_NAME = "displayName"; + final static String IN_VOCABULARY = "inVocabulary"; final static String REF_NAME = "refName"; final static String CSID = "csid"; } diff --git a/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd b/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd index e8e450536..83c083baf 100644 --- a/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd +++ b/services/vocabulary/jaxb/src/main/resources/vocabularyitem_common.xsd @@ -19,6 +19,7 @@ + diff --git a/services/vocabulary/sample/sample/src/main/java/org/collectionspace/services/vocabulary/client/sample/Sample.java b/services/vocabulary/sample/sample/src/main/java/org/collectionspace/services/vocabulary/client/sample/Sample.java index d6f647535..f55a4a203 100644 --- a/services/vocabulary/sample/sample/src/main/java/org/collectionspace/services/vocabulary/client/sample/Sample.java +++ b/services/vocabulary/sample/sample/src/main/java/org/collectionspace/services/vocabulary/client/sample/Sample.java @@ -110,7 +110,7 @@ public class Sample { ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; logger.info("Import: Create Item: \""+itemName+"\" in vocabulary: \"" + vocabName +"\""); - MultipartOutput multipart = createVocabularyItemInstance(itemName, refName); + MultipartOutput multipart = createVocabularyItemInstance(vcsid, itemName, refName); ClientResponse res = client.createItem(vcsid, multipart); int statusCode = res.getStatus(); @@ -314,8 +314,9 @@ public class Sample { } private MultipartOutput createVocabularyItemInstance( - String displayName, String refName) { + String inVocabulary, String displayName, String refName) { VocabularyitemsCommon vocabularyItem = new VocabularyitemsCommon(); + vocabularyItem.setInVocabulary(inVocabulary); vocabularyItem.setDisplayName(displayName); vocabularyItem.setRefName(refName); MultipartOutput multipart = new MultipartOutput(); -- 2.47.3