-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee4a6a9
commit 0374ab4
Showing
21 changed files
with
333 additions
and
125 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 0 additions & 65 deletions
65
src/main/java/com/enonic/app/guillotine/graphql/fetchers/GetContentPathDataFetcher.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/enonic/app/guillotine/graphql/helper/ParamsUrHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.enonic.app.guillotine.graphql.helper; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import com.google.common.collect.Multimap; | ||
|
||
public class ParamsUrHelper | ||
{ | ||
public static void resolveParams( final Multimap<String, String> holder, final Object originalParams ) | ||
{ | ||
if ( originalParams instanceof Map ) | ||
{ | ||
for ( Map.Entry<String, Object> entry : ( (Map<String, Object>) originalParams ).entrySet() ) | ||
{ | ||
applyParam( holder, entry.getKey(), entry.getValue() ); | ||
} | ||
} | ||
} | ||
|
||
private static void applyParam( final Multimap<String, String> holder, final String key, final Object value ) | ||
{ | ||
if ( value instanceof Iterable ) | ||
{ | ||
applyParam( holder, key, (Iterable) value ); | ||
} | ||
else | ||
{ | ||
holder.put( key, Objects.toString( value, null ) ); | ||
} | ||
} | ||
|
||
private static void applyParam( final Multimap<String, String> holder, final String key, final Iterable values ) | ||
{ | ||
for ( final Object value : values ) | ||
{ | ||
holder.put( key, Objects.toString( value, null ) ); | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/test/java/com/enonic/app/guillotine/graphql/GetMediaContentGraphQLIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.enonic.app.guillotine.graphql; | ||
|
||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import graphql.schema.GraphQLSchema; | ||
|
||
import com.enonic.app.guillotine.graphql.helper.CastHelper; | ||
import com.enonic.xp.content.ContentId; | ||
import com.enonic.xp.portal.url.AttachmentUrlParams; | ||
|
||
import static com.enonic.app.guillotine.graphql.ResourceHelper.readGraphQLQuery; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class GetMediaContentGraphQLIntegrationTest | ||
extends BaseGraphQLIntegrationTest | ||
{ | ||
@Override | ||
protected void initialize() | ||
throws Exception | ||
{ | ||
super.initialize(); | ||
} | ||
|
||
@Test | ||
public void testMediaAndAttachmentUrls() | ||
{ | ||
when( serviceFacade.getPortalUrlService().attachmentUrl( any( AttachmentUrlParams.class ) ) ).thenReturn( "url?a=1&b=2&b=3&c" ); | ||
when( contentService.getById( ContentId.from( "contentId" ) ) ).thenReturn( ContentFixtures.createMediaContent() ); | ||
|
||
GraphQLSchema graphQLSchema = getBean().createSchema(); | ||
|
||
Map<String, Object> result = executeQuery( graphQLSchema, readGraphQLQuery( "graphql/getMediaContent.graphql" ) ); | ||
|
||
assertFalse( result.containsKey( "errors" ) ); | ||
assertTrue( result.containsKey( "data" ) ); | ||
|
||
Map<String, Object> attachmentUrlField = CastHelper.cast( getFieldFromGuillotine( result, "attachmentUrl" ) ); | ||
assertEquals( "url?a=1&b=2&b=3&c", attachmentUrlField.get( "mediaUrl" ) ); | ||
} | ||
|
||
@Test | ||
public void testDownloadAttachmentUrl() | ||
{ | ||
when( serviceFacade.getPortalUrlService().attachmentUrl( any( AttachmentUrlParams.class ) ) ).thenReturn( "url?download" ); | ||
when( contentService.getById( ContentId.from( "contentId" ) ) ).thenReturn( ContentFixtures.createMediaContent() ); | ||
|
||
GraphQLSchema graphQLSchema = getBean().createSchema(); | ||
|
||
Map<String, Object> result = executeQuery( graphQLSchema, readGraphQLQuery( "graphql/getMediaContent.graphql" ) ); | ||
|
||
assertFalse( result.containsKey( "errors" ) ); | ||
assertTrue( result.containsKey( "data" ) ); | ||
|
||
Map<String, Object> downloadAttachmentUrlField = CastHelper.cast( getFieldFromGuillotine( result, "downloadAttachmentUrl" ) ); | ||
assertEquals( "url?download", downloadAttachmentUrlField.get( "mediaUrl" ) ); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/test/java/com/enonic/app/guillotine/graphql/GetPageUrlGraphQLIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.enonic.app.guillotine.graphql; | ||
|
||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import graphql.schema.GraphQLSchema; | ||
|
||
import com.enonic.app.guillotine.graphql.helper.CastHelper; | ||
import com.enonic.xp.content.ContentId; | ||
import com.enonic.xp.content.ContentPath; | ||
import com.enonic.xp.portal.url.PageUrlParams; | ||
import com.enonic.xp.site.Site; | ||
|
||
import static com.enonic.app.guillotine.graphql.ResourceHelper.readGraphQLQuery; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class GetPageUrlGraphQLIntegrationTest | ||
extends BaseGraphQLIntegrationTest | ||
{ | ||
@Test | ||
public void testMediaAndAttachmentUrls() | ||
{ | ||
when( serviceFacade.getPortalUrlService().pageUrl( any( PageUrlParams.class ) ) ).thenReturn( "pageUrl" ); | ||
when( contentService.getById( ContentId.from( "contentId" ) ) ).thenReturn( ContentFixtures.createMediaContent() ); | ||
when( contentService.getByPath( Mockito.any() ) ).thenReturn( Site.create(). | ||
description( "Site" ). | ||
name( "test-site" ). | ||
parentPath( ContentPath.ROOT ). | ||
language( Locale.ENGLISH ). | ||
build() ); | ||
|
||
GraphQLSchema graphQLSchema = getBean().createSchema(); | ||
|
||
Map<String, Object> result = executeQuery( graphQLSchema, readGraphQLQuery( "graphql/getPageUrl.graphql" ) ); | ||
|
||
assertFalse( result.containsKey( "errors" ) ); | ||
assertTrue( result.containsKey( "data" ) ); | ||
|
||
Map<String, Object> getField = CastHelper.cast( getFieldFromGuillotine( result, "get" ) ); | ||
assertEquals( "pageUrl", getField.get( "pageUrl" ) ); | ||
} | ||
} |
Oops, something went wrong.