From f978954c01a46d105237e37d8e68c0100accb553 Mon Sep 17 00:00:00 2001 From: remillet Date: Tue, 29 Mar 2016 10:35:14 -0700 Subject: [PATCH] CSPACE-6826: Ensured a default SELECT clause is part of all QueryContext instances. --- .../services/client/IQueryManager.java | 2 + .../services/common/query/QueryContext.java | 8 +- .../client/test/IndexServiceTest.java | 168 +----------------- 3 files changed, 11 insertions(+), 167 deletions(-) diff --git a/services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java b/services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java index abc45b684..ea8bb775f 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java +++ b/services/client/src/main/java/org/collectionspace/services/client/IQueryManager.java @@ -42,6 +42,8 @@ public interface IQueryManager { final static String SEARCH_TYPE_INVOCATION = "inv"; final static String SEARCH_QUALIFIER_AND = SEARCH_TERM_SEPARATOR + "AND" + SEARCH_TERM_SEPARATOR; final static String SEARCH_QUALIFIER_OR = SEARCH_TERM_SEPARATOR + "OR" + SEARCH_TERM_SEPARATOR; + final static String DEFAULT_SELECT_CLAUSE = "SELECT * FROM "; + // // Nuxeo pseudo-values (and filters) for special document properties. diff --git a/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java b/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java index e13d2ec77..84faf175b 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java +++ b/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java @@ -1,5 +1,6 @@ package org.collectionspace.services.common.query; +import org.collectionspace.services.client.IQueryManager; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.context.ServiceContext; @@ -52,6 +53,7 @@ public class QueryContext { throw new IllegalArgumentException( "Service context has no Tenant ID specified."); } + selectClause = IQueryManager.DEFAULT_SELECT_CLAUSE; } /** @@ -137,8 +139,12 @@ public class QueryContext { * Gets the select clause. * * @return the select clause + * @throws Exception */ - public String getSelectClause() { + public String getSelectClause() throws Exception { + if (selectClause == null) { + throw new Exception("Select clause for query context was null."); + } return selectClause; } diff --git a/services/index/client/src/test/java/org/collectionspace/services/client/test/IndexServiceTest.java b/services/index/client/src/test/java/org/collectionspace/services/client/test/IndexServiceTest.java index 98b5a62d5..00a2a23ba 100644 --- a/services/index/client/src/test/java/org/collectionspace/services/client/test/IndexServiceTest.java +++ b/services/index/client/src/test/java/org/collectionspace/services/client/test/IndexServiceTest.java @@ -24,179 +24,15 @@ package org.collectionspace.services.client.test; import javax.ws.rs.core.Response; -import org.collectionspace.services.client.CollectionSpaceClient; -import org.collectionspace.services.client.PayloadOutputPart; -import org.collectionspace.services.client.PoxPayloadIn; -import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.jaxb.AbstractCommonList; -import org.collectionspace.services.index.IndexCommon; -import org.collectionspace.services.client.DimensionClient; -import org.collectionspace.services.client.index.IndexClient; -import org.collectionspace.services.dimension.DimensionsCommon; -import org.jboss.resteasy.client.ClientResponse; -import org.testng.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * ObjectExitServiceTest, carries out tests against a deployed and running ObjectExit Service.

+ * IndexServiceTest, carries out tests against a deployed and running Index Service.

* $LastChangedRevision: $ * $LastChangedDate: $ */ -public class IndexServiceTest extends AbstractPoxServiceTestImpl { - +public class IndexServiceTest { private final String CLASS_NAME = IndexServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); - private String knownResourceId = null; - - @Override - public String getServicePathComponent() { - return IndexClient.SERVICE_PATH_COMPONENT; - } - - @Override - protected String getServiceName() { - return IndexClient.SERVICE_NAME; - } - - @Override - protected CollectionSpaceClient getClientInstance() { - return new DimensionClient(); - } - - // - // Test overrides - // - - @Override - public void create(String testName) throws Exception { - String csid = this.createTestObject(testName); - if (this.knownResourceId == null) { - this.knownResourceId = csid; - } - } - - @Override - public void read(String testName) throws Exception { -// setupRead(); -// DimensionClient client = new DimensionClient(); -// Response res = client.getIndex(knownResourceId); -// try { -// assertStatusCode(res, testName); -// PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class)); -// IndexCommon indexsCommon = (IndexCommon) extractPart(input, IndexClient.SERVICE_COMMONPART_NAME, IndexCommon.class); -// if (logger.isDebugEnabled() == true) { -// logger.debug("Index payload is: " + input.getXmlPayload()); -// } -// Assert.assertNotNull(indexsCommon); -// } finally { -// if (res != null) { -// res.close(); -// } -// } - } - - // - // FIXME: REM - This test should be a subclass of BaseServiceTest and *not* AbstractPoxServiceTestImpl - // - - @Override - public void update(String testName) throws Exception { - setupUpdate(); - } - - @Override - public void delete(String testName) throws Exception { - // Do nothing. N/A - } - - public void searchIndexDeleted(String testName) throws Exception { - // Do nothing. N/A - } - - @Override - public void readList(String testName) throws Exception { - // Do nothing. N/A - } - - @Override - public void readPaginatedList(String testName) throws Exception { - // Do nothing. N/A - } - - @Override - public void CRUDTests(String testName) { - // TODO Auto-generated method stub - } - - @Override - protected IndexCommon updateInstance(IndexCommon commonPartObject) { - // TODO Auto-generated method stub - return null; - } - - @Override - protected void compareUpdatedInstances(IndexCommon original, - IndexCommon updated) throws Exception { - // TODO Auto-generated method stub - - } - - /* - * (non-Javadoc) - * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) - */ - @Override - public void createList(String testName) throws Exception { - //empty N/A - } - - public void testSubmitRequest() { - // Do nothing. N/A - } - - // --------------------------------------------------------------- - // Utility methods used by tests above - // --------------------------------------------------------------- - - @Override - protected PoxPayloadOut createInstance(String identifier) { - String dimensionsCommonPartName = new DimensionClient().getCommonPartName(); - return createInstance(identifier, dimensionsCommonPartName); - } - - @Override - protected PoxPayloadOut createInstance(String commonPartName, - String identifier) { - return createDimensionInstance(commonPartName, identifier); - } - - /* - * We're using a DimensionsCommon instance to test the index service. - */ - private PoxPayloadOut createDimensionInstance(String dimensionValue) { - String commonPartName = new DimensionClient().getCommonPartName(); - return createDimensionInstance(commonPartName, dimensionValue); - } - - /* - * We're using a DimensionsCommon instance to test the index service. - */ - private PoxPayloadOut createDimensionInstance(String commonPartName, - String dimensionValue) { - String measurementUnit = "measurementUnit-" + dimensionValue; - DimensionsCommon dimensionsCommon = new DimensionsCommon(); - - dimensionsCommon.setMeasurementUnit(measurementUnit); - PoxPayloadOut multipart = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = multipart.addPart(commonPartName, dimensionsCommon); - - if (logger.isDebugEnabled()) { - logger.debug("To be created, Dimensions common: " + commonPart.asXML()); - logger.debug(objectAsXmlString(dimensionsCommon, DimensionsCommon.class)); - } - - return multipart; - } - } -- 2.47.3