Dear All,
I have written the below JUNIT for my service IMPL and I am getting null pointer exception for below
clientIntegrationDataAPIServiceImpl.requestCommunityCreation(clientCommunity);
********************************** JUNIT Class ***************************
package ai.contentadmin.core.service;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import java.io.IOException;
import java.net.URISyntaxException;
import javax.jcr.RepositoryException;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.testing.mock.sling.ResourceResolverType;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import com.github.tomakehurst.wiremock.WireMockServer;
import ai.contentadmin.core.constants.Constants;
import ai.contentadmin.core.models.authorapi.ClientCommunity;
import io.wcm.testing.mock.aem.junit5.AemContext;
class ClientIntegrationDataAPIServiceImplTest {
private WireMockServer wireMockServer = new WireMockServer(wireMockConfig().dynamicPort());
@Rule
public final AemContext context = new AemContext(ResourceResolverType.JCR_MOCK);
@InjectMocks
ClientIntegrationDataAPIServiceImpl clientIntegrationDataAPIServiceImpl;
@test
void requestCommunityCreation() throws IOException, URISyntaxException, LoginException, RepositoryException {
wireMockServer.stubFor(post("/search".concat(String.format(Constants.COMMUNITIES)))
.willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")));
ClientCommunity clientCommunity = new ClientCommunity();
clientCommunity.setName("TestCommunity");
clientCommunity.setUserId("userid");
clientCommunity.setType("client");
clientCommunity.setPrivate(true);
String expected = Constants.STATUS_OK;
String actual = clientIntegrationDataAPIServiceImpl.requestCommunityCreation(clientCommunity);
Assert.assertEquals("Response should match", expected, actual);
wireMockServer.stop();
}
}
********************************** My Service Class ****************************
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
HI @subnaik ,
You need to register your core service class in test class.
@BeforeEach
public void setup() throws LoginException {
context.registerService(SampleService.class);
context.load().json("/sample.json", "/content");
}
Here I have mentioned sample service class, you can replace it with your actual service class.
Thanks
Tarun
HI @subnaik ,
You need to register your core service class in test class.
@BeforeEach
public void setup() throws LoginException {
context.registerService(SampleService.class);
context.load().json("/sample.json", "/content");
}
Here I have mentioned sample service class, you can replace it with your actual service class.
Thanks
Tarun
Views
Likes
Replies