@Test
  public void addParticipantRefTest() {
    grou = new Grounding(topo);

    ParticipantRef pref1 =
        new ParticipantRef("Ref1", new QName("http://example.com", "localpart1", "cns"));

    ParticipantRef pref2 =
        new ParticipantRef("Ref2", new QName("http://example.com/2", "localpart2", "cns"));

    // 1.
    int expectedInt = grou.getParticipantRefs().size() + 1;
    grou.add(pref1);
    int actualInt = grou.getParticipantRefs().size();
    Assert.assertEquals(expectedInt, actualInt);
    Assert.assertEquals("http://example.com", grou.getNamespaceMap().get("cns"));

    // 2.
    expectedInt = grou.getParticipantRefs().size() + 1;
    grou.add(pref2);
    actualInt = grou.getParticipantRefs().size();
    Assert.assertEquals(expectedInt, actualInt);
    Assert.assertTrue(
        grou.getNamespaceMap().getReverse("http://example.com/2").get(0).equals("cns1"));
  }
  @Test
  public void addMessageLinkTest() {
    grou = new Grounding(topo);
    // test case
    // input: a messageLink will be added, it's portType will contains a new namespace.
    // expected: 1) the namespace is collected in the namespaceMap
    //           2) the messageLink is added to grounding
    //           3) if new prefix is created, the qName(portType) in the messageLink should be
    // updated.
    org.bpel4chor.model.topology.impl.MessageLink tMsgLink =
        new org.bpel4chor.model.topology.impl.MessageLink();
    tMsgLink.setName("eTicket");

    String ns = "www.wsdl.com";
    String localpart = "input";
    String prefix = "wsdl";
    QName portType = new QName(ns, localpart, prefix);

    MessageLink ml = new MessageLink(tMsgLink, portType, "sendTicket");

    // 1)
    String expectedString = ns;
    int expectedSize = grou.getNamespaceMap().size() + 1;
    grou.add(ml);
    String actualString = grou.getNamespaceMap().get(prefix);
    Assert.assertEquals(expectedString, actualString);

    // 2
    int actualSize = grou.getNamespaceMap().size();
    Assert.assertEquals(expectedSize, actualSize);

    // 3
    org.bpel4chor.model.topology.impl.MessageLink tMsgLink2 =
        new org.bpel4chor.model.topology.impl.MessageLink();
    tMsgLink2.setName("eTicket2");

    QName portType2 = new QName("http://www.example.com/receive", "localpart", "wsdl");
    MessageLink ml2 = new MessageLink(tMsgLink2, portType2, "receiveTicket");
    grou.add(ml2);
    String oldPrefix = "wsdl";
    String newPrefix = ml2.getPortType().getPrefix();
    Assert.assertFalse(newPrefix.equals(oldPrefix));
  }
  @Test
  public void GroundingImplTopologyRefTest() {
    grou = new Grounding(topo);
    String expected = BPEL4ChorConstants.TOPOLOGY_XMLNS;
    String actual = grou.getNamespaceMap().get("tns");
    Assert.assertEquals(expected, actual);

    QName expectedQName =
        new QName(
            topo.getTargetNamespace(), topo.getName(), BPEL4ChorConstants.TOPOLOGY_PREFIX_BASE);
    QName actualQName = grou.getTopology();
    Assert.assertEquals(
        BPEL4ChorUtil.getString(expectedQName), BPEL4ChorUtil.getString(actualQName));
  }
Ejemplo n.º 4
0
  /**
   * Read in the grounding file from the given InputStream
   *
   * @param inputStream The {@link InputStream} for reading
   * @param topology The {@link Topology} belonging to the Grounding
   * @return The read {@link Grounding}
   */
  public static Grounding readGrounding(InputStream inputStream, Topology topology) {
    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLStreamReader parser;
    Grounding grounding = null;

    try {
      parser = factory.createXMLStreamReader(inputStream);

      if ((parser.getEventType() == XMLStreamConstants.START_DOCUMENT)) {
        parser.nextTag();
      }

      if (parser.getLocalName().equals("grounding")
          && !(parser.getEventType() == XMLStreamConstants.END_ELEMENT)) {

        grounding = new Grounding(topology);
        for (int i = 0; i < parser.getNamespaceCount(); i++) {
          if (parser.getNamespacePrefix(i) != null) {
            grounding
                .getNamespaceMap()
                .addNamespace(parser.getNamespaceURI(i), parser.getNamespacePrefix(i));
          }
        }

        grounding.setTargetNamespace(
            BPEL4ChorReader.getStrAttribute(parser, "targetNamespace", true).toString());

        parser.nextTag();
      }
      if (parser.getLocalName().equals("messageLinks")) {

        parser.nextTag();
        while (parser.hasNext() && parser.getLocalName().equals("messageLink")) {
          if (!(parser.getEventType() == XMLStreamConstants.END_ELEMENT)) {

            grounding
                .getMessageLinks()
                .add(
                    BPEL4ChorReader.readInMessageLinkGD(
                        parser, grounding.getNamespaceMap(), topology));
          }
          parser.nextTag();
        }
        parser.nextTag();
      }

      if (parser.getLocalName().equals("participantRefs")) {
        parser.nextTag();
        while (parser.hasNext() && parser.getLocalName().equals("participantRef")) {
          if (!(parser.getEventType() == XMLStreamConstants.END_ELEMENT)) {

            grounding
                .getParticipantRefs()
                .add(BPEL4ChorReader.readInParticipantRef(parser, grounding.getNamespaceMap()));
          }
          parser.nextTag();
        }
        parser.nextTag();
      }

      if (parser.getLocalName().equals("properties")) {
        parser.nextTag();
        while (parser.hasNext() && parser.getLocalName().equals("property")) {

          if (!(parser.getEventType() == XMLStreamConstants.END_ELEMENT)) {

            grounding
                .getProperties()
                .add(BPEL4ChorReader.readInProperty(parser, grounding.getNamespaceMap()));
          }
          parser.nextTag();
        }
        parser.nextTag();
      }

    } catch (XMLStreamException e) {
      e.printStackTrace();

    } catch (MalformedTLGLSyntaxException e) {
      e.printStackTrace();
    }

    return grounding;
  }