use of com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson in project xp by enonic.
the class ApplicationResourceTest method install_exception.
@Test
public void install_exception() throws Exception {
ApplicationResource resource = getResourceInstance();
MultipartItem multipartItem = Mockito.mock(MultipartItem.class);
ByteSource byteSource = ByteSource.wrap("bytes".getBytes());
String fileName = "app-name";
Mockito.when(multipartItem.getBytes()).thenReturn(byteSource);
Mockito.when(multipartItem.getFileName()).thenReturn(fileName);
MultipartForm multipartForm = Mockito.mock(MultipartForm.class);
Mockito.when(this.applicationService.installGlobalApplication(Mockito.isA(ByteSource.class), eq("app-name"))).thenThrow(new RuntimeException());
Mockito.when(multipartForm.get("file")).thenReturn(multipartItem);
ApplicationInstallResultJson result = resource.install(multipartForm);
assertEquals("Failed to process application app-name", result.getFailure());
}
use of com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson in project xp by enonic.
the class ApplicationResource method installApplication.
private ApplicationInstallResultJson installApplication(final URL url, byte[] sha512) {
final ApplicationInstallResultJson result = new ApplicationInstallResultJson();
try {
final Application application = this.applicationService.installGlobalApplication(url, sha512);
result.setApplicationInstalledJson(new ApplicationInstalledJson(application, false));
} catch (Exception e) {
final String failure = "Failed to process application from " + url;
LOG.error(failure, e);
result.setFailure(failure);
}
return result;
}
use of com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson in project xp by enonic.
the class ApplicationResource method installUrl.
@POST
@Path("installUrl")
@Consumes(MediaType.APPLICATION_JSON)
public ApplicationInstallResultJson installUrl(final ApplicationInstallParams params) {
final String urlString = params.getUrl();
final byte[] sha512 = Optional.ofNullable(params.getSha512()).map(HexEncoder::fromHex).orElse(null);
final ApplicationInstallResultJson result = new ApplicationInstallResultJson();
String failure;
try {
final URL url = new URL(urlString);
if (ALLOWED_PROTOCOLS.contains(url.getProtocol())) {
return installApplication(url, sha512);
} else {
failure = "Illegal protocol: " + url.getProtocol();
result.setFailure(failure);
return result;
}
} catch (IOException e) {
LOG.error(failure = "Failed to upload application from " + urlString, e);
result.setFailure(failure);
return result;
}
}
use of com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson in project xp by enonic.
the class ApplicationResource method installApplication.
private ApplicationInstallResultJson installApplication(final ByteSource byteSource, final String applicationName) {
final ApplicationInstallResultJson result = new ApplicationInstallResultJson();
try {
final Application application = this.applicationService.installGlobalApplication(byteSource, applicationName);
result.setApplicationInstalledJson(new ApplicationInstalledJson(application, false));
} catch (Exception e) {
final String failure = "Failed to process application " + applicationName;
LOG.error(failure, e);
result.setFailure(failure);
}
return result;
}
use of com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson 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());
}
Aggregations