Search in sources :

Example 6 with BeforeComponent

use of org.xwiki.test.annotation.BeforeComponent in project xwiki-platform by xwiki.

the class IntegrationTest method setUpComponents.

@BeforeComponent
public void setUpComponents() throws Exception {
    // Isolate from xwiki configuration file
    URLConfiguration urlConfiguration = this.componentManager.registerMockComponent(URLConfiguration.class);
    when(urlConfiguration.getURLFormatId()).thenReturn("standard");
    // Isolate from xwiki configuration file
    StandardURLConfiguration standardURLConfiguration = this.componentManager.registerMockComponent(StandardURLConfiguration.class);
    when(standardURLConfiguration.getEntityPathPrefix()).thenReturn("bin");
    when(standardURLConfiguration.getWikiPathPrefix()).thenReturn("wiki");
    when(standardURLConfiguration.isViewActionHidden()).thenReturn(false);
    // Isolate from xwiki configuration file
    ModelConfiguration modelConfiguration = this.componentManager.registerMockComponent(ModelConfiguration.class);
    when(modelConfiguration.getDefaultReferenceValue(EntityType.WIKI)).thenReturn("xwiki");
    // Isolate from xwiki's model
    WikiDescriptorManager wikiDescriptorManager = this.componentManager.registerMockComponent(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("xwiki");
    // Isolate from Environment
    EntityResourceActionLister actionLister = this.componentManager.registerMockComponent(EntityResourceActionLister.class);
    when(actionLister.listActions()).thenReturn(Arrays.asList("view"));
    // Simulate a configured Execution Context
    Execution execution = this.componentManager.registerMockComponent(Execution.class);
    when(execution.getContext()).thenReturn(new ExecutionContext());
    // For test simplicity consider that Context CM == CM
    this.componentManager.registerComponent(ComponentManager.class, "context", this.componentManager);
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) URLConfiguration(org.xwiki.url.URLConfiguration) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ModelConfiguration(org.xwiki.model.ModelConfiguration) EntityResourceActionLister(org.xwiki.resource.internal.entity.EntityResourceActionLister) BeforeComponent(org.xwiki.test.annotation.BeforeComponent)

Example 7 with BeforeComponent

use of org.xwiki.test.annotation.BeforeComponent in project xwiki-platform by xwiki.

the class CascadingVfsPermissionCheckerTest method beforeComponent.

@BeforeComponent
public void beforeComponent() throws Exception {
    Provider<XWikiContext> provider = this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    XWikiContext xcontext = mock(XWikiContext.class);
    when(provider.get()).thenReturn(xcontext);
    when(xcontext.getUserReference()).thenReturn(contextUser);
}
Also used : XWikiContext(com.xpn.xwiki.XWikiContext) BeforeComponent(org.xwiki.test.annotation.BeforeComponent)

Example 8 with BeforeComponent

use of org.xwiki.test.annotation.BeforeComponent in project xwiki-platform by xwiki.

the class AuthenticatingIntegrationTest method registerConfiguration.

@BeforeComponent
public void registerConfiguration() throws Exception {
    Properties properties = new Properties();
    properties.setProperty("mail.smtp.starttls.enable", "true");
    // Required by GreenMail. When using XWiki with Gmail for example this is not required.
    properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    this.configuration = new TestMailSenderConfiguration(this.mail.getSmtps().getPort(), "peter", "password", properties);
    this.componentManager.registerComponent(MailSenderConfiguration.class, this.configuration);
    // Set the current wiki in the Context
    ModelContext modelContext = this.componentManager.registerMockComponent(ModelContext.class);
    when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("wiki"));
    Provider<XWikiContext> xwikiContextProvider = this.componentManager.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    when(xwikiContextProvider.get()).thenReturn(Mockito.mock(XWikiContext.class));
    this.componentManager.registerMockComponent(ExecutionContextManager.class);
    this.componentManager.registerMockComponent(Execution.class);
    this.componentManager.registerMockComponent(new DefaultParameterizedType(null, Copier.class, ExecutionContext.class));
    EnvironmentConfiguration environmentConfiguration = this.componentManager.registerMockComponent(EnvironmentConfiguration.class);
    when(environmentConfiguration.getPermanentDirectoryPath()).thenReturn(System.getProperty("java.io.tmpdir"));
}
Also used : ModelContext(org.xwiki.model.ModelContext) ExecutionContext(org.xwiki.context.ExecutionContext) EnvironmentConfiguration(org.xwiki.environment.internal.EnvironmentConfiguration) Copier(org.xwiki.mail.internal.thread.context.Copier) XWikiContext(com.xpn.xwiki.XWikiContext) Properties(java.util.Properties) WikiReference(org.xwiki.model.reference.WikiReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) BeforeComponent(org.xwiki.test.annotation.BeforeComponent)

Example 9 with BeforeComponent

use of org.xwiki.test.annotation.BeforeComponent in project xwiki-platform by xwiki.

the class ScriptingIntegrationTest method registerConfiguration.

@BeforeComponent
public void registerConfiguration() throws Exception {
    MailSenderConfiguration configuration = new TestMailSenderConfiguration(this.mail.getSmtp().getPort(), null, null, new Properties());
    this.componentManager.registerComponent(MailSenderConfiguration.class, configuration);
    // Register a test Permission Checker that allows sending mails
    ScriptServicePermissionChecker checker = mock(ScriptServicePermissionChecker.class);
    this.componentManager.registerComponent(ScriptServicePermissionChecker.class, "test", checker);
    // Set the current wiki in the Context
    ModelContext modelContext = this.componentManager.registerMockComponent(ModelContext.class);
    Mockito.when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("wiki"));
    Provider<XWikiContext> xwikiContextProvider = this.componentManager.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    when(xwikiContextProvider.get()).thenReturn(Mockito.mock(XWikiContext.class));
    this.componentManager.registerMockComponent(ExecutionContextManager.class);
    this.componentManager.registerMockComponent(new DefaultParameterizedType(null, Copier.class, ExecutionContext.class));
    EnvironmentConfiguration environmentConfiguration = this.componentManager.registerMockComponent(EnvironmentConfiguration.class);
    when(environmentConfiguration.getPermanentDirectoryPath()).thenReturn(System.getProperty("java.io.tmpdir"));
    this.componentManager.registerMockComponent(ConverterManager.class);
}
Also used : ModelContext(org.xwiki.model.ModelContext) ExecutionContext(org.xwiki.context.ExecutionContext) EnvironmentConfiguration(org.xwiki.environment.internal.EnvironmentConfiguration) Copier(org.xwiki.mail.internal.thread.context.Copier) XWikiContext(com.xpn.xwiki.XWikiContext) Properties(java.util.Properties) WikiReference(org.xwiki.model.reference.WikiReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) ScriptServicePermissionChecker(org.xwiki.mail.script.ScriptServicePermissionChecker) MailSenderConfiguration(org.xwiki.mail.MailSenderConfiguration) BeforeComponent(org.xwiki.test.annotation.BeforeComponent)

Example 10 with BeforeComponent

use of org.xwiki.test.annotation.BeforeComponent in project xwiki-platform by xwiki.

the class SolrReferenceResolverTest method registerComponents.

@BeforeComponent
public void registerComponents() throws Exception {
    this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    this.mocker.registerMockComponent(QueryManager.class);
    WikiDescriptorManager wikiDescriptorManager = this.mocker.registerMockComponent(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getAllIds()).thenReturn(Arrays.asList(wikiReference1.getName(), wikiReference2.getName()));
}
Also used : WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) BeforeComponent(org.xwiki.test.annotation.BeforeComponent)

Aggregations

BeforeComponent (org.xwiki.test.annotation.BeforeComponent)10 XWikiContext (com.xpn.xwiki.XWikiContext)4 ExecutionContext (org.xwiki.context.ExecutionContext)4 Properties (java.util.Properties)3 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)3 EnvironmentConfiguration (org.xwiki.environment.internal.EnvironmentConfiguration)3 Copier (org.xwiki.mail.internal.thread.context.Copier)3 ModelContext (org.xwiki.model.ModelContext)3 WikiReference (org.xwiki.model.reference.WikiReference)3 CacheManager (org.xwiki.cache.CacheManager)2 CacheConfiguration (org.xwiki.cache.config.CacheConfiguration)2 EntityResourceActionLister (org.xwiki.resource.internal.entity.EntityResourceActionLister)2 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)2 RenderingCache (com.xpn.xwiki.internal.cache.rendering.RenderingCache)1 File (java.io.File)1 Cache (org.xwiki.cache.Cache)1 Execution (org.xwiki.context.Execution)1 Environment (org.xwiki.environment.Environment)1 MailSenderConfiguration (org.xwiki.mail.MailSenderConfiguration)1 ScriptServicePermissionChecker (org.xwiki.mail.script.ScriptServicePermissionChecker)1