Vani Kumar

Greenhorn
+ Follow
since Jul 17, 2014
Merit badge: grant badges
For More
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
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vani Kumar

I have a situation to load data while JSF page loads. Also have a filter which populates user information from http request.

I was expecting the filter first to populate the user information and in the managed bean get method to verify the user information and get the data (from database). But in this case i see the managed bean get method is invoked before filter populates user information and i get null pointer exception because the user information is null.

I had to work around to get the user information from FacesContext in the managed bean get method because the user information wasn't available. Is there a way to make sure the filter is invoked first?
9 years ago
JSF
I already have the logging check in my code, i saw the situation like some of developers from my team couldn't even invoke the @AroundInvoke method (and there were no compile or runtime errors). I was checking whether i can verify the call to @AroundInvoke method. My concern is if the interceptor isn't invoked and don't see any errors, i might be allowing the user to access the application without verifying the entitlements.
I have an interceptor (configured with beans.xml from the following link, IBM Specs) on JAX-RS resource method for checking user entitlements. How can i verify if the interceptor (method annotated with @AroundInvoke) is being invoked?
I know this might not be real question, please suggest if any ideas.
My bad!, it should have been like below in beans.xml.

<interceptors>
<class>com.example.jaxrs.SecurityCheckInterceptor</class>
</interceptors>
I have just enabled CDI on Websphere 8.5.5 and added interceptors

In beans.xml file


SecurityChecked annotation





In JAX-RS class as below



When i deploy EAR, i get below error.

WebContainerL I WebContainerLifecycle startApplication OpenWebBeans Container is starting...

[10/15/14 14:53:15:259 EDT] 00000067 BeansDeployer E BeansDeployer deploy org.apache.webbeans.exception.WebBeansConfigurationException: Given class : interface com.example.jaxrs.SecurityChecked is not a interceptor class

Any suggestions what would be the cause of this error?
I have 2 enums like below





How can i map the same names in 2 enums and get message from enum 1 and code from enum 2.
9 years ago
If i need to mock RESTful resource class and the facade method as below, the facade won't be mocked.

e.g.,



How to mock the facade method call inside RESTful(JAX-RS) resource class? Is there possibility i can mock both resource class and method calls inside it.
9 years ago
How can i POST JSON string into POST/PUT request method using RestFuse?

@HttpTest( method = Method.POST, path = "/" )
public void postStocks() {
assertOk( response );
}

with JSON string as
e.g.,



I can't use content in @HTTPTest (can't use JSON string in content).
9 years ago
-- Answer posted below
I learnt that i don't actually need to spy, i can just mock the internal method as well and that works

e.g.,

9 years ago
Thanks! will use code tags next time. Yes, I checked the other thread and will see if that helps.
9 years ago
-- Added spying after checking spy from Mockito documentation and gets NullPointerException for empid. findEmployeeById method is expecting empid and its null, do i need to spy the empid as well. I don't think i can spy the String object right.

-- Exception after spying
java.lang.NullPointerException
at EmployeeRegistryImpl.findEmployeeById(EmployeeRegistryImpl.java:)
at EmployeeRegistryImpl.createEmployee(EmployeeRegistryImpl.java:)
at EmployeeRegistryImplTest.createEmployeeReturnsNotNull(EmployeeRegistryImplTest.java:)
9 years ago
I have 2 methods, first method in jpa class to find id and another method to create a record (which checks whether the id already exists and creates a record if the record with id doesn't exists).

I wrote test cases with JUnit and Mockito frameworks for first method, findEmployeeById. e.g.,

I tried to write the test case for createEmployee

Since the createEmployee method calls internally findEmployeeById and will get NullPointerException, how can i mock the findEmployeeById (and empid as an input to the same method) for createEmployee method in my test class, EmployeeRegistryTest.
9 years ago
I am using Dozer BeanMapper to copy an object to another object based on field names. I have 4 classes, two as java classes (User, PhoneNumber) and the other as jpa entities (User, PhoneNumber)
I have to copy the User to jpa User entity object.

Java classes:

Class User{
int userid;
List<PhoneNumber> phoneNumbers;
}

Class PhoneNumber{
int userid;
String phoneNumber
}
JPA Entities:

@Entity
Class User{
int userid;
List<PhoneNumber> phoneNumbers;
}

@Entity
Class PhoneNumber{
int userid;
String phoneNumber
}

I have a mapping in dozerBeanMapping file as below

<mapping map-id="user">
<class-a>User</class-a>
<class-b>User</class-b>
<field>
<a>userid</a>
<b>userid</b>
</field>
<field>
<a>phoneNumbers</a>
<b is-accessible="true">phoneNumbers</b>
</field>
</mapping>

<mapping map-id="phoneNumbers">
<class-a>PhoneNumber</class-a>
<class-b>PhoneNumber</class-b>
<field>
<a>userid</a>
<b>userid</b>
</field>
<field>
<a>phoneNumber</a>
<b>phoneNumber</b>
</field>
</mapping>

For the PhoneNumber object, i won't be getting userid, how can i copy the userid from the map-id "user" to map-id "phoneNumbers"
9 years ago
I realized this feature can be achieved by using libraries like java framework/library like Odata4j, Apache olingo.
9 years ago
Don't have quite experience on parser and regular expressions as well. Please suggest any ideas. Thanks!

Just found some parser generators online, will do some research, learn and will check my luck.
9 years ago