Integration Test with Content Fragments - How can I create a Content Fragment?
In my integration test I want to create a Content Fragment in a testfolder and then implement this Content Fragment in a testpage. (Sidenote: Manually everything I want to do in this test works.)
So far I managed to create a testpage and a testfolder, but I couldn't find a solution to create a Content Fragment.
This code shows how I created a user (admin).
@ClassRule
public static final CQAuthorClassRule cqBaseClassRule = new CQAuthorClassRule();
@Rule
public CQRule cqBaseRule = new CQRule(cqBaseClassRule.authorRule);
static CQClient adminAuthor;
@BeforeClass
public static void beforeClass() {
adminAuthor = cqBaseClassRule.authorRule.getAdminClient(CQClient.class);
}
and here I created a testpage and testfolder in my Test
try {
SlingHttpResponse page = adminAuthor.createPageWithRetry(pageName, pageTitle, pageParentPath, templatePath, MINUTES.toMillis(1), 500, HttpStatus.SC_OK);
String pagePath = page.getSlingLocation();
LOG.info("Created page at {}", pagePath);
// This shows that the page exists
CQAssert.assertCQPageExistsWithTimeout(adminAuthor, pagePath, TIMEOUT, 500);
SlingHttpResponse folder = adminAuthor.createFolder(folderName, folderTitle, folderParentPath, HttpStatus.SC_OK);
String folderPath = folder.getSlingLocation();
LOG.info("Created folder at {}", folderPath);
// This shows that the folder exists
CQAssert.assertFolderExists(adminAuthor, folderPath, folderTitle);
}
There is nothing like "createContentFragment" only "createNode"... Bu then I would have to create several Nodes and update these nodes to have the structure I want in my CRX.
Any idea how I can create this content Fragment? Is there an API to use in integration tests?