Search in sources :

Example 26 with DistributionPackage

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);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) AccessControlManager(javax.jcr.security.AccessControlManager) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) InputStream(java.io.InputStream) Node(javax.jcr.Node) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ValueFactory(javax.jcr.ValueFactory) Privilege(javax.jcr.security.Privilege) Session(javax.jcr.Session) Test(org.junit.Test)

Example 27 with 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());
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 28 with DistributionPackage

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());
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Example 29 with DistributionPackage

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());
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Example 30 with DistributionPackage

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);
}
Also used : DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) SharedDistributionPackage(org.apache.sling.distribution.packaging.impl.SharedDistributionPackage) DistributionPackageInfo(org.apache.sling.distribution.packaging.DistributionPackageInfo) HashMap(java.util.HashMap) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueProvider(org.apache.sling.distribution.queue.DistributionQueueProvider) Test(org.junit.Test)

Aggregations

DistributionPackage (org.apache.sling.distribution.packaging.DistributionPackage)59 Test (org.junit.Test)41 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)25 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)21 DistributionRequest (org.apache.sling.distribution.DistributionRequest)17 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)17 DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)16 DefaultDistributionLog (org.apache.sling.distribution.log.impl.DefaultDistributionLog)12 DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)12 HashMap (java.util.HashMap)11 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)10 DistributionException (org.apache.sling.distribution.common.DistributionException)9 DistributionPackageProcessor (org.apache.sling.distribution.packaging.DistributionPackageProcessor)9 SlingRepository (org.apache.sling.jcr.api.SlingRepository)9 InputStream (java.io.InputStream)8 DistributionEventFactory (org.apache.sling.distribution.event.impl.DistributionEventFactory)8 FileDistributionPackageBuilder (org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder)8 Resource (org.apache.sling.api.resource.Resource)7 DistributionPackageExporter (org.apache.sling.distribution.packaging.DistributionPackageExporter)7 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)7