org.deephacks.tools4j.config.test.schema.SchemaManagerTests Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tools4j-config-tck Show documentation
Show all versions of tools4j-config-tck Show documentation
Functional Tests for Tools4j Config
package org.deephacks.tools4j.config.test.schema;
import org.deephacks.tools4j.config.model.AbortRuntimeException;
import org.deephacks.tools4j.config.model.Events;
import org.deephacks.tools4j.config.model.Schema;
import org.deephacks.tools4j.config.model.Schema.SchemaId;
import org.deephacks.tools4j.config.model.Schema.SchemaProperty;
import org.deephacks.tools4j.config.model.Schema.SchemaPropertyList;
import org.deephacks.tools4j.config.spi.SchemaManager;
import org.deephacks.tools4j.config.test.FeatureTestsRunner;
import org.deephacks.tools4j.config.test.LookupProxy;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
@RunWith(FeatureTestsRunner.class)
public final class SchemaManagerTests {
protected SchemaManager manager = LookupProxy.lookup(SchemaManager.class);
@Test
public void test_add_get_schema() {
Set schemas = generateSchemas(10, 10);
for (Schema schema : schemas) {
manager.registerSchema(schema);
Schema response = manager.getSchema(schema.getName());
assertThat(schema, equalTo(response));
}
}
@Test
public void test_get_schemas() {
Set schemas = generateSchemas(10, 10);
for (Schema schema : schemas) {
manager.registerSchema(schema);
Schema response = manager.getSchema(schema.getName());
assertThat(schema, equalTo(response));
}
Map schemaNames = manager.getSchemas();
for (Schema s : schemas) {
assertTrue(schemaNames.containsKey(s.getName()));
}
}
@Test
public void test_remove_schema() {
Set schemas = generateSchemas(2, 2);
for (Schema schema : schemas) {
manager.registerSchema(schema);
Schema response = manager.getSchema(schema.getName());
assertThat(schema, equalTo(response));
}
Schema s = schemas.iterator().next();
assertThat(manager.getSchema(s.getName()), is(s));
manager.removeSchema(s.getName());
try {
s = manager.getSchema(s.getName());
} catch (AbortRuntimeException e) {
assertThat(e.getEvent().getCode(), is(Events.CFG101));
}
}
public Set generateSchemas(int numBeans, int numProps) {
HashSet schemas = new HashSet();
for (int i = 0; i < numBeans; i++) {
String type = "configType" + i;
String name = "configName" + i;
String desc = "configDesc" + i;
SchemaId id = SchemaId.create("configId" + i, "configDesc" + i, false);
Schema schema = Schema.create(id, type, name, desc);
for (int j = 0; j < numProps; j++) {
String _name = "propName" + j;
String _fieldName = "propFieldName" + j;
String _classType = Integer.class.getName();
String _desc = "propDesc" + j;
String _defaultValue = "" + j;
SchemaProperty prop = SchemaProperty.create(_name, _fieldName, _classType, _desc,
true, new ArrayList(), _defaultValue, false);
schema.add(prop);
_name = "collPropName" + j;
_fieldName = "collpropFieldName" + j;
_classType = String.class.getName();
_desc = "collpropDesc" + j;
_defaultValue = "collpropDefaultValue" + j;
List _colDefault = new ArrayList<>();
_colDefault.add("simple1");
_colDefault.add("simple2");
SchemaPropertyList col = SchemaPropertyList.create(_name, _fieldName, _classType,
_desc, true, new ArrayList(), _colDefault, _colDefault.getClass()
.getName(), false);
schema.add(col);
}
schemas.add(schema);
}
return schemas;
}
}