use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.
the class RepositoryDistributionPackageImporterTest method testImportPackageWithRequiredPrivileges.
@Test
public void testImportPackageWithRequiredPrivileges() throws Exception {
SlingRepository repository = mock(SlingRepository.class);
String serviceName = "admin";
Session session = mock(Session.class);
ValueFactory vf = mock(ValueFactory.class);
when(session.getValueFactory()).thenReturn(vf);
AccessControlManager acm = mock(AccessControlManager.class);
String privilegeName = "jcr:read";
Privilege privilege = mock(Privilege.class);
String path = "/var/something";
Node rootNode = mock(Node.class);
Node createdNode = mock(Node.class);
Node jcrContentNode = mock(Node.class);
when(createdNode.addNode(JcrConstants.JCR_CONTENT, NodeType.NT_RESOURCE)).thenReturn(jcrContentNode);
when(rootNode.addNode(any(String.class), any(String.class))).thenReturn(createdNode);
when(session.getNode(path)).thenReturn(rootNode);
when(acm.hasPrivileges(path, new Privilege[] { privilege })).thenReturn(true);
when(acm.privilegeFromName(privilegeName)).thenReturn(privilege);
when(session.getAccessControlManager()).thenReturn(acm);
when(repository.loginService(serviceName, null)).thenReturn(session);
RepositoryDistributionPackageImporter repositoryDistributionPackageImporter = new RepositoryDistributionPackageImporter(repository, serviceName, path, privilegeName);
ResourceResolver resourceResolver = mock(ResourceResolver.class);
DistributionPackage distributionPackage = mock(DistributionPackage.class);
when(distributionPackage.getId()).thenReturn("someid");
InputStream stream = mock(InputStream.class);
when(distributionPackage.createInputStream()).thenReturn(stream);
repositoryDistributionPackageImporter.importPackage(resourceResolver, distributionPackage);
}
use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.
the class DistributionPackageMBeanTest method verifyMBeanExposedValues.
@Test
public void verifyMBeanExposedValues() {
String type = "jcrvlt";
long processingTime = 2000L;
Map<String, Object> base = new HashMap<String, Object>();
base.put(PROPERTY_REQUEST_PATHS, new String[] { "a", "b", "c" });
base.put(PROPERTY_REQUEST_TYPE, DistributionRequestType.ADD);
DistributionPackageInfo distributionPackageInfo = new DistributionPackageInfo(type, base);
DistributionPackage distributionPackage = mock(DistributionPackage.class);
when(distributionPackage.getId()).thenReturn("#distributionPackage");
when(distributionPackage.getSize()).thenReturn(1000L);
when(distributionPackage.getInfo()).thenReturn(distributionPackageInfo);
DistributionPackageMBean mBean = new DistributionPackageMBeanImpl(distributionPackage, type, processingTime);
assertEquals(distributionPackage.getId(), mBean.getId());
assertEquals(type, mBean.getType());
assertArrayEquals(distributionPackageInfo.getPaths(), mBean.getPaths());
assertEquals(distributionPackageInfo.getRequestType().name().toLowerCase(), mBean.getRequestType());
assertEquals(distributionPackage.getSize(), mBean.getSize());
assertEquals(processingTime, mBean.getProcessingTime());
}
use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.
the class SingleQueueDistributionStrategyTest method testPackageAdditionWithFailingItemDelivery.
@Test
public void testPackageAdditionWithFailingItemDelivery() throws Exception {
SingleQueueDispatchingStrategy singleQueueDistributionStrategy = new SingleQueueDispatchingStrategy();
DistributionPackage distributionPackage = mock(DistributionPackage.class);
DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
DistributionQueue queue = mock(DistributionQueue.class);
DistributionQueueItem queueItem = mock(DistributionQueueItem.class);
when(queueProvider.getQueue(DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME)).thenReturn(queue);
DistributionQueueItemStatus state = mock(DistributionQueueItemStatus.class);
when(queue.add(queueItem)).thenReturn(new DistributionQueueEntry(null, queueItem, state));
Iterable<DistributionQueueItemStatus> returnedStates = singleQueueDistributionStrategy.add(distributionPackage, queueProvider);
assertNotNull(returnedStates);
Iterator<DistributionQueueItemStatus> iterator = returnedStates.iterator();
assertNotNull(iterator);
assertTrue(iterator.hasNext());
assertNotNull(iterator.next());
}
use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.
the class SingleQueueDistributionStrategyTest method testPackageAdditionWithSucceedingItemDelivery.
@Test
public void testPackageAdditionWithSucceedingItemDelivery() throws Exception {
SingleQueueDispatchingStrategy singleQueueDistributionStrategy = new SingleQueueDispatchingStrategy();
DistributionPackage distributionPackage = mock(DistributionPackage.class);
DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
DistributionQueue queue = mock(DistributionQueue.class);
when(queueProvider.getQueue(DistributionQueueDispatchingStrategy.DEFAULT_QUEUE_NAME)).thenReturn(queue);
DistributionQueueItemStatus state = mock(DistributionQueueItemStatus.class);
when(queue.add(any(DistributionQueueItem.class))).thenReturn(new DistributionQueueEntry(null, null, state));
Iterable<DistributionQueueItemStatus> returnedStates = singleQueueDistributionStrategy.add(distributionPackage, queueProvider);
assertNotNull(returnedStates);
Iterator<DistributionQueueItemStatus> iterator = returnedStates.iterator();
assertNotNull(iterator);
assertTrue(iterator.hasNext());
assertNotNull(iterator.next());
}
use of org.apache.sling.distribution.packaging.DistributionPackage in project sling by apache.
the class PriorityQueueDispatchingStrategyTest method testNoMatchingDispatching.
@Test
public void testNoMatchingDispatching() throws Exception {
PriorityQueueDispatchingStrategy dispatchingStrategy = new PriorityQueueDispatchingStrategy(selectors, queueNames);
DistributionPackage distributionPackage = mock(SharedDistributionPackage.class);
DistributionQueueProvider queueProvider = mock(DistributionQueueProvider.class);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(DistributionPackageInfo.PROPERTY_REQUEST_PATHS, new String[] { "/content/other" });
when(distributionPackage.getInfo()).thenReturn(new DistributionPackageInfo("vlt", properties));
DistributionQueue other1 = mock(DistributionQueue.class);
when(other1.getName()).thenReturn("publish1");
when(queueProvider.getQueue("publish1")).thenReturn(other1);
DistributionQueue other2 = mock(DistributionQueue.class);
when(other2.getName()).thenReturn("publish2");
when(queueProvider.getQueue("publish2")).thenReturn(other2);
dispatchingStrategy.add(distributionPackage, queueProvider);
verify(queueProvider).getQueue("publish1");
verify(queueProvider).getQueue("publish2");
verifyNoMoreInteractions(queueProvider);
}
Aggregations