-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
control-service: fix graphql team filter not retrieveing special chars (
#863) why: users of control-service complained that graphQL API calls for a team with special characters such as '(' don't yeild results even though the team exists. what: investigating the issue concluded that the team filter strategy uses a regex method - String.matches("regex") string to match the teams and would get the results tripped by special chars. testing: added unit test. Signed-off-by: Momchil Zhivkov [email protected]
- Loading branch information
Momchil Z
authored
Jun 21, 2022
1 parent
04c3f2d
commit eb991a5
Showing
2 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...trol_service/src/test/java/com/vmware/taurus/service/graphql/GraphQLJobTeamFetcherIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright 2021 VMware, Inc. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.vmware.taurus.service.graphql; | ||
|
||
import com.vmware.taurus.ControlplaneApplication; | ||
import com.vmware.taurus.service.JobsRepository; | ||
import com.vmware.taurus.service.model.DataJob; | ||
import com.vmware.taurus.service.model.JobConfig; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
||
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = ControlplaneApplication.class) | ||
@AutoConfigureMockMvc(addFilters = false) | ||
public class GraphQLJobTeamFetcherIT { | ||
|
||
@Autowired | ||
JobsRepository jobsRepository; | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@AfterEach | ||
public void cleanup() { | ||
jobsRepository.deleteAll(); | ||
} | ||
|
||
private static String getJobsUri(String teamName) { | ||
return "/data-jobs/for-team/" + teamName + "/jobs"; | ||
} | ||
|
||
private static String getQuery(String jobTeam) { | ||
return "{\n" + | ||
" jobs(\n" + | ||
" pageNumber: 1\n" + | ||
" pageSize: 100\n" + | ||
" filter: [\n" + | ||
" { property: \"config.team\", pattern: \"" + jobTeam + "\", sort: ASC }\n" + | ||
" { property: \"jobName\", sort: ASC }\n" + | ||
" ]\n" + | ||
" ) {\n" + | ||
" content {\n" + | ||
" jobName\n" + | ||
" config {\n" + | ||
" team\n" + | ||
" description\n" + | ||
" schedule {\n" + | ||
" scheduleCron\n" + | ||
" }\n" + | ||
" }\n" + | ||
" deployments {\n" + | ||
" enabled\n" + | ||
" status\n" + | ||
" }\n" + | ||
" }\n" + | ||
" }\n" + | ||
"}"; | ||
} | ||
|
||
@Test | ||
public void testRetrieveJobNameWithParentheses() throws Exception { | ||
testJobApiRetrievalWithTeamName("VIDA (Eco-system)"); | ||
} | ||
|
||
@Test | ||
public void testRetrieveJobNameWithoutParentheses() throws Exception { | ||
testJobApiRetrievalWithTeamName("VIDA"); | ||
} | ||
|
||
/** | ||
* Re-usable test that creates a data job with a given | ||
* team name and attempts to retrieve it via the graphQL | ||
* API | ||
* | ||
* @param jobTeam - the team name. | ||
* @throws Exception | ||
*/ | ||
private void testJobApiRetrievalWithTeamName(String jobTeam) throws Exception { | ||
createJobWithTeam(jobTeam); | ||
mockMvc.perform(MockMvcRequestBuilders.get(getJobsUri(jobTeam)) | ||
.queryParam("query", getQuery(jobTeam)) | ||
.with(user("test"))) | ||
.andExpect(status().is(200)) | ||
.andExpect(jsonPath("$.data.content[0].jobName").value("test-job")) | ||
.andExpect(jsonPath("$.data.content[0].config.team").value(jobTeam)); | ||
} | ||
|
||
private void createJobWithTeam(String jobTeam) { | ||
DataJob dataJob = new DataJob(); | ||
JobConfig jobConfig = new JobConfig(); | ||
jobConfig.setTeam(jobTeam); | ||
dataJob.setName("test-job"); | ||
dataJob.setJobConfig(jobConfig); | ||
jobsRepository.save(dataJob); | ||
} | ||
} |