Skip to content
Permalink
Browse files
Validating ApplicationName parameters. Added unit tests for parameter…
… validation.
  • Loading branch information
mifosio-04-04-2018 committed Apr 4, 2017
1 parent b88a000 commit 14329d4a4e0408ccfd0c5e0e50f1cd07ece1cfca
Showing 6 changed files with 96 additions and 12 deletions.
@@ -20,6 +20,10 @@ dependencies {
[group: 'io.mifos.core', name: 'api', version: versions.frameworkapi],
[group: 'org.hibernate', name: 'hibernate-validator', version: versions.validator]
)

testCompile(
[group: 'io.mifos.core', name: 'test', version: versions.frameworktest],
)
}

publishing {
@@ -15,15 +15,12 @@
*/
package io.mifos.provisioner.api.v1.domain;

import io.mifos.core.lang.validation.constraints.ValidIdentifier;
import io.mifos.core.lang.validation.constraints.ValidApplicationName;

import javax.validation.constraints.NotNull;

@SuppressWarnings("unused")
@SuppressWarnings({"unused", "WeakerAccess"})
public class Application {

@NotNull
@ValidIdentifier //name should be URL-safe.
@ValidApplicationName
private String name;
private String description;
private String vendor;
@@ -15,15 +15,12 @@
*/
package io.mifos.provisioner.api.v1.domain;

import io.mifos.core.lang.validation.constraints.ValidIdentifier;
import io.mifos.core.lang.validation.constraints.ValidApplicationName;

import javax.validation.constraints.NotNull;

@SuppressWarnings("unused")
@SuppressWarnings({"unused", "WeakerAccess"})
public class AssignedApplication {

@NotNull
@ValidIdentifier
@ValidApplicationName
private String name;

public AssignedApplication() {
@@ -0,0 +1,44 @@
package io.mifos.provisioner.api.v1.domain;

import io.mifos.core.test.domain.ValidationTest;
import io.mifos.core.test.domain.ValidationTestCase;
import org.junit.runners.Parameterized;

import java.util.ArrayList;
import java.util.Collection;

/**
* @author Myrle Krantz
*/
public class ApplicationTest extends ValidationTest<Application> {

public ApplicationTest(ValidationTestCase<Application> testCase) {
super(testCase);
}

@Override
protected Application createValidTestSubject() {
final Application ret = new Application();
ret.setName("bebop-v3");
ret.setHomepage("http://xyz.bebop:2021/v1");
ret.setDescription("bebop manager");
ret.setVendor("fineract");
return ret;
}

@Parameterized.Parameters
public static Collection testCases() {
final Collection<ValidationTestCase> ret = new ArrayList<>();
ret.add(new ValidationTestCase<Application>("basicCase")
.adjustment(x -> {})
.valid(true));
ret.add(new ValidationTestCase<Application>("invalidApplicationName")
.adjustment(x -> x.setName("bebop-dowop"))
.valid(false));
ret.add(new ValidationTestCase<Application>("nullApplicationName")
.adjustment(x -> x.setName(null))
.valid(false));
return ret;
}

}
@@ -0,0 +1,41 @@
package io.mifos.provisioner.api.v1.domain;

import io.mifos.core.test.domain.ValidationTest;
import io.mifos.core.test.domain.ValidationTestCase;
import org.junit.runners.Parameterized;

import java.util.ArrayList;
import java.util.Collection;

/**
* @author Myrle Krantz
*/
public class AssignedApplicationTest extends ValidationTest<AssignedApplication> {

public AssignedApplicationTest(ValidationTestCase<AssignedApplication> testCase) {
super(testCase);
}

@Override
protected AssignedApplication createValidTestSubject() {
final AssignedApplication ret = new AssignedApplication();
ret.setName("bebop-v3");
return ret;
}

@Parameterized.Parameters
public static Collection testCases() {
final Collection<ValidationTestCase> ret = new ArrayList<>();
ret.add(new ValidationTestCase<AssignedApplication>("basicCase")
.adjustment(x -> {})
.valid(true));
ret.add(new ValidationTestCase<AssignedApplication>("invalidApplicationName")
.adjustment(x -> x.setName("bebop-dowop"))
.valid(false));
ret.add(new ValidationTestCase<AssignedApplication>("nullApplicationName")
.adjustment(x -> x.setName(null))
.valid(false));
return ret;
}

}
@@ -10,6 +10,7 @@ ext.versions = [
frameworkcassandra : '0.1.0-BUILD-SNAPSHOT',
frameworkmariadb : '0.1.0-BUILD-SNAPSHOT',
frameworkcrypto : '0.1.0-BUILD-SNAPSHOT',
frameworktest : '0.1.0-BUILD-SNAPSHOT',
validator : '5.3.0.Final'
]

0 comments on commit 14329d4

Please sign in to comment.