use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.
the class RemoteDistributionPackageImporterTest method testDummyImport.
@Test
public void testDummyImport() throws Exception {
DistributionTransportSecretProvider distributionTransportSecretProvider = mock(DistributionTransportSecretProvider.class);
Map<String, String> endpoints = new HashMap<String, String>();
RemoteDistributionPackageImporter remotedistributionPackageImporter = new RemoteDistributionPackageImporter(mock(DefaultDistributionLog.class), distributionTransportSecretProvider, endpoints, new HttpConfiguration(10000));
endpoints.put("default", "http://endpoint");
ResourceResolver resourceResolver = mock(ResourceResolver.class);
DistributionPackage distributionPackage = mock(DistributionPackage.class);
DistributionPackageInfo info = new DistributionPackageInfo("/foo");
when(distributionPackage.getInfo()).thenReturn(info);
remotedistributionPackageImporter.importPackage(resourceResolver, distributionPackage);
}
use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.
the class RepositoryDistributionPackageImporterTest method testImportPackageWithoutRequiredPrivileges.
@Test(expected = DistributionException.class)
public void testImportPackageWithoutRequiredPrivileges() throws Exception {
SlingRepository repository = mock(SlingRepository.class);
String serviceName = "admin";
Session session = mock(Session.class);
AccessControlManager acm = mock(AccessControlManager.class);
String privilegeName = "jcr:read";
Privilege privilege = mock(Privilege.class);
when(acm.privilegeFromName(privilegeName)).thenReturn(privilege);
when(session.getAccessControlManager()).thenReturn(acm);
when(repository.loginService(serviceName, null)).thenReturn(session);
String path = "/var/something";
RepositoryDistributionPackageImporter repositoryDistributionPackageImporter = new RepositoryDistributionPackageImporter(repository, serviceName, path, privilegeName);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
DistributionPackage distributionPackage = mock(DistributionPackage.class);
when(distributionPackage.getId()).thenReturn("someid");
repositoryDistributionPackageImporter.importPackage(resourceResolver, distributionPackage);
}
use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.
the class RepositoryDistributionPackageImporterTest method testImportPackageWithUnauthorizedServiceUser.
@Test(expected = DistributionException.class)
public void testImportPackageWithUnauthorizedServiceUser() throws Exception {
SlingRepository repository = mock(SlingRepository.class);
String serviceName = "admin";
String path = "/var/something";
String privilegeName = "jcr:read";
RepositoryDistributionPackageImporter repositoryDistributionPackageImporter = new RepositoryDistributionPackageImporter(repository, serviceName, path, privilegeName);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
DistributionPackage distributionPackage = mock(DistributionPackage.class);
when(distributionPackage.getId()).thenReturn("someid");
repositoryDistributionPackageImporter.importPackage(resourceResolver, distributionPackage);
}
use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.
the class AsyncDeliveryDispatchingStrategyTest method testAddWithNotSharedPackage.
@Test(expected = DistributionException.class)
public void testAddWithNotSharedPackage() throws Exception {
Map<String, String> deliveryMappings = new HashMap<String, String>();
deliveryMappings.put("queue1", "delivery1");
deliveryMappings.put("queue2", "delivery2");
AsyncDeliveryDispatchingStrategy asyncDeliveryDispatchingStrategy = new AsyncDeliveryDispatchingStrategy(deliveryMappings);
DistributionPackage distributionPackage = mock(DistributionPackage.class);
DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
asyncDeliveryDispatchingStrategy.add(distributionPackage, queueProvider);
}
use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.
the class SimpleHttpDistributionTransport method retrievePackage.
@Nullable
public RemoteDistributionPackage retrievePackage(@Nonnull ResourceResolver resourceResolver, @Nonnull DistributionRequest distributionRequest, @Nonnull DistributionTransportContext distributionContext) throws DistributionException {
log.debug("pulling from {}", distributionEndpoint.getUri());
try {
URI distributionURI = RequestUtils.appendDistributionRequest(distributionEndpoint.getUri(), distributionRequest);
Executor executor = getExecutor(distributionContext);
// TODO : add queue parameter
InputStream inputStream = HttpTransportUtils.fetchNextPackage(executor, distributionURI, httpConfiguration);
if (inputStream == null) {
return null;
}
try {
final DistributionPackage responsePackage = packageBuilder.readPackage(resourceResolver, inputStream);
responsePackage.getInfo().put(PACKAGE_INFO_PROPERTY_ORIGIN_URI, distributionURI);
log.debug("pulled package with info {}", responsePackage.getInfo());
return new DefaultRemoteDistributionPackage(responsePackage, executor, distributionURI);
} finally {
IOUtils.closeQuietly(inputStream);
}
} catch (HttpHostConnectException e) {
log.debug("could not connect to {} - skipping", distributionEndpoint.getUri());
} catch (Exception ex) {
log.error("cannot retrieve packages", ex);
}
return null;
}
Aggregations