Search in sources :

Example 1 with JsonLookupDto

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

Example 2 with JsonLookupDto

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);
    }
}
Also used : JsonLookupDto(org.motechproject.mds.dto.JsonLookupDto) LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) JsonLookupDto(org.motechproject.mds.dto.JsonLookupDto)

Aggregations

JsonLookupDto (org.motechproject.mds.dto.JsonLookupDto)2 LookupDto (org.motechproject.mds.dto.LookupDto)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1