Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
#244 sample things for refactor - not working yet
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaihuludus committed Jul 1, 2018
1 parent 933eef5 commit 0b55684
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.cognifide.qa.bb.junit.listener;

public class ReportCollectorListener {

}
27 changes: 27 additions & 0 deletions bb-reports-allure/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>bobcat</artifactId>
<groupId>com.cognifide.qa.bb</groupId>
<version>1.4.1-SNAPSHOT</version>
</parent>

<artifactId>bb-reports-allure</artifactId>

<dependencies>
<dependency>
<groupId>com.cognifide.qa.bb</groupId>
<artifactId>bb-reports</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit4</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 Cognifide Ltd.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.logging.allure;

import com.cognifide.qa.bb.logging.allure.reporter.AllureReporter;
import com.cognifide.qa.bb.logging.reporter.provider.CustomReportBinder;
import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;

/**
* Guice module that will allow Allure Reporter to be run
*/
public class AllureModule extends AbstractModule {

@Override
protected void configure() {
Multibinder<CustomReportBinder> customReportersBinder = Multibinder.newSetBinder(binder(),
CustomReportBinder.class);
customReportersBinder.addBinding()
.toInstance(new CustomReportBinder("allure", AllureReporter.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 Cognifide Ltd.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.logging.allure.reporter;

import com.cognifide.qa.bb.logging.TestInfo;
import com.cognifide.qa.bb.logging.entries.AssertionFailedEntry;
import com.cognifide.qa.bb.logging.entries.BrowserInfoEntry;
import com.cognifide.qa.bb.logging.entries.BrowserLogEntry;
import com.cognifide.qa.bb.logging.entries.ErrorEntry;
import com.cognifide.qa.bb.logging.entries.EventEntry;
import com.cognifide.qa.bb.logging.entries.ExceptionEntry;
import com.cognifide.qa.bb.logging.entries.InfoEntry;
import com.cognifide.qa.bb.logging.entries.ScreenshotEntry;
import com.cognifide.qa.bb.logging.entries.SoftAssertionFailedEntry;
import com.cognifide.qa.bb.logging.entries.SubreportEndEntry;
import com.cognifide.qa.bb.logging.entries.SubreportStartEntry;
import com.cognifide.qa.bb.logging.reporter.AbstractReporter;
import io.qameta.allure.Allure;
import io.qameta.allure.AllureLifecycle;
import io.qameta.allure.model.TestResult;
import java.util.Properties;
import java.util.UUID;

public class AllureReporter extends AbstractReporter {

private final ThreadLocal<String> testCases = new InheritableThreadLocal<String>() {
@Override
protected String initialValue() {
return UUID.randomUUID().toString();
}
};

private final AllureLifecycle lifecycle = Allure.getLifecycle();

@Override
public void suiteStart() {
//Nothing now
}

@Override
public void suiteEnd() {
//Nothing now
}

@Override
public void testStart(TestInfo testInfo) {
final String uuid = testCases.get();
final TestResult result = createTestResult(uuid, testInfo);
lifecycle.scheduleTestCase(result);
lifecycle.startTestCase(uuid);
}

@Override
public void testEnd(TestInfo testInfo) {

}

@Override
public void errorEntry(ErrorEntry errorLogEntry) {

}

@Override
public void exceptionEntry(ExceptionEntry exceptionLogEntry) {

}

@Override
public void screenshotEntry(ScreenshotEntry screenshotLogEntry) {

}

@Override
public void infoEntry(InfoEntry infoEntry) {

}

@Override
public void eventEntry(EventEntry eventLogEntry) {

}

@Override
public void subreportStart(SubreportStartEntry subreportStartLogEntry) {

}

@Override
public void subreportEnd(SubreportEndEntry subreportEndLogEntry) {

}

@Override
public void browserInfoEntry(BrowserInfoEntry browserInfoEntry) {

}

@Override
public void assertion(AssertionFailedEntry assertionFailedEntry) {

}

@Override
public void softAssertion(SoftAssertionFailedEntry softAssertionFailedEntry) {

}

@Override
public void properties(Properties properties) {

}

@Override
public void browserLogEntry(BrowserLogEntry browserLogEntry) {

}

private TestResult createTestResult(String uuid, TestInfo testInfo) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
*/
package com.cognifide.qa.bb.logging;

import org.openqa.selenium.support.events.WebDriverEventListener;

import com.cognifide.qa.bb.junit.TestEventCollector;
import com.cognifide.qa.bb.junit.concurrent.ReportingHandler;
import com.cognifide.qa.bb.logging.reporter.provider.CustomReportBinder;
import com.cognifide.qa.bb.logging.reporter.provider.ReporterProvider;
import com.cognifide.qa.bb.logging.subreport.Subreport;
import com.cognifide.qa.bb.logging.subreport.SubreportInterceptor;
Expand All @@ -31,6 +30,7 @@
import com.google.inject.Singleton;
import com.google.inject.matcher.Matchers;
import com.google.inject.multibindings.Multibinder;
import org.openqa.selenium.support.events.WebDriverEventListener;

/**
* Install this module to enable reporting capabilities. Following features are available:
Expand All @@ -50,6 +50,9 @@ protected void configure() {
bind(TestEventCollector.class).to(TestEventCollectorImpl.class);
bind(ReportingHandler.ACTIVE_REPORTERS).toProvider(ReporterProvider.class).in(Singleton.class);

Multibinder.newSetBinder(binder(),
CustomReportBinder.class);

SubreportInterceptor subreportInterceptor = new SubreportInterceptor();
requestInjection(subreportInterceptor);
bindInterceptor(Matchers.any(), Matchers.annotatedWith(Subreport.class), subreportInterceptor);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*-
* #%L
* Bobcat
* %%
* Copyright (C) 2018 Cognifide Ltd.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.logging.reporter.provider;

import com.cognifide.qa.bb.reporter.Reporter;

/**
* Allows to create custom bindings for report generators.
* Pair name (for configuration) and class is required
*/
public class CustomReportBinder {

private final String name;

private final Class<? extends Reporter> className;

public CustomReportBinder(String name, Class<? extends Reporter> className) {
this.name = name;
this.className = className;
}

public String getName() {
return name;
}

public Class<? extends Reporter> getClassName() {
return className;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@
*/
package com.cognifide.qa.bb.logging.reporter.provider;

import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.slf4j.LoggerFactory;

import com.cognifide.qa.bb.junit.concurrent.ReportingHandler;
import com.cognifide.qa.bb.logging.constants.ReportsConfigKeys;
import com.cognifide.qa.bb.logging.reporter.HtmlReporter;
Expand All @@ -37,10 +30,15 @@
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Provider;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.slf4j.LoggerFactory;

/**
* This is a provider of Reporter instances.
* It creates and configures the instances as indicated in the property files.
* This is a provider of Reporter instances. It creates and configures the instances as indicated in
* the property files.
*/
public class ReporterProvider implements Provider<Set<Reporter>> {

Expand All @@ -62,13 +60,15 @@ public class ReporterProvider implements Provider<Set<Reporter>> {
@Inject
private Properties properties;

@Inject
private Set<CustomReportBinder> customReportBinders;

@Inject
private Injector injector;

/**
* Provider method.
* Creates and returns instances of Reporters that are indicated in
* {@link ReportsConfigKeys#BOBCAT_REPORT_REPORTERS} property.
* Provider method. Creates and returns instances of Reporters that are indicated in {@link
* ReportsConfigKeys#BOBCAT_REPORT_REPORTERS} property.
*/
@SuppressWarnings("unchecked")
@Override
Expand All @@ -80,17 +80,29 @@ public Set<Reporter> get() {
}

for (String r : prop.split(REPORTERS_SEPARATOR)) {
Class<? extends Reporter> clazz = REPORTER_MAP.get(r);
Class<? extends Reporter> clazz =
REPORTER_MAP.get(r) == null ? findCustomReporter(r) : REPORTER_MAP.get(r);
if (clazz == null) {
try {
clazz = (Class<? extends Reporter>) Class.forName(r);
} catch (ClassNotFoundException e) {
LOG.error("Can't find reporter class", e);
continue;
}
continue;
}
reporters.add(injector.getInstance(clazz));
}
return reporters;
}

private Class<? extends Reporter> findCustomReporter(String reporterName) {
Class<? extends Reporter> reporterClass = null;
CustomReportBinder customReportBinder = customReportBinders.stream()
.filter(entry -> entry.getName().equals(reporterName)).findFirst().orElse(null);
if (customReportBinder != null) {
reporterClass = customReportBinder.getClassName();
} else {
try {
reporterClass = (Class<? extends Reporter>) Class.forName(reporterName);
} catch (ClassNotFoundException e) {
LOG.error("Can't find reporter class", e);
}
}
return reporterClass;
}
}
Loading

0 comments on commit 0b55684

Please sign in to comment.