Search in sources :

Example 1 with CheckedConsumer

use of com.adobe.acs.commons.functions.CheckedConsumer in project acs-aem-commons by Adobe-Consulting-Services.

the class AssetFolderCreatorTest method setUp.

@Before
public void setUp() throws Exception {
    context.create().resource("/content/dam", JcrConstants.JCR_PRIMARYTYPE, "sling:Folder");
    context.resourceResolver().commit();
    final Map<String, ResourceDefinitionBuilder> resourceDefinitionBuilders = new HashMap<>();
    resourceDefinitionBuilders.put(AssetFolderCreator.AssetFolderBuilder.LOWERCASE_WITH_DASHES.name(), new LowercaseWithDashesDefinitionBuilderImpl());
    resourceDefinitionBuilders.put(AssetFolderCreator.AssetFolderBuilder.TITLE_AND_NODE_NAME.name(), new TitleAndNodeNameDefinitionBuilderImpl());
    resourceDefinitionBuilders.put(AssetFolderCreator.AssetFolderBuilder.TITLE_TO_NODE_NAME.name(), new JcrValidNameDefinitionBuilderImpl());
    assetFolderCreator = new AssetFolderCreator(resourceDefinitionBuilders);
    assetFolderCreator.excelFile = getClass().getResourceAsStream("/com/adobe/acs/commons/mcp/impl/processes/asset-folder-creator.xlsx");
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            CheckedConsumer<ResourceResolver> method = (CheckedConsumer<ResourceResolver>) invocation.getArguments()[0];
            method.accept(context.resourceResolver());
            return null;
        }
    }).when(actionManager).withResolver(any(CheckedConsumer.class));
}
Also used : TitleAndNodeNameDefinitionBuilderImpl(com.adobe.acs.commons.util.datadefinitions.impl.TitleAndNodeNameDefinitionBuilderImpl) CheckedConsumer(com.adobe.acs.commons.functions.CheckedConsumer) HashMap(java.util.HashMap) LowercaseWithDashesDefinitionBuilderImpl(com.adobe.acs.commons.util.datadefinitions.impl.LowercaseWithDashesDefinitionBuilderImpl) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ResourceDefinitionBuilder(com.adobe.acs.commons.util.datadefinitions.ResourceDefinitionBuilder) JcrValidNameDefinitionBuilderImpl(com.adobe.acs.commons.util.datadefinitions.impl.JcrValidNameDefinitionBuilderImpl) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Before(org.junit.Before)

Example 2 with CheckedConsumer

use of com.adobe.acs.commons.functions.CheckedConsumer in project acs-aem-commons by Adobe-Consulting-Services.

the class S3AssetIngestorTest method setup.

@Before
public void setup() throws PersistenceException {
    context.registerAdapter(ResourceResolver.class, AssetManager.class, new Function<ResourceResolver, AssetManager>() {

        @Nullable
        @Override
        public AssetManager apply(@Nullable ResourceResolver input) {
            return assetManager;
        }
    });
    context.create().resource("/content/dam", JcrConstants.JCR_PRIMARYTYPE, "sling:Folder");
    context.resourceResolver().commit();
    ingestor = new S3AssetIngestor(context.getService(MimeTypeService.class));
    ingestor.jcrBasePath = "/content/dam";
    ingestor.ignoreFileList = Collections.emptyList();
    ingestor.ignoreExtensionList = Collections.emptyList();
    ingestor.ignoreFolderList = Arrays.asList(".ds_store");
    ingestor.existingAssetAction = AssetIngestor.AssetAction.skip;
    int port = FreePortFinder.findFreeLocalPort();
    s3Mock = new S3Mock.Builder().withPort(port).withInMemoryBackend().build();
    s3Mock.start();
    S3ClientOptions options = S3ClientOptions.builder().setPathStyleAccess(true).build();
    s3Client = new AmazonS3Client(new AnonymousAWSCredentials());
    s3Client.setS3ClientOptions(options);
    s3Client.setEndpoint("http://localhost:" + port);
    ingestor.s3Client = s3Client;
    ingestor.bucket = TEST_BUCKET;
    s3Client.createBucket(TEST_BUCKET);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            CheckedConsumer<ResourceResolver> method = (CheckedConsumer<ResourceResolver>) invocation.getArguments()[0];
            method.accept(context.resourceResolver());
            return null;
        }
    }).when(actionManager).deferredWithResolver(any(CheckedConsumer.class));
}
Also used : AssetManager(com.day.cq.dam.api.AssetManager) CheckedConsumer(com.adobe.acs.commons.functions.CheckedConsumer) AnonymousAWSCredentials(com.amazonaws.auth.AnonymousAWSCredentials) Answer(org.mockito.stubbing.Answer) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) S3ClientOptions(com.amazonaws.services.s3.S3ClientOptions) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Nullable(javax.annotation.Nullable) Before(org.junit.Before)

Example 3 with CheckedConsumer

use of com.adobe.acs.commons.functions.CheckedConsumer in project acs-aem-commons by Adobe-Consulting-Services.

the class FileAssetIngestorTest method setup.

@Before
public void setup() throws PersistenceException {
    context.registerAdapter(ResourceResolver.class, AssetManager.class, new Function<ResourceResolver, AssetManager>() {

        @Nullable
        @Override
        public AssetManager apply(@Nullable ResourceResolver input) {
            return assetManager;
        }
    });
    context.create().resource("/content/dam", JcrConstants.JCR_PRIMARYTYPE, "sling:Folder");
    context.resourceResolver().commit();
    ingestor = new FileAssetIngestor(context.getService(MimeTypeService.class));
    ingestor.jcrBasePath = "/content/dam";
    ingestor.ignoreFileList = Collections.emptyList();
    ingestor.ignoreExtensionList = Collections.emptyList();
    ingestor.ignoreFolderList = Arrays.asList(".ds_store");
    ingestor.existingAssetAction = AssetIngestor.AssetAction.skip;
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            CheckedConsumer<ResourceResolver> method = (CheckedConsumer<ResourceResolver>) invocation.getArguments()[0];
            method.accept(context.resourceResolver());
            return null;
        }
    }).when(actionManager).deferredWithResolver(any(CheckedConsumer.class));
    tempDirectory = Files.createTempDir();
    ingestor.fileBasePath = tempDirectory.getAbsolutePath();
}
Also used : Answer(org.mockito.stubbing.Answer) AssetManager(com.day.cq.dam.api.AssetManager) CheckedConsumer(com.adobe.acs.commons.functions.CheckedConsumer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Nullable(javax.annotation.Nullable) Before(org.junit.Before)

Aggregations

CheckedConsumer (com.adobe.acs.commons.functions.CheckedConsumer)3 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)3 Before (org.junit.Before)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Answer (org.mockito.stubbing.Answer)3 AssetManager (com.day.cq.dam.api.AssetManager)2 Nullable (javax.annotation.Nullable)2 ResourceDefinitionBuilder (com.adobe.acs.commons.util.datadefinitions.ResourceDefinitionBuilder)1 JcrValidNameDefinitionBuilderImpl (com.adobe.acs.commons.util.datadefinitions.impl.JcrValidNameDefinitionBuilderImpl)1 LowercaseWithDashesDefinitionBuilderImpl (com.adobe.acs.commons.util.datadefinitions.impl.LowercaseWithDashesDefinitionBuilderImpl)1 TitleAndNodeNameDefinitionBuilderImpl (com.adobe.acs.commons.util.datadefinitions.impl.TitleAndNodeNameDefinitionBuilderImpl)1 AnonymousAWSCredentials (com.amazonaws.auth.AnonymousAWSCredentials)1 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)1 S3ClientOptions (com.amazonaws.services.s3.S3ClientOptions)1 HashMap (java.util.HashMap)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1