CCM NG: Improved createDeployment method for Arquillian tests
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4322 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
cc84642782
commit
1c08efca11
|
|
@ -43,8 +43,10 @@ import org.libreccm.tests.categories.IntegrationTest;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
|
@ -64,32 +66,32 @@ import static org.junit.Assert.*;
|
|||
@Transactional(TransactionMode.COMMIT)
|
||||
@CreateSchema({"create_ccm_shortcuts_schema.sql"})
|
||||
public class ShortcutRepositoryTest {
|
||||
|
||||
|
||||
@Inject
|
||||
private ShortcutRepository shortcutRepository;
|
||||
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
|
||||
public ShortcutRepositoryTest() {
|
||||
}
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
|
||||
@Deployment
|
||||
public static WebArchive createDeployment() {
|
||||
final PomEquippedResolveStage pom = Maven
|
||||
|
|
@ -97,32 +99,38 @@ public class ShortcutRepositoryTest {
|
|||
.loadPomFromFile("pom.xml");
|
||||
final PomEquippedResolveStage dependencies = pom
|
||||
.importCompileAndRuntimeDependencies();
|
||||
dependencies.addDependency(MavenDependencies.createDependency(
|
||||
"org.libreccm:ccm-core", ScopeType.RUNTIME, false));
|
||||
dependencies.addDependency(MavenDependencies.createDependency(
|
||||
"org.libreccm:ccm-testutils", ScopeType.RUNTIME, false));
|
||||
dependencies.addDependency(MavenDependencies.createDependency(
|
||||
"net.sf.saxon:Saxon-HE", ScopeType.RUNTIME, false));
|
||||
dependencies.addDependency(MavenDependencies.createDependency(
|
||||
"org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-impl-maven",
|
||||
ScopeType.RUNTIME, false));
|
||||
final File[] libsWithCcmCore = dependencies.resolve().withTransitivity()
|
||||
|
||||
final File[] libFiles = dependencies.resolve().withTransitivity()
|
||||
.asFile();
|
||||
|
||||
final List<File> libsList = new ArrayList<>(libsWithCcmCore.length - 1);
|
||||
IntStream.range(0, libsWithCcmCore.length).forEach(i -> {
|
||||
final File lib = libsWithCcmCore[i];
|
||||
if (!lib.getName().startsWith("ccm-core")) {
|
||||
libsList.add(lib);
|
||||
}
|
||||
});
|
||||
|
||||
final PomEquippedResolveStage pomCcmCore = Maven
|
||||
.resolver()
|
||||
.loadPomFromFile("../ccm-core/pom.xml");
|
||||
final PomEquippedResolveStage dependenciesCcmCore = pomCcmCore
|
||||
.importCompileAndRuntimeDependencies();
|
||||
final File[] ccmCoreLibFiles = dependenciesCcmCore.resolve()
|
||||
.withTransitivity().asFile();
|
||||
|
||||
final List<File> libsList = Arrays.stream(libFiles)
|
||||
.filter(lib -> !lib.getName().startsWith("ccm-"))
|
||||
.collect(Collectors.toList());
|
||||
final List<File> ccmCoreLibsList = Arrays.stream(ccmCoreLibFiles)
|
||||
.filter(lib -> !lib.getName().startsWith("ccm-"))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final File[] libs = libsList.toArray(new File[libsList.size()]);
|
||||
|
||||
for (File lib : libs) {
|
||||
System.err.printf("Adding file '%s' to test archive...%n",
|
||||
lib.getName());
|
||||
}
|
||||
|
||||
Arrays.stream(libs)
|
||||
.forEach(lib -> System.err.printf(
|
||||
"Adding file '%s' to test archive...%n",
|
||||
lib.getName()));
|
||||
|
||||
final File[] ccmCoreLibs = ccmCoreLibsList.toArray(
|
||||
new File[ccmCoreLibsList.size()]);
|
||||
Arrays.stream(ccmCoreLibs)
|
||||
.forEach(lib -> System.err.printf(
|
||||
"Adding file '%s' to test archive...%n",
|
||||
lib.getName()));
|
||||
|
||||
return ShrinkWrap.create(
|
||||
WebArchive.class,
|
||||
"LibreCCM-org.libreccm.shortcuts.ShortcutRepositoryTest-web.war")
|
||||
|
|
@ -139,56 +147,59 @@ public class ShortcutRepositoryTest {
|
|||
.addPackage(org.libreccm.security.Permission.class.getPackage())
|
||||
.addPackage(org.libreccm.web.CcmApplication.class.getPackage())
|
||||
.addPackage(org.libreccm.workflow.Workflow.class.getPackage())
|
||||
.addPackage(org.libreccm.tests.categories.IntegrationTest.class
|
||||
.getPackage())
|
||||
.addClass(org.libreccm.shortcuts.Shortcut.class)
|
||||
.addClass(org.libreccm.shortcuts.ShortcutRepository.class)
|
||||
.addAsLibraries(libs)
|
||||
.addAsLibraries(ccmCoreLibs)
|
||||
.addAsResource("test-persistence.xml",
|
||||
"META-INF/persistence.xml")
|
||||
.addAsWebInfResource("test-web.xml", "WEB-INF/web.xml")
|
||||
.addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@InSequence(1)
|
||||
public void repoIsInjected() {
|
||||
assertThat(shortcutRepository, is(not(nullValue())));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@InSequence(2)
|
||||
public void entityManagerIsInjected() {
|
||||
assertThat(entityManager, is(not((nullValue()))));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@UsingDataSet(
|
||||
"datasets/org/libreccm/shortcuts/ShortcutRepositoryTest/data.xml")
|
||||
@InSequence(10)
|
||||
public void findByUrlKey() {
|
||||
|
||||
|
||||
final Optional<Shortcut> members = shortcutRepository.findByUrlKey(
|
||||
"members");
|
||||
final Optional<Shortcut> mitglieder = shortcutRepository.findByUrlKey(
|
||||
"mitglieder");
|
||||
final Optional<Shortcut> shop = shortcutRepository.findByUrlKey("shop");
|
||||
|
||||
|
||||
assertThat(members.isPresent(), is(true));
|
||||
assertThat(members.get().getUrlKey(), is(equalTo("/members/")));
|
||||
assertThat(members.get().getRedirect(),
|
||||
is(equalTo("/ccm/navigation/members")));
|
||||
|
||||
|
||||
assertThat(mitglieder.isPresent(), is(true));
|
||||
assertThat(mitglieder.get().getUrlKey(), is(equalTo("/mitglieder/")));
|
||||
assertThat(mitglieder.get().getRedirect(),
|
||||
is(equalTo("/ccm/navigation/members")));
|
||||
|
||||
|
||||
assertThat(shop.isPresent(), is(true));
|
||||
assertThat(shop.get().getUrlKey(),
|
||||
is(equalTo("/shop/")));
|
||||
assertThat(shop.get().getRedirect(),
|
||||
is(equalTo("http://www.example.com")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@UsingDataSet(
|
||||
"datasets/org/libreccm/shortcuts/ShortcutRepositoryTest/data.xml")
|
||||
|
|
@ -196,17 +207,17 @@ public class ShortcutRepositoryTest {
|
|||
public void findByUrlKeyNotExisting() {
|
||||
final Optional<Shortcut> result = shortcutRepository.findByUrlKey(
|
||||
"foo");
|
||||
|
||||
|
||||
assertThat(result, is(not(nullValue())));
|
||||
assertThat(result.isPresent(), is(false));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@UsingDataSet(
|
||||
"datasets/org/libreccm/shortcuts/ShortcutRepositoryTest/data.xml")
|
||||
@InSequence(30)
|
||||
public void findByRedirect() {
|
||||
|
||||
|
||||
final List<Shortcut> toMembers = shortcutRepository.findByRedirect(
|
||||
"/ccm/navigation/members");
|
||||
assertThat(toMembers.size(), is(2));
|
||||
|
|
@ -216,7 +227,7 @@ public class ShortcutRepositoryTest {
|
|||
assertThat(toMembers.get(1).getUrlKey(), is(equalTo("/mitglieder/")));
|
||||
assertThat(toMembers.get(1).getRedirect(),
|
||||
is(equalTo("/ccm/navigation/members")));
|
||||
|
||||
|
||||
final List<Shortcut> toExampleCom = shortcutRepository.findByRedirect(
|
||||
"http://www.example.com");
|
||||
assertThat(toExampleCom.size(), is(1));
|
||||
|
|
@ -224,7 +235,7 @@ public class ShortcutRepositoryTest {
|
|||
assertThat(toExampleCom.get(0).getRedirect(),
|
||||
is(equalTo("http://www.example.com")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@UsingDataSet(
|
||||
"datasets/org/libreccm/shortcuts/ShortcutRepositoryTest/data.xml")
|
||||
|
|
@ -232,7 +243,7 @@ public class ShortcutRepositoryTest {
|
|||
public void findByRedirectNotExisting() {
|
||||
final List<Shortcut> result = shortcutRepository.findByRedirect(
|
||||
"http://www.example.org");
|
||||
|
||||
|
||||
assertThat(result, is(not(nullValue())));
|
||||
assertThat(result.isEmpty(), is(true));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue