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
7f543e0
commit 81ce47f
Showing
6 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.aem.demo.core.models; | ||
|
||
import com.adobe.cq.wcm.core.components.models.Title; | ||
|
||
public interface TitleExtd extends Title { | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
core/src/main/java/com/aem/demo/core/models/TitleExtdImpl.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,33 @@ | ||
package com.aem.demo.core.models; | ||
|
||
import com.adobe.cq.export.json.ComponentExporter; | ||
import com.adobe.cq.export.json.ExporterConstants; | ||
import com.adobe.cq.wcm.core.components.models.Title; | ||
import lombok.experimental.Delegate; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.sling.api.SlingHttpServletRequest; | ||
import org.apache.sling.models.annotations.DefaultInjectionStrategy; | ||
import org.apache.sling.models.annotations.Exporter; | ||
import org.apache.sling.models.annotations.Model; | ||
import org.apache.sling.models.annotations.Via; | ||
import org.apache.sling.models.annotations.injectorspecific.Self; | ||
import org.apache.sling.models.annotations.via.ResourceSuperType; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
@Slf4j | ||
@Model(adaptables = SlingHttpServletRequest.class, adapters = {TitleExtd.class, ComponentExporter.class}, | ||
resourceType = TitleExtdImpl.RESOURCE_TYPE, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) | ||
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION) | ||
public class TitleExtdImpl implements TitleExtd { | ||
public static final String RESOURCE_TYPE = "aem-demo/components/title"; | ||
|
||
@Delegate(types = com.adobe.cq.wcm.core.components.models.Title.class) | ||
@Self | ||
private com.adobe.cq.wcm.core.components.models.Title delegate; | ||
|
||
@PostConstruct | ||
protected void init() { | ||
log.info("Start Extended Title Model"); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
core/src/test/java/com/aem/demo/core/models/TitleExtdImplTest.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,37 @@ | ||
package com.aem.demo.core.models; | ||
|
||
import com.aem.demo.core.testcontext.AppAemContext; | ||
import com.day.cq.wcm.api.Page; | ||
import io.wcm.testing.mock.aem.junit5.AemContext; | ||
import io.wcm.testing.mock.aem.junit5.AemContextExtension; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@ExtendWith({AemContextExtension.class, MockitoExtension.class}) | ||
class TitleExtdImplTest { | ||
private final AemContext context = AppAemContext.newAemContext(); | ||
private TitleExtd titleExtd; | ||
|
||
@BeforeEach | ||
void init() { | ||
Resource pageResource = context.load().json("/com/aem/demo/core/models/page.json", "/content/uk"); | ||
Page page = pageResource.getChild("en/product").adaptTo(Page.class); | ||
|
||
Map<String, Object> jsonObject = TestUtils.getJsonObject("/com/aem/demo/core/models/title.json"); | ||
context.currentResource(context.create().resource(page, "extendedTitle", jsonObject)); | ||
titleExtd = context.request().adaptTo(TitleExtd.class); | ||
} | ||
|
||
@Test | ||
void idTest() { | ||
assertNotNull(titleExtd.getId()); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
core/src/test/resources/com/aem/demo/core/models/title.json
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,15 @@ | ||
{ | ||
"jcr:primaryType": "nt:unstructured", | ||
"jcr:createdBy": "admin", | ||
"jcr:title": "Product", | ||
"jcr:lastModifiedBy": "admin", | ||
"jcr:created": "Fri Dec 07 2018 13:50:54 GMT+0100", | ||
"type": "h1", | ||
"linkURL": "/content/core-components-examples/library/title", | ||
"linkAccessibilityLabel": "Link", | ||
"jcr:lastModified": "Thu Jul 06 2023 12:55:24 GMT+0000", | ||
"sling:resourceType": "aem-demo/components/title", | ||
"cq:styleIds": [ | ||
"1544759629303" | ||
] | ||
} |
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