Search in sources :

Example 46 with Application

use of com.enonic.xp.app.Application in project xp by enonic.

the class ApplicationImplTest method testApplication.

@Test
public void testApplication() throws Exception {
    final Bundle bundle = deployBundle();
    final ApplicationUrlResolver urlResolver = Mockito.mock(ApplicationUrlResolver.class);
    final Application application = new ApplicationBuilder().bundle(bundle).urlResolver(urlResolver).build();
    assertEquals("myapplication", application.getKey().toString());
    assertEquals("1.0.0", application.getVersion().toString());
    assertEquals("myapplication", application.getDisplayName());
    assertEquals("http://enonic.com/path/to/application", application.getUrl());
    assertEquals("Enonic AS", application.getVendorName());
    assertEquals("http://enonic.com", application.getVendorUrl());
    assertEquals(bundle, application.getBundle());
    assertTrue(application.getModifiedTime().getEpochSecond() > 0);
    assertFalse(application.isStarted());
    assertTrue(ApplicationBundleUtils.isApplication(bundle));
    assertNotNull(application.getClassLoader());
    assertEquals("[1.2.0,2.0.0)", application.getSystemVersion());
    assertEquals("2.0.0", application.getMaxSystemVersion());
    assertEquals("1.2.0", application.getMinSystemVersion());
    application.getFiles();
    Mockito.verify(urlResolver, Mockito.times(1)).findFiles();
    application.resolveFile("a/b.txt");
    Mockito.verify(urlResolver, Mockito.times(1)).findUrl("a/b.txt");
    bundle.start();
    assertTrue(application.isStarted());
}
Also used : ApplicationUrlResolver(com.enonic.xp.core.impl.app.resolver.ApplicationUrlResolver) Bundle(org.osgi.framework.Bundle) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Example 47 with Application

use of com.enonic.xp.app.Application in project xp by enonic.

the class XDataServiceImpl method getAll.

@Override
public XDatas getAll() {
    final Set<XData> list = new LinkedHashSet<>(this.builtInTypes.getAll().getList());
    for (final Application application : this.applicationService.getInstalledApplications()) {
        final XDatas types = getByApplication(application.getKey());
        list.addAll(types.getList());
    }
    return XDatas.from(list);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) XDatas(com.enonic.xp.schema.xdata.XDatas) XData(com.enonic.xp.schema.xdata.XData) Application(com.enonic.xp.app.Application)

Example 48 with Application

use of com.enonic.xp.app.Application in project xp by enonic.

the class MainExecutorTest method mainJsError.

@Test
public void mainJsError() {
    final ResourceKey key = ResourceKey.from("foo.bar:/main.js");
    when(this.scriptService.hasScript(key)).thenReturn(true);
    when(this.scriptService.executeAsync(key)).thenReturn(CompletableFuture.failedFuture(new RuntimeException()));
    final Application app = mock(Application.class);
    when(app.getKey()).thenReturn(ApplicationKey.from("foo.bar"));
    this.executor.activated(app);
}
Also used : Application(com.enonic.xp.app.Application) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 49 with Application

use of com.enonic.xp.app.Application in project xp by enonic.

the class MainExecutorTest method mainJsMissing.

@Test
public void mainJsMissing() {
    final Application app = mock(Application.class);
    when(app.getKey()).thenReturn(ApplicationKey.from("foo.bar"));
    this.executor.activated(app);
    verify(this.scriptService, times(1)).hasScript(any());
    verify(this.scriptService, times(0)).execute(any());
}
Also used : Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Example 50 with Application

use of com.enonic.xp.app.Application in project xp by enonic.

the class SseEntryPointTest method testSubscribe.

@Test
public void testSubscribe() {
    listener.setSse(sse);
    final SseEventSink eventSink = mock(SseEventSink.class);
    doNothing().when(broadcaster).register(eventSink);
    final Application application = mock(Application.class);
    when(application.getKey()).thenReturn(ApplicationKey.from("appKey"));
    when(application.getVersion()).thenReturn(Version.emptyVersion);
    final Applications applications = Applications.from(application);
    when(applicationService.getInstalledApplications()).thenReturn(applications);
    when(applicationService.isLocalApplication(any(ApplicationKey.class))).thenReturn(false);
    final ArgumentCaptor<ListApplicationJson> listApplicationCaptor = ArgumentCaptor.forClass(ListApplicationJson.class);
    listener.subscribe(eventSink);
    verify(broadcaster, times(1)).register(eventSink);
    verify(sse, times(1)).newEventBuilder();
    verify(eventBuilder).data(eq(ListApplicationJson.class), listApplicationCaptor.capture());
    verify(applicationService, times(1)).getInstalledApplications();
    verify(applicationService, times(1)).isLocalApplication(any(ApplicationKey.class));
    final List<ApplicationInfoJson> actualApplications = listApplicationCaptor.getValue().getApplications();
    assertNotNull(actualApplications);
    assertFalse(actualApplications.isEmpty());
    assertEquals("appKey", actualApplications.get(0).getKey());
    assertFalse(actualApplications.get(0).getLocal());
}
Also used : ApplicationInfoJson(com.enonic.xp.impl.server.rest.model.ApplicationInfoJson) ApplicationKey(com.enonic.xp.app.ApplicationKey) ListApplicationJson(com.enonic.xp.impl.server.rest.model.ListApplicationJson) Applications(com.enonic.xp.app.Applications) SseEventSink(javax.ws.rs.sse.SseEventSink) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Aggregations

Application (com.enonic.xp.app.Application)68 Test (org.junit.jupiter.api.Test)42 ApplicationKey (com.enonic.xp.app.ApplicationKey)20 Node (com.enonic.xp.node.Node)16 Bundle (org.osgi.framework.Bundle)16 ByteSource (com.google.common.io.ByteSource)12 URL (java.net.URL)11 ResourceKey (com.enonic.xp.resource.ResourceKey)9 ApplicationService (com.enonic.xp.app.ApplicationService)8 ResourceService (com.enonic.xp.resource.ResourceService)8 BundleContext (org.osgi.framework.BundleContext)8 UrlResource (com.enonic.xp.resource.UrlResource)7 ScriptAsyncService (com.enonic.xp.script.impl.async.ScriptAsyncService)7 ScriptRuntimeFactoryImpl (com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl)7 PortalScriptServiceImpl (com.enonic.xp.portal.impl.script.PortalScriptServiceImpl)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 IOException (java.io.IOException)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 PropertyTree (com.enonic.xp.data.PropertyTree)4 PortalRequest (com.enonic.xp.portal.PortalRequest)4