Hi,
I am facing the problem with junit testing for sightly based components can you people please suggest how to write the test cases for below code which i mentioned?
public void activate() throws Exception {
LOGGER.info("Class : " + this.getClass().getName()
+ " : Method : activate() : [Start]");
bioDetailsBean = new BioDetailsBean();
String prsnInfoPath = getProperties().get(
BioDetailsConstants.PERSON_DETAILS, String.class);
Session session = getResourceResolver().adaptTo(Session.class);
try {
Node node = session.getNode(prsnInfoPath);
String description = getProperties().get(
BioDetailsConstants.JCR_DESCRIPTION, String.class);
String introText = getProperties().get(
BioDetailsConstants.JCR_INTROTEXT, String.class);
String firstName = node
.getProperty(BioDetailsConstants.JCR_FSTNAME).getValue()
.getString();
String image = node.getProperty(BioDetailsConstants.JCR_IMAGE)
.getValue().getString();
String recrtUniv = node
.getProperty(BioDetailsConstants.JCR_RECRTUNIV).getValue()
.getString();
String title = node.getProperty(BioDetailsConstants.JCR_TITLE)
.getValue().getString();
bioDetailsBean.setDescription(description);
bioDetailsBean.setFirstName(firstName);
bioDetailsBean.setImage(image);
bioDetailsBean.setIntroText(introText);
bioDetailsBean.setRecrtUniv(recrtUniv);
bioDetailsBean.setTitle(title);
} catch (PathNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RepositoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
LOGGER.info("Class : " + this.getClass().getName()
+ " : Method : activate() : [End]");
}
And i am getting the problem like how to call my controller methods in test class using mock objects
Ex: when(wcmuse_mock.getProperties()).thenReturn(V_MOCK); ?
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
just to make your question more specific: You do a unittest of the backing WCM-Use class, but not of the sightly component (the HTML output generated by sightly) itself. Is this correct?
If you want to unit-test your models, you should try to avoid the use of JCR session. Stay on the sling level. And you work only with the page or component properties, just mock the ValupMap containing the properties.
Kind regards,
Jörg
Views
Replies
Total Likes
Hi,
just to make your question more specific: You do a unittest of the backing WCM-Use class, but not of the sightly component (the HTML output generated by sightly) itself. Is this correct?
If you want to unit-test your models, you should try to avoid the use of JCR session. Stay on the sling level. And you work only with the page or component properties, just mock the ValupMap containing the properties.
Kind regards,
Jörg
Views
Replies
Total Likes
Looking at the code here, you are creating a model object based on resource-properties.
To me this is *the* use-case for using sling-models, and reducing the Java-classes you have here.
Overall I would try to avoid Node-class, and use the ValueMap this is much less error-prone.
Views
Replies
Total Likes
Please refer to link : http://www.citytechinc.com/us/en/blog/2010/02/making_a_mockeryof.html
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies