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();
}
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));
}
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);
}
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);
}
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());
}
}
Aggregations