use of io.gravitee.repository.management.model.Environment in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentService_FindByUserAndIdOrHridTest method getEnvironments.
public Set<Environment> getEnvironments() {
Environment env1 = new Environment();
env1.setId("envId");
env1.setHrids(Arrays.asList("env1", "1env"));
Environment env2 = new Environment();
env2.setId("env2Id");
env2.setHrids(Arrays.asList("env2", "2env"));
HashSet<Environment> envSet = new HashSet<>();
envSet.add(env1);
envSet.add(env2);
return envSet;
}
use of io.gravitee.repository.management.model.Environment in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentServiceImpl method createOrUpdate.
@Override
public EnvironmentEntity createOrUpdate(String organizationId, String environmentId, final UpdateEnvironmentEntity environmentEntity) {
try {
// First we check that organization exists
this.organizationService.findById(organizationId);
Optional<Environment> environmentOptional = environmentRepository.findById(environmentId);
Environment environment = convert(environmentEntity);
environment.setId(environmentId);
environment.setOrganizationId(organizationId);
if (environmentOptional.isPresent()) {
return convert(environmentRepository.update(environment));
} else {
EnvironmentEntity createdEnvironment = convert(environmentRepository.create(environment));
// create Default items for environment
apiHeaderService.initialize(createdEnvironment.getId());
pageService.initialize(createdEnvironment.getId());
return createdEnvironment;
}
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to update environment {}", environmentEntity.getName(), ex);
throw new TechnicalManagementException("An error occurs while trying to update environment " + environmentEntity.getName(), ex);
}
}
use of io.gravitee.repository.management.model.Environment in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentServiceImpl method initialize.
@Override
public void initialize() {
Environment defaultEnvironment = new Environment();
defaultEnvironment.setId(GraviteeContext.getDefaultEnvironment());
defaultEnvironment.setName("Default environment");
defaultEnvironment.setDescription("Default environment");
defaultEnvironment.setOrganizationId(GraviteeContext.getDefaultOrganization());
try {
environmentRepository.create(defaultEnvironment);
} catch (TechnicalException ex) {
LOGGER.error("An error occurs while trying to create default environment", ex);
throw new TechnicalManagementException("An error occurs while trying to create default environment", ex);
}
}
use of io.gravitee.repository.management.model.Environment in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentService_CreateTest method shouldCreateEnvironment.
@Test
public void shouldCreateEnvironment() throws TechnicalException {
when(mockOrganizationService.findById(any())).thenReturn(null);
when(mockEnvironmentRepository.findById(any())).thenReturn(Optional.empty());
UpdateEnvironmentEntity env1 = new UpdateEnvironmentEntity();
env1.setHrids(Arrays.asList("envhrid"));
env1.setName("env_name");
env1.setDescription("env_desc");
List<String> domainRestrictions = Arrays.asList("domain", "restriction");
env1.setDomainRestrictions(domainRestrictions);
Environment createdEnv = new Environment();
createdEnv.setId("env_id");
when(mockEnvironmentRepository.create(any())).thenReturn(createdEnv);
EnvironmentEntity environment = environmentService.createOrUpdate("DEFAULT", "env_id", env1);
assertNotNull("result is null", environment);
verify(mockEnvironmentRepository, times(1)).create(argThat(arg -> arg != null && arg.getHrids().equals(Arrays.asList("envhrid")) && arg.getName().equals("env_name") && arg.getDescription().equals("env_desc") && arg.getDomainRestrictions().equals(domainRestrictions) && arg.getOrganizationId().equals("DEFAULT")));
verify(mockEnvironmentRepository, never()).update(any());
verify(mockAPIHeaderService, times(1)).initialize("env_id");
verify(mockPageService, times(1)).initialize("env_id");
}
use of io.gravitee.repository.management.model.Environment in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentService_CreateTest method shouldUpdateEnvironment.
@Test
public void shouldUpdateEnvironment() throws TechnicalException {
when(mockOrganizationService.findById(any())).thenReturn(null);
when(mockEnvironmentRepository.findById(any())).thenReturn(Optional.of(new Environment()));
UpdateEnvironmentEntity env1 = new UpdateEnvironmentEntity();
env1.setHrids(Arrays.asList("envhrid"));
env1.setName("env_name");
env1.setDescription("env_desc");
List<String> domainRestrictions = Arrays.asList("domain", "restriction");
env1.setDomainRestrictions(domainRestrictions);
Environment updatedEnv = new Environment();
when(mockEnvironmentRepository.update(any())).thenReturn(updatedEnv);
EnvironmentEntity environment = environmentService.createOrUpdate("DEFAULT", "env_id", env1);
assertNotNull("result is null", environment);
verify(mockEnvironmentRepository, times(1)).update(argThat(arg -> arg != null && arg.getHrids().equals(Arrays.asList("envhrid")) && arg.getName().equals("env_name") && arg.getDescription().equals("env_desc") && arg.getDomainRestrictions().equals(domainRestrictions) && arg.getOrganizationId().equals("DEFAULT")));
verify(mockEnvironmentRepository, never()).create(any());
verify(mockAPIHeaderService, never()).initialize("env_id");
verify(mockPageService, never()).initialize("env_id");
}
Aggregations