remove debug log prints
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / api / ComponentBaseTest.java
index a9cc119..4803bb5 100644 (file)
@@ -60,7 +60,7 @@ import org.openecomp.sdc.ci.tests.utils.Utils;
 import org.openecomp.sdc.ci.tests.utils.cassandra.CassandraUtils;
 import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils;
 import org.openecomp.sdc.ci.tests.utils.general.ElementFactory;
-import org.openecomp.sdc.ci.tests.utils.rest.AutomationUtils;
+import org.openecomp.sdc.ci.tests.utils.general.FileHandling;
 import org.openecomp.sdc.ci.tests.utils.rest.BaseRestUtils;
 import org.openecomp.sdc.ci.tests.utils.rest.CatalogRestUtils;
 import org.openecomp.sdc.ci.tests.utils.rest.CategoryRestUtils;
@@ -76,8 +76,8 @@ import org.testng.annotations.AfterMethod;
 import org.testng.annotations.AfterSuite;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.Test;
 
-import com.aventstack.extentreports.ExtentReports;
 import com.aventstack.extentreports.ExtentTest;
 import com.aventstack.extentreports.Status;
 import com.thinkaurelius.titan.core.TitanFactory;
@@ -94,17 +94,16 @@ public abstract class ComponentBaseTest {
        protected static Logger logger= Logger.getLogger(ComponentBaseTest.class);      
        
 
-       // public ComponentBaseTest(TestName testName, String className) {
-       // super(testName, className);
-       // }
+//      public ComponentBaseTest(TestName testName, String className) {
+//      super(testName, className);
+//      }
 
-       protected static ExtentReports extentReport;
-       public static final String REPORT_FOLDER = "./ExtentReport/";
+       protected static final String REPORT_FOLDER = "." + File.separator + "ExtentReport" + File.separator;
        private static final String VERSIONS_INFO_FILE_NAME = "versions.info";
        private static final String REPORT_FILE_NAME = "SDC_CI_Extent_Report.html";
        protected static TitanGraph titanGraph;
-       private static Config myconfig;
        public static Config config;
+       protected static ITestContext myContext;
        
        
        
@@ -124,105 +123,53 @@ public abstract class ComponentBaseTest {
                lc.getLogger("com.datastax").setLevel(Level.INFO);
                lc.getLogger("io.netty").setLevel(Level.INFO);
                lc.getLogger("c.d").setLevel(Level.INFO);
+               lc.getLogger("o.a.h").setLevel(Level.INFO);
+               lc.getLogger("o.o.s.c.t.d.h").setLevel(Level.INFO);
+       }
+       
+       public static String getReportFolder() {
+               return REPORT_FOLDER;
        }
 
        @BeforeSuite(alwaysRun = true)
-       public static void openTitan(ITestContext context) throws Exception {
-                               
-               logger.info("<<<BeforeSuite>>>");
-               myconfig = Utils.getConfig();
+       public void setupBeforeSuite(ITestContext context) throws Exception {
                config = Utils.getConfig();
-
-               File dir = new File(REPORT_FOLDER);
-               try {
-                       FileUtils.deleteDirectory(dir);
-               } catch (IOException e) {
-               }
-               dir.mkdir();
-               
-               System.out.println("BeforeSuite  - get reporter");
-               extentReport = ExtentManager.getReporter(REPORT_FOLDER + REPORT_FILE_NAME);
-               
-               String onboardVersion = AutomationUtils.getOnboardVersion();
-               String osVersion = AutomationUtils.getOSVersion();
-               String envData = myconfig.getUrl();
-               // TODO: uncomment config file
-//             extentReport.loadConfig(AutomationUtils.getConfigFile(CONFIG_FILE));
-               
-               extentReport.setSystemInfo("Onboard Version", onboardVersion);
-               extentReport.setSystemInfo("OS Version", osVersion);
-               extentReport.setSystemInfo("ExecutedOn", envData);
-               extentReport.setSystemInfo("SuiteName", context.getName());
-               AutomationUtils.createVersionsInfoFile(REPORT_FOLDER + VERSIONS_INFO_FILE_NAME, onboardVersion, osVersion, envData);
-
-               System.out.println("BeforeSuite - open titan");
-               openTitanLogic();
-               
-               System.out.println("BeforeSuite - createConsumer");
+               myContext=context;
+               ExtentManager.initReporter(getReportFolder(), REPORT_FILE_NAME, context);       
                AtomicOperationUtils.createDefaultConsumer(true);
-               
-               System.out.println("BeforeSuite - performClean");
+               openTitanLogic();
                performClean();
-       }
-
-       protected static void openTitanLogic() throws Exception {
-       
-               logger.trace(config.toString());
-               String titanConfigFilePath = myconfig.getTitanPropertiesFile();
-               titanGraph = TitanFactory.open(titanConfigFilePath);
-               assertNotNull(titanGraph);
                
+               String basePath = FileHandling.getBasePath();
+               String csarDir = FileHandling.getCreateDirByName("outputCsar");
+               FileUtils.cleanDirectory(new File(csarDir));
        }
        
-       @AfterClass(alwaysRun = true)
-       public synchronized static void cleanAfterClass() throws Exception{
-               
-//             System.out.println("<<<<<<<<class name>>>>>"+method.getDeclaringClass());
-//             System.out.println("<<<<<<<<class name>>>>>"+method.getName());
-               
-               
-               System.out.println("delete components AfterClass");
-               deleteCreatedComponents(getCatalogAsMap());
-//             extentReport.flush();
-
-       }
-       
-       @AfterSuite(alwaysRun = true)
-       public static void shutdownTitan() throws Exception {
-               
-               System.out.println("AfterSuite  - flush report");
-               extentReport.flush();
-               System.out.println("AfterSuite  - perform clean");
-               performClean();
-               System.out.println("AfterSuite  - close report");
-//             extentReport.close();
-               System.out.println("AfterSuite  - close titan");
-               shutdownTitanLogic();
-               System.out.println("AfterSuite  - suite ended");
-       }
+       @BeforeMethod(alwaysRun = true)
+       public void setBrowserBeforeTest(java.lang.reflect.Method method, ITestContext context) throws Exception {
 
-       protected static void shutdownTitanLogic() {
-               if (titanGraph.isOpen()) {
-                       titanGraph.close();
-               }
-               CassandraUtils.close();
-       }
 
-       @BeforeMethod(alwaysRun = true)
-       public void beforeState(java.lang.reflect.Method method) throws Exception {
+//                 String suiteName = ExtentManager.getSuiteName(context);
+//                     ExtentTestManager.startTest(method.getName());
+//                     ExtentTestManager.assignCategory(this.getClass());
 
+               boolean emptyDataProvider = method.getAnnotation(Test.class).dataProvider().isEmpty();
+               String className = method.getDeclaringClass().getName();
+               System.out.println(" method.getName() " + method.getName());
+               if (!method.getName().equals("onboardVNFShotFlow"))  {
+                       System.out.println("ExtentReport instance started from BeforeMethod...");
+                       ExtentTestManager.startTest(method.getName());
+                       ExtentTestManager.assignCategory(this.getClass());
 
-               ExtentTestManager.startTest(method.getName());
-               String[] parts = this.getClass().getName().toString().split("\\.");
-               String lastOne1 = parts[parts.length-1];
-               String lastOne2 = parts[parts.length-2];
-               getExtendTest().assignCategory(lastOne2 + "-" + lastOne1);
-               getExtendTest().log(Status.INFO, "Test started");
+               } else {
+                       System.out.println("ExtentReport instance started from Test...");
+               }
+      
 
        }
        
        @AfterMethod(alwaysRun = true)
-       public void afterState(ITestResult result) throws Exception {
+       public void quitAfterTest(ITestResult result, ITestContext context) throws Exception {
 
                String testName = result.getName();
                Throwable throwable = result.getThrowable();
@@ -248,8 +195,49 @@ public abstract class ComponentBaseTest {
 
 
                ExtentTestManager.endTest();
-       extentReport.flush();
+       
                
+       }
+
+       @AfterClass(alwaysRun = true)
+       public synchronized static void cleanAfterClass() throws Exception{
+
+               System.out.println("delete components AfterClass");
+               deleteCreatedComponents(getCatalogAsMap());
+
+       }
+       
+       @AfterSuite(alwaysRun = true)
+       public static void shutdownTitan() throws Exception {
+               
+               performClean();
+               shutdownTitanLogic();
+       }
+
+       protected static void openTitanLogic() throws Exception {
+       
+               logger.trace(config.toString());
+               String titanConfigFilePath = config.getTitanPropertiesFile();
+               titanGraph = TitanFactory.open(titanConfigFilePath);
+               assertNotNull(titanGraph);
+               
+       }
+
+
+       protected static void shutdownTitanLogic() {
+               if (titanGraph.isOpen()) {
+                       titanGraph.close();
+               }
+               CassandraUtils.close();
+       }
+
+       
+
+       public void setLog(String fromDataProvider) {
+
+               String suiteName = ExtentManager.getSuiteName(myContext);
+               ExtentTestManager.startTest(Thread.currentThread().getStackTrace()[2].getMethodName() + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + fromDataProvider);
+               ExtentTestManager.assignCategory(this.getClass());
 
        }