use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class DistributorServlet method doPost.
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
String action = request.getParameter("action");
String agentName = request.getParameter("agent");
String[] paths = request.getParameterValues("path");
if (agentName == null) {
response.getWriter().print("agent is required");
return;
}
DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.fromName(action), paths);
DistributionResponse distributionResponse = distributor.distribute(agentName, request.getResourceResolver(), distributionRequest);
if (distributionResponse.isSuccessful()) {
response.setStatus(200);
} else {
response.setStatus(400);
}
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class DistributionExportFilterTest method testCreateFilter.
@Test
public void testCreateFilter() throws Exception {
DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/a", "/b");
NavigableMap<String, List<String>> nodeFilters = new TreeMap<String, List<String>>();
NavigableMap<String, List<String>> propertyFilters = new TreeMap<String, List<String>>();
DistributionExportFilter filter = DistributionExportFilter.createFilter(request, nodeFilters, propertyFilters);
assertNotNull(filter);
assertNotNull(filter.getNodeFilters());
assertNotNull(filter.getPropertyFilter());
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class FileVaultContentSerializerTest method testExportToStream.
@Test
public void testExportToStream() throws Exception {
Packaging packaging = mock(Packaging.class);
ImportMode importMode = ImportMode.REPLACE;
AccessControlHandling aclHandling = AccessControlHandling.IGNORE;
String[] packageRoots = new String[] { "/etc/packages" };
String[] nodeFilters = new String[0];
String[] propertyFilters = new String[0];
boolean useReferences = false;
int threshold = 1024;
FileVaultContentSerializer fileVaultContentSerializer = new FileVaultContentSerializer("vlt", packaging, importMode, aclHandling, packageRoots, nodeFilters, propertyFilters, useReferences, threshold);
ResourceResolver sessionResolver = mock(ResourceResolver.class);
Session session = mock(Session.class);
PackageManager pm = mock(PackageManager.class);
when(packaging.getPackageManager()).thenReturn(pm);
OutputStream outputStream = new ByteArrayOutputStream();
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
return null;
}
}).when(pm).assemble(same(session), any(ExportOptions.class), same(outputStream));
Workspace workspace = mock(Workspace.class);
ObservationManager observationManager = mock(ObservationManager.class);
when(workspace.getObservationManager()).thenReturn(observationManager);
when(session.getWorkspace()).thenReturn(workspace);
when(sessionResolver.adaptTo(Session.class)).thenReturn(session);
DistributionExportFilter filter = mock(DistributionExportFilter.class);
DistributionRequest request = mock(DistributionRequest.class);
when(request.getPaths()).thenReturn(new String[] { "/libs" });
when(request.getFilters("/libs")).thenReturn(new String[0]);
DistributionExportOptions exportOptions = new DistributionExportOptions(request, filter);
fileVaultContentSerializer.exportToStream(sessionResolver, exportOptions, outputStream);
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class KryoContentSerializerTest method testBuildAndInstallOnSingleDeepPath.
@Test
public void testBuildAndInstallOnSingleDeepPath() throws Exception {
String type = "kryo";
DistributionContentSerializer contentSerializer = new KryoContentSerializer(type);
String tempFilesFolder = "target";
String[] nodeFilters = new String[0];
String[] propertyFilters = new String[0];
DistributionPackageBuilder packageBuilder = new FileDistributionPackageBuilder(type, contentSerializer, tempFilesFolder, null, nodeFilters, propertyFilters);
DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, true, "/libs");
DistributionPackage distributionPackage = packageBuilder.createPackage(resourceResolver, request);
Resource resource = resourceResolver.getResource("/libs/sub");
resourceResolver.delete(resource);
resourceResolver.commit();
assertTrue(packageBuilder.installPackage(resourceResolver, distributionPackage));
assertNotNull(resourceResolver.getResource("/libs"));
assertNotNull(resourceResolver.getResource("/libs/sub"));
assertNotNull(resourceResolver.getResource("/libs/sameLevel"));
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class JcrEventDistributionTriggerTest method testProcessEventWithoutPathProperty.
@Test
public void testProcessEventWithoutPathProperty() throws Exception {
SlingRepository repository = mock(SlingRepository.class);
Scheduler scheduler = mock(Scheduler.class);
ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
String path = "/some/path";
String serviceName = "serviceId";
JcrEventDistributionTrigger jcrEventdistributionTrigger = new JcrEventDistributionTrigger(repository, scheduler, resolverFactory, path, false, serviceName, null);
Event event = mock(Event.class);
DistributionRequest distributionRequest = jcrEventdistributionTrigger.processEvent(event);
assertNull(distributionRequest);
}
Aggregations