seenu java

Greenhorn
+ Follow
since Oct 03, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by seenu java

public abstract class BaseClass {

@Autowired
protected DBproperties dbprop;

}

public class SampleClass extends BaseClass
{
@Autowired
private OrderService orderService ;

valdiateOrder(String input){
String config = dbprop.getProperty("config");


}


}


public class TestSampleClass{

@InjectMocks
SampleClass sampleClass ;
@Mock
private OrderService orderService ;

@Test
public void testValidateOrder(){
DBproperties dbprop = mock(DBproperties .class);
when(dbprop.getProperty("config")).thenReturn("xxxx");
assertNotNull(SampleClass.valdiateOrder("xxx"));
}
}

am using Junit4 and Mockito for test cases,in the above code dbprop.getProperty("config") throwing null pointer exception because of dbProp as null, please help me out why it was not mocked?
9 years ago
already we are using interceptor,i think it would n't be good change to filter because of this problem.
9 years ago
I have a requirement that i have to modify a request parameter value before it reaches controller,So i think in interceptor i have to change?in filters by using HttpServletRequestWrapper we can modify the request.but how can we
do using interceptor?
9 years ago
if the values are predefined,it is simple ,you can do with javascript.

<s:select id="dropdown1" onchange = "resetDropdown2()" >

<s:select id="dropdown2" onchange = "resetDropdown1()">


javascript:

function resetDropdown2{
your logic here
document.getElementById("dropdown2").value=""; // here you can set by the index also

}
function resetDropdown1{
your logic here
document.getElementById("dropdown1").value=""; // here you can set by the index also

}
10 years ago
Sam: i could not find the answer in documentation,if you know the answer please post it.

Ranjan: i know we should not use in Standalone applications,but if we use what happens?
10 years ago


Hi,
What happens if we use "request" and "session" scopes(in spring) in standalone(desktop) applications?
10 years ago
Hi Rajesh,
am not sure about the Shared lock and how it works,but two synchronized methods can be executed simultaneously when two different locks gets on two different synchornized methods(seperate locks),
could you please provide any links or information on shared locks.

http://download.oracle.com/javase/tutorial/essential/concurrency/locksync.html checks this might be useful
sorry wrongly posted above one
10 years ago
you have to implement interceptor for that,check this works out for you?

public class LoginInterceptor extends AbstractInterceptor {

private static final String USER = "user";


public String intercept (ActionInvocation invocation) throws Exception {
// Get the action context from the invocation so we can access the
// HttpServletRequest and HttpSession objects.
final ActionContext context = invocation.getInvocationContext ();
HttpServletRequest request = (HttpServletRequest) context.get(HTTP_REQUEST);
HttpSession session = request.getSession (true);

Object user = session.getAttribute (USER);
if (user != null) {
// The user already logged in..
return invocation.invoke (); // send to other interceptor/other page

} else {
return "login"; // if login failed/invalid user redirecting to login page(configure in struts.xml file)
}
}
}
10 years ago
you have to implement interceptor for that,check this works out for you?

public class LoginInterceptor extends AbstractInterceptor {

private static final String USER = "user";


public String intercept (ActionInvocation invocation) throws Exception {
// Get the action context from the invocation so we can access the
// HttpServletRequest and HttpSession objects.
final ActionContext context = invocation.getInvocationContext ();
HttpServletRequest request = (HttpServletRequest) context.get(HTTP_REQUEST);
HttpSession session = request.getSession (true);

Object user = session.getAttribute (USER);
if (user != null) {
// The user already logged in..
return invocation.invoke (); // send to other interceptor/other page

} else {
return "login"; // if login failed/invalid user redirecting to login page(configure in struts.xml file)
}
}
}
10 years ago
the "lock" is associated with synchronized methods only,two synchronized methods cant run at a time,but non-synchronized methods can execute simultaneously.