use of org.motechproject.mds.dto.JsonLookupDto in project motech by motech.
the class EditableLookupsLoaderTest method shouldAddLookupIfJsonIsValid.
@Test
public void shouldAddLookupIfJsonIsValid() throws Exception {
JsonLookupDto expectedJsonLookup = new JsonLookupDto(CLASS_NAME, ORIGIN_LOOKUP_NAME);
LookupDto expectedLookup = loadLookup();
when(bundle.getResource(MDS_LOOKUPS_JSON)).thenReturn(VALID_JSON);
when(jsonLookupService.exists(CLASS_NAME, ORIGIN_LOOKUP_NAME)).thenReturn(false);
editableLookupsLoader.addEditableLookups(output, bundle);
verify(jsonLookupService, times(1)).exists(matches(CLASS_NAME), matches(ORIGIN_LOOKUP_NAME));
verify(jsonLookupService, times(1)).createJsonLookup(jsonLookupCaptor.capture());
assertLookupsEquals(expectedJsonLookup, jsonLookupCaptor.getValue());
assertEquals(1, output.getLookupProcessorOutputs().size());
assertEquals(1, output.getLookupProcessorOutputs().get(CLASS_NAME).size());
assertEquals(expectedLookup, output.getLookupProcessorOutputs().get(CLASS_NAME).get(0));
}
use of org.motechproject.mds.dto.JsonLookupDto in project motech by motech.
the class EditableLookupsLoader method addEditableEntityLookups.
private void addEditableEntityLookups(MDSProcessorOutput output, EntityLookups entityLookups) {
String entityClassName = entityLookups.getEntityClassName();
List<LookupDto> lookupsToAdd = new ArrayList<>();
for (LookupDto lookup : entityLookups.getLookups()) {
if (!jsonLookupService.exists(entityClassName, lookup.getLookupName())) {
lookupsToAdd.add(lookup);
JsonLookupDto jsonLookup = new JsonLookupDto(entityClassName, lookup.getLookupName());
jsonLookupService.createJsonLookup(jsonLookup);
LOGGER.debug(LOOKUP_ADDED, lookup.getLookupName(), entityClassName);
}
}
List<LookupDto> lookups = getLookups(output, entityClassName);
if (lookupsToAdd.size() > 0) {
if (lookups == null) {
lookups = new ArrayList<>();
output.getLookupProcessorOutputs().put(entityClassName, lookups);
}
lookups.addAll(lookupsToAdd);
}
}
Aggregations