Highlighted

Test Cases for sling model class

sharsha5545

21-06-2019

Hi team,

I have requirement to write test cases for sling model class. I have never written any test cases. I have gone through online but there is no enough information. I am posting my sample sling model class. Can anyone help me know the procedure to write test cases.

FYI those are Page properties

public class AMPSyndicationValues {

  private Logger LOG = LoggerFactory.getLogger(AMPSyndicationValues.class);

  @Inject

  @Optional

  @Source("sling-object")

  SlingHttpServletRequest request;

  @Inject

  @Optional

  @Via("resource")

  String appleNews;

  @Inject

  @Optional

  @Via("resource")

  String googleAmp;

  @Inject

  @Optional

  @Via("resource")

  String googleAmpUrl;

  private String reqPath;

  private String ampUrl;

  @PostConstruct

  public void init() {

  Resource resource = request.getResource();

  if (null != resource) {

  reqPath = resource.getPath();

  reqPath = reqPath.replaceAll("/content/....../e[n|s]/home/", "");

  reqPath = reqPath.replaceAll("/content/..../e[n|s]/home/", "");

  reqPath = reqPath.replaceAll("/jcr:content", ".html");

  ampUrl = (googleAmpUrl == null) ? "https://feeds.test.org/" + reqPath + "?_amp=true" : googleAmpUrl;

  }

  }

  public String getAmpUrl() {

  return ampUrl;

  }

  public String getGoogleAmp() {

  return googleAmp;

  }

}

Replies