Search in sources :

Example 76 with DefaultParameterizedType

use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.

the class FilesystemResourceReferenceSerializerTest method serializeWithCSSPathAdjustmentsWithDocParentLevels.

@Test
public void serializeWithCSSPathAdjustmentsWithDocParentLevels() throws Exception {
    FilesystemExportContext exportContext = new FilesystemExportContext();
    exportContext.setExportDir(BASEDIR);
    exportContext.setDocParentLevels(2);
    Provider<FilesystemExportContext> exportContextProvider = this.mocker.getInstance(new DefaultParameterizedType(null, Provider.class, FilesystemExportContext.class));
    Mockito.when(exportContextProvider.get()).thenReturn(exportContext);
    WebJarsResourceReference reference = new WebJarsResourceReference("wiki:wiki", Arrays.asList("font-awesome", "4.7.0", "fonts/FontAwesome.otf"));
    // Verify that the returned URL is ok
    assertEquals("../../webjars/font-awesome/4.7.0/fonts/FontAwesome.otf", this.mocker.getComponentUnderTest().serialize(reference).serialize());
    // Also verify that the resource has been copied!
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/fonts/FontAwesome.otf").exists());
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) FilesystemExportContext(org.xwiki.url.filesystem.FilesystemExportContext) File(java.io.File) Provider(javax.inject.Provider) Test(org.junit.Test)

Example 77 with DefaultParameterizedType

use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.

the class NotificationPreferenceScriptServiceTest method setUp.

@Before
public void setUp() throws Exception {
    notificationPreferenceManager = mocker.getInstance(NotificationPreferenceManager.class);
    documentAccessBridge = mocker.getInstance(DocumentAccessBridge.class);
    authorizationManager = mocker.getInstance(ContextualAuthorizationManager.class);
    targetableNotificationPreferenceBuilderProvider = mock(Provider.class);
    when(targetableNotificationPreferenceBuilderProvider.get()).thenReturn(new DefaultTargetableNotificationPreferenceBuilder());
    mocker.registerComponent(new DefaultParameterizedType(null, Provider.class, TargetableNotificationPreferenceBuilder.class), targetableNotificationPreferenceBuilderProvider);
}
Also used : ContextualAuthorizationManager(org.xwiki.security.authorization.ContextualAuthorizationManager) NotificationPreferenceManager(org.xwiki.notifications.preferences.NotificationPreferenceManager) DefaultTargetableNotificationPreferenceBuilder(org.xwiki.notifications.preferences.internal.DefaultTargetableNotificationPreferenceBuilder) DefaultTargetableNotificationPreferenceBuilder(org.xwiki.notifications.preferences.internal.DefaultTargetableNotificationPreferenceBuilder) TargetableNotificationPreferenceBuilder(org.xwiki.notifications.preferences.TargetableNotificationPreferenceBuilder) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Provider(javax.inject.Provider) Before(org.junit.Before)

Example 78 with DefaultParameterizedType

use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.

the class DBListClass method getDBList.

public List<ListItem> getDBList(XWikiContext context) {
    List<ListItem> list = getCachedDBList(context);
    if (list == null) {
        try {
            DefaultParameterizedType dbListQueryBuilderType = new DefaultParameterizedType(null, QueryBuilder.class, DBListClass.class);
            QueryBuilder<DBListClass> dbListQueryBuilder = Utils.getComponent(dbListQueryBuilderType);
            // Execute the query with the rights of the class last author.
            AuthorExecutor authorExecutor = Utils.getComponent(AuthorExecutor.class);
            list = makeList(authorExecutor.call(() -> {
                return dbListQueryBuilder.build(this).execute();
            }, getOwnerDocument().getAuthorReference()));
        } catch (Exception e) {
            LOGGER.warn("Failed to get the Database List values. Root cause is [{}].", ExceptionUtils.getRootCauseMessage(e));
            list = new ArrayList<>();
        }
        setCachedDBList(list, context);
    }
    return list;
}
Also used : AuthorExecutor(org.xwiki.security.authorization.AuthorExecutor) ArrayList(java.util.ArrayList) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Example 79 with DefaultParameterizedType

use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.

the class DefaultDBListQueryBuilderTest method build.

@Test
public void build() throws Exception {
    DBListClass dbListClass = new DBListClass();
    DefaultParameterizedType dbListQueryBuilderType = new DefaultParameterizedType(null, QueryBuilder.class, DBListClass.class);
    QueryBuilder<DBListClass> explicitlyAllowedValuesQueryBuilder = this.mocker.getInstance(dbListQueryBuilderType, "explicitlyAllowedValues");
    QueryBuilder<DBListClass> implicitlyAllowedValuesQueryBuilder = this.mocker.getInstance(dbListQueryBuilderType, "implicitlyAllowedValues");
    Query explicitlyAllowedValuesQuery = mock(Query.class, "explicit");
    when(explicitlyAllowedValuesQueryBuilder.build(dbListClass)).thenReturn(explicitlyAllowedValuesQuery);
    Query implicitlyAllowedValuesQuery = mock(Query.class, "implicit");
    when(implicitlyAllowedValuesQueryBuilder.build(dbListClass)).thenReturn(implicitlyAllowedValuesQuery);
    assertSame(implicitlyAllowedValuesQuery, this.mocker.getComponentUnderTest().build(dbListClass));
    dbListClass.setSql("test");
    assertSame(explicitlyAllowedValuesQuery, this.mocker.getComponentUnderTest().build(dbListClass));
}
Also used : DBListClass(com.xpn.xwiki.objects.classes.DBListClass) Query(org.xwiki.query.Query) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Test(org.junit.Test)

Example 80 with DefaultParameterizedType

use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.

the class WikiTemplateMigrationTest method setUp.

@Before
public void setUp() throws Exception {
    wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    queryManager = mocker.getInstance(QueryManager.class);
    // documentReferenceResolver = mocker.getInstance(DocumentReferenceResolver.TYPE_STRING, "current");
    documentReferenceResolver = mocker.getInstance(new DefaultParameterizedType(null, DocumentReferenceResolver.class, String.class));
    execution = mock(Execution.class);
    mocker.registerComponent(Execution.class, execution);
    xcontext = mock(XWikiContext.class);
    xwiki = mock(XWiki.class);
    ExecutionContext executionContext = mock(ExecutionContext.class);
    when(execution.getContext()).thenReturn(executionContext);
    when(executionContext.getProperty("xwikicontext")).thenReturn(xcontext);
    when(xcontext.getWiki()).thenReturn(xwiki);
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWiki");
    query = mock(Query.class);
    when(queryManager.createQuery(any(), eq(Query.XWQL))).thenReturn(query);
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) Query(org.xwiki.query.Query) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) QueryManager(org.xwiki.query.QueryManager) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Before(org.junit.Before)

Aggregations

DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)104 Test (org.junit.Test)44 Before (org.junit.Before)32 Provider (javax.inject.Provider)27 DocumentReference (org.xwiki.model.reference.DocumentReference)24 XWikiContext (com.xpn.xwiki.XWikiContext)19 ComponentManager (org.xwiki.component.manager.ComponentManager)19 ExecutionContext (org.xwiki.context.ExecutionContext)17 ExtendedURL (org.xwiki.url.ExtendedURL)15 Execution (org.xwiki.context.Execution)14 HashMap (java.util.HashMap)13 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)13 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)12 ResourceReferenceSerializer (org.xwiki.resource.ResourceReferenceSerializer)10 VfsResourceReference (org.xwiki.vfs.VfsResourceReference)10 Properties (java.util.Properties)9 MimeBodyPartFactory (org.xwiki.mail.MimeBodyPartFactory)9 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)8 XWiki (com.xpn.xwiki.XWiki)7 File (java.io.File)7