Search in sources :

Example 6 with Parameter

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);
    }
}
Also used : TechnicalException(io.gravitee.repository.exceptions.TechnicalException) Parameter(io.gravitee.repository.management.model.Parameter) ParameterAlreadyExistsException(io.gravitee.management.service.exceptions.ParameterAlreadyExistsException) Date(java.util.Date) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException)

Example 7 with Parameter

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));
}
Also used : Parameter(io.gravitee.repository.management.model.Parameter) Test(org.junit.Test)

Example 8 with Parameter

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));
}
Also used : Parameter(io.gravitee.repository.management.model.Parameter) Test(org.junit.Test)

Example 9 with 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));
}
Also used : Parameter(io.gravitee.repository.management.model.Parameter) Test(org.junit.Test)

Example 10 with 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");
}
Also used : Parameter(io.gravitee.repository.management.model.Parameter) Test(org.junit.Test)

Aggregations

Parameter (io.gravitee.repository.management.model.Parameter)12 Test (org.junit.Test)9 TechnicalManagementException (io.gravitee.management.service.exceptions.TechnicalManagementException)3 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)3 Date (java.util.Date)2 ParameterAlreadyExistsException (io.gravitee.management.service.exceptions.ParameterAlreadyExistsException)1 ParameterNotFoundException (io.gravitee.management.service.exceptions.ParameterNotFoundException)1