Search in sources :

Example 16 with InstallationEntity

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

the class DefaultInstallationUpgrader method upgrade.

@Override
public boolean upgrade() {
    final InstallationEntity installation = installationService.getOrInitialize();
    logger.info("Current installation id is [{}]", installation.getId());
    return true;
}
Also used : InstallationEntity(io.gravitee.rest.api.model.InstallationEntity)

Example 17 with InstallationEntity

use of io.gravitee.rest.api.model.InstallationEntity 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)

Example 18 with InstallationEntity

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

the class InstallationServiceTest method shouldGetInstallationIfExists.

@Test
public void shouldGetInstallationIfExists() throws TechnicalException {
    final InstallationEntity installationEntity = installationService.getOrInitialize();
    verify(installationRepository).find();
    verify(installationRepository, times(0)).create(any());
    assertNotNull(installationEntity);
    assertEquals(INSTALLATION_ID, installationEntity.getId());
    assertEquals(NOW, installationEntity.getCreatedAt());
    assertEquals(NOW, installationEntity.getUpdatedAt());
    assertEquals(2, installationEntity.getAdditionalInformation().size());
    assertEquals(COCKPIT_INSTALLATION_ID, installationEntity.getAdditionalInformation().get(InstallationService.COCKPIT_INSTALLATION_ID));
    assertEquals(COCKPIT_INSTALLATION_STATUS, installationEntity.getAdditionalInformation().get(InstallationService.COCKPIT_INSTALLATION_STATUS));
}
Also used : InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) Test(org.junit.Test)

Example 19 with InstallationEntity

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

the class InstallationServiceTest method shouldCreateInstallationIfNotFound.

@Test
public void shouldCreateInstallationIfNotFound() throws TechnicalException {
    when(installationRepository.find()).thenReturn(Optional.empty());
    when(installationRepository.create(any())).thenReturn(installation);
    final InstallationEntity installationEntity = installationService.getOrInitialize();
    verify(installationRepository).find();
    verify(installationRepository).create(any());
    assertNotNull(installationEntity);
    assertEquals(INSTALLATION_ID, installationEntity.getId());
    assertEquals(NOW, installationEntity.getCreatedAt());
    assertEquals(NOW, installationEntity.getUpdatedAt());
    assertEquals(2, installationEntity.getAdditionalInformation().size());
    assertEquals(COCKPIT_INSTALLATION_ID, installationEntity.getAdditionalInformation().get(InstallationService.COCKPIT_INSTALLATION_ID));
    assertEquals(COCKPIT_INSTALLATION_STATUS, installationEntity.getAdditionalInformation().get(InstallationService.COCKPIT_INSTALLATION_STATUS));
}
Also used : InstallationEntity(io.gravitee.rest.api.model.InstallationEntity) Test(org.junit.Test)

Aggregations

InstallationEntity (io.gravitee.rest.api.model.InstallationEntity)19 Test (org.junit.Test)15 BridgeCommand (io.gravitee.cockpit.api.command.bridge.BridgeCommand)5 BridgeReply (io.gravitee.cockpit.api.command.bridge.BridgeReply)5 BridgePayload (io.gravitee.cockpit.api.command.bridge.BridgePayload)4 BridgeTarget (io.gravitee.cockpit.api.command.bridge.BridgeTarget)4 BridgeSimpleReply (io.gravitee.cockpit.api.command.bridge.BridgeSimpleReply)3 GoodbyeCommand (io.gravitee.cockpit.api.command.goodbye.GoodbyeCommand)3 GoodbyeReply (io.gravitee.cockpit.api.command.goodbye.GoodbyeReply)3 PromotionEntity (io.gravitee.rest.api.model.promotion.PromotionEntity)3 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)3 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 InstallationCommand (io.gravitee.cockpit.api.command.installation.InstallationCommand)2 InstallationPayload (io.gravitee.cockpit.api.command.installation.InstallationPayload)2 InstallationReply (io.gravitee.cockpit.api.command.installation.InstallationReply)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 BridgeMultiReply (io.gravitee.cockpit.api.command.bridge.BridgeMultiReply)1 HelloCommand (io.gravitee.cockpit.api.command.hello.HelloCommand)1 HelloPayload (io.gravitee.cockpit.api.command.hello.HelloPayload)1