use of org.motechproject.mds.domain.Lookup in project motech by motech.
the class UserPreferencesServiceTest method getField2.
private Field getField2() {
Field field = new Field(null, "sampleField2", "Display Name 2", true, false, false, false, false, false, "default 2", "tooltip 2", "placeholder 2", new HashSet<Lookup>());
field.setUIDisplayable(true);
return field;
}
use of org.motechproject.mds.domain.Lookup in project motech by motech.
the class EntityServiceImplTest method shouldAddNewLookup.
@Test
public void shouldAddNewLookup() {
// given
long entityId = 1L;
LookupDto lookupDto = new LookupDto("lookupName", true, false, null, false);
lookupDto.getLookupFields().add(lookupFieldDto("zero"));
lookupDto.getLookupFields().add(lookupFieldDto("two"));
int fieldCount = 4;
List<Field> fields = new ArrayList<>();
String[] fieldNames = { "zero", "one", "two", "three" };
for (long idx = 0; idx < fieldCount; ++idx) {
Field field = mock(Field.class);
doReturn(idx).when(field).getId();
doReturn(field).when(entity).getField(idx);
String fieldName = fieldNames[(int) idx];
doReturn(field).when(entity).getField(fieldName);
doReturn(fieldName).when(field).getName();
if (idx % 2 == 0) {
fields.add(field);
}
}
// when
doReturn(entity).when(allEntities).retrieveById(entityId);
doReturn(null).when(entity).getLookupById(anyLong());
entityService.addLookups(entityId, asList(lookupDto));
// then
verify(allEntities).retrieveById(entityId);
verify(entity).getLookupByName("lookupName");
verify(entity).addLookup(lookupCaptor.capture());
for (long idx = 0; idx < fieldCount; ++idx) {
int wantedNumberOfInvocations = (int) Math.abs(idx % 2 - 1);
verify(entity, times(wantedNumberOfInvocations)).getField(fieldNames[(int) idx]);
}
Lookup lookup = lookupCaptor.getValue();
assertEquals(lookupDto.getLookupName(), lookup.getLookupName());
assertEquals(lookupDto.isSingleObjectReturn(), lookup.isSingleObjectReturn());
assertEquals(lookupDto.isExposedViaRest(), lookup.isExposedViaRest());
assertEquals(fields, lookup.getFields());
}
use of org.motechproject.mds.domain.Lookup in project motech by motech.
the class EntityServiceImplTest method shouldUpdateExistingLookup.
@Test
public void shouldUpdateExistingLookup() {
// given
long entityId = 1L;
LookupDto lookupDto = new LookupDto("lookupName", true, false, null, false);
lookupDto.getLookupFields().add(lookupFieldDto("zero"));
lookupDto.getLookupFields().add(lookupFieldDto("two"));
Lookup lookup = new Lookup();
int fieldCount = 4;
List<Field> fields = new ArrayList<>();
String[] fieldNames = { "zero", "one", "two", "three" };
for (long idx = 0; idx < fieldCount; ++idx) {
Field field = mock(Field.class);
doReturn(idx).when(field).getId();
doReturn(field).when(entity).getField(idx);
String fieldName = fieldNames[(int) idx];
doReturn(field).when(entity).getField(fieldName);
doReturn(fieldName).when(field).getName();
if (idx % 2 == 0) {
fields.add(field);
}
}
// when
doReturn(entity).when(allEntities).retrieveById(entityId);
doReturn(lookup).when(entity).getLookupByName("lookupName");
entityService.addLookups(entityId, asList(lookupDto));
// then
verify(allEntities).retrieveById(entityId);
verify(entity).getLookupByName("lookupName");
verify(entity, never()).addLookup(any(Lookup.class));
assertEquals(lookupDto.getLookupName(), lookup.getLookupName());
assertEquals(lookupDto.isSingleObjectReturn(), lookup.isSingleObjectReturn());
assertEquals(lookupDto.isExposedViaRest(), lookup.isExposedViaRest());
assertEquals(fields, lookup.getFields());
}
use of org.motechproject.mds.domain.Lookup in project motech by motech.
the class EntityWriter method writeLookups.
private void writeLookups() throws IOException {
jsonWriter.name("lookups");
jsonWriter.beginArray();
for (Lookup lookup : entity.getLookups()) {
if (!lookup.isReadOnly()) {
lookupWriter.writeLookup(lookup);
}
}
jsonWriter.endArray();
}
use of org.motechproject.mds.domain.Lookup in project motech by motech.
the class SwaggerGenerator method addLookupEndpoints.
private void addLookupEndpoints(SwaggerModel swaggerModel, Entity entity, Locale locale) {
for (Lookup lookup : entity.getLookupsExposedByRest()) {
String lookupUrl = ClassName.restLookupUrl(entity.getName(), entity.getModule(), entity.getNamespace(), lookup.getMethodName());
swaggerModel.addPathEntry(lookupUrl, HttpMethod.GET, lookupPathEntry(entity, lookup, locale));
}
}
Aggregations