use of org.apache.sling.distribution.DistributionRequest 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.DistributionRequest 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.DistributionRequest 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.DistributionRequest 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.DistributionRequest in project sling by apache.
the class JcrEventDistributionTriggerTest method testProcessEventOnMultipleIgnoredPattern.
@Test
public void testProcessEventOnMultipleIgnoredPattern() 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[] { ".*/.tokens.*", ".*/.rep:cache.*" };
JcrEventDistributionTrigger jcrEventdistributionTrigger = new JcrEventDistributionTrigger(repository, scheduler, resolverFactory, path, false, serviceName, ignoredPaths);
Event event = mock(Event.class);
when(event.getPath()).thenReturn("/home/users/3/3U3HxUUzJJ60BdN4lEDJ/.tokens/2017-01-10T15.52.37.842+01.00");
DistributionRequest distributionRequest = jcrEventdistributionTrigger.processEvent(event);
assertNull(distributionRequest);
}
Aggregations