@Test public void shouldGenerateJson() { String json = "{\n" + " \"name\": \"data-services\",\n" + " \"objects\": [ {\n" + " \"displayName\": \"TestEntity\",\n" + " \"type\": \"org.motechproject.TestEntity\",\n" + " \"lookupFields\": [ {\n" + " \"displayName\": \"TestLookupName\",\n" + " \"fields\": [\n" + " \"TestFieldName\" ]\n" + " }, {\n" + " \"displayName\": \"mds.dataprovider.byinstanceid\",\n" + " \"fields\": [\n" + " \"mds.dataprovider.instanceid\"\n" + " ]\n" + " }\n" + " ],\n" + " \"fields\": [\n" + " {\n" + " \"displayName\": \"TestFieldDisplayName\",\n" + " \"fieldKey\": \"TestFieldName\"\n" + " } ]\n" + " } ]\n" + "}\n"; EntityDto entity = new EntityDto(); entity.setId(Long.valueOf("1")); entity.setName("TestEntity"); entity.setClassName("org.motechproject.TestEntity"); FieldDto field = new FieldDto(); FieldBasicDto fieldBasicDto = new FieldBasicDto(); fieldBasicDto.setName("TestFieldName"); fieldBasicDto.setDisplayName("TestFieldDisplayName"); field.setBasic(fieldBasicDto); fieldList.add(field); LookupDto lookup = new LookupDto(); lookup.setLookupName("TestLookupName"); List<LookupFieldDto> lookupFields = new LinkedList<>(); lookupFields.add(FieldTestHelper.lookupFieldDto("TestFieldName")); lookup.setLookupFields(lookupFields); lookupList.add(lookup); AdvancedSettingsDto advancedSettings = new AdvancedSettingsDto(); advancedSettings.setIndexes(lookupList); SchemaHolder schema = new SchemaHolder(); schema.addEntity(entity, advancedSettings, fieldList); String generatedJson = mdsDataProviderBuilder.generateDataProvider(schema); assertEquals(json, generatedJson.replace("\r\n", "\n")); }
@Override public String generateDataProvider(SchemaHolder schemaHolder) { Map<String, Object> model = new HashMap<>(); model.put("schema", schemaHolder); StringWriter writer = new StringWriter(); VelocityEngineUtils.mergeTemplate(velocityEngine, MDS_TASK_DATA_PROVIDER, model, writer); return writer.toString(); }
MDSDataProviderBuilderImpl implements MDSDataProviderBuilder { @Override public String generateDataProvider(SchemaHolder schemaHolder) { Map<String, Object> model = new HashMap<>(); model.put("schema", schemaHolder); StringWriter writer = new StringWriter(); VelocityEngineUtils.mergeTemplate(velocityEngine, MDS_TASK_DATA_PROVIDER, model, writer); return writer.toString(); } }
MDSDataProviderBuilderImpl implements MDSDataProviderBuilder { @Override public String generateDataProvider(SchemaHolder schemaHolder) { Map<String, Object> model = new HashMap<>(); model.put("schema", schemaHolder); StringWriter writer = new StringWriter(); VelocityEngineUtils.mergeTemplate(velocityEngine, MDS_TASK_DATA_PROVIDER, model, writer); return writer.toString(); }  }
MDSDataProviderBuilderImpl implements MDSDataProviderBuilder { @Override public String generateDataProvider(SchemaHolder schemaHolder) { Map<String, Object> model = new HashMap<>(); model.put("schema", schemaHolder); StringWriter writer = new StringWriter(); VelocityEngineUtils.mergeTemplate(velocityEngine, MDS_TASK_DATA_PROVIDER, model, writer); return writer.toString(); }  @Override String generateDataProvider(SchemaHolder schemaHolder); @Resource(name = "mdsVelocityEngine") void setVelocityEngine(VelocityEngine velocityEngine); }
MDSDataProviderBuilderImpl implements MDSDataProviderBuilder { @Override public String generateDataProvider(SchemaHolder schemaHolder) { Map<String, Object> model = new HashMap<>(); model.put("schema", schemaHolder); StringWriter writer = new StringWriter(); VelocityEngineUtils.mergeTemplate(velocityEngine, MDS_TASK_DATA_PROVIDER, model, writer); return writer.toString(); }  @Override String generateDataProvider(SchemaHolder schemaHolder); @Resource(name = "mdsVelocityEngine") void setVelocityEngine(VelocityEngine velocityEngine);  }