From db98c7976e57f8bacbcc93b802b4d05b1db7b8cf Mon Sep 17 00:00:00 2001 From: Ittay Stern Date: Wed, 17 Jul 2019 18:02:48 +0300 Subject: [PATCH] Let API tests run without report_portal_integration, using dynamic loading MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - Removed @Step annotations, as pointcut is hardcoded in com.att->   .automation.common.report_portal_integration.aspects.StepAspects - Introduced ReportPortalListenerDelegator that loads com.att->   .automation.common.report_portal_integration if available - Optimized and organized dependencies - Upgrade maven-assembly-plugin to resolve "Java heap space" error. Issue-ID: VID-378 Change-Id: Iaf9279a48a1474d0ef6d0f514259dd383f6f5dbf Signed-off-by: Ittay Stern --- pom.xml | 2 +- vid-automation/pom.xml | 100 ++++++-------- .../main/java/org/onap/vid/api/BaseApiTest.java | 3 +- .../ReportPortalListenerDelegator.java | 147 +++++++++++++++++++++ .../vid/automation/test/test/VidBaseTestCase.java | 5 +- .../src/main/resources/reportportal.properties | 7 - 6 files changed, 194 insertions(+), 70 deletions(-) create mode 100644 vid-automation/src/main/java/vid/automation/reportportal/ReportPortalListenerDelegator.java delete mode 100644 vid-automation/src/main/resources/reportportal.properties diff --git a/pom.xml b/pom.xml index b91431abc..e2e911a52 100644 --- a/pom.xml +++ b/pom.xml @@ -133,7 +133,7 @@ org.apache.maven.plugins maven-compiler-plugin - 2.3.2 + 3.5.1 true diff --git a/vid-automation/pom.xml b/vid-automation/pom.xml index c00f79926..a6ca977b1 100644 --- a/vid-automation/pom.xml +++ b/vid-automation/pom.xml @@ -8,10 +8,10 @@ 5.1.6.RELEASE 2.28 - 2.9.7 + 2.9.9 1.8.10 3.6.0 - 2.9.1 + 2.12.0 4.4.1 @@ -33,14 +33,9 @@ ${log4j.version} - log4j - log4j - 1.2.17 - - - org.testng - testng - 6.14.3 + org.apache.logging.log4j + log4j-1.2-api + ${log4j.version} javax.ws.rs @@ -48,32 +43,11 @@ 2.0.1 - - junit - junit - RELEASE - com.aventstack extentreports 3.0.7 - - org.seleniumhq.selenium - selenium-java - ${selenium.version} - - - org.seleniumhq.selenium - selenium-server - ${selenium.version} - runtime - - - org.seleniumhq.selenium - selenium-api - ${selenium.version} - ch.qos.logback @@ -120,12 +94,39 @@ browsermob-core 2.1.4 + + junit + junit + RELEASE + + + + org.seleniumhq.selenium + selenium-java + ${selenium.version} + + + org.seleniumhq.selenium + selenium-server + ${selenium.version} + runtime + + + + org.seleniumhq.selenium + selenium-api + ${selenium.version} + org.functionaljava functionaljava RELEASE - + + org.testng + testng + 6.14.3 + org.glassfish.jersey.core jersey-common @@ -167,22 +168,6 @@ commons-beanutils 1.9.3 - - org.springframework - spring-aop - ${springframework.version} - - - org.springframework - spring-core - ${springframework.version} - - - commons-logging - commons-logging - - - org.springframework spring-web @@ -193,11 +178,6 @@ jsonassert 1.5.0 - - com.google.collections - google-collections - 1.0 - commons-io commons-io @@ -223,16 +203,17 @@ commons-lang3 3.6 + + org.apache.commons + commons-proxy + 1.0 + + net.javacrumbs.json-unit json-unit 2.2.0 - - - - - org.togglz togglz-spring-core @@ -260,6 +241,7 @@ org.apache.maven.plugins maven-compiler-plugin + 3.5.1 1.8 1.8 @@ -270,7 +252,7 @@ org.apache.maven.plugins maven-assembly-plugin - 2.5.5 + 3.1.1 create.jar.with.dependencies diff --git a/vid-automation/src/main/java/org/onap/vid/api/BaseApiTest.java b/vid-automation/src/main/java/org/onap/vid/api/BaseApiTest.java index 7ce29446c..3778e4b16 100644 --- a/vid-automation/src/main/java/org/onap/vid/api/BaseApiTest.java +++ b/vid-automation/src/main/java/org/onap/vid/api/BaseApiTest.java @@ -35,11 +35,12 @@ import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.client.RestTemplate; import org.testng.annotations.BeforeClass; import org.testng.annotations.Listeners; +import vid.automation.reportportal.ReportPortalListenerDelegator; import vid.automation.test.infra.FeaturesTogglingConfiguration; import vid.automation.test.services.UsersService; import vid.automation.test.utils.CookieAndJsonHttpHeadersInterceptor; -//@Listeners(ReportPortalListener.class) +@Listeners(ReportPortalListenerDelegator.class) public class BaseApiTest { protected static final Logger LOGGER = LogManager.getLogger(BaseApiTest.class); diff --git a/vid-automation/src/main/java/vid/automation/reportportal/ReportPortalListenerDelegator.java b/vid-automation/src/main/java/vid/automation/reportportal/ReportPortalListenerDelegator.java new file mode 100644 index 000000000..6daa6d604 --- /dev/null +++ b/vid-automation/src/main/java/vid/automation/reportportal/ReportPortalListenerDelegator.java @@ -0,0 +1,147 @@ +package vid.automation.reportportal; + +import static org.apache.commons.beanutils.MethodUtils.invokeStaticMethod; + +import org.apache.commons.proxy.ProxyFactory; +import org.apache.commons.proxy.factory.javassist.JavassistProxyFactory; +import org.apache.commons.proxy.invoker.NullInvoker; +import org.openqa.selenium.WebDriver; +import org.testng.IExecutionListener; +import org.testng.ISuite; +import org.testng.ISuiteListener; +import org.testng.ITestContext; +import org.testng.ITestResult; +import org.testng.internal.IResultListener2; + +/** + * Loads and delegates to ReportPortalListener. When class not found -- yields no-op object, and no side-effect. + */ +public class ReportPortalListenerDelegator implements IExecutionListener, ISuiteListener, IResultListener2 { + + private static final String CLASSNAME_REPORT_PORTAL_LISTENER = "com.att.automation.common.report_portal_integration.listeners.ReportPortalListener"; + private static final String CLASSNAME_WEB_DRIVER_SCREENSHOTS_PROVIDER = "com.att.automation.common.report_portal_integration.screenshots.WebDriverScreenshotsProvider"; + + private static final Object instance = createReportPortalListener(); + + private final IExecutionListener iExecutionListener; + private final ISuiteListener iSuiteListener; + private final IResultListener2 iResultListener2; + + public ReportPortalListenerDelegator() { + iExecutionListener = ((IExecutionListener) instance); + iSuiteListener = ((ISuiteListener) instance); + iResultListener2 = ((IResultListener2) instance); + } + + public static void setScreenShotsWebDriver(WebDriver driver) { + try { + invokeStaticMethod(instance.getClass(), "setScreenShotsProvider", createScreenshotsProvider(driver)); + } catch (ClassNotFoundException e) { + // if class not found, don't bother + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } + + + @Override + public void beforeConfiguration(ITestResult tr) { + iResultListener2.beforeConfiguration(tr); + } + + @Override + public void onConfigurationSuccess(ITestResult itr) { + iResultListener2.onConfigurationSuccess(itr); + } + + @Override + public void onConfigurationFailure(ITestResult itr) { + iResultListener2.onConfigurationFailure(itr); + } + + @Override + public void onConfigurationSkip(ITestResult itr) { + iResultListener2.onConfigurationSkip(itr); + } + + @Override + public void onExecutionStart() { + iExecutionListener.onExecutionStart(); + } + + @Override + public void onExecutionFinish() { + iExecutionListener.onExecutionFinish(); + } + + @Override + public void onStart(ISuite suite) { + iSuiteListener.onStart(suite); + + } + + @Override + public void onFinish(ISuite suite) { + iSuiteListener.onFinish(suite); + } + + @Override + public void onTestStart(ITestResult result) { + iResultListener2.onTestStart(result); + } + + @Override + public void onTestSuccess(ITestResult result) { + iResultListener2.onTestSuccess(result); + } + + @Override + public void onTestFailure(ITestResult result) { + iResultListener2.onTestFailure(result); + } + + @Override + public void onTestSkipped(ITestResult result) { + iResultListener2.onTestSkipped(result); + } + + @Override + public void onTestFailedButWithinSuccessPercentage(ITestResult result) { + iResultListener2.onTestFailedButWithinSuccessPercentage(result); + } + + @Override + public void onStart(ITestContext context) { + iResultListener2.onStart(context); + } + + @Override + public void onFinish(ITestContext context) { + iResultListener2.onFinish(context); + } + + + private static Object createReportPortalListener() { + try { + final Class classToLoad = Class.forName(CLASSNAME_REPORT_PORTAL_LISTENER, + true, ReportPortalListenerDelegator.class.getClassLoader()); + return classToLoad.getConstructor().newInstance(); + } catch (ClassNotFoundException e) { + // Fallback to NullInvoker + final Class[] classes = {IExecutionListener.class, ISuiteListener.class, IResultListener2.class}; + final ProxyFactory proxyFactory = new JavassistProxyFactory(); + + return proxyFactory.createInvokerProxy(new NullInvoker(), classes); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } + + private static Object createScreenshotsProvider(WebDriver driver) throws ReflectiveOperationException { + Class classToLoad = Class.forName(CLASSNAME_WEB_DRIVER_SCREENSHOTS_PROVIDER, + true, driver.getClass().getClassLoader()); + + return classToLoad.getDeclaredConstructor(WebDriver.class).newInstance(driver); + } + +} diff --git a/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java b/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java index ced874ee3..a45f25853 100644 --- a/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java +++ b/vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java @@ -33,6 +33,7 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Listeners; import org.testng.annotations.Test; +import vid.automation.reportportal.ReportPortalListenerDelegator; import vid.automation.test.Constants; import vid.automation.test.Constants.ViewEdit; import vid.automation.test.infra.*; @@ -70,7 +71,7 @@ import static org.testng.AssertJUnit.fail; import static vid.automation.test.utils.TestHelper.GET_SERVICE_MODELS_BY_DISTRIBUTION_STATUS; import static vid.automation.test.utils.TestHelper.GET_TENANTS; -//@Listeners(com.automation.common.report_portal_integration.listeners.ReportPortalListener.class) +@Listeners(ReportPortalListenerDelegator.class) public class VidBaseTestCase extends SetupCDTest{ protected final UsersService usersService = new UsersService(); @@ -153,7 +154,7 @@ public class VidBaseTestCase extends SetupCDTest{ @BeforeSuite(alwaysRun = true) public void screenShotsForReportPortal(){ try { - //ReportPortalListener.setScreenShotsProvider(new WebDriverScreenshotsProvider(getDriver())); + ReportPortalListenerDelegator.setScreenShotsWebDriver(getDriver()); System.out.println("Called to ReportPortalListener to set ScreenShotsProvider"); } catch (Exception e) { e.printStackTrace(); diff --git a/vid-automation/src/main/resources/reportportal.properties b/vid-automation/src/main/resources/reportportal.properties deleted file mode 100644 index ba8c26020..000000000 --- a/vid-automation/src/main/resources/reportportal.properties +++ /dev/null @@ -1,7 +0,0 @@ -rp.endpoint = http://reportportal.intl.att.com:8080 -rp.uuid=441fc8fa-84f9-468c-9c55-02b28c480770 -rp.project=VID -rp.mode=DEBUG -rp.enable=false -rp.launch=VID_UI -rp.skipped.issue = FALSE \ No newline at end of file -- 2.16.6