Skip to content

Commit

Permalink
Merge pull request #9 from ppi-ag/dev
Browse files Browse the repository at this point in the history
Version 1.0.1
  • Loading branch information
JanSchankin authored Nov 26, 2020
2 parents c2e9516 + 5896d9a commit 39c4bf8
Show file tree
Hide file tree
Showing 28 changed files with 112 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Build & Test

on:
push:
branches: [ main ]
branches: [ main, dev ]
pull_request:
branches: [ main ]
branches: [ main, dev ]

jobs:
build:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

![Build & Test](https://github.com/ppi-ag/deep-sampler/workflows/Build%20&%20Test/badge.svg) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=ppi-ag_deep-sampler&metric=coverage)](https://sonarcloud.io/dashboard?id=ppi-ag_deep-sampler) [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=ppi-ag_deep-sampler&metric=bugs)](https://sonarcloud.io/dashboard?id=ppi-ag_deep-sampler) [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=ppi-ag_deep-sampler&metric=code_smells)](https://sonarcloud.io/dashboard?id=ppi-ag_deep-sampler) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=ppi-ag_deep-sampler&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=ppi-ag_deep-sampler) [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=ppi-ag_deep-sampler&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=ppi-ag_deep-sampler)

DeepSampler is a stubbing framework for integrated component tests.
DeepSampler is a __stubbing framework__ for __compound tests__. A _compound_ is a net of objects. A compound can be isolated from an application but its content is integrated.

The API is able to _stub_ methods anywhere _deep_ inside of an object tree of any size without the need to manually move a stubbed instance
from a test case into the object tree.
The API is able to _stub_ methods anywhere _deep_ inside of a compound of any size without the need to manually move a stubbed instance
from a test case into the compound.

For tests with large test data (called _Samples_) DeepSampler can separate test logic from test data by _loading_
and _saving_ test data in JSON-files. The JSON-files can be _recorded_ by activating the record-mode and simply running
a test case. If a stub is in record-mode, it routes calls to the original methods and collects all data that flows through the stub. This collected data can then be saved to JSON-files.

For light-way tests with smaller Samples, where using separate JSON-files might be unnecessary, DeepSampler
provides an API that can be used to define Samples
conveniently inside test classes. The API also comes with means to freely redefine the behavior of stubbed methods.
conveniently inside test classes. The API also comes with means to completely redefine the behavior of stubbed methods.

## License
DeepSampler is made available under the terms of the __MIT License__ (see [LICENSE.md](./LICENSE.md)).
Expand Down
37 changes: 27 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,36 @@ plugins {
`java-library`
jacoco
id("org.sonarqube") version "3.0"
id("com.vanniktech.maven.publish") version "0.13.0"
}

allprojects {
version = "1.0.0"
group = "de.ppi.deepsampler"
group = "de.ppi"

apply(plugin = "java-library")
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

repositories {
jcenter()
}
}

tasks.jar {
from("LICENSE.md") {
into("/META-INF")
}
}

mavenPublish {
nexus {
baseUrl = "https://oss.sonatype.org/service/local/"
stagingProfile = "de.ppi"
}
}


sonarqube {
Expand Down Expand Up @@ -70,13 +89,20 @@ tasks.register<JacocoReport>("codeCoverageReport") {
var projectsWithoutTests = arrayOf("deepsampler-provider")

subprojects {

apply(plugin = "java-library")

if (!projectsWithoutTests.contains(project.name)) {
collectTestCoverage()
}


tasks.jar {
from("../LICENSE.md") {
into("/META-INF")
}
}

dependencies {
testImplementation("org.mockito:mockito-core:3.3.3")
if (project.name != "deepsampler-junit4") {
Expand All @@ -88,12 +114,6 @@ subprojects {



}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withSourcesJar()
}

dependencies {
Expand All @@ -117,9 +137,6 @@ tasks.register<Javadoc>("JavadocAll") {
classpath = files(classPathList)
}




fun Project.collectTestCoverage() {
apply(plugin = "jacoco")

Expand Down
4 changes: 4 additions & 0 deletions deepsampler-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* This program is made available under the terms of the MIT License.
*/

plugins {
id("com.vanniktech.maven.publish")
}

dependencies {
implementation("org.javassist:javassist:3.27.0-GA")
implementation("org.objenesis:objenesis:3.1")
Expand Down
3 changes: 3 additions & 0 deletions deepsampler-core/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=deepsampler-core
POM_NAME=deepsampler-core
POM_DESCRIPTION=DeepSampler is a stubbing framework for integrated compound tests.
1 change: 1 addition & 0 deletions deepsampler-junit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

plugins {
`java-test-fixtures`
id("com.vanniktech.maven.publish")
}

dependencies {
Expand Down
3 changes: 3 additions & 0 deletions deepsampler-junit/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=deepsampler-junit
POM_NAME=deepsampler-junit
POM_DESCRIPTION=The base module for supporting various versions of JUnit.
3 changes: 3 additions & 0 deletions deepsampler-junit4/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* Copyright 2020 PPI AG (Hamburg, Germany)
* This program is made available under the terms of the MIT License.
*/
plugins {
id("com.vanniktech.maven.publish")
}

dependencies {
implementation("junit:junit:4.13")
Expand Down
3 changes: 3 additions & 0 deletions deepsampler-junit4/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=deepsampler-junit4
POM_NAME=deepsampler-junit4
POM_DESCRIPTION=Contains supporting classes for using DeepSampler with JUnit 4.
3 changes: 3 additions & 0 deletions deepsampler-junit5/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* Copyright 2020 PPI AG (Hamburg, Germany)
* This program is made available under the terms of the MIT License.
*/
plugins {
id("com.vanniktech.maven.publish")
}

dependencies {
implementation(project(":deepsampler-core"))
Expand Down
3 changes: 3 additions & 0 deletions deepsampler-junit5/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=deepsampler-junit5
POM_NAME=deepsampler-junit5
POM_DESCRIPTION=Contains supporting classes for using DeepSampler with JUnit 5.
3 changes: 3 additions & 0 deletions deepsampler-persistence-json/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* Copyright 2020 PPI AG (Hamburg, Germany)
* This program is made available under the terms of the MIT License.
*/
plugins {
id("com.vanniktech.maven.publish")
}

dependencies {
implementation(project(":deepsampler-core"))
Expand Down
3 changes: 3 additions & 0 deletions deepsampler-persistence-json/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=deepsampler-persistence-json
POM_NAME=deepsampler-persistence-json
POM_DESCRIPTION=With this module you can use a json implementation of the persistence api in DeepSampler.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
package de.ppi.deepsampler.persistence.json;

import com.fasterxml.jackson.databind.Module;
import de.ppi.deepsampler.persistence.PersistentSamplerContext;
import de.ppi.deepsampler.persistence.json.error.JsonPersistenceException;
import de.ppi.deepsampler.persistence.json.extension.DeserializationExtension;
import de.ppi.deepsampler.persistence.model.PersistentModel;
Expand All @@ -31,7 +30,7 @@ public JsonLoader(PersistentResource persistentResource, List<DeserializationExt
super(persistentResource, deserializerList, Collections.emptyList(), moduleList);
}

public PersistentModel load(PersistentSamplerContext persistentSamplerContext) {
public PersistentModel load() {
try {
InputStream in = Objects.requireNonNull(getPersistentResource().readAsStream());
return createObjectMapper().readValue(new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)), JsonSampleModel.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public void save(final Map<Class<?>, ExecutionInformation> executionInformation,
}

@Override
public PersistentModel load(final PersistentSamplerContext persistentSamplerContext) {
return jsonLoader.load(persistentSamplerContext);
public PersistentModel load() {
return jsonLoader.load();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void testLoad() {
final Path path = Paths.get("./record/testPersistent.json");

// WHEN
final PersistentModel persistentModel = new JsonLoader(new PersistentFile(path)).load(new PersistentSamplerContext());
final PersistentModel persistentModel = new JsonLoader(new PersistentFile(path)).load();

// THEN
assertEquals(1, persistentModel.getSampleMethodToSampleMap().size());
Expand All @@ -39,7 +39,7 @@ void testLoadTime() {
final Path path = Paths.get("./record/testTimePersistent.json");

// WHEN
final PersistentModel persistentModel = new JsonLoader(new PersistentFile(path)).load(new PersistentSamplerContext());
final PersistentModel persistentModel = new JsonLoader(new PersistentFile(path)).load();

// THEN
assertEquals(1, persistentModel.getSampleMethodToSampleMap().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void testBuilderWithSerializerLoad() {
final JsonSourceManager sourceManager = JsonSourceManager.builder()
.addModule(module)
.buildWithFile(pathAsString);
final PersistentModel persistentModel = sourceManager.load(new PersistentSamplerContext());
final PersistentModel persistentModel = sourceManager.load();

// THEN
assertNull(persistentModel.getSampleMethodToSampleMap().entrySet().iterator().next()
Expand All @@ -112,7 +112,7 @@ void testBuilderWithModLoad() {
.addDeserializer(JsonPersistentParameter.class, new CustomJsonDeserializer())
.addSerializer(JsonPersistentParameter.class, new CustomJsonSerializer())
.buildWithFile(pathAsString);
final PersistentModel persistentModel = sourceManager.load(new PersistentSamplerContext());
final PersistentModel persistentModel = sourceManager.load();

// THEN
assertNull(persistentModel.getSampleMethodToSampleMap().entrySet().iterator().next()
Expand All @@ -124,7 +124,7 @@ void testBuilderWithClassPathResource() {
// WHEN
final JsonSourceManager sourceManager = JsonSourceManager.builder()
.buildWithResource(new PersistentClassPathResource("myTestJson.json", getClass()));
final PersistentModel persistentModel = sourceManager.load(new PersistentSamplerContext());
final PersistentModel persistentModel = sourceManager.load();

// THEN
assertNotNull(persistentModel.getSampleMethodToSampleMap().entrySet().iterator().next()
Expand Down
3 changes: 3 additions & 0 deletions deepsampler-persistence/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* Copyright 2020 PPI AG (Hamburg, Germany)
* This program is made available under the terms of the MIT License.
*/
plugins {
id("com.vanniktech.maven.publish")
}

dependencies {
implementation(project(":deepsampler-core"))
Expand Down
3 changes: 3 additions & 0 deletions deepsampler-persistence/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=deepsampler-persistence
POM_NAME=deepsampler-persistence
POM_DESCRIPTION=This module is the core of the persistence api in DeepSampler.
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ public void record() {
}

/**
* End of chain method: Calls {@link SourceManager#load(PersistentSamplerContext)} on all {@link SourceManager}s and write
* End of chain method: Calls {@link SourceManager#load()} on all {@link SourceManager}s and write
* all loaded samples to the DeepSampler repositories.
*/
public void load() {
for (final SourceManager sourceManager: sourceManagerList) {
final Map<String, SampledMethod> definedSamples = SampleRepository.getInstance().getSamples().stream()
.collect(Collectors.toMap(SampleDefinition::getSampleId, SampleDefinition::getSampledMethod));
final PersistentModel persistentModel = sourceManager.load(persistentSamplerContext);
final PersistentModel persistentModel = sourceManager.load();

final List<SampleDefinition> filteredMappedSample = toSample(persistentModel, definedSamples);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ public interface SourceManager {
void save(Map<Class<?>, ExecutionInformation> executionInformation, PersistentSamplerContext persistentSamplerContext);

/**
* Load the data you wrote. You will also have to transform this (if not already happened by design) to an
* Load the persistent data. You will also have to transform this (if not already happened by design) to an
* implementation of {@link PersistentModel}.
*
* @param persistentSamplerContext context of the persistent sampler
* @return PersistentModel
*/
PersistentModel load(PersistentSamplerContext persistentSamplerContext);
PersistentModel load();
}
3 changes: 3 additions & 0 deletions deepsampler-provider-guice/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* Copyright 2020 PPI AG (Hamburg, Germany)
* This program is made available under the terms of the MIT License.
*/
plugins {
id("com.vanniktech.maven.publish")
}

dependencies {
implementation(group = "com.google.inject", name = "guice", version = "4.0")
Expand Down
3 changes: 3 additions & 0 deletions deepsampler-provider-guice/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=deepsampler-provider-guice
POM_NAME=deepsampler-provider-guice
POM_DESCRIPTION=This module provides the possibility to use DeepSampler with guice based on their aop-framework.
3 changes: 3 additions & 0 deletions deepsampler-provider-spring/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* Copyright 2020 PPI AG (Hamburg, Germany)
* This program is made available under the terms of the MIT License.
*/
plugins {
id("com.vanniktech.maven.publish")
}

dependencies {
implementation("org.aspectj:aspectjrt:1.9.6")
Expand Down
3 changes: 3 additions & 0 deletions deepsampler-provider-spring/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=deepsampler-provider-spring
POM_NAME=deepsampler-provider-spring
POM_DESCRIPTION=This module provides the possibility to use DeepSampler with spring based on their aop-framework.
1 change: 1 addition & 0 deletions deepsampler-provider/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

plugins {
`java-test-fixtures`
id("com.vanniktech.maven.publish")
}

dependencies {
Expand Down
3 changes: 3 additions & 0 deletions deepsampler-provider/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_ARTIFACT_ID=deepsampler-provider
POM_NAME=deepsampler-provider
POM_DESCRIPTION=This module is the base for implementing custom stub-provider.
16 changes: 16 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
GROUP=de.ppi
VERSION_NAME=1.0.1
POM_ARTIFACT_ID=deepsampler
POM_NAME=deepsampler
POM_PACKAGING=jar
POM_DESCRIPTION=DeepSampler is a stubbing framework for integrated compound tests.
POM_INCEPTION_YEAR=2020
POM_URL=https://github.com/ppi-ag/deep-sampler
POM_SCM_URL=https://github.com/ppi-ag/deep-sampler
POM_SCM_CONNECTION=scm:git:git://github.com/ppi-ag/deep-sampler.git
POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com:ppi-ag/deep-sampler.git
POM_LICENCE_NAME=MIT License
POM_LICENCE_URL=https://github.com/ppi-ag/deep-sampler/blob/main/LICENSE.md
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=ppi
POM_DEVELOPER_NAME=ppi

0 comments on commit 39c4bf8

Please sign in to comment.