use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertServiceTest method shouldCreateResponseTimeAlert.
@Test
public void shouldCreateResponseTimeAlert() {
NewAlertTriggerEntity newAlert = new NewAlertTriggerEntity();
newAlert.setId(ALERT_ID);
newAlert.setType("METRICS_AGGREGATION");
ApplicationEntity application = getApplication();
prepareForCreation(newAlert);
when(applicationService.findById(APPLICATION_ID)).thenReturn(application);
cut.create(APPLICATION_ID, newAlert);
verify(alertService, times(1)).create(newAlert);
verify(notificationTemplateService, times(1)).findByHookAndScope(AlertHook.CONSUMER_RESPONSE_TIME.name(), HookScope.TEMPLATES_FOR_ALERT.name());
}
use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_CreateTest method shouldCreateForUser.
@Test
public void shouldCreateForUser() throws TechnicalException {
ApplicationSettings settings = new ApplicationSettings();
SimpleApplicationSettings clientSettings = new SimpleApplicationSettings();
clientSettings.setClientId(CLIENT_ID);
settings.setApp(clientSettings);
when(newApplication.getSettings()).thenReturn(settings);
when(application.getName()).thenReturn(APPLICATION_NAME);
when(application.getType()).thenReturn(ApplicationType.SIMPLE);
when(application.getStatus()).thenReturn(ApplicationStatus.ACTIVE);
when(applicationRepository.create(any())).thenReturn(application);
when(newApplication.getName()).thenReturn(APPLICATION_NAME);
when(newApplication.getDescription()).thenReturn("My description");
when(groupService.findByEvent(any())).thenReturn(Collections.emptySet());
when(userService.findById(any())).thenReturn(mock(UserEntity.class));
final ApplicationEntity applicationEntity = applicationService.create(newApplication, USER_NAME);
assertNotNull(applicationEntity);
assertEquals(APPLICATION_NAME, applicationEntity.getName());
}
use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_UpdateTest method shouldUpdateBecauseSameApplication.
@Test
public void shouldUpdateBecauseSameApplication() throws TechnicalException {
when(applicationRepository.findById(APPLICATION_ID)).thenReturn(Optional.of(application));
when(application.getId()).thenReturn(APPLICATION_ID);
Map<String, String> metadata = new HashMap<>();
metadata.put("client_id", CLIENT_ID);
when(application.getMetadata()).thenReturn(metadata);
ApplicationSettings settings = new ApplicationSettings();
SimpleApplicationSettings clientSettings = new SimpleApplicationSettings();
clientSettings.setClientId(CLIENT_ID);
settings.setApp(clientSettings);
when(existingApplication.getSettings()).thenReturn(settings);
when(application.getName()).thenReturn(APPLICATION_NAME);
when(application.getStatus()).thenReturn(ApplicationStatus.ACTIVE);
when(application.getType()).thenReturn(ApplicationType.SIMPLE);
when(existingApplication.getName()).thenReturn(APPLICATION_NAME);
when(existingApplication.getDescription()).thenReturn("My description");
when(applicationRepository.update(any())).thenReturn(application);
when(roleService.findPrimaryOwnerRoleByOrganization(any(), any())).thenReturn(mock(RoleEntity.class));
MembershipEntity po = new MembershipEntity();
po.setMemberId(USER_NAME);
po.setMemberType(MembershipMemberType.USER);
po.setReferenceId(APPLICATION_ID);
po.setReferenceType(MembershipReferenceType.APPLICATION);
po.setRoleId("APPLICATION_PRIMARY_OWNER");
when(membershipService.getMembershipsByReferencesAndRole(any(), any(), any())).thenReturn(Collections.singleton(po));
final ApplicationEntity applicationEntity = applicationService.update(APPLICATION_ID, existingApplication);
verify(applicationRepository).update(argThat(application -> APPLICATION_NAME.equals(application.getName()) && application.getUpdatedAt() != null));
assertNotNull(applicationEntity);
assertEquals(APPLICATION_NAME, applicationEntity.getName());
}
Aggregations