Search in sources :

Example 41 with DefaultParameterizedType

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

the class AbstractListClassPropertyValuesProviderTest method addProperty.

protected void addProperty(String name, PropertyClass definition, boolean withQueryBuilders) throws Exception {
    XWiki xwiki = this.xcontext.getWiki();
    BaseClass xclass = this.classDocument.getXClass();
    ClassPropertyReference propertyReference = new ClassPropertyReference(name, this.classReference);
    when(xwiki.getDocument(propertyReference, this.xcontext)).thenReturn(this.classDocument);
    when(xclass.get(name)).thenReturn(definition);
    definition.setOwnerDocument(this.classDocument);
    if (withQueryBuilders) {
        DefaultParameterizedType allowedValuesQueryBuilderType = new DefaultParameterizedType(null, QueryBuilder.class, definition.getClass());
        QueryBuilder allowedValuesQueryBuilder = getMocker().getInstance(allowedValuesQueryBuilderType);
        when(allowedValuesQueryBuilder.build(definition)).thenReturn(this.allowedValuesQuery);
        if (definition instanceof ListClass) {
            DefaultParameterizedType usedValuesQueryBuilderType = new DefaultParameterizedType(null, QueryBuilder.class, ListClass.class);
            this.usedValuesQueryBuilder = getMocker().getInstance(usedValuesQueryBuilderType, "usedValues");
            when(this.usedValuesQueryBuilder.build((ListClass) definition)).thenReturn(this.usedValuesQuery);
        }
    }
}
Also used : ListClass(com.xpn.xwiki.objects.classes.ListClass) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) XWiki(com.xpn.xwiki.XWiki) QueryBuilder(org.xwiki.query.QueryBuilder) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference)

Example 42 with DefaultParameterizedType

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

the class FilesystemResourceReferenceSerializerTest method serializeCSSResourceWithURLsInIt.

@Test
public void serializeCSSResourceWithURLsInIt() throws Exception {
    FilesystemExportContext exportContext = new FilesystemExportContext();
    exportContext.setExportDir(BASEDIR);
    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", "css/font-awesome.min.css"));
    assertEquals("webjars/font-awesome/4.7.0/css/font-awesome.min.css", this.mocker.getComponentUnderTest().serialize(reference).serialize());
    // Also verify that the resources haves been copied!
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/css/font-awesome.min.css").exists());
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/fonts/fontawesome-webfont.eot").exists());
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2").exists());
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/fonts/fontawesome-webfont.woff").exists());
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/fonts/fontawesome-webfont.svg").exists());
    assertTrue(new File(BASEDIR, "webjars/font-awesome/4.7.0/fonts/fontawesome-webfont.ttf").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 43 with DefaultParameterizedType

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

the class FilesystemResourceReferenceSerializerTest method serializeWithCSSPathAdjustments.

@Test
public void serializeWithCSSPathAdjustments() throws Exception {
    FilesystemExportContext exportContext = new FilesystemExportContext();
    exportContext.setExportDir(BASEDIR);
    exportContext.pushCSSParentLevels(3);
    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 44 with DefaultParameterizedType

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

the class FilesystemResourceReferenceSerializerTest method serialize.

@Test
public void serialize() throws Exception {
    FilesystemExportContext exportContext = new FilesystemExportContext();
    exportContext.setExportDir(BASEDIR);
    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 45 with DefaultParameterizedType

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

the class WebJarsResourceReferenceSerializerTest method serialize.

@Test
public void serialize() throws Exception {
    URLNormalizer<ExtendedURL> normalizer = this.mocker.getInstance(new DefaultParameterizedType(null, URLNormalizer.class, ExtendedURL.class), "contextpath");
    Map<String, List<String>> parameters = new HashMap<>();
    parameters.put("key1", Arrays.asList("value1"));
    parameters.put("key2", Arrays.asList("value2", "value3"));
    ExtendedURL partialURL = new ExtendedURL(Arrays.asList("webjars", "namespace", "one", "two"), parameters);
    ExtendedURL expectedURL = new ExtendedURL(Arrays.asList("xwiki", "webjars", "namespace", "one", "two"), parameters);
    when(normalizer.normalize(partialURL)).thenReturn(expectedURL);
    WebJarsResourceReference reference = new WebJarsResourceReference("namespace", Arrays.asList("one", "two"));
    reference.addParameter("key1", "value1");
    reference.addParameter("key2", new String[] { "value2", "value3" });
    assertEquals(expectedURL, this.mocker.getComponentUnderTest().serialize(reference));
}
Also used : URLNormalizer(org.xwiki.url.URLNormalizer) HashMap(java.util.HashMap) List(java.util.List) ExtendedURL(org.xwiki.url.ExtendedURL) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Test(org.junit.Test)

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