Search in sources :

Example 6 with ClassLoaderWriter

use of org.apache.sling.commons.classloader.ClassLoaderWriter in project sling by apache.

the class SightlyScriptEngineFactoryTest method testActivateOverPreviousVersion.

@Test
public void testActivateOverPreviousVersion() {
    SightlyScriptEngineFactory scriptEngineFactory = new SightlyScriptEngineFactory();
    ClassLoaderWriter classLoaderWriter = mock(ClassLoaderWriter.class);
    try {
        when(classLoaderWriter.getInputStream(SightlyScriptEngineFactory.SIGHTLY_CONFIG_FILE)).thenReturn(IOUtils.toInputStream("1.0.16", "UTF-8"));
    } catch (IOException e) {
        fail("IOException while setting tests.");
    }
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    when(classLoaderWriter.getOutputStream(SightlyScriptEngineFactory.SIGHTLY_CONFIG_FILE)).thenReturn(outputStream);
    when(classLoaderWriter.delete(sightlyEngineConfiguration.getScratchFolder())).thenReturn(true);
    Whitebox.setInternalState(scriptEngineFactory, "classLoaderWriter", classLoaderWriter);
    Whitebox.setInternalState(scriptEngineFactory, "sightlyEngineConfiguration", sightlyEngineConfiguration);
    scriptEngineFactory.activate();
    verify(classLoaderWriter).delete(sightlyEngineConfiguration.getScratchFolder());
    assertEquals("1.0.17-SNAPSHOT", outputStream.toString());
}
Also used : ClassLoaderWriter(org.apache.sling.commons.classloader.ClassLoaderWriter) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

ClassLoaderWriter (org.apache.sling.commons.classloader.ClassLoaderWriter)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 JavaCompiler (org.apache.sling.commons.compiler.JavaCompiler)2 File (java.io.File)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 JarFile (java.util.jar.JarFile)1 CompilationUnit (org.apache.sling.commons.compiler.CompilationUnit)1 Options (org.apache.sling.commons.compiler.Options)1 EclipseJavaCompiler (org.apache.sling.commons.compiler.impl.EclipseJavaCompiler)1 IOProvider (org.apache.sling.scripting.jsp.jasper.IOProvider)1 JspConfig (org.apache.sling.scripting.jsp.jasper.compiler.JspConfig)1 JspRuntimeContext (org.apache.sling.scripting.jsp.jasper.compiler.JspRuntimeContext)1 TagPluginManager (org.apache.sling.scripting.jsp.jasper.compiler.TagPluginManager)1 ResourceBackedPojoChangeMonitor (org.apache.sling.scripting.sightly.impl.engine.ResourceBackedPojoChangeMonitor)1 SightlyEngineConfiguration (org.apache.sling.scripting.sightly.impl.engine.SightlyEngineConfiguration)1 SightlyJavaCompilerService (org.apache.sling.scripting.sightly.impl.engine.SightlyJavaCompilerService)1 ICompilationUnit (org.eclipse.jdt.internal.compiler.env.ICompilationUnit)1