Search in sources :

Example 6 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class SerializedFilesMimeMessageFactoryTest method createMessageWhenNoExecution.

@Test
public void createMessageWhenNoExecution() throws Exception {
    Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(componentManagerProvider.get()).thenReturn(this.mocker);
    try {
        this.mocker.getComponentUnderTest().createMessage("batchId", null);
        fail("Should have thrown an exception");
    } catch (MessagingException expected) {
        assertEquals("Failed to find an Environment Component", expected.getMessage());
    }
}
Also used : MessagingException(javax.mail.MessagingException) ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Provider(javax.inject.Provider) Test(org.junit.Test)

Example 7 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class GroupMimeMessageFactoryTest method createMessageWhenNotExistingMimeMessageFactory.

@Test
public void createMessageWhenNotExistingMimeMessageFactory() throws Exception {
    DocumentReference groupReference = new DocumentReference("wiki", "space", "page");
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("hint", "factoryHint");
    parameters.put("source", "factorySource");
    Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(componentManagerProvider.get()).thenReturn(this.mocker);
    try {
        this.mocker.getComponentUnderTest().createMessage(groupReference, parameters);
        fail("Should have thrown an exception");
    } catch (MessagingException expected) {
        assertEquals("Failed to find a [MimeMessageFactory<MimeMessage>] for hint [factoryHint]", expected.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) MessagingException(javax.mail.MessagingException) ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentReference(org.xwiki.model.reference.DocumentReference) Provider(javax.inject.Provider) Test(org.junit.Test)

Example 8 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class MailStorageScriptServiceTest method setUp.

@Before
public void setUp() throws Exception {
    Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(componentManagerProvider.get()).thenReturn(this.mocker);
    Execution execution = this.mocker.getInstance(Execution.class);
    ExecutionContext executionContext = new ExecutionContext();
    when(execution.getContext()).thenReturn(executionContext);
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Provider(javax.inject.Provider) Before(org.junit.Before)

Example 9 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class UsersMimeMessageFactoryTest method createMessageWhenNotExistingMimeMessageFactory.

@Test
public void createMessageWhenNotExistingMimeMessageFactory() throws Exception {
    DocumentReference userReference = new DocumentReference("wiki", "space", "page");
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("hint", "factoryHint");
    parameters.put("source", "factoryHint");
    Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(componentManagerProvider.get()).thenReturn(this.mocker);
    try {
        this.mocker.getComponentUnderTest().createMessage(Arrays.asList(userReference), parameters);
        fail("Should have thrown an exception");
    } catch (MessagingException expected) {
        assertEquals("Failed to find a [MimeMessageFactory<MimeMessage>] for hint [factoryHint]", expected.getMessage());
    }
}
Also used : HashMap(java.util.HashMap) MessagingException(javax.mail.MessagingException) ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentReference(org.xwiki.model.reference.DocumentReference) Provider(javax.inject.Provider) Test(org.junit.Test)

Example 10 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class XWikiDocument method init.

private void init(DocumentReference reference) {
    // if the passed reference is null consider it points to the default reference
    if (reference == null) {
        setDocumentReference(Utils.<Provider<DocumentReference>>getComponent(DocumentReference.TYPE_PROVIDER).get());
    } else {
        setDocumentReference(reference);
    }
    this.updateDate = new Date();
    this.updateDate.setTime((this.updateDate.getTime() / 1000) * 1000);
    this.contentUpdateDate = new Date();
    this.contentUpdateDate.setTime((this.contentUpdateDate.getTime() / 1000) * 1000);
    this.creationDate = new Date();
    this.creationDate.setTime((this.creationDate.getTime() / 1000) * 1000);
    this.content = "";
    this.format = "";
    this.locale = Locale.ROOT;
    this.defaultLocale = Locale.ROOT;
    this.customClass = "";
    this.comment = "";
// Note: As there's no notion of an Empty document we don't set the original document
// field. Thus getOriginalDocument() may return null.
}
Also used : Date(java.util.Date) Provider(javax.inject.Provider) EntityReferenceProvider(org.xwiki.model.reference.EntityReferenceProvider)

Aggregations

Provider (javax.inject.Provider)53 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)23 Test (org.junit.Test)15 ComponentManager (org.xwiki.component.manager.ComponentManager)15 Before (org.junit.Before)11 HashMap (java.util.HashMap)9 File (java.io.File)7 FilesystemExportContext (org.xwiki.url.filesystem.FilesystemExportContext)7 ArrayList (java.util.ArrayList)6 XWikiContext (com.xpn.xwiki.XWikiContext)5 Map (java.util.Map)5 DocumentReference (org.xwiki.model.reference.DocumentReference)5 Maps (com.google.common.collect.Maps)4 Type (java.lang.reflect.Type)4 Query (org.graylog.plugins.views.search.Query)4 QueryResult (org.graylog.plugins.views.search.QueryResult)4 SearchJob (org.graylog.plugins.views.search.SearchJob)4 SearchType (org.graylog.plugins.views.search.SearchType)4 IndexLookup (org.graylog.plugins.views.search.elasticsearch.IndexLookup)4 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)4