From d10dc905f6249617ed10dc0f88f9b9dd45b447e1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 02:58:02 +0000 Subject: [PATCH 1/4] Bump com.github.node-gradle.node from 7.0.0 to 7.0.1 Bumps com.github.node-gradle.node from 7.0.0 to 7.0.1. --- updated-dependencies: - dependency-name: com.github.node-gradle.node dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 4f4c79ae..62511b57 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ plugins { id 'com.enonic.defaults' version '2.1.2' id 'com.enonic.xp.app' version '3.4.0' - id 'com.github.node-gradle.node' version '7.0.0' + id 'com.github.node-gradle.node' version '7.0.1' id 'maven-publish' id 'jacoco' } From dbc7fe77c2d806e40757debdcfdf89983191e631 Mon Sep 17 00:00:00 2001 From: Anatol Sialitski Date: Thu, 5 Oct 2023 14:14:43 +0200 Subject: [PATCH 2/4] Big query optimization #567 --- package-lock.json | 4 +- .../app/guillotine/graphql/GraphQLApi.java | 11 ++- .../guillotine/graphql/GuillotineContext.java | 24 +++++++ .../factory/ComponentTypesFactory.java | 5 +- .../graphql/factory/ContentTypesFactory.java | 2 +- .../graphql/factory/FormItemTypesFactory.java | 6 +- .../graphql/factory/MacroTypesFactory.java | 3 +- .../graphql/factory/XDataTypesFactory.java | 19 +++-- .../graphql/fetchers/FormItemDataFetcher.java | 12 ++-- .../graphql/fetchers/RichTextDataFetcher.java | 16 ++--- .../graphql/BaseGraphQLIntegrationTest.java | 70 ++++++++++++------- .../RichTextGraphQLIntegrationTest.java | 29 -------- 12 files changed, 110 insertions(+), 91 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2f3a0657..f62a165d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9649,9 +9649,7 @@ "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", "dev": true, - "requires": { - "ajv": "^8.0.0" - } + "requires": {} }, "ajv-keywords": { "version": "5.1.0", diff --git a/src/main/java/com/enonic/app/guillotine/graphql/GraphQLApi.java b/src/main/java/com/enonic/app/guillotine/graphql/GraphQLApi.java index d4dc6a43..4f390b6a 100644 --- a/src/main/java/com/enonic/app/guillotine/graphql/GraphQLApi.java +++ b/src/main/java/com/enonic/app/guillotine/graphql/GraphQLApi.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -30,6 +31,7 @@ import com.enonic.app.guillotine.graphql.transformer.SchemaExtensions; import com.enonic.app.guillotine.mapper.ExecutionResultMapper; import com.enonic.xp.app.ApplicationService; +import com.enonic.xp.macro.MacroDescriptor; import com.enonic.xp.script.ScriptValue; import com.enonic.xp.script.bean.BeanContext; import com.enonic.xp.script.bean.ScriptBean; @@ -165,7 +167,8 @@ private GraphQLSchema createBaseGraphQLSchema() private void generateGuillotineApi( GraphQLTypesRegister typesRegister ) { - GuillotineContext context = GuillotineContext.create().addApplications( getApplicationNames() ).build(); + GuillotineContext context = + GuillotineContext.create().addApplications( getApplicationNames() ).addMacroDecorators( getRegisteredMacrosInSystem() ).build(); new TypeFactory( context, serviceFacadeSupplier.get() ).createTypes(); GraphQLObjectType guillotineApi = new HeadlessCmsTypeFactory( context, serviceFacadeSupplier.get() ).create(); @@ -227,4 +230,10 @@ private List getApplicationNames() application -> application.getKey().getName() ).collect( Collectors.toList() ); } + private Map getRegisteredMacrosInSystem() + { + return serviceFacadeSupplier.get().getMacroDescriptorService().getAll().stream().collect( + Collectors.toMap( MacroDescriptor::getName, Function.identity() ) ); + } + } diff --git a/src/main/java/com/enonic/app/guillotine/graphql/GuillotineContext.java b/src/main/java/com/enonic/app/guillotine/graphql/GuillotineContext.java index 37d80e39..2e500c15 100644 --- a/src/main/java/com/enonic/app/guillotine/graphql/GuillotineContext.java +++ b/src/main/java/com/enonic/app/guillotine/graphql/GuillotineContext.java @@ -1,10 +1,14 @@ package com.enonic.app.guillotine.graphql; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArrayList; +import com.google.common.collect.ImmutableMap; + import graphql.schema.DataFetcher; import graphql.schema.FieldCoordinates; import graphql.schema.GraphQLEnumType; @@ -14,6 +18,7 @@ import graphql.schema.GraphQLType; import graphql.schema.TypeResolver; +import com.enonic.xp.macro.MacroDescriptor; import com.enonic.xp.portal.PortalRequest; import com.enonic.xp.portal.PortalRequestAccessor; @@ -33,12 +38,15 @@ public class GuillotineContext private final CopyOnWriteArrayList applications; + private final ImmutableMap macroDecorators; + private final CopyOnWriteArrayList allowPaths; private GuillotineContext( final Builder builder ) { this.applications = builder.applications; this.allowPaths = builder.allowPaths; + this.macroDecorators = ImmutableMap.builder().putAll( builder.macroDecorators ).build(); } public boolean isGlobalMode() @@ -64,6 +72,11 @@ public List getAllowPaths() return allowPaths; } + public Map getMacroDecorators() + { + return macroDecorators; + } + public void registerType( String name, GraphQLType type ) { types.put( name, type ); @@ -149,6 +162,8 @@ public static final class Builder private final CopyOnWriteArrayList allowPaths = new CopyOnWriteArrayList<>(); + private final Map macroDecorators = new HashMap<>(); + public Builder() { @@ -172,6 +187,15 @@ public Builder addAllowPaths( final List allowPaths ) return this; } + public Builder addMacroDecorators( final Map macroDecorators ) + { + if ( macroDecorators != null ) + { + this.macroDecorators.putAll( macroDecorators ); + } + return this; + } + public GuillotineContext build() { return new GuillotineContext( this ); diff --git a/src/main/java/com/enonic/app/guillotine/graphql/factory/ComponentTypesFactory.java b/src/main/java/com/enonic/app/guillotine/graphql/factory/ComponentTypesFactory.java index 57d1cbf5..0962a109 100644 --- a/src/main/java/com/enonic/app/guillotine/graphql/factory/ComponentTypesFactory.java +++ b/src/main/java/com/enonic/app/guillotine/graphql/factory/ComponentTypesFactory.java @@ -152,7 +152,8 @@ private void createTextComponentDataType() context.registerDataFetcher( objectType.getName(), "value", environment -> { Map sourceAsMap = environment.getSource(); return new RichTextDataFetcher( CastHelper.cast( sourceAsMap.get( "value" ) ), - CastHelper.cast( sourceAsMap.get( "__contentId" ) ), serviceFacade ).get( environment ); + CastHelper.cast( sourceAsMap.get( "__contentId" ) ), serviceFacade, context ).get( + environment ); } ); context.registerType( objectType.getName(), objectType ); } @@ -271,7 +272,7 @@ private List createFormItemFields( FormItems formItems, GraphQLFieldDefinition field = outputField( fieldName, formItemObject, formItemTypesFactory.generateFormItemArguments( formItem ) ); - context.registerDataFetcher( typeName, fieldName, new FormItemDataFetcher( formItem, serviceFacade ) ); + context.registerDataFetcher( typeName, fieldName, new FormItemDataFetcher( formItem, serviceFacade, context ) ); resultFields.add( field ); } ); diff --git a/src/main/java/com/enonic/app/guillotine/graphql/factory/ContentTypesFactory.java b/src/main/java/com/enonic/app/guillotine/graphql/factory/ContentTypesFactory.java index ae1f5531..46ce3a85 100644 --- a/src/main/java/com/enonic/app/guillotine/graphql/factory/ContentTypesFactory.java +++ b/src/main/java/com/enonic/app/guillotine/graphql/factory/ContentTypesFactory.java @@ -207,7 +207,7 @@ private GraphQLObjectType generateContentDataType( String parentTypeName, String GraphQLFieldDefinition field = outputField( fieldName, formItemObject, formItemTypesFactory.generateFormItemArguments( formItem ) ); - context.registerDataFetcher( typeName, fieldName, new FormItemDataFetcher( formItem, serviceFacade ) ); + context.registerDataFetcher( typeName, fieldName, new FormItemDataFetcher( formItem, serviceFacade, context ) ); return field; } ).collect( Collectors.toList() ); diff --git a/src/main/java/com/enonic/app/guillotine/graphql/factory/FormItemTypesFactory.java b/src/main/java/com/enonic/app/guillotine/graphql/factory/FormItemTypesFactory.java index 5b2154fb..9a7feb93 100644 --- a/src/main/java/com/enonic/app/guillotine/graphql/factory/FormItemTypesFactory.java +++ b/src/main/java/com/enonic/app/guillotine/graphql/factory/FormItemTypesFactory.java @@ -90,7 +90,7 @@ private GraphQLType generateItemSetObjectType( String parentTypeName, FormItemSe GraphQLFieldDefinition field = outputField( fieldName, formItemObject, generateFormItemArguments( formItem ) ); - context.registerDataFetcher( typeName, fieldName, new FormItemDataFetcher( formItem, serviceFacade ) ); + context.registerDataFetcher( typeName, fieldName, new FormItemDataFetcher( formItem, serviceFacade, context ) ); return field; } ).collect( Collectors.toList() ); @@ -126,7 +126,7 @@ private GraphQLObjectType generateOptionSetObjectType( String parentTypeName, Fo fields.add( outputField( optionName, type ) ); - context.registerDataFetcher( typeName, optionName, new FormItemDataFetcher( option, serviceFacade ) ); + context.registerDataFetcher( typeName, optionName, new FormItemDataFetcher( option, serviceFacade, context ) ); } ); GraphQLObjectType objectType = newObject( context.uniqueName( typeName ), description, fields ); @@ -247,7 +247,7 @@ private GraphQLObjectType generateOptionSetObjectType( String parentTypeName, Fo GraphQLFieldDefinition field = outputField( fieldName, formItemObject, generateFormItemArguments( formItem ) ); - context.registerDataFetcher( typeName, fieldName, new FormItemDataFetcher( formItem, serviceFacade ) ); + context.registerDataFetcher( typeName, fieldName, new FormItemDataFetcher( formItem, serviceFacade, context ) ); return field; } ).collect( Collectors.toList() ); diff --git a/src/main/java/com/enonic/app/guillotine/graphql/factory/MacroTypesFactory.java b/src/main/java/com/enonic/app/guillotine/graphql/factory/MacroTypesFactory.java index 7d3e7546..3459185c 100644 --- a/src/main/java/com/enonic/app/guillotine/graphql/factory/MacroTypesFactory.java +++ b/src/main/java/com/enonic/app/guillotine/graphql/factory/MacroTypesFactory.java @@ -67,7 +67,8 @@ private void createMacroConfigType() GraphQLFieldDefinition field = outputField( fieldName, formItemObject, formItemTypesFactory.generateFormItemArguments( formItem ) ); - context.registerDataFetcher( macroDataConfigTypeName, fieldName, new FormItemDataFetcher( formItem, serviceFacade ) ); + context.registerDataFetcher( macroDataConfigTypeName, fieldName, + new FormItemDataFetcher( formItem, serviceFacade, context ) ); macroDataConfigFields.add( field ); } ); diff --git a/src/main/java/com/enonic/app/guillotine/graphql/factory/XDataTypesFactory.java b/src/main/java/com/enonic/app/guillotine/graphql/factory/XDataTypesFactory.java index 9db21035..c50d0506 100644 --- a/src/main/java/com/enonic/app/guillotine/graphql/factory/XDataTypesFactory.java +++ b/src/main/java/com/enonic/app/guillotine/graphql/factory/XDataTypesFactory.java @@ -66,10 +66,9 @@ public void create() if ( !xDataConfigFields.isEmpty() ) { GraphQLObjectType xDataConfigType = newObject( context.uniqueName( xDataConfigTypeName ), - "Extra data config for application ['" + - applicationKey + "}'] and descriptor ['" + - xData.getName().getLocalName() + "']", - xDataConfigFields ); + "Extra data config for application ['" + applicationKey + + "}'] and descriptor ['" + xData.getName().getLocalName() + "']", + xDataConfigFields ); context.registerType( xDataConfigType.getName(), xDataConfigType ); @@ -83,10 +82,9 @@ public void create() if ( !xDataApplicationTypeFields.isEmpty() ) { - GraphQLObjectType applicationConfigType = - newObject( context.uniqueName( xDataApplicationConfigTypeName ), - "XDataApplicationConfig for application ['" + applicationKey + "']", - xDataApplicationTypeFields ); + GraphQLObjectType applicationConfigType = newObject( context.uniqueName( xDataApplicationConfigTypeName ), + "XDataApplicationConfig for application ['" + applicationKey + + "']", xDataApplicationTypeFields ); GraphQLFieldDefinition xDataTypeField = outputField( StringNormalizer.create( applicationKey ), applicationConfigType ); xDataTypeFields.add( xDataTypeField ); @@ -99,8 +97,7 @@ public void create() if ( !xDataTypeFields.isEmpty() ) { - GraphQLObjectType extraDataType = - newObject( context.uniqueName( extraDataTypeName ), "Extra data.", xDataTypeFields ); + GraphQLObjectType extraDataType = newObject( context.uniqueName( extraDataTypeName ), "Extra data.", xDataTypeFields ); context.registerType( extraDataType.getName(), extraDataType ); } @@ -118,7 +115,7 @@ private List createFormItemFields( FormItems formItems, GraphQLFieldDefinition field = outputField( fieldName, formItemObject, formItemTypesFactory.generateFormItemArguments( formItem ) ); - context.registerDataFetcher( typeName, fieldName, new FormItemDataFetcher( formItem, serviceFacade ) ); + context.registerDataFetcher( typeName, fieldName, new FormItemDataFetcher( formItem, serviceFacade, context ) ); xDataConfigFields.add( field ); } ); diff --git a/src/main/java/com/enonic/app/guillotine/graphql/fetchers/FormItemDataFetcher.java b/src/main/java/com/enonic/app/guillotine/graphql/fetchers/FormItemDataFetcher.java index 64a0fe11..726fa04c 100644 --- a/src/main/java/com/enonic/app/guillotine/graphql/fetchers/FormItemDataFetcher.java +++ b/src/main/java/com/enonic/app/guillotine/graphql/fetchers/FormItemDataFetcher.java @@ -11,6 +11,7 @@ import com.enonic.app.guillotine.ServiceFacade; import com.enonic.app.guillotine.graphql.ArgumentsValidator; import com.enonic.app.guillotine.graphql.Constants; +import com.enonic.app.guillotine.graphql.GuillotineContext; import com.enonic.app.guillotine.graphql.commands.GetContentCommand; import com.enonic.app.guillotine.graphql.helper.ArrayHelper; import com.enonic.app.guillotine.graphql.helper.CastHelper; @@ -28,11 +29,14 @@ public class FormItemDataFetcher private final ServiceFacade serviceFacade; - public FormItemDataFetcher( final FormItem formItem, final ServiceFacade serviceFacade ) + private final GuillotineContext guillotineContext; + + public FormItemDataFetcher( final FormItem formItem, final ServiceFacade serviceFacade, final GuillotineContext guillotineContext ) { this.formItem = formItem; this.serviceFacade = serviceFacade; + this.guillotineContext = guillotineContext; } @Override @@ -54,7 +58,7 @@ public Object get( final DataFetchingEnvironment environment ) InputTypeName inputType = ( (Input) formItem ).getInputType(); if ( inputType.equals( InputTypeName.HTML_AREA ) ) { - return new RichTextDataFetcher( (String) value, contentId, serviceFacade ).execute( environment ); + return new RichTextDataFetcher( (String) value, contentId, serviceFacade, guillotineContext ).execute( environment ); } if ( inputType.equals( InputTypeName.ATTACHMENT_UPLOADER ) ) { @@ -89,8 +93,8 @@ public Object get( final DataFetchingEnvironment environment ) if ( inputType.equals( InputTypeName.HTML_AREA ) ) { return values.stream().map( - value -> new RichTextDataFetcher( (String) value, contentId, serviceFacade ).execute( environment ) ).collect( - Collectors.toList() ); + value -> new RichTextDataFetcher( (String) value, contentId, serviceFacade, guillotineContext ).execute( + environment ) ).collect( Collectors.toList() ); } if ( inputType.equals( InputTypeName.ATTACHMENT_UPLOADER ) ) { diff --git a/src/main/java/com/enonic/app/guillotine/graphql/fetchers/RichTextDataFetcher.java b/src/main/java/com/enonic/app/guillotine/graphql/fetchers/RichTextDataFetcher.java index 11b215e0..6f0de195 100644 --- a/src/main/java/com/enonic/app/guillotine/graphql/fetchers/RichTextDataFetcher.java +++ b/src/main/java/com/enonic/app/guillotine/graphql/fetchers/RichTextDataFetcher.java @@ -4,13 +4,13 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.function.Function; import java.util.stream.Collectors; import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; import com.enonic.app.guillotine.ServiceFacade; +import com.enonic.app.guillotine.graphql.GuillotineContext; import com.enonic.app.guillotine.graphql.helper.GuillotineLocalContextHelper; import com.enonic.app.guillotine.macro.CustomHtmlPostProcessor; import com.enonic.app.guillotine.macro.HtmlEditorProcessedResult; @@ -38,11 +38,15 @@ public class RichTextDataFetcher private final ServiceFacade serviceFacade; - public RichTextDataFetcher( final String htmlText, final String contentId, final ServiceFacade serviceFacade ) + private final GuillotineContext guillotineContext; + + public RichTextDataFetcher( final String htmlText, final String contentId, final ServiceFacade serviceFacade, + final GuillotineContext guillotineContext ) { this.htmlText = htmlText; this.contentId = contentId; this.serviceFacade = serviceFacade; + this.guillotineContext = guillotineContext; } public Object execute( final DataFetchingEnvironment environment ) @@ -70,7 +74,7 @@ public Object get( final DataFetchingEnvironment environment ) PortalRequest portalRequest = PortalRequestAccessor.get(); Map registeredMacros = - portalRequest.getSite() != null ? getRegisteredMacrosInSystemForSite( portalRequest ) : getRegisteredMacrosInSystem(); + portalRequest.getSite() != null ? getRegisteredMacrosInSystemForSite( portalRequest ) : guillotineContext.getMacroDecorators(); htmlParams.processMacros( false ); htmlParams.customHtmlProcessor( processor -> { @@ -152,10 +156,4 @@ private Map getRegisteredMacrosInSystemForSite( final P return result; } - - private Map getRegisteredMacrosInSystem() - { - return serviceFacade.getMacroDescriptorService().getAll().stream().collect( - Collectors.toMap( MacroDescriptor::getName, Function.identity() ) ); - } } diff --git a/src/test/java/com/enonic/app/guillotine/graphql/BaseGraphQLIntegrationTest.java b/src/test/java/com/enonic/app/guillotine/graphql/BaseGraphQLIntegrationTest.java index 9ab634bd..4cfa5ef4 100644 --- a/src/test/java/com/enonic/app/guillotine/graphql/BaseGraphQLIntegrationTest.java +++ b/src/test/java/com/enonic/app/guillotine/graphql/BaseGraphQLIntegrationTest.java @@ -28,6 +28,8 @@ import com.enonic.xp.context.Context; import com.enonic.xp.context.ContextAccessor; import com.enonic.xp.context.ContextBuilder; +import com.enonic.xp.macro.MacroDescriptorService; +import com.enonic.xp.macro.MacroService; import com.enonic.xp.portal.script.PortalScriptService; import com.enonic.xp.portal.url.PortalUrlService; import com.enonic.xp.resource.ResourceKey; @@ -41,6 +43,11 @@ import com.enonic.xp.security.auth.AuthenticationInfo; import com.enonic.xp.testing.ScriptTestSupport; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class BaseGraphQLIntegrationTest extends ScriptTestSupport { @@ -54,21 +61,21 @@ protected void initialize() { super.initialize(); - final BundleContext bundleContext = Mockito.mock( BundleContext.class ); + final BundleContext bundleContext = mock( BundleContext.class ); - final Bundle bundle = Mockito.mock( Bundle.class ); - Mockito.when( bundle.getBundleContext() ).thenReturn( bundleContext ); + final Bundle bundle = mock( Bundle.class ); + when( bundle.getBundleContext() ).thenReturn( bundleContext ); final Application application = createApplication( bundle ); - final ApplicationService applicationService = Mockito.mock( ApplicationService.class ); + final ApplicationService applicationService = mock( ApplicationService.class ); final Applications applications = Applications.from( application ); - Mockito.when( applicationService.getInstalledApplications() ).thenReturn( applications ); + when( applicationService.getInstalledApplications() ).thenReturn( applications ); - final PortalScriptService scriptService = Mockito.mock( PortalScriptService.class ); + final PortalScriptService scriptService = mock( PortalScriptService.class ); - Mockito.when( scriptService.execute( Mockito.any() ) ).thenAnswer( invocation -> { + when( scriptService.execute( any() ) ).thenAnswer( invocation -> { ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0]; return runScript( resourceKey ); } ); @@ -76,31 +83,40 @@ protected void initialize() final ExtensionsExtractorService extensionsExtractorService = new ExtensionsExtractorService( applicationService, getResourceService(), scriptService ); - this.serviceFacade = Mockito.mock( ServiceFacade.class ); + this.serviceFacade = mock( ServiceFacade.class ); - final ComponentDescriptorService componentDescriptorService = Mockito.mock( ComponentDescriptorService.class ); + final ComponentDescriptorService componentDescriptorService = mock( ComponentDescriptorService.class ); - Mockito.when( componentDescriptorService.getMacroDescriptors( Mockito.anyList() ) ).thenReturn( - BuiltinMacros.getSystemMacroDescriptors() ); + when( componentDescriptorService.getMacroDescriptors( Mockito.anyList() ) ).thenReturn( BuiltinMacros.getSystemMacroDescriptors() ); - Mockito.when( componentDescriptorService.getExtraData( Mockito.anyString() ) ).thenReturn( + when( componentDescriptorService.getExtraData( anyString() ) ).thenReturn( XDatas.from( TestFixtures.CAMERA_METADATA, TestFixtures.IMAGE_METADATA, TestFixtures.GPS_METADATA ) ); - final ContentTypeService contentTypeService = Mockito.mock( ContentTypeService.class ); + final ContentTypeService contentTypeService = mock( ContentTypeService.class ); + + when( contentTypeService.getAll() ).thenReturn( createContentTypes() ); + + PortalUrlService portalUrlService = mock( PortalUrlService.class ); - Mockito.when( contentTypeService.getAll() ).thenReturn( createContentTypes() ); + MacroDescriptorService macroDescriptorService = mock( MacroDescriptorService.class ); + MacroService macroService = mock( MacroService.class ); - PortalUrlService portalUrlService = Mockito.mock( PortalUrlService.class ); + when( serviceFacade.getComponentDescriptorService() ).thenReturn( componentDescriptorService ); + when( serviceFacade.getContentTypeService() ).thenReturn( contentTypeService ); + when( serviceFacade.getContentService() ).thenReturn( contentService ); + when( serviceFacade.getPortalUrlService() ).thenReturn( portalUrlService ); - Mockito.when( serviceFacade.getComponentDescriptorService() ).thenReturn( componentDescriptorService ); - Mockito.when( serviceFacade.getContentTypeService() ).thenReturn( contentTypeService ); - Mockito.when( serviceFacade.getContentService() ).thenReturn( contentService ); - Mockito.when( serviceFacade.getPortalUrlService() ).thenReturn( portalUrlService ); + when( macroDescriptorService.getAll() ).thenReturn( BuiltinMacros.getSystemMacroDescriptors() ); + when( serviceFacade.getMacroDescriptorService() ).thenReturn( macroDescriptorService ); + when( macroService.evaluateMacros( anyString(), any() ) ).thenReturn( "processedMacros" ); + when( serviceFacade.getMacroService() ).thenReturn( macroService ); addService( ServiceFacade.class, serviceFacade ); addService( ExtensionsExtractorService.class, extensionsExtractorService ); addService( ApplicationService.class, applicationService ); addService( PortalUrlService.class, portalUrlService ); + addService( MacroDescriptorService.class, macroDescriptorService ); + addService( MacroService.class, macroService ); createGraphQLApiBean(); } @@ -149,14 +165,14 @@ private ResourceService getResourceService() private Application createApplication( final Bundle bundle ) { - final Application application = Mockito.mock( Application.class ); - - Mockito.when( application.getKey() ).thenReturn( ApplicationKey.from( "myapplication" ) ); - Mockito.when( application.getVersion() ).thenReturn( Version.emptyVersion ); - Mockito.when( application.getBundle() ).thenReturn( bundle ); - Mockito.when( application.getClassLoader() ).thenReturn( getClass().getClassLoader() ); - Mockito.when( application.isStarted() ).thenReturn( true ); - Mockito.when( application.getConfig() ).thenReturn( ConfigBuilder.create().build() ); + final Application application = mock( Application.class ); + + when( application.getKey() ).thenReturn( ApplicationKey.from( "myapplication" ) ); + when( application.getVersion() ).thenReturn( Version.emptyVersion ); + when( application.getBundle() ).thenReturn( bundle ); + when( application.getClassLoader() ).thenReturn( getClass().getClassLoader() ); + when( application.isStarted() ).thenReturn( true ); + when( application.getConfig() ).thenReturn( ConfigBuilder.create().build() ); return application; } diff --git a/src/test/java/com/enonic/app/guillotine/graphql/RichTextGraphQLIntegrationTest.java b/src/test/java/com/enonic/app/guillotine/graphql/RichTextGraphQLIntegrationTest.java index ffc7eccf..ce921111 100644 --- a/src/test/java/com/enonic/app/guillotine/graphql/RichTextGraphQLIntegrationTest.java +++ b/src/test/java/com/enonic/app/guillotine/graphql/RichTextGraphQLIntegrationTest.java @@ -10,7 +10,6 @@ import graphql.schema.GraphQLSchema; -import com.enonic.app.guillotine.BuiltinMacros; import com.enonic.app.guillotine.graphql.helper.CastHelper; import com.enonic.xp.content.Content; import com.enonic.xp.content.ContentId; @@ -18,8 +17,6 @@ import com.enonic.xp.data.PropertyTree; import com.enonic.xp.form.Input; import com.enonic.xp.inputtype.InputTypeName; -import com.enonic.xp.macro.MacroDescriptorService; -import com.enonic.xp.macro.MacroService; import com.enonic.xp.portal.url.ProcessHtmlParams; import com.enonic.xp.schema.content.ContentType; import com.enonic.xp.schema.content.ContentTypeName; @@ -33,40 +30,14 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class RichTextGraphQLIntegrationTest extends BaseGraphQLIntegrationTest { - private MacroDescriptorService macroDescriptorService; - - private MacroService macroService; - - - @Override - protected void initialize() - throws Exception - { - super.initialize(); - - this.macroDescriptorService = mock( MacroDescriptorService.class ); - this.macroService = mock( MacroService.class ); - - addService( MacroDescriptorService.class, this.macroDescriptorService ); - addService( MacroService.class, this.macroService ); - } - @Test public void testRichTextField() { - when( macroDescriptorService.getAll() ).thenReturn( BuiltinMacros.getSystemMacroDescriptors() ); - when( serviceFacade.getMacroDescriptorService() ).thenReturn( macroDescriptorService ); - - when( macroService.evaluateMacros( anyString(), any() ) ).thenReturn( "processedMacros" ); - when( serviceFacade.getMacroService() ).thenReturn( macroService ); - when( serviceFacade.getPortalUrlService().processHtml( any( ProcessHtmlParams.class ) ) ).thenReturn( "processedHtml" ); when( contentService.getById( ContentId.from( "contentId" ) ) ).thenReturn( createContent() ); From 15dcd39001128bd4f9bb5cca956908c9381dc225 Mon Sep 17 00:00:00 2001 From: Anatol Sialitski Date: Thu, 5 Oct 2023 14:38:55 +0200 Subject: [PATCH 3/4] Release v7.0.0-A5 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 837b3f2a..ebef554f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,5 +5,5 @@ group=com.enonic.app projectName=guillotine appName=com.enonic.app.guillotine xpVersion=7.12.1 -version=7.0.0-SNAPSHOT +version=7.0.0-A5 From 66b2816f6505e6a77cfebecc462b6b645478061f Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 12:42:30 +0000 Subject: [PATCH 4/4] Updated to next SNAPSHOT version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index ebef554f..837b3f2a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,5 +5,5 @@ group=com.enonic.app projectName=guillotine appName=com.enonic.app.guillotine xpVersion=7.12.1 -version=7.0.0-A5 +version=7.0.0-SNAPSHOT