Search in sources :

Example 16 with Validator

use of com.yahoo.rdl.Validator in project athenz by yahoo.

the class ZMSImpl method loadSchemaValidator.

void loadSchemaValidator() {
    schema = ZMSSchema.instance();
    validator = new Validator(schema);
}
Also used : Validator(com.yahoo.rdl.Validator)

Example 17 with Validator

use of com.yahoo.rdl.Validator in project athenz by yahoo.

the class ProviderSchemaTest method testTenants.

@Test
public void testTenants() {
    Schema schema = ProviderSchema.instance();
    Validator validator = new Validator(schema);
    Tenant t = new Tenant().setService("test-service").setName("test.domain").setState(TenantState.ACTIVE);
    Result result = validator.validate(t, "Tenant");
    assertTrue(result.valid);
    t = new Tenant().setService("test_service").setName("test.domain").setState(TenantState.ACTIVE);
    result = validator.validate(t, "Tenant");
    assertTrue(result.valid);
    t = new Tenant().setService("test@service").setName("test.domain").setState(TenantState.ACTIVE);
    result = validator.validate(t, "Tenant");
    assertFalse(result.valid);
}
Also used : Schema(com.yahoo.rdl.Schema) Validator(com.yahoo.rdl.Validator) Result(com.yahoo.rdl.Validator.Result) Test(org.testng.annotations.Test)

Example 18 with Validator

use of com.yahoo.rdl.Validator in project athenz by yahoo.

the class ProviderSchemaTest method testTenantsMethods.

@Test
public void testTenantsMethods() {
    Schema schema = ProviderSchema.instance();
    Validator validator = new Validator(schema);
    List<String> roles = Arrays.asList("test-role");
    List<String> rg = Arrays.asList("test-resource-group");
    Tenant t = new Tenant().setService("test-service").setName("test.domain").setState(TenantState.ACTIVE).setRoles(roles).setResourceGroups(rg);
    Result result = validator.validate(t, "Tenant");
    assertTrue(result.valid);
    assertEquals(t.getService(), "test-service");
    assertEquals(t.getName(), "test.domain");
    assertEquals(t.getState(), TenantState.ACTIVE);
    assertEquals(t.getRoles(), roles);
    assertEquals(t.getResourceGroups(), rg);
    assertEquals(t.getState(), TenantState.fromString("ACTIVE"));
    Tenant t2 = new Tenant().setService("test-service").setName("test.domain").setState(TenantState.ACTIVE).setRoles(roles).setResourceGroups(rg);
    assertTrue(t.equals(t));
    t.setResourceGroups(null);
    assertFalse(t.equals(t2));
    t.setRoles(null);
    assertFalse(t.equals(t2));
    t.setState(null);
    assertFalse(t.equals(t2));
    t.setName(null);
    assertFalse(t.equals(t2));
    t.setService(null);
    assertFalse(t.equals(t2));
    assertFalse(t.equals(new String()));
}
Also used : Schema(com.yahoo.rdl.Schema) Validator(com.yahoo.rdl.Validator) Result(com.yahoo.rdl.Validator.Result) Test(org.testng.annotations.Test)

Example 19 with Validator

use of com.yahoo.rdl.Validator in project athenz by yahoo.

the class ProviderSchemaTest method testTenantResourceGroup.

@Test
public void testTenantResourceGroup() {
    Schema schema = ProviderSchema.instance();
    Validator validator = new Validator(schema);
    TenantResourceGroup trg = new TenantResourceGroup().setService("test-service").setName("test.domain").setResourceGroup("test-group");
    Result result = validator.validate(trg, "TenantResourceGroup");
    assertTrue(result.valid);
    trg = new TenantResourceGroup().setService("test@service").setName("test.domain").setResourceGroup("test-group");
    result = validator.validate(trg, "TenantResourceGroup");
    assertFalse(result.valid);
}
Also used : Schema(com.yahoo.rdl.Schema) Validator(com.yahoo.rdl.Validator) Result(com.yahoo.rdl.Validator.Result) Test(org.testng.annotations.Test)

Example 20 with Validator

use of com.yahoo.rdl.Validator in project athenz by yahoo.

the class ProviderSchemaTest method testTenantResourceGroupMethods.

@Test
public void testTenantResourceGroupMethods() {
    Schema schema = ProviderSchema.instance();
    Validator validator = new Validator(schema);
    List<String> roles = Arrays.asList("test-role");
    TenantResourceGroup trg = new TenantResourceGroup().setService("test-service").setName("test.domain").setResourceGroup("test-group").setRoles(roles);
    Result result = validator.validate(trg, "TenantResourceGroup");
    assertTrue(result.valid);
    assertEquals(trg.getService(), "test-service");
    assertEquals(trg.getName(), "test.domain");
    assertEquals(trg.getResourceGroup(), "test-group");
    assertEquals(trg.getRoles(), roles);
    TenantResourceGroup trg2 = new TenantResourceGroup().setService("test-service").setName("test.domain").setResourceGroup("test-group").setRoles(roles);
    assertTrue(trg.equals(trg));
    trg.setRoles(null);
    assertFalse(trg.equals(trg2));
    trg.setResourceGroup(null);
    assertFalse(trg.equals(trg2));
    trg.setName(null);
    assertFalse(trg.equals(trg2));
    trg.setService(null);
    assertFalse(trg.equals(trg2));
    assertFalse(trg.equals(new String()));
}
Also used : Schema(com.yahoo.rdl.Schema) Validator(com.yahoo.rdl.Validator) Result(com.yahoo.rdl.Validator.Result) Test(org.testng.annotations.Test)

Aggregations

Validator (com.yahoo.rdl.Validator)47 Schema (com.yahoo.rdl.Schema)45 Result (com.yahoo.rdl.Validator.Result)45 Test (org.testng.annotations.Test)45 ArrayList (java.util.ArrayList)3 Struct (com.yahoo.rdl.Struct)1