public void testAllowBareFromEntityOnlyOnSingleBoundResource() throws XMLSemanticError, BindException {
// from="client@vysper.org" is only allowed when a single resource is bound
// if there is more than one resource bound in the same session, from must come
// fully qualified, e.g. from="client@vysper.org/resourceId"
Entity server = sessionContext.getServerRuntimeContext().getServerEnitity();
sessionContext.setSessionState(SessionState.AUTHENTICATED);
// the session is running for 'lea'
sessionContext.setInitiatingEntity(new EntityImpl("lea", server.getDomain(), null));
CallTestStanzaHandler stanzaHandler = new CallTestStanzaHandler("iq", "testNSURI");
namespaceHandlerDictionary.register(stanzaHandler);
String firstBoundResource = sessionContext.bindResource();
String secondBoundResource = sessionContext.bindResource();
StanzaBuilder stanzaBuilder = StanzaBuilder.createIQStanza(null, null, IQStanzaType.GET, "test");
stanzaBuilder.addAttribute("from", new EntityImpl("lea", server.getDomain(), null).getFullQualifiedName());
stanzaBuilder.startInnerElement("query", "testNSURI").endInnerElement();
protocolWorker.processStanza(sessionContext.getServerRuntimeContext(), sessionContext, stanzaBuilder.build(),
sessionStateHolder);
Stanza recordedResponse = sessionContext.getNextRecordedResponse();
assertUnknownSenderError(recordedResponse); // not allowed, bare id without resource and two resources bound
sessionContext.reset();
// unbind second resource, leaving only one
boolean noResourceRemains = sessionContext.getServerRuntimeContext().getResourceRegistry().unbindResource(
secondBoundResource);
assertFalse(noResourceRemains);
// bare id allowed, only one resource is bound
stanzaBuilder = StanzaBuilder.createIQStanza(null, null, IQStanzaType.GET, "test");
stanzaBuilder.addAttribute("from", new EntityImpl("lea", server.getDomain(), null).getFullQualifiedName());
stanzaBuilder.startInnerElement("query", "testNSURI").endInnerElement();
protocolWorker.processStanza(sessionContext.getServerRuntimeContext(), sessionContext, stanzaBuilder.build(),
sessionStateHolder);
stanzaHandler.assertHandlerCalled();
sessionContext.reset();
// second resource is now invalid and cannot be used anymore in a full qualified entity
stanzaBuilder = StanzaBuilder.createIQStanza(null, null, IQStanzaType.GET, "test");
stanzaBuilder.addAttribute("from", new EntityImpl("lea", server.getDomain(), secondBoundResource)
.getFullQualifiedName());
stanzaBuilder.startInnerElement("query", "testNSURI").endInnerElement();
protocolWorker.processStanza(sessionContext.getServerRuntimeContext(), sessionContext, stanzaBuilder.build(),
sessionStateHolder);
recordedResponse = sessionContext.getNextRecordedResponse();