use of org.apache.sling.distribution.SimpleDistributionRequest in project sling by apache.
the class VltUtilsTest method testDeepFilter.
@Test
public void testDeepFilter() throws Exception {
DistributionRequest request = new SimpleDistributionRequest(ADD, true, "/foo");
NavigableMap<String, List<String>> nodeFilters = new TreeMap<String, List<String>>();
nodeFilters.put("/foo", Arrays.asList("/foo/bar", "/foo/bar1"));
NavigableMap<String, List<String>> propFilters = new TreeMap<String, List<String>>();
propFilters.put("/", Arrays.asList("^.*/prop1", "^.*/prop2"));
WorkspaceFilter wsFilter = VltUtils.createFilter(request, nodeFilters, propFilters);
assertNotNull(wsFilter);
assertNotNull(wsFilter.getPropertyFilterSets());
List<PathFilterSet> propFilterSet = wsFilter.getPropertyFilterSets();
assertEquals(1, propFilterSet.size());
PathFilterSet propFilter = propFilterSet.get(0);
assertEquals(2, propFilter.getEntries().size());
PathFilter filter = propFilter.getEntries().get(0).getFilter();
assertTrue(filter.matches("/foo/bar/prop1"));
assertTrue(filter.matches("/foo/prop1"));
}
use of org.apache.sling.distribution.SimpleDistributionRequest in project sling by apache.
the class SimpleHttpDistributionTransportTest method testRetrievePackagesRemotelyFailing.
@Test
public void testRetrievePackagesRemotelyFailing() throws Exception {
DistributionTransportSecret secret = mock(DistributionTransportSecret.class);
Map<String, String> credentialsMap = new HashMap<String, String>();
credentialsMap.put("username", "foo");
credentialsMap.put("password", "foo");
when(secret.asCredentialsMap()).thenReturn(credentialsMap);
DistributionTransportSecretProvider secretProvider = mock(DistributionTransportSecretProvider.class);
when(secretProvider.getSecret(any(URI.class))).thenReturn(secret);
Executor executor = mock(Executor.class);
Response response = mock(Response.class);
HttpResponse httpResponse = mock(HttpResponse.class);
StatusLine statusLine = mock(StatusLine.class);
when(statusLine.getStatusCode()).thenReturn(404);
when(httpResponse.getStatusLine()).thenReturn(statusLine);
when(response.returnResponse()).thenReturn(httpResponse);
when(executor.execute(any(Request.class))).thenReturn(response);
DistributionEndpoint endpoint = new DistributionEndpoint("http://127.0.0.1:8080/some/resource");
DistributionPackageBuilder packageBuilder = mock(DistributionPackageBuilder.class);
SimpleHttpDistributionTransport simpleHttpDistributionTransport = new SimpleHttpDistributionTransport(mock(DefaultDistributionLog.class), endpoint, packageBuilder, secretProvider, new HttpConfiguration(1000, 1000));
ResourceResolver resourceResolver = mock(ResourceResolver.class);
DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
RemoteDistributionPackage retrievedPackage = simpleHttpDistributionTransport.retrievePackage(resourceResolver, distributionRequest, new DistributionTransportContext());
assertNull(retrievedPackage);
}
use of org.apache.sling.distribution.SimpleDistributionRequest in project sling by apache.
the class SimpleHttpDistributionTransportTest method testRetrievePackagesRemotelyWorking.
@Test
public void testRetrievePackagesRemotelyWorking() throws Exception {
DistributionTransportSecret secret = mock(DistributionTransportSecret.class);
Map<String, String> credentialsMap = new HashMap<String, String>();
credentialsMap.put("username", "foo");
credentialsMap.put("password", "foo");
when(secret.asCredentialsMap()).thenReturn(credentialsMap);
DistributionTransportSecretProvider secretProvider = mock(DistributionTransportSecretProvider.class);
when(secretProvider.getSecret(any(URI.class))).thenReturn(secret);
Executor executor = mock(Executor.class);
Response response = mock(Response.class);
HttpResponse httpResponse = mock(HttpResponse.class);
StatusLine statusLine = mock(StatusLine.class);
when(statusLine.getStatusCode()).thenReturn(200);
when(httpResponse.getStatusLine()).thenReturn(statusLine);
HttpEntity entity = mock(HttpEntity.class);
InputStream stream = new ByteArrayInputStream("package binary stuff".getBytes("UTF-8"));
when(entity.getContent()).thenReturn(stream);
when(httpResponse.getEntity()).thenReturn(entity);
when(response.returnResponse()).thenReturn(httpResponse);
when(executor.execute(any(Request.class))).thenReturn(response);
DistributionEndpoint endpoint = new DistributionEndpoint("http://127.0.0.1:8080/some/resource");
DistributionPackageBuilder packageBuilder = mock(DistributionPackageBuilder.class);
DistributionPackage distributionPackage = mock(DistributionPackage.class);
when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("type"));
when(packageBuilder.readPackage(any(ResourceResolver.class), any(InputStream.class))).thenReturn(distributionPackage);
SimpleHttpDistributionTransport simpleHttpDistributionTransport = new SimpleHttpDistributionTransport(mock(DefaultDistributionLog.class), endpoint, packageBuilder, secretProvider, new HttpConfiguration(1000, 1000));
ResourceResolver resourceResolver = mock(ResourceResolver.class);
DistributionRequest distributionRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, "/");
DistributionTransportContext distributionContext = mock(DistributionTransportContext.class);
when(distributionContext.get(any(String.class), same(Executor.class))).thenReturn(executor);
when(distributionContext.containsKey(any(String.class))).thenReturn(true);
RemoteDistributionPackage retrievedPackage = simpleHttpDistributionTransport.retrievePackage(resourceResolver, distributionRequest, distributionContext);
assertNotNull(retrievedPackage);
}
use of org.apache.sling.distribution.SimpleDistributionRequest in project sling by apache.
the class AbstractJcrEventTriggerTest method addToListTest.
//"SLING-6054"
@Test
public void addToListTest() throws Exception {
SlingRepository repository = mock(SlingRepository.class);
Scheduler scheduler = mock(Scheduler.class);
String path = "/";
String serviceUser = "service-user";
AbstractJcrEventTrigger trigger = new AbstractJcrEventTrigger(repository, scheduler, rrf, path, serviceUser) {
@Override
protected DistributionRequest processEvent(Event event) throws RepositoryException {
return null;
}
};
String descendant = "/a/b/c/d/e/f/h";
String ancestor = "/a/b/c/d";
List<DistributionRequest> requests = new LinkedList<DistributionRequest>();
requests.add(new SimpleDistributionRequest(DistributionRequestType.ADD, descendant));
DistributionRequest newRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, ancestor);
trigger.addToList(newRequest, requests);
assertEquals(1, requests.size());
assertEquals(3, requests.get(0).getPaths().length);
String[] paths = requests.get(0).getPaths();
assertEquals(ancestor, paths[0]);
// the missing path is added
assertEquals("/a/b/c/d/e/f/g", paths[1]);
assertEquals(descendant, paths[2]);
// invert order of requests
requests = new LinkedList<DistributionRequest>();
requests.add(new SimpleDistributionRequest(DistributionRequestType.ADD, ancestor));
newRequest = new SimpleDistributionRequest(DistributionRequestType.ADD, descendant);
trigger.addToList(newRequest, requests);
assertEquals(1, requests.size());
assertEquals(3, requests.get(0).getPaths().length);
paths = requests.get(0).getPaths();
assertEquals(ancestor, paths[0]);
// the missing path is added
assertEquals("/a/b/c/d/e/f/g", paths[1]);
assertEquals(descendant, paths[2]);
}
use of org.apache.sling.distribution.SimpleDistributionRequest 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);
}
}
Aggregations