Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
testing for all fields in constructor in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hettling committed Aug 13, 2018
1 parent 399e89b commit b5d35f4
Show file tree
Hide file tree
Showing 54 changed files with 2,779 additions and 57 deletions.
Expand Up @@ -15,6 +15,7 @@
import com.fasterxml.jackson.databind.SerializationFeature;

import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.DefaultCodegen;
import io.swagger.codegen.SupportingFile;
Expand Down Expand Up @@ -77,14 +78,12 @@ public NbarcodegenGenerator()
supportingFiles.add(new SupportingFile("package.mustache", "", "R/nbaR-package.r"));
supportingFiles.add(new SupportingFile("license.mustache", "", "LICENSE"));

// set the output folder here
this.outputFolder = ".";

this.testPackage = "tests/testthat/";
this.testPackage = "tests/testthat";

modelTestTemplateFiles.put("model_test.mustache", ".r");

// set the output folder here
outputFolder = ".";

/**
* Template Location. This is the location which templates will
Expand Down Expand Up @@ -139,13 +138,64 @@ public NbarcodegenGenerator()

}

@Override
public void processOpts() {
super.processOpts();

if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
} else {
setPackageName("swagger");
}

if (additionalProperties.containsKey(CodegenConstants.PACKAGE_VERSION)) {
setPackageVersion((String) additionalProperties.get(CodegenConstants.PACKAGE_VERSION));
} else {
setPackageVersion("1.0.0");
}

additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);

additionalProperties.put("apiDocPath", apiDocPath);
additionalProperties.put("modelDocPath", modelDocPath);

//Hannes: Commented out from superclass
//apiTestTemplateFiles.clear(); // TODO: add api test template
//modelTestTemplateFiles.clear(); // TODO: add model test template

//apiDocTemplateFiles.clear(); // TODO: add api doc template
//modelDocTemplateFiles.clear(); // TODO: add model doc template

modelPackage = packageName;
apiPackage = packageName;

supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
supportingFiles.add(new SupportingFile("description.mustache", "", "DESCRIPTION"));
supportingFiles.add(new SupportingFile("Rbuildignore.mustache", "", ".Rbuildignore"));
supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
supportingFiles.add(new SupportingFile("response.mustache", "/R", "Response.r"));
supportingFiles.add(new SupportingFile("element.mustache", "/R", "Element.r"));
supportingFiles.add(new SupportingFile("api_client.mustache", "/R", "ApiClient.r"));
supportingFiles.add(new SupportingFile("NAMESPACE.mustache", "", "NAMESPACE"));
}

@Override
public String toModelTestFilename(String name)
{
System.out.println("toModelTestFilename");
return ("test-" + name);
}

/* @Override
public String modelTestFileFolder()
{
System.out.println("Testpackage : " + testPackage());
return "tests/testthat/";
}
*/
/*
* Overridden to change later R object name from e.g. SpecimenApi to
* SpecimenClient
Expand Down
13 changes: 12 additions & 1 deletion tests/testthat/test-Agent.r
@@ -1,12 +1,23 @@

library("nbaR")
library("testthat")

set.seed(111)

context("Testing class Agent")

test_that("Constructor works", {
obj <- Agent$new()
expect_is(obj, "Agent")

# test constructor with random arguments
# test field agentText, type character
obj <- Agent$new(
agentText = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "Agent")
})

test_that("toList works", {
Expand Down
21 changes: 20 additions & 1 deletion tests/testthat/test-AssociatedTaxon.r
@@ -1,12 +1,31 @@

library("nbaR")
library("testthat")

set.seed(111)

context("Testing class AssociatedTaxon")

test_that("Constructor works", {
obj <- AssociatedTaxon$new()
expect_is(obj, "AssociatedTaxon")

# test constructor with random arguments
# test field name, type character
obj <- AssociatedTaxon$new(
name = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "AssociatedTaxon")
# test field relationType, type character
obj <- AssociatedTaxon$new(
relationType = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "AssociatedTaxon")
})

test_that("toList works", {
Expand Down
117 changes: 116 additions & 1 deletion tests/testthat/test-BioStratigraphy.r
@@ -1,12 +1,127 @@

library("nbaR")
library("testthat")

set.seed(111)

context("Testing class BioStratigraphy")

test_that("Constructor works", {
obj <- BioStratigraphy$new()
expect_is(obj, "BioStratigraphy")

# test constructor with random arguments
# test field youngBioDatingQualifier, type character
obj <- BioStratigraphy$new(
youngBioDatingQualifier = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "BioStratigraphy")
# test field youngBioName, type character
obj <- BioStratigraphy$new(
youngBioName = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "BioStratigraphy")
# test field youngFossilZone, type character
obj <- BioStratigraphy$new(
youngFossilZone = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "BioStratigraphy")
# test field youngFossilSubZone, type character
obj <- BioStratigraphy$new(
youngFossilSubZone = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "BioStratigraphy")
# test field youngBioCertainty, type character
obj <- BioStratigraphy$new(
youngBioCertainty = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "BioStratigraphy")
# test field youngStratType, type character
obj <- BioStratigraphy$new(
youngStratType = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "BioStratigraphy")
# test field bioDatingQualifier, type character
obj <- BioStratigraphy$new(
bioDatingQualifier = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "BioStratigraphy")
# test field rangePosition, type character
obj <- BioStratigraphy$new(
rangePosition = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "BioStratigraphy")
# test field oldBioName, type character
obj <- BioStratigraphy$new(
oldBioName = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "BioStratigraphy")
# test field bioIdentifier, type character
obj <- BioStratigraphy$new(
bioIdentifier = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "BioStratigraphy")
# test field oldFossilzone, type character
obj <- BioStratigraphy$new(
oldFossilzone = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "BioStratigraphy")
# test field oldFossilSubzone, type character
obj <- BioStratigraphy$new(
oldFossilSubzone = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "BioStratigraphy")
# test field oldBioCertainty, type character
obj <- BioStratigraphy$new(
oldBioCertainty = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "BioStratigraphy")
# test field oldBioStratType, type character
obj <- BioStratigraphy$new(
oldBioStratType = paste(sample(
c(LETTERS, letters),
sample(1:20, 1)
), collapse = "")
)
expect_is(obj, "BioStratigraphy")
})

test_that("toList works", {
Expand Down

0 comments on commit b5d35f4

Please sign in to comment.