@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")); }
/** * 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; }