use of io.gravitee.am.service.model.NewEnvironment in project gravitee-access-management by gravitee-io.
the class EnvironmentServiceTest method shouldCreate_update.
@Test
public void shouldCreate_update() {
Environment existingEnvironment = new Environment();
existingEnvironment.setId(ENVIRONMENT_ID);
existingEnvironment.setOrganizationId(ORGANIZATION_ID);
when(environmentRepository.findById(ENVIRONMENT_ID, ORGANIZATION_ID)).thenReturn(Maybe.just(existingEnvironment));
when(environmentRepository.update(argThat(environment -> environment.getId().equals(ENVIRONMENT_ID)))).thenAnswer(i -> Single.just(i.getArgument(0)));
NewEnvironment newEnvironment = new NewEnvironment();
newEnvironment.setName("TestName");
newEnvironment.setDescription("TestDescription");
newEnvironment.setDomainRestrictions(Collections.singletonList("TestDomainRestriction"));
newEnvironment.setHrids(Collections.singletonList("testHRIDUpdated"));
DefaultUser createdBy = new DefaultUser("test");
createdBy.setId(USER_ID);
TestObserver<Environment> obs = cut.createOrUpdate(ORGANIZATION_ID, ENVIRONMENT_ID, newEnvironment, createdBy).test();
obs.awaitTerminalEvent();
obs.assertValue(environment -> {
assertEquals(ENVIRONMENT_ID, environment.getId());
assertEquals(newEnvironment.getName(), environment.getName());
assertEquals(newEnvironment.getDescription(), environment.getDescription());
assertEquals(newEnvironment.getDomainRestrictions(), environment.getDomainRestrictions());
assertEquals(newEnvironment.getHrids(), environment.getHrids());
return true;
});
verify(auditService, times(1)).report(argThat(builder -> {
Audit audit = builder.build(new ObjectMapper());
assertEquals(ReferenceType.ORGANIZATION, audit.getReferenceType());
assertEquals(ORGANIZATION_ID, audit.getReferenceId());
assertEquals(createdBy.getId(), audit.getActor().getId());
assertEquals(EventType.ENVIRONMENT_UPDATED, audit.getType());
assertEquals(Status.SUCCESS, audit.getOutcome().getStatus());
return true;
}));
}
use of io.gravitee.am.service.model.NewEnvironment in project gravitee-access-management by gravitee-io.
the class EnvironmentServiceTest method shouldCreate_organizationNotFound.
@Test
public void shouldCreate_organizationNotFound() {
when(environmentRepository.findById(ENVIRONMENT_ID, ORGANIZATION_ID)).thenReturn(Maybe.empty());
when(organizationService.findById(ORGANIZATION_ID)).thenReturn(Single.error(new OrganizationNotFoundException(ORGANIZATION_ID)));
NewEnvironment newEnvironment = new NewEnvironment();
newEnvironment.setName("TestName");
newEnvironment.setDescription("TestDescription");
newEnvironment.setDomainRestrictions(Collections.singletonList("TestDomainRestriction"));
DefaultUser createdBy = new DefaultUser("test");
createdBy.setId(USER_ID);
TestObserver<Environment> obs = cut.createOrUpdate(ORGANIZATION_ID, ENVIRONMENT_ID, newEnvironment, createdBy).test();
obs.awaitTerminalEvent();
obs.assertError(OrganizationNotFoundException.class);
verifyZeroInteractions(auditService);
}
use of io.gravitee.am.service.model.NewEnvironment in project gravitee-access-management by gravitee-io.
the class EnvironmentServiceTest method shouldCreate_error.
@Test
public void shouldCreate_error() {
Organization organization = new Organization();
organization.setId(ORGANIZATION_ID);
when(environmentRepository.findById(ENVIRONMENT_ID, ORGANIZATION_ID)).thenReturn(Maybe.empty());
when(organizationService.findById(ORGANIZATION_ID)).thenReturn(Single.just(organization));
when(environmentRepository.create(argThat(environment -> environment.getId().equals(ENVIRONMENT_ID)))).thenReturn(Single.error(new TechnicalManagementException()));
NewEnvironment newEnvironment = new NewEnvironment();
newEnvironment.setName("TestName");
newEnvironment.setDescription("TestDescription");
newEnvironment.setDomainRestrictions(Collections.singletonList("TestDomainRestriction"));
DefaultUser createdBy = new DefaultUser("test");
createdBy.setId(USER_ID);
TestObserver<Environment> obs = cut.createOrUpdate(ORGANIZATION_ID, ENVIRONMENT_ID, newEnvironment, createdBy).test();
obs.awaitTerminalEvent();
obs.assertError(TechnicalManagementException.class);
verify(auditService, times(1)).report(argThat(builder -> {
Audit audit = builder.build(new ObjectMapper());
assertEquals(ReferenceType.ORGANIZATION, audit.getReferenceType());
assertEquals(ORGANIZATION_ID, audit.getReferenceId());
assertEquals(createdBy.getId(), audit.getActor().getId());
assertEquals(EventType.ENVIRONMENT_CREATED, audit.getType());
assertEquals(Status.FAILURE, audit.getOutcome().getStatus());
return true;
}));
}
use of io.gravitee.am.service.model.NewEnvironment in project gravitee-access-management by gravitee-io.
the class EnvironmentServiceTest method shouldCreate_updateError.
@Test
public void shouldCreate_updateError() {
Environment existingEnvironment = new Environment();
existingEnvironment.setId(ENVIRONMENT_ID);
existingEnvironment.setOrganizationId(ORGANIZATION_ID);
when(environmentRepository.findById(ENVIRONMENT_ID, ORGANIZATION_ID)).thenReturn(Maybe.just(existingEnvironment));
when(environmentRepository.update(argThat(environment -> environment.getId().equals(ENVIRONMENT_ID)))).thenReturn(Single.error(new TechnicalManagementException()));
NewEnvironment newEnvironment = new NewEnvironment();
newEnvironment.setName("TestName");
newEnvironment.setDescription("TestDescription");
newEnvironment.setDomainRestrictions(Collections.singletonList("TestDomainRestriction"));
DefaultUser createdBy = new DefaultUser("test");
createdBy.setId(USER_ID);
TestObserver<Environment> obs = cut.createOrUpdate(ORGANIZATION_ID, ENVIRONMENT_ID, newEnvironment, createdBy).test();
obs.awaitTerminalEvent();
obs.assertError(TechnicalManagementException.class);
verify(auditService, times(1)).report(argThat(builder -> {
Audit audit = builder.build(new ObjectMapper());
assertEquals(ReferenceType.ORGANIZATION, audit.getReferenceType());
assertEquals(ORGANIZATION_ID, audit.getReferenceId());
assertEquals(createdBy.getId(), audit.getActor().getId());
assertEquals(EventType.ENVIRONMENT_UPDATED, audit.getType());
assertEquals(Status.FAILURE, audit.getOutcome().getStatus());
return true;
}));
}
use of io.gravitee.am.service.model.NewEnvironment in project gravitee-access-management by gravitee-io.
the class EnvironmentServiceTest method shouldCreate.
@Test
public void shouldCreate() {
Organization organization = new Organization();
organization.setId(ORGANIZATION_ID);
when(environmentRepository.findById(ENVIRONMENT_ID, ORGANIZATION_ID)).thenReturn(Maybe.empty());
when(organizationService.findById(ORGANIZATION_ID)).thenReturn(Single.just(organization));
when(environmentRepository.create(argThat(environment -> environment.getId().equals(ENVIRONMENT_ID)))).thenAnswer(i -> Single.just(i.getArgument(0)));
NewEnvironment newEnvironment = new NewEnvironment();
newEnvironment.setName("TestName");
newEnvironment.setDescription("TestDescription");
newEnvironment.setDomainRestrictions(Collections.singletonList("TestDomainRestriction"));
newEnvironment.setHrids(Collections.singletonList("testEnvHRID"));
DefaultUser createdBy = new DefaultUser("test");
createdBy.setId(USER_ID);
TestObserver<Environment> obs = cut.createOrUpdate(ORGANIZATION_ID, ENVIRONMENT_ID, newEnvironment, createdBy).test();
obs.awaitTerminalEvent();
obs.assertValue(environment -> {
assertEquals(ORGANIZATION_ID, environment.getOrganizationId());
assertEquals(newEnvironment.getName(), environment.getName());
assertEquals(newEnvironment.getDescription(), environment.getDescription());
assertEquals(newEnvironment.getDomainRestrictions(), environment.getDomainRestrictions());
assertEquals(newEnvironment.getHrids(), environment.getHrids());
return true;
});
verify(auditService, times(1)).report(argThat(builder -> {
Audit audit = builder.build(new ObjectMapper());
assertEquals(ReferenceType.ORGANIZATION, audit.getReferenceType());
assertEquals(ORGANIZATION_ID, audit.getReferenceId());
assertEquals(createdBy.getId(), audit.getActor().getId());
assertEquals(EventType.ENVIRONMENT_CREATED, audit.getType());
assertEquals(Status.SUCCESS, audit.getOutcome().getStatus());
return true;
}));
}
Aggregations