String hostPattern = "hostPattern[" + (i + 1) + "]"; assertXpathEvaluatesTo(gateways[i].getAddress(), hostMatch + hostPattern, domDoc);
String hostMatch = String.format(hostMatchFormat, i + 1); assertXpathEvaluatesTo(gateways[i].getAddress(), hostMatch + "hostPattern", domDoc);  String prefix = prefixBuilder.toString(); assertXpathEvaluatesTo(prefix + "555", hostMatch + "userMatch/userPattern", domDoc); assertXpathEvaluatesTo(prefix + "666", hostMatch + "userMatch/userPattern[2]", domDoc); assertXpathEvaluatesTo(prefix + "777", hostMatch + "userMatch/userPattern[3]", domDoc); assertXpathEvaluatesTo("Voicemail", hostMatch + "/userMatch/permissionMatch/permission", domDoc); prefixBuilder.append("2");
    public void testGenerateMultipleGateways() throws Exception {        Gateway[] gateways = new Gateway[GATEWAYS_LEN];        for (int i = 0; i < gateways.length; i++) {            gateways[i] = new Gateway();            gateways[i].setUniqueId();            gateways[i].setAddress("10.1.2." + i);        }        IMocksControl control = EasyMock.createControl();        IDialingRule rule = control.createMock(IDialingRule.class);        rule.getDescription();        control.andReturn(null);        rule.getTransformedPatterns();        control.andReturn(new String[] {            "555", "666", "777"        });        rule.getPermissions();        control.andReturn(Arrays.asList(new Permission[] {            Permission.VOICEMAIL        }));        rule.getGateways();        control.andReturn(Arrays.asList(gateways));        rule.getName();        control.andReturn("testrule");        control.replay();        AuthRules authRules = new AuthRules();        authRules.begin();        authRules.generate(rule);        authRules.end();        Document document = authRules.getDocument();        String domDoc = XmlUnitHelper.asString(document);        String hostMatch = "/mappings/hostMatch/";        for (int i = 0; i < gateways.length; i++) {            String hostPattern = "hostPattern[" + (i + 1) + "]";            assertXpathEvaluatesTo(gateways[i].getAddress(), hostMatch + hostPattern, domDoc);        }        assertXpathEvaluatesTo("555", hostMatch + "userMatch/userPattern", domDoc);        assertXpathEvaluatesTo("666", hostMatch + "userMatch/userPattern[2]", domDoc);        assertXpathEvaluatesTo("777", hostMatch + "userMatch/userPattern[3]", domDoc);        assertXpathEvaluatesTo("Voicemail", hostMatch + "/userMatch/permissionMatch/permission",                domDoc);        String lastHostMatch = "/mappings/hostMatch[2]/";        // "no access" match at the end of the file - just checks if paths are that        // testGenerateNoAccessRule tests if values are correct        for (int i = 0; i < gateways.length; i++) {            assertXpathExists(lastHostMatch + "hostPattern[" + (i + 1) + "]", domDoc);        }        assertXpathEvaluatesTo(".", lastHostMatch + "userMatch/userPattern", domDoc);        assertXpathEvaluatesTo("NoAccess",                lastHostMatch + "userMatch/permissionMatch/permission", domDoc);        control.verify();    }