Пример #1
0
 /**
  * Parse the document and creates the model.
  *
  * @param document to parse.
  * @return {@link WroModel} object.
  */
 private WroModel createModel() {
   final WroModel model = new WroModel();
   final Set<Group> groups = new HashSet<Group>();
   for (final Element element : allGroupElements.values()) {
     parseGroup(element, groups);
   }
   model.setGroups(groups);
   return model;
 }
Пример #2
0
 /**
  * Test the usecase when the resource has no type. For now, it is ok to have it null because
  * you'll get a NPE exception during processing if no type is specified anyway.
  */
 @Test
 public void createIncompleteModel() {
   factory =
       new JsonModelFactory() {
         @Override
         protected InputStream getModelResourceAsStream() throws IOException {
           return getClass().getResourceAsStream("incomplete-wro.json");
         };
       };
   final WroModel model = factory.create();
   Assert.assertNotNull(model);
   Assert.assertEquals(1, model.getGroups().size());
   final Group group = new ArrayList<Group>(model.getGroups()).get(0);
   Assert.assertNull(group.getResources().get(0).getType());
   LOG.debug("model: {}", model);
 }
Пример #3
0
  private void processImports(final Document document, final WroModel model) {
    final NodeList importsList = document.getElementsByTagName(TAG_IMPORT);
    LOG.debug("number of imports: {}", importsList.getLength());
    for (int i = 0; i < importsList.getLength(); i++) {
      final Element element = (Element) importsList.item(i);
      final String name = element.getTextContent();
      LOG.debug("processing import: {}", name);
      LOG.debug("processImports#uriLocatorFactory: {}", uriLocatorFactory);
      final XmlModelFactory importedModelFactory =
          new XmlModelFactory() {
            @Override
            protected InputStream getModelResourceAsStream() throws IOException {
              LOG.debug("build model from import: {}", name);
              LOG.debug("uriLocatorFactory: {}", uriLocatorFactory);
              return uriLocatorFactory.locate(name);
            };
          };
      // pass the reference of the uriLocatorFactory to the anonymously created factory.
      importedModelFactory.uriLocatorFactory = this.uriLocatorFactory;
      if (processedImports.contains(name)) {
        final String message = "Recursive import detected: " + name;
        LOG.error(message);
        throw new RecursiveGroupDefinitionException(message);
      }

      processedImports.add(name);
      importedModelFactory.processedImports.addAll(this.processedImports);
      model.merge(importedModelFactory.create());
    }
  }
Пример #4
0
  @Test(expected = WroRuntimeException.class)
  public void shouldNotProcessGroupWithNoResources() throws Exception {
    final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    final HttpServletResponse response = Context.get().getResponse();
    Mockito.when(request.getRequestURI()).thenReturn("/noResources.css");

    WroConfiguration config = new WroConfiguration();
    config.setIgnoreEmptyGroup(false);
    Context.set(Context.webContext(request, response, Mockito.mock(FilterConfig.class)), config);

    WroModel model = new WroModel();
    model.addGroup(new Group("noResources"));
    WroManagerFactory managerFactory =
        new BaseWroManagerFactory().setModelFactory(WroUtil.factoryFor(model));
    managerFactory = new InjectableWroManagerFactoryDecorator(managerFactory);
    managerFactory.create().process();
  }