Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r5377 - in branches/new-structure-with-base2/ps-mdm-ls/src: main/java/org/perfsonar/service/lookupservice main/java/org/perfsonar/service/lookupservice/storage/exist test/java/org/perfsonar/tests/actions test/java/org/perfsonar/tests/dao

Subject: perfsonar development work

List archive

perfsonar: r5377 - in branches/new-structure-with-base2/ps-mdm-ls/src: main/java/org/perfsonar/service/lookupservice main/java/org/perfsonar/service/lookupservice/storage/exist test/java/org/perfsonar/tests/actions test/java/org/perfsonar/tests/dao


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r5377 - in branches/new-structure-with-base2/ps-mdm-ls/src: main/java/org/perfsonar/service/lookupservice main/java/org/perfsonar/service/lookupservice/storage/exist test/java/org/perfsonar/tests/actions test/java/org/perfsonar/tests/dao
  • Date: Mon, 7 Dec 2009 07:50:58 -0500

Author: trzaszcz
Date: 2009-12-07 07:50:58 -0500 (Mon, 07 Dec 2009)
New Revision: 5377

Modified:

branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/EchoServiceEngine.java

branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryServiceEngine.java

branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/CommonExistDAOImpl.java

branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/ExistDbManager.java

branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/XQueryDAOSupportImpl.java

branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/actions/QueryActionTests.java

branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/dao/SummarizationDaoTests.java

branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/dao/XQueryExistDAOImplTests.java
Log:
refactoring, unit tests improved, queryAction,echoAction enhancement

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/EchoServiceEngine.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/EchoServiceEngine.java
2009-12-04 15:37:31 UTC (rev 5376)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/EchoServiceEngine.java
2009-12-07 12:50:58 UTC (rev 5377)
@@ -13,354 +13,313 @@
import org.perfsonar.service.lookupservice.storage.exist.CommonExistDAOImpl;

/**
- * Handling EchoRequest
- * for Echo (Ping) and SelfTest
+ * Handling EchoRequest for Echo (Ping) and SelfTest
*
- * @author Maciej Glowiak
+ * @author Maciej Glowiak,Slawomir Trzaszczka
*
*/
public class EchoServiceEngine extends GenericLSServiceEngine implements
- ServiceEngine {
+ ServiceEngine {

- private static final Logger logger = Logger
- .getLogger(EchoServiceEngine.class.getName());
+ private static final Logger logger = Logger
+ .getLogger(EchoServiceEngine.class.getName());

- public final static String[] SUPPORTED_SELFTEST_EVENT_TYPES = {
- "http://schemas.perfsonar.net/tools/admin/echo/ls/2.0";,
- "http://schemas.perfsonar.net/tools/admin/selftest/1.0"; };
+ public final static String[] SUPPORTED_SELFTEST_EVENT_TYPES = {
+
"http://schemas.perfsonar.net/tools/admin/echo/ls/2.0";,
+
"http://schemas.perfsonar.net/tools/admin/selftest/1.0"; };

- public final static String[] SUPPORTED_ECHO_EVENT_TYPES = {
"http://schemas.perfsonar.net/tools/admin/echo/2.0";, };
+ public final static String[] SUPPORTED_ECHO_EVENT_TYPES = {
"http://schemas.perfsonar.net/tools/admin/echo/2.0";, };

- /**
- * Constructor
- * @throws PerfSONARException
- */
- public EchoServiceEngine() throws PerfSONARException {
- super();
- }
+ /**
+ * Constructor
+ *
+ * @throws PerfSONARException
+ */
+ public EchoServiceEngine() throws PerfSONARException {
+ super();
+ }

-
-
- /**
- * Tests whether eventType is echo
- *
- * @param evt
- * @return true if selftest
- */
- private boolean isSelfTestEventTypeSupported(String evt) {
+
+
+ private boolean isStringOccurInArray(String key,String [] array){
+ for (String s : array) {
+ if (s.equals(key)) {
+ return true;
+ }
+ if ((s + "/").equals(key)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Tests whether eventType is echo
+ *
+ * @param evt
+ * @return true if selftest
+ */
+ private boolean isSelfTestEventTypeSupported(String evt) {
+ return
isStringOccurInArray(evt,SUPPORTED_SELFTEST_EVENT_TYPES);
+ }

- boolean i = false;
- for (String s : SUPPORTED_SELFTEST_EVENT_TYPES) {
- if (s.equals(evt)) {
- i = true;
- break;
- }
- if ((s + "/").equals(evt)) {
- i = true;
- break;
- }
- }
- return i;
- }
+ /**
+ * Tests whether eventType is echo
+ *
+ * @param evt
+ * @return true if echo
+ */
+ private boolean isEchoEventTypeSupported(String evt) {
+ return isStringOccurInArray(evt,SUPPORTED_ECHO_EVENT_TYPES);
+ }

+ /**
+ * Prints event Types (for result code message)
+ *
+ * @return
+ */
+ private String getEventTypesString() {

- /**
- * Tests whether eventType is echo
- *
- * @param evt
- * @return true if echo
- */
- private boolean isEchoEventTypeSupported(String evt) {
+ StringBuffer sb = new StringBuffer();
+ int j = 0;
+ for (int i = 0; i < SUPPORTED_ECHO_EVENT_TYPES.length; i++) {
+ if (j > 0)
+ sb.append(" | ");
+ sb.append(SUPPORTED_ECHO_EVENT_TYPES[i]);
+ j++;
+ }
+ for (int i = 0; i < SUPPORTED_SELFTEST_EVENT_TYPES.length;
i++) {
+ if (j > 0)
+ sb.append(" | ");
+ sb.append(SUPPORTED_SELFTEST_EVENT_TYPES[i]);
+ j++;
+ }
+ return sb.toString();
+ }

- boolean i = false;
- for (String s : SUPPORTED_ECHO_EVENT_TYPES) {
- if (s.equals(evt)) {
- i = true;
- break;
- }
- if ((s + "/").equals(evt)) {
- i = true;
- break;
- }
- }
- return i;
- }
+ public void takeAction(ServiceMessage serviceRequest,
+ ServiceMessage serviceResponse) throws
PerfSONARException {

+ // extract message
+ Message request = serviceRequest.getMessageElement();

- /**
- * Prints event Types (for result code message)
- *
- * @return
- */
- private String getEventTypesString() {
+ logger.debug("Echo Service Engine started");

- StringBuffer sb = new StringBuffer();
- int j = 0;
- for (int i = 0; i < SUPPORTED_ECHO_EVENT_TYPES.length; i++) {
- if (j > 0)
- sb.append(" | ");
- sb.append(SUPPORTED_ECHO_EVENT_TYPES[i]);
- j++;
- }
- for (int i = 0; i < SUPPORTED_SELFTEST_EVENT_TYPES.length; i++) {
- if (j > 0)
- sb.append(" | ");
- sb.append(SUPPORTED_SELFTEST_EVENT_TYPES[i]);
- j++;
- }
- return sb.toString();
- }
+ // get metadata to exctract parameters
+ Metadata metadata = getFirstMetadataFromRequest(request);
+ boolean selftest = false;
+ boolean echo = false;
+ String eventType = null;

+ try {
+ // check eventtype
+ eventType =
metadata.getFirstEventType().getEventType();
+ selftest = isSelfTestEventTypeSupported(eventType);
+ echo = isEchoEventTypeSupported(eventType);

- public void takeAction(ServiceMessage serviceRequest,
- ServiceMessage serviceResponse) throws PerfSONARException {
+ if (!selftest && !echo)
+ throw new PerfSONARException(
+
"error/ls/eventtype_not_supported",
+ "LS EchoRequest error: " +
"Not supported event type ["
+ + eventType +
"]. " + "Must be: ["
+ +
getEventTypesString() + "]");

- // extract message
- Message request = serviceRequest.getMessageElement();
+ } catch (RuntimeException ex) {
+ //TODO : refactor - change exception this exception !
+ throw new PerfSONARException(
+ "error/ls/no_eventtype",
+ "LS EchoRequest error: "
+ + "Error while
determining eventType (possibly no eventType at all). "
+ + "EventType must be
[" + getEventTypesString()
+ + "]. " + "Nested
exception is : "
+ + ex.getMessage());
+ }

- logger.debug("Echo Service Engine started");
+ // Take action
+ Message msg = null;

- // get metadata to exctract parameters
- Metadata metadata = getFirstMetadataFromRequest(request);
- boolean selftest = false;
- boolean echo = false;
- String eventType = null;
+ logger.debug("Taking ECHO action");
+
+ // ECHO
+ if (echo) {
+ msg = takeEchoAction(serviceRequest);
+ }else if (selftest) {// or SELFTEST
+ msg = takeSelfTestAction(serviceRequest);
+ }

- try {
- // check eventtype
- eventType = metadata.getFirstEventType().getEventType();
- selftest = isSelfTestEventTypeSupported(eventType);
- echo = isEchoEventTypeSupported(eventType);
+ // exit with success
+ serviceResponse.setElement(msg);
+ }

- if (!selftest && !echo)
- throw new PerfSONARException(
- "error/ls/eventtype_not_supported",
- "LS EchoRequest error: " + "Not supported event type
["
- + eventType + "]. " + "Must be: ["
- + getEventTypesString() + "]");
+ /**
+ * Sub action for SelfTest
+ *
+ * @param serviceRequest
+ * @return
+ * @throws PerfSONARException
+ */
+ public Message takeSelfTestAction(ServiceMessage serviceRequest)
+ throws PerfSONARException {

- } catch (RuntimeException ex) {
- throw new PerfSONARException(
- "error/ls/no_eventtype",
- "LS EchoRequest error: "
- + "Error while determining eventType (possibly
no eventType at all). "
- + "EventType must be [" + getEventTypesString()
- + "]. " + "Nested exception is : "
- + ex.getMessage());
- }
+ // create request
+ Message msg = new Message();
+ msg.setId("EchoResponse");

- // Take action
- Message msg = null;
+ Metadata meta = new Metadata("result-code-metadata", "nmwg");
+ EventType evt = new EventType(
+
"http://schemas.perfsonar.net/tools/admin/selftest/1.0";, "nmwg");
+ meta.addChild(evt);

- // ECHO
- if (echo) {
- logger.debug("Taking ECHO action");
- msg = takeEchoAction(serviceRequest);
- }
+ Data data = new Data("result-code-data", "result-code",
"nmwg");
+ data.setMetadataIdRef("result-code-metadata");

- // or SELFTEST
- else if (selftest) {
- msg = takeSelfTestAction(serviceRequest);
- logger.debug("Taking ECHO action");
- } else
- throw new PerfSONARException("error/ls/no_eventtype",
- "Cannot take selftest or echo action.");
+ Element datum = new Element("datum", "nmwgr",
+ "http://ggf.org/ns/nmwg/result/2.0/";);
+ data.addChild(datum);

- // exit with success
- serviceResponse.setElement(msg);
- }
+ msg.addChild(meta);
+ msg.addChild(data);

+ // test db connectivity - add
+ testDBConnectivity(data);

- /**
- * Sub action for SelfTest
- *
- * @param serviceRequest
- * @return
- * @throws PerfSONARException
- */
- public Message takeSelfTestAction(ServiceMessage serviceRequest)
- throws PerfSONARException {
+ // test db collection LSStore
+ testDBCollectionSummary(data);

- // create request
- Message msg = new Message();
- msg.setId("EchoResponse");
+ // test db collection LSStore-control
+ testDBCollectionControl(data);

- Metadata meta = new Metadata("result-code-metadata", "nmwg");
- EventType evt = new EventType(
- "http://schemas.perfsonar.net/tools/admin/selftest/1.0";,
"nmwg");
- meta.addChild(evt);
+ return msg;
+ }

- Data data = new Data("result-code-data", "result-code", "nmwg");
- data.setMetadataIdRef("result-code-metadata");
+ /**
+ * Tests whether there is LSStore-control collection
+ *
+ * @param data
+ * to be filled with result code
+ */
+ private void testDBCollectionControl(Data data) {
+
+ String messageName="exist-db-collection-store-control";
+ String messageDescription="";
+ String
postfixResult="/ls/selftest/collection/lsstore-control";
+ String prefixResult="success";
+
+ try {
+ boolean test = dao
+
.isDBCollection(CommonExistDAOImpl.LS_STORE_CONTROL_COLLECTION_TYPE);
+
+ if (test){
+ prefixResult="success";
+ messageDescription="collection
LSStore-control exists and is accessible";
+ }else{
+ prefixResult="error";
+ messageDescription="collection
LSStore-control doesn't exist and isn't accessible";
+ }
+
+ } catch (PerfSONARException ex) {
+ prefixResult="error";
+ messageDescription="collection LSStore-control does
not exist or is not accessible:"+ ex.getMessage();
+ }
+
+ addResultCode(data, messageName, prefixResult+postfixResult,
messageDescription);
+ }

- Element datum = new Element("datum", "nmwgr",
- "http://ggf.org/ns/nmwg/result/2.0/";);
- data.addChild(datum);
+
+ /**
+ * Tests whether there is LSStorecollection
+ *
+ * @param data
+ * to be filled with result code
+ */
+ private void testDBCollectionSummary(Data data) {
+
+ String messageName="exist-db-collection-store-summary";
+ String messageDescription="";
+ String postfixResult="/ls/selftest/collection/summary";
+ String prefixResult="success";
+
+ try {
+ boolean test =
dao.isDBCollection(CommonExistDAOImpl.LS_STORE_SUMMARY_COLLECTION_TYPE);
+ if (test){
+ prefixResult="success";
+ messageDescription="collection
LSStore-summary exists and is accessible";
+ }else{
+ prefixResult="error";
+ messageDescription="collection
LSStore-summary doesn't exist";
+ }
+ } catch (PerfSONARException ex) {
+ prefixResult="error";
+ messageDescription="collection LSStore-summary does
not exist or is not accessible:"+ ex.getMessage();
+ }
+
+ addResultCode(data, messageName, prefixResult+postfixResult,
messageDescription);
+ }

- msg.addChild(meta);
- msg.addChild(data);
+ /**
+ * Tests whether there is connectivity with DB
+ *
+ * @param data
+ * to be filled with result code
+ */
+ private void testDBConnectivity(Data data) {
+ try {
+ if(dao.isDBConnectivity()){
+ addResultCode(data, "exist-db-connectivity",
+
"success/ls/selftest/dbconnectivity",
+ "eXist DB connection
established");
+ }
+ } catch (PerfSONARException ex) {
+ addResultCode(data, "exist-db-connectivity",
+ "error/ls/selftest/dbconnectivity",
+ "eXist DB connection not working: " +
ex.getMessage());
+ }
+ }

- // test db connectivity - add
- testDBConnectivity(data);
+ /**
+ * Returns success echo response from service
+ *
+ * @param serviceRequest
+ * @return
+ * @throws PerfSONARException
+ */
+ public Message takeEchoAction(ServiceMessage serviceRequest)
+ throws PerfSONARException {

- // test db collection LSStore
- testDBCollectionStore(data);
+ Message msg = ResultCodesUtil.generateResultMessage(null,
+ "success/echo", "Echo - ping succeeded");
+ return msg;
+ }

- // test db collection LSStore-control
- testDBCollectionControl(data);
+ /**
+ * Adds sub result code to the selftest data element
+ *
+ * @param incomingData
+ * @param name
+ * @param code
+ * @param desc
+ */
+ private void addResultCode(Data incomingData, String name, String
code,
+ String desc) {

- return msg;
- }
+ Metadata meta = new Metadata();
+ meta.setId(name);

- /**
- * Tests whether there is LSStore-control collection
- * @param data to be filled with result code
- */
- private void testDBCollectionControl(Data data) {
+ EventType evt = new EventType();
+ evt.setEventType(PerfSONARException.RESULT_CODE_PREFIX+code);
+ meta.setEventType(evt);
+ incomingData.addChild(meta);

- boolean test;
- String s;
- test = false;
- s = "";
- try {
- test = dao
-
.isDBCollection(CommonExistDAOImpl.LS_STORE_CONTROL_COLLECTION_TYPE); //
returns
- // true
- // if
- // so,
- // or
- // exception
- } catch (Exception ex) {
- test = false;
- s = ex.getMessage();
- }
- if (test)
- addResultCode(data, "exist-db-collection-store-control",
- "success.ls.selftest.collection.lsstore-control",
- "collection LSStore-control exists and is accessible");
- else
- addResultCode(data, "exist-db-collection-store-control",
- "error/ls/selftest.collection.lsstore-control",
- "collection LSStore-control does not exist or is not
accessible: "
- + s);
- }
+ Data data = new Data();
+ data.setId(name + "-data");
+ data.setMetadataIdRef(name);

- /**
- * Tests whether there is LSStorecollection
- * @param data to be filled with result code
- */
- private void testDBCollectionStore(Data data) {
+ Element datum = new Element("datum", "nmwgr",
+ "http://ggf.org/ns/nmwg/result/2.0/";);
+ datum.setText(desc);
+ data.addChild(datum);

- boolean test;
- String s;
- test = false;
- s = "";
- try {
- test = dao
-
.isDBCollection(CommonExistDAOImpl.LS_STORE_COLLECTION_TYPE); // returns
- // true
- // if
- // so,
- // or
- // exception
- } catch (Exception ex) {
- test = false;
- s = ex.getMessage();
- }
- if (test)
- addResultCode(data, "exist-db-collection-store",
- "success.ls.selftest.collection.lsstore",
- "collection LSStore exists and is accessible");
- else
- addResultCode(data, "exist-db-collection-store",
- "error/ls/selftest.collection.lsstore",
- "collection LSStore does not exist or is not accessible:
"
- + s);
- }
+ incomingData.addChild(data);
+ }

- /**
- * Tests whether there is connectivity with DB
- * @param data to be filled with result code
- */
- private void testDBConnectivity(Data data) {
-
- boolean test;
- String s;
- test = false;
- s = "";
- try {
- test = dao.isDBConnectivity(); // returns true if so, or
exception
- } catch (Exception ex) {
- test = false;
- s = ex.getMessage();
- }
- if (test)
- addResultCode(data, "exist-db-connectivity",
- "success.ls.selftest.dbconnectivity",
- "eXist DB connection established");
- else
- addResultCode(data, "exist-db-connectivity",
- "error/ls/selftest.dbconnectivity",
- "eXist DB connection not working: " + s);
- }
-
-
- /**
- * Sub action for Echo
- *
- * @param serviceRequest
- * @return
- * @throws PerfSONARException
- */
- public Message takeEchoAction(ServiceMessage serviceRequest)
- throws PerfSONARException {
-
- Message msg = ResultCodesUtil.generateResultMessage(null,
- "success/echo", "Echo - ping succeeded");
- return msg;
- }
-
-
- /**
- * Adds sub result code to the selftest data element
- *
- * @param incomingData
- * @param name
- * @param code
- * @param desc
- */
- private void addResultCode(Data incomingData, String name, String code,
- String desc) {
-
- // <!-- metadata/data block for result of first test -->
-
- // <nmwg:metadata id="bwctl_command_test">
- //
<nmwg:eventType>http://schemas.perfsonar.net/tools/admin/selftest/MP/BWCTL/bwctl_command_test/success/1.0</nmwg:eventType>
- // </nmwg:metadata>
- //
- // <nmwg:data id="data_bwctl_command_test"
- // metadataIdRef="bwctl_command_test">
- // <nmwg:datum>BWCTL tool /usr/local/bin/bwctl found
</nmwg:datum>
- // </nmwg:data>
-
- Metadata meta = new Metadata();
- meta.setId(name);
-
- EventType evt = new EventType();
- evt.setEventType(code);
- meta.setEventType(evt);
- incomingData.addChild(meta);
-
- Data data = new Data();
- data.setId(name + "-data");
- data.setMetadataIdRef(name);
-
- Element datum = new Element("datum", "nmwgr",
- "http://ggf.org/ns/nmwg/result/2.0/";);
- datum.setText(desc);
- data.addChild(datum);
-
- incomingData.addChild(data);
- }
-
-} // EchoRequestAction
+}

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryServiceEngine.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryServiceEngine.java
2009-12-04 15:37:31 UTC (rev 5376)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/LSQueryServiceEngine.java
2009-12-07 12:50:58 UTC (rev 5377)
@@ -88,7 +88,7 @@
// try to get parameters
Parameters parameters = m

.getParameters("http://ggf.org/ns/nmwg/tools/org/perfsonar/service/lookup/xquery/1.0/";);
- if (parameters.getChildren("parameters") !=
null) {
+ if (parameters!=null &&
parameters.getChildren("parameters") != null) {
lsOutput =
parameters.getFirstParameter("lsOutput")
.getValue();
logger.debug("Found lsOutput
parameter [" + lsOutput + "]");

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/CommonExistDAOImpl.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/CommonExistDAOImpl.java
2009-12-04 15:37:31 UTC (rev 5376)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/CommonExistDAOImpl.java
2009-12-07 12:50:58 UTC (rev 5377)
@@ -38,6 +38,8 @@
* The name of the control collection of LS
*/
public static final String LS_STORE_CONTROL_COLLECTION_TYPE =
"LSStore-control";
+
+ public static final String LS_STORE_SUMMARY_COLLECTION_TYPE =
"LSStore-summary";

public final static String DECLARE_NMWG_NAMESPACE = "declare
namespace nmwg='http://ggf.org/ns/nmwg/base/2.0/'; \n";


Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/ExistDbManager.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/ExistDbManager.java
2009-12-04 15:37:31 UTC (rev 5376)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/ExistDbManager.java
2009-12-07 12:50:58 UTC (rev 5377)
@@ -183,9 +183,8 @@
return parseExistXMLReponse(new
ByteArrayInputStream(

existResult.getBytes()), count);
}
-
- } catch (XMLDBException e) {
- e.printStackTrace();
+ }catch (XMLDBException e) {
+ throw new
PerfSONARException("error/ls/query","Problem with executing xquery
:"+e.getMessage());
} catch (IOException e) {
e.printStackTrace();
} catch (XMLStreamException e) {

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/XQueryDAOSupportImpl.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/XQueryDAOSupportImpl.java
2009-12-04 15:37:31 UTC (rev 5376)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/main/java/org/perfsonar/service/lookupservice/storage/exist/XQueryDAOSupportImpl.java
2009-12-07 12:50:58 UTC (rev 5377)
@@ -27,8 +27,13 @@
String xquery = DECLARE_NMWG_NAMESPACE + "
count(/nmwg:store[@type='"
+ collection + "'])";
XMLDBResult res = performXQuery(xquery);
- int result = res.getTotal();
- return (result > 0);
+ if(res.getTextResults().length==1){
+ int count=Integer.valueOf(res.getTextResults()[0]);
+ if(count>0){
+ return true;
+ }
+ }
+ return false;
}

public boolean isDBConnectivity() throws PerfSONARException {

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/actions/QueryActionTests.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/actions/QueryActionTests.java
2009-12-04 15:37:31 UTC (rev 5376)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/actions/QueryActionTests.java
2009-12-07 12:50:58 UTC (rev 5377)
@@ -37,15 +37,15 @@
msg.addChild(meta);

meta.addChild(subject);
+ meta.addChild(eventType);
meta.addChild(params);
- meta.addChild(eventType);
-
+
msg.addChild(data);

return msg;
}

- public void testEchoRequestProcessing() throws PerfSONARException {
+ public void testQueryRequestProcessing() throws PerfSONARException {

LSQueryServiceEngine engine = new LSQueryServiceEngine();
ServiceMessage serviceRequest = new ServiceMessage(

Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/dao/SummarizationDaoTests.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/dao/SummarizationDaoTests.java
2009-12-04 15:37:31 UTC (rev 5376)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/dao/SummarizationDaoTests.java
2009-12-07 12:50:58 UTC (rev 5377)
@@ -38,7 +38,7 @@

summarizationDAO.putSummaryData(meta);

- assertTrue(summarizationDAO.getSummaryData().getCount()>0);
+ assertTrue(summarizationDAO.getSummaryData().getTotal()>0);

}

@@ -68,7 +68,7 @@

summarizationDAO.removeSummaryData();

- summarizationDAO.putBatchData(elements, 1);
+ summarizationDAO.putBatchData(elements, 100);


assertTrue(summarizationDAO.getSummaryData().getTotal()==elements.size());


Modified:
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/dao/XQueryExistDAOImplTests.java
===================================================================
---
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/dao/XQueryExistDAOImplTests.java
2009-12-04 15:37:31 UTC (rev 5376)
+++
branches/new-structure-with-base2/ps-mdm-ls/src/test/java/org/perfsonar/tests/dao/XQueryExistDAOImplTests.java
2009-12-07 12:50:58 UTC (rev 5377)
@@ -14,9 +14,14 @@
import org.perfsonar.base2.xml.nmwg.Parameters;
import org.perfsonar.service.lookupservice.storage.LookupServiceDAO;
import org.perfsonar.service.lookupservice.storage.exist.CommonExistDAOImpl;
+import org.perfsonar.service.lookupservice.storage.exist.ExistDbManager;

public class XQueryExistDAOImplTests extends TestCase {

+ public XQueryExistDAOImplTests() throws PerfSONARException {
+ ExistDbManager.getService();
+ }
+
private LookupServiceDAO getXQueryExistDAOImplDao()
throws PerfSONARException {
return (LookupServiceDAO) ConfigurationManager
@@ -40,25 +45,28 @@
dao.putLookupInfo(meta, new Data[] { data1, data2 });
}

- public void testSaveDeleteLookupInformation() throws
PerfSONARException {
+ public void testSaveDeleteData() throws PerfSONARException {
+
LookupServiceDAO dao = getXQueryExistDAOImplDao();
assertNotNull(dao);

- String metadataId = "id";
+ String metadataId = "222";

insertExampleData(dao, metadataId);
+ assertTrue(dao.isLookupInfo(metadataId));
+ dao.removeLookupInfo(metadataId);
+ assertFalse(dao.isLookupInfo(metadataId));

- assertEquals(3, dao.removeLookupInfo(metadataId));
-
}

public void testQueryLookupInformation() throws PerfSONARException {
+
LookupServiceDAO dao = getXQueryExistDAOImplDao();
assertNotNull(dao);
String metadataId = "id";

insertExampleData(dao, metadataId);
-
+
assertTrue(dao.isLookupInfo(metadataId));

ArrayList<Element> elements = (ArrayList<Element>)
dao.performXQuery(
@@ -67,46 +75,46 @@
+ metadataId +
"']").getResults();
assertEquals(1, elements.size());
Metadata dbMetadata = (Metadata) elements.get(0);
-
+
assertEquals(metadataId, dbMetadata.getId());
-
+
dao.removeLookupInfo(metadataId);
-
+
}
-
-
+
public void testSaveControlParameter() throws PerfSONARException {
-
+
LookupServiceDAO dao = getXQueryExistDAOImplDao();
assertNotNull(dao);
String metadataId = "id";
insertExampleData(dao, metadataId);
-
- String paramName="parameter";
- String paramValue="value";
-
+
+ String paramName = "parameter";
+ String paramValue = "value";
+
dao.setControlParameter(metadataId, paramName, paramValue);
- ArrayList<Element> elements = (ArrayList<Element>)
dao.performXQuery(
- CommonExistDAOImpl.DECLARE_NMWG_NAMESPACE
- + "
/nmwg:store[@type='LSStore-control']/nmwg:metadata[@id='"
- + metadataId +
"']").getResults();
-
+ ArrayList<Element> elements = (ArrayList<Element>) dao
+ .performXQuery(
+
CommonExistDAOImpl.DECLARE_NMWG_NAMESPACE
+ + "
/nmwg:store[@type='LSStore-control']/nmwg:metadata[@id='"
+ + metadataId
+ "']").getResults();
+
assertEquals(1, elements.size());
Metadata dbMetadata = (Metadata) elements.get(0);
- Collection<Element>
parametersCollection=dbMetadata.getChildren("parameters");
- assertEquals(1,parametersCollection.size());
- Parameters
params=(Parameters)parametersCollection.iterator().next();
- Collection<Element> paramCollection=params.getChildren();
-
- assertEquals(1,paramCollection.size());
-
- Parameter param=(Parameter)paramCollection.iterator().next();
+ Collection<Element> parametersCollection = dbMetadata
+ .getChildren("parameters");
+ assertEquals(1, parametersCollection.size());
+ Parameters params = (Parameters)
parametersCollection.iterator().next();
+ Collection<Element> paramCollection = params.getChildren();
+
+ assertEquals(1, paramCollection.size());
+
+ Parameter param = (Parameter)
paramCollection.iterator().next();
assertEquals(paramName, param.getAttribute("name"));
assertEquals(paramValue, param.getAttribute("value"));
-
+
dao.removeLookupInfo(metadataId);
-
+
}
-

}



  • perfsonar: r5377 - in branches/new-structure-with-base2/ps-mdm-ls/src: main/java/org/perfsonar/service/lookupservice main/java/org/perfsonar/service/lookupservice/storage/exist test/java/org/perfsonar/tests/actions test/java/org/perfsonar/tests/dao, svnlog, 12/07/2009

Archive powered by MHonArc 2.6.16.

Top of Page