Search in sources :

Example 51 with DefaultParameterizedType

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

the class SignableMacroTest method setUp.

@Before
public void setUp() throws Exception {
    BeanManager beanManager = mocker.getInstance(BeanManager.class);
    when(beanManager.getBeanDescriptor(Object.class)).thenReturn(new DefaultBeanDescriptor(Object.class));
    store = mocker.registerMockComponent(SignatureStore.class);
    when(store.retrieve(BLOCK_REFERENCE)).thenReturn(SIGNATURE);
    BlockSignatureGenerator signer = mocker.registerMockComponent(BlockSignatureGenerator.class, "macro");
    when(signer.generate(BLOCK, PARAMETERS)).thenReturn(SIGNATURE);
    BlockSignatureVerifier verifier = mocker.registerMockComponent(BlockSignatureVerifier.class, "macro");
    when(verifier.verify(SIGNATURE, BLOCK, null)).thenReturn(VERIFIED);
    BlockReferenceResolver<Block> resolver = mocker.registerMockComponent(new DefaultParameterizedType(null, BlockReferenceResolver.class, Block.class), "currentsignedmacro");
    when(resolver.resolve(BLOCK)).thenReturn(BLOCK_REFERENCE);
    macro = mocker.getComponentUnderTest();
}
Also used : SignatureStore(org.xwiki.crypto.store.SignatureStore) BlockSignatureGenerator(org.xwiki.rendering.signature.BlockSignatureGenerator) DefaultBeanDescriptor(org.xwiki.properties.internal.DefaultBeanDescriptor) Block(org.xwiki.rendering.block.Block) MacroBlock(org.xwiki.rendering.block.MacroBlock) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) BeanManager(org.xwiki.properties.BeanManager) BlockSignatureVerifier(org.xwiki.rendering.signature.BlockSignatureVerifier) BlockReferenceResolver(org.xwiki.model.reference.BlockReferenceResolver) Before(org.junit.Before)

Example 52 with DefaultParameterizedType

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

the class SolrDocumentIteratorTest method configure.

@Before
public void configure() throws Exception {
    solr = mock(SolrInstance.class);
    Provider<SolrInstance> solrInstanceProvider = mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, SolrInstance.class));
    when(solrInstanceProvider.get()).thenReturn(solr);
    this.solrDocumentReferenceResolver = this.mocker.getInstance(new DefaultParameterizedType(null, DocumentReferenceResolver.class, SolrDocument.class));
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) SolrInstance(org.xwiki.search.solr.internal.api.SolrInstance) Provider(javax.inject.Provider) Before(org.junit.Before)

Example 53 with DefaultParameterizedType

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

the class SolrQueryExecutorTest method configure.

@Before
public void configure() throws Exception {
    ParameterizedType solrProviderType = new DefaultParameterizedType(null, Provider.class, SolrInstance.class);
    Provider<SolrInstance> provider = this.componentManager.registerMockComponent(solrProviderType);
    when(provider.get()).thenReturn(this.solr);
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) SolrInstance(org.xwiki.search.solr.internal.api.SolrInstance) Before(org.junit.Before)

Example 54 with DefaultParameterizedType

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

the class SolrQueryExecutorTest method filterResponse.

@Test
public void filterResponse() throws Exception {
    ParameterizedType resolverType = new DefaultParameterizedType(null, DocumentReferenceResolver.class, SolrDocument.class);
    DocumentReferenceResolver<SolrDocument> resolver = this.componentManager.getInstance(resolverType);
    AuthorizationManager authorizationManager = this.componentManager.getInstance(AuthorizationManager.class);
    DocumentReference currentUserReference = new DocumentReference("xwiki", "XWiki", "currentuser");
    this.oldCore.getXWikiContext().setUserReference(currentUserReference);
    DocumentReference currentAuthorReference = new DocumentReference("xwiki", "XWiki", "currentauthor");
    XWikiDocument currentDocument = new XWikiDocument(currentAuthorReference);
    currentDocument.setContentAuthorReference(currentAuthorReference);
    this.oldCore.getXWikiContext().setDoc(currentDocument);
    DocumentReference aliceReference = new DocumentReference("wiki", "Users", "Alice");
    when(authorizationManager.hasAccess(Right.VIEW, currentAuthorReference, aliceReference)).thenReturn(true);
    SolrDocument alice = new SolrDocument();
    when(resolver.resolve(alice)).thenReturn(aliceReference);
    DocumentReference bobReference = new DocumentReference("wiki", "Users", "Bob");
    when(authorizationManager.hasAccess(Right.VIEW, currentUserReference, bobReference)).thenReturn(true);
    when(authorizationManager.hasAccess(Right.VIEW, currentAuthorReference, bobReference)).thenReturn(true);
    SolrDocument bob = new SolrDocument();
    when(resolver.resolve(bob)).thenReturn(bobReference);
    DocumentReference carolReference = new DocumentReference("wiki", "Users", "Carol");
    when(authorizationManager.hasAccess(Right.VIEW, currentUserReference, carolReference)).thenReturn(true);
    SolrDocument carol = new SolrDocument();
    when(resolver.resolve(carol)).thenReturn(carolReference);
    SolrDocumentList sourceResults = new SolrDocumentList();
    sourceResults.addAll(Arrays.asList(alice, bob, carol));
    sourceResults.setNumFound(3);
    QueryResponse response = mock(QueryResponse.class);
    when(this.solr.query(any(SolrParams.class))).thenReturn(response);
    DefaultQuery query = new DefaultQuery("", null);
    // No right check
    when(response.getResults()).thenReturn((SolrDocumentList) sourceResults.clone());
    SolrDocumentList results = ((QueryResponse) this.componentManager.getComponentUnderTest().execute(query).get(0)).getResults();
    assertEquals(Arrays.asList(alice, bob, carol), results);
    // Check current user right
    query.checkCurrentUser(true);
    when(response.getResults()).thenReturn((SolrDocumentList) sourceResults.clone());
    results = ((QueryResponse) this.componentManager.getComponentUnderTest().execute(query).get(0)).getResults();
    assertEquals(Arrays.asList(bob, carol), results);
    // Check both current user and author rights
    query.checkCurrentAuthor(true);
    when(response.getResults()).thenReturn((SolrDocumentList) sourceResults.clone());
    results = ((QueryResponse) this.componentManager.getComponentUnderTest().execute(query).get(0)).getResults();
    assertEquals(Arrays.asList(bob), results);
    // Check current author right
    query.checkCurrentUser(false);
    when(response.getResults()).thenReturn((SolrDocumentList) sourceResults.clone());
    results = ((QueryResponse) this.componentManager.getComponentUnderTest().execute(query).get(0)).getResults();
    assertEquals(Arrays.asList(alice, bob), results);
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) SolrDocument(org.apache.solr.common.SolrDocument) DefaultQuery(org.xwiki.query.internal.DefaultQuery) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrParams(org.apache.solr.common.params.SolrParams) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) SolrDocumentList(org.apache.solr.common.SolrDocumentList) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 55 with DefaultParameterizedType

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

the class StandardExtendedURLResourceReferenceSerializerTest method serializeWhenNoMatchingSerializer.

@Test
public void serializeWhenNoMatchingSerializer() throws Exception {
    TestResourceReference resource = new TestResourceReference();
    ComponentManager componentManager = this.mocker.getInstance(ComponentManager.class, "context");
    when(componentManager.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, TestResourceReference.class, ExtendedURL.class), "standard")).thenThrow(new ComponentLookupException("error"));
    when(componentManager.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, TestResourceReference.class, ExtendedURL.class))).thenThrow(new ComponentLookupException("error"));
    try {
        this.mocker.getComponentUnderTest().serialize(resource);
        fail("Should have thrown an exception here");
    } catch (UnsupportedResourceReferenceException expected) {
        assertEquals("Failed to find serializer for Resource Reference [type = [test], parameters = []] and " + "URL format [standard]", expected.getMessage());
    }
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) ResourceReferenceSerializer(org.xwiki.resource.ResourceReferenceSerializer) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) UnsupportedResourceReferenceException(org.xwiki.resource.UnsupportedResourceReferenceException) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) ExtendedURL(org.xwiki.url.ExtendedURL) 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