Search in sources :

Example 6 with RestOptionsDto

use of org.motechproject.mds.dto.RestOptionsDto in project motech by motech.

the class RestIgnoreProcessorTest method shouldProperlyDiscoverRestIgnoredFields.

@Test
public void shouldProperlyDiscoverRestIgnoredFields() throws Exception {
    RestOptionsDto restOptionsDto = new RestOptionsDto();
    List<FieldDto> fields = mockEntityFields();
    processor.setClazz(AnotherSample.class);
    processor.setFields(fields);
    processor.setRestOptions(restOptionsDto);
    processor.execute(bundle, schemaHolder);
    // entity fields + auto generated fields
    Assert.assertEquals(7, processor.getProcessingResult().getFieldNames().size());
    // @RestIgnore annotated
    Assert.assertFalse(processor.getProcessingResult().containsField("modificationDate"));
    Assert.assertFalse(processor.getProcessingResult().containsField("restIgnoreBoolean"));
    // not annotated, regular fields
    Assert.assertTrue(processor.getProcessingResult().containsField("anotherInt"));
    Assert.assertTrue(processor.getProcessingResult().containsField("anotherString"));
}
Also used : RestOptionsDto(org.motechproject.mds.dto.RestOptionsDto) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 7 with RestOptionsDto

use of org.motechproject.mds.dto.RestOptionsDto in project motech by motech.

the class Entity method updateRestOptions.

protected void updateRestOptions(AdvancedSettingsDto advancedSettings) {
    RestOptionsDto dto = advancedSettings.getRestOptions();
    updateRestOptions(dto);
}
Also used : RestOptionsDto(org.motechproject.mds.dto.RestOptionsDto)

Example 8 with RestOptionsDto

use of org.motechproject.mds.dto.RestOptionsDto in project motech by motech.

the class LookupProcessorTest method shouldNotUpdateRestExposedValueForLookupsThatHaveThatModifiedByUser.

@Test
public void shouldNotUpdateRestExposedValueForLookupsThatHaveThatModifiedByUser() throws Exception {
    when(paranamer.lookupParameterNames(getTestMethodExposedViaRest())).thenReturn(argNames);
    AdvancedSettingsDto advanced = mock(AdvancedSettingsDto.class);
    RestOptionsDto restOptions = mock(RestOptionsDto.class);
    when(schemaHolder.getAdvancedSettings(TEST_CLASS_NAME)).thenReturn(advanced);
    when(advanced.getRestOptions()).thenReturn(restOptions);
    when(restOptions.isModifiedByUser()).thenReturn(true);
    EntityProcessorOutput eop = mockEntityProcessorOutput(new EntityDto(TestClass.class.getName()), Arrays.asList(new FieldDto("aaa", "bbb", TypeDto.STRING)));
    lookupProcessor.setEntityProcessingResult(Arrays.asList(eop));
    Method method = getTestMethodExposedViaRest();
    LookupDto dto = new LookupDto("Test Method Exposed Via Rest", true, false, lookupFieldDtos(argNames), true, "testMethodExposedViaRest", asList(argNames), true);
    lookupProcessor.process(method);
    Map<String, List<LookupDto>> elements = lookupProcessor.getProcessingResult();
    assertTrue(elements.containsKey(TEST_CLASS_NAME));
    List<LookupDto> list = elements.get(TEST_CLASS_NAME);
    assertEquals(1, list.size());
    assertEquals(dto, list.get(0));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) Method(java.lang.reflect.Method) RestOptionsDto(org.motechproject.mds.dto.RestOptionsDto) FieldTestHelper.lookupFieldDto(org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Test(org.junit.Test)

Example 9 with RestOptionsDto

use of org.motechproject.mds.dto.RestOptionsDto in project motech by motech.

the class RestOperationsProcessorTest method setUp.

@Before
public void setUp() throws Exception {
    processor = new RestOperationsProcessor();
    restOptions = new RestOptionsDto();
    processor.setRestOptions(restOptions);
}
Also used : RestOptionsDto(org.motechproject.mds.dto.RestOptionsDto) Before(org.junit.Before)

Example 10 with RestOptionsDto

use of org.motechproject.mds.dto.RestOptionsDto in project motech by motech.

the class MdsRestBundleIT method prepareEntity.

private void prepareEntity() throws IOException {
    EntityDto entityDto = new EntityDto(ENTITY_NAME);
    entityDto = entityService.createEntity(entityDto);
    FieldDto strField = new FieldDto(null, entityDto.getId(), TypeDto.STRING, new FieldBasicDto("strFieldDisp", "strField", true, false), false, null);
    FieldDto intField = new FieldDto(null, entityDto.getId(), TypeDto.INTEGER, new FieldBasicDto("intFieldDisp", "intField"), false, null);
    entityService.addFields(entityDto, asList(strField, intField));
    RestOptionsDto restOptions = new RestOptionsDto(true, true, true, true, false);
    restOptions.setFieldNames(prepareAllRestFieldNames(entityService.getEntityFields(entityDto.getId())));
    entityService.updateRestOptions(entityDto.getId(), restOptions);
    // a set based lookup for our convenience
    LookupFieldDto intSetLookupField = new LookupFieldDto(null, "intField", LookupFieldType.SET);
    LookupDto setLookup = new LookupDto("byIntSet", false, true, asList(intSetLookupField), false);
    // list return REST lookup
    LookupFieldDto intLookupField = new LookupFieldDto(null, "intField", LookupFieldType.VALUE);
    LookupDto listLookup = new LookupDto("byInt", false, true, asList(intLookupField), false);
    // single return REST lookup
    LookupFieldDto strLookupField = new LookupFieldDto(null, "strField", LookupFieldType.VALUE);
    LookupDto singleLookup = new LookupDto("byStr", true, true, asList(strLookupField), false);
    entityService.addLookups(entityDto.getId(), asList(setLookup, listLookup, singleLookup));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) LookupDto(org.motechproject.mds.dto.LookupDto) RestOptionsDto(org.motechproject.mds.dto.RestOptionsDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Aggregations

RestOptionsDto (org.motechproject.mds.dto.RestOptionsDto)11 FieldDto (org.motechproject.mds.dto.FieldDto)6 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)5 EntityDto (org.motechproject.mds.dto.EntityDto)5 Test (org.junit.Test)4 LookupDto (org.motechproject.mds.dto.LookupDto)4 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)4 ArrayList (java.util.ArrayList)2 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)2 TrackingDto (org.motechproject.mds.dto.TrackingDto)2 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 Arrays.asList (java.util.Arrays.asList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 NotPersistent (javax.jdo.annotations.NotPersistent)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Entity (org.motechproject.mds.annotations.Entity)1