/**
  * Searches for a module matching the supplied URN. if a module instance that matches the supplied
  * URN exactly is found it is returned.
  *
  * <p>Otherwise, an attempt is made to find the first module that has the same URN elements as the
  * ones that are specified in the supplied URN and return it.
  *
  * <p>For example, if the supplied URN is <code>metc:mytype</code>, this method will return the
  * first module that is found to have a URN with the providerType 'mytype'.
  *
  * <p>Do note that this method doesn't do implement an efficient search as it iterates through the
  * URNs of all the modules. This may not be a huge issue, if the number of modules is small.
  * However, if the number of modules grows, we might want to use different data structures to make
  * the search more efficient.
  *
  * @param inURN the module URN
  * @return a module matching the supplied URN, null if no matching module could be found
  * @throws ModuleNotFoundException if multiple modules matching the supplied URN were found.
  */
 synchronized Module search(ModuleURN inURN) throws ModuleNotFoundException {
   Module m;
   // Look for an exact match
   m = get(inURN);
   if (m != null) {
     return m;
   }
   // Figure out which elements of the URN are specified.
   boolean noProviderType = inURN.providerType() == null || inURN.providerType().isEmpty();
   boolean noProviderName = inURN.providerName() == null || inURN.providerName().isEmpty();
   boolean noInstanceName = inURN.instanceName() == null || inURN.instanceName().isEmpty();
   // Match the first instance that matches all the specified fields
   // of the URN
   Module returnValue = null;
   for (ModuleURN i : mModules.keySet()) {
     if ((noProviderType || inURN.providerType().equals(i.providerType()))
         && (noProviderName || inURN.providerName().equals(i.providerName()))
         && (noInstanceName || inURN.instanceName().equals(i.instanceName()))) {
       if (returnValue == null) {
         returnValue = get(i);
       } else {
         throw new ModuleNotFoundException(
             new I18NBoundMessage3P(
                 Messages.MULTIPLE_MODULES_MATCH_URN,
                 inURN.getValue(),
                 returnValue.getURN().getValue(),
                 get(i).getURN().getValue()));
       }
     }
   }
   return returnValue;
 }
 /**
  * Verifies failures when incorrect request parameters are provided.
  *
  * @throws Exception if there were unexpected failures.
  */
 @Test
 public void invalidRequests_null() throws Exception {
   // null request
   new ExpectedFailure<IllegalRequestParameterValue>(
       org.marketcetera.module.Messages.ILLEGAL_REQ_PARM_VALUE, TEST_URN.getValue(), null) {
     protected void run() throws Exception {
       esperPr.requestData(new DataRequest(TEST_URN, null), null);
     }
   };
 }
 // what if we just send it an empty array as a request?
 @Test
 public void invalidRequests_EmptyArray() throws Exception {
   final String[] emptyParams = new String[0];
   new ExpectedTestFailure(
       IllegalRequestParameterValue.class,
       org.marketcetera.module.Messages.ILLEGAL_REQ_PARM_VALUE.getText(
           TEST_URN.getValue(), emptyParams)) {
     protected void execute() throws Throwable {
       esperPr.requestData(new DataRequest(TEST_URN, emptyParams), null);
     }
   }.run();
 }