@Ignore
  // Move this test to Integration test suite
  @Test
  public void NoMatch() throws Exception {
    TopicConfigurationManager topicConfigurationManager = TopicConfigurationManager.getInstance();
    TopicConfigurationEntry topicConfigEntry;

    Element topic =
        XmlUtility.convertXmlToElement(
            "<wsnt:Topic xmlns:wsnt=\"http://docs.oasis-open.org/wsn/b-2\" xmlns:n=\"http://www.hhs.gov/healthit/nhin\" Dialect=\"http://doc.oasis-open.org/wsn/t-1/TopicExpression/Simple\">NoTopic</wsnt:Topic>");
    topicConfigEntry = topicConfigurationManager.getTopicConfiguration(topic);
    assertNull(topicConfigEntry);
  }
  public static AdhocQueryType unmarshalAdhocQuery(Element adhocQueryElement) {
    AdhocQueryType unmarshalledObject = null;
    String contextPath = "oasis.names.tc.ebxml_regrep.xsd.rim._3";
    LOG.debug("begin unmarshal");

    if (adhocQueryElement == null) {
      LOG.warn("element to unmarshal is null");
    } else {
      try {
        LOG.debug("desializing element");
        String serializedElement = XmlUtility.serializeElement(adhocQueryElement);
        LOG.debug("serializedElement=[" + serializedElement + "]");
        LOG.debug("get instance of JAXBContext [contextPath='" + contextPath + "']");
        JAXBContextHandler oHandler = new JAXBContextHandler();
        JAXBContext jc = oHandler.getJAXBContext(contextPath);
        LOG.debug("get instance of unmarshaller");
        javax.xml.bind.Unmarshaller unmarshaller = jc.createUnmarshaller();
        LOG.debug("init stringReader");
        StringReader stringReader = new StringReader(serializedElement);
        LOG.debug("Calling unmarshal");
        JAXBElement<AdhocQueryType> jaxbElement =
            (JAXBElement<AdhocQueryType>) unmarshaller.unmarshal(stringReader);
        LOG.debug("unmarshalled to JAXBElement");
        unmarshalledObject = jaxbElement.getValue();
        LOG.debug("end unmarshal");
      } catch (Exception e) {
        // "java.security.PrivilegedActionException: java.lang.ClassNotFoundException:
        // com.sun.xml.bind.v2.ContextFactory"
        // use jaxb element
        LOG.error("Failed to unmarshall: " + e.getMessage(), e);
        unmarshalledObject = null;
      }
    }

    return unmarshalledObject;
  }
  public void notify(
      Element notifyElement,
      ReferenceParametersElements referenceParametersElements,
      AssertionType assertion,
      NhinTargetSystemType target) {
    String url = null;

    log.debug(
        "Notify element received in NhinHiemNotifyWebServiceProxy: "
            + XmlUtility.serializeElementIgnoreFaults(notifyElement));

    if (target != null) {
      try {
        url =
            ConnectionManagerCache.getEndpontURLFromNhinTarget(
                target, NhincConstants.HIEM_NOTIFY_SERVICE_NAME);
      } catch (ConnectionManagerException ex) {
        log.error(
            "Error: Failed to retrieve url for service: "
                + NhincConstants.HIEM_NOTIFY_SERVICE_NAME);
        log.error(ex.getMessage());
      }
    } else {
      log.error("Target system passed into the proxy is null");
    }

    try {
      if (NullChecker.isNotNullish(url)) {
        NotificationConsumer port = getPort(url);

        log.debug("unmarshaling notify message");
        WsntSubscribeMarshaller notifyMarshaller = new WsntSubscribeMarshaller();
        Notify notify = notifyMarshaller.unmarshalNotifyRequest(notifyElement);

        //                Element reMarshalled = notifyMarshaller.marshalNotifyRequest(notify);
        //                log.debug("REMARSHALLED: " +
        // XmlUtility.serializeElementIgnoreFaults(reMarshalled));

        // Policy check
        log.debug("Calling checkPolicy");
        if (checkPolicy(notify, assertion)) {
          log.debug("attaching reference parameter headers");
          SoapUtil soapUtil = new SoapUtil();
          soapUtil.attachReferenceParameterElements(
              (WSBindingProvider) port, referenceParametersElements);

          auditInputMessage(notify, assertion);

          log.debug("Calling token creator");
          SamlTokenCreator tokenCreator = new SamlTokenCreator();
          Map requestContext =
              tokenCreator.CreateRequestContext(assertion, url, NhincConstants.SUBSCRIBE_ACTION);
          ((BindingProvider) port).getRequestContext().putAll(requestContext);

          try {
            log.debug("Calling notification consumer port in NhinHiemWebServiceProxy.");
            port.notify(notify);
          } catch (Exception ex) {
            log.error("Error occurred while trying to invoke notify", ex);
          }

          ((Closeable) port).close();
        } else {
          log.error("Failed policy check on send NHIN notify message");
        }
      } else {
        log.error("The URL for service: " + NhincConstants.HIEM_NOTIFY_SERVICE_NAME + " is null");
      }
    } catch (Throwable t) {
      // TODO: Figure out what to do with the exception
      log.error("Error sending notify to remote gateway: " + t.getMessage(), t);
    }
  }
  public SubscribeResponse handleSubscribe(
      TopicConfigurationEntry topicConfig,
      Subscribe subscribe,
      Element subscribeElement,
      AssertionType assertion,
      NhinTargetCommunitiesType targetCommunitites)
      throws TopicNotSupportedFault, InvalidTopicExpressionFault, SubscribeCreationFailedFault {
    log.debug(
        "In handleSubscribe - patient id: "
            + patientIdentifier.getSubjectIdentifier()
            + ", assigning authority: "
            + patientIdentifier.getAssigningAuthorityIdentifier());
    SubscribeResponse response = new SubscribeResponse();
    CMUrlInfos urlInfoList = null;

    // Store initial subscription received from agency adapter (the parent subscription)
    EndpointReferenceType parentSubscriptionReference =
        storeSubscription(subscribe, subscribeElement, assertion, targetCommunitites);
    String parentSubscriptionReferenceXml = null;
    if (parentSubscriptionReference != null) {
      parentSubscriptionReferenceXml = serializeEndpointReferenceType(parentSubscriptionReference);
    }

    // Obtain all the URLs for the targets being sent to
    try {
      urlInfoList =
          ConnectionManagerCache.getEndpontURLFromNhinTargetCommunities(
              targetCommunitites, NhincConstants.HIEM_SUBSCRIBE_SERVICE_NAME);
    } catch (ConnectionManagerException ex) {
      log.error("Failed to obtain target URLs");
      return null;
    }

    // Find patient correlations
    List<QualifiedSubjectIdentifierType> correlations = determineTargets(urlInfoList);

    // Common message preparation

    int correlationCount = 1;
    if (correlations != null) {
      log.debug("Processing correlation #" + correlationCount++);
      AssigningAuthorityHomeCommunityMappingDAO assigningAuthorityDao =
          new AssigningAuthorityHomeCommunityMappingDAO();
      for (QualifiedSubjectIdentifierType correlation : correlations) {
        CMUrlInfo community = new CMUrlInfo();
        String remoteCommunityId =
            assigningAuthorityDao.getHomeCommunityId(correlation.getAssigningAuthorityIdentifier());
        if (log.isDebugEnabled()) {
          log.debug(
              "Remote assigning authority id: " + correlation.getAssigningAuthorityIdentifier());
          log.debug("Mapped remote community id: " + remoteCommunityId);
        }

        community = findTarget(remoteCommunityId, urlInfoList);

        if (community == null) {
          continue;
        }

        //      Update Subscribe
        updateSubscribe(subscribeElement, correlation);
        if (log.isDebugEnabled()) {
          log.debug(
              "@@@ Updated subscribe: "
                  + XmlUtility.serializeElementIgnoreFaults(subscribeElement));
        }
        //      Policy check - performed in proxy?
        //      Audit Event - performed in proxy?
        //      Send Subscribe
        Element childSubscribeElement = subscribeElement;
        SubscribeResponse subscribeResponse =
            sendSubscribeRequest(childSubscribeElement, assertion, community);
        //
        //      Store subscription
        if (subscribeResponse != null) {
          String childSubscriptionReference = null;

          // Use reflection to get the correct subscription reference object
          Object subRef = getSubscriptionReference(subscribeResponse);
          if (subRef != null) {
            if (subRef.getClass().isAssignableFrom(EndpointReferenceType.class)) {
              childSubscriptionReference =
                  serializeEndpointReferenceType((EndpointReferenceType) subRef);
            } else if (subRef.getClass().isAssignableFrom(W3CEndpointReference.class)) {
              childSubscriptionReference =
                  serializeW3CEndpointReference((W3CEndpointReference) subRef);
            } else {
              log.error("Unknown subscription reference type: " + subRef.getClass().getName());
            }

            String childSubscribeXml;
            try {
              childSubscribeXml = XmlUtility.serializeElement(childSubscribeElement);
            } catch (Exception ex) {
              log.error("failed to process subscribe xml", ex);
              childSubscribeXml = null;
            }

            storeChildSubscription(
                childSubscribeXml, childSubscriptionReference, parentSubscriptionReferenceXml);
          } else {
            log.error("Subscription reference was null");
          }
        } else {
          log.error("The subscribe response message was null.");
        }
      }
    }
    setSubscriptionReference(response, parentSubscriptionReference);

    return response;
  }