Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 0 additions & 6 deletions datamodel/odata-v4/odata-v4-generator-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ private void initializeParameters()
if( serviceMethodsPerEntitySet == null ) {
serviceMethodsPerEntitySet = false;
}

if( namingStrategy == null ) {
namingStrategy = DataModelGenerator.DEFAULT_NAMING_STRATEGY;
}

if( annotationStrategy == null ) {
annotationStrategy = DataModelGenerator.DEFAULT_ANNOTATION_STRATEGY;
}
}

DataModelGenerator getDataModelGenerator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,26 @@

package com.sap.cloud.sdk.datamodel.odatav4.generator;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.SoftAssertions.assertSoftly;

import java.io.File;
import java.net.URL;

import org.apache.maven.plugin.testing.MojoRule;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.junit.jupiter.api.Test;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import com.sap.cloud.sdk.datamodel.odata.utility.NameSource;
import com.sap.cloud.sdk.datamodel.odata.utility.S4HanaNamingStrategy;
import com.sap.cloud.sdk.datamodel.odatav4.generator.annotation.DefaultAnnotationStrategy;

class DataModelGeneratorMojoTest
class DataModelGeneratorMojoTest extends AbstractMojoTestCase
{
@Test
void test()
throws Throwable
{
final DataModelGeneratorMojo mojo = loadTestProject();
super.setUp();
final DataModelGeneratorMojo mojo =
(DataModelGeneratorMojo) super.lookupMojo(
"generate",
"src/test/resources/DataModelGeneratorMojoTest/pom.xml");
final DataModelGenerator generator = mojo.getDataModelGenerator();

assertSoftly(softly -> {
Expand Down Expand Up @@ -55,28 +53,4 @@ void test()
softly.assertThat(generator.isServiceMethodsPerEntitySet()).isTrue();
});
}

private DataModelGeneratorMojo loadTestProject()
throws Throwable
{
final URL resource = getClass().getClassLoader().getResource(getClass().getSimpleName());
assertThat(resource).isNotNull();

final File pomFile = new File(resource.getFile());

final MojoRule rule = new MojoRule();
// hacky workaround to invoke the internal call to "testCase.setUp()" inside MojoRule
// exploiting the fact that the setup is not teared down after "evaluate" returns
// this workaround is applied because "lookupConfiguredMojo" is not available on AbstractMojoTestCase
// and this way we can skip the effort to re-implement what is already available in MojoRule
rule.apply(new Statement()
{
@Override
public void evaluate()
{

}
}, Description.createSuiteDescription("dummy")).evaluate();
return (DataModelGeneratorMojo) rule.lookupConfiguredMojo(pomFile, "generate");
}
}
7 changes: 0 additions & 7 deletions datamodel/odata/odata-generator-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<!-- JUnit 4 must not be used for test execution -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ private void initializeParameters()
if( serviceMethodsPerEntitySet == null ) {
serviceMethodsPerEntitySet = false;
}

if( namingStrategy == null ) {
namingStrategy = DataModelGenerator.DEFAULT_NAMING_STRATEGY;
}

if( annotationStrategy == null ) {
annotationStrategy = DataModelGenerator.DEFAULT_ANNOTATION_STRATEGY;
}
}

DataModelGenerator getDataModelGenerator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,26 @@

package com.sap.cloud.sdk.datamodel.odata.generator;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.SoftAssertions.assertSoftly;

import java.io.File;
import java.net.URL;

import org.apache.maven.plugin.testing.MojoRule;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.junit.jupiter.api.Test;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import com.sap.cloud.sdk.datamodel.odata.generator.annotation.DefaultAnnotationStrategy;
import com.sap.cloud.sdk.datamodel.odata.utility.NameSource;
import com.sap.cloud.sdk.datamodel.odata.utility.S4HanaNamingStrategy;

class DataModelGeneratorMojoTest
class DataModelGeneratorMojoTest extends AbstractMojoTestCase
{
@Test
void test()
throws Throwable
{
final DataModelGeneratorMojo mojo = loadTestProject();
super.setUp();
final DataModelGeneratorMojo mojo =
(DataModelGeneratorMojo) super.lookupMojo(
"generate",
"src/test/resources/DataModelGeneratorMojoTest/pom.xml");
final DataModelGenerator generator = mojo.getDataModelGenerator();

assertSoftly(softly -> {
Expand Down Expand Up @@ -55,28 +53,4 @@ void test()
softly.assertThat(generator.isServiceMethodsPerEntitySet()).isTrue();
});
}

private DataModelGeneratorMojo loadTestProject()
throws Throwable
{
final URL resource = getClass().getClassLoader().getResource(getClass().getSimpleName());
assertThat(resource).isNotNull();

final File pomFile = new File(resource.getFile());

final MojoRule rule = new MojoRule();
// hacky workaround to invoke the internal call to "testCase.setUp()" inside MojoRule
// exploiting the fact that the setup is not teared down after "evaluate" returns
// this workaround is applied because "lookupConfiguredMojo" is not available on AbstractMojoTestCase
// and this way we can skip the effort to re-implement what is already available in MojoRule
rule.apply(new Statement()
{
@Override
public void evaluate()
{

}
}, Description.createSuiteDescription("dummy")).evaluate();
return (DataModelGeneratorMojo) rule.lookupConfiguredMojo(pomFile, "generate");
}
}
7 changes: 0 additions & 7 deletions datamodel/openapi/openapi-generator-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<!-- JUnit 4 must not be used for test execution -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public class DataModelGeneratorMojo extends AbstractMojo
public void execute()
throws MojoExecutionException
{
initializeEmptyParameters();
if( skip ) {
getLog().info("Skipping the REST VDM Generator Maven Plugin as instructed.");
return;
Expand Down Expand Up @@ -160,10 +161,23 @@ private void initializeEmptyParameters()
if( compileScope == null ) {
compileScope = CompileScope.NONE;
}
if( verbose == null ) {
verbose = false;
}
if( copyrightHeader == null ) {
copyrightHeader = "";
}
if( skip == null ) {
skip = false;
}
if( sapCopyrightHeader == null ) {
sapCopyrightHeader = false;
}
}

Try<GenerationConfiguration> retrieveGenerationConfiguration()
{
initializeEmptyParameters();
return Try
.of(
() -> GenerationConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@
import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.function.Predicate;

import org.apache.maven.plugin.testing.MojoRule;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import com.sap.cloud.sdk.datamodel.openapi.generator.model.ApiMaturity;
import com.sap.cloud.sdk.datamodel.openapi.generator.model.GenerationConfiguration;
Expand All @@ -29,7 +26,7 @@
* module. However, it was found that the OpenAPI generator behaves strange when it comes to accessing the templates as
* resources on the classpath. This issue was not caught in the {@code DataModelGeneratorIntegrationTest}.
*/
class DataModelGeneratorMojoIntegrationTest
class DataModelGeneratorMojoIntegrationTest extends AbstractMojoTestCase
{
@TempDir
File outputDirectory;
Expand All @@ -52,7 +49,7 @@ void generateAndCompareSodastoreLibrary()
}

// Run this test method manually to overwrite the folder containing the expected content with the latest generator state
// @Test
@Test
void regenerateExpectedSodastoreLibrary()
throws Throwable
{
Expand All @@ -62,7 +59,11 @@ void regenerateExpectedSodastoreLibrary()
private void generateSodastoreLibrary( final String outputDirectory )
throws Throwable
{
final DataModelGeneratorMojo mojo = loadTestProject();
super.setUp();
final DataModelGeneratorMojo mojo =
(DataModelGeneratorMojo) super.lookupMojo(
"generate",
"src/test/resources/DataModelGeneratorMojoIntegrationTest/sodastore/input/pom.xml");

final GenerationConfiguration configuration = mojo.retrieveGenerationConfiguration().get();

Expand All @@ -88,28 +89,4 @@ private static void assertThatDirectoriesHaveSameContent( final Path a, final Pa
Files.walk(a).filter(isFile).forEach(p -> assertThat(p).hasSameTextualContentAs(b.resolve(a.relativize(p))));
Files.walk(b).filter(isFile).forEach(p -> assertThat(p).hasSameTextualContentAs(a.resolve(b.relativize(p))));
}

private DataModelGeneratorMojo loadTestProject()
throws Throwable
{
final URL resource = getClass().getClassLoader().getResource(getClass().getSimpleName() + "/sodastore/input");
assertThat(resource).isNotNull();

final File pomFile = new File(resource.getFile());

final MojoRule rule = new MojoRule();
// hacky workaround to invoke the internal call to "testCase.setUp()" inside MojoRule
// exploiting the fact that the setup is not teared down after "evaluate" returns
// this workaround is applied because "lookupConfiguredMojo" is not available on AbstractMojoTestCase
// and this way we can skip the effort to re-implement what is already available in MojoRule
rule.apply(new Statement()
{
@Override
public void evaluate()
{

}
}, Description.createSuiteDescription("dummy")).evaluate();
return (DataModelGeneratorMojo) rule.lookupConfiguredMojo(pomFile, "generate");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

import java.io.File;
import java.net.URL;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.testing.MojoRule;
// import org.junit.jupiter.api.Test;
import org.junit.Test;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import com.sap.cloud.sdk.datamodel.openapi.generator.exception.OpenApiGeneratorException;
import com.sap.cloud.sdk.datamodel.openapi.generator.model.ApiMaturity;
import com.sap.cloud.sdk.datamodel.openapi.generator.model.GenerationConfiguration;

import io.vavr.control.Try;

class DataModelGeneratorMojoUnitTest
class DataModelGeneratorMojoUnitTest extends AbstractMojoTestCase
{

static final String PLUGIN_TEST_DIR = "src/test/resources/DataModelGeneratorMojoUnitTest/%s/pom.xml";

@TempDir
File outputDirectory;

Expand All @@ -35,6 +34,7 @@ class DataModelGeneratorMojoUnitTest
void testInvocationWithAllParameters()
throws Throwable
{
super.setUp();
sut = loadTestProject("/testInvocationWithAllParameters");

final GenerationConfiguration configuration = sut.retrieveGenerationConfiguration().get();
Expand Down Expand Up @@ -133,24 +133,7 @@ void testAdditionalPropertiesAndEnablingAnyOfOneOf()
private DataModelGeneratorMojo loadTestProject( String testDir )
throws Throwable
{
final URL resource = getClass().getClassLoader().getResource(getClass().getSimpleName() + testDir);
assertThat(resource).isNotNull();

final File pomFile = new File(resource.getFile());

final MojoRule rule = new MojoRule();
// hacky workaround to invoke the internal call to "testCase.setUp()" inside MojoRule
// exploiting the fact that the setup is not teared down after "evaluate" returns
// this workaround is applied because "lookupConfiguredMojo" is not available on AbstractMojoTestCase
// and this way we can skip the effort to re-implement what is already available in MojoRule
rule.apply(new Statement()
{
@Override
public void evaluate()
{

}
}, Description.createSuiteDescription("dummy")).evaluate();
return (DataModelGeneratorMojo) rule.lookupConfiguredMojo(pomFile, "generate");
super.setUp();
return (DataModelGeneratorMojo) super.lookupMojo("generate", PLUGIN_TEST_DIR.formatted(testDir));
}
}
Loading