org.jboss.forge.addon.resource.Resource Java Examples

The following examples show how to use org.jboss.forge.addon.resource.Resource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FreemarkerClientPartialsLookupPropertyTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateEnumProperty() throws Exception {
    String enumProperty = "paymentType";
    Map<String, Object> root = createInspectionResultWrapper(ENTITY_NAME, ENUM_PROP);

    Resource<URL> templateResource = resourceFactory.create(getClass().getResource(Deployments.BASE_PACKAGE_PATH + Deployments.LOOKUP_PROPERTY_DETAIL_INCLUDE));
    Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
    String output = processor.process(root);
    Document html = Jsoup.parseBodyFragment(output);
    assertThat(output.trim(), not(equalTo("")));
    
    Elements container = html.select("div.form-group");
    assertThat(container, notNullValue());
    assertThat(container.attr("ng-class"), not(equalTo("")));
    
    Elements nToManyWidgetElement = html.select("div.form-group > div.col-sm-10");
    assertThat(nToManyWidgetElement, notNullValue());

    Elements selectElement = nToManyWidgetElement.select(" > select");
    assertThat(selectElement.attr("id"), equalTo(enumProperty));
    assertThat(selectElement.attr("ng-model"), equalTo(StringUtils.camelCase(ENTITY_NAME) + "." + enumProperty));
    String collectionElement = enumProperty.substring(0, 1);
    String optionsExpression = collectionElement +" for "+ collectionElement +" in " + enumProperty + "List";
    assertThat(selectElement.attr("ng-options"), equalTo(optionsExpression));
}
 
Example #2
Source File: AngularScaffoldProvider.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public List<Resource<?>> setup(ScaffoldSetupContext setupContext)
{
   setProject(setupContext.getProject());
   String targetDir = setupContext.getTargetDirectory();
   targetDir = (targetDir == null) ? "" : targetDir;

   // Setup static resources.
   ArrayList<Resource<?>> result = new ArrayList<>();
   WebResourcesFacet web = project.getFacet(WebResourcesFacet.class);
   ProcessingStrategy strategy = new CopyResourcesStrategy(web);
   for (ScaffoldResource scaffoldResource : getStatics(targetDir, strategy))
   {
      result.add(scaffoldResource.generate());
   }

   return result;
}
 
Example #3
Source File: DetailTemplateStrategy.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
private String processInclude(Map<String, Object> dataModel)
{
   Resource<?> resource = resourceFactory.create(getClass().getResource(
            SCAFFOLD_DIR + source));
   if (project.hasFacet(TemplateFacet.class))
   {
      TemplateFacet templates = project.getFacet(TemplateFacet.class);
      Resource<?> templateResource = templates.getResource(source);
      if (templateResource.exists())
      {
         resource = templateResource;
      }
   }

   Template template = templateFactory.create(resource, FreemarkerTemplate.class);
   String output = null;
   try
   {
      output = template.process(dataModel);
   }
   catch (IOException ioEx)
   {
      throw new IllegalStateException(ioEx);
   }
   return output;
}
 
Example #4
Source File: SearchTemplateStrategy.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Resource<?> execute(ScaffoldResource scaffoldResource)
{
   List<Map<String, String>> properties = (List<Map<String, String>>) dataModel.get("properties");
   StringBuilder searchFormProperties = new StringBuilder();
   for (Map<String, String> property : properties)
   {
      dataModel.put("property", property);
      Include includeFile = new Include(SEARCH_FORM_INPUT);
      String output = includeFile.processInclude(dataModel);
      searchFormProperties.append(output).append('\n');
   }
   Include searchResultsInclude = new Include(SEARCH_RESULTS);
   Include searchResultsPaginatorInclude = new Include(SEARCH_RESULTS_PAGINATOR);
   String searchResults = searchResultsInclude.processInclude(dataModel);
   String searchResultsPaginator = searchResultsPaginatorInclude.processInclude(dataModel);
   dataModel.put("searchFormProperties", searchFormProperties.toString());
   dataModel.put("searchResults", searchResults);
   dataModel.put("searchResultsPaginator", searchResultsPaginator);
   ProcessTemplateStrategy strategy = new ProcessTemplateStrategy(web, resourceFactory, project,
            templateFactory, dataModel);
   return strategy.execute(scaffoldResource);
}
 
Example #5
Source File: SearchTemplateStrategy.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
private String processInclude(Map<String, Object> dataModel)
{
   Resource<?> resource = resourceFactory.create(getClass().getResource(
            SCAFFOLD_DIR + source));
   if (project.hasFacet(TemplateFacet.class))
   {
      TemplateFacet templates = project.getFacet(TemplateFacet.class);
      Resource<?> templateResource = templates.getResource(source);
      if (templateResource.exists())
      {
         resource = templateResource;
      }
   }

   Template template = templateFactory.create(resource, FreemarkerTemplate.class);
   String output = null;
   try
   {
      output = template.process(dataModel);
   }
   catch (IOException ioEx)
   {
      throw new IllegalStateException(ioEx);
   }
   return output;
}
 
Example #6
Source File: FreemarkerClientPartialsSearchResultsPaginatorTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateSearchResultsPaginator() throws Exception
{
   Map<String, String> idProperties = new HashMap<String, String>();
   idProperties.put("name", "id");
   idProperties.put("hidden", "true");
   idProperties.put("type", "number");

   Map<String, Object> root = new HashMap<String, Object>();
   root.put("entityName", "SampleEntity");
   root.put("property", idProperties);
   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.SEARCH_RESULTS_PAGINATOR_INCLUDE));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   assertThat(output, IsEqual.equalTo(PAGINATOR_OUTPUT));
}
 
Example #7
Source File: FreemarkerClientPartialsBasicPropertyTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateBasicStringPropertyWithMaxlength() throws Exception
{
   Map<String, Object> root = createInspectionResultWrapper(ENTITY_NAME, STRING_PROP_WITH_MAX_LEN);

   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.BASIC_PROPERTY_DETAIL_INCLUDE));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements container = html.select("div.form-group");
   assertThat(container, notNullValue());
   assertThat(container.attr("ng-class"), not(equalTo("")));

   Elements formInputElement = html.select("div.form-group input");
   assertThat(formInputElement.attr("id"), equalTo("fullName"));
   assertThat(formInputElement.attr("type"), equalTo("text"));
   assertThat(formInputElement.attr("ng-model"), equalTo(StringUtils.camelCase(ENTITY_NAME) + "." + "fullName"));
   assertThat(formInputElement.attr("ng-maxlength"), equalTo("100"));
}
 
Example #8
Source File: FreemarkerClientPartialsBasicPropertyTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateBasicStringPropertyWithMinlength() throws Exception
{
   Map<String, Object> root = createInspectionResultWrapper(ENTITY_NAME, STRING_PROP_WITH_MIN_LEN);

   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.BASIC_PROPERTY_DETAIL_INCLUDE));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements container = html.select("div.form-group");
   assertThat(container, notNullValue());
   assertThat(container.attr("ng-class"), not(equalTo("")));

   Elements formInputElement = html.select("div.form-group input");
   assertThat(formInputElement.attr("id"), equalTo("fullName"));
   assertThat(formInputElement.attr("type"), equalTo("text"));
   assertThat(formInputElement.attr("ng-model"), equalTo(StringUtils.camelCase(ENTITY_NAME) + "." + "fullName"));
   assertThat(formInputElement.attr("ng-minlength"), equalTo("5"));
}
 
Example #9
Source File: FreemarkerClientPartialsBasicPropertyTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateBasicNumberProperty() throws Exception
{
   Map<String, Object> root = createInspectionResultWrapper(ENTITY_NAME, NUMBER_PROP);

   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.BASIC_PROPERTY_DETAIL_INCLUDE));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements container = html.select("div.form-group");
   assertThat(container, notNullValue());
   assertThat(container.attr("ng-class"), not(equalTo("")));

   Elements formInputElement = html.select("div.form-group input");
   assertThat(formInputElement.attr("id"), equalTo("score"));
   assertThat(formInputElement.attr("type"), equalTo("number"));
   assertThat(formInputElement.attr("ng-model"), equalTo(StringUtils.camelCase(ENTITY_NAME) + "." + "score"));
}
 
Example #10
Source File: FreemarkerClientPartialsBasicPropertyTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateBasicNumberPropertyWithMinConstraint() throws Exception
{
   Map<String, Object> root = createInspectionResultWrapper(ENTITY_NAME, NUMBER_PROP_WITH_MIN_VAL);

   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.BASIC_PROPERTY_DETAIL_INCLUDE));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements container = html.select("div.form-group");
   assertThat(container, notNullValue());
   assertThat(container.attr("ng-class"), not(equalTo("")));

   Elements formInputElement = html.select("div.form-group input");
   assertThat(formInputElement.attr("id"), equalTo("score"));
   assertThat(formInputElement.attr("type"), equalTo("number"));
   assertThat(formInputElement.attr("min"), equalTo("0"));
   assertThat(formInputElement.attr("ng-model"), equalTo(StringUtils.camelCase(ENTITY_NAME) + "." + "score"));
}
 
Example #11
Source File: FreemarkerClientPartialsBasicPropertyTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateBasicNumberPropertyWithMaxConstraint() throws Exception
{
   Map<String, Object> root = createInspectionResultWrapper(ENTITY_NAME, NUMBER_PROP_WITH_MAX_VAL);

   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.BASIC_PROPERTY_DETAIL_INCLUDE));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements container = html.select("div.form-group");
   assertThat(container, notNullValue());
   assertThat(container.attr("ng-class"), not(equalTo("")));

   Elements formInputElement = html.select("div.form-group input");
   assertThat(formInputElement.attr("id"), equalTo("score"));
   assertThat(formInputElement.attr("type"), equalTo("number"));
   assertThat(formInputElement.attr("max"), equalTo("100"));
   assertThat(formInputElement.attr("ng-model"), equalTo(StringUtils.camelCase(ENTITY_NAME) + "." + "score"));
}
 
Example #12
Source File: FreemarkerClientPartialsBasicPropertyTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateBasicDateProperty() throws Exception
{
   Map<String, Object> root = createInspectionResultWrapper(ENTITY_NAME, DATE_PROP);

   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.BASIC_PROPERTY_DETAIL_INCLUDE));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements container = html.select("div.form-group");
   assertThat(container, notNullValue());
   assertThat(container.attr("ng-class"), not(equalTo("")));

   Elements formInputElement = html.select("div.form-group date");
   assertThat(formInputElement.attr("id"), equalTo("dateOfBirth"));
   assertThat(formInputElement.attr("ng-model"), equalTo(StringUtils.camelCase(ENTITY_NAME) + "." + "dateOfBirth"));
}
 
Example #13
Source File: FreemarkerClientPartialsBasicPropertyTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateBasicTimeProperty() throws Exception
{
   Map<String, Object> root = createInspectionResultWrapper(ENTITY_NAME, TIME_PROP);

   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.BASIC_PROPERTY_DETAIL_INCLUDE));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements container = html.select("div.form-group");
   assertThat(container, notNullValue());
   assertThat(container.attr("ng-class"), not(equalTo("")));

   Elements formInputElement = html.select("div.form-group time");
   assertThat(formInputElement.attr("id"), equalTo("alarmTime"));
   assertThat(formInputElement.attr("ng-model"), equalTo(StringUtils.camelCase(ENTITY_NAME) + "." + "alarmTime"));
}
 
Example #14
Source File: FreemarkerClientPartialsBasicPropertyTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateBasicBooleanProperty() throws Exception
{
   Map<String, Object> root = createInspectionResultWrapper(ENTITY_NAME, BOOLEAN_PROP);

   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.BASIC_PROPERTY_DETAIL_INCLUDE));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements container = html.select("div.form-group");
   assertThat(container, notNullValue());
   assertThat(container.attr("ng-class"), not(equalTo("")));

   Elements formInputElement = html.select("div.form-group input");
   assertThat(formInputElement.attr("id"), equalTo("optForMail"));
   assertThat(formInputElement.attr("type"), equalTo("checkbox"));
   assertThat(formInputElement.attr("ng-model"), equalTo(StringUtils.camelCase(ENTITY_NAME) + "." + "optForMail"));
}
 
Example #15
Source File: FreemarkerClientPartialsBasicPropertyTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateBasicStringProperty() throws Exception
{
   Map<String, Object> root = createInspectionResultWrapper(ENTITY_NAME, BASIC_STRING_PROP);

   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.BASIC_PROPERTY_DETAIL_INCLUDE));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements container = html.select("div.form-group");
   assertThat(container, notNullValue());
   assertThat(container.attr("ng-class"), not(equalTo("")));

   Elements formInputElement = html.select("div.form-group input");
   assertThat(formInputElement.attr("id"), equalTo("fullName"));
   assertThat(formInputElement.attr("type"), equalTo("text"));
   assertThat(formInputElement.attr("ng-model"), equalTo(StringUtils.camelCase(ENTITY_NAME) + "." + "fullName"));
}
 
Example #16
Source File: FreemarkerClientPartialsSearchInputTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateManyToOneProperty() throws Exception {
    Map<String, Object> root = TestHelpers.createInspectionResultWrapper(ENTITY_NAME, MANY_TO_ONE_PROP);

    Resource<URL> templateResource = resourceFactory.create(getClass().getResource(Deployments.BASE_PACKAGE_PATH + Deployments.SEARCH_FORM_INPUT));
    Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
    String output = processor.process(root);
    Document html = Jsoup.parseBodyFragment(output);
    assertThat(output.trim(), not(equalTo("")));

    Elements container = html.select("div.form-group");
    assertThat(container, notNullValue());

    Elements formInputElement = container.select("div.col-sm-10 > select");
    assertThat(formInputElement.attr("id"), equalTo("customer"));
    assertThat(formInputElement.attr("ng-model"), equalTo("search" + "." + "customer"));
}
 
Example #17
Source File: FreemarkerClientPartialsSearchInputTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateOneToOneProperty() throws Exception {
    Map<String, Object> root = TestHelpers.createInspectionResultWrapper(ENTITY_NAME, ONE_TO_ONE_PROP);

    Resource<URL> templateResource = resourceFactory.create(getClass().getResource(Deployments.BASE_PACKAGE_PATH + Deployments.SEARCH_FORM_INPUT));
    Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
    String output = processor.process(root);
    Document html = Jsoup.parseBodyFragment(output);
    assertThat(output.trim(), not(equalTo("")));

    Elements container = html.select("div.form-group");
    assertThat(container, notNullValue());

    Elements formInputElement = container.select("div.col-sm-10 > select");
    assertThat(formInputElement.attr("id"), equalTo("voucher"));
    assertThat(formInputElement.attr("ng-model"), equalTo("search" + "." + "voucher"));
}
 
Example #18
Source File: FreemarkerClientPartialsSearchInputTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateBasicDateProperty() throws Exception {
    Map<String, Object> root = TestHelpers.createInspectionResultWrapper(ENTITY_NAME, DATE_PROP);

    Resource<URL> templateResource = resourceFactory.create(getClass().getResource(Deployments.BASE_PACKAGE_PATH + Deployments.SEARCH_FORM_INPUT));
    Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
    String output = processor.process(root);
    Document html = Jsoup.parseBodyFragment(output);
    assertThat(output.trim(), not(equalTo("")));

    Elements container = html.select("div.form-group");
    assertThat(container, notNullValue());

    Elements formInputElement = container.select("div.col-sm-10 > input");
    assertThat(formInputElement.attr("id"), equalTo("dateOfBirth"));
    assertThat(formInputElement.attr("type"), equalTo("text"));
    assertThat(formInputElement.attr("ng-model"), equalTo("search" + "." + "dateOfBirth"));
}
 
Example #19
Source File: FreemarkerClientPartialsSearchInputTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateBasicBooleanProperty() throws Exception {
    Map<String, Object> root = TestHelpers.createInspectionResultWrapper(ENTITY_NAME, BOOLEAN_PROP);

    Resource<URL> templateResource = resourceFactory.create(getClass().getResource(Deployments.BASE_PACKAGE_PATH + Deployments.SEARCH_FORM_INPUT));
    Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
    String output = processor.process(root);
    Document html = Jsoup.parseBodyFragment(output);
    assertThat(output.trim(), not(equalTo("")));

    Elements container = html.select("div.form-group");
    assertThat(container, notNullValue());

    Elements formInputElement = container.select("div.col-sm-10 > select");
    assertThat(formInputElement.attr("id"), equalTo("optForMail"));
    assertThat(formInputElement.attr("ng-model"), equalTo("search" + "." + "optForMail"));
}
 
Example #20
Source File: FreemarkerClientPartialsSearchInputTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateBasicNumberProperty() throws Exception {
    Map<String, Object> root = TestHelpers.createInspectionResultWrapper(ENTITY_NAME, NUMBER_PROP);

    Resource<URL> templateResource = resourceFactory.create(getClass().getResource(Deployments.BASE_PACKAGE_PATH + Deployments.SEARCH_FORM_INPUT));
    Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
    String output = processor.process(root);
    Document html = Jsoup.parseBodyFragment(output);
    assertThat(output.trim(), not(equalTo("")));

    Elements container = html.select("div.form-group");
    assertThat(container, notNullValue());

    Elements formInputElement = container.select("div.col-sm-10 > input");
    assertThat(formInputElement.attr("id"), equalTo("score"));
    assertThat(formInputElement.attr("type"), equalTo("text"));
    assertThat(formInputElement.attr("ng-model"), equalTo("search" + "." + "score"));
}
 
Example #21
Source File: FreemarkerClientPartialsSearchInputTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateBasicStringProperty() throws Exception {
    Map<String, Object> root = TestHelpers.createInspectionResultWrapper(ENTITY_NAME, BASIC_STRING_PROP);

    Resource<URL> templateResource = resourceFactory.create(getClass().getResource(Deployments.BASE_PACKAGE_PATH + Deployments.SEARCH_FORM_INPUT));
    Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
    String output = processor.process(root);
    Document html = Jsoup.parseBodyFragment(output);
    assertThat(output.trim(), not(equalTo("")));

    Elements container = html.select("div.form-group");
    assertThat(container, notNullValue());

    Elements formInputElement = container.select("div.col-sm-10 > input");
    assertThat(formInputElement.attr("id"), equalTo("fullName"));
    assertThat(formInputElement.attr("type"), equalTo("text"));
    assertThat(formInputElement.attr("ng-model"), equalTo("search" + "." + "fullName"));
}
 
Example #22
Source File: FreemarkerClientPartialsNToOnePropertyTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateHiddenAndRequiredProperty() throws Exception
{
   Map<String, String> idProperties = new HashMap<String, String>();
   idProperties.put("name", "id");
   idProperties.put("identifier", "id");
   idProperties.put("label", "Id");
   idProperties.put("hidden", "true");
   idProperties.put("required", "true");
   idProperties.put("type", "number");

   Map<String, Object> root = new HashMap<String, Object>();
   root.put("entityName", "SampleEntity");
   root.put("property", idProperties);
   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.N_TO_ONE_PROPERTY_DETAIL_INCLUDE));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   assertThat(output.trim(), IsEqual.equalTo(""));
}
 
Example #23
Source File: FreemarkerClientPartialsNToOnePropertyTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateHiddenProperty() throws Exception
{
   Map<String, String> idProperties = new HashMap<String, String>();
   idProperties.put("name", "id");
   idProperties.put("identifier", "id");
   idProperties.put("label", "Id");
   idProperties.put("hidden", "true");
   idProperties.put("type", "number");

   Map<String, Object> root = new HashMap<String, Object>();
   root.put("entityName", "SampleEntity");
   root.put("property", idProperties);
   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.N_TO_ONE_PROPERTY_DETAIL_INCLUDE));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   assertThat(output.trim(), IsEqual.equalTo(""));
}
 
Example #24
Source File: FreemarkerClientPartialsSearchResultsTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateHiddenAndRequiredProperty() throws Exception
{
   Map<String, String> idProperties = new HashMap<String, String>();
   idProperties.put("name", "id");
   idProperties.put("hidden", "true");
   idProperties.put("required", "true");
   idProperties.put("type", "number");

   List<Map<String, ? extends Object>> properties = new ArrayList<Map<String, ? extends Object>>();
   properties.add(idProperties);

   Map<String, Object> root = new HashMap<String, Object>();
   root.put("entityName", "SampleEntity");
   root.put("properties", properties);
   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.SEARCH_RESULTS));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements headers = html.select("table > thead > tr > th");
   assertThat(0, equalTo(headers.size()));
}
 
Example #25
Source File: FreemarkerClientPartialsSearchResultsTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateHiddenProperty() throws Exception
{
   Map<String, String> idProperties = new HashMap<String, String>();
   idProperties.put("name", "id");
   idProperties.put("hidden", "true");
   idProperties.put("type", "number");

   List<Map<String, ? extends Object>> properties = new ArrayList<Map<String, ? extends Object>>();
   properties.add(idProperties);

   Map<String, Object> root = new HashMap<String, Object>();
   root.put("entityName", "SampleEntity");
   root.put("properties", properties);
   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.SEARCH_RESULTS));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements headers = html.select("table > thead > tr > th");
   assertThat(0, equalTo(headers.size()));
}
 
Example #26
Source File: FreemarkerClientPartialsBasicPropertyTest.java    From angularjs-addon with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGenerateBasicDatetimeProperty() throws Exception
{
   Map<String, Object> root = createInspectionResultWrapper(ENTITY_NAME, DATETIME_PROP);
   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.BASIC_PROPERTY_DETAIL_INCLUDE));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements container = html.select("div.form-group");
   assertThat(container, notNullValue());
   assertThat(container.attr("ng-class"), not(equalTo("")));

   Elements formInputElement = html.select("div.form-group datetime");
   assertThat(formInputElement.attr("id"), equalTo("auditTimestamp"));
   assertThat(formInputElement.attr("ng-model"),
            equalTo(StringUtils.camelCase(ENTITY_NAME) + "." + "auditTimestamp"));
}
 
Example #27
Source File: FreemarkerClientPartialsSearchResultsTest.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testGenerateBasicStringProperty() throws Exception
{
   Map<String, String> nameProperties = new HashMap<String, String>();
   String basicStringProperty = "fullName";
   nameProperties.put("name", basicStringProperty);
   nameProperties.put("label", StringUtils.uncamelCase(basicStringProperty));
   nameProperties.put("type", "java.lang.String");

   List<Map<String, ? extends Object>> properties = new ArrayList<Map<String, ? extends Object>>();
   properties.add(nameProperties);

   Map<String, Object> root = new HashMap<String, Object>();
   root.put("entityName", "SampleEntity");
   root.put("pluralizedEntityName", "SampleEntities");
   root.put("entityId", basicStringProperty);
   root.put("properties", properties);
   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.SEARCH_RESULTS));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements headers = html.select("table > thead > tr > th");
   assertThat(headers.size(), equalTo(1));
   assertThat(headers.text(), equalTo("Full Name"));

   Elements resultRows = html.select("table > tbody > tr");
   assertThat(resultRows.attr("ng-repeat"), containsString("result in filteredResults"));

   Elements resultCells = resultRows.select(" > td");
   assertThat(resultCells.size(), equalTo(1));
   assertThat(resultCells.select("a").attr("href"), equalTo("#/" + "SampleEntities" + "/edit/{{result.fullName}}"));
   assertThat(resultCells.select("a").text(), equalTo("{{result.fullName}}"));
}
 
Example #28
Source File: FreemarkerClientPartialsSearchResultsTest.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testGenerateManyToManyProperty() throws Exception
{
   Map<String, String> usersProperties = new HashMap<String, String>();
   String manyToManyProperty = "users";
   usersProperties.put("name", manyToManyProperty);
   usersProperties.put("type", "java.lang.String");
   usersProperties.put("n-to-many", "true");
   usersProperties.put("parameterized-type", "com.example.scaffoldtester.model.UserIdentity");
   usersProperties.put("type", "java.util.Set");
   usersProperties.put("simpleType", "UserIdentity");

   List<Map<String, ? extends Object>> properties = new ArrayList<Map<String, ? extends Object>>();
   properties.add(usersProperties);

   Map<String, Object> root = new HashMap<String, Object>();
   root.put("entityName", "SampleEntity");
   root.put("properties", properties);
   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.SEARCH_RESULTS));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements headers = html.select("table > thead > tr > th");
   assertThat(0, equalTo(headers.size()));
}
 
Example #29
Source File: FreemarkerClientPartialsSearchResultsTest.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testGenerateBasicDateProperty() throws Exception
{
   Map<String, String> dateOfBirthProperties = new HashMap<String, String>();
   String basicDateProperty = "dateOfBirth";
   dateOfBirthProperties.put("name", basicDateProperty);
   dateOfBirthProperties.put("label", StringUtils.uncamelCase(basicDateProperty));
   dateOfBirthProperties.put("type", "java.util.Date");
   dateOfBirthProperties.put("datetime-type", "date");

   List<Map<String, ? extends Object>> properties = new ArrayList<Map<String, ? extends Object>>();
   properties.add(dateOfBirthProperties);

   Map<String, Object> root = new HashMap<String, Object>();
   root.put("entityName", "SampleEntity");
   root.put("pluralizedEntityName", "SampleEntities");
   root.put("entityId", basicDateProperty);
   root.put("properties", properties);
   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.SEARCH_RESULTS));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements headers = html.select("table > thead > tr > th");
   assertThat(headers.size(), equalTo(1));
   assertThat(headers.text(), equalTo("Date Of Birth"));

   Elements resultRows = html.select("table > tbody > tr");
   assertThat(resultRows.attr("ng-repeat"), containsString("result in filteredResults"));

   Elements resultCells = resultRows.select(" > td");
   assertThat(resultCells.size(), equalTo(1));
   assertThat(resultCells.select("a").attr("href"),
            equalTo("#/" + "SampleEntities" + "/edit/{{result.dateOfBirth}}"));
   assertThat(resultCells.select("a").text(), equalTo("{{result.dateOfBirth| date:'mediumDate'}}"));
}
 
Example #30
Source File: FreemarkerClientPartialsSearchResultsTest.java    From angularjs-addon with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testGenerateOneToOneProperty() throws Exception
{
   Map<String, String> voucherProperties = new HashMap<String, String>();
   String oneToOneProperty = "voucher";
   voucherProperties.put("name", oneToOneProperty);
   voucherProperties.put("label", StringUtils.uncamelCase(oneToOneProperty));
   voucherProperties.put("type", "com.example.scaffoldtester.model.DiscountVoucher");
   voucherProperties.put("one-to-one", "true");
   voucherProperties.put("simpleType", "DiscountVoucher");
   voucherProperties.put("optionLabel", "id");

   List<Map<String, ? extends Object>> properties = new ArrayList<Map<String, ? extends Object>>();
   properties.add(voucherProperties);

   Map<String, Object> root = new HashMap<String, Object>();
   root.put("entityName", "SampleEntity");
   root.put("pluralizedEntityName", "SampleEntities");
   root.put("entityId", oneToOneProperty);
   root.put("properties", properties);
   Resource<URL> templateResource = resourceFactory.create(getClass().getResource(
            Deployments.BASE_PACKAGE_PATH + Deployments.SEARCH_RESULTS));
   Template processor = processorFactory.create(templateResource, FreemarkerTemplate.class);
   String output = processor.process(root);
   Document html = Jsoup.parseBodyFragment(output);
   assertThat(output.trim(), not(equalTo("")));

   Elements headers = html.select("table > thead > tr > th");
   assertThat(headers.size(), equalTo(1));
   assertThat(headers.text(), equalTo("Voucher"));

   Elements resultRows = html.select("table > tbody > tr");
   assertThat(resultRows.attr("ng-repeat"), containsString("result in filteredResults"));

   Elements resultCells = resultRows.select(" > td");
   assertThat(resultCells.size(), equalTo(1));
   assertThat(resultCells.select("a").attr("href"), equalTo("#/" + "SampleEntities" + "/edit/{{result.voucher}}"));
   assertThat(resultCells.select("a").text(), equalTo("{{result.voucher.id}}"));
}