http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/startup/ModuleStartupObserver.java ---------------------------------------------------------------------- diff --git a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/startup/ModuleStartupObserver.java b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/startup/ModuleStartupObserver.java index 9af7889..0fb2a6b 100644 --- a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/startup/ModuleStartupObserver.java +++ b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/startup/ModuleStartupObserver.java @@ -1,38 +1,38 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.superbiz.deltaspike.startup; - -import javax.annotation.PostConstruct; -import javax.ejb.Singleton; -import javax.ejb.Startup; -import java.util.logging.Level; -import java.util.logging.Logger; - -@Singleton -@Startup -public class ModuleStartupObserver { - private Logger logger = Logger.getLogger(ModuleStartupObserver.class.getName()); - - @PostConstruct - public void logStartup() { - if (logger.isLoggable(Level.INFO)) { - logger.info("starting application module"); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.deltaspike.startup; + +import javax.annotation.PostConstruct; +import javax.ejb.Singleton; +import javax.ejb.Startup; +import java.util.logging.Level; +import java.util.logging.Logger; + +@Singleton +@Startup +public class ModuleStartupObserver { + private Logger logger = Logger.getLogger(ModuleStartupObserver.class.getName()); + + @PostConstruct + public void logStartup() { + if (logger.isLoggable(Level.INFO)) { + logger.info("starting application module"); + } + } +}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/FeedbackPage.java ---------------------------------------------------------------------- diff --git a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/FeedbackPage.java b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/FeedbackPage.java index 69b32e4..c359e3e 100644 --- a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/FeedbackPage.java +++ b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/FeedbackPage.java @@ -1,74 +1,74 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.superbiz.deltaspike.view; - -import org.apache.deltaspike.core.api.config.view.controller.PreRenderView; -import org.apache.deltaspike.core.api.scope.GroupedConversation; -import org.apache.deltaspike.core.api.scope.GroupedConversationScoped; -import org.superbiz.deltaspike.domain.Feedback; -import org.superbiz.deltaspike.repository.FeedbackRepository; - -import javax.annotation.PostConstruct; -import javax.inject.Inject; -import javax.inject.Named; -import java.io.Serializable; -import java.util.List; - -@Named -@GroupedConversationScoped -public class FeedbackPage implements Serializable { - private static final long serialVersionUID = 744025508253889974L; - - private List<Feedback> feedbackList; - - @Inject - private GroupedConversation conversation; - - @Inject - private FeedbackRepository feedbackRepository; - - private Feedback feedback; - - @PostConstruct - protected void init() { - this.feedback = new Feedback(); - } - - @PreRenderView - public void reloadFeedbackList() { - this.feedbackList = this.feedbackRepository.findAll(); - } - - public void save() { - this.feedbackRepository.save(this.feedback); - this.conversation.close(); - } - - /* - * generated - */ - - public List<Feedback> getFeedbackList() { - return feedbackList; - } - - public Feedback getFeedback() { - return feedback; - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.deltaspike.view; + +import org.apache.deltaspike.core.api.config.view.controller.PreRenderView; +import org.apache.deltaspike.core.api.scope.GroupedConversation; +import org.apache.deltaspike.core.api.scope.GroupedConversationScoped; +import org.superbiz.deltaspike.domain.Feedback; +import org.superbiz.deltaspike.repository.FeedbackRepository; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.inject.Named; +import java.io.Serializable; +import java.util.List; + +@Named +@GroupedConversationScoped +public class FeedbackPage implements Serializable { + private static final long serialVersionUID = 744025508253889974L; + + private List<Feedback> feedbackList; + + @Inject + private GroupedConversation conversation; + + @Inject + private FeedbackRepository feedbackRepository; + + private Feedback feedback; + + @PostConstruct + protected void init() { + this.feedback = new Feedback(); + } + + @PreRenderView + public void reloadFeedbackList() { + this.feedbackList = this.feedbackRepository.findAll(); + } + + public void save() { + this.feedbackRepository.save(this.feedback); + this.conversation.close(); + } + + /* + * generated + */ + + public List<Feedback> getFeedbackList() { + return feedbackList; + } + + public Feedback getFeedback() { + return feedback; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/InfoPage.java ---------------------------------------------------------------------- diff --git a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/InfoPage.java b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/InfoPage.java index 66d635a..aa161df 100644 --- a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/InfoPage.java +++ b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/InfoPage.java @@ -1,36 +1,36 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.superbiz.deltaspike.view; - -import org.apache.deltaspike.core.api.config.view.metadata.ViewMetaData; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -@Target({TYPE}) -@Retention(RUNTIME) -@Documented - -@ViewMetaData -public @interface InfoPage { -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.deltaspike.view; + +import org.apache.deltaspike.core.api.config.view.metadata.ViewMetaData; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target({TYPE}) +@Retention(RUNTIME) +@Documented + +@ViewMetaData +public @interface InfoPage { +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/MenuBean.java ---------------------------------------------------------------------- diff --git a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/MenuBean.java b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/MenuBean.java index b797a86..a3fb281 100644 --- a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/MenuBean.java +++ b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/MenuBean.java @@ -1,61 +1,61 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.superbiz.deltaspike.view; - -import org.apache.deltaspike.core.spi.scope.conversation.GroupedConversationManager; -import org.superbiz.deltaspike.view.config.Pages; - -import javax.enterprise.inject.Model; -import javax.inject.Inject; - -@Model -public class MenuBean { - @Inject - private GroupedConversationManager groupedConversationManager; - - public Class<? extends Pages> home() { - //close all conversations of the current window - this.groupedConversationManager.closeConversations(); - return Pages.Index.class; - } - - public Class<? extends Pages.Secure> feedback() { - //close all conversations of the current window - this.groupedConversationManager.closeConversations(); - return Pages.Secure.FeedbackList.class; - } - - public Class<? extends Pages> about() { - //close all conversations of the current window - this.groupedConversationManager.closeConversations(); - return Pages.About.class; - } - - public Class<? extends Pages> login() { - //close all conversations of the current window - this.groupedConversationManager.closeConversations(); - return Pages.Login.class; - } - - public Class<? extends Pages> register() { - //close all conversations of the current window - this.groupedConversationManager.closeConversations(); - return Pages.Registration.class; - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.deltaspike.view; + +import org.apache.deltaspike.core.spi.scope.conversation.GroupedConversationManager; +import org.superbiz.deltaspike.view.config.Pages; + +import javax.enterprise.inject.Model; +import javax.inject.Inject; + +@Model +public class MenuBean { + @Inject + private GroupedConversationManager groupedConversationManager; + + public Class<? extends Pages> home() { + //close all conversations of the current window + this.groupedConversationManager.closeConversations(); + return Pages.Index.class; + } + + public Class<? extends Pages.Secure> feedback() { + //close all conversations of the current window + this.groupedConversationManager.closeConversations(); + return Pages.Secure.FeedbackList.class; + } + + public Class<? extends Pages> about() { + //close all conversations of the current window + this.groupedConversationManager.closeConversations(); + return Pages.About.class; + } + + public Class<? extends Pages> login() { + //close all conversations of the current window + this.groupedConversationManager.closeConversations(); + return Pages.Login.class; + } + + public Class<? extends Pages> register() { + //close all conversations of the current window + this.groupedConversationManager.closeConversations(); + return Pages.Registration.class; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/RegistrationPage.java ---------------------------------------------------------------------- diff --git a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/RegistrationPage.java b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/RegistrationPage.java index 9853f7c..266d164 100644 --- a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/RegistrationPage.java +++ b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/RegistrationPage.java @@ -1,93 +1,93 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.superbiz.deltaspike.view; - -import org.apache.deltaspike.core.api.scope.GroupedConversation; -import org.apache.deltaspike.core.api.scope.GroupedConversationScoped; -import org.apache.deltaspike.jsf.api.message.JsfMessage; -import org.apache.myfaces.extensions.validator.beanval.annotation.BeanValidation; -import org.apache.myfaces.extensions.validator.crossval.annotation.Equals; -import org.superbiz.deltaspike.WebappMessageBundle; -import org.superbiz.deltaspike.domain.User; -import org.superbiz.deltaspike.domain.validation.Full; -import org.superbiz.deltaspike.repository.UserRepository; -import org.superbiz.deltaspike.view.config.Pages; - -import javax.inject.Inject; -import javax.inject.Named; -import java.io.Serializable; - -@Named -@GroupedConversationScoped -public class RegistrationPage implements Serializable { - private static final long serialVersionUID = 3844502441069448490L; - - @Inject - private UserRepository userService; - - @Inject - private GroupedConversation conversation; - - @Inject - private JsfMessage<WebappMessageBundle> webappMessages; - - private User user = new User(); - - @Inject - private UserHolder userHolder; - - @Equals("user.password") - private String repeatedPassword; - - @BeanValidation(useGroups = Full.class) //triggers UniqueUserNameValidator - public Class<? extends Pages> register() { - this.userService.save(this.user); - this.webappMessages.addInfo().msgUserRegistered(this.user.getUserName()); - - //in order to re-use the page-bean for the login-page - this.conversation.close(); - - return Pages.Login.class; - } - - public Class<? extends Pages> login() { - User user = this.userService.findByUserName(this.user.getUserName()); - if (user != null && user.getPassword().equals(this.user.getPassword())) { - this.webappMessages.addInfo().msgLoginSuccessful(); - this.userHolder.setCurrentUser(user); - return Pages.About.class; - } - - this.webappMessages.addError().msgLoginFailed(); - - return null; - } - - public User getUser() { - return user; - } - - public String getRepeatedPassword() { - return repeatedPassword; - } - - public void setRepeatedPassword(String repeatedPassword) { - this.repeatedPassword = repeatedPassword; - } +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.deltaspike.view; + +import org.apache.deltaspike.core.api.scope.GroupedConversation; +import org.apache.deltaspike.core.api.scope.GroupedConversationScoped; +import org.apache.deltaspike.jsf.api.message.JsfMessage; +import org.apache.myfaces.extensions.validator.beanval.annotation.BeanValidation; +import org.apache.myfaces.extensions.validator.crossval.annotation.Equals; +import org.superbiz.deltaspike.WebappMessageBundle; +import org.superbiz.deltaspike.domain.User; +import org.superbiz.deltaspike.domain.validation.Full; +import org.superbiz.deltaspike.repository.UserRepository; +import org.superbiz.deltaspike.view.config.Pages; + +import javax.inject.Inject; +import javax.inject.Named; +import java.io.Serializable; + +@Named +@GroupedConversationScoped +public class RegistrationPage implements Serializable { + private static final long serialVersionUID = 3844502441069448490L; + + @Inject + private UserRepository userService; + + @Inject + private GroupedConversation conversation; + + @Inject + private JsfMessage<WebappMessageBundle> webappMessages; + + private User user = new User(); + + @Inject + private UserHolder userHolder; + + @Equals("user.password") + private String repeatedPassword; + + @BeanValidation(useGroups = Full.class) //triggers UniqueUserNameValidator + public Class<? extends Pages> register() { + this.userService.save(this.user); + this.webappMessages.addInfo().msgUserRegistered(this.user.getUserName()); + + //in order to re-use the page-bean for the login-page + this.conversation.close(); + + return Pages.Login.class; + } + + public Class<? extends Pages> login() { + User user = this.userService.findByUserName(this.user.getUserName()); + if (user != null && user.getPassword().equals(this.user.getPassword())) { + this.webappMessages.addInfo().msgLoginSuccessful(); + this.userHolder.setCurrentUser(user); + return Pages.About.class; + } + + this.webappMessages.addError().msgLoginFailed(); + + return null; + } + + public User getUser() { + return user; + } + + public String getRepeatedPassword() { + return repeatedPassword; + } + + public void setRepeatedPassword(String repeatedPassword) { + this.repeatedPassword = repeatedPassword; + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/UserHolder.java ---------------------------------------------------------------------- diff --git a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/UserHolder.java b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/UserHolder.java index b59849e..7cef222 100644 --- a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/UserHolder.java +++ b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/UserHolder.java @@ -1,54 +1,54 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.superbiz.deltaspike.view; - -import org.apache.deltaspike.core.api.scope.WindowScoped; -import org.superbiz.deltaspike.domain.User; - -import javax.enterprise.context.Dependent; -import javax.enterprise.inject.New; -import javax.enterprise.inject.Produces; -import javax.inject.Inject; -import javax.inject.Named; -import java.io.Serializable; - -//due to the enhanced entities it isn't possible to use them directly (due to final methods) -@WindowScoped -public class UserHolder implements Serializable { - private static final long serialVersionUID = -7687528373042288584L; - - @Inject - @New - private User user; - - @Produces - @Dependent - @Named("currentUser") - protected User createCurrentUser() { - return this.user; - } - - public void setCurrentUser(User user) { - this.user = user; - } - - public boolean isLoggedIn() { - return this.user.getId() != null; - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.deltaspike.view; + +import org.apache.deltaspike.core.api.scope.WindowScoped; +import org.superbiz.deltaspike.domain.User; + +import javax.enterprise.context.Dependent; +import javax.enterprise.inject.New; +import javax.enterprise.inject.Produces; +import javax.inject.Inject; +import javax.inject.Named; +import java.io.Serializable; + +//due to the enhanced entities it isn't possible to use them directly (due to final methods) +@WindowScoped +public class UserHolder implements Serializable { + private static final long serialVersionUID = -7687528373042288584L; + + @Inject + @New + private User user; + + @Produces + @Dependent + @Named("currentUser") + protected User createCurrentUser() { + return this.user; + } + + public void setCurrentUser(User user) { + this.user = user; + } + + public boolean isLoggedIn() { + return this.user.getId() != null; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/config/Pages.java ---------------------------------------------------------------------- diff --git a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/config/Pages.java b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/config/Pages.java index d973520..d1a6622 100644 --- a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/config/Pages.java +++ b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/config/Pages.java @@ -1,55 +1,55 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.superbiz.deltaspike.view.config; - -import org.apache.deltaspike.core.api.config.view.DefaultErrorView; -import org.apache.deltaspike.core.api.config.view.ViewConfig; -import org.apache.deltaspike.core.api.config.view.controller.ViewControllerRef; -import org.apache.deltaspike.jsf.api.config.view.View; -import org.apache.deltaspike.security.api.authorization.Secured; -import org.superbiz.deltaspike.view.FeedbackPage; -import org.superbiz.deltaspike.view.InfoPage; -import org.superbiz.deltaspike.view.security.LoginAccessDecisionVoter; - -import static org.apache.deltaspike.jsf.api.config.view.View.NavigationMode.REDIRECT; - -@View(navigation = REDIRECT) -public interface Pages extends ViewConfig { - class Index implements Pages { - } - - @InfoPage - class About implements Pages { - } - - class Registration implements Pages { - } - - class Login extends DefaultErrorView implements Pages /*just to benefit from the config*/ { - } - - @Secured(LoginAccessDecisionVoter.class) - //@Secured(value = LoginAccessDecisionVoter.class, errorView = Login.class) - interface Secure extends Pages { - @ViewControllerRef(FeedbackPage.class) - //optional: @View - class FeedbackList implements Secure { - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.deltaspike.view.config; + +import org.apache.deltaspike.core.api.config.view.DefaultErrorView; +import org.apache.deltaspike.core.api.config.view.ViewConfig; +import org.apache.deltaspike.core.api.config.view.controller.ViewControllerRef; +import org.apache.deltaspike.jsf.api.config.view.View; +import org.apache.deltaspike.security.api.authorization.Secured; +import org.superbiz.deltaspike.view.FeedbackPage; +import org.superbiz.deltaspike.view.InfoPage; +import org.superbiz.deltaspike.view.security.LoginAccessDecisionVoter; + +import static org.apache.deltaspike.jsf.api.config.view.View.NavigationMode.REDIRECT; + +@View(navigation = REDIRECT) +public interface Pages extends ViewConfig { + class Index implements Pages { + } + + @InfoPage + class About implements Pages { + } + + class Registration implements Pages { + } + + class Login extends DefaultErrorView implements Pages /*just to benefit from the config*/ { + } + + @Secured(LoginAccessDecisionVoter.class) + //@Secured(value = LoginAccessDecisionVoter.class, errorView = Login.class) + interface Secure extends Pages { + @ViewControllerRef(FeedbackPage.class) + //optional: @View + class FeedbackList implements Secure { + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/security/LoginAccessDecisionVoter.java ---------------------------------------------------------------------- diff --git a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/security/LoginAccessDecisionVoter.java b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/security/LoginAccessDecisionVoter.java index 71a3cfa..1729e49 100644 --- a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/security/LoginAccessDecisionVoter.java +++ b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/security/LoginAccessDecisionVoter.java @@ -1,48 +1,48 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.superbiz.deltaspike.view.security; - -import org.apache.deltaspike.security.api.authorization.AbstractAccessDecisionVoter; -import org.apache.deltaspike.security.api.authorization.AccessDecisionVoterContext; -import org.apache.deltaspike.security.api.authorization.SecurityViolation; -import org.superbiz.deltaspike.WebappMessageBundle; -import org.superbiz.deltaspike.view.UserHolder; - -import javax.enterprise.context.ApplicationScoped; -import javax.inject.Inject; -import java.util.Set; - -@ApplicationScoped -public class LoginAccessDecisionVoter extends AbstractAccessDecisionVoter { - private static final long serialVersionUID = -6332617547592896599L; - - @Inject - private UserHolder userHolder; - - @Inject - private WebappMessageBundle webappMessageBundle; - - @Override - protected void checkPermission(AccessDecisionVoterContext accessDecisionVoterContext, - Set<SecurityViolation> violations) { - if (!this.userHolder.isLoggedIn()) { - violations.add(newSecurityViolation(this.webappMessageBundle.msgAccessDenied())); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.deltaspike.view.security; + +import org.apache.deltaspike.security.api.authorization.AbstractAccessDecisionVoter; +import org.apache.deltaspike.security.api.authorization.AccessDecisionVoterContext; +import org.apache.deltaspike.security.api.authorization.SecurityViolation; +import org.superbiz.deltaspike.WebappMessageBundle; +import org.superbiz.deltaspike.view.UserHolder; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import java.util.Set; + +@ApplicationScoped +public class LoginAccessDecisionVoter extends AbstractAccessDecisionVoter { + private static final long serialVersionUID = -6332617547592896599L; + + @Inject + private UserHolder userHolder; + + @Inject + private WebappMessageBundle webappMessageBundle; + + @Override + protected void checkPermission(AccessDecisionVoterContext accessDecisionVoterContext, + Set<SecurityViolation> violations) { + if (!this.userHolder.isLoggedIn()) { + violations.add(newSecurityViolation(this.webappMessageBundle.msgAccessDenied())); + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/util/InfoBean.java ---------------------------------------------------------------------- diff --git a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/util/InfoBean.java b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/util/InfoBean.java index 3f10344..a7c2bab 100644 --- a/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/util/InfoBean.java +++ b/examples/deltaspike-fullstack/src/main/java/org/superbiz/deltaspike/view/util/InfoBean.java @@ -1,135 +1,135 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.superbiz.deltaspike.view.util; - -import org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor; -import org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver; -import org.apache.deltaspike.core.api.projectstage.ProjectStage; -import org.apache.deltaspike.core.api.provider.BeanManagerProvider; -import org.apache.deltaspike.core.spi.scope.window.WindowContext; -import org.apache.deltaspike.jsf.api.message.JsfMessage; -import org.apache.myfaces.extensions.validator.ExtValInformation; -import org.apache.myfaces.extensions.validator.util.ClassUtils; -import org.superbiz.deltaspike.WebappMessageBundle; -import org.superbiz.deltaspike.view.InfoPage; - -import javax.annotation.PostConstruct; -import javax.enterprise.context.SessionScoped; -import javax.faces.context.FacesContext; -import javax.inject.Inject; -import javax.inject.Named; -import javax.persistence.Persistence; -import javax.validation.Validation; -import java.io.Serializable; - -@SuppressWarnings("CdiUnproxyableBeanTypesInspection") -@Named -@SessionScoped -public class InfoBean implements Serializable { - private static final long serialVersionUID = -1748909261695527800L; - - @Inject - private WindowContext windowContext; - - @Inject - private JsfMessage<WebappMessageBundle> webappMessages; - - @Inject - private ProjectStage projectStage; - - @Inject - private ViewConfigResolver viewConfigResolver; - - private String applicationMessageVersionInfo; - - private String beanValidationVersion; - - private String jpaVersion; - - @PostConstruct - protected void showWelcomeMessage() { - String versionString = ClassUtils.getJarVersion(InfoBean.class); - - if (versionString != null) { - this.applicationMessageVersionInfo = " (v" + versionString + ")"; - } - - this.beanValidationVersion = - ClassUtils.getJarVersion(Validation.buildDefaultValidatorFactory().getValidator().getClass()); - - this.jpaVersion = - ClassUtils.getJarVersion(Persistence.createEntityManagerFactory("demoApplicationPU").getClass()); - - if (!ProjectStage.IntegrationTest.equals(this.projectStage)) { - this.webappMessages.addInfo().msgWelcome(); - } - } - - public boolean isInfoPage() { - ViewConfigDescriptor viewConfigDescriptor = - this.viewConfigResolver.getViewConfigDescriptor(FacesContext.getCurrentInstance().getViewRoot().getViewId()); - - if (viewConfigDescriptor == null) { - return false; - } - - return !viewConfigDescriptor.getMetaData(InfoPage.class).isEmpty(); - } - - public String getProjectStage() { - return this.projectStage.toString(); - } - - public String getApplicationVersion() { - return this.applicationMessageVersionInfo; - } - - public String getDeltaSpikeVersion() { - return ClassUtils.getJarVersion(BeanManagerProvider.class); - } - - public String getCdiVersion() { - try { - return ClassUtils.getJarVersion(BeanManagerProvider.getInstance().getBeanManager().getClass()); - } catch (Exception e) { - e.printStackTrace(); - return "Failed to get CDI Version: " + e.getMessage(); - } - } - - public String getExtValVersion() { - return ExtValInformation.VERSION; - } - - public String getJsfVersion() { - return ClassUtils.getJarVersion(FacesContext.class); - } - - public String getBeanValidationVersion() { - return this.beanValidationVersion; - } - - public String getJpaVersion() { - return this.jpaVersion; - } - - public String getWindowId() { - return this.windowContext.getCurrentWindowId(); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.deltaspike.view.util; + +import org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor; +import org.apache.deltaspike.core.api.config.view.metadata.ViewConfigResolver; +import org.apache.deltaspike.core.api.projectstage.ProjectStage; +import org.apache.deltaspike.core.api.provider.BeanManagerProvider; +import org.apache.deltaspike.core.spi.scope.window.WindowContext; +import org.apache.deltaspike.jsf.api.message.JsfMessage; +import org.apache.myfaces.extensions.validator.ExtValInformation; +import org.apache.myfaces.extensions.validator.util.ClassUtils; +import org.superbiz.deltaspike.WebappMessageBundle; +import org.superbiz.deltaspike.view.InfoPage; + +import javax.annotation.PostConstruct; +import javax.enterprise.context.SessionScoped; +import javax.faces.context.FacesContext; +import javax.inject.Inject; +import javax.inject.Named; +import javax.persistence.Persistence; +import javax.validation.Validation; +import java.io.Serializable; + +@SuppressWarnings("CdiUnproxyableBeanTypesInspection") +@Named +@SessionScoped +public class InfoBean implements Serializable { + private static final long serialVersionUID = -1748909261695527800L; + + @Inject + private WindowContext windowContext; + + @Inject + private JsfMessage<WebappMessageBundle> webappMessages; + + @Inject + private ProjectStage projectStage; + + @Inject + private ViewConfigResolver viewConfigResolver; + + private String applicationMessageVersionInfo; + + private String beanValidationVersion; + + private String jpaVersion; + + @PostConstruct + protected void showWelcomeMessage() { + String versionString = ClassUtils.getJarVersion(InfoBean.class); + + if (versionString != null) { + this.applicationMessageVersionInfo = " (v" + versionString + ")"; + } + + this.beanValidationVersion = + ClassUtils.getJarVersion(Validation.buildDefaultValidatorFactory().getValidator().getClass()); + + this.jpaVersion = + ClassUtils.getJarVersion(Persistence.createEntityManagerFactory("demoApplicationPU").getClass()); + + if (!ProjectStage.IntegrationTest.equals(this.projectStage)) { + this.webappMessages.addInfo().msgWelcome(); + } + } + + public boolean isInfoPage() { + ViewConfigDescriptor viewConfigDescriptor = + this.viewConfigResolver.getViewConfigDescriptor(FacesContext.getCurrentInstance().getViewRoot().getViewId()); + + if (viewConfigDescriptor == null) { + return false; + } + + return !viewConfigDescriptor.getMetaData(InfoPage.class).isEmpty(); + } + + public String getProjectStage() { + return this.projectStage.toString(); + } + + public String getApplicationVersion() { + return this.applicationMessageVersionInfo; + } + + public String getDeltaSpikeVersion() { + return ClassUtils.getJarVersion(BeanManagerProvider.class); + } + + public String getCdiVersion() { + try { + return ClassUtils.getJarVersion(BeanManagerProvider.getInstance().getBeanManager().getClass()); + } catch (Exception e) { + e.printStackTrace(); + return "Failed to get CDI Version: " + e.getMessage(); + } + } + + public String getExtValVersion() { + return ExtValInformation.VERSION; + } + + public String getJsfVersion() { + return ClassUtils.getJarVersion(FacesContext.class); + } + + public String getBeanValidationVersion() { + return this.beanValidationVersion; + } + + public String getJpaVersion() { + return this.jpaVersion; + } + + public String getWindowId() { + return this.windowContext.getCurrentWindowId(); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/deltaspike-fullstack/src/test/java/org/superbiz/deltaspike/test/MockedPageBeanTest.java ---------------------------------------------------------------------- diff --git a/examples/deltaspike-fullstack/src/test/java/org/superbiz/deltaspike/test/MockedPageBeanTest.java b/examples/deltaspike-fullstack/src/test/java/org/superbiz/deltaspike/test/MockedPageBeanTest.java index 72632f9..88be950 100644 --- a/examples/deltaspike-fullstack/src/test/java/org/superbiz/deltaspike/test/MockedPageBeanTest.java +++ b/examples/deltaspike-fullstack/src/test/java/org/superbiz/deltaspike/test/MockedPageBeanTest.java @@ -1,99 +1,99 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.superbiz.deltaspike.test; - -import org.apache.deltaspike.cdise.api.ContextControl; -import org.apache.deltaspike.core.spi.scope.window.WindowContext; -import org.apache.deltaspike.testcontrol.api.mock.DynamicMockManager; -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; -import org.superbiz.deltaspike.WebappMessageBundle; -import org.superbiz.deltaspike.domain.User; -import org.superbiz.deltaspike.repository.UserRepository; -import org.superbiz.deltaspike.view.RegistrationPage; -import org.superbiz.deltaspike.view.config.Pages; - -import javax.faces.context.FacesContext; -import javax.inject.Inject; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; - -//@RunWith(CdiTestRunner.class) -public class MockedPageBeanTest { - - @Inject - private RegistrationPage registrationPage; //will use a the mocked UserRepository - - @Inject - private WindowContext windowContext; - - @Inject - private WebappMessageBundle webappMessageBundle; - - @Inject - private DynamicMockManager mockManager; - - @Inject - private UserRepository userRepository; //will inject the mocked instance - - @Inject - private ContextControl contextControl; - - @Ignore("Does no work because DS cannot mock dynamic repositories") - @Test - public void saveUserWithMockedBean() { - final String userName = "gp"; - final String firstName = "Gerhard"; - final String lastName = "Petracek"; - - // mockito doesn't support interfaces...seriously? but you can mock CDI impl - // here we don't have one so implementing for the test the interface - final UserRepository mockedUserRepository = (UserRepository) Proxy.newProxyInstance( - Thread.currentThread().getContextClassLoader(), - new Class<?>[]{UserRepository.class}, - new InvocationHandler() { - @Override - public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { - return new User(userName, firstName, lastName.toUpperCase() /*just to illustrate that the mock-instance is used*/); - } - }); - mockManager.addMock(mockedUserRepository); - - - this.windowContext.activateWindow("testWindow"); - - this.registrationPage.getUser().setUserName(userName); - this.registrationPage.getUser().setFirstName(firstName); - this.registrationPage.getUser().setLastName(lastName); - this.registrationPage.getUser().setPassword("123"); - - final Class<? extends Pages> targetPage = this.registrationPage.register(); - - Assert.assertEquals(Pages.Login.class, targetPage); - Assert.assertFalse(FacesContext.getCurrentInstance().getMessageList().isEmpty()); - Assert.assertEquals(webappMessageBundle.msgUserRegistered(userName), FacesContext.getCurrentInstance().getMessageList().iterator().next().getSummary()); - - final User user = this.userRepository.findByUserName(userName); - Assert.assertNotNull(user); - Assert.assertEquals(firstName, user.getFirstName()); - Assert.assertEquals(lastName.toUpperCase(), user.getLastName()); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.deltaspike.test; + +import org.apache.deltaspike.cdise.api.ContextControl; +import org.apache.deltaspike.core.spi.scope.window.WindowContext; +import org.apache.deltaspike.testcontrol.api.mock.DynamicMockManager; +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; +import org.superbiz.deltaspike.WebappMessageBundle; +import org.superbiz.deltaspike.domain.User; +import org.superbiz.deltaspike.repository.UserRepository; +import org.superbiz.deltaspike.view.RegistrationPage; +import org.superbiz.deltaspike.view.config.Pages; + +import javax.faces.context.FacesContext; +import javax.inject.Inject; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +//@RunWith(CdiTestRunner.class) +public class MockedPageBeanTest { + + @Inject + private RegistrationPage registrationPage; //will use a the mocked UserRepository + + @Inject + private WindowContext windowContext; + + @Inject + private WebappMessageBundle webappMessageBundle; + + @Inject + private DynamicMockManager mockManager; + + @Inject + private UserRepository userRepository; //will inject the mocked instance + + @Inject + private ContextControl contextControl; + + @Ignore("Does no work because DS cannot mock dynamic repositories") + @Test + public void saveUserWithMockedBean() { + final String userName = "gp"; + final String firstName = "Gerhard"; + final String lastName = "Petracek"; + + // mockito doesn't support interfaces...seriously? but you can mock CDI impl + // here we don't have one so implementing for the test the interface + final UserRepository mockedUserRepository = (UserRepository) Proxy.newProxyInstance( + Thread.currentThread().getContextClassLoader(), + new Class<?>[]{UserRepository.class}, + new InvocationHandler() { + @Override + public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { + return new User(userName, firstName, lastName.toUpperCase() /*just to illustrate that the mock-instance is used*/); + } + }); + mockManager.addMock(mockedUserRepository); + + + this.windowContext.activateWindow("testWindow"); + + this.registrationPage.getUser().setUserName(userName); + this.registrationPage.getUser().setFirstName(firstName); + this.registrationPage.getUser().setLastName(lastName); + this.registrationPage.getUser().setPassword("123"); + + final Class<? extends Pages> targetPage = this.registrationPage.register(); + + Assert.assertEquals(Pages.Login.class, targetPage); + Assert.assertFalse(FacesContext.getCurrentInstance().getMessageList().isEmpty()); + Assert.assertEquals(webappMessageBundle.msgUserRegistered(userName), FacesContext.getCurrentInstance().getMessageList().iterator().next().getSummary()); + + final User user = this.userRepository.findByUserName(userName); + Assert.assertNotNull(user); + Assert.assertEquals(firstName, user.getFirstName()); + Assert.assertEquals(lastName.toUpperCase(), user.getLastName()); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/deltaspike-fullstack/src/test/java/org/superbiz/deltaspike/test/PageBeanTest.java ---------------------------------------------------------------------- diff --git a/examples/deltaspike-fullstack/src/test/java/org/superbiz/deltaspike/test/PageBeanTest.java b/examples/deltaspike-fullstack/src/test/java/org/superbiz/deltaspike/test/PageBeanTest.java index b3855c7..a7239ca 100644 --- a/examples/deltaspike-fullstack/src/test/java/org/superbiz/deltaspike/test/PageBeanTest.java +++ b/examples/deltaspike-fullstack/src/test/java/org/superbiz/deltaspike/test/PageBeanTest.java @@ -1,127 +1,127 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.superbiz.deltaspike.test; - -import org.apache.deltaspike.cdise.api.ContextControl; -import org.apache.deltaspike.core.spi.scope.window.WindowContext; -import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.superbiz.deltaspike.WebappMessageBundle; -import org.superbiz.deltaspike.domain.User; -import org.superbiz.deltaspike.repository.UserRepository; -import org.superbiz.deltaspike.view.RegistrationPage; -import org.superbiz.deltaspike.view.config.Pages; - -import javax.faces.context.FacesContext; -import javax.inject.Inject; -import javax.persistence.PersistenceException; - -@RunWith(CdiTestRunner.class) -public class PageBeanTest { - @Inject - private RegistrationPage registrationPage; - - @Inject - private WindowContext windowContext; - - @Inject - private WebappMessageBundle webappMessageBundle; - - @Inject - private UserRepository userRepository; - - @Inject - private ContextControl contextControl; - - @Test(expected = PersistenceException.class) - public void duplicatedUser() { - final String userName = "tomee"; - final String firstName = "Apache"; - final String lastName = "TomEE"; - - this.userRepository.saveAndFlush(new User(userName, firstName, lastName)); - this.userRepository.saveAndFlush(new User(userName, firstName + "2", lastName + "2")); - } - - @Test - public void saveUser() { - final String userName = "GP"; - final String firstName = "Gerhard"; - final String lastName = "Petracek"; - this.windowContext.activateWindow("testWindow"); - - this.registrationPage.getUser().setUserName(userName); - this.registrationPage.getUser().setFirstName(firstName); - this.registrationPage.getUser().setLastName(lastName); - this.registrationPage.getUser().setPassword("123"); - - Class<? extends Pages> targetPage = this.registrationPage.register(); - - Assert.assertEquals(Pages.Login.class, targetPage); - Assert.assertFalse(FacesContext.getCurrentInstance().getMessageList().isEmpty()); - Assert.assertEquals(webappMessageBundle.msgUserRegistered(userName), FacesContext.getCurrentInstance().getMessageList().iterator().next().getSummary()); - - User user = this.userRepository.findByUserName(userName); - Assert.assertNotNull(user); - Assert.assertEquals(firstName, user.getFirstName()); - Assert.assertEquals(lastName, user.getLastName()); - } - - @Test - public void saveUserAndLogin() { - final String userName = "tt"; - final String firstName = "Tom"; - final String lastName = "Tester"; - this.windowContext.activateWindow("testWindow"); - - Assert.assertTrue(FacesContext.getCurrentInstance().getMessageList().isEmpty()); - - this.registrationPage.getUser().setUserName(userName); - this.registrationPage.getUser().setFirstName(firstName); - this.registrationPage.getUser().setLastName(lastName); - this.registrationPage.getUser().setPassword("123"); - - Class<? extends Pages> targetPage = this.registrationPage.register(); - - Assert.assertEquals(Pages.Login.class, targetPage); - Assert.assertFalse(FacesContext.getCurrentInstance().getMessageList().isEmpty()); - Assert.assertEquals(webappMessageBundle.msgUserRegistered(userName), FacesContext.getCurrentInstance().getMessageList().iterator().next().getSummary()); - - User user = this.userRepository.findByUserName(userName); - Assert.assertNotNull(user); - Assert.assertEquals(firstName, user.getFirstName()); - Assert.assertEquals(lastName, user.getLastName()); - - this.contextControl.stopContexts(); - this.contextControl.startContexts(); - this.windowContext.activateWindow("testWindow"); - - Assert.assertTrue(FacesContext.getCurrentInstance().getMessageList().isEmpty()); - - this.registrationPage.getUser().setUserName(userName); - this.registrationPage.getUser().setFirstName(firstName); - this.registrationPage.getUser().setLastName(lastName); - this.registrationPage.getUser().setPassword("123"); - - targetPage = this.registrationPage.login(); - Assert.assertEquals(Pages.About.class, targetPage); - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.deltaspike.test; + +import org.apache.deltaspike.cdise.api.ContextControl; +import org.apache.deltaspike.core.spi.scope.window.WindowContext; +import org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.superbiz.deltaspike.WebappMessageBundle; +import org.superbiz.deltaspike.domain.User; +import org.superbiz.deltaspike.repository.UserRepository; +import org.superbiz.deltaspike.view.RegistrationPage; +import org.superbiz.deltaspike.view.config.Pages; + +import javax.faces.context.FacesContext; +import javax.inject.Inject; +import javax.persistence.PersistenceException; + +@RunWith(CdiTestRunner.class) +public class PageBeanTest { + @Inject + private RegistrationPage registrationPage; + + @Inject + private WindowContext windowContext; + + @Inject + private WebappMessageBundle webappMessageBundle; + + @Inject + private UserRepository userRepository; + + @Inject + private ContextControl contextControl; + + @Test(expected = PersistenceException.class) + public void duplicatedUser() { + final String userName = "tomee"; + final String firstName = "Apache"; + final String lastName = "TomEE"; + + this.userRepository.saveAndFlush(new User(userName, firstName, lastName)); + this.userRepository.saveAndFlush(new User(userName, firstName + "2", lastName + "2")); + } + + @Test + public void saveUser() { + final String userName = "GP"; + final String firstName = "Gerhard"; + final String lastName = "Petracek"; + this.windowContext.activateWindow("testWindow"); + + this.registrationPage.getUser().setUserName(userName); + this.registrationPage.getUser().setFirstName(firstName); + this.registrationPage.getUser().setLastName(lastName); + this.registrationPage.getUser().setPassword("123"); + + Class<? extends Pages> targetPage = this.registrationPage.register(); + + Assert.assertEquals(Pages.Login.class, targetPage); + Assert.assertFalse(FacesContext.getCurrentInstance().getMessageList().isEmpty()); + Assert.assertEquals(webappMessageBundle.msgUserRegistered(userName), FacesContext.getCurrentInstance().getMessageList().iterator().next().getSummary()); + + User user = this.userRepository.findByUserName(userName); + Assert.assertNotNull(user); + Assert.assertEquals(firstName, user.getFirstName()); + Assert.assertEquals(lastName, user.getLastName()); + } + + @Test + public void saveUserAndLogin() { + final String userName = "tt"; + final String firstName = "Tom"; + final String lastName = "Tester"; + this.windowContext.activateWindow("testWindow"); + + Assert.assertTrue(FacesContext.getCurrentInstance().getMessageList().isEmpty()); + + this.registrationPage.getUser().setUserName(userName); + this.registrationPage.getUser().setFirstName(firstName); + this.registrationPage.getUser().setLastName(lastName); + this.registrationPage.getUser().setPassword("123"); + + Class<? extends Pages> targetPage = this.registrationPage.register(); + + Assert.assertEquals(Pages.Login.class, targetPage); + Assert.assertFalse(FacesContext.getCurrentInstance().getMessageList().isEmpty()); + Assert.assertEquals(webappMessageBundle.msgUserRegistered(userName), FacesContext.getCurrentInstance().getMessageList().iterator().next().getSummary()); + + User user = this.userRepository.findByUserName(userName); + Assert.assertNotNull(user); + Assert.assertEquals(firstName, user.getFirstName()); + Assert.assertEquals(lastName, user.getLastName()); + + this.contextControl.stopContexts(); + this.contextControl.startContexts(); + this.windowContext.activateWindow("testWindow"); + + Assert.assertTrue(FacesContext.getCurrentInstance().getMessageList().isEmpty()); + + this.registrationPage.getUser().setUserName(userName); + this.registrationPage.getUser().setFirstName(firstName); + this.registrationPage.getUser().setLastName(lastName); + this.registrationPage.getUser().setPassword("123"); + + targetPage = this.registrationPage.login(); + Assert.assertEquals(Pages.About.class, targetPage); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/deltaspike-i18n/src/main/java/org/superbiz/deltaspike/i18n/MessageHelper.java ---------------------------------------------------------------------- diff --git a/examples/deltaspike-i18n/src/main/java/org/superbiz/deltaspike/i18n/MessageHelper.java b/examples/deltaspike-i18n/src/main/java/org/superbiz/deltaspike/i18n/MessageHelper.java index 17ddb8e..350bc46 100644 --- a/examples/deltaspike-i18n/src/main/java/org/superbiz/deltaspike/i18n/MessageHelper.java +++ b/examples/deltaspike-i18n/src/main/java/org/superbiz/deltaspike/i18n/MessageHelper.java @@ -1,27 +1,27 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.deltaspike.i18n; - -import org.apache.deltaspike.core.api.message.MessageBundle; -import org.apache.deltaspike.core.api.message.MessageTemplate; - -@MessageBundle -public interface MessageHelper { - - @MessageTemplate("{openejb.and.deltaspike}") - String openejbAndDeltaspike(); -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.deltaspike.i18n; + +import org.apache.deltaspike.core.api.message.MessageBundle; +import org.apache.deltaspike.core.api.message.MessageTemplate; + +@MessageBundle +public interface MessageHelper { + + @MessageTemplate("{openejb.and.deltaspike}") + String openejbAndDeltaspike(); +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/deltaspike-i18n/src/test/java/org/superbiz/deltaspike/i18n/MessageHelperTest.java ---------------------------------------------------------------------- diff --git a/examples/deltaspike-i18n/src/test/java/org/superbiz/deltaspike/i18n/MessageHelperTest.java b/examples/deltaspike-i18n/src/test/java/org/superbiz/deltaspike/i18n/MessageHelperTest.java index b2c7ad6..8f24444 100644 --- a/examples/deltaspike-i18n/src/test/java/org/superbiz/deltaspike/i18n/MessageHelperTest.java +++ b/examples/deltaspike-i18n/src/test/java/org/superbiz/deltaspike/i18n/MessageHelperTest.java @@ -1,56 +1,56 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.deltaspike.i18n; - -import org.apache.deltaspike.core.impl.config.DefaultConfigSourceProvider; -import org.apache.deltaspike.core.spi.config.ConfigSourceProvider; -import org.apache.ziplock.JarLocation; -import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.shrinkwrap.api.ArchivePaths; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.asset.EmptyAsset; -import org.jboss.shrinkwrap.api.spec.WebArchive; -import org.junit.Test; -import org.junit.runner.RunWith; - -import javax.inject.Inject; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -@RunWith(Arquillian.class) -public class MessageHelperTest { - - @Inject - private MessageHelper msg; - - @Deployment - public static WebArchive jar() { - return ShrinkWrap.create(WebArchive.class) - .addClasses(MessageHelper.class) - .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")) - .addAsLibraries(JarLocation.jarLocation(ConfigSourceProvider.class)) - .addAsLibraries(JarLocation.jarLocation(DefaultConfigSourceProvider.class)); - } - - @Test - public void check() { - assertNotNull(msg); - assertEquals("OpenEJB and DeltaSpike are cool products!", msg.openejbAndDeltaspike()); - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.deltaspike.i18n; + +import org.apache.deltaspike.core.impl.config.DefaultConfigSourceProvider; +import org.apache.deltaspike.core.spi.config.ConfigSourceProvider; +import org.apache.ziplock.JarLocation; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.ArchivePaths; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.EmptyAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.inject.Inject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@RunWith(Arquillian.class) +public class MessageHelperTest { + + @Inject + private MessageHelper msg; + + @Deployment + public static WebArchive jar() { + return ShrinkWrap.create(WebArchive.class) + .addClasses(MessageHelper.class) + .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml")) + .addAsLibraries(JarLocation.jarLocation(ConfigSourceProvider.class)) + .addAsLibraries(JarLocation.jarLocation(DefaultConfigSourceProvider.class)); + } + + @Test + public void check() { + assertNotNull(msg); + assertEquals("OpenEJB and DeltaSpike are cool products!", msg.openejbAndDeltaspike()); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/dynamic-dao-implementation/src/main/java/org/superbiz/dynamic/User.java ---------------------------------------------------------------------- diff --git a/examples/dynamic-dao-implementation/src/main/java/org/superbiz/dynamic/User.java b/examples/dynamic-dao-implementation/src/main/java/org/superbiz/dynamic/User.java index 4d9de82..0e397b1 100644 --- a/examples/dynamic-dao-implementation/src/main/java/org/superbiz/dynamic/User.java +++ b/examples/dynamic-dao-implementation/src/main/java/org/superbiz/dynamic/User.java @@ -1,61 +1,61 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.dynamic; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; - -@Entity -@NamedQueries({ - @NamedQuery(name = "dynamic-ejb-impl-test.query", query = "SELECT u FROM User AS u WHERE u.name LIKE :name"), - @NamedQuery(name = "dynamic-ejb-impl-test.all", query = "SELECT u FROM User AS u") -}) -public class User { - - @Id - @GeneratedValue - private long id; - private String name; - private int age; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.dynamic; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.NamedQueries; +import javax.persistence.NamedQuery; + +@Entity +@NamedQueries({ + @NamedQuery(name = "dynamic-ejb-impl-test.query", query = "SELECT u FROM User AS u WHERE u.name LIKE :name"), + @NamedQuery(name = "dynamic-ejb-impl-test.all", query = "SELECT u FROM User AS u") +}) +public class User { + + @Id + @GeneratedValue + private long id; + private String name; + private int age; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/6e2a4f7c/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/BoostrapUtility.java ---------------------------------------------------------------------- diff --git a/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/BoostrapUtility.java b/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/BoostrapUtility.java index d74b1e7..458c919 100755 --- a/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/BoostrapUtility.java +++ b/examples/dynamic-datasource-routing/src/main/java/org/superbiz/dynamicdatasourcerouting/BoostrapUtility.java @@ -1,51 +1,51 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.superbiz.dynamicdatasourcerouting; - -import javax.annotation.PostConstruct; -import javax.ejb.Singleton; -import javax.ejb.Startup; -import javax.ejb.TransactionAttribute; -import javax.ejb.TransactionAttributeType; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; - -/** - * OpenJPA create the table at the first query. - * To avoid to have to create the table manunally this singleton will do it for us. - */ -@Startup -@Singleton -public class BoostrapUtility { - - @PersistenceContext(unitName = "db1") - private EntityManager em1; - - @PersistenceContext(unitName = "db2") - private EntityManager em2; - - @PersistenceContext(unitName = "db3") - private EntityManager em3; - - @PostConstruct - @TransactionAttribute(TransactionAttributeType.SUPPORTS) - public void initDatabase() { - em1.find(Person.class, 0); - em2.find(Person.class, 0); - em3.find(Person.class, 0); - } -} +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * <p/> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p/> + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.dynamicdatasourcerouting; + +import javax.annotation.PostConstruct; +import javax.ejb.Singleton; +import javax.ejb.Startup; +import javax.ejb.TransactionAttribute; +import javax.ejb.TransactionAttributeType; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; + +/** + * OpenJPA create the table at the first query. + * To avoid to have to create the table manunally this singleton will do it for us. + */ +@Startup +@Singleton +public class BoostrapUtility { + + @PersistenceContext(unitName = "db1") + private EntityManager em1; + + @PersistenceContext(unitName = "db2") + private EntityManager em2; + + @PersistenceContext(unitName = "db3") + private EntityManager em3; + + @PostConstruct + @TransactionAttribute(TransactionAttributeType.SUPPORTS) + public void initDatabase() { + em1.find(Person.class, 0); + em2.find(Person.class, 0); + em3.find(Person.class, 0); + } +}