use of org.motechproject.mds.domain.Entity in project motech by motech.
the class SwaggerFieldConverterTest method shouldConvertComboboxes.
@Test
public void shouldConvertComboboxes() {
// not user-supplied
Property property = SwaggerFieldConverter.fieldToProperty(field(List.class));
verifySimpleProperty(property, "string", null);
Entity entity = new Entity("org.example.Something");
Field field = FieldTestHelper.fieldWithComboboxSettings(entity, "name", "disp name", List.class, true, false, asList("a", "b", "c"));
property = SwaggerFieldConverter.fieldToProperty(field);
verifyComboboxProperty(property, true);
// user-supplied
FieldTestHelper.setAllowUserSupplied(field, true);
property = SwaggerFieldConverter.fieldToProperty(field);
verifyComboboxProperty(property, false);
}
use of org.motechproject.mds.domain.Entity in project motech by motech.
the class TrashServiceTest method shouldFindTrashEntityById.
@Test
public void shouldFindTrashEntityById() throws Exception {
doReturn(Record__Trash.class).when(classLoader).loadClass("org.test.history.TestEntity__Trash");
doReturn(query).when(manager).newQuery(Record__Trash.class);
Entity entity = mock(Entity.class);
Field field = mock(Field.class);
Type type = mock(Type.class);
doReturn(17L).when(entity).getEntityVersion();
doReturn("org.test.TestEntity").when(entity).getClassName();
doReturn(field).when(entity).getField("id");
doReturn(field).when(entity).getField("value");
doReturn(type).when(field).getType();
doReturn(false).when(type).isRelationship();
doReturn(entity).when(allEntities).retrieveById(1L);
doReturn(new Record__Trash()).when(query).execute(anyLong());
Object trash = trashService.findTrashById(1L, "org.test.TestEntity");
assertNotNull(trash);
}
use of org.motechproject.mds.domain.Entity in project motech by motech.
the class AllEntitiesContextIT method setUp.
@Before
public void setUp() throws Exception {
super.setUp();
PersistenceManager persistenceManager = getPersistenceManager();
persistenceManager.makePersistent(new Entity(SAMPLE_CLASS));
persistenceManager.makePersistent(new Entity(EXAMPLE_CLASS));
persistenceManager.makePersistent(new Entity(FOO_CLASS));
Entity entityWithLookups = new Entity(EXAMPLE_CLASS_WITH_LOOKUPS);
List<Lookup> lookups = new LinkedList<>();
lookups.add(new Lookup(EXAMPLE_LOOKUP_1, true, false, null, entityWithLookups));
lookups.add(new Lookup(EXAMPLE_LOOKUP_2, true, false, null, entityWithLookups));
entityWithLookups.setLookups(lookups);
persistenceManager.makePersistent(entityWithLookups);
}
use of org.motechproject.mds.domain.Entity in project motech by motech.
the class InstancesWriterTest method shouldWriteOneRefIdRelationshipProperty.
@Test
public void shouldWriteOneRefIdRelationshipProperty() throws Exception {
Entity entity = EntitySchemaBuilder.eude(ENTITY).field(PROPERTY, "mds.field.relationship.oneToOne").metadata(RELATED_CLASS, EntityWithProperty.class.getName()).metadata(RELATED_FIELD, PROPERTY).done().build();
EntityWithProperty<EntityWithProperty> instance = new EntityWithProperty<>(1L, null);
EntityWithProperty<EntityWithProperty> relatedInstance = new EntityWithProperty<>(42L, null);
instance.setProperty(relatedInstance);
relatedInstance.setProperty(instance);
assertInstanceWrittenCorrectly(entity, instance, "{\"refId\":1,\"property\":42}");
}
use of org.motechproject.mds.domain.Entity in project motech by motech.
the class InstancesWriterTest method shouldWriteNullForNullMultiValueComboboxProperty.
@Test
public void shouldWriteNullForNullMultiValueComboboxProperty() throws Exception {
Entity entity = EntitySchemaBuilder.eude(ENTITY).field(PROPERTY, "mds.field.combobox").setting(ALLOW_MULTIPLE_SELECTIONS, TRUE).metadata(ENUM_CLASS_NAME, ABC.class.getName()).done().build();
List<ABC> combobox = null;
assertInstanceWrittenCorrectly(entity, new EntityWithProperty<>(1L, combobox), NULL_PROPERTY_JSON);
}
Aggregations