Search in sources :

Example 1 with Installation

use of io.gravitee.repository.management.model.Installation in project gravitee-management-rest-api by gravitee-io.

the class InstallationServiceImpl method setAdditionalInformation.

@Override
public InstallationEntity setAdditionalInformation(Map<String, String> additionalInformation) {
    try {
        final Optional<Installation> optInstallation = this.installationRepository.find();
        if (optInstallation.isPresent()) {
            Installation installation = optInstallation.get();
            installation.setAdditionalInformation(additionalInformation);
            installation.setUpdatedAt(new Date());
            return convert(this.installationRepository.update(installation));
        }
    } catch (final Exception ex) {
        LOGGER.error("Error while updating installation : {}", ex.getMessage());
        throw new TechnicalManagementException("Error while updating installation", ex);
    }
    throw new InstallationNotFoundException("");
}
Also used : Installation(io.gravitee.repository.management.model.Installation) InstallationNotFoundException(io.gravitee.rest.api.service.exceptions.InstallationNotFoundException) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) InstallationNotFoundException(io.gravitee.rest.api.service.exceptions.InstallationNotFoundException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 2 with Installation

use of io.gravitee.repository.management.model.Installation in project gravitee-management-rest-api by gravitee-io.

the class InstallationServiceImpl method createInstallation.

private InstallationEntity createInstallation() {
    final Date now = Date.from(Instant.now());
    final Installation installation = new Installation();
    installation.setId(UuidString.generateRandom());
    installation.setCreatedAt(now);
    installation.setUpdatedAt(now);
    installation.setAdditionalInformation(new HashMap<>());
    try {
        return convert(this.installationRepository.create(installation));
    } catch (final Exception ex) {
        LOGGER.error("Error while creating installation : {}", ex.getMessage());
        throw new TechnicalManagementException("Error while creating installation", ex);
    }
}
Also used : Installation(io.gravitee.repository.management.model.Installation) Date(java.util.Date) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) InstallationNotFoundException(io.gravitee.rest.api.service.exceptions.InstallationNotFoundException) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException)

Example 3 with Installation

use of io.gravitee.repository.management.model.Installation in project gravitee-management-rest-api by gravitee-io.

the class InstallationServiceTest method init.

@Before
public void init() throws TechnicalException {
    reset(installationRepository);
    installation = new Installation();
    installation.setId(INSTALLATION_ID);
    installation.setCreatedAt(NOW);
    installation.setUpdatedAt(NOW);
    installation.setAdditionalInformation(ADDITIONAL_INFORMATION);
    when(installationRepository.find()).thenReturn(Optional.of(installation));
}
Also used : Installation(io.gravitee.repository.management.model.Installation) Before(org.junit.Before)

Example 4 with Installation

use of io.gravitee.repository.management.model.Installation in project gravitee-management-rest-api by gravitee-io.

the class InstallationServiceTest method shouldUpdateAdditionalInformation.

@Test
public void shouldUpdateAdditionalInformation() throws TechnicalException {
    Map<String, String> newAdditionalInformation = new HashMap<>();
    newAdditionalInformation.put("key1", "value1");
    Installation updatedInstallation = new Installation(installation);
    updatedInstallation.setAdditionalInformation(newAdditionalInformation);
    updatedInstallation.setUpdatedAt(new Date());
    when(installationRepository.update(any(Installation.class))).thenReturn(updatedInstallation);
    final InstallationEntity updatedInstallationEntity = installationService.setAdditionalInformation(newAdditionalInformation);
    verify(installationRepository).find();
    verify(installationRepository).update(ArgumentMatchers.argThat(argument -> argument != null && INSTALLATION_ID.equals(argument.getId()) && NOW.equals(argument.getCreatedAt()) && NOW.before(argument.getUpdatedAt()) && newAdditionalInformation.equals(argument.getAdditionalInformation())));
    assertNotNull(updatedInstallationEntity);
    assertEquals(INSTALLATION_ID, updatedInstallationEntity.getId());
    assertEquals(NOW, updatedInstallationEntity.getCreatedAt());
    assertEquals(1, updatedInstallationEntity.getAdditionalInformation().size());
    assertEquals("value1", updatedInstallationEntity.getAdditionalInformation().get("key1"));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) InstallationRepository(io.gravitee.repository.management.api.InstallationRepository) Installation(io.gravitee.repository.management.model.Installation) ArgumentMatchers(org.mockito.ArgumentMatchers) Date(java.util.Date) Mock(org.mockito.Mock) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) InstallationStatus(io.gravitee.rest.api.model.InstallationStatus) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) Map(java.util.Map) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) Instant(java.time.Instant) Mockito(org.mockito.Mockito) ChronoUnit(java.time.temporal.ChronoUnit) InstallationNotFoundException(io.gravitee.rest.api.service.exceptions.InstallationNotFoundException) Optional(java.util.Optional) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) InstallationServiceImpl(io.gravitee.rest.api.service.impl.InstallationServiceImpl) Installation(io.gravitee.repository.management.model.Installation) InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) HashMap(java.util.HashMap) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Installation (io.gravitee.repository.management.model.Installation)4 InstallationNotFoundException (io.gravitee.rest.api.service.exceptions.InstallationNotFoundException)3 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)3 Date (java.util.Date)3 Before (org.junit.Before)2 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 InstallationRepository (io.gravitee.repository.management.api.InstallationRepository)1 InstallationEntity (io.gravitee.rest.api.model.InstallationEntity)1 InstallationStatus (io.gravitee.rest.api.model.InstallationStatus)1 InstallationServiceImpl (io.gravitee.rest.api.service.impl.InstallationServiceImpl)1 Instant (java.time.Instant)1 ChronoUnit (java.time.temporal.ChronoUnit)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 ArgumentMatchers (org.mockito.ArgumentMatchers)1