Tuesday, June 30, 2015

The method post(string) is undefined for controller test


The method post(string) is undefined for controller test

Problem :


I came across this common exception when i was using mocks for unit testing spring application.

Exception I Encountered Was :


################################################################################################### ################

the method post(string) is undefined for controller test

################################################################################################### ################

Solution :


When unit testing your spring application with mocks you need to make sure that you are using the necessary static imports in your code.
See below for the list of static imports to use.
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

Once i had the static imports in place it resolved the exception. Hope this helps resolve your exception, Happy Coding.

Similar Exception :


- How to test a spring controller method by using MockMvc?
- My test helper methods get() status() are undefined
- the method post(string) is undefined for controller test
- Integration testing of spring MVC applicaitons
- the method print() is undefined for the type Controller


Tuesday, June 23, 2015

project build error: 'dependencies.dependency.groupid' for null:spring-test.jar


project build error: 'dependencies.dependency.groupid' for null:spring-test.jar

Problem :


I came across this common exception when i was manually updating maven dependencies in eclipse.

Exception I Encountered Was :


###################################################################################################################

project build error: 'dependencies.dependency.groupid' for null:spring-test.jar

###################################################################################################################

Solution :


I was manullay updating maven dependencies and gave artifact groupid instead of groupId (I is caps), be specific when you type the artifacts. Do cross check your artifacts if you have manually updated your artifacts.

Similar Exception :

     

- 'dependencies.dependency.version' is missing error, but version is managed in parent
- 'dependencies.dependency.groupid' for null:spring-test.jar
- Missing artifact but jars are in place
- org.springframework.security:spring-security-parent:jar:3.0.7.RELEASE:compile
- Could not resolve dependencies, artifacts could not be resolved



Wednesday, June 10, 2015

The type password is not accessible due to restriction on required library


The type password is not accessible due to restriction on required library

Problem :


We come across this common exception when i was using com.sun.* pacakge in our java code.

Exception I Encountered Was :


###################################################################################################################

the type password is not accessible due to restriction on required library

###################################################################################################################

Solution :


I was using com/sun/xml/internal.* package in my code. I had to update Access rules in eclipse to overcome this exception.
Please refer below to see how it was fixed.

It can be fixed in the follows two ways :


First method :

1) Go to Eclipse 2) Click on Project -> Properties 3) Select Java Build Path in left hand navigation 4) Select Libraries tab. 5) Then Expand JRE System Library entry and Select "Access rules" and hit the Edit button. 6) A new dialog windows opens 7) Click the add button and click ok. 8) Select Accessible in resolution and in Rule pattern add "com/sun/xml/internal/**". Second Method : 1) Go to Eclipse 2) Click on Project -> Properties 3) Select Java Build Path in left hand navigation 4) Select Libraries tab. 5) Select JRE System Library and click remove. 6) Click on Add Library and select JRE System Library 7) Select workspace default library or the one you want to select and click Finish. 8) For me the default worked. I hope this resolves your above exception / error, happy coding.


Similar Exception :

     

- the type password is not accessible due to restriction on required library
- Project won't compile when using com.sun.xml.internal.ws.server.UnsupportedMediaException
- How to overcome “package com.sun.xml.internal.xxx does not exist”


Wednesday, June 3, 2015

No naming context bound to this class loader


No naming context bound to this class loader

Problem :


We come across this common exception when i removed the project and re-imported it again in eclipse.

Exception I Encountered Was :


###################################################################################################################

No naming context bound to this class loader

###################################################################################################################

Solution :


I was using existing maven project in Eclipse. So i had to run a maven command to add the porject and then referesh the project to resolve it.
Please refer below to see how it was fixed.

Example :


- Follow these steps to resolve the exception :

1) Open DOS command prompt and navigate to your project folder where you have your pom.xml file. 2) Run the following command :
mvn eclipse:eclipse -Dwtpversion=2.0
3) Refresh the project in eclipse. 4) Now right click on server and select "add and remove" option, you should see your applicaion in the list to add. I hope this resolves your above exception / error, happy coding.


Similar Exception :

     

- No naming context bound to this class loader
- There are No resources that can be added or removed from the server
- How can I add my application to Tomcat in Eclipse?
- What needs to be done to add a project to a Server in Eclipse ?
- There are no projects that can be added or removed from the server