Skip to content

Commit

Permalink
Add dummy module for IT (#22)
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Stejskal <[email protected]>
  • Loading branch information
Frawless authored Feb 15, 2024
1 parent 0957563 commit 8772eae
Show file tree
Hide file tree
Showing 12 changed files with 309 additions and 55 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea
**/target
.DS_Store
*.iml
docs/
131 changes: 131 additions & 0 deletions dummy-module/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?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>

<packaging>jar</packaging>
<artifactId>dummy-module</artifactId>
<version>0.0.4-SNAPSHOT</version>

<parent>
<groupId>io.skodjob</groupId>
<artifactId>test-generator</artifactId>
<version>0.0.4-SNAPSHOT</version>
</parent>

<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>

<name>${project.groupId}:${project.artifactId}</name>
<description>Dummy module</description>
<url>https://github.com/skodjob/test-metadata-generator</url>

<scm>
<connection>scm:git:git:/github.com/skodjob/test-metadata-generator.git</connection>
<developerConnection>scm:git:ssh://github.com/skodjob/test-metadata-generator.git</developerConnection>
<url>https://github.com/skodjob/test-metadata-generator</url>
</scm>

<issueManagement>
<system>GitHub</system>
<url>https://github.com/skodjob/test-metadata-generator/issues</url>
</issueManagement>

<developers>
<developer>
<id>im-konge</id>
<name>Lukáš Král</name>
<email>[email protected]</email>
</developer>
<developer>
<id>kornys</id>
<name>David Kornel</name>
<email>[email protected]</email>
</developer>
<developer>
<id>Frawless</id>
<name>Jakub Stejskal</name>
<email>[email protected]</email>
</developer>
</developers>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- Skip publishing of this module -->
<maven.deploy.skip>true</maven.deploy.skip>
<generator.version>0.0.4-SNAPSHOT</generator.version>
</properties>

<dependencies>
<dependency>
<groupId>io.skodjob</groupId>
<artifactId>test-docs-generator-maven-plugin</artifactId>
<version>${generator.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.skodjob</groupId>
<artifactId>test-docs-generator-maven-plugin</artifactId>
<version>${generator.version}</version>
<executions>
<execution>
<phase>post-integration-test</phase>
<goals>
<goal>test-docs-generator</goal>
</goals>
</execution>
</executions>
<configuration>
<filePath>./dummy-module/src/test/java/io/</filePath>
<generatePath>./docs/</generatePath>
<generateFmf>true</generateFmf>
</configuration>
</plugin>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Check generated data</id>
<phase>post-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/../scripts/check-docs.sh</executable>
<arguments>
<argument>dummy-module</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>
93 changes: 93 additions & 0 deletions dummy-module/src/test/java/io/skodjob/DummyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright Skodjob authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.skodjob;

import io.skodjob.annotations.Contact;
import io.skodjob.annotations.Desc;
import io.skodjob.annotations.Step;
import io.skodjob.annotations.SuiteDoc;
import io.skodjob.annotations.TestDoc;
import io.skodjob.annotations.TestTag;
import io.skodjob.annotations.UseCase;
@SuiteDoc(
description = @Desc("My test suite containing various tests"),
beforeTestSteps = {
@Step(value = "Deploy uber operator across all namespaces, with custom configuration", expected = "Uber operator is deployed"),
@Step(value = "Deploy management Pod for accessing all other Pods", expected = "Management Pod is deployed")
},
afterTestSteps = {
@Step(value = "Delete management Pod", expected = "Management Pod is deleted"),
@Step(value = "Delete uber operator", expected = "Uber operator is deleted")
},
useCases = {
@UseCase(id = "core")
},
tags = {
@TestTag(value = "regression"),
@TestTag(value = "clients")
}
)
public class DummyTest {

@TestDoc(
description = @Desc("Test checking that the application works as expected"),
steps = {
@Step(value = "Create object instance", expected = "Instance of an object is created"),
@Step(value = "Do a magic trick", expected = "Magic trick is done with success"),
@Step(value = "Clean up the test case", expected = "Everything is cleared")
},
useCases = {
@UseCase(id = "core")
},
tags = {
@TestTag(value = "default")
}
)
void testMethodOne() {

}

@TestDoc(
description = @Desc("Test checking that the application works as expected. " +
"This is just a little bit longer line, nothing else."),
contact = @Contact(name = "Jakub Stejskal", email = "[email protected]"),
steps = {
@Step(value = "Create object instance", expected = "Instance of an object is created"),
@Step(value = "Do a magic trick", expected = "Magic trick is done with success"),
@Step(value = "Clean up the test case", expected = "Everything is cleared"),
@Step(value = "Do a magic cleanup check", expected = "Everything magically work")
},
useCases = {
@UseCase(id = "core"),
@UseCase(id = "core+"),
@UseCase(id = "core+++")
}
)
void testMethodTwo() {

}

@TestDoc(
description = @Desc("Test checking that the application works as expected. " +
"This is just a little bit longer line, nothing else."),
contact = @Contact(name = "Jakub Stejskal", email = "[email protected]")
)
void testMethodThree() {

}

@TestDoc(
description = @Desc("Test checking that the application works as expected. " +
"This is just a little bit longer line, nothing else."),
contact = @Contact(name = "Jakub Stejskal", email = "[email protected]"),
tags = {
@TestTag(value = "default"),
@TestTag(value = "regression"),
}
)
void testMethodFour() {

}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

<modules>
<module>test-docs-generator-maven-plugin</module>
<module>dummy-module</module>
</modules>

<properties>
Expand Down
25 changes: 25 additions & 0 deletions scripts/check-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

fmf_output="${DIR}/../docs/io/skodjob/DummyTest.fmf"
fmf_expected="${DIR}/../test-docs-generator-maven-plugin/src/test/resources/expected-docs.fmf"

md_output="${DIR}/../docs/io/skodjob/DummyTest.md"
md_expected="${DIR}/../test-docs-generator-maven-plugin/src/test/resources/expected-docs.md"

if cmp -s "$fmf_output" "$fmf_expected"; then
echo "The files \"$fmf_output\" and \"$fmf_expected\" are the same."
else
echo "The files \"$fmf_output\" and \"$fmf_expected\" are different."
diff "$fmf_output" "$fmf_expected"
exit 1
fi

if cmp -s "$md_output" "$md_expected"; then
echo "The files \"$md_output\" and \"$md_expected\" are the same."
else
echo "The files \"$md_output\" and \"$md_expected\" are different."
diff "$md_output" "$md_expected"
exit 1
fi
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -43,7 +44,7 @@ public class FmfGenerator {
public static void generate(Class<?> testClass, String classFilePath) throws IOException {
List<Method> methods = Arrays.stream(testClass.getDeclaredMethods())
.filter(method -> method.getAnnotation(TestDoc.class) != null)
.toList();
.sorted(Comparator.comparing(Method::getName)).toList();

if (!methods.isEmpty()) {
PrintWriter printWriter = Utils.createFilesForTestClass(classFilePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;

Expand All @@ -47,7 +48,7 @@ public static void generate(Class<?> testClass, String classFilePath) throws IOE

List<Method> methods = Arrays.stream(testClass.getDeclaredMethods())
.filter(method -> method.getAnnotation(TestDoc.class) != null)
.toList();
.sorted(Comparator.comparing(Method::getName)).toList();

if (suiteDoc != null || !methods.isEmpty()) {
PrintWriter printWriter = Utils.createFilesForTestClass(classFilePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Stream;

/**
* Utils class with supported method for all kind of generators.
Expand All @@ -38,18 +39,18 @@ public class Utils {
* @return updated Map with test-classes info from the {@param packagePath}
*/
private static Map<String, String> getClassesForPackage(Map<String, String> classes, Path packagePath, String generatePath) {
try {
Files.list(packagePath)
.forEach(path -> {
if (Files.isDirectory(path)) {
classes.putAll(getClassesForPackage(classes, path, generatePath));
} else {
String classPackagePath = path.toAbsolutePath().toString().replaceAll(REMOVE_BEFORE_PACKAGE.toString(), "").replace(".java", "");
classes.put(generatePath + classPackagePath, classPackagePath.replaceAll("/", "."));
}
});
} catch (IOException exception) {
throw new RuntimeException(exception);
try (Stream<Path> pathStream = Files.list(packagePath)) {
pathStream.forEach(path -> {
if (Files.isDirectory(path)) {
classes.putAll(getClassesForPackage(classes, path, generatePath));
} else {
String classPackagePath = path.toAbsolutePath().toString().replaceAll(REMOVE_BEFORE_PACKAGE.toString(), "").replace(".java", "");
classes.put(generatePath + classPackagePath, classPackagePath.replaceAll("/", "."));
}
});
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}

return classes;
Expand All @@ -67,9 +68,8 @@ private static Map<String, String> getClassesForPackage(Map<String, String> clas
public static Map<String, String> getTestClassesWithTheirPath(String filePath, String generatePath) {
Map<String, String> classes = new HashMap<>();

try {
Files.list(Paths.get(filePath))
.forEach(path -> classes.putAll(getClassesForPackage(classes, path, generatePath)));
try (Stream<Path> pathStream = Files.list(Paths.get(filePath))) {
pathStream.forEach(path -> classes.putAll(getClassesForPackage(classes, path, generatePath)));
} catch (IOException exception) {
throw new RuntimeException(exception);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class FmfGeneratorTest {
void testCreateTableOfSteps() throws IOException {
String expectedFilePath = FmfGeneratorTest.class.getClassLoader().getResource("expected-docs.fmf").getPath();
String generatedFilePath = "target/io/test.fmf";
FmfGenerator.generate(MdGeneratorTest.TestClass.class, generatedFilePath);
FmfGenerator.generate(MdGeneratorTest.DummyTest.class, generatedFilePath);

assertThat(MdGeneratorTest.compareFiles(expectedFilePath, generatedFilePath), is(true));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MdGeneratorTest {
void testCreateTableOfSteps() throws IOException {
String expectedFilePath = MdGeneratorTest.class.getClassLoader().getResource("expected-docs.md").getPath();
String generatedFilePath = "target/io/test.md";
MdGenerator.generate(TestClass.class, generatedFilePath);
MdGenerator.generate(DummyTest.class, generatedFilePath);

assertThat(compareFiles(expectedFilePath, generatedFilePath), is(true));
}
Expand All @@ -49,7 +49,7 @@ void testCreateTableOfSteps() throws IOException {
@TestTag(value = "clients")
}
)
public static class TestClass {
public static class DummyTest {

@TestDoc(
description = @Desc("Test checking that the application works as expected"),
Expand Down
Loading

0 comments on commit 8772eae

Please sign in to comment.