use of org.motechproject.mds.domain.Entity in project motech by motech.
the class TrashServiceTest method shouldMoveObjectToTrash.
@Test
public void shouldMoveObjectToTrash() throws Exception {
doReturn(Record__Trash.class).when(classLoader).loadClass(Record__Trash.class.getName());
Entity entity = mock(Entity.class);
Field field = mock(Field.class);
Type type = mock(Type.class);
doReturn(17L).when(entity).getEntityVersion();
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).retrieveByClassName(anyString());
Record instance = new Record();
trashService.moveToTrash(instance, 1L);
verify(manager).makePersistent(trashCaptor.capture());
Record__Trash trash = trashCaptor.getValue();
assertEquals(instance.getValue(), trash.getValue());
}
use of org.motechproject.mds.domain.Entity in project motech by motech.
the class EntityWriterTest method shouldWriteUnmodifiedDDE.
@Test
public void shouldWriteUnmodifiedDDE() throws IOException {
Entity dde = buildUnmodifiedDDE();
String ddeJsonResource = "json/EntityWriterTest_UnmodifiedDDE.json";
assertEntityWrittenCorrectly(dde, ddeJsonResource);
}
use of org.motechproject.mds.domain.Entity in project motech by motech.
the class EntityWriterTest method shouldWriteEUDE.
@Test
public void shouldWriteEUDE() throws IOException {
Entity eude = buildEUDE();
String eudeJsonResource = "json/EntityWriterTest_EUDE.json";
assertEntityWrittenCorrectly(eude, eudeJsonResource);
}
use of org.motechproject.mds.domain.Entity in project motech by motech.
the class PropertyBuilderTest method shouldGenerateAppropriatePropertyType.
@Test
public void shouldGenerateAppropriatePropertyType() throws Exception {
Set<String> set = new HashSet<>();
Range<Integer> range = new Range<>(0, 1);
Type type = new Type("mds.field.combobox", "", List.class);
Entity entity = new Entity("org.motechproject.mds.Sample");
Field field = new Field(entity, "roles", "roles", type, true, false, false);
// should not create collection property for fields without list field
assertProperty(PropertyBuilder.create("roles", 1L, Long.class.getName()), EqualProperty.class, "roles", 1L);
field.addSetting(new FieldSetting(field, new TypeSetting(Constants.Settings.ALLOW_MULTIPLE_SELECTIONS), "true"));
// should create collection property for enum list
assertProperty(PropertyBuilder.create(field, "role"), CollectionProperty.class, "roles", Arrays.asList("role"));
field.addSetting(new FieldSetting(field, new TypeSetting(Constants.Settings.ALLOW_USER_SUPPLIED), "true"));
// should create collection property for string list
assertProperty(PropertyBuilder.create(field, "role"), CollectionProperty.class, "roles", Arrays.asList("role"));
assertProperty(PropertyBuilder.create("set", set, String.class), SetProperty.class, "set", set);
assertProperty(PropertyBuilder.create("range", range, Integer.class), RangeProperty.class, "range", range);
assertProperty(PropertyBuilder.create("equal", 1L, Long.class), EqualProperty.class, "equal", 1L);
assertProperty(PropertyBuilder.create("text", "someString", String.class.getName(), "matches()"), MatchesProperty.class, "text", ".*someString.*");
assertProperty(PropertyBuilder.create("text", "someString", String.class.getName(), "matches((?i))"), MatchesCaseInsensitiveProperty.class, "text", "(?i).*someString.*");
}
use of org.motechproject.mds.domain.Entity in project motech by motech.
the class RelationshipResolver method removeUnresolvedEntities.
public List<Entity> removeUnresolvedEntities(Set<Entity> entities) {
List<Entity> resolvedEntities = new ArrayList<>();
EntitiesRetriever entitiesRetriever = new EntitiesRetriever(entities);
for (Entity entity : entities) {
if (isEntityResolved(entity, new ArrayList<>(), new ArrayList<>(), entitiesRetriever)) {
resolvedEntities.add(entity);
}
}
return resolvedEntities;
}
Aggregations