-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
APIM 7550 fix get archived applications info #10072
Open
mukul-tyagi08
wants to merge
2
commits into
4.2.x
Choose a base branch
from
APIM-7550-fix-get-archived-applications-info
base: 4.2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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
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
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
219 changes: 219 additions & 0 deletions
219
...est/java/io/gravitee/rest/api/service/impl/ApplicationService_FindByIdsAndStatusTest.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,219 @@ | ||
/* | ||
* Copyright © 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.rest.api.service.impl; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
import com.google.common.collect.Sets; | ||
import io.gravitee.common.data.domain.Page; | ||
import io.gravitee.repository.exceptions.TechnicalException; | ||
import io.gravitee.repository.management.api.ApplicationRepository; | ||
import io.gravitee.repository.management.api.search.ApplicationCriteria; | ||
import io.gravitee.repository.management.model.ApiKeyMode; | ||
import io.gravitee.repository.management.model.Application; | ||
import io.gravitee.repository.management.model.ApplicationStatus; | ||
import io.gravitee.rest.api.model.MembershipEntity; | ||
import io.gravitee.rest.api.model.RoleEntity; | ||
import io.gravitee.rest.api.model.application.ApplicationListItem; | ||
import io.gravitee.rest.api.model.permissions.RoleScope; | ||
import io.gravitee.rest.api.service.MembershipService; | ||
import io.gravitee.rest.api.service.RoleService; | ||
import io.gravitee.rest.api.service.UserService; | ||
import io.gravitee.rest.api.service.common.ExecutionContext; | ||
import io.gravitee.rest.api.service.common.GraviteeContext; | ||
import io.gravitee.rest.api.service.configuration.application.ClientRegistrationService; | ||
import io.gravitee.rest.api.service.exceptions.TechnicalManagementException; | ||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
/** | ||
* @author Guillaume CUSNIEUX (guillaume.cusnieux at graviteesource.com) | ||
* @author GraviteeSource Team | ||
*/ | ||
@RunWith(MockitoJUnitRunner.class) | ||
public class ApplicationService_FindByIdsAndStatusTest { | ||
|
||
private static final List<String> APPLICATION_IDS = Arrays.asList("id-app-1", "id-app-2"); | ||
|
||
@InjectMocks | ||
private ApplicationServiceImpl applicationService = new ApplicationServiceImpl(); | ||
|
||
@Mock | ||
private ApplicationRepository applicationRepository; | ||
|
||
@Mock | ||
private MembershipService membershipService; | ||
|
||
@Mock | ||
private UserService userService; | ||
|
||
@Mock | ||
private RoleService roleService; | ||
|
||
@Mock | ||
private RoleEntity primaryOwnerRole; | ||
|
||
@Mock | ||
private Set<MembershipEntity> primaryOwners; | ||
|
||
@Mock | ||
private Application app1; | ||
|
||
@Mock | ||
private Application app2; | ||
|
||
@Mock | ||
private ClientRegistrationService clientRegistrationService; | ||
|
||
@Before | ||
public void setUp() { | ||
GraviteeContext.setCurrentOrganization("DEFAULT"); | ||
GraviteeContext.setCurrentEnvironment("DEFAULT"); | ||
when(app1.getStatus()).thenReturn(ApplicationStatus.ACTIVE); | ||
when(app1.getId()).thenReturn(APPLICATION_IDS.get(0)); | ||
when(app1.getApiKeyMode()).thenReturn(ApiKeyMode.UNSPECIFIED); | ||
|
||
when(app2.getStatus()).thenReturn(ApplicationStatus.ACTIVE); | ||
when(app2.getId()).thenReturn(APPLICATION_IDS.get(1)); | ||
when(app2.getApiKeyMode()).thenReturn(ApiKeyMode.UNSPECIFIED); | ||
|
||
doReturn(primaryOwnerRole) | ||
.when(roleService) | ||
.findPrimaryOwnerRoleByOrganization(GraviteeContext.getCurrentOrganization(), RoleScope.APPLICATION); | ||
|
||
doReturn("role-id").when(primaryOwnerRole).getId(); | ||
|
||
when(membershipService.getMembershipsByReferencesAndRole(any(), any(), any())).thenReturn(primaryOwners); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
GraviteeContext.cleanContext(); | ||
} | ||
|
||
@Test | ||
public void shouldFindByIdsAndStatus() throws TechnicalException { | ||
ExecutionContext executionContext = GraviteeContext.getExecutionContext(); | ||
ApplicationCriteria criteria = new ApplicationCriteria.Builder() | ||
.ids(Sets.newHashSet(APPLICATION_IDS)) | ||
.status(ApplicationStatus.ACTIVE) | ||
.environmentIds(executionContext.getEnvironmentId()) | ||
.build(); | ||
doReturn(new Page(Arrays.asList(app1, app2), 1, 2, 2)).when(applicationRepository).search(criteria, null); | ||
doReturn(2).when(primaryOwners).size(); | ||
|
||
final Set<ApplicationListItem> applications = applicationService.findByIdsAndStatus( | ||
executionContext, | ||
APPLICATION_IDS, | ||
ApplicationStatus.ACTIVE | ||
); | ||
|
||
assertNotNull(applications); | ||
assertEquals(APPLICATION_IDS, applications.stream().map(ApplicationListItem::getId).collect(Collectors.toList())); | ||
} | ||
|
||
@Test | ||
public void shouldFindByIdsAndStatusWithDuplicatedIdsAndStatus() throws TechnicalException { | ||
ExecutionContext executionContext = GraviteeContext.getExecutionContext(); | ||
ApplicationCriteria criteria = new ApplicationCriteria.Builder() | ||
.ids(Sets.newHashSet(APPLICATION_IDS)) | ||
.status(ApplicationStatus.ACTIVE) | ||
.environmentIds(executionContext.getEnvironmentId()) | ||
.build(); | ||
|
||
doReturn(new Page<>(Arrays.asList(app1, app2), 1, 2, 2)).when(applicationRepository).search(criteria, null); | ||
doReturn(2).when(primaryOwners).size(); | ||
|
||
final Set<ApplicationListItem> applications = applicationService.findByIdsAndStatus( | ||
executionContext, | ||
List.of("id-app-1", "id-app-1", "id-app-2"), | ||
ApplicationStatus.ACTIVE | ||
); | ||
|
||
assertNotNull(applications); | ||
assertEquals(APPLICATION_IDS, applications.stream().map(ApplicationListItem::getId).collect(Collectors.toList())); | ||
} | ||
|
||
@Test | ||
public void shouldFindByIdsAndStatusWithNoEnvironmentCriteria() throws TechnicalException { | ||
ExecutionContext executionContext = new ExecutionContext("DEFAULT", null); | ||
ApplicationCriteria criteria = new ApplicationCriteria.Builder() | ||
.ids(Sets.newHashSet(APPLICATION_IDS)) | ||
.status(ApplicationStatus.ACTIVE) | ||
.build(); | ||
doReturn(new Page(Arrays.asList(app1, app2), 1, 2, 2)).when(applicationRepository).search(criteria, null); | ||
doReturn(2).when(primaryOwners).size(); | ||
|
||
final Set<ApplicationListItem> applications = applicationService.findByIdsAndStatus( | ||
executionContext, | ||
APPLICATION_IDS, | ||
ApplicationStatus.ACTIVE | ||
); | ||
|
||
assertNotNull(applications); | ||
assertEquals(APPLICATION_IDS, applications.stream().map(ApplicationListItem::getId).collect(Collectors.toList())); | ||
} | ||
|
||
@Test | ||
public void shouldFindByIdsAndStatusWithEmptySet() throws TechnicalException { | ||
ExecutionContext executionContext = GraviteeContext.getExecutionContext(); | ||
|
||
final Set<ApplicationListItem> applications = applicationService.findByIdsAndStatus( | ||
executionContext, | ||
Collections.emptySet(), | ||
ApplicationStatus.ACTIVE | ||
); | ||
|
||
assertNotNull(applications); | ||
assertTrue(applications.isEmpty()); | ||
verify(applicationRepository, times(0)).search(any(), any()); | ||
} | ||
|
||
@Test(expected = TechnicalManagementException.class) | ||
public void shouldThrowsIfNoPrimaryOwner() throws TechnicalException { | ||
ExecutionContext executionContext = GraviteeContext.getExecutionContext(); | ||
ApplicationCriteria criteria = new ApplicationCriteria.Builder() | ||
.ids(Sets.newHashSet(APPLICATION_IDS)) | ||
.status(ApplicationStatus.ACTIVE) | ||
.environmentIds(executionContext.getEnvironmentId()) | ||
.build(); | ||
doReturn(new Page(Arrays.asList(app1, app2), 1, 2, 2)).when(applicationRepository).search(criteria, null); | ||
|
||
final Set<ApplicationListItem> applications = applicationService.findByIdsAndStatus( | ||
GraviteeContext.getExecutionContext(), | ||
APPLICATION_IDS, | ||
ApplicationStatus.ACTIVE | ||
); | ||
|
||
assertNotNull(applications); | ||
assertEquals(APPLICATION_IDS, applications.stream().map(ApplicationListItem::getId).collect(Collectors.toList())); | ||
} | ||
|
||
@Test(expected = TechnicalManagementException.class) | ||
public void shouldThrowTechnicalManagementException() throws TechnicalException { | ||
when(applicationRepository.search(any(), any())).thenThrow(new TechnicalException()); | ||
applicationService.findByIdsAndStatus(GraviteeContext.getExecutionContext(), APPLICATION_IDS, ApplicationStatus.ACTIVE); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, the findByIds method implicitly searched applications by id and ApplicationStatus.ACTIVE by default. By replacing it with your implementation, you've altered the behaviour for all existing resources or services that currently rely on this method.
Could you please verify whether this method is still being called elsewhere? If so, ensure that the default behaviour hasn't been unintentionally modified. If the change impacts existing functionality, consider using your findByIdsAndStatus method explicitly to preserve the intended behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.