use of io.gravitee.repository.management.model.Parameter in project gravitee-management-rest-api by gravitee-io.
the class ParameterServiceImpl method create.
@Override
public Parameter create(final String key, final String value) {
try {
final Optional<Parameter> optionalParameter = parameterRepository.findById(key);
if (optionalParameter.isPresent()) {
throw new ParameterAlreadyExistsException(key);
}
final Parameter parameter = new Parameter();
parameter.setKey(key);
parameter.setValue(value);
final Parameter savedParameter = parameterRepository.create(parameter);
auditService.createPortalAuditLog(singletonMap(PARAMETER, savedParameter.getKey()), PARAMETER_CREATED, new Date(), null, savedParameter);
return savedParameter;
} catch (final TechnicalException ex) {
final String message = "An error occurs while trying to create parameter for key/value: " + key + '/' + value;
LOGGER.error(message, ex);
throw new TechnicalManagementException(message, ex);
}
}
use of io.gravitee.repository.management.model.Parameter in project gravitee-management-rest-api by gravitee-io.
the class ParameterServiceTest method shouldCreateMultipleValueWithExistingParameter.
@Test
public void shouldCreateMultipleValueWithExistingParameter() throws TechnicalException {
final Parameter parameter = new Parameter();
parameter.setKey(PARAMETER_KEY);
parameter.setValue("api1");
final Parameter newParameter = new Parameter();
newParameter.setKey(PARAMETER_KEY);
newParameter.setValue("api1;api1");
when(parameterRepository.findById(PARAMETER_KEY)).thenReturn(of(parameter));
when(parameterRepository.update(newParameter)).thenReturn(newParameter);
parameterService.createMultipleValue(PARAMETER_KEY, "api1");
verify(parameterRepository).update(newParameter);
verify(auditService).createPortalAuditLog(eq(singletonMap(PARAMETER, PARAMETER_KEY)), eq(PARAMETER_UPDATED), any(), eq(parameter), eq(newParameter));
}
use of io.gravitee.repository.management.model.Parameter in project gravitee-management-rest-api by gravitee-io.
the class ParameterServiceTest method shouldCreateMultipleValue.
@Test
public void shouldCreateMultipleValue() throws TechnicalException {
final Parameter parameter = new Parameter();
parameter.setKey(PARAMETER_KEY);
parameter.setValue("api1");
when(parameterRepository.findById(PARAMETER_KEY)).thenReturn(empty());
when(parameterRepository.create(parameter)).thenReturn(parameter);
parameterService.createMultipleValue(PARAMETER_KEY, "api1");
verify(parameterRepository).create(parameter);
verify(auditService).createPortalAuditLog(eq(singletonMap(PARAMETER, PARAMETER_KEY)), eq(PARAMETER_CREATED), any(), eq(null), eq(parameter));
}
use of io.gravitee.repository.management.model.Parameter in project gravitee-management-rest-api by gravitee-io.
the class ParameterServiceTest method shouldCreate.
@Test
public void shouldCreate() throws TechnicalException {
final Parameter parameter = new Parameter();
parameter.setKey(PARAMETER_KEY);
parameter.setValue("api1");
when(parameterRepository.findById(PARAMETER_KEY)).thenReturn(empty());
when(parameterRepository.create(parameter)).thenReturn(parameter);
parameterService.create(PARAMETER_KEY, "api1");
verify(parameterRepository).create(parameter);
verify(auditService).createPortalAuditLog(eq(singletonMap(PARAMETER, PARAMETER_KEY)), eq(PARAMETER_CREATED), any(), eq(null), eq(parameter));
}
use of io.gravitee.repository.management.model.Parameter in project gravitee-management-rest-api by gravitee-io.
the class ParameterServiceTest method shouldNotUpdate.
@Test(expected = ParameterNotFoundException.class)
public void shouldNotUpdate() throws TechnicalException {
final Parameter parameter = new Parameter();
parameter.setKey(PARAMETER_KEY);
parameter.setValue("api1");
when(parameterRepository.findById(PARAMETER_KEY)).thenReturn(empty());
parameterService.update(PARAMETER_KEY, "api2");
}
Aggregations