@Test public void testMethod() { if ("testcontext".equalsIgnoreCase(whatWasPassed)) { // only testcontext was provided assertNotNull(ctx); currentXmlTest = ctx.getCurrentXmlTest(); } assertNotNull(currentXmlTest); int number = Integer.parseInt(currentXmlTest.getParameter("number")); assertTrue(number != 0); } }
@Override public Module createModule(ITestContext context, Class<?> testClass) { String parameter = context.getCurrentXmlTest().getParameter("inject"); String expected = "guice"; if (!expected.equals(parameter)) { throw new RuntimeException("Excepted parameter to be " + expected + ", got " + parameter); } if (GuiceModuleFactoryTest.class == testClass) { return new GuiceExampleModule(); } else { throw new RuntimeException("Don't know how to create a module for class " + testClass); } } }
@Test public void failedFile() throws ParserConfigurationException, SAXException, IOException { XmlSuite xmlSuite = createXmlSuite("Suite"); xmlSuite.getParameters().put("n", "42"); XmlTest xmlTest = createXmlTest(xmlSuite, "Test"); xmlTest.addParameter("o", "43"); XmlClass xmlClass = createXmlClass(xmlTest, SimpleFailedSample.class); xmlClass.getLocalParameters().put("p", "44"); TestNG tng = create(xmlSuite); Path temp = Files.createTempDirectory("tmp"); tng.setOutputDirectory(temp.toAbsolutePath().toString()); tng.addListener((ITestNGListener) new FailedReporter()); tng.run(); Collection<XmlSuite> failedSuites = new Parser(temp.resolve(FailedReporter.TESTNG_FAILED_XML).toAbsolutePath().toString()).parse(); XmlSuite failedSuite = failedSuites.iterator().next(); Assert.assertEquals("42", failedSuite.getParameter("n")); XmlTest failedTest = failedSuite.getTests().get(0); Assert.assertEquals("43", failedTest.getParameter("o")); XmlClass failedClass = failedTest.getClasses().get(0); Assert.assertEquals("44", failedClass.getAllParameters().get("p")); } }
private final String getParameter(XmlTest xmlTest, String key, String defaultValue) { String value = xmlTest.getParameter(key); return value != null ? value : defaultValue; }
private final String getParameter(XmlTest xmlTest, String key, String defaultValue) { String value = xmlTest.getParameter(key); return value != null ? value : defaultValue; }
private final int getIntParameter(XmlTest xmlTest, String key, int defaultValue) { String value = xmlTest.getParameter(key); return value != null ? Integer.parseInt(value) : defaultValue; }
private final int getIntParameter(XmlTest xmlTest, String key, int defaultValue) { String value = xmlTest.getParameter(key); return value != null ? Integer.parseInt(value) : defaultValue; }
public static String getTestParameter(ITestContext context, String parameterName) { String value = context.getCurrentXmlTest().getParameter(parameterName); return checkNotNull(value, "test parameter not set: %s", parameterName); }
@Parameters({"wmTests", "wmBindAddress", "wmRoot", "wmPort"}) @Override public void onStart(ITestContext iTestContext) { if (isWiremockTest(iTestContext, "wmTests")) { logger.info("{} is a wiremock test.\n Wiremock server is starting...", iTestContext.getCurrentXmlTest().getName()); String wmBindAddress = iTestContext.getCurrentXmlTest().getParameter("wmBindAddress"); String wmRoot = iTestContext.getCurrentXmlTest().getParameter("wmRoot"); String wmPort = iTestContext.getCurrentXmlTest().getParameter("wmPort"); this.runNewServer(wmBindAddress, wmRoot, wmPort); logger.info("... Wiremock server started"); } }
@DataProvider(name = "responseTypesCodeIdTokenFailDataProvider") public Object[][] responseTypesCodeIdTokenFailDataProvider(ITestContext context) { String redirectUris = context.getCurrentXmlTest().getParameter("redirectUris"); String redirectUri = context.getCurrentXmlTest().getParameter("redirectUri"); String userId = context.getCurrentXmlTest().getParameter("userId"); String userSecret = context.getCurrentXmlTest().getParameter("userSecret"); String sectorIdentifierUri = context.getCurrentXmlTest().getParameter("sectorIdentifierUri"); return new Object[][]{ {redirectUris, redirectUri, userId, userSecret, Arrays.asList(ResponseType.TOKEN), sectorIdentifierUri}, {redirectUris, redirectUri, userId, userSecret, Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN), sectorIdentifierUri}, {redirectUris, redirectUri, userId, userSecret, Arrays.asList(ResponseType.CODE, ResponseType.TOKEN), sectorIdentifierUri}, {redirectUris, redirectUri, userId, userSecret, Arrays.asList(ResponseType.CODE, ResponseType.TOKEN, ResponseType.ID_TOKEN), sectorIdentifierUri}, }; }
@DataProvider(name = "responseTypesTokenIdTokenStep4DataProvider") public Object[][] responseTypesTokenIdTokenStep4DataProvider(ITestContext context) { String authorizePath = context.getCurrentXmlTest().getParameter("authorizePath"); String userId = context.getCurrentXmlTest().getParameter("userId"); String userSecret = context.getCurrentXmlTest().getParameter("userSecret"); String redirectUri = context.getCurrentXmlTest().getParameter("redirectUri"); return new Object[][]{{authorizePath, userId, userSecret, redirectUri, Arrays.asList(ResponseType.CODE)}, {authorizePath, userId, userSecret, redirectUri, Arrays.asList(ResponseType.CODE, ResponseType.ID_TOKEN)}, {authorizePath, userId, userSecret, redirectUri, Arrays.asList(ResponseType.CODE, ResponseType.TOKEN)}, {authorizePath, userId, userSecret, redirectUri, Arrays.asList(ResponseType.CODE, ResponseType.TOKEN, ResponseType.ID_TOKEN)},}; }
public synchronized static List<String> getTickets(ITestResult result) { // return any specified jira tickets by tests if (jiraTickets.get() != null) { return jiraTickets.get(); } List<String> tickets = new ArrayList<String>(); if (result.getTestContext().getCurrentXmlTest().getParameter(SpecialKeywords.JIRA_TICKET) != null) { tickets.add(result.getTestContext().getCurrentXmlTest().getParameter(SpecialKeywords.JIRA_TICKET)); } if (result.getMethod().getDescription() != null && result.getMethod().getDescription().contains(SpecialKeywords.JIRA_TICKET)) { tickets.clear(); String description = null; try { description = result.getMethod().getDescription(); tickets.add(description.split("#")[1].trim()); } catch (Exception e) { LOG.error("Incorrect Jira-ticket format: " + description, e); } } @SuppressWarnings("unchecked") Map<Object[], String> testnameJiraMap = (Map<Object[], String>) result.getTestContext().getAttribute(SpecialKeywords.JIRA_ARGS_MAP); if (testnameJiraMap != null) { String testHash = String.valueOf(Arrays.hashCode(result.getParameters())); if (testnameJiraMap.containsKey(testHash)) { tickets.clear(); tickets.add(testnameJiraMap.get(testHash)); } } return tickets; }
@DataProvider(name = "responseTypesTokenIdTokenFailDataProvider") public Object[][] responseTypesTokenIdTokenFailDataProvider(ITestContext context) { String redirectUris = context.getCurrentXmlTest().getParameter("redirectUris"); String redirectUri = context.getCurrentXmlTest().getParameter("redirectUri"); String userId = context.getCurrentXmlTest().getParameter("userId"); String userSecret = context.getCurrentXmlTest().getParameter("userSecret"); String sectorIdentifierUri = context.getCurrentXmlTest().getParameter("sectorIdentifierUri"); return new Object[][]{ {redirectUris, redirectUri, userId, userSecret, Arrays.asList(ResponseType.CODE), sectorIdentifierUri}, {redirectUris, redirectUri, userId, userSecret, Arrays.asList(ResponseType.CODE, ResponseType.ID_TOKEN), sectorIdentifierUri}, {redirectUris, redirectUri, userId, userSecret, Arrays.asList(ResponseType.CODE, ResponseType.TOKEN), sectorIdentifierUri}, {redirectUris, redirectUri, userId, userSecret, Arrays.asList(ResponseType.CODE, ResponseType.TOKEN, ResponseType.ID_TOKEN), sectorIdentifierUri}, }; }
@DataProvider(name = "responseTypesCodeIdTokenStep4DataProvider") public Object[][] responseTypesCodeIdTokenStep4DataProvider(ITestContext context) { String authorizePath = context.getCurrentXmlTest().getParameter("authorizePath"); String userId = context.getCurrentXmlTest().getParameter("userId"); String userSecret = context.getCurrentXmlTest().getParameter("userSecret"); String redirectUri = context.getCurrentXmlTest().getParameter("redirectUri"); return new Object[][]{{authorizePath, userId, userSecret, redirectUri, Arrays.asList(ResponseType.TOKEN)}, {authorizePath, userId, userSecret, redirectUri, Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN)}, {authorizePath, userId, userSecret, redirectUri, Arrays.asList(ResponseType.CODE, ResponseType.TOKEN)}, {authorizePath, userId, userSecret, redirectUri, Arrays.asList(ResponseType.CODE, ResponseType.TOKEN, ResponseType.ID_TOKEN)}, {authorizePath, userId, userSecret, redirectUri, Arrays.asList(ResponseType.ID_TOKEN)},}; }
@DataProvider(name = "omittedResponseTypesFailDataProvider") public Object[][] omittedResponseTypesFailDataProvider(ITestContext context) { String redirectUris = context.getCurrentXmlTest().getParameter("redirectUris"); String userId = context.getCurrentXmlTest().getParameter("userId"); String userSecret = context.getCurrentXmlTest().getParameter("userSecret"); String redirectUri = context.getCurrentXmlTest().getParameter("redirectUri"); String sectorIdentifierUri = context.getCurrentXmlTest().getParameter("sectorIdentifierUri"); return new Object[][]{ {redirectUris, redirectUri, userId, userSecret, Arrays.asList(ResponseType.CODE, ResponseType.ID_TOKEN), sectorIdentifierUri}, {redirectUris, redirectUri, userId, userSecret, Arrays.asList(ResponseType.TOKEN), sectorIdentifierUri}, {redirectUris, redirectUri, userId, userSecret, Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN), sectorIdentifierUri}, {redirectUris, redirectUri, userId, userSecret, Arrays.asList(ResponseType.CODE, ResponseType.TOKEN), sectorIdentifierUri}, {redirectUris, redirectUri, userId, userSecret, Arrays.asList(ResponseType.CODE, ResponseType.TOKEN, ResponseType.ID_TOKEN), sectorIdentifierUri}, {redirectUris, redirectUri, userId, userSecret, Arrays.asList(ResponseType.ID_TOKEN), sectorIdentifierUri}, }; }
@DataProvider(name = "omittedResponseTypesStep4DataProvider") public Object[][] omittedResponseTypesStep4DataProvider(ITestContext context) { String authorizePath = context.getCurrentXmlTest().getParameter("authorizePath"); String userId = context.getCurrentXmlTest().getParameter("userId"); String userSecret = context.getCurrentXmlTest().getParameter("userSecret"); String redirectUri = context.getCurrentXmlTest().getParameter("redirectUri"); return new Object[][]{ {authorizePath, userId, userSecret, redirectUri, Arrays.asList(ResponseType.CODE, ResponseType.ID_TOKEN)}, {authorizePath, userId, userSecret, redirectUri, Arrays.asList(ResponseType.TOKEN)}, {authorizePath, userId, userSecret, redirectUri, Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN)}, {authorizePath, userId, userSecret, redirectUri, Arrays.asList(ResponseType.CODE, ResponseType.TOKEN)}, {authorizePath, userId, userSecret, redirectUri, Arrays.asList(ResponseType.CODE, ResponseType.TOKEN, ResponseType.ID_TOKEN)}, {authorizePath, userId, userSecret, redirectUri, Arrays.asList(ResponseType.ID_TOKEN)},}; }
@DataProvider(name = "requestAuthorizationCustomHeaderDataProvider") public Object[][] omittedResponseTypesFailDataProvider(ITestContext context) { String userId = context.getCurrentXmlTest().getParameter("userId"); String userSecret = context.getCurrentXmlTest().getParameter("userSecret"); String redirectUris = context.getCurrentXmlTest().getParameter("redirectUris"); String redirectUri = context.getCurrentXmlTest().getParameter("redirectUri"); String sectorIdentifierUri = context.getCurrentXmlTest().getParameter("sectorIdentifierUri"); return new Object[][]{ {Arrays.asList(ResponseType.CODE), userId, userSecret, redirectUris, redirectUri, sectorIdentifierUri}, {Arrays.asList(ResponseType.TOKEN), userId, userSecret, redirectUris, redirectUri, sectorIdentifierUri}, {Arrays.asList(ResponseType.ID_TOKEN), userId, userSecret, redirectUris, redirectUri, sectorIdentifierUri}, {Arrays.asList(ResponseType.CODE, ResponseType.TOKEN), userId, userSecret, redirectUris, redirectUri, sectorIdentifierUri}, {Arrays.asList(ResponseType.CODE, ResponseType.ID_TOKEN), userId, userSecret, redirectUris, redirectUri, sectorIdentifierUri}, {Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN), userId, userSecret, redirectUris, redirectUri, sectorIdentifierUri}, {Arrays.asList(ResponseType.CODE, ResponseType.TOKEN, ResponseType.ID_TOKEN), userId, userSecret, redirectUris, redirectUri, sectorIdentifierUri}, }; } }
/** * Adds the list of conformance classes to the TestRun resource. A * conformance class corresponds to a {@literal <test>} tag in the TestNG * suite definition; it is represented as an earl:TestRequirement resource. * * @param earl * An RDF model containing EARL statements. * @param testList * The list of test sets comprising the test suite. */ void addTestRequirements(Model earl, final List<XmlTest> testList) { Seq reqs = earl.createSeq(); String key = null; for (XmlTest xmlTest : testList) { String testName = xmlTest.getName(); Resource testReq = earl.createResource(testName.replaceAll("\\s", "-"), EARL.TestRequirement); testReq.addProperty(DCTerms.title, testName); String testOptionality = xmlTest.getParameter(CITE.CC_OPTIONALITY); if (null != testOptionality && !testOptionality.isEmpty()) { testReq.addProperty(CITE.optionality, testOptionality); } if (isBasicConformanceClass(testName)) { testReq.addProperty(CITE.isBasic, "true"); } reqs.add(testReq); } this.testRun.addProperty(CITE.requirements, reqs); }
@BeforeSuite public void initTestSuite(ITestContext context) throws FileNotFoundException, IOException { SecurityProviderUtility.installBCProvider(); Reporter.log("Invoked init test suite method \n", true); String propertiesFile = context.getCurrentXmlTest().getParameter("propertiesFile"); if (StringHelper.isEmpty(propertiesFile)) { propertiesFile = "target/test-classes/testng.properties"; //propertiesFile = "U:\\own\\project\\git\\oxAuth\\Client\\src\\test\\resources\\testng_yuriy_ce_dev3.properties"; //propertiesFile = "/Users/JAVIER/IdeaProjects/oxAuth/Client/target/test-classes/testng.properties"; } FileInputStream conf = new FileInputStream(propertiesFile); Properties prop = new Properties(); prop.load(conf); Map<String, String> parameters = new HashMap<String, String>(); for (Entry<Object, Object> entry : prop.entrySet()) { Object key = entry.getKey(); Object value = entry.getValue(); if (StringHelper.isEmptyString(key) || StringHelper.isEmptyString(value)) { continue; } parameters.put(key.toString(), value.toString()); } // Overrided test paramters context.getSuite().getXmlSuite().setParameters(parameters); }
String testValue = testNGContext.getCurrentXmlTest().getParameter(attributeName);