All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aventstack.extentreports.GherkinKeyword Maven / Gradle / Ivy

There is a newer version: 5.1.1
Show newest version
package com.aventstack.extentreports;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.aventstack.extentreports.gherkin.GherkinDialect;
import com.aventstack.extentreports.gherkin.GherkinDialectProvider;
import com.aventstack.extentreports.gherkin.model.Asterisk;
import com.aventstack.extentreports.gherkin.model.IGherkinFormatterModel;

import freemarker.template.utility.StringUtil;

/**
 * Allows {@link IGherkinFormatterModel} to be returned by using a name, from
 * the below gherkin model classes:
 * 
 * 
    *
  • {@link com.aventstack.extentreports.gherkin.model.Feature}
  • *
  • {@link com.aventstack.extentreports.gherkin.model.Background}
  • *
  • {@link com.aventstack.extentreports.gherkin.model.Scenario}
  • *
  • {@link com.aventstack.extentreports.gherkin.model.Given}
  • *
  • {@link com.aventstack.extentreports.gherkin.model.When}
  • *
  • {@link com.aventstack.extentreports.gherkin.model.Then}
  • *
  • {@link com.aventstack.extentreports.gherkin.model.And}
  • *
  • {@link com.aventstack.extentreports.gherkin.model.But}
  • *
* *

* Example: *

* *
 * extent.createTest(new GherkinKeyword("Feature"), "bddTest");
 * test.createNode(new GherkinKeyword("Scenario"), bddNode");
 * 
* * @see IGherkinFormatterModel */ public class GherkinKeyword { private static final Logger logger = Logger.getLogger(GherkinKeyword.class.getName()); private Class clazz = IGherkinFormatterModel.class; private IGherkinFormatterModel keywordClazz; public GherkinKeyword(String keyword) throws ClassNotFoundException { GherkinDialect dialect = null; String apiKeyword = StringUtil.capitalize(keyword.trim()); String refPath = clazz.getPackage().getName(); try { apiKeyword = apiKeyword.equals("*") ? Asterisk.class.getSimpleName() : apiKeyword; dialect = GherkinDialectProvider.getDialect(); if (dialect != null && !dialect.getLanguage().equalsIgnoreCase(GherkinDialectProvider.getDefaultLanguage())) { apiKeyword = null; Map> keywords = dialect.getKeywords(); for (Entry> key : keywords.entrySet()) { boolean keywordLocated = key.getValue().stream() .anyMatch(x -> x.trim().equalsIgnoreCase(keyword.trim())); if (keywordLocated) { apiKeyword = StringUtil.capitalize(key.getKey()); break; } } } if (apiKeyword == null) { throw new GherkinKeywordNotFoundException("Keyword " + apiKeyword + " cannot be null"); } String clazzName = refPath + "." + apiKeyword.replace(" ", ""); Class c = Class.forName(clazzName); keywordClazz = (IGherkinFormatterModel) c.newInstance(); } catch (InstantiationException | IllegalAccessException e) { logger.log(Level.SEVERE, "", e); } } IGherkinFormatterModel getKeyword() { return keywordClazz; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy