Let API tests run without report_portal_integration, using dynamic loading 78/91478/5
authorIttay Stern <ittay.stern@att.com>
Wed, 17 Jul 2019 15:02:48 +0000 (18:02 +0300)
committerIttay Stern <ittay.stern@att.com>
Wed, 17 Jul 2019 15:06:43 +0000 (18:06 +0300)
- 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 <ittay.stern@att.com>
pom.xml
vid-automation/pom.xml
vid-automation/src/main/java/org/onap/vid/api/BaseApiTest.java
vid-automation/src/main/java/vid/automation/reportportal/ReportPortalListenerDelegator.java [new file with mode: 0644]
vid-automation/src/main/java/vid/automation/test/test/VidBaseTestCase.java
vid-automation/src/main/resources/reportportal.properties [deleted file]

diff --git a/pom.xml b/pom.xml
index b91431a..e2e911a 100644 (file)
--- a/pom.xml
+++ b/pom.xml
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
-                <version>2.3.2</version>
+                <version>3.5.1</version>
 
                 <configuration>
                     <debug>true</debug>
index c00f799..a6ca977 100644 (file)
@@ -8,10 +8,10 @@
     <properties>
         <springframework.version>5.1.6.RELEASE</springframework.version>
         <jersey.version>2.28</jersey.version>
-        <jackson.version>2.9.7</jackson.version>
+        <jackson.version>2.9.9</jackson.version>
         <aspectj.version>1.8.10</aspectj.version>
         <selenium.version>3.6.0</selenium.version>
-        <log4j.version>2.9.1</log4j.version>
+        <log4j.version>2.12.0</log4j.version>
         <apachehttp.version>4.4.1</apachehttp.version>
 
     </properties>
             <version>${log4j.version}</version>
         </dependency>
         <dependency>
-            <groupId>log4j</groupId>
-            <artifactId>log4j</artifactId>
-            <version>1.2.17</version>
-        </dependency>
-        <dependency>
-            <groupId>org.testng</groupId>
-            <artifactId>testng</artifactId>
-            <version>6.14.3</version>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-1.2-api</artifactId>
+            <version>${log4j.version}</version>
         </dependency>
         <dependency>
             <groupId>javax.ws.rs</groupId>
             <version>2.0.1</version>
         </dependency>
 
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <version>RELEASE</version>
-        </dependency>
         <dependency>
             <groupId>com.aventstack</groupId>
             <artifactId>extentreports</artifactId>
             <version>3.0.7</version>
         </dependency>
-        <dependency>
-            <groupId>org.seleniumhq.selenium</groupId>
-            <artifactId>selenium-java</artifactId>
-            <version>${selenium.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.seleniumhq.selenium</groupId>
-            <artifactId>selenium-server</artifactId>
-            <version>${selenium.version}</version>
-            <scope>runtime</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.seleniumhq.selenium</groupId>
-            <artifactId>selenium-api</artifactId>
-            <version>${selenium.version}</version>
-        </dependency>
 
         <dependency>
             <groupId>ch.qos.logback</groupId>
             <artifactId>browsermob-core</artifactId>
             <version>2.1.4</version>
         </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>RELEASE</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.seleniumhq.selenium</groupId>
+            <artifactId>selenium-java</artifactId>
+            <version>${selenium.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.seleniumhq.selenium</groupId>
+            <artifactId>selenium-server</artifactId>
+            <version>${selenium.version}</version>
+            <scope>runtime</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.seleniumhq.selenium</groupId>
+            <artifactId>selenium-api</artifactId>
+            <version>${selenium.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.functionaljava</groupId>
             <artifactId>functionaljava</artifactId>
             <version>RELEASE</version>
         </dependency>
-
+        <dependency>
+            <groupId>org.testng</groupId>
+            <artifactId>testng</artifactId>
+            <version>6.14.3</version>
+        </dependency>
         <dependency>
             <groupId>org.glassfish.jersey.core</groupId>
             <artifactId>jersey-common</artifactId>
             <artifactId>commons-beanutils</artifactId>
             <version>1.9.3</version>
         </dependency>
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-aop</artifactId>
-            <version>${springframework.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-core</artifactId>
-            <version>${springframework.version}</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>commons-logging</groupId>
-                    <artifactId>commons-logging</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-web</artifactId>
             <artifactId>jsonassert</artifactId>
             <version>1.5.0</version>
         </dependency>
-        <dependency>
-            <groupId>com.google.collections</groupId>
-            <artifactId>google-collections</artifactId>
-            <version>1.0</version>
-        </dependency>
         <dependency>
             <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>
             <artifactId>commons-lang3</artifactId>
             <version>3.6</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-proxy</artifactId>
+            <version>1.0</version>
+        </dependency>
+
         <dependency>
             <groupId>net.javacrumbs.json-unit</groupId>
             <artifactId>json-unit</artifactId>
             <version>2.2.0</version>
         </dependency>
-        <!--<dependency>-->
-            <!--<groupId>org.openecomp.vid</groupId>-->
-            <!--<artifactId>vid-ext-services-simulator-preset-gen</artifactId>-->
-            <!--<version>1.1.0-SNAPSHOT</version>-->
-        <!--</dependency>-->
         <dependency>
             <groupId>org.togglz</groupId>
             <artifactId>togglz-spring-core</artifactId>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.5.1</version>
                 <configuration>
                     <source>1.8</source>
                     <target>1.8</target>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-assembly-plugin</artifactId>
-                <version>2.5.5</version>
+                <version>3.1.1</version>
                 <executions>
                     <execution>
                         <id>create.jar.with.dependencies</id>
index 7ce2944..3778e4b 100644 (file)
@@ -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 (file)
index 0000000..6daa6d6
--- /dev/null
@@ -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);
+    }
+
+}
index ced874e..a45f258 100644 (file)
@@ -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 (file)
index ba8c260..0000000
+++ /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