Search in sources :

Example 51 with Entity

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);
}
Also used : Entity(org.motechproject.mds.domain.Entity) Field(org.motechproject.mds.domain.Field) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Property(org.motechproject.mds.docs.swagger.model.Property) Test(org.junit.Test)

Example 52 with Entity

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);
}
Also used : Record__Trash(org.motechproject.mds.testutil.records.history.Record__Trash) Entity(org.motechproject.mds.domain.Entity) Field(org.motechproject.mds.domain.Field) Type(org.motechproject.mds.domain.Type) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 53 with Entity

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);
}
Also used : Entity(org.motechproject.mds.domain.Entity) PersistenceManager(javax.jdo.PersistenceManager) Lookup(org.motechproject.mds.domain.Lookup) LinkedList(java.util.LinkedList) Before(org.junit.Before)

Example 54 with Entity

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}");
}
Also used : Entity(org.motechproject.mds.domain.Entity) Test(org.junit.Test)

Example 55 with Entity

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);
}
Also used : Entity(org.motechproject.mds.domain.Entity) Test(org.junit.Test)

Aggregations

Entity (org.motechproject.mds.domain.Entity)97 Test (org.junit.Test)35 Field (org.motechproject.mds.domain.Field)33 MdsEntity (org.motechproject.mds.domain.MdsEntity)32 MdsVersionedEntity (org.motechproject.mds.domain.MdsVersionedEntity)32 Transactional (org.springframework.transaction.annotation.Transactional)32 ArrayList (java.util.ArrayList)14 Lookup (org.motechproject.mds.domain.Lookup)12 UserPreferences (org.motechproject.mds.domain.UserPreferences)8 Type (org.motechproject.mds.domain.Type)7 AllUserPreferences (org.motechproject.mds.repository.internal.AllUserPreferences)7 EntityDto (org.motechproject.mds.dto.EntityDto)6 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)6 HashMap (java.util.HashMap)5 FieldDto (org.motechproject.mds.dto.FieldDto)5 HashSet (java.util.HashSet)4 EntityDraft (org.motechproject.mds.domain.EntityDraft)4 MotechDataService (org.motechproject.mds.service.MotechDataService)4 Query (javax.jdo.Query)3 FieldSetting (org.motechproject.mds.domain.FieldSetting)3