Search in sources :

Example 51 with Mockery

use of org.jmock.Mockery in project xwiki-platform by xwiki.

the class IntegrationTests method initialize.

@RenderingTestSuite.Initialized
public void initialize(MockingComponentManager cm) throws Exception {
    Mockery mockery = new JUnit4Mockery();
    new ScriptMockSetup(mockery, cm);
    // fake nested script validator never fails
    final EventListener nestedValidator = cm.registerMockComponent(mockery, EventListener.class, "nestedscriptmacrovalidator");
    mockery.checking(new Expectations() {

        {
            atLeast(1).of(nestedValidator).onEvent(with(any(Event.class)), with(any(MacroTransformationContext.class)), with(any(ScriptMacroParameters.class)));
            allowing(nestedValidator).getName();
            will(returnValue("nestedscriptmacrovalidator"));
            allowing(nestedValidator).getEvents();
            will(returnValue(Collections.singletonList((Event) new ScriptEvaluatingEvent())));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) ScriptEvaluatingEvent(org.xwiki.script.event.ScriptEvaluatingEvent) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) ScriptEvaluatingEvent(org.xwiki.script.event.ScriptEvaluatingEvent) Event(org.xwiki.observation.event.Event) EventListener(org.xwiki.observation.EventListener) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Mockery(org.jmock.Mockery)

Example 52 with Mockery

use of org.jmock.Mockery 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 53 with Mockery

use of org.jmock.Mockery 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 54 with Mockery

use of org.jmock.Mockery in project xwiki-platform by xwiki.

the class IntegrationTests method initialize.

@RenderingTestSuite.Initialized
public void initialize(MockingComponentManager componentManager) throws Exception {
    Mockery mockery = new JUnit4Mockery();
    final LocalizationManager localizationManager = componentManager.registerMockComponent(mockery, LocalizationManager.class);
    final LocalizationContext localizationContext = componentManager.registerMockComponent(mockery, LocalizationContext.class);
    mockery.checking(new Expectations() {

        {
            allowing(localizationManager).getTranslation("some.translation", Locale.ENGLISH);
            will(returnValue(new Translation() {

                @Override
                public Block render(Locale locale, Object... parameters) {
                    return parameters.length > 0 ? new WordBlock("entranslationmessage" + Arrays.toString(parameters)) : new WordBlock("entranslationmessage");
                }

                @Override
                public Block render(Object... parameters) {
                    return render(null, parameters);
                }

                @Override
                public String getRawSource() {
                    return "entranslationmessagesource";
                }

                @Override
                public Locale getLocale() {
                    return Locale.ENGLISH;
                }

                @Override
                public String getKey() {
                    return "some.translation";
                }

                @Override
                public TranslationBundle getBundle() {
                    return null;
                }
            }));
            allowing(localizationManager).getTranslation("some.translation", Locale.FRENCH);
            will(returnValue(new Translation() {

                @Override
                public Block render(Locale locale, Object... parameters) {
                    return parameters.length > 0 ? new WordBlock("frtranslationmessage" + Arrays.toString(parameters)) : new WordBlock("frtranslationmessage");
                }

                @Override
                public Block render(Object... parameters) {
                    return render(null, parameters);
                }

                @Override
                public String getRawSource() {
                    return "frtranslationmessagesource";
                }

                @Override
                public Locale getLocale() {
                    return Locale.FRENCH;
                }

                @Override
                public String getKey() {
                    return "some.translation";
                }

                @Override
                public TranslationBundle getBundle() {
                    return null;
                }
            }));
            allowing(localizationManager).getTranslation("unexisting.translation", Locale.ENGLISH);
            will(returnValue(null));
            allowing(localizationContext).getCurrentLocale();
            will(returnValue(Locale.ENGLISH));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) Locale(java.util.Locale) Translation(org.xwiki.localization.Translation) LocalizationContext(org.xwiki.localization.LocalizationContext) WordBlock(org.xwiki.rendering.block.WordBlock) Mockery(org.jmock.Mockery) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) LocalizationManager(org.xwiki.localization.LocalizationManager) TranslationBundle(org.xwiki.localization.TranslationBundle) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) WordBlock(org.xwiki.rendering.block.WordBlock) Block(org.xwiki.rendering.block.Block)

Example 55 with Mockery

use of org.jmock.Mockery in project xwiki-platform by xwiki.

the class IntegrationTests method initialize.

@RenderingTestSuite.Initialized
public void initialize(ComponentManager componentManager) throws Exception {
    Mockery mockery = new JUnit4Mockery();
    // Attachment Reference Resolver Mock
    final AttachmentReferenceResolver<String> mockResolver = mockery.mock(AttachmentReferenceResolver.class);
    mockery.checking(new Expectations() {

        {
            allowing(mockResolver).resolve("Space.ExistingPage@my.png");
            will(returnValue(new AttachmentReference("my.png", new DocumentReference("wiki", "Space", "ExistingPage"))));
        }
    });
    DefaultComponentDescriptor<AttachmentReferenceResolver<String>> descriptorARS = new DefaultComponentDescriptor<AttachmentReferenceResolver<String>>();
    descriptorARS.setRoleType(AttachmentReferenceResolver.TYPE_STRING);
    descriptorARS.setRoleHint("current");
    componentManager.registerComponent(descriptorARS, mockResolver);
    // WikiModel Mock
    componentManager.registerComponent(MockWikiModel.getComponentDescriptor());
}
Also used : Expectations(org.jmock.Expectations) AttachmentReference(org.xwiki.model.reference.AttachmentReference) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) AttachmentReferenceResolver(org.xwiki.model.reference.AttachmentReferenceResolver) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Mockery(org.jmock.Mockery) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

Mockery (org.jmock.Mockery)148 Expectations (org.jmock.Expectations)118 Test (org.junit.Test)77 Before (org.junit.Before)28 ArrayList (java.util.ArrayList)24 Date (java.util.Date)21 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)17 File (java.io.File)15 BeforeMethod (org.testng.annotations.BeforeMethod)15 Synchroniser (org.jmock.lib.concurrent.Synchroniser)14 List (java.util.List)11 ActorDTO (com.management.dto.ActorDTO)7 FanZoneDTO (com.management.dto.FanZoneDTO)6 PropsDTO (com.management.dto.PropsDTO)6 ActorPerformancesRepository (com.management.repositories.ActorPerformancesRepository)6 ActorRepository (com.management.repositories.ActorRepository)6 CinemaTheatreRepository (com.management.repositories.CinemaTheatreRepository)6 EventRepository (com.management.repositories.EventRepository)6 FriendsListRepository (com.management.repositories.FriendsListRepository)6 PerformanceRepository (com.management.repositories.PerformanceRepository)6