EJB / EE :: How To Unit Test MDBs And Session Beans

Apr 18, 2014

What are the best practices for unit testing MDBs and session beans ?How can they be tested without running an application server ?

View Replies


ADVERTISEMENT

EJB / EE :: Session Beans Concurrency

Jan 13, 2015

I'm trying to understand the concurrent model of each EJB session bean types.

The singleton is well documented and seems clear to me... Only one instance and many threads using it but each method by default is synchronized because @Lock is defaulted to WRITE. We can let multiple threads use on method with @Lock(READ).

The stateless beans are in a pool I think I read somewhere that the container will ensure only one thread is using one instance at a time but this instances are recycled/reused so many threads can use the same instance but one at a time.

Is this correct ? or is it possible that multi-threading occur in one instance of SLSB ?If in the client I obtain a single reference of a SLSB and share this "instance reference" in multiple threads is it true that all the threads could use different instances on the server side ?

The stateful instance I obtain in the client is linked to one server instance and any method call will target the same instace. If many threads are using the same reference, all method calls will be synchronized and waiting for a certain amount of time that can be defined in @AccessTimeout and if the timeout is reach will end with a ConcurrentAccessException.

Can we use @Lock(READ) and let many thread use the same method like in a singleton ?

View Replies View Related

Getting NullPointer Exception In Unit Test At Activemq Connection Factory Creation

Dec 2, 2014

I have the following unit test that gives me a null pointer exception. The debugger goes to the finally block right after the line that creates a connection factory. Here's the test:

@Test
public void receiveMessage() throws Exception {
MessageConsumer consumer = null;
ConnectionFactory connectionFactory = null;
Connection connection = null;
Session session = null;
Destination destination = null;

[code]....

View Replies View Related

How To Call EnrolStudent Method On Unit Constructor In Another Class When Create A New Unit

Mar 29, 2014

public Unit(String code, String name)
{
enrolStudent(student);
this.unitCode = code;
this.unitName = name;
}
public void enrolStudent(Student newStudent){
students = new ArrayList<Student>();
newStudent = new Student(24662496, "Kingsley", " Iwunze");
students.add(newStudent);
}

how can I call this enrolStudent() method on this Unit constructor in another class when I create a new Unit. all I need is to enroll students in units when units are created. below is my create unit method.

public void createUnits( ){
units = new ArrayList<Unit>();
units.add(new Unit("FIT2034", "Java Programming 2"));
units.add(new Unit("FIT2024", "Software Engineering"));
units.add(new Unit("MAT1830","Discrete Maths"));
unit.enrolStudent(new Student(25486321, "Julia", "Garcia"));
unit.enrolStudent(new Student(44589736, "James", "Olivia"));
unit.enrolStudent(new Student(47852103, "Lucky", "Thyriod"));
}

View Replies View Related

JSP :: Page Directive Attribute Session False - Yet Session Created

Feb 26, 2014

May be I did not understand the meaning and usage of attribute "session" in page directive. My understanding is if session=false, in page directive, then the JSP page will not participate in the session. However, I have my welcomepage as below:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" session="true"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
........
.......
<%= session %>
<c:out value="${pageContext.request.session}"/>

if I choose session=true, then both ways of accessing session works , which means the JSP page participated in the session.

But if I change the session=false, then <%= session %> fails, but <c:out value="${pageContext.request.session}"/> does not fail.

how can c:out still show the session, when session = false

View Replies View Related

Servlets :: Can Access Session Object Even Session Is Time Out

Jun 4, 2014

Can I access the session object even session has been expired? I need to check whether session is expired or not for each request.The session invalidation is set null the session object. What I concluded, session time out I can access session object but session invalidation I can not access session object. How can I find the session time out by using session object?

View Replies View Related

Web Services :: Rest Session Not Getting Invalidated After Invalidating UI Session?

Dec 17, 2014

I have 2 war in 1 EAR.

War A corresponds to UI

War B corresponds to Rest

1) From War A, I login to the application and then fetch some users that is a rest call. I get the response back from rest in json form that ui consumes and display the data on page.

2) Now I click on the logout link from ui jsp. This logs out the session from Ui. I use <form data-dojo-type="dijit/form/Form" based logout.

3) I then go to the proxy (using burp) and manually request the rest call which I made in step no 1), the rest gives the response back with the same json object returned in step no 1) This shows that the logout action on step 2) is invalidated the session from War A (ui war) but the session or cookie based from WAR B (rest war) is not invalidated.

Expected outcome:After I Logout from War A(ui war), the session must also get invalidated from war B (rest war) and manually request from proxy should not get the same response object as received in step 1)

View Replies View Related

Servlets :: Updating Session Value But Same Session In JSP Page Not Updated

Jul 8, 2014

I am developing a e-commerce college project, here i add the items in the cart(a div tag in the jsp page) via servlet by creating sessions,

flow control: shopping jsp (when user wants to add an item in the cart) --> item servlet (which is used to create session and synchronized it) --> cart servlet(which is used to add items in the arraylist and show them in the shopping.jsp's div tag + it also sets the total purchase amount in the session variable "totalpurchase")

now after that user wants to proceed to checkout, here i use the onclick event to check the minimumshopping amount must be less than the totalpurchase (totalpurchase which i had setted in the session),but my jsp page is unable to rechognise the updated value of the totalpurchase, yes, if i reload the page, it rechognises the new updated value of the totalpurchase? but i want it to rechognise the updated total purchase value, without reloading he jsp page..

View Replies View Related

EJB / EE :: JTA And Dynamic Persistence Unit?

Jan 26, 2015

In my application, users select the year and manage data for that year (for example, they can choose 2014 for managing invoices for 2014, then switch to 2015 and work with that year). Each year as his own database.

I'am able to change persistence unit connection at runtime with Persistence.createEntityManagerFactory(PU_NAME,map_with_connection_info) This procedure build a non-jta environment.

It is possible to create entityManager / entityManagerFactory with JTA ?

I don't want to create new persistence unit each year or each time a new database is required.

View Replies View Related

Shifting Row From 2D Array Down One Unit?

Feb 24, 2014

So I have this 2D array that contains some Object foo.

[f] [f] [f][f]

[3][3][3][3]

[b][b][b][b]

[x][x][x][x]

[ ][ ][ ][ ]

[ ][ ][ ][ ]

[ ][ ][ ][ ]

I want to shift all the rows down one unit, starting for the rows containing x. So the x row is first shifted to row 4. then the b row shifted to where the x row was, row 3 and so on. My question is:

1. How can I check if the next row is empty

2. How do I shift a row down

Here's my attempt:

Java Code:

//board is the 2D array defined elsewhere
public void shiftRowDown(){
int counter = 0;
int rowCounter = 0;
for (int i = 0; i < this.board.length; i++) {

[code]....

Is this correct.

View Replies View Related

Website Interaction Using HTML UNIT

Apr 23, 2015

I am having a difficult time trying to get results from the code below. The purpose is for my program to insert the DHL tracking number in the tracking text box, and then for the program to "click" the search button and get the tracking results.

This is the code:

import com.gargoylesoftware.htmlunit.WebClient;
import java.io.*;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import java.net.*;
public class DHL {

[Code]...

These are the results I am getting in the console (in red), which look like an error:

Apr 23, 2015 7:55:49 PM com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement addbehavior
WARNING: Unimplemented behavior: #default#userdata
Exception in thread "main" com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[*] attributeName=[name] attributeValue=[sbtc]
at com.gargoylesoftware.htmlunit.html.HtmlPage.getElementByName(HtmlPage.java:1747)
at htmlTest.main(htmlTest.java:17)

I just cannot figure it out for the life of me. Also, is there a community that focuses on HTML Unit?

View Replies View Related

EJB / EE :: Bean Annotations And Unit Testing?

Mar 6, 2014

I have a bean that represents data been collected from a form on a jsp page. Currently I would like to validate my fields and write some test cases for them. As you can see from my test case example I test a string in the hope that it fails because it contains only one letter. My problem is my unit test is passing. The reason this is from what I can tell is that at runtime it fails when I try to persist my object using my entity manager. During my unit test I just I don’t call my entity manager I just try and set the field.

What I thought would happen was that when I use my bean fields set method the annotations would be checked and fail at that point. Hence why I expected my unit test in this case to fail.

What I would like to know is

1.Are annotations specifically designed to validate when I persist my object and am I using them incorrectly at this point?

2.Is this the best method to use to validate fields, is there a better way, should I write my own code to validate for me when I set my value?

a. Should I throw an exception from the set method of each bean field?

Unit Test:

@Test
public void testName(){
Human h=new Human();
try {
h.setFname("a");
} catch (Exception e) {
// TODO Auto-generated catch block
fail("failed");
e.printStackTrace();

[code]....

View Replies View Related

Time Unit Conversion Program

Feb 8, 2015

So, here is the question I have been working on: Write a java class named Time that prompts the user to input the elapsed time for an event in seconds. The program then outputs the elapsed time in hours, minutes, and seconds. (For example the elapsed time is 9630 seconds, and then the output is 2:40:30 ).Hint: an hour has 3600 seconds and a minute has 60 seconds. Use Scanner class for reading the input.

Here is my code:

import java.util.Scanner;
public class Time {
public static void main(String[] args) {
Scanner scan= new Scanner(System.in);
System.out.println("Enter the elapsed time in seconds:");
int totalseconds= scan.nextInt();

[Code] .....

Now, I know I am supposed to use the remainder operator to figure out the time in minutes and seconds, but the hours has be a little confused. Right now this code compiles but gives me an exception.

View Replies View Related

JSF :: Persisting Beans In A Database

Apr 8, 2014

This is a general question about best practices for handling persisted data in JSF. My JSF page is going to have several fields that map to a managed bean. Upon a button click the fields of this bean are going to be persisted in a database. Is it better to use another bean with application scope to handle the JDBC code, or should I have a method in the bean itself to handle that? Similarly I'll need a method to retrieve the information upon a user request.

View Replies View Related

JSF :: Viewscoped Managed Beans

Nov 24, 2014

I have a primefaces editable datatable with column filtering feature.The datatable has live scrolling feature.The problem that i am facing here is that both filtering and scrolling are happening correctly with Request scoped managed bean but when the scope of the same bean is changed to view scope(javax.faces.bean.ViewScoped) then the filtering happens but on removing the keyed in key word from filter box the table content is not reset to original state and also i am not able to scroll down to next set of records on reaching the end of scrolling.Cell editing feature is working perfectly.

One thing that i observed is ,currently i am querying 5000 odd records to load into datatable.But if the number of records is limited below 5000 scrolling is happening correctly but problem with filtering remains same.I even tested by upgrading to Primefaces 5.1 from 3.Code snippet of xhtml page

<h:form id="form">
<div id="content">

<p:dataTable id="workSpaceList" var="data"
value="#{workSpaceBean.list}" widgetVar="multiSelection"
selection="#{workSpaceBean.selectedRows}" resizableColumns="true"
liveScroll="true" scrollRows="10" scrollWidth="90%"
scrollHeight="70%" styleClass="datatable"
tableStyle="table-layout:auto;width:auto important!;height:auto important!;padding-left:15px;"
scrollable="true" editable="true" editMode="cell"
filteredValue="#{workSpaceBean.filteredWorkSpaceItems}"
rowKey="#{data.lpID}" >

[code]....

View Replies View Related

JavaFX 2.0 :: VRML - Unit Of Measure Convention In 3D?

Apr 12, 2015

When creating VRML, there is a convention that one unit corresponds to 1 metre in the real world. This makes sharing models easier. Is there any similar convention for JavaFX 3D?

View Replies View Related

JSF :: Using Generic Templates For Managed Beans

Aug 5, 2014

I'm wondering if there's a way to build a template for managed beans which could be extended by a constructor instead of re-writing beans for each entity. I can do that quite easily for Dao objects by creating facades and using those facades to create Dao implementations for specific entities. Not sure if the same concept works for managed beans and haven't really come accross any searches.

I wrote the following but I'm not sure how to implement or even if the concept of generics and templating can be applied to managed beans in the same way it can be applied to Dao classes:

public class BeanTemplate<T> {
private ListDataModel<T> listModel;
@EJB
private GenDao dao;
private Class<T> entityClass;

[Code] .....

The above assumes there's only one method needed in the bean. I thought of extending like this:

public class EmployeeBean extends BeanTemplate<Employee> {
public EmployeeBean() {
super(Employee.class);
}

// how can the methods be called??

Is the same concept for creating dao templates possible for managed beans?

View Replies View Related

JSF :: Not Showing Up Beans Attributes In XHTML

Jan 29, 2015

My code of start.xhtml is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">

[Code] .....

when I deploy the app(glassfish) I get this message only:
hi #{user.minimum} a #{user.maximum} .

Instead of a picture: wave.med.gif and message:
hi 0 a 10 .

file hierarchy is attached

View Replies View Related

JSF :: Request Scoped Action Beans

May 24, 2014

If I have the next request scoped JSF bean for example:

public class UserBean {
private String name;
private String surname;
public String saveUser(){
//service is called to save a user
}
public String updateUser(){
//service is called to update a user

[Code] ....

1.In struts for example the Action classes are singletons and I think is the way it has to be because they contain business logic and is the same logic for every user but in JSF because of you mix properties from a form and methods with business logic, these beans have to be request scoped like the above one but is very wierd that a bean which contains business logic(saveUser()....) be request scoped;I dont see it effective, is like creating a new servlet each time you want to save a user but I think is the way JSF works, right?

2 To avoid the mixing of form properties in a bean with business logic, some people say to have the form beans request scoped and actions beans session scoped.

- Is this right?
- How then can you get the request form bean in the action bean?
- The scopes in JSF are request, session and view so you cannot create singleton action beans, the best you can get is a session action bean, right?. Once again I dont see the point of creating action beans with session scoped,they should be application scoped if it existed

View Replies View Related

Java Beans Usage - Storing Data

Mar 7, 2015

I've spent almost 3 hours on googling about java beans and where it is usable. What I've figured out is that a bean has a public non-arg constructor, properties and getters/setters to manipulate them. I also know that a bean contains no logic, only fields. However, I don't fully understand why I need to use beans instead of normal classes even if a class can do the same things like a bean? Are beans used to store data or what?

View Replies View Related

Write Unit Tests When Some Other Classes Are Involved And Abstraction Is Much Higher?

Mar 5, 2015

I have two classes Person and Group. Group object is suppose to contain many Persons, How can I write unit tests when some other classes are involved and abstraction is much higher?

View Replies View Related

Calculate Possible Tiles Clicked Unit Can Be Moved On And Display It To Player

May 15, 2014

Alright, so I'm having problems with lines 11 - 55. I'm trying to calculate the possible tiles the clicked unit can be moved on and display it to the player.

The field is a 9 (columns) by 5 (rows) grid. A unit with can move tiles horizontally or vertically based on its movement.

Example: (unit = o; possible tiles = x) (assuming movement of 2).

[ ][ ][ ][ ][x][ ][ ][ ][ ]
[ ][ ][ ][x][x][x][ ][ ][ ]
[ ][ ][x][x][o][x][x][ ][ ]
[ ][ ][ ][x][x][x][][ ][ ]
[ ][ ][ ][ ][x][ ][ ][ ][ ]

I tried to calculate movement by finding out what column the unit is in, subtracting the column it wants to go to, multiplying the difference by *-1 if the difference is less than 0. Then, doing the same with rows and adding the difference of columns to the difference of rows and comparing it to the unit's movement. Unfortunately, with my code, it seems to move in any directions.

@Override
public void mouseClicked(MouseEvent e) {
if (Main.cards.size() > 0) {
mainloop: for (int i = 0; i < Main.cards.size(); i++) {
Card c = (Card) Main.cards.get(i);
int startingColumn = 0;

[Code] ......

View Replies View Related

JSF :: Model Of Backing Beans / Separated Class Or Just Properties?

May 29, 2014

I have seen in some examples like URL... a good design is to have the model and the action methods in one just single bean and the model not to be a separated class but a few properties like this:

public class CustomerBean implements Serializable{
//DI via Spring
CustomerBo customerBo;
[b]public String name;[/b]
[b]public String address;[/b]
//getter and setter methods

[code]...

Some questions:

1. If you are using hibernate or any other ORM like the above example(URL...), why not to use the hibernate pojo bean directly like it represented the form instead of using properties?:

public class CustomerBean implements Serializable{
//DI via Spring
CustomerBo customerBo;
[b]Customer customer;[/b] //represents the properties of a form
//getter and setter methods
public void setCustomerBo(CustomerBo customerBo) {
this.custom

2. Why is it said that JSF represents the purest MVC? Spring separates the model from the view too and Struts does too. I dont really understand it

View Replies View Related

JSF :: Primefaces In-cell Editing Not Working With Viewscoped Managed Beans?

Nov 17, 2014

I have an in-cell editable data table with a viewscoped managed bean.I found that the control never goes to the ajax event method onCellEdit when the scope of the bean is @Viewscoped but it works when the scope is changed to request scope.how to get this feature work with viewscope.Below is my code snippet

xhtml snippet

<p:dataTable id="workSpaceList" var="data"
value="#{workSpaceBean.lpInfoList}" widgetVar="multiSelection"
selection="#{workSpaceBean.selectedRows}"
scrollable="true" rowIndexVar="index" editable="true"
editMode="cell".......>

[code]....

View Replies View Related

Swing/AWT/SWT :: Stopwatch - User Select How Timer Format Is On Java Beans

Mar 17, 2014

I am working on a java bean, on a stopwatch

private String displayFormat = "%02d:%02d:%02d";// produces 00:00:00 hour:min:seconds
public void timerHasChanged() {
currentTime = System.currentTimeMillis();
// How long has been taken so far?
long secsTaken = (currentTime - startTime) / 1000;
long minsTaken = secsTaken / 60;
secsTaken %= 60;
long hoursTaken = minsTaken/60;
minsTaken %= 60;

Formatter fmt = new Formatter();
fmt.format(displayFormat, hoursTaken, minsTaken, secsTaken);
timerJbl.setText(fmt.toString());

How would i code the get and set method for format, so in property tab a user can choose if they want the timer shown in seconds, or minutes or hours or seconds&minutes

View Replies View Related

EJB / EE :: Session Bean Must Not Extend Another Session Bean?

Nov 9, 2014

I have tried this example ([URL].../) with CarDao extending the BaseDao, it works like a charm.However, from the CarDao class, my NetBeans underlined the class name “CarDao” with the error message “A session bean must not extend another session bean.” But I can compile, deploy and run the application without any problem.

I have also heard that a session bean cannot extend another session bean, but why it works here?

I am using Java EE 6, NetBeans 8.0.1 and WebLogic 12c for this code testing.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved