use of io.gravitee.rest.api.model.EnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class EnvironmentCommandHandlerTest method handle.
@Test
public void handle() {
EnvironmentPayload environmentPayload = new EnvironmentPayload();
EnvironmentCommand command = new EnvironmentCommand(environmentPayload);
environmentPayload.setId("env#1");
environmentPayload.setCockpitId("env#cockpit-1");
environmentPayload.setHrids(Collections.singletonList("env-1"));
environmentPayload.setOrganizationId("orga#1");
environmentPayload.setDescription("Environment description");
environmentPayload.setName("Environment name");
environmentPayload.setDomainRestrictions(Arrays.asList("domain.restriction1.io", "domain.restriction2.io"));
when(environmentService.createOrUpdate(eq("orga#1"), eq("env#1"), argThat(newEnvironment -> newEnvironment.getCockpitId().equals(environmentPayload.getCockpitId()) && newEnvironment.getHrids().equals(environmentPayload.getHrids()) && newEnvironment.getDescription().equals(environmentPayload.getDescription()) && newEnvironment.getName().equals(environmentPayload.getName()) && newEnvironment.getDomainRestrictions().equals(environmentPayload.getDomainRestrictions())))).thenReturn(new EnvironmentEntity());
TestObserver<EnvironmentReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
}
use of io.gravitee.rest.api.model.EnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class HelloCommandProducerTest method handleReplay_shouldUpdateDefaultEnvironmentCockpitId.
@Test
public void handleReplay_shouldUpdateDefaultEnvironmentCockpitId() {
HelloReply helloReply = new HelloReply();
helloReply.setCommandStatus(CommandStatus.SUCCEEDED);
helloReply.setDefaultEnvironmentCockpitId("env#cockpit-1");
String defaultEnvId = "DEFAULT";
EnvironmentEntity defaultEnvironment = new EnvironmentEntity();
defaultEnvironment.setId(defaultEnvId);
defaultEnvironment.setOrganizationId("org#1");
when(environmentService.findById(defaultEnvId)).thenReturn(defaultEnvironment);
cut.handleReply(helloReply);
verify(environmentService).createOrUpdate(eq(defaultEnvironment.getOrganizationId()), eq(defaultEnvId), argThat(env -> env.getCockpitId().equals("env#cockpit-1")));
}
use of io.gravitee.rest.api.model.EnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class ListEnvironmentOperationHandlerTest method shouldListEnvironments.
@Test
public void shouldListEnvironments() throws JsonProcessingException {
// Given
EnvironmentEntity envA = new EnvironmentEntity();
envA.setId("my-env-A");
envA.setOrganizationId(ORGANIZATION_ID);
envA.setName("ENV A");
EnvironmentEntity envB = new EnvironmentEntity();
envB.setId("my-env-B");
envB.setOrganizationId(ORGANIZATION_ID);
envB.setName("ENV B");
EnvironmentEntity envC_ERROR = new EnvironmentEntity();
envC_ERROR.setId("my-env-C");
envC_ERROR.setOrganizationId(ORGANIZATION_ID);
envC_ERROR.setName("ENV C");
when(environmentService.findByOrganization(ORGANIZATION_ID)).thenReturn(Arrays.asList(envA, envB, envC_ERROR));
when(objectMapper.writeValueAsString(envA)).thenReturn("envA");
when(objectMapper.writeValueAsString(envB)).thenReturn("envB");
when(objectMapper.writeValueAsString(envC_ERROR)).thenThrow(new JsonProcessingException("") {
});
InstallationEntity installationEntity = new InstallationEntity();
installationEntity.setId(INSTALLATION_ID);
when(installationService.get()).thenReturn(installationEntity);
BridgeCommand command = new BridgeCommand();
command.setOperation(BridgeOperation.LIST_ENVIRONMENT.name());
command.setId(COMMAND_ID);
command.setInstallationId(INSTALLATION_ID);
command.setOrganizationId(ORGANIZATION_ID);
command.setEnvironmentId(ENVIRONMENT_ID);
// When
TestObserver<BridgeReply> obs = cut.handle(command).test();
// Then
obs.awaitTerminalEvent();
obs.assertValue(reply -> {
if (reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED) && BridgeMultiReply.class.isInstance(reply)) {
BridgeMultiReply multiReply = ((BridgeMultiReply) reply);
if (multiReply.getReplies() != null && multiReply.getReplies().size() == 3) {
for (BridgeSimpleReply simpleReply : multiReply.getReplies()) {
if (simpleReply.getEnvironmentId().equals(envA.getId()) && simpleReply.getCommandStatus() == CommandStatus.ERROR) {
return false;
}
if (simpleReply.getEnvironmentId().equals(envB.getId()) && simpleReply.getCommandStatus() == CommandStatus.ERROR) {
return false;
}
if (simpleReply.getEnvironmentId().equals(envC_ERROR.getId()) && simpleReply.getCommandStatus() == CommandStatus.SUCCEEDED) {
return false;
}
}
return true;
}
}
return false;
});
}
use of io.gravitee.rest.api.model.EnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class PromotionTasksServiceImplTest method getAnEnvironmentEntity.
private EnvironmentEntity getAnEnvironmentEntity() {
final EnvironmentEntity environmentEntity = new EnvironmentEntity();
environmentEntity.setId("env#1");
environmentEntity.setCockpitId("env#1-cockpit-id");
environmentEntity.setName("Env 1");
return environmentEntity;
}
use of io.gravitee.rest.api.model.EnvironmentEntity in project gravitee-management-rest-api by gravitee-io.
the class VirtualHostServiceTest method validate_hostSubDomainOfOneOfDomainConstraints.
@Test
public void validate_hostSubDomainOfOneOfDomainConstraints() {
VirtualHost vhost = getValidVirtualHost();
String domainConstraint = vhost.getHost();
vhost.setHost("level2.level1." + domainConstraint);
EnvironmentEntity environmentEntity = new EnvironmentEntity();
environmentEntity.setDomainRestrictions(Arrays.asList("test.gravitee.io", "other.gravitee.io", domainConstraint));
when(environmentService.findById(any())).thenReturn(environmentEntity);
virtualHostService.sanitizeAndValidate(Collections.singletonList(vhost));
}
Aggregations