Search in sources :

Example 1 with InstallationRepository

use of io.gravitee.repository.management.api.InstallationRepository 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

TechnicalException (io.gravitee.repository.exceptions.TechnicalException)1 InstallationRepository (io.gravitee.repository.management.api.InstallationRepository)1 Installation (io.gravitee.repository.management.model.Installation)1 InstallationEntity (io.gravitee.rest.api.model.InstallationEntity)1 InstallationStatus (io.gravitee.rest.api.model.InstallationStatus)1 InstallationNotFoundException (io.gravitee.rest.api.service.exceptions.InstallationNotFoundException)1 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)1 InstallationServiceImpl (io.gravitee.rest.api.service.impl.InstallationServiceImpl)1 Instant (java.time.Instant)1 ChronoUnit (java.time.temporal.ChronoUnit)1 Date (java.util.Date)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 Before (org.junit.Before)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 ArgumentMatchers (org.mockito.ArgumentMatchers)1