Package ro.isdc.wro.model.resource

Examples of ro.isdc.wro.model.resource.Resource


    public void testProcess2() throws Exception {
        Reader reader = new StringReader("goog . provide  ('id');goog . require('id2'); console.log('hi')");
        StringWriter writer = new StringWriter();
        final StripGoogProcessor processor = new StripGoogProcessor();
        Resource resource = new Resource();
        resource.setMinimize(true);
        resource.setType(ResourceType.JS);
        resource.setUri("file://dir/file.js");
        processor.process(resource, reader, writer);

        assertEquals("console.log('hi')", writer.toString().trim());
    }
View Full Code Here


    public void testProcess3() throws Exception {
        Reader reader = new StringReader("goog . provide  ('id')\ngoog . require('id2')\n console.log('hi')");
        StringWriter writer = new StringWriter();
        final StripGoogProcessor processor = new StripGoogProcessor();
        Resource resource = new Resource();
        resource.setMinimize(true);
        resource.setType(ResourceType.JS);
        resource.setUri("file://dir/file.js");
        processor.process(resource, reader, writer);

        assertEquals("console.log('hi')", writer.toString().trim());
    }
View Full Code Here

    public void testProcess4() throws Exception {
        Reader reader = new StringReader("goog.provide('id');goog.require('id2'); goog.require('id2'); goog.require('id2'); \n" +
                                         "goog.require('id2'); \ngoog.require('id2'); goog.require('id2'); \n\nconsole.log('hi')");
        StringWriter writer = new StringWriter();
        final StripGoogProcessor processor = new StripGoogProcessor();
        Resource resource = new Resource();
        resource.setMinimize(true);
        resource.setType(ResourceType.JS);
        resource.setUri("file://dir/file.js");
        processor.process(resource, reader, writer);

        assertEquals("console.log('hi')", writer.toString().trim());
    }
View Full Code Here

public class ClosureDependencyUriLocatorTest {
    @Test
    public void testLocate() throws Exception {
        final ClosureDependencyUriLocator locator = new ClosureDependencyUriLocator();

        final Resource resource = new Resource();
        resource.setUri(ClosureDependencyUriLocator.URI_PREFIX + "/abc.js@@a");

        assertTrue(locator.accept(resource.getUri()));
        final String actual = IOUtils.toString(locator.locate(resource.getUri()));
        assertEquals("goog.addDependency('" + PATH_TO_WEBAPP_BASE_FROM_CLOSURE_BASE_JS_FILE + "/abc.js', ['a'], []);\n", actual);
    }
View Full Code Here

    @Test
    public void testLocate() throws Exception {
      Context.set(Context.standaloneContext());
        final TemplatesUriLocator locator = new TemplatesUriLocator();
        String path = TemplatesUriLocatorTest.class.getResource("/partials/").getFile();
        final Resource resource = new Resource();
        resource.setUri(TemplatesUriLocator.URI_PREFIX + path);

        assertTrue(locator.accept(resource.getUri()));
        final String actual = IOUtils.toString(locator.locate(resource.getUri()));
        assertEquals(String.format("$templateCache.put('%stemplate.html', '<html><div ng-class=\"test | \\'bold\\'\"></div></html>');","../.."+path.replace('\\','/')), actual);
    }
View Full Code Here

  }

  @Test
  public void shouldIdentifyChangeAfterDestroyOrForgetIsInvoked() {
    final String resourceUri = ClasspathUriLocator.createUri(getClass().getName().replace(".", "/") + ".class");
    final Resource resource = Resource.create(resourceUri, ResourceType.JS);
    assertEquals(true, victim.isResourceChanged(resource));
    victim.remember(resource);
    assertEquals(false, victim.isResourceChanged(resource));
    victim.forget(resource);
    assertEquals(true, victim.isResourceChanged(resource));
View Full Code Here

  @Test
  public void shouldReuseGroupNameMappingFileWithIncrementalBuild()
      throws Exception {
    final File groupNameMappingFile = WroUtil.createTempFile();

    final Resource g1Resource = spy(Resource.create("1.js"));
    try {
      final WroModel model = new WroModel();
      model.addGroup(new Group("g1").addResource(g1Resource));
      model.addGroup(new Group("g2").addResource(Resource.create("2.js")));
      victim = new Wro4jMojo() {
        @Override
        protected WroManagerFactory newWroManagerFactory()
            throws MojoExecutionException {
          final DefaultStandaloneContextAwareManagerFactory managerFactory = new DefaultStandaloneContextAwareManagerFactory();
          managerFactory.setUriLocatorFactory(WroTestUtils.createResourceMockingLocatorFactory());
          managerFactory.setModelFactory(WroTestUtils.simpleModelFactory(model));
          managerFactory.setNamingStrategy(new DefaultHashEncoderNamingStrategy());
          return managerFactory;
        }
      };
      setUpMojo(victim);

      victim.setGroupNameMappingFile(groupNameMappingFile);

      assertEquals(2, victim.getTargetGroupsAsList().size());
      victim.execute();

      // Now mark it as incremental
      when(mockBuildContext.isIncremental()).thenReturn(true);

      final Properties groupNames = new Properties();
      groupNames.load(new FileInputStream(groupNameMappingFile));
      assertEquals(4, groupNames.entrySet().size());

      // change the uri of the resource from group a (equivalent to changing its content).
      when(g1Resource.getUri()).thenReturn("1a.js");

      assertEquals(1, victim.getTargetGroupsAsList().size());
      victim.execute();

      groupNames.load(new FileInputStream(groupNameMappingFile));
View Full Code Here

        final String message = "Exception occured while processing: " + e.toString() + ", class: "
            + e.getClass().getName() + ",caused by: " + (e.getCause() != null ? e.getCause().getClass().getName() : "");
        getLog().error(message, e);
        if (e instanceof WroRuntimeException) {
          // Do not keep resources which cause the exception. This is helpful for linter processors.
          final Resource resource = ((WroRuntimeException) e).getResource();
          forgetResource(resource);
        }
        throw new MojoExecutionException(message, e);
      } finally {
        try {
View Full Code Here

    }

    private LessSource computeRelative(final Resource resource, final String relativePath) throws StringSourceException {
      try {
        final String relativeResourceUri = computeRelativeResourceUri(resource.getUri(), relativePath);
        final Resource relativeResource = Resource.create(relativeResourceUri, ResourceType.CSS);
        final String relativeResourceContent = IOUtils.toString(locatorFactory.locate(relativeResourceUri), "UTF-8");
        return new RelativeAwareLessSource(relativeResource, relativeResourceContent, locatorFactory);
      } catch (final IOException e) {
        LOG.error("Failed to compute relative resource: " + resource, e);
        throw new StringSourceException();
View Full Code Here

  }

  private void checkThatInclusionMatches(final String resourceUri, final String... patterns)
      throws IOException {
    victim = PathPatternProcessorDecorator.include(mockProcessor, patterns);
    final Resource resource = Resource.create(resourceUri, ResourceType.CSS);
    victim.process(resource, mockReader, mockWriter);
    Mockito.verify(mockProcessor, Mockito.times(1)).process(resource, mockReader, mockWriter);
    // reset for correct times computation
    Mockito.reset(mockProcessor);
  }
View Full Code Here

TOP

Related Classes of ro.isdc.wro.model.resource.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.