Skip to content

Commit

Permalink
Code clean-up - no functional change
Browse files Browse the repository at this point in the history
  • Loading branch information
bpross-52n committed Dec 15, 2023
1 parent afe8faf commit 81e5877
Show file tree
Hide file tree
Showing 40 changed files with 4,792 additions and 4,625 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import java.util.List;

/**
* Declares supported command line arguments that are parsed using the
* JCommander library. All arguments are optional. The default values are as
* follows:
* Declares supported command line arguments that are parsed using the JCommander library.
* All arguments are optional. The default values are as follows:
* <ul>
* <li>XML properties file: ${user.home}/test-run-props.xml</li>
* <li>outputDir: ${user.home}</li>
Expand All @@ -26,35 +25,38 @@
*/
public class CommandLineArguments {

@Parameter(description = "Properties file")
private final List<String> xmlProps;

@Parameter(names = {"-o", "--outputDir"}, description = "Output directory")
private String outputDir;

@Parameter(names = {"-d", "--deleteSubjectOnFinish"}, description = "Delete file containing representation of test subject when finished")
private boolean deleteSubjectOnFinish = false;

public CommandLineArguments() {
this.xmlProps = new ArrayList<>();
}

public File getPropertiesFile() {
File fileRef;
if (xmlProps.isEmpty()) {
fileRef = new File(System.getProperty("user.home"), "test-run-props.xml");
} else {
String propsFile = xmlProps.get(0);
fileRef = (propsFile.startsWith("file:")) ? new File(URI.create(propsFile)) : new File(propsFile);
}
return fileRef;
}

public String getOutputDir() {
return (null != outputDir) ? outputDir : System.getProperty("user.home");
}

public boolean doDeleteSubjectOnFinish() {
return deleteSubjectOnFinish;
}
@Parameter(description = "Properties file")
private final List<String> xmlProps;

@Parameter(names = { "-o", "--outputDir" }, description = "Output directory")
private String outputDir;

@Parameter(names = { "-d", "--deleteSubjectOnFinish" },
description = "Delete file containing representation of test subject when finished")
private boolean deleteSubjectOnFinish = false;

public CommandLineArguments() {
this.xmlProps = new ArrayList<>();
}

public File getPropertiesFile() {
File fileRef;
if (xmlProps.isEmpty()) {
fileRef = new File(System.getProperty("user.home"), "test-run-props.xml");
}
else {
String propsFile = xmlProps.get(0);
fileRef = (propsFile.startsWith("file:")) ? new File(URI.create(propsFile)) : new File(propsFile);
}
return fileRef;
}

public String getOutputDir() {
return (null != outputDir) ? outputDir : System.getProperty("user.home");
}

public boolean doDeleteSubjectOnFinish() {
return deleteSubjectOnFinish;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,64 +20,67 @@
*/
public class CommonDataFixture extends CommonFixture {

private static final int DEFAULT_NUMBER_OF_COLLECTIONS = 3;

private OpenApi3 apiModel;

private List<RequirementClass> requirementClasses;

protected int noOfCollections = DEFAULT_NUMBER_OF_COLLECTIONS;

@BeforeClass
public void requirementClasses( ITestContext testContext ) {
this.requirementClasses = (List<RequirementClass>) testContext.getSuite().getAttribute( REQUIREMENTCLASSES.getName() );
}

@BeforeClass
public void noOfCollections( ITestContext testContext ) {
Object noOfCollections = testContext.getSuite().getAttribute( NO_OF_COLLECTIONS.getName() );
if ( noOfCollections != null ) {
this.noOfCollections = (Integer) noOfCollections;
}
}

@BeforeClass
public void retrieveApiModel( ITestContext testContext ) {
this.apiModel = (OpenApi3) testContext.getSuite().getAttribute( API_MODEL.getName() );
}

public OpenApi3 getApiModel() {
if ( apiModel == null )
throw new SkipException( "ApiModel is not available." );
return apiModel;
}

protected List<String> createListOfMediaTypesToSupportForOtherResources( Map<String, Object> linkToSelf ) {
if ( this.requirementClasses == null )
throw new SkipException( "No requirement classes described in resource /conformance available" );
List<String> mediaTypesToSupport = new ArrayList<>();
for ( RequirementClass requirementClass : this.requirementClasses )
if ( requirementClass.hasMediaTypeForOtherResources() )
mediaTypesToSupport.add( requirementClass.getMediaTypeOtherResources() );
if ( linkToSelf != null )
mediaTypesToSupport.remove( linkToSelf.get( "type" ) );
return mediaTypesToSupport;
}

protected List<String> createListOfMediaTypesToSupportForFeatureCollectionsAndFeatures() {
if ( this.requirementClasses == null )
throw new SkipException( "No requirement classes described in resource /conformance available" );
List<String> mediaTypesToSupport = new ArrayList<>();
for ( RequirementClass requirementClass : this.requirementClasses )
if ( requirementClass.hasMediaTypeForFeaturesAndCollections() )
mediaTypesToSupport.add( requirementClass.getMediaTypeFeaturesAndCollections() );
return mediaTypesToSupport;
}

protected List<String> createListOfMediaTypesToSupportForFeatureCollectionsAndFeatures( Map<String, Object> linkToSelf ) {
List<String> mediaTypesToSupport = createListOfMediaTypesToSupportForFeatureCollectionsAndFeatures();
if ( linkToSelf != null )
mediaTypesToSupport.remove( linkToSelf.get( "type" ) );
return mediaTypesToSupport;
}
private static final int DEFAULT_NUMBER_OF_COLLECTIONS = 3;

private OpenApi3 apiModel;

private List<RequirementClass> requirementClasses;

protected int noOfCollections = DEFAULT_NUMBER_OF_COLLECTIONS;

@BeforeClass
public void requirementClasses(ITestContext testContext) {
this.requirementClasses = (List<RequirementClass>) testContext.getSuite()
.getAttribute(REQUIREMENTCLASSES.getName());
}

@BeforeClass
public void noOfCollections(ITestContext testContext) {
Object noOfCollections = testContext.getSuite().getAttribute(NO_OF_COLLECTIONS.getName());
if (noOfCollections != null) {
this.noOfCollections = (Integer) noOfCollections;
}
}

@BeforeClass
public void retrieveApiModel(ITestContext testContext) {
this.apiModel = (OpenApi3) testContext.getSuite().getAttribute(API_MODEL.getName());
}

public OpenApi3 getApiModel() {
if (apiModel == null)
throw new SkipException("ApiModel is not available.");
return apiModel;
}

protected List<String> createListOfMediaTypesToSupportForOtherResources(Map<String, Object> linkToSelf) {
if (this.requirementClasses == null)
throw new SkipException("No requirement classes described in resource /conformance available");
List<String> mediaTypesToSupport = new ArrayList<>();
for (RequirementClass requirementClass : this.requirementClasses)
if (requirementClass.hasMediaTypeForOtherResources())
mediaTypesToSupport.add(requirementClass.getMediaTypeOtherResources());
if (linkToSelf != null)
mediaTypesToSupport.remove(linkToSelf.get("type"));
return mediaTypesToSupport;
}

protected List<String> createListOfMediaTypesToSupportForFeatureCollectionsAndFeatures() {
if (this.requirementClasses == null)
throw new SkipException("No requirement classes described in resource /conformance available");
List<String> mediaTypesToSupport = new ArrayList<>();
for (RequirementClass requirementClass : this.requirementClasses)
if (requirementClass.hasMediaTypeForFeaturesAndCollections())
mediaTypesToSupport.add(requirementClass.getMediaTypeFeaturesAndCollections());
return mediaTypesToSupport;
}

protected List<String> createListOfMediaTypesToSupportForFeatureCollectionsAndFeatures(
Map<String, Object> linkToSelf) {
List<String> mediaTypesToSupport = createListOfMediaTypesToSupportForFeatureCollectionsAndFeatures();
if (linkToSelf != null)
mediaTypesToSupport.remove(linkToSelf.get("type"));
return mediaTypesToSupport;
}

}
Loading

0 comments on commit 81e5877

Please sign in to comment.