Search in sources :

Example 61 with Application

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

the class MixinServiceImpl method getAll.

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

Example 62 with Application

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

the class FilterScriptImplTest method setup.

@BeforeEach
public void setup() throws Exception {
    this.portalRequest = new PortalRequest();
    this.portalResponse = PortalResponse.create().build();
    final BundleContext bundleContext = Mockito.mock(BundleContext.class);
    final Bundle bundle = Mockito.mock(Bundle.class);
    Mockito.when(bundle.getBundleContext()).thenReturn(bundleContext);
    final Application application = Mockito.mock(Application.class);
    Mockito.when(application.getBundle()).thenReturn(bundle);
    Mockito.when(application.getClassLoader()).thenReturn(getClass().getClassLoader());
    Mockito.when(application.isStarted()).thenReturn(true);
    Mockito.when(application.getConfig()).thenReturn(ConfigBuilder.create().build());
    final ApplicationService applicationService = Mockito.mock(ApplicationService.class);
    Mockito.when(applicationService.getInstalledApplication(ApplicationKey.from("myapplication"))).thenReturn(application);
    this.resourceService = Mockito.mock(ResourceService.class);
    Mockito.when(resourceService.getResource(Mockito.any())).thenAnswer(invocation -> {
        final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
        final URL resourceUrl = FilterScriptImplTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
        return new UrlResource(resourceKey, resourceUrl);
    });
    final ScriptAsyncService scriptAsyncService = Mockito.mock(ScriptAsyncService.class);
    final ScriptRuntimeFactoryImpl runtimeFactory = new ScriptRuntimeFactoryImpl(applicationService, this.resourceService, scriptAsyncService);
    final PortalScriptServiceImpl scriptService = new PortalScriptServiceImpl(runtimeFactory);
    scriptService.initialize();
    this.factory = new FilterScriptFactoryImpl();
    this.factory.setScriptService(scriptService);
    final HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
    ServletRequestHolder.setRequest(req);
}
Also used : Bundle(org.osgi.framework.Bundle) ResourceService(com.enonic.xp.resource.ResourceService) PortalScriptServiceImpl(com.enonic.xp.portal.impl.script.PortalScriptServiceImpl) URL(java.net.URL) PortalRequest(com.enonic.xp.portal.PortalRequest) ResourceKey(com.enonic.xp.resource.ResourceKey) ScriptRuntimeFactoryImpl(com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl) HttpServletRequest(javax.servlet.http.HttpServletRequest) UrlResource(com.enonic.xp.resource.UrlResource) ScriptAsyncService(com.enonic.xp.script.impl.async.ScriptAsyncService) Application(com.enonic.xp.app.Application) BundleContext(org.osgi.framework.BundleContext) ApplicationService(com.enonic.xp.app.ApplicationService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 63 with Application

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

the class ApplicationResourceTest method createApplication.

private Application createApplication(final String url) {
    final Application application = Mockito.mock(Application.class);
    Mockito.when(application.getKey()).thenReturn(ApplicationKey.from("testapplication"));
    Mockito.when(application.getVersion()).thenReturn(new Version(1, 0, 0));
    Mockito.when(application.getDisplayName()).thenReturn("application name");
    Mockito.when(application.getUrl()).thenReturn(url);
    Mockito.when(application.getVendorName()).thenReturn("Enonic");
    Mockito.when(application.getVendorUrl()).thenReturn("https://www.enonic.com");
    Mockito.when(application.getMinSystemVersion()).thenReturn("5.0");
    Mockito.when(application.getMaxSystemVersion()).thenReturn("5.1");
    Mockito.when(application.isStarted()).thenReturn(true);
    Mockito.when(application.getModifiedTime()).thenReturn(Instant.parse("2012-01-01T00:00:00.00Z"));
    return application;
}
Also used : Version(org.osgi.framework.Version) Application(com.enonic.xp.app.Application)

Example 64 with Application

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

the class ApplicationResourceTest method install_url.

@Test
public void install_url() throws Exception {
    Application application = createApplication();
    Mockito.when(this.applicationService.installGlobalApplication(eq(new URL(application.getUrl())), any())).thenReturn(application);
    String jsonString = request().path("app/installUrl").entity("{\"URL\":\"http://enonic.net\"}", MediaType.APPLICATION_JSON_TYPE).post().getAsString();
    assertJson("install_url_result.json", jsonString);
}
Also used : Application(com.enonic.xp.app.Application) URL(java.net.URL) Test(org.junit.jupiter.api.Test)

Example 65 with Application

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

the class ApplicationResourceTest method install.

@Test
public void install() throws Exception {
    ApplicationResource resource = getResourceInstance();
    ByteSource byteSource = ByteSource.wrap("bytes".getBytes());
    Application application = createApplication();
    MultipartItem multipartItem = Mockito.mock(MultipartItem.class);
    Mockito.when(multipartItem.getBytes()).thenReturn(byteSource);
    String fileName = application.getDisplayName();
    Mockito.when(multipartItem.getFileName()).thenReturn(fileName);
    MultipartForm multipartForm = Mockito.mock(MultipartForm.class);
    Mockito.when(this.applicationService.installGlobalApplication(Mockito.isA(ByteSource.class), eq(fileName))).thenReturn(application);
    Mockito.when(multipartForm.get("file")).thenReturn(multipartItem);
    ApplicationInstallResultJson result = resource.install(multipartForm);
    assertEquals(new ApplicationInstalledJson(application, false), result.getApplicationInstalledJson());
}
Also used : MultipartItem(com.enonic.xp.web.multipart.MultipartItem) ApplicationInstallResultJson(com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson) ApplicationInstalledJson(com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson) ByteSource(com.google.common.io.ByteSource) MultipartForm(com.enonic.xp.web.multipart.MultipartForm) 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