Junit Test Case for Custom Rest Endpoint

cancel
Showing results for 
Search instead for 
Did you mean: 
sanjaybandhniya
Intermediate

Junit Test Case for Custom Rest Endpoint

Jump to solution

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 Solutions

Accepted Solutions
openpj
Moderator
Moderator

Re: Junit Test Case for Custom Rest Endpoint

Jump to solution

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 solution in original post

sanjaybandhniya
Intermediate

Re: Junit Test Case for Custom Rest Endpoint

Jump to solution

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 solution in original post

2 Replies
openpj
Moderator
Moderator

Re: Junit Test Case for Custom Rest Endpoint

Jump to solution

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

sanjaybandhniya
Intermediate

Re: Junit Test Case for Custom Rest Endpoint

Jump to solution

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.