Search in sources :

Example 11 with EntityReferenceProvider

use of org.xwiki.model.reference.EntityReferenceProvider in project xwiki-platform by xwiki.

the class DocumentTitleDisplayerTest method whenSettingTheContextDocumentTheContextWikiIsAlsoSet.

@Test
public void whenSettingTheContextDocumentTheContextWikiIsAlsoSet() throws Exception {
    EntityReferenceProvider defaultEntityReferenceProvider = this.mocker.getInstance(EntityReferenceProvider.class);
    when(defaultEntityReferenceProvider.getDefaultReference(EntityType.DOCUMENT)).thenReturn(new EntityReference("Page", EntityType.DOCUMENT));
    DocumentModelBridge document = mock(DocumentModelBridge.class);
    DocumentReference documentReference = new DocumentReference("wiki", Arrays.asList("Space"), "Page");
    when(document.getDocumentReference()).thenReturn(documentReference);
    when(document.getTitle()).thenReturn("title");
    XDOM titleXDOM = new XDOM(Arrays.asList(new WordBlock("title")));
    Parser plainTextParser = this.mocker.getInstance(Parser.class, "plain/1.0");
    when(plainTextParser.parse(any(StringReader.class))).thenReturn(titleXDOM);
    ModelContext modelContext = this.mocker.getInstance(ModelContext.class);
    WikiReference currentWikiReference = new WikiReference("currentWiki");
    when(modelContext.getCurrentEntityReference()).thenReturn(currentWikiReference);
    AuthorizationManager authorizationManager = this.mocker.getInstance(AuthorizationManager.class);
    when(authorizationManager.hasAccess(eq(Right.SCRIPT), any(), any())).thenReturn(true);
    DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
    DocumentDisplayerParameters params = new DocumentDisplayerParameters();
    params.setTitleDisplayed(true);
    params.setExecutionContextIsolated(true);
    this.mocker.getComponentUnderTest().display(document, params);
    // Check that the context is set.
    verify(dab).pushDocumentInContext(any(), eq(documentReference));
    verify(modelContext).setCurrentEntityReference(documentReference.getWikiReference());
    // Check that the context is restored.
    verify(dab).popDocumentFromContext(any());
    verify(modelContext).setCurrentEntityReference(currentWikiReference);
}
Also used : XDOM(org.xwiki.rendering.block.XDOM) WordBlock(org.xwiki.rendering.block.WordBlock) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) Parser(org.xwiki.rendering.parser.Parser) ModelContext(org.xwiki.model.ModelContext) EntityReferenceProvider(org.xwiki.model.reference.EntityReferenceProvider) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) EntityReference(org.xwiki.model.reference.EntityReference) StringReader(java.io.StringReader) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 12 with EntityReferenceProvider

use of org.xwiki.model.reference.EntityReferenceProvider in project xwiki-platform by xwiki.

the class DefaultReferenceEntityReferenceResolverTest method setUp.

@Before
public void setUp() throws Exception {
    this.resolver = this.mocker.getComponentUnderTest();
    EntityReferenceProvider referenceProvider = mock(EntityReferenceProvider.class);
    ReflectionUtils.setFieldValue(this.resolver, "provider", referenceProvider);
    when(referenceProvider.getDefaultReference(EntityType.WIKI)).thenReturn(DEFAULT_WIKI_REFERENCE);
    when(referenceProvider.getDefaultReference(EntityType.SPACE)).thenReturn(DEFAULT_SPACE_REFERENCE);
    when(referenceProvider.getDefaultReference(EntityType.DOCUMENT)).thenReturn(DEFAULT_PAGE_REFERENCE);
    when(referenceProvider.getDefaultReference(EntityType.OBJECT)).thenReturn(DEFAULT_OBJECT_REFERENCE);
    when(referenceProvider.getDefaultReference(EntityType.OBJECT_PROPERTY)).thenReturn(DEFAULT_OBJECT_PROPERTY_REFERENCE);
}
Also used : EntityReferenceProvider(org.xwiki.model.reference.EntityReferenceProvider) Before(org.junit.Before)

Example 13 with EntityReferenceProvider

use of org.xwiki.model.reference.EntityReferenceProvider in project xwiki-platform by xwiki.

the class XWikiLinkLabelGeneratorTest method setUp.

@Before
public void setUp() throws Exception {
    RenderingConfiguration configuration = this.mocker.getInstance(RenderingConfiguration.class);
    when(configuration.getLinkLabelFormat()).thenReturn("%l%la%n%na%N%NA [%w:%s.%p] %ls %np %P %NP (%t) [%w:%s.%p] %ls %np %P %NP (%t)");
    EntityReferenceProvider entityReferenceProvider = this.mocker.getInstance(EntityReferenceProvider.class);
    when(entityReferenceProvider.getDefaultReference(EntityType.DOCUMENT)).thenReturn(new EntityReference("WebHome", EntityType.DOCUMENT));
}
Also used : EntityReferenceProvider(org.xwiki.model.reference.EntityReferenceProvider) EntityReference(org.xwiki.model.reference.EntityReference) RenderingConfiguration(org.xwiki.rendering.configuration.RenderingConfiguration) Before(org.junit.Before)

Example 14 with EntityReferenceProvider

use of org.xwiki.model.reference.EntityReferenceProvider in project xwiki-platform by xwiki.

the class CurrentUserAndGroupDocumentReferenceResolverTest method afterComponent.

@AfterComponent
public void afterComponent() throws Exception {
    EntityReferenceProvider provider = this.mocker.registerMockComponent(EntityReferenceProvider.class, "current");
    when(provider.getDefaultReference(EntityType.WIKI)).thenReturn(new WikiReference("currentwiki"));
}
Also used : EntityReferenceProvider(org.xwiki.model.reference.EntityReferenceProvider) WikiReference(org.xwiki.model.reference.WikiReference) AfterComponent(org.xwiki.test.annotation.AfterComponent)

Example 15 with EntityReferenceProvider

use of org.xwiki.model.reference.EntityReferenceProvider in project xwiki-platform by xwiki.

the class X509CertificateWikiStoreTest method setUp.

@Before
public void setUp() throws Exception {
    EntityReferenceProvider valueProvider = mock(EntityReferenceProvider.class);
    when(valueProvider.getDefaultReference(EntityType.WIKI)).thenReturn(WIKI_REFERENCE);
    when(valueProvider.getDefaultReference(EntityType.SPACE)).thenReturn(SPACE_REFERENCE);
    when(valueProvider.getDefaultReference(EntityType.DOCUMENT)).thenReturn(DOCUMENT_REFERENCE);
    mocker.registerComponent(EntityReferenceProvider.class, "current", valueProvider);
    Provider<XWikiContext> xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    xcontext = mock(XWikiContext.class);
    when(xcontextProvider.get()).thenReturn(xcontext);
    xwiki = mock(com.xpn.xwiki.XWiki.class);
    when(xcontext.getWiki()).thenReturn(xwiki);
    BinaryStringEncoder encoder = mocker.getInstance(BinaryStringEncoder.class, "Base64");
    when(encoder.encode(CERTIFICATE, 64)).thenReturn(ENCODED_CERTIFICATE);
    when(encoder.decode(ENCODED_CERTIFICATE)).thenReturn(CERTIFICATE);
    when(encoder.encode(SUBJECT_KEYID)).thenReturn(ENCODED_SUBJECTKEYID);
    when(encoder.decode(ENCODED_SUBJECTKEYID)).thenReturn(SUBJECT_KEYID);
    QueryManager queryManager = mocker.getInstance(QueryManager.class);
    query = mock(Query.class);
    when(query.bindValue(any(String.class), any())).thenReturn(query);
    when(query.setWiki(WIKI)).thenReturn(query);
    when(queryManager.createQuery(any(String.class), any(String.class))).thenReturn(query);
    store = mocker.getComponentUnderTest();
}
Also used : BinaryStringEncoder(org.xwiki.crypto.BinaryStringEncoder) EntityReferenceProvider(org.xwiki.model.reference.EntityReferenceProvider) AbstractX509StoreQuery(org.xwiki.crypto.store.wiki.internal.query.AbstractX509StoreQuery) Query(org.xwiki.query.Query) AbstractX509IssuerAndSerialQuery(org.xwiki.crypto.store.wiki.internal.query.AbstractX509IssuerAndSerialQuery) AbstractX509SubjectQuery(org.xwiki.crypto.store.wiki.internal.query.AbstractX509SubjectQuery) AbstractX509KeyIdentifierQuery(org.xwiki.crypto.store.wiki.internal.query.AbstractX509KeyIdentifierQuery) QueryManager(org.xwiki.query.QueryManager) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) Before(org.junit.Before)

Aggregations

EntityReferenceProvider (org.xwiki.model.reference.EntityReferenceProvider)16 Before (org.junit.Before)10 EntityReference (org.xwiki.model.reference.EntityReference)7 XWikiContext (com.xpn.xwiki.XWikiContext)4 DocumentReference (org.xwiki.model.reference.DocumentReference)4 WikiReference (org.xwiki.model.reference.WikiReference)4 XWiki (com.xpn.xwiki.XWiki)3 Test (org.junit.Test)3 BinaryStringEncoder (org.xwiki.crypto.BinaryStringEncoder)3 StringReader (java.io.StringReader)2 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)2 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)2 SpaceReference (org.xwiki.model.reference.SpaceReference)2 Query (org.xwiki.query.Query)2 QueryManager (org.xwiki.query.QueryManager)2 WordBlock (org.xwiki.rendering.block.WordBlock)2 XDOM (org.xwiki.rendering.block.XDOM)2 Parser (org.xwiki.rendering.parser.Parser)2 AuthorizationManager (org.xwiki.security.authorization.AuthorizationManager)2 AfterComponent (org.xwiki.test.annotation.AfterComponent)2