Search in sources :

Example 11 with Environment

use of io.gravitee.am.model.Environment in project gravitee-access-management by gravitee-io.

the class EnvironmentRepositoryTest method testUpdate.

@Test
public void testUpdate() {
    Environment env = buildEnv();
    Environment envCreated = environmentRepository.create(env).blockingGet();
    Environment envUpdated = new Environment();
    envUpdated.setId(envCreated.getId());
    envUpdated.setOrganizationId(env.getOrganizationId());
    envUpdated.setName("testNameUpdated");
    envUpdated.setDomainRestrictions(Arrays.asList("ValueDom2", "ValueDom3", "ValueDom4"));
    envUpdated.setHrids(Arrays.asList("Hrid2", "Hrid3", "Hrid4"));
    TestObserver<Environment> obs = environmentRepository.update(envUpdated).test();
    obs.awaitTerminalEvent();
    obs.assertComplete();
    obs.assertNoErrors();
    obs.assertValue(e -> e.getName().equals(envUpdated.getName()) && e.getId().equals(envCreated.getId()));
    obs.assertValue(e -> e.getDomainRestrictions().containsAll(envUpdated.getDomainRestrictions()));
    obs.assertValue(e -> e.getHrids().containsAll(envUpdated.getHrids()));
}
Also used : Environment(io.gravitee.am.model.Environment) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 12 with Environment

use of io.gravitee.am.model.Environment in project gravitee-access-management by gravitee-io.

the class EnvironmentRepositoryTest method testDelete.

@Test
public void testDelete() {
    Environment env = new Environment();
    env.setName("testName");
    env.setOrganizationId(UUID.randomUUID().toString());
    env.setDescription("testDescription");
    env.setCreatedAt(new Date());
    env.setUpdatedAt(env.getUpdatedAt());
    env.setDomainRestrictions(Arrays.asList("ValueDom1", "ValueDom2"));
    env.setHrids(Arrays.asList("Hrid1", "Hrid2"));
    Environment envCreated = environmentRepository.create(env).blockingGet();
    assertNotNull(environmentRepository.findById(envCreated.getId()).blockingGet());
    TestObserver<Void> obs = environmentRepository.delete(envCreated.getId()).test();
    obs.awaitTerminalEvent();
    obs.assertNoValues();
    assertNull(environmentRepository.findById(envCreated.getId()).blockingGet());
}
Also used : Environment(io.gravitee.am.model.Environment) Date(java.util.Date) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 13 with Environment

use of io.gravitee.am.model.Environment in project gravitee-access-management by gravitee-io.

the class EnvironmentRepositoryTest method testCreate.

@Test
public void testCreate() {
    Environment env = buildEnv();
    env.setOrganizationId(UUID.randomUUID().toString());
    env.setName("testName");
    TestObserver<Environment> obs = environmentRepository.create(env).test();
    obs.awaitTerminalEvent();
    obs.assertComplete();
    obs.assertNoErrors();
    obs.assertValue(e -> e.getName().equals(env.getName()) && e.getId() != null);
    obs.assertValue(e -> e.getOrganizationId().equals(env.getOrganizationId()) && e.getId() != null);
    obs.assertValue(e -> e.getName().equals(env.getName()));
    obs.assertValue(e -> e.getDescription().equals(env.getDescription()));
    obs.assertValue(e -> e.getOrganizationId().equals(env.getOrganizationId()));
    obs.assertValue(e -> e.getDomainRestrictions().containsAll(env.getDomainRestrictions()));
    obs.assertValue(e -> e.getHrids().containsAll(env.getHrids()));
}
Also used : Environment(io.gravitee.am.model.Environment) Test(org.junit.Test) AbstractManagementTest(io.gravitee.am.repository.management.AbstractManagementTest)

Example 14 with Environment

use of io.gravitee.am.model.Environment in project gravitee-access-management by gravitee-io.

the class DomainNotificationServiceTest method prepareTest.

@Before
public void prepareTest() {
    ReflectionTestUtils.setField(cut, "emailNotifierEnabled", true);
    env = new Environment();
    env.setId(ENV_ID);
    env.setOrganizationId(ORGANIZATION_ID);
    domain = new Domain();
    domain.setId(DOMAIN_ID);
    domain.setReferenceId(ENV_ID);
    domain.setReferenceType(ReferenceType.ENVIRONMENT);
    certificate = new Certificate();
    certificate.setDomain(domain.getId());
    when(domainService.findById(certificate.getDomain())).thenReturn(Maybe.just(domain));
    when(environmentService.findById(domain.getReferenceId())).thenReturn(Single.just(env));
    final Role role = new Role();
    role.setId("role#1");
    when(roleService.findSystemRole(SystemRole.DOMAIN_PRIMARY_OWNER, ReferenceType.DOMAIN)).thenReturn(Maybe.just(role));
    final Role role2 = new Role();
    role2.setId("role#2");
    when(roleService.findDefaultRole(ORGANIZATION_ID, DefaultRole.DOMAIN_OWNER, ReferenceType.DOMAIN)).thenReturn(Maybe.just(role2));
}
Also used : SystemRole(io.gravitee.am.model.permissions.SystemRole) Role(io.gravitee.am.model.Role) DefaultRole(io.gravitee.am.model.permissions.DefaultRole) Environment(io.gravitee.am.model.Environment) Domain(io.gravitee.am.model.Domain) Certificate(io.gravitee.am.model.Certificate) Before(org.junit.Before)

Example 15 with Environment

use of io.gravitee.am.model.Environment in project gravitee-access-management by gravitee-io.

the class EnvironmentServiceTest method shouldFindByIdAndOrgId.

@Test
public void shouldFindByIdAndOrgId() {
    Environment environment = new Environment();
    when(environmentRepository.findById(ENVIRONMENT_ID, ORGANIZATION_ID)).thenReturn(Maybe.just(environment));
    TestObserver<Environment> obs = cut.findById(ENVIRONMENT_ID, ORGANIZATION_ID).test();
    obs.awaitTerminalEvent();
    obs.assertComplete();
    obs.assertValue(environment);
}
Also used : Environment(io.gravitee.am.model.Environment) NewEnvironment(io.gravitee.am.service.model.NewEnvironment) Test(org.junit.Test)

Aggregations

Environment (io.gravitee.am.model.Environment)24 Test (org.junit.Test)16 NewEnvironment (io.gravitee.am.service.model.NewEnvironment)13 Single (io.reactivex.Single)8 Collections (java.util.Collections)8 EventType (io.gravitee.am.common.audit.EventType)7 DefaultUser (io.gravitee.am.identityprovider.api.DefaultUser)7 Organization (io.gravitee.am.model.Organization)7 EnvironmentRepository (io.gravitee.am.repository.management.api.EnvironmentRepository)7 EnvironmentNotFoundException (io.gravitee.am.service.exception.EnvironmentNotFoundException)7 Flowable (io.reactivex.Flowable)7 Maybe (io.reactivex.Maybe)7 Before (org.junit.Before)7 ReferenceType (io.gravitee.am.model.ReferenceType)6 TechnicalException (io.gravitee.am.repository.exceptions.TechnicalException)6 OrganizationNotFoundException (io.gravitee.am.service.exception.OrganizationNotFoundException)6 TestObserver (io.reactivex.observers.TestObserver)6 Assert.assertEquals (org.junit.Assert.assertEquals)6 RunWith (org.junit.runner.RunWith)6 Mock (org.mockito.Mock)6