Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use only Spring, no Java EE! #1

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 15 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@
<artifactId>wicket-auth-roles</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-cdi-1.1</artifactId>
<version>${wicket.version}</version>
</dependency>
<dependency>
<groupId>org.wicketstuff</groupId>
<artifactId>wicketstuff-javaee-inject</artifactId>
<version>${wicket.version}</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.apache.wicket</groupId>-->
<!--<artifactId>wicket-cdi-1.1</artifactId>-->
<!--<version>${wicket.version}</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.wicketstuff</groupId>-->
<!--<artifactId>wicketstuff-javaee-inject</artifactId>-->
<!--<version>${wicket.version}</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.apache.wicket</groupId>
<artifactId>wicket-spring</artifactId>
Expand Down Expand Up @@ -142,11 +142,11 @@
</dependency>

<!-- java ee7 -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<!--<dependency>-->
<!--<groupId>javax.enterprise</groupId>-->
<!--<artifactId>cdi-api</artifactId>-->
<!--<scope>provided</scope>-->
<!--</dependency>-->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/copperarrow/WicketApplication.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.copperarrow;

import com.copperarrow.auth.SecureWebSession;
import com.copperarrow.dao.UserDAO;
import com.copperarrow.pages.AdminPage;
import com.copperarrow.pages.HomePage;
import com.copperarrow.pages.LoginPage;
import com.copperarrow.pages.UserPage;
import org.apache.wicket.Application;
import org.apache.wicket.authroles.authentication.AbstractAuthenticatedWebSession;
import org.apache.wicket.authroles.authentication.AuthenticatedWebApplication;
import org.apache.wicket.cdi.CdiConfiguration;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.wicketstuff.javaee.injection.JavaEEComponentInjector;
import org.wicketstuff.javaee.naming.global.ModuleJndiNamingStrategy;
import org.apache.wicket.spring.test.ApplicationContextMock;

/**
* Application object for your web application.
Expand Down Expand Up @@ -50,6 +49,7 @@ public void init() {
super.init();

configureCDIEJB();

getComponentInstantiationListeners().add(new SpringComponentInjector(this));

mountPage("login", LoginPage.class);
Expand All @@ -58,7 +58,7 @@ public void init() {
}

private void configureCDIEJB() {
getComponentInstantiationListeners().add(new JavaEEComponentInjector(this, new ModuleJndiNamingStrategy()));
// getComponentInstantiationListeners().add(new JavaEEComponentInjector(this, new ModuleJndiNamingStrategy()));
// new CdiConfiguration().configure(this);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,43 @@
package com.copperarrow.model.dataproviders;

import com.copperarrow.dao.UserDAO;
import com.copperarrow.model.UserAccount;
import org.apache.wicket.cdi.NonContextual;
import org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder;
import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
import org.apache.wicket.injection.Injector;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import java.util.Iterator;
import java.util.List;

import javax.ejb.Stateless;

import com.copperarrow.dao.UserDAO;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class is missing

import com.copperarrow.model.UserAccount;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class is missing


/**
* Created by dbeer on 11/02/17.
*/
@Stateless(name = "UserAcDataProvider")
public class UserAccountDataProvider extends SortableDataProvider<UserAccount, String> {

@EJB(name = "UserDAO")
@SpringBean
private UserDAO userDAO;

public UserAccountDataProvider() {
Injector.get().inject(this);
setSort("firstName", SortOrder.ASCENDING);
}

private void getDAO() {
if (userDAO == null) {
NonContextual.of(UserAccountDataProvider.class).inject(this);
}
}

@Override
public Iterator<UserAccount> iterator(long first, long last) {
getDAO();
List<UserAccount> users = userDAO.sort(getSort().toString(), "firstName");

return users.subList((int)first, (int)(first + last)).iterator();
}

@Override
public long size() {
getDAO();
return userDAO.size();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/copperarrow/pages/UserPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public UserPage(PageParameters parameters) {
super(parameters);

Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal != null && principal instanceof UserAccount) {
if (principal instanceof UserAccount) {
String username = ((UserAccount) principal).getUserName();
add(new Label("username", username));
} else {
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/com/copperarrow/WicketApplicationTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.copperarrow;

import org.apache.wicket.Page;
import org.apache.wicket.cdi.CdiConfiguration;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.apache.wicket.spring.test.ApplicationContextMock;
import org.apache.wicket.util.tester.WicketTester;
import org.junit.Before;
import org.springframework.stereotype.Component;
import org.wicketstuff.javaee.injection.JavaEEComponentInjector;
import org.wicketstuff.javaee.naming.global.ModuleJndiNamingStrategy;

import com.copperarrow.dao.UserDAO;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class is missing


/**
* Created by dbeer on 15/01/17.
Expand Down Expand Up @@ -44,7 +43,6 @@ protected void init() {
//Configures the SpringBean annotation support to use the mock application context.
//This ensures that the mock objects are injected instead of the actual bean classes.
getComponentInstantiationListeners().add(new SpringComponentInjector(this, applicationContextMock));
getComponentInstantiationListeners().add(new JavaEEComponentInjector(this, new ModuleJndiNamingStrategy()));
WicketApplicationTest.this.init(this);
}

Expand Down
7 changes: 6 additions & 1 deletion src/test/java/com/copperarrow/pages/AdminPageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.copperarrow.auth.config.SecurityWebApplicationInitializer;
import com.copperarrow.dao.EntitiesDAO;
import com.copperarrow.dao.UserDAO;
import com.copperarrow.model.UserAccount;
import com.copperarrow.model.dataproviders.UserAccountDataProvider;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.util.tester.WicketTester;
Expand All @@ -18,7 +19,10 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Collections;

import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -53,6 +57,7 @@ protected void setupTest() {
userDAO = mock(UserDAO.class);

when(userDAO.size()).thenReturn(1);
when(userDAO.sort(anyString(), anyString())).thenReturn(Collections.singletonList(new UserAccount()));
addMock("java:module/UserAcDataProvider", userAccountDataProvider);
addMock(userDAO);
}
Expand All @@ -63,4 +68,4 @@ public void renderSuccessfully() {
tester.startPage(AdminPage.class);
tester.assertRenderedPage(AdminPage.class);
}
}
}