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

Commit

Permalink
#244 - extract report-core module
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaihuludus committed Jul 3, 2018
1 parent 1282212 commit 7c38ac8
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.logging;
package com.cognifide.qa.bb.core.logging;

import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;

import com.cognifide.qa.bb.logging.ProxyLogger;
import com.cognifide.qa.bb.core.logging.reporter.GuiceModulesInstaller;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.cognifide.qa.bb.logging.reporter.GuiceModulesInstaller;
import com.cognifide.qa.bb.proxy.analyzer.predicate.ClosestHarEntryElector;
import com.cognifide.qa.bb.proxy.analyzer.predicate.RequestPredicate;
import com.google.inject.Guice;
Expand All @@ -41,17 +38,17 @@

public class ProxyLoggerTest {

private final ClosestHarEntryElector elector = mock(ClosestHarEntryElector.class);
private final ClosestHarEntryElector elector = Mockito.mock(ClosestHarEntryElector.class);

private final RequestPredicate matchingPredicate = mock(RequestPredicate.class);
private final RequestPredicate matchingPredicate = Mockito.mock(RequestPredicate.class);

private final Har har = mock(Har.class, RETURNS_DEEP_STUBS);
private final Har har = Mockito.mock(Har.class, Mockito.RETURNS_DEEP_STUBS);

private final HarEntry closestHarEntry = mock(HarEntry.class, RETURNS_DEEP_STUBS);
private final HarEntry closestHarEntry = Mockito.mock(HarEntry.class, Mockito.RETURNS_DEEP_STUBS);

@Before
public void setUp() throws Exception {
when(elector.findSimilarEntry(any(List.class)))
Mockito.when(elector.findSimilarEntry(ArgumentMatchers.any(List.class)))
.thenReturn(closestHarEntry);
}

Expand All @@ -69,7 +66,7 @@ public void testTimeoutBehaviourWhenNoElectorInjected() throws Exception {
proxyLogger.listeningStopped(har);

// then
verifyNoMoreInteractions(matchingPredicate);
Mockito.verifyNoMoreInteractions(matchingPredicate);
}

@Test
Expand All @@ -86,6 +83,6 @@ public void testTimeoutBehaviourWhenElectorInjected() throws Exception {
proxyLogger.listeningStopped(har);

// then
verify(elector).findSimilarEntry(any(List.class));
Mockito.verify(elector).findSimilarEntry(ArgumentMatchers.any(List.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.logging.reporter;
package com.cognifide.qa.bb.core.logging.reporter;

import com.cognifide.qa.bb.junit.JUnitModule;
import com.cognifide.qa.bb.logging.ReporterModule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,13 @@
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.logging.reporter;
package com.cognifide.qa.bb.core.logging.reporter;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import static org.mockito.Mockito.mock;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.model.InitializationError;

import com.cognifide.qa.bb.junit.Modules;
import com.cognifide.qa.bb.junit.TestRunner;
import com.cognifide.qa.bb.logging.ReportEntryLogger;
Expand All @@ -45,6 +34,15 @@
import com.cognifide.qa.bb.logging.entries.LogEntry;
import com.cognifide.qa.bb.logging.entries.ScreenshotEntry;
import com.google.inject.Inject;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.model.InitializationError;

@RunWith(TestRunner.class)
@Modules(GuiceModulesInstaller.class)
Expand Down
5 changes: 5 additions & 0 deletions bb-junit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<artifactId>bb-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.cognifide.qa.bb</groupId>
<artifactId>bb-reports-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.cognifide.qa.bb.junit;

import com.cognifide.qa.bb.reports.core.TestEventCollector;
import java.util.List;
import java.util.function.Consumer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.cognifide.qa.bb.junit;

import com.cognifide.qa.bb.reports.core.TestEventCollector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.google.inject.util.Types;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.cognifide.qa.bb.junit.concurrent;

import com.cognifide.qa.bb.reports.core.concurrent.ReportingHandler;
import java.util.Properties;

import org.junit.runners.Suite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.cognifide.qa.bb.junit.concurrent;

import com.cognifide.qa.bb.reports.core.concurrent.ReportingHandler;
import java.util.LinkedList;
import java.util.Properties;
import java.util.Queue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.junit.runner.Result;
import org.junit.runner.notification.RunListener;

import com.cognifide.qa.bb.junit.concurrent.ReportingHandler;
import com.cognifide.qa.bb.reports.core.concurrent.ReportingHandler;
import com.google.common.collect.Sets;
import com.google.inject.Injector;

Expand Down
40 changes: 19 additions & 21 deletions bb-reports-allure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,27 @@ See the License for the specific language governing permissions and
limitations under the License.
#L%
-->
<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>
<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>
<artifactId>bb-reports-allure</artifactId>

<dependencies>
<dependency>
<groupId>com.cognifide.qa.bb</groupId>
<artifactId>bb-reports</artifactId>
<version>${project.version}</version>
</dependency>
<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>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit4</artifactId>
</dependency>
</dependencies>

</project>
38 changes: 38 additions & 0 deletions bb-reports-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
#%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%
-->
<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-core</artifactId>

<dependencies>
<dependency>
<groupId>com.cognifide.qa.bb</groupId>
<artifactId>bb-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.junit;
package com.cognifide.qa.bb.reports.core;

/**
* Interface for test events that needs to be collected for further use (i.e. reporting)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@
* limitations under the License.
* #L%
*/
package com.cognifide.qa.bb.junit.concurrent;

import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package com.cognifide.qa.bb.reports.core.concurrent;

import com.cognifide.qa.bb.guice.ThreadScoped;
import com.cognifide.qa.bb.reporter.Reporter;
Expand All @@ -34,18 +27,24 @@
import com.google.inject.Injector;
import com.google.inject.Provider;
import com.google.inject.TypeLiteral;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* ReportingHandler receives asynchronous reporting requests from test threads and redirects them
* to all Reporter instances.
* ReportingHandler receives asynchronous reporting requests from test threads and redirects them to
* all Reporter instances.
* <p>
* ConcurrentSuite runs this class in a separate thread.
*/
@ThreadScoped
public class ReportingHandler implements Runnable {

public static final TypeLiteral<Set<Reporter>> ACTIVE_REPORTERS =
new TypeLiteral<Set<Reporter>>() {};
new TypeLiteral<Set<Reporter>>() {
};

private static final String THREAD_NAME = "Reporting thread";

Expand Down Expand Up @@ -74,8 +73,8 @@ public ReportingHandler(Injector injector) {
}

/**
* Sets the flag to indicate that there will be no more tests.
* Waits for reporting thread to finish its job.
* Sets the flag to indicate that there will be no more tests. Waits for reporting thread to
* finish its job.
*
* @throws InterruptedException in case of reporting thread is not running yet.
*/
Expand Down
2 changes: 1 addition & 1 deletion bb-reports/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</dependency>
<dependency>
<groupId>com.cognifide.qa.bb</groupId>
<artifactId>bb-junit</artifactId>
<artifactId>bb-reports-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@
*/
package com.cognifide.qa.bb.logging;

import com.cognifide.qa.bb.junit.TestEventCollector;
import com.cognifide.qa.bb.junit.concurrent.ReportingHandler;
import com.cognifide.qa.bb.logging.listeners.ReportCollectorListener;
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;
import com.cognifide.qa.bb.proxy.ProxyEventListener;
import com.cognifide.qa.bb.reports.core.TestEventCollector;
import com.cognifide.qa.bb.reports.core.concurrent.ReportingHandler;
import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
import com.google.inject.matcher.Matchers;
import com.google.inject.multibindings.Multibinder;
import org.junit.runner.notification.RunListener;
import org.openqa.selenium.support.events.WebDriverEventListener;

/**
Expand Down Expand Up @@ -65,5 +67,8 @@ protected void configure() {
ProxyEventListener.class);
proxyListenerBinder.addBinding().to(ProxyLogger.class);

Multibinder<RunListener> runListenerMultibinder = Multibinder.newSetBinder(binder(),
RunListener.class);
runListenerMultibinder.addBinding().to(ReportCollectorListener.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package com.cognifide.qa.bb.logging;

import com.cognifide.qa.bb.reports.core.TestEventCollector;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
Expand All @@ -31,7 +32,6 @@
import org.openqa.selenium.HasCapabilities;
import org.openqa.selenium.WebDriver;

import com.cognifide.qa.bb.junit.TestEventCollector;
import com.cognifide.qa.bb.logging.reporter.AbstractReporter;
import com.google.inject.Inject;
import com.google.inject.Injector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
*/
package com.cognifide.qa.bb.logging.reporter.provider;

import com.cognifide.qa.bb.junit.concurrent.ReportingHandler;
import com.cognifide.qa.bb.logging.constants.ReportsConfigKeys;
import com.cognifide.qa.bb.logging.reporter.HtmlReporter;
import com.cognifide.qa.bb.logging.reporter.JsonReporter;
import com.cognifide.qa.bb.logging.reporter.SimpleReporter;
import com.cognifide.qa.bb.logging.reporter.StdoutReporter;
import com.cognifide.qa.bb.reporter.Reporter;
import com.cognifide.qa.bb.reports.core.concurrent.ReportingHandler;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import com.google.inject.Injector;
Expand Down
Loading

0 comments on commit 7c38ac8

Please sign in to comment.