Skip to content

Commit

Permalink
MAT-7060 removed unnecessary API key
Browse files Browse the repository at this point in the history
  • Loading branch information
adongare committed Aug 6, 2024
1 parent 1c6e2ec commit 32b97c6
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public ResponseEntity<String> deleteLibraryAlongWithVersions(
@PathVariable String libraryName,
@RequestHeader("Authorization") String accessToken,
@Value("${admin-api-key}") String apiKey) {
cqlLibraryService.deleteLibraryAlongWithVersions(libraryName, accessToken, apiKey);
cqlLibraryService.deleteLibraryAlongWithVersions(libraryName, accessToken);
return ResponseEntity.ok()
.body("The library and all its associated versions have been removed successfully.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ public List<LibraryUsage> findLibraryUsage(String libraryName) {
* @param apiKey
* @return true/false
*/
public boolean isLibraryBeinUsed(String name, String accessToken, String apiKey) {
public boolean isLibraryBeinUsed(String name, String accessToken) {
// check usage in libraries
List<LibraryUsage> usageInLibraries = findLibraryUsage(name);
if (CollectionUtils.isEmpty(usageInLibraries)) {
// check usage in measures
List<LibraryUsage> usageInMeasures =
measureServiceClient.getLibraryUsageInMeasures(name, accessToken, apiKey);
measureServiceClient.getLibraryUsageInMeasures(name, accessToken);
return CollectionUtils.isNotEmpty(usageInMeasures);
}
return true;
Expand All @@ -166,8 +166,8 @@ public boolean isLibraryBeinUsed(String name, String accessToken, String apiKey)
* @param name
* @param apiKey
*/
public void deleteLibraryAlongWithVersions(String name, String accessToken, String apiKey) {
if (isLibraryBeinUsed(name, accessToken, apiKey)) {
public void deleteLibraryAlongWithVersions(String name, String accessToken) {
if (isLibraryBeinUsed(name, accessToken)) {
throw new GeneralConflictException(
"Library is being used actively, hence can not be deleted.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public class MeasureServiceClient {
private EnvironmentConfig environmentConfig;
private RestTemplate restTemplate;

public List<LibraryUsage> getLibraryUsageInMeasures(
String libraryName, String accessToken, String apiKey) {
public List<LibraryUsage> getLibraryUsageInMeasures(String libraryName, String accessToken) {
try {
URI uri =
URI.create(
Expand All @@ -35,7 +34,6 @@ public List<LibraryUsage> getLibraryUsageInMeasures(
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
headers.set(HttpHeaders.AUTHORIZATION, accessToken);
headers.set("api-key", apiKey);
ResponseEntity<List<LibraryUsage>> responseEntity =
restTemplate.exchange(
new RequestEntity<>(headers, HttpMethod.GET, uri),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1575,9 +1575,7 @@ void testGetLibraryUsage() throws Exception {

@Test
void testDeleteLibraryAlongWithVersions() throws Exception {
doNothing()
.when(cqlLibraryService)
.deleteLibraryAlongWithVersions(anyString(), anyString(), anyString());
doNothing().when(cqlLibraryService).deleteLibraryAlongWithVersions(anyString(), anyString());
MvcResult result =
mockMvc
.perform(
Expand All @@ -1595,9 +1593,7 @@ void testDeleteLibraryAlongWithVersions() throws Exception {

@Test
void testDeleteLibraryAlongWithVersionsMissingAdminKey() throws Exception {
doNothing()
.when(cqlLibraryService)
.deleteLibraryAlongWithVersions(anyString(), anyString(), anyString());
doNothing().when(cqlLibraryService).deleteLibraryAlongWithVersions(anyString(), anyString());
MvcResult result =
mockMvc
.perform(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,7 @@ void testDeleteLibraryAlongWithVersions() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("api-key", "key");
String libraryName = "Helper";
doNothing()
.when(cqlLibraryService)
.deleteLibraryAlongWithVersions(anyString(), anyString(), anyString());
doNothing().when(cqlLibraryService).deleteLibraryAlongWithVersions(anyString(), anyString());
ResponseEntity<String> response =
cqlLibraryController.deleteLibraryAlongWithVersions(request, libraryName, "token", "key");
assertThat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ void testDeleteLibraryAlongWithVersionsSuccess() {
CqlLibrary cqlLibrary = CqlLibrary.builder().cqlLibraryName(libraryName).build();
when(cqlLibraryRepository.existsByCqlLibraryName(anyString())).thenReturn(true);
when(cqlLibraryRepository.findLibraryUsageByLibraryName(anyString())).thenReturn(List.of());
when(measureServiceClient.getLibraryUsageInMeasures(anyString(), anyString(), anyString()))
when(measureServiceClient.getLibraryUsageInMeasures(anyString(), anyString()))
.thenReturn(List.of());
when(cqlLibraryRepository.findAllByCqlLibraryName(anyString())).thenReturn(List.of(cqlLibrary));

cqlLibraryService.deleteLibraryAlongWithVersions(libraryName, "token", "key");
cqlLibraryService.deleteLibraryAlongWithVersions(libraryName, "token");
verify(cqlLibraryRepository, times(1)).deleteAll(List.of(cqlLibrary));
}

Expand All @@ -336,7 +336,7 @@ void testDeleteLibraryAlongWithVersionsIfUsedInLibrary() {
Exception ex =
assertThrows(
GeneralConflictException.class,
() -> cqlLibraryService.deleteLibraryAlongWithVersions(libraryName, "token", "key"));
() -> cqlLibraryService.deleteLibraryAlongWithVersions(libraryName, "token"));
assertThat(
ex.getMessage(), is(equalTo("Library is being used actively, hence can not be deleted.")));
}
Expand All @@ -348,12 +348,12 @@ void testDeleteLibraryAlongWithVersionsIfUsedInMeasure() {
LibraryUsage usage = LibraryUsage.builder().name(libraryName).owner(owner).build();
when(cqlLibraryRepository.existsByCqlLibraryName(anyString())).thenReturn(true);
when(cqlLibraryRepository.findLibraryUsageByLibraryName(anyString())).thenReturn(List.of());
when(measureServiceClient.getLibraryUsageInMeasures(anyString(), anyString(), anyString()))
when(measureServiceClient.getLibraryUsageInMeasures(anyString(), anyString()))
.thenReturn(List.of(usage));
Exception ex =
assertThrows(
GeneralConflictException.class,
() -> cqlLibraryService.deleteLibraryAlongWithVersions(libraryName, "token", "key"));
() -> cqlLibraryService.deleteLibraryAlongWithVersions(libraryName, "token"));
assertThat(
ex.getMessage(), is(equalTo("Library is being used actively, hence can not be deleted.")));
}
Expand All @@ -365,7 +365,7 @@ void testDeleteLibraryAlongWithVersionsIfOneNotExists() {
Exception ex =
assertThrows(
ResourceNotFoundException.class,
() -> cqlLibraryService.deleteLibraryAlongWithVersions(libraryName, "token", "key"));
() -> cqlLibraryService.deleteLibraryAlongWithVersions(libraryName, "token"));
assertThat(
ex.getMessage(), is(equalTo("Could not find resource Library with name: " + libraryName)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class MeasureServiceClientTest {
@InjectMocks private MeasureServiceClient measureServiceClient;

private final String token = "124";
private final String apiKey = "key";
private final String libraryName = "Test";

@Test
Expand All @@ -43,7 +42,7 @@ void testGetLibraryUsageInMeasures() {
when(restTemplate.exchange(any(RequestEntity.class), any(ParameterizedTypeReference.class)))
.thenReturn(ResponseEntity.ok(List.of(libraryUsage)));
List<LibraryUsage> libraryUsages =
measureServiceClient.getLibraryUsageInMeasures(libraryName, token, apiKey);
measureServiceClient.getLibraryUsageInMeasures(libraryName, token);
assertThat(libraryUsages.size(), is(equalTo(1)));
assertThat(libraryUsages.get(0).getName(), is(equalTo(libraryName)));
assertThat(libraryUsages.get(0).getOwner(), is(equalTo(owner)));
Expand All @@ -59,7 +58,7 @@ void testGetLibraryUsageInMeasuresThrowsException() {
Exception ex =
assertThrows(
MeasureServiceException.class,
() -> measureServiceClient.getLibraryUsageInMeasures(libraryName, token, apiKey));
() -> measureServiceClient.getLibraryUsageInMeasures(libraryName, token));
assertThat(ex.getMessage(), is(equalTo(message)));
}
}

0 comments on commit 32b97c6

Please sign in to comment.