Search in sources :

Example 1 with EntityResourceActionLister

use of org.xwiki.resource.internal.entity.EntityResourceActionLister in project xwiki-platform by xwiki.

the class XWikiServletURLFactoryTest method beforeComponent.

@BeforeComponent
public void beforeComponent() throws Exception {
    EntityResourceActionLister actionLister = this.oldcore.getMocker().registerMockComponent(EntityResourceActionLister.class);
    when(actionLister.listActions()).thenReturn(Arrays.asList("view"));
}
Also used : EntityResourceActionLister(org.xwiki.resource.internal.entity.EntityResourceActionLister) BeforeComponent(org.xwiki.test.annotation.BeforeComponent)

Example 2 with EntityResourceActionLister

use of org.xwiki.resource.internal.entity.EntityResourceActionLister in project xwiki-platform by xwiki.

the class StandardExtendedURLResourceTypeResolver method registerEntityResourceReferenceResolver.

private void registerEntityResourceReferenceResolver(String registrationHint, Class<? extends ResourceReferenceResolver<ExtendedURL>> registrationImplementation, String wikiExtractorHint) throws InitializationException {
    DefaultComponentDescriptor<ResourceReferenceResolver<ExtendedURL>> resolverDescriptor = new DefaultComponentDescriptor<>();
    resolverDescriptor.setImplementation(registrationImplementation);
    resolverDescriptor.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON);
    String hint = computeHint(registrationHint);
    resolverDescriptor.setRoleHint(hint);
    resolverDescriptor.setRoleType(new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class));
    // Register dependencies
    DefaultComponentDependency<WikiReferenceExtractor> wikiReferenceExtractorDependency = new DefaultComponentDependency<>();
    wikiReferenceExtractorDependency.setRoleType(WikiReferenceExtractor.class);
    wikiReferenceExtractorDependency.setRoleHint(wikiExtractorHint);
    wikiReferenceExtractorDependency.setName("wikiExtractor");
    resolverDescriptor.addComponentDependency(wikiReferenceExtractorDependency);
    DefaultComponentDependency<EntityReferenceResolver<EntityReference>> entityReferenceResolverDependency = new DefaultComponentDependency<>();
    entityReferenceResolverDependency.setRoleType(new DefaultParameterizedType(null, EntityReferenceResolver.class, EntityReference.class));
    entityReferenceResolverDependency.setName("defaultReferenceEntityReferenceResolver");
    resolverDescriptor.addComponentDependency(entityReferenceResolverDependency);
    DefaultComponentDependency<StandardURLConfiguration> standardURLConfigurationDependency = new DefaultComponentDependency<>();
    standardURLConfigurationDependency.setRoleType(StandardURLConfiguration.class);
    standardURLConfigurationDependency.setName("configuration");
    resolverDescriptor.addComponentDependency(standardURLConfigurationDependency);
    DefaultComponentDependency<EntityResourceActionLister> entityResourceActionListerDependency = new DefaultComponentDependency<>();
    entityResourceActionListerDependency.setRoleType(EntityResourceActionLister.class);
    entityResourceActionListerDependency.setName("entityResourceActionLister");
    resolverDescriptor.addComponentDependency(entityResourceActionListerDependency);
    try {
        this.rootComponentManager.registerComponent(resolverDescriptor);
    } catch (ComponentRepositoryException e) {
        throw new InitializationException(String.format("Failed to dynamically register Resource Reference Resolver for hint [%s]", hint), e);
    }
}
Also used : DefaultComponentDependency(org.xwiki.component.descriptor.DefaultComponentDependency) EntityReferenceResolver(org.xwiki.model.reference.EntityReferenceResolver) BinEntityResourceReferenceResolver(org.xwiki.url.internal.standard.entity.BinEntityResourceReferenceResolver) ResourceReferenceResolver(org.xwiki.resource.ResourceReferenceResolver) WikiEntityResourceReferenceResolver(org.xwiki.url.internal.standard.entity.WikiEntityResourceReferenceResolver) ComponentRepositoryException(org.xwiki.component.manager.ComponentRepositoryException) ExtendedURL(org.xwiki.url.ExtendedURL) InitializationException(org.xwiki.component.phase.InitializationException) EntityResourceActionLister(org.xwiki.resource.internal.entity.EntityResourceActionLister) DefaultComponentDescriptor(org.xwiki.component.descriptor.DefaultComponentDescriptor) EntityReference(org.xwiki.model.reference.EntityReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Example 3 with EntityResourceActionLister

use of org.xwiki.resource.internal.entity.EntityResourceActionLister in project xwiki-platform by xwiki.

the class IntegrationTest method setUpComponents.

@BeforeComponent
public void setUpComponents() throws Exception {
    // Isolate from xwiki configuration file
    URLConfiguration urlConfiguration = this.componentManager.registerMockComponent(URLConfiguration.class);
    when(urlConfiguration.getURLFormatId()).thenReturn("standard");
    // Isolate from xwiki configuration file
    StandardURLConfiguration standardURLConfiguration = this.componentManager.registerMockComponent(StandardURLConfiguration.class);
    when(standardURLConfiguration.getEntityPathPrefix()).thenReturn("bin");
    when(standardURLConfiguration.getWikiPathPrefix()).thenReturn("wiki");
    when(standardURLConfiguration.isViewActionHidden()).thenReturn(false);
    // Isolate from xwiki configuration file
    ModelConfiguration modelConfiguration = this.componentManager.registerMockComponent(ModelConfiguration.class);
    when(modelConfiguration.getDefaultReferenceValue(EntityType.WIKI)).thenReturn("xwiki");
    // Isolate from xwiki's model
    WikiDescriptorManager wikiDescriptorManager = this.componentManager.registerMockComponent(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("xwiki");
    // Isolate from Environment
    EntityResourceActionLister actionLister = this.componentManager.registerMockComponent(EntityResourceActionLister.class);
    when(actionLister.listActions()).thenReturn(Arrays.asList("view"));
    // Simulate a configured Execution Context
    Execution execution = this.componentManager.registerMockComponent(Execution.class);
    when(execution.getContext()).thenReturn(new ExecutionContext());
    // For test simplicity consider that Context CM == CM
    this.componentManager.registerComponent(ComponentManager.class, "context", this.componentManager);
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) URLConfiguration(org.xwiki.url.URLConfiguration) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) ModelConfiguration(org.xwiki.model.ModelConfiguration) EntityResourceActionLister(org.xwiki.resource.internal.entity.EntityResourceActionLister) BeforeComponent(org.xwiki.test.annotation.BeforeComponent)

Aggregations

EntityResourceActionLister (org.xwiki.resource.internal.entity.EntityResourceActionLister)3 BeforeComponent (org.xwiki.test.annotation.BeforeComponent)2 DefaultComponentDependency (org.xwiki.component.descriptor.DefaultComponentDependency)1 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)1 ComponentRepositoryException (org.xwiki.component.manager.ComponentRepositoryException)1 InitializationException (org.xwiki.component.phase.InitializationException)1 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)1 Execution (org.xwiki.context.Execution)1 ExecutionContext (org.xwiki.context.ExecutionContext)1 ModelConfiguration (org.xwiki.model.ModelConfiguration)1 EntityReference (org.xwiki.model.reference.EntityReference)1 EntityReferenceResolver (org.xwiki.model.reference.EntityReferenceResolver)1 ResourceReferenceResolver (org.xwiki.resource.ResourceReferenceResolver)1 ExtendedURL (org.xwiki.url.ExtendedURL)1 URLConfiguration (org.xwiki.url.URLConfiguration)1 BinEntityResourceReferenceResolver (org.xwiki.url.internal.standard.entity.BinEntityResourceReferenceResolver)1 WikiEntityResourceReferenceResolver (org.xwiki.url.internal.standard.entity.WikiEntityResourceReferenceResolver)1 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)1