Search in sources :

Example 1 with SkinAccessBridge

use of org.xwiki.bridge.SkinAccessBridge in project xwiki-platform by xwiki.

the class IntegrationTests method initialize.

@RenderingTestSuite.Initialized
public void initialize(ComponentManager componentManager) throws Exception {
    Mockery mockery = new JUnit4Mockery();
    final SkinAccessBridge mockSkinAccessBridge = mockery.mock(SkinAccessBridge.class);
    DefaultComponentDescriptor<SkinAccessBridge> descriptorSAB = new DefaultComponentDescriptor<SkinAccessBridge>();
    descriptorSAB.setRoleType(SkinAccessBridge.class);
    componentManager.registerComponent(descriptorSAB, mockSkinAccessBridge);
    mockery.checking(new Expectations() {

        {
            allowing(mockSkinAccessBridge).getSkinFile(with(any(String.class)));
            will(returnValue("/xwiki/resources/icons/silk/feed.png"));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) SkinAccessBridge(org.xwiki.bridge.SkinAccessBridge) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Mockery(org.jmock.Mockery)

Example 2 with SkinAccessBridge

use of org.xwiki.bridge.SkinAccessBridge in project xwiki-platform by xwiki.

the class IntegrationTests method initialize.

@RenderingTestSuite.Initialized
public void initialize(ComponentManager componentManager) throws Exception {
    Mockery mockery = new JUnit4Mockery();
    // Skin Access Bridge Mock
    final SkinAccessBridge mockSkinAccessBridge = registerMockComponent(componentManager, mockery, SkinAccessBridge.class);
    mockery.checking(new Expectations() {

        {
            allowing(mockSkinAccessBridge).getSkinFile("icons/xwiki/noavatar.png");
            will(returnValue("/xwiki/resources/icons/xwiki/noavatar.png"));
        }
    });
    // Document Access Bridge Mock
    final DocumentReference adminUserReference = new DocumentReference("wiki", "XWiki", "Admin");
    final DocumentReference userWithoutAvatarReference = new DocumentReference("wiki", "XWiki", "ExistingUserWithoutAvatar");
    final DocumentReference userNotExistingReference = new DocumentReference("wiki", "XWiki", "UserNotExisting");
    final DocumentReference userWithNonExistingAvatarFileReference = new DocumentReference("wiki", "XWiki", "UserWithNonExistingAvatarFile");
    final DocumentReference userWithExceptionRetrievingAvatarFileReference = new DocumentReference("wiki", "XWiki", "UserWithExceptionRetrievingAvatarFile");
    final DocumentReference userClassReference = new DocumentReference("wiki", "XWiki", "XWikiUsers");
    final DocumentAccessBridge mockDocumentAccessBridge = registerMockComponent(componentManager, mockery, DocumentAccessBridge.class);
    mockery.checking(new Expectations() {

        {
            allowing(mockDocumentAccessBridge).exists(adminUserReference);
            will(returnValue(true));
            allowing(mockDocumentAccessBridge).exists(userWithoutAvatarReference);
            will(returnValue(true));
            allowing(mockDocumentAccessBridge).exists(with(any(String.class)));
            will(returnValue(false));
            allowing(mockDocumentAccessBridge).exists(userNotExistingReference);
            will(returnValue(false));
            allowing(mockDocumentAccessBridge).exists(userWithNonExistingAvatarFileReference);
            will(returnValue(true));
            allowing(mockDocumentAccessBridge).exists(userWithExceptionRetrievingAvatarFileReference);
            will(returnValue(true));
            allowing(mockDocumentAccessBridge).getProperty(adminUserReference, userClassReference, "avatar");
            will(returnValue("mockAvatar.png"));
            allowing(mockDocumentAccessBridge).getProperty(userWithoutAvatarReference, userClassReference, "avatar");
            will(returnValue(null));
            allowing(mockDocumentAccessBridge).getProperty(userWithNonExistingAvatarFileReference, userClassReference, "avatar");
            will(returnValue("mockAvatar.png"));
            allowing(mockDocumentAccessBridge).getProperty(userWithExceptionRetrievingAvatarFileReference, userClassReference, "avatar");
            will(returnValue("mockAvatar.png"));
            allowing(mockDocumentAccessBridge).getAttachmentVersion(new AttachmentReference("mockAvatar.png", adminUserReference));
            will(returnValue("1.1"));
            allowing(mockDocumentAccessBridge).getAttachmentVersion(new AttachmentReference("mockAvatar.png", userWithNonExistingAvatarFileReference));
            will(returnValue(null));
            allowing(mockDocumentAccessBridge).getAttachmentVersion(new AttachmentReference("mockAvatar.png", userWithExceptionRetrievingAvatarFileReference));
            will(throwException(new Exception("Sum Ting Wong")));
        }
    });
    // Document Resolver Mock
    final DocumentReferenceResolver<String> mockDocumentReferenceResolver = registerMockComponent(componentManager, mockery, DocumentReferenceResolver.TYPE_STRING, "current");
    mockery.checking(new Expectations() {

        {
            allowing(mockDocumentReferenceResolver).resolve("XWiki.Admin", new EntityReference("XWiki", EntityType.SPACE));
            will(returnValue(adminUserReference));
            allowing(mockDocumentReferenceResolver).resolve("XWiki.ExistingUserWithoutAvatar", new EntityReference("XWiki", EntityType.SPACE));
            will(returnValue(userWithoutAvatarReference));
            allowing(mockDocumentReferenceResolver).resolve("XWiki.UserNotExisting", new EntityReference("XWiki", EntityType.SPACE));
            will(returnValue(userNotExistingReference));
            allowing(mockDocumentReferenceResolver).resolve("XWiki.UserWithNonExistingAvatarFile", new EntityReference("XWiki", EntityType.SPACE));
            will(returnValue(userWithNonExistingAvatarFileReference));
            allowing(mockDocumentReferenceResolver).resolve("XWiki.UserWithExceptionRetrievingAvatarFile", new EntityReference("XWiki", EntityType.SPACE));
            will(returnValue(userWithExceptionRetrievingAvatarFileReference));
        }
    });
    // Entity Reference Serializer Mock
    final EntityReferenceSerializer<String> mockEntityReferenceSerializer = registerMockComponent(componentManager, mockery, EntityReferenceSerializer.TYPE_STRING, "compactwiki");
    mockery.checking(new Expectations() {

        {
            allowing(mockEntityReferenceSerializer).serialize(new AttachmentReference("mockAvatar.png", adminUserReference));
            will(returnValue("XWiki.Admin@mockAvatar.png"));
            allowing(mockEntityReferenceSerializer).serialize(userNotExistingReference);
            will(returnValue("XWiki.UserNotExisting"));
            allowing(mockEntityReferenceSerializer).serialize(new AttachmentReference("mockAvatar.png", userWithNonExistingAvatarFileReference));
            will(returnValue("XWiki.UserWithNonExistingAvatarFile@mockAvatar.png"));
            allowing(mockEntityReferenceSerializer).serialize(new AttachmentReference("mockAvatar.png", userWithExceptionRetrievingAvatarFileReference));
            will(returnValue("XWiki.UserWithExceptionRetrievingAvatarFile@mockAvatar.png"));
            allowing(mockEntityReferenceSerializer).serialize(userWithExceptionRetrievingAvatarFileReference);
            will(returnValue("XWiki.UserWithExceptionRetrievingAvatarFile"));
        }
    });
    // Entity Reference Serializer Mock
    final EntityReferenceValueProvider mockEntityReferenceValueProvider = registerMockComponent(componentManager, mockery, EntityReferenceValueProvider.class, "current");
    mockery.checking(new Expectations() {

        {
            allowing(mockEntityReferenceValueProvider).getDefaultValue(EntityType.WIKI);
            will(returnValue("wiki"));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) AttachmentReference(org.xwiki.model.reference.AttachmentReference) EntityReferenceValueProvider(org.xwiki.model.reference.EntityReferenceValueProvider) SkinAccessBridge(org.xwiki.bridge.SkinAccessBridge) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) Mockery(org.jmock.Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) EntityReference(org.xwiki.model.reference.EntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 3 with SkinAccessBridge

use of org.xwiki.bridge.SkinAccessBridge in project xwiki-platform by xwiki.

the class XWikiWikiModelTest method getImageURLWhenIcon.

@Test
public void getImageURLWhenIcon() throws Exception {
    ResourceReference reference = new ResourceReference("iconname", ResourceType.ICON);
    SkinAccessBridge skinAccessBridge = this.mocker.getInstance((Type) SkinAccessBridge.class);
    when(skinAccessBridge.getIconURL("iconname")).thenReturn("/path/to/icon");
    assertEquals("/path/to/icon", this.mocker.getComponentUnderTest().getImageURL(reference, Collections.<String, String>emptyMap()));
}
Also used : SkinAccessBridge(org.xwiki.bridge.SkinAccessBridge) AttachmentResourceReference(org.xwiki.rendering.listener.reference.AttachmentResourceReference) ResourceReference(org.xwiki.rendering.listener.reference.ResourceReference) DocumentResourceReference(org.xwiki.rendering.listener.reference.DocumentResourceReference) Test(org.junit.Test)

Aggregations

SkinAccessBridge (org.xwiki.bridge.SkinAccessBridge)3 Expectations (org.jmock.Expectations)2 Mockery (org.jmock.Mockery)2 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)2 Test (org.junit.Test)1 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)1 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)1 AttachmentReference (org.xwiki.model.reference.AttachmentReference)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 EntityReference (org.xwiki.model.reference.EntityReference)1 EntityReferenceValueProvider (org.xwiki.model.reference.EntityReferenceValueProvider)1 AttachmentResourceReference (org.xwiki.rendering.listener.reference.AttachmentResourceReference)1 DocumentResourceReference (org.xwiki.rendering.listener.reference.DocumentResourceReference)1 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)1