SenBotReferenceService { public String namespaceString(String plainString) throws RuntimeException { if(plainString.startsWith(NAME_SPACE_PREFIX)) { return (plainString.replace(NAME_SPACE_PREFIX, nameSpaceThreadLocale.get())); } if(plainString.startsWith(SCENARIO_NAME_SPACE_PREFIX)) { if(cucumberManager.getCurrentScenarioGlobals() == null) { throw new ScenarioNameSpaceAccessOutsideScenarioScopeException("You cannot fetch a Scneario namespace outside the scope of a scenario"); } return (plainString.replace(SCENARIO_NAME_SPACE_PREFIX, cucumberManager.getCurrentScenarioGlobals().getNameSpace())); } else { return plainString; } } SenBotReferenceService(String populatorClassName,
    		CucumberManager cucumberManager); void addUser(String refName, GenericUser user); void addPageReference(String pageReference, String pageUrl); void addLocatorReference(String locatorReference, By locator); By getElementLocatorForElementReference(String elementReference); By getElementLocatorForElementReference(String elementReference, String apendix); void addPageRepresentationReference(String name, Class clazz); GenericUser getUserForUserReference(String userReference); String getUrlForPageReference(String pageReference); Class getPageRepresentationReference(String pageRepresentationReference); T getPageRepresentationInstance(Class<T> referenceClassType); String namespaceString(String plainString); void addReference(Class<T> referenceClass, String referenceName, T referenceObject); Map<String, T> getObjectReferenceMap(Class<T> referenceClass); T getReference(Class<T> referenceClass, String referenceName); static final String NAME_SPACE_PREFIX; static final String SCENARIO_NAME_SPACE_PREFIX; }
@Test public void testSeleniumManager_NameSpace() { SenBotReferenceService referenceService = SenBotContext.getSenBotContext().getReferenceService(); String noNameSpace = "This is just a plain old string;!§$%&/()=?${}"; String namespacenizedNoNameSpace = referenceService.namespaceString(noNameSpace); assertTrue(noNameSpace.equals(namespacenizedNoNameSpace)); String nameSpace = referenceService.NAME_SPACE_PREFIX + " a String "; String namespacenizedNameSpace = referenceService.namespaceString(nameSpace); assertTrue(!nameSpace.equals(namespacenizedNameSpace)); }
@Test(expected = ScenarioNameSpaceAccessOutsideScenarioScopeException.class) public void testSeleniumManager_ScenarioNameSpace_outsideScenario() { SenBotReferenceService referenceService = SenBotContext.getSenBotContext().getReferenceService(); String scenarioNameSpace = referenceService.SCENARIO_NAME_SPACE_PREFIX + " a String "; referenceService.namespaceString(scenarioNameSpace); }
@Test public void testSeleniumManager_ScenarioNameSpace() { SenBotReferenceService referenceService = SenBotContext.getSenBotContext().getReferenceService(); SenBotContext.getSenBotContext().getCucumberManager().startNewScenario(); String noNameSpace = "This is just a plain old string;!§$%&/()=?${}"; String namespacenizedNoNameSpace = referenceService.namespaceString(noNameSpace); assertTrue(noNameSpace.equals(namespacenizedNoNameSpace)); String nameSpace = referenceService.NAME_SPACE_PREFIX + " a String "; String scenarioNameSpace = referenceService.SCENARIO_NAME_SPACE_PREFIX + " a String "; String nameSpacedValue = referenceService.namespaceString(nameSpace); String scenarioNameSpacedValue = referenceService.namespaceString(scenarioNameSpace); assertFalse("The returned value should have been changed", scenarioNameSpace.equals(scenarioNameSpacedValue)); assertFalse("The scenarion name space should be different than the normal name space", nameSpacedValue.equals(scenarioNameSpacedValue)); SenBotContext.getSenBotContext().getCucumberManager().stopNewScenario(); }
@Test public void testSeleniumManager_NameSpace_multipleCalls() { SenBotReferenceService referenceService = SenBotContext.getSenBotContext().getReferenceService(); String nameSpace = " a String " + referenceService.NAME_SPACE_PREFIX + " a String "; assertEquals(referenceService.namespaceString(nameSpace), referenceService.namespaceString(nameSpace)); }
@Test public void testSeleniumManager_NameSpace_midOfString() { SenBotReferenceService referenceService = SenBotContext.getSenBotContext().getReferenceService(); String nameSpace = " a String " + referenceService.NAME_SPACE_PREFIX + " a String "; assertNotEquals(referenceService.namespaceString(nameSpace), referenceService); }
@Test public void testSeleniumManager_NameSpace_multiOccurance() { SenBotReferenceService referenceService = SenBotContext.getSenBotContext().getReferenceService(); String nameSpace = referenceService.NAME_SPACE_PREFIX + " a String " + referenceService.NAME_SPACE_PREFIX + " a String "; assertNotEquals(referenceService.namespaceString(nameSpace), referenceService); }