contentFragment Element getValue unit test unsupported operation | Community
Skip to main content
sreenu539
Level 7
July 13, 2023
Solved

contentFragment Element getValue unit test unsupported operation

  • July 13, 2023
  • 4 replies
  • 1172 views

Hi,

 

any example to unit test 

 

contentElement.getValue().getValue(String[].class);

 

I am getting io.wcm unsupported operation exception, when trying to unit test this specific line of code. 

 

Thanks,

Sri

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by BrianKasingli

Yeah I got this problem too, I fixed it by refactoring the code, and broke it up.

 

 

String[] cfNamesArray = contentFragment.map(cf -> cf.getElement("names")).map(ContentElement::getContent) .filter(StringUtils::isNotEmpty) .map(names -> names.split(",")) .orElse(null);

 

 

4 replies

DPrakashRaj
Community Advisor
Community Advisor
July 13, 2023
BrianKasingli
Community Advisor and Adobe Champion
BrianKasingliCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
July 14, 2023

Yeah I got this problem too, I fixed it by refactoring the code, and broke it up.

 

 

String[] cfNamesArray = contentFragment.map(cf -> cf.getElement("names")).map(ContentElement::getContent) .filter(StringUtils::isNotEmpty) .map(names -> names.split(",")) .orElse(null);

 

 

Tanika02
July 14, 2023

Hello @sreenu539 - 

 

I see the same has been reported here https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/java-lang-unsupportedoperationexception-in-junit-test-content/m-p/546188 

 

Looks like these methods are not supported yet with the wcm.io mocking library & I see the issue is listed here https://github.com/wcm-io/io.wcm.testing.aem-mock/issues/15 still in progress.