cancel
Showing results for 
Search instead for 
Did you mean: 

Junit Test Case for Custom Rest Endpoint

sanjaybandhaniya
Elite Collaborator
Elite Collaborator

Hi,

I am following APS Junit  for testing aps custom logic.

I have JavaDelegate and for that I am able to create jUnit Test case and it is working.

I have custom endpoint which is calling third party api to fetch data, for that How Can I craete Test case?

Any help would be appreciated.

2 ACCEPTED ANSWERS

openpj
Elite Collaborator
Elite Collaborator

You can take a look at the Integration Test example provided by my APS SDK:

https://github.com/OpenPj/alfresco-process-services-project-sdk/blob/master/aps-extensions-jar/src/t...

You will find something like the following:

@Test
	public void testCustomPrivateRestEndpoint() throws Exception {
		String url = getEnterpriseApiURL("my-api-endpoint");

		// append query string parameters here

		executeGETRequest(url, adminUserForPrivateApi, HttpStatus.OK);
	}

	@Test
	public void testCustomPublicRestEndpoint() throws Exception {
		String url = getPrivateApiURL("my-rest-endpoint");

		// append query string parameters here

		executeGETRequest(url, adminUserForPrivateApi, HttpStatus.OK);
	}

Hope this helps Smiley Happy

View answer in original post

Hi,Your solution is working.

But the problem is that My Test case is executing when I start my sdk(docker base) and it is trying call that api and failing because aps is not still start.

I have solved above issue by excluding that test case from starting aps.

View answer in original post

2 REPLIES 2

openpj
Elite Collaborator
Elite Collaborator

You can take a look at the Integration Test example provided by my APS SDK:

https://github.com/OpenPj/alfresco-process-services-project-sdk/blob/master/aps-extensions-jar/src/t...

You will find something like the following:

@Test
	public void testCustomPrivateRestEndpoint() throws Exception {
		String url = getEnterpriseApiURL("my-api-endpoint");

		// append query string parameters here

		executeGETRequest(url, adminUserForPrivateApi, HttpStatus.OK);
	}

	@Test
	public void testCustomPublicRestEndpoint() throws Exception {
		String url = getPrivateApiURL("my-rest-endpoint");

		// append query string parameters here

		executeGETRequest(url, adminUserForPrivateApi, HttpStatus.OK);
	}

Hope this helps Smiley Happy

Hi,Your solution is working.

But the problem is that My Test case is executing when I start my sdk(docker base) and it is trying call that api and failing because aps is not still start.

I have solved above issue by excluding that test case from starting aps.