use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class KryoContentSerializerTest method testExtract.
@Test
public void testExtract() throws Exception {
KryoContentSerializer kryoContentSerializer = new KryoContentSerializer("kryo");
DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/libs");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
NavigableMap<String, List<String>> nodeFilters = new TreeMap<String, List<String>>();
NavigableMap<String, List<String>> propertyFilters = new TreeMap<String, List<String>>();
try {
DistributionExportFilter filter = DistributionExportFilter.createFilter(request, nodeFilters, propertyFilters);
kryoContentSerializer.exportToStream(resourceResolver, new DistributionExportOptions(request, filter), outputStream);
byte[] bytes = outputStream.toByteArray();
assertNotNull(bytes);
assertTrue(bytes.length > 0);
} finally {
outputStream.close();
}
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class DistributionAgentLogServlet method doGet.
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/plain");
DistributionRequest distributionRequest = RequestUtils.fromServletRequest(request);
log.debug("distribution request : {}", distributionRequest);
DistributionLog distributionLog = request.getResource().adaptTo(DistributionLog.class);
PrintWriter writer = response.getWriter();
if (distributionLog != null) {
for (String line : distributionLog.getLines()) {
writer.append(line);
writer.append("\n");
}
} else {
response.setStatus(404);
writer.append("agent not found");
}
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class KryoContentSerializerTest method testBuildAndInstallOnMultipleShallowPaths.
@Test
public void testBuildAndInstallOnMultipleShallowPaths() 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, "/libs/sub", "/libs/sameLevel");
DistributionPackage distributionPackage = packageBuilder.createPackage(resourceResolver, request);
Resource resource = resourceResolver.getResource("/libs/sub");
resourceResolver.delete(resource);
resource = resourceResolver.getResource("/libs/sameLevel");
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 PersistingJcrEventDistributionTriggerTest method testProcessEventWithPrivileges.
@Test
public void testProcessEventWithPrivileges() throws Exception {
String nuggetsPath = "/var/nuggets";
String serviceName = "serviceId";
Session session = mock(Session.class);
when(session.nodeExists("/var/nuggets")).thenReturn(true);
Workspace workspace = mock(Workspace.class);
ObservationManager observationManager = mock(ObservationManager.class);
when(workspace.getObservationManager()).thenReturn(observationManager);
when(session.getWorkspace()).thenReturn(workspace);
when(session.hasPermission(nuggetsPath, Session.ACTION_ADD_NODE)).thenReturn(true);
SlingRepository repository = mock(SlingRepository.class);
Scheduler scheduler = mock(Scheduler.class);
ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
when(repository.loginService(serviceName, null)).thenReturn(session);
String path = "/some/path";
PersistedJcrEventDistributionTrigger persistingJcrEventdistributionTrigger = new PersistedJcrEventDistributionTrigger(repository, scheduler, resolverFactory, path, serviceName, nuggetsPath);
DistributionRequestHandler handler = mock(DistributionRequestHandler.class);
persistingJcrEventdistributionTrigger.register(handler);
Node nuggetsNode = mock(Node.class);
Node eventNode = mock(Node.class);
when(nuggetsNode.addNode(any(String.class), any(String.class))).thenReturn(eventNode);
when(session.getNode(nuggetsPath)).thenReturn(nuggetsNode);
Event event = mock(Event.class);
when(event.getPath()).thenReturn("/some/path/generating/event");
DistributionRequest distributionRequest = persistingJcrEventdistributionTrigger.processEvent(event);
assertNotNull(distributionRequest);
}
use of org.apache.sling.distribution.DistributionRequest in project sling by apache.
the class JcrEventDistributionTriggerTest method testProcessEventOnIgnoredPattern.
@Test
public void testProcessEventOnIgnoredPattern() throws Exception {
SlingRepository repository = mock(SlingRepository.class);
Scheduler scheduler = mock(Scheduler.class);
ResourceResolverFactory resolverFactory = mock(ResourceResolverFactory.class);
String path = "/home/users";
String serviceName = "serviceId";
String[] ignoredPaths = new String[] { "/home/users/\\w" };
JcrEventDistributionTrigger jcrEventdistributionTrigger = new JcrEventDistributionTrigger(repository, scheduler, resolverFactory, path, false, serviceName, ignoredPaths);
Event event = mock(Event.class);
when(event.getPath()).thenReturn("/home/users/a");
DistributionRequest distributionRequest = jcrEventdistributionTrigger.processEvent(event);
assertNull(distributionRequest);
}
Aggregations