Skip to content

Instantly share code, notes, and snippets.

@lklement
Created April 7, 2017 02:40
Show Gist options
  • Save lklement/a6644f241f9f37d36f6728fb85ea177c to your computer and use it in GitHub Desktop.
Save lklement/a6644f241f9f37d36f6728fb85ea177c to your computer and use it in GitHub Desktop.
Code to demonstrate AEM / Sling Server-Side JUnit Testing
package com.adobe.training.core.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.junit.annotations.SlingAnnotationsTestRunner;
import org.apache.sling.junit.annotations.TestReference;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.adobe.training.core.ProcessContent;
@RunWith(SlingAnnotationsTestRunner.class)
public class SlingProcessContentTest {
@TestReference
private SlingRepository repository;
@Test
public void testRepoName() {
assertTrue(repository.getDescriptor(Repository.REP_NAME_DESC).equals("Apache Jackrabbit Oak"));
}
@Test
public void testGetContentPath() {
Session adminSession= null;
try {
adminSession = repository.loginAdministrative(null);
ProcessContent tc = new ProcessContent();
assertEquals("/content", tc.getContentPath(adminSession));
} catch (RepositoryException e) {
}finally {
if(adminSession != null) {
if (adminSession.isLive())
adminSession.logout();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment