Skip to content

Commit 9536083

Browse files
Unit tests coverage for Deck Dynamo (#3334)
* add unit tests for Dynamic deck functionality --------- Co-authored-by: david g <[email protected]>
1 parent de8470f commit 9536083

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*-
2+
* #%L
3+
* ACS AEM Commons Bundle
4+
* %%
5+
* Copyright (C) 2013 - 2024 Adobe
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.adobe.acs.commons.indesign.dynamicdeckdynamo.services.impl;
21+
22+
import com.adobe.acs.commons.indesign.dynamicdeckdynamo.exception.DynamicDeckDynamoException;
23+
import com.adobe.acs.commons.indesign.dynamicdeckdynamo.services.DynamicDeckConfigurationService;
24+
import com.adobe.acs.commons.indesign.dynamicdeckdynamo.services.XMLGeneratorService;
25+
import io.wcm.testing.mock.aem.junit5.AemContext;
26+
import io.wcm.testing.mock.aem.junit5.AemContextExtension;
27+
import org.apache.sling.api.resource.Resource;
28+
import org.apache.sling.api.resource.ResourceResolver;
29+
import org.apache.sling.event.jobs.JobManager;
30+
import org.junit.jupiter.api.BeforeEach;
31+
import org.junit.jupiter.api.Test;
32+
import org.junit.jupiter.api.extension.ExtendWith;
33+
import org.mockito.InjectMocks;
34+
import org.mockito.Mock;
35+
import org.mockito.Mockito;
36+
import org.mockito.junit.jupiter.MockitoExtension;
37+
38+
import java.util.Collections;
39+
import java.util.List;
40+
41+
import static org.junit.Assert.assertThrows;
42+
43+
@ExtendWith({AemContextExtension.class, MockitoExtension.class})
44+
class DynamicDeckServiceImplTest {
45+
46+
private final AemContext context = new AemContext();
47+
48+
private ResourceResolver resourceResolver;
49+
50+
@Mock
51+
private DynamicDeckConfigurationService configurationService;
52+
53+
@Mock
54+
private XMLGeneratorService xmlGeneratorService;
55+
56+
@Mock
57+
private JobManager jobManager;
58+
59+
@InjectMocks
60+
private DynamicDeckServiceImpl dynamicDeckService;
61+
62+
@BeforeEach
63+
void setUp() {
64+
context.load().json("/com/adobe/acs/commons/dynamicdeckdynamo/dynamicdeckResources.json", "/content");
65+
resourceResolver = context.resourceResolver();
66+
67+
context.registerService(DynamicDeckConfigurationService.class, configurationService);
68+
context.registerService(XMLGeneratorService.class, xmlGeneratorService);
69+
context.registerService(JobManager.class, jobManager);
70+
dynamicDeckService = context.registerInjectActivateService(new DynamicDeckServiceImpl());
71+
}
72+
73+
@Test
74+
void shouldThrowExceptionInCaseOfTemplateAbsents() {
75+
context.request().setPathInfo("/content/some/en/en/some.json");
76+
List<Resource> assetResourceList = Collections.singletonList(Mockito.mock(Resource.class));
77+
Resource masterAssetResource = resourceResolver.getResource("/content/dam/dynamic-deck-dynamo/master-assets");
78+
Resource templateFolderResource = resourceResolver.getResource("/content/dam/dynamic-deck-dynamo/templates/simple-template-2018");
79+
Resource destinationFolderResource = resourceResolver.getResource("/content/dam/dynamic-deck-dynamo/destination");
80+
81+
assertThrows(DynamicDeckDynamoException.class, () ->
82+
dynamicDeckService.createDeck("deckTitle", masterAssetResource, assetResourceList, templateFolderResource,
83+
destinationFolderResource, resourceResolver));
84+
}
85+
86+
@Test
87+
void shouldThrowExceptionInCaseOfDamAssetResourceNull() {
88+
context.request().setPathInfo("/content/some/en/en/some.json");
89+
List<Resource> assetResourceList = Collections.singletonList(Mockito.mock(Resource.class));
90+
Resource masterAssetResource = resourceResolver.getResource("/content/dam/dynamic-deck-dynamo/master-assets");
91+
Resource templateFolderResource = resourceResolver.getResource("/content/dam/dynamic-deck-dynamo/templates/simple-template-2019");
92+
Resource destinationFolderResource = resourceResolver.getResource("/content/dam/dynamic-deck-dynamo/destination");
93+
94+
assertThrows(DynamicDeckDynamoException.class, () ->
95+
dynamicDeckService.createDeck("deckTitle", masterAssetResource, assetResourceList, templateFolderResource,
96+
destinationFolderResource, resourceResolver));
97+
}
98+
}

bundle/src/test/resources/com/adobe/acs/commons/dynamicdeckdynamo/dynamicdeckResources.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,33 @@
77
"jcr:primaryType": "sling:Folder",
88
"simple-template-2018": {
99
"jcr:primaryType": "sling:Folder"
10+
},
11+
"simple-template-2019": {
12+
"jcr:primaryType": "sling:Folder",
13+
"asset.indd": {
14+
"jcr:primaryType": "dam:Asset"
15+
},
16+
"asset.xml": {
17+
"jcr:primaryType": "dam:Asset",
18+
"jcr:content": {
19+
"renditions": {
20+
"original.dir": {
21+
"jcr:primaryType": "nt:file",
22+
"jcr:content": {
23+
}
24+
},
25+
"original": {
26+
"jcr:primaryType": "nt:file",
27+
"jcr:content": {
28+
"jcr:primaryType": "oak:Resource",
29+
"jcr:mimeType": "application/x-indesign",
30+
"jcr:data": {
31+
}
32+
}
33+
}
34+
}
35+
}
36+
}
1037
}
1138
},
1239
"master-assets": {

0 commit comments

Comments
 (0)