Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Programming exercises: Add blackbox tests as another Java project type #6736

Merged
merged 82 commits into from
Sep 16, 2023
Merged
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
2fc4919
add maven_blackbox as project type
Apr 23, 2023
1bad098
files
May 6, 2023
4e021f8
more files
May 7, 2023
e4a3a31
added DejaGnu ProjectType button
May 16, 2023
c7a70e8
backend changes
May 16, 2023
4639b5a
adapted readme to the user input exercise format
May 17, 2023
4eb8904
resolve conflicts
May 17, 2023
e45f842
cosmetic improvements for the readme
May 17, 2023
c4a1fb5
Suggestions from Code Review
b-fein May 17, 2023
f4099ca
deactivate sequential test runs and testwise coverage for dejagnu pro…
May 17, 2023
06d1d80
remove test repo instructions that no longer apply
May 17, 2023
5f0556b
remove unsupported dependencies in pom
May 17, 2023
140d4fe
files added and fixed
May 29, 2023
e54ce39
correctly annotated files
May 29, 2023
be51569
fix
May 31, 2023
bbcfddf
standardized time zone
May 31, 2023
a9df1b3
added import
May 31, 2023
493f12e
changed date format in the tests also
May 31, 2023
4d7e721
initialized sorting algorithm in the context class
May 31, 2023
6fad054
timezone oversight
May 31, 2023
d0e00a6
no more complaining from the static code analysis
May 31, 2023
ed07c81
added Tests.txt
May 31, 2023
7500422
Merge remote-tracking branch 'origin/develop' into feature/blackbox-t…
Jun 4, 2023
b505bb3
content for tests.txt and policy class with character limit
Jun 4, 2023
be8f76d
respect 80 line character limit in policy class
Jun 4, 2023
1c75011
new docker image
Jun 4, 2023
54cccab
updated readme once again
Jun 6, 2023
a6cced3
make prefix more general
Jun 6, 2023
b4d839e
remove comma
Jun 6, 2023
e47b764
Suggestions from Code Review.
b-fein Jun 6, 2023
7077776
static code analysis fixes
Jun 6, 2023
d193d1a
further improvements
Jun 6, 2023
b041464
improve front-end hack
Jun 6, 2023
7d38866
fix dejagnu to testsuite folder for dejagnu 1.6.3
chbachm Jun 13, 2023
dde809a
Development: Add script to generate a code coverage table automatical…
FelixTJDietrich Jun 5, 2023
05d38e1
Programming exercises: Make UML diagrams responsive (#6667)
terlan98 Jun 5, 2023
e16a996
Development: Improve exception assertions in server tests (#6603)
laadvo Jun 5, 2023
1d55d87
Communication: Fix authorization error in courses without messaging (…
JohannesStoehr Jun 6, 2023
9bbbccf
Merge branch 'develop' into 'feature/blackbox-tests'
Jun 14, 2023
b51605e
added test for selectable features
Jun 20, 2023
034ed77
Merge remote-tracking branch 'origin/develop' into feature/blackbox-t…
Jun 22, 2023
636c175
fix after merge
Jun 23, 2023
5ccaac1
Merge remote-tracking branch 'origin/develop' into feature/blackbox-t…
Jun 23, 2023
9b5b1b2
started integration test
Jun 26, 2023
88f64e8
remove unfinished test
Jun 27, 2023
5e107c5
Merge remote-tracking branch 'origin/develop' into feature/blackbox-t…
Jun 27, 2023
7c1d6df
final cleanup maybe hopefully
Jun 28, 2023
926b27c
forgot an import
Jun 28, 2023
e90ac19
fixed potenital nullpointer
Jun 28, 2023
d79a3f7
Merge remote-tracking branch 'origin/develop' into feature/blackbox-t…
Jun 29, 2023
82b78fd
Merge remote-tracking branch 'origin/develop' into feature/blackbox-t…
b-fein Jun 29, 2023
a44cd5c
fix colours in UML diagram in task
b-fein Jun 29, 2023
edc37d5
package name with dots fix
chrisknedl Jul 9, 2023
2904c10
Apply suggestions from code review
chrisknedl Jul 9, 2023
fa394e4
missing dollar sign escape
Jul 10, 2023
37715e0
Merge remote-tracking branch 'origin/develop' into feature/blackbox-t…
Jul 13, 2023
4dbbd89
regex for blackbox project type and pipeline groovy adjustments
Jul 20, 2023
0206cee
single quotes needed for dockerFlags
Jul 20, 2023
8ec92e4
make editor height dependent on viewport
Jul 20, 2023
4860cd3
remove viewport limit again
Jul 23, 2023
33b20a0
Merge remote-tracking branch 'origin/develop' into feature/blackbox-t…
Aug 4, 2023
ca9dc60
remove redundant part of regex
Aug 7, 2023
18c634a
fixed feature availabilty based on selected project type
Aug 7, 2023
5fb7ca0
test fix
Aug 7, 2023
e6dfcfd
extend test
Aug 7, 2023
5574e55
fix error message for invalid blackbox package names
Aug 9, 2023
cea85dc
Update src/main/resources/templates/java/maven_blackbox/exercise/src/…
chrisknedl Aug 18, 2023
0eefd03
Merge remote-tracking branch 'origin/develop' into feature/blackbox-t…
Aug 21, 2023
4ca640e
fix formatting after merge
b-fein Aug 21, 2023
ca86b51
Code Review 1
chrisknedl Aug 25, 2023
fe73cd6
Code Review 2
chrisknedl Aug 25, 2023
ddc517f
Merge branch 'develop' into feature/blackbox-tests
b-fein Aug 25, 2023
2c24d46
Merge remote-tracking branch 'origin/develop' into feature/blackbox-t…
Aug 31, 2023
67e3ce6
Merge remote-tracking branch 'origin/develop' into feature/blackbox-t…
Sep 1, 2023
1be5fa2
Merge branch 'develop' into feature/blackbox-tests
b-fein Sep 7, 2023
f3fd478
Merge branch 'develop' into feature/blackbox-tests
b-fein Sep 8, 2023
629601d
Merge branch 'develop' into feature/blackbox-tests
b-fein Sep 11, 2023
7e95978
isMavenProject should include MAVEN_BLACKBOX
b-fein Sep 14, 2023
22d4b7f
Merge branch 'develop' into feature/blackbox-tests
b-fein Sep 14, 2023
aefa008
better name for extracted method
b-fein Sep 14, 2023
0d3f18c
Merge remote-tracking branch 'origin/develop' into feature/blackbox-t…
Sep 14, 2023
ba66234
Merge branch 'develop' into feature/blackbox-tests
MarkusPaulsen Sep 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ private ProjectType getConfiguredProjectType(final ProjectType actualProjectType
case XCODE -> ProjectType.XCODE;
case FACT -> ProjectType.FACT;
case GCC -> ProjectType.GCC;
case MAVEN_BLACKBOX -> ProjectType.MAVEN_BLACKBOX;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
public enum ProjectType {

MAVEN_MAVEN, PLAIN_MAVEN, PLAIN, XCODE, FACT, GCC, PLAIN_GRADLE, GRADLE_GRADLE;
MAVEN_MAVEN, PLAIN_MAVEN, PLAIN, XCODE, FACT, GCC, PLAIN_GRADLE, GRADLE_GRADLE, MAVEN_BLACKBOX;

public boolean isMaven() {
return this == MAVEN_MAVEN || this == PLAIN_MAVEN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public class FileService implements DisposableBean {
/**
* These directories get falsely marked as files and should be ignored during copying.
*/
private static final List<String> IGNORED_DIRECTORY_SUFFIXES = List.of(".xcassets", ".colorset", ".appiconset", ".xcworkspace", ".xcodeproj", ".swiftpm");
private static final List<String> IGNORED_DIRECTORY_SUFFIXES = List.of(".xcassets", ".colorset", ".appiconset", ".xcworkspace", ".xcodeproj", ".swiftpm", ".tests");

@Override
public void destroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class JenkinsProgrammingLanguageFeatureService extends ProgrammingLanguag
public JenkinsProgrammingLanguageFeatureService() {
// Must be extended once a new programming language is added
programmingLanguageFeatures.put(EMPTY, new ProgrammingLanguageFeature(EMPTY, false, false, false, false, false, List.of(), false, true, false));
programmingLanguageFeatures.put(JAVA,
new ProgrammingLanguageFeature(JAVA, true, true, true, true, false, List.of(PLAIN_GRADLE, GRADLE_GRADLE, PLAIN_MAVEN, MAVEN_MAVEN), true, true, false));
programmingLanguageFeatures.put(JAVA, new ProgrammingLanguageFeature(JAVA, true, true, true, true, false,
List.of(PLAIN_GRADLE, GRADLE_GRADLE, PLAIN_MAVEN, MAVEN_MAVEN, MAVEN_BLACKBOX), true, true, false));
programmingLanguageFeatures.put(KOTLIN, new ProgrammingLanguageFeature(KOTLIN, true, false, true, true, false, List.of(), true, true, false));
programmingLanguageFeatures.put(PYTHON, new ProgrammingLanguageFeature(PYTHON, false, false, true, false, false, List.of(), false, true, false));
// Jenkins is not supporting XCODE at the moment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ private Optional<String> getProjectTypeName(final ProgrammingLanguage programmin
else if (projectType.isPresent() && projectType.get().isGradle()) {
return Optional.of("gradle");
}
else if (projectType.isPresent() && projectType.get().equals(ProjectType.MAVEN_BLACKBOX)) {
return Optional.of("blackbox");
}
Strohgelaender marked this conversation as resolved.
Show resolved Hide resolved
// Maven is also the project type for all other Java exercises (also if the project type is not present)
else if (ProgrammingLanguage.JAVA.equals(programmingLanguage)) {
return Optional.of("maven");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.tum.in.www1.artemis.service.programming;

import static de.tum.in.www1.artemis.config.Constants.SETUP_COMMIT_MESSAGE;
import static de.tum.in.www1.artemis.domain.enumeration.ProjectType.isMavenProject;

import java.io.FileNotFoundException;
import java.io.IOException;
Expand Down Expand Up @@ -301,9 +302,12 @@ private void setupJVMTestTemplateAndPush(final RepositoryResources resources, fi
if (projectType != null && projectType.isGradle()) {
projectTemplatePath = projectTemplatePath.resolve("gradle");
}
else {
else if (isMavenProject(projectType)) {
projectTemplatePath = projectTemplatePath.resolve("maven");
}
else {
projectTemplatePath = projectTemplatePath.resolve("blackbox");
}
projectTemplatePath = projectTemplatePath.resolve("projectTemplate");

final Resource[] projectTemplate = resourceLoaderService.getResources(projectTemplatePath);
Expand All @@ -315,6 +319,11 @@ private void setupJVMTestTemplateAndPush(final RepositoryResources resources, fi
setupJVMTestTemplateProjectTypeResources(resources, programmingExercise, repoLocalPath);
}

if (projectType == ProjectType.MAVEN_BLACKBOX) {
Path dejagnuLibFolderPath = repoLocalPath.resolve("testsuite").resolve("lib");
fileService.replaceVariablesInFileName(dejagnuLibFolderPath.toString(), PACKAGE_NAME_FILE_PLACEHOLDER, programmingExercise.getPackageName());
}

final Map<String, Boolean> sectionsMap = new HashMap<>();
// Keep or delete static code analysis configuration in the build configuration file
sectionsMap.put("static-code-analysis", Boolean.TRUE.equals(programmingExercise.isStaticCodeAnalysisEnabled()));
Expand Down Expand Up @@ -378,7 +387,9 @@ private void setupTestTemplateRegularTestRuns(final RepositoryResources resource

setupBuildToolProjectFile(repoLocalPath, projectType, sectionsMap);

fileService.copyResources(testFileResources, resources.prefix, packagePath, false);
if (programmingExercise.getProjectType() != ProjectType.MAVEN_BLACKBOX) {
fileService.copyResources(testFileResources, resources.prefix, packagePath, false);
}

if (projectType != null) {
overwriteProjectTypeSpecificFiles(resources, programmingExercise, packagePath);
Expand Down Expand Up @@ -455,7 +466,7 @@ private void setupTestTemplateSequentialTestRuns(final RepositoryResources resou
sectionsMap.put("sequential", true);

// maven configuration should be set for kotlin and older exercises where no project type has been introduced where no project type is defined
final boolean isMaven = ProjectType.isMavenProject(projectType);
final boolean isMaven = isMavenProject(projectType);

final String projectFileName;
if (isMaven) {
Expand Down Expand Up @@ -527,7 +538,7 @@ private void setupBuildStage(final Path resourcePrefix, final Path templatePath,
final Path packagePath = buildStagePath.toAbsolutePath().resolve(TEST_DIR).resolve(PACKAGE_NAME_FOLDER_PLACEHOLDER).toAbsolutePath();

// staging project files are only required for maven
final boolean isMaven = ProjectType.isMavenProject(projectType);
final boolean isMaven = isMavenProject(projectType);
if (isMaven && stagePomXml.isPresent()) {
Files.copy(stagePomXml.get().getInputStream(), buildStagePath.resolve(POM_XML));
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ artemis:
java:
# possible overrides: maven, gradle
default: "ls1tum/artemis-maven-template:java17-18"
maven_blackbox: "ghcr.io/uni-passau-artemis/artemis-dejagnu:20"
kotlin:
# possible overrides: maven, gradle
default: "ls1tum/artemis-maven-template:java17-18"
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to other reviewers: Intentionally empty as part of the template. The student should fill it with content.

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>${packageName}</groupId>
<artifactId>${exerciseNamePomXml}</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>${exerciseNamePomXml}</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>20</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ${packageName};
chrisknedl marked this conversation as resolved.
Show resolved Hide resolved

public class Client {
// TODO: Create and implement interactive command line handling
}
134 changes: 134 additions & 0 deletions src/main/resources/templates/java/maven_blackbox/readme
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Sorting with the Strategy Pattern

In this exercise, we want to implement sorting algorithms and control the program interactively via user input on the console.

**Note:** This project is using `Maven`! You have to import the project as Maven project (not as Eclipse project) as otherwise, errors will occur and you won't be able to work on this exercise.

### Part 1: User Input

First, there has to be a way for the user to communicate with the program.
The `Client` class should handle the user input. The following commands need to be supported by your implementation:

`add date1 date2 ...`<br>
Adds at least one date, but should also support multiple dates.<br>

`sort`<br>
Sorts the previously entered dates.<br>

`clear`<br>
Clears the list of dates.<br>

`help`<br>
Prints a dialog to the console that briefly explains the supported commands.<br>

`print`<br>
Prints the current list of dates to the console.<br>

`quit`<br>
Terminates the program.<br>

Using a `BufferedReader` might be a good starting point.



### Part 2: Sorting

We need to implement two sorting algorithms, in this case `MergeSort` and `BubbleSort`.

**You have the following tasks:**

1. **Implement Bubble Sort**<br>
Implement the method `performSort(List<Date>)` in the class `BubbleSort`. Make sure to follow the Bubble Sort algorithm exactly.

2. **Implement Merge Sort**<br>
Implement the method `performSort(List<Date>)` in the class `MergeSort`. Make sure to follow the Merge Sort algorithm exactly.

### Part 3: Strategy Pattern

We want the application to apply different algorithms for sorting a `List` of `Date` objects.
Use the strategy pattern to select the right sorting algorithm at runtime.

**You have the following tasks:**

1. **SortStrategy Interface**<br>
Create a `SortStrategy` interface and adjust the sorting algorithms so that they implement this interface.

2. **Context Class**<br>
Create and implement a `Context` class following the below class diagram

3. **Context Policy**<br>
Create and implement a `Policy` class following the below class diagram with a simple configuration mechanism:

1. **Select MergeSort**<br>
Select `MergeSort` when the List has more than 10 dates.

2. **Select BubbleSort**<br>
Select `BubbleSort` when the List has less or equal 10 dates.

4. Complete the `Client` class which demonstrates switching between two strategies at runtime.

@startuml

class Client {
}

class Policy {
+configure()
}

class Context {
-dates: List<Date>
+sort()
}

interface SortStrategy {
+performSort(List<Date>)
}

class BubbleSort {
+performSort(List<Date>)
}

class MergeSort {
+performSort(List<Date>)
}

MergeSort -up-|> SortStrategy
BubbleSort -up-|> SortStrategy
Policy -right-> Context: context
Context -right-> SortStrategy: sortAlgorithm
Client .down.> Policy
Client .down.> Context

hide empty fields
hide empty methods

@enduml

### Part 4: Tests

This section shows you which tests are passed by your implementation.

1. [task][Main method exists](MainMethodChecker)

2. [task][All lines have <= 80 characters](LineLengthChecker)

3. [task][Tests.txt exists and is not empty](FileExistsChecker)

4. [task][Public Tests](dejagnu[public])

5. [task][Advanced Tests](dejagnu[advanced])

6. [task][Secret Tests](dejagnu[secret])


### Part 5: Optional Challenges

(These are not tested)

1. Create a new class `QuickSort` that implements `SortStrategy` and implement the Quick Sort algorithm.

2. Make the method `performSort(List<Dates>)` generic, so that other objects can also be sorted by the same method.
**Hint:** Have a look at Java Generics and the interface `Comparable`.

3. Think about a useful decision in `Policy` when to use the new `QuickSort` algorithm.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
sort> help
add: adds the given Dates to the list (format: YYYY-MM-DD)
clear: empties the list
help: prints this text
print: prints the list
sort: sorts the list
quit: quits the program
sort>
Unknown command. Use 'help' to show available commands.
sort> help
add: adds the given Dates to the list (format: YYYY-MM-DD)
clear: empties the list
help: prints this text
print: prints the list
sort: sorts the list
quit: quits the program
sort> 2015-04-01
Unknown command. Use 'help' to show available commands.
sort> add 2015-04-01
sort> print
[Wed Apr 01 02:00:00 CEST 2015]
sort> add 2016-04-01
sort> add 2014-04-01
sort> add 2015-05-01 2015-04-30
sort> prinr
Unknown command. Use 'help' to show available commands.
sort> print
[Wed Apr 01 02:00:00 CEST 2015, Fri Apr 01 02:00:00 CEST 2016, Tue Apr 01 02:00:00 CEST 2014, Fri May 01 02:00:00 CEST 2015, Thu Apr 30 02:00:00 CEST 2015]
sort> sort
sort> print
[Tue Apr 01 02:00:00 CEST 2014, Wed Apr 01 02:00:00 CEST 2015, Thu Apr 30 02:00:00 CEST 2015, Fri May 01 02:00:00 CEST 2015, Fri Apr 01 02:00:00 CEST 2016]
sort> clear
sort> print
[]
sort> quit
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>${packageName}</groupId>
<artifactId>${exerciseNamePomXml}-Solution</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<name>${exerciseNamePomXml} Solution</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<release>20</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading