use of eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto in project CzechIdMng by bcvsolutions.
the class CsvConnectorTypeTest method testReopenSystemInWizard.
@Test
public void testReopenSystemInWizard() {
ConnectorTypeDto mockCsvConnectorTypeDto = new ConnectorTypeDto();
mockCsvConnectorTypeDto.setReopened(false);
mockCsvConnectorTypeDto.setId(CsvConnectorType.NAME);
mockCsvConnectorTypeDto.setConnectorName(csvConnectorType.getConnectorName());
ConnectorTypeDto csvConnectorTypeDto = connectorManager.load(mockCsvConnectorTypeDto);
assertNotNull(csvConnectorTypeDto);
csvConnectorTypeDto.getMetadata().put(CsvConnectorType.FILE_PATH, CSV_TEST_FILE);
csvConnectorTypeDto.setWizardStepName(CsvConnectorType.STEP_ONE_CREATE_SYSTEM);
// Execute the first step.
ConnectorTypeDto stepExecutedResult = connectorManager.execute(csvConnectorTypeDto);
// The system had to be created.
BaseDto system = stepExecutedResult.getEmbedded().get(CsvConnectorType.SYSTEM_DTO_KEY);
assertTrue(system instanceof SysSystemDto);
SysSystemDto systemDto = systemService.get(system.getId());
assertNotNull(systemDto);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(systemDto.getId());
schemaAttributeFilter.setName("username");
SysSchemaAttributeDto usernameAttributeDto = schemaAttributeService.find(schemaAttributeFilter, null).getContent().stream().findFirst().orElse(null);
assertNotNull(usernameAttributeDto);
// Set username attribute as primary attribute for second wizard step.
stepExecutedResult.getMetadata().put(CsvConnectorType.PRIMARY_SCHEMA_ATTRIBUTE, usernameAttributeDto.getId().toString());
// Execute the second step.
csvConnectorTypeDto.setWizardStepName(CsvConnectorType.STEP_TWO_SELECT_PK);
csvConnectorTypeDto.getMetadata().put(CsvConnectorType.SYSTEM_DTO_KEY, systemDto.getId().toString());
connectorManager.execute(csvConnectorTypeDto);
// Load wizard data for existed system;
ConnectorType connectorTypeBySystem = connectorManager.findConnectorTypeBySystem(systemDto);
ConnectorTypeDto reopenSystem = new ConnectorTypeDto();
reopenSystem.setReopened(true);
reopenSystem.setId(connectorTypeBySystem.getId());
reopenSystem.getEmbedded().put(CsvConnectorType.SYSTEM_DTO_KEY, systemDto);
reopenSystem = connectorManager.load(reopenSystem);
assertNotNull(reopenSystem);
assertEquals(systemDto.getName(), reopenSystem.getMetadata().get(CsvConnectorType.SYSTEM_NAME));
assertEquals(";", reopenSystem.getMetadata().get(CsvConnectorType.SEPARATOR));
assertEquals(usernameAttributeDto.getId().toString(), reopenSystem.getMetadata().get(CsvConnectorType.PRIMARY_SCHEMA_ATTRIBUTE));
// Delete created system.
systemService.delete(systemDto);
}
use of eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto in project CzechIdMng by bcvsolutions.
the class CsvConnectorTypeTest method testCsvFirstStep.
@Test
public void testCsvFirstStep() {
ConnectorTypeDto mockCsvConnectorTypeDto = new ConnectorTypeDto();
mockCsvConnectorTypeDto.setReopened(false);
mockCsvConnectorTypeDto.setId(CsvConnectorType.NAME);
mockCsvConnectorTypeDto.setConnectorName(csvConnectorType.getConnectorName());
ConnectorTypeDto csvConnectorTypeDto = connectorManager.load(mockCsvConnectorTypeDto);
assertNotNull(csvConnectorTypeDto);
csvConnectorTypeDto.getMetadata().put(CsvConnectorType.FILE_PATH, CSV_TEST_FILE);
csvConnectorTypeDto.setWizardStepName(CsvConnectorType.STEP_ONE_CREATE_SYSTEM);
// Execute the first step.
ConnectorTypeDto stepExecutedResult = connectorManager.execute(csvConnectorTypeDto);
// The system had to be created.
BaseDto system = stepExecutedResult.getEmbedded().get(CsvConnectorType.SYSTEM_DTO_KEY);
assertTrue(system instanceof SysSystemDto);
SysSystemDto systemDto = systemService.get(system.getId());
assertNotNull(systemDto);
// Load connector properties from created system.
IcConnectorInstance connectorInstance = systemService.getConnectorInstance(systemDto);
assertEquals("eu.bcvsolutions.idm.connectors.csv.CSVConnConnector", connectorInstance.getConnectorKey().getConnectorName());
IcConnectorConfiguration connectorConfiguration = systemService.getConnectorConfiguration(systemDto);
IcConfigurationProperties configurationProperties = connectorConfiguration.getConfigurationProperties();
// Check source path of CSV.
IcConfigurationProperty sourcePathProperty = configurationProperties.getProperties().stream().filter(property -> CsvConnectorType.CONNECTOR_SOURCE_PATH.equals(property.getName())).findFirst().orElse(null);
assertNotNull(sourcePathProperty);
assertEquals(CSV_TEST_FILE.replace('/', '\\'), ((String) sourcePathProperty.getValue()).replace('/', '\\'));
// Check separator.
IcConfigurationProperty separatorProperty = configurationProperties.getProperties().stream().filter(property -> CsvConnectorType.CONNECTOR_SOURCE_PATH.equals(property.getName())).findFirst().orElse(null);
assertNotNull(separatorProperty);
// Check include headers.
IcConfigurationProperty includeHeadersProperty = configurationProperties.getProperties().stream().filter(property -> CsvConnectorType.CONNECTOR_INCLUDES_HEADERS.equals(property.getName())).findFirst().orElse(null);
assertNotNull(includeHeadersProperty);
// Headers have to be always included in CSV file.
assertEquals(true, includeHeadersProperty.getValue());
// Check uid attribute (in first step has value "...random...").
IcConfigurationProperty uidProperty = configurationProperties.getProperties().stream().filter(property -> CsvConnectorType.CONNECTOR_UID.equals(property.getName())).findFirst().orElse(null);
assertNotNull(uidProperty);
// UID attribute have to be filled, but will be selected in the next wizard step -> is use temporary value "...random...".
assertEquals("...random...", uidProperty.getValue());
// Delete created system.
systemService.delete(systemDto);
}
use of eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultConnectorManagerTest method testFinishStep.
@Test
public void testFinishStep() {
SysSystemDto systemDto = helper.createTestResourceSystem(true);
ConnectorType connectorType = connectorManager.findConnectorTypeBySystem(systemDto);
Assert.assertEquals(DefaultConnectorType.NAME, connectorType.getConnectorName());
ConnectorTypeDto connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
connectorTypeDto.getEmbedded().put(AbstractConnectorType.SYSTEM_DTO_KEY, systemDto);
connectorTypeDto.setReopened(true);
connectorTypeDto = connectorManager.load(connectorTypeDto);
// One mapping already exists.
BaseDto mapping = connectorTypeDto.getEmbedded().get(AbstractConnectorType.MAPPING_DTO_KEY);
Assert.assertTrue(mapping instanceof SysSystemMappingDto);
// Execute finish step.
String roleName = getHelper().createName();
connectorTypeDto.setReopened(false);
connectorTypeDto.getMetadata().put(AbstractConnectorType.SYSTEM_DTO_KEY, systemDto.getId().toString());
connectorTypeDto.getMetadata().put(AbstractConnectorType.MAPPING_ID, mapping.getId().toString());
connectorTypeDto.setWizardStepName(AbstractConnectorType.STEP_FINISH);
connectorTypeDto.getMetadata().put(AbstractConnectorType.NEW_ROLE_WITH_SYSTEM_CODE, roleName);
connectorTypeDto.getMetadata().put(AbstractConnectorType.CREATES_ROLE_WITH_SYSTEM, Boolean.TRUE.toString());
systemController.executeConnectorType(connectorTypeDto);
// A new role-system was to be created.
SysRoleSystemFilter roleSystemFilter = new SysRoleSystemFilter();
roleSystemFilter.setSystemId(systemDto.getId());
List<SysRoleSystemDto> roleSystemDtos = roleSystemService.find(roleSystemFilter, null).getContent();
Assert.assertEquals(1, roleSystemDtos.size());
IdmRoleDto roleDto = (IdmRoleDto) roleSystemDtos.get(0).getEmbedded().get(SysRoleSystem_.role.getName());
Assert.assertEquals(roleName, roleDto.getBaseCode());
}
use of eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultConnectorManagerTest method testSupportsConnectorTypes.
@Test
public void testSupportsConnectorTypes() {
String defaultTableConnectorName = "net.tirasa.connid.bundles.db.table.DatabaseTableConnector";
Resources<ConnectorTypeDto> supportedTypes = systemController.getSupportedTypes();
// Find connector without connector type (it is default table connector
// = table connector has tree connector types and one default connector type).
DefaultConnectorType mockDefaultConnectorType = new DefaultConnectorType();
ConnectorTypeDto defaultConnectorTypeDto = supportedTypes.getContent().stream().filter(connectorTypeDto -> defaultTableConnectorName.equals(connectorTypeDto.getId())).findFirst().orElse(null);
assertNotNull(defaultConnectorTypeDto);
assertEquals(defaultConnectorTypeDto.getIconKey(), mockDefaultConnectorType.getIconKey());
// Find PostgreSQL connector (table connector has tree connector types and one default connector type).
ConnectorTypeDto postgresqlConnectorTypeDto = supportedTypes.getContent().stream().filter(connectorTypeDto -> PostgresqlConnectorType.NAME.equals(connectorTypeDto.getId())).findFirst().orElse(null);
assertNotNull(postgresqlConnectorTypeDto);
// Find CSV connector type
ConnectorTypeDto csvConnectorTypeDto = supportedTypes.getContent().stream().filter(connectorTypeDto -> CsvConnectorType.NAME.equals(connectorTypeDto.getId())).findFirst().orElse(null);
assertNotNull(csvConnectorTypeDto);
}
use of eu.bcvsolutions.idm.acc.dto.ConnectorTypeDto in project CzechIdMng by bcvsolutions.
the class DefaultConnectorManagerTest method testMappingStep.
@Test
public void testMappingStep() {
SysSystemDto systemDto = helper.createTestResourceSystem(true);
ConnectorType connectorType = connectorManager.findConnectorTypeBySystem(systemDto);
Assert.assertEquals(DefaultConnectorType.NAME, connectorType.getConnectorName());
ConnectorTypeDto connectorTypeDto = connectorManager.convertTypeToDto(connectorType);
connectorTypeDto.getEmbedded().put(AbstractConnectorType.SYSTEM_DTO_KEY, systemDto);
connectorTypeDto.setReopened(true);
connectorTypeDto = connectorManager.load(connectorTypeDto);
// One mapping already exists.
BaseDto mapping = connectorTypeDto.getEmbedded().get(AbstractConnectorType.MAPPING_DTO_KEY);
Assert.assertTrue(mapping instanceof SysSystemMappingDto);
// Only one mapping exists now.
String moreMappings = connectorTypeDto.getMetadata().get(AbstractConnectorType.ALERT_MORE_MAPPINGS);
Assert.assertNull(moreMappings);
// Execute mapping step.
connectorTypeDto.setReopened(false);
connectorTypeDto.setWizardStepName(AbstractConnectorType.STEP_MAPPING);
connectorTypeDto.getMetadata().put(AbstractConnectorType.SCHEMA_ID, ((SysSystemMappingDto) mapping).getObjectClass().toString());
connectorTypeDto.getMetadata().put(AbstractConnectorType.OPERATION_TYPE, SystemOperationType.SYNCHRONIZATION.name());
connectorTypeDto.getMetadata().put(AbstractConnectorType.ENTITY_TYPE, SystemEntityType.IDENTITY.name());
systemController.executeConnectorType(connectorTypeDto);
ConnectorTypeDto connectorTypeDtoAfterMappingStep = connectorManager.convertTypeToDto(connectorType);
connectorTypeDtoAfterMappingStep.getEmbedded().put(AbstractConnectorType.SYSTEM_DTO_KEY, systemDto);
connectorTypeDtoAfterMappingStep.setReopened(true);
connectorTypeDtoAfterMappingStep = connectorManager.load(connectorTypeDtoAfterMappingStep);
// Two mappings have to exists now.
moreMappings = connectorTypeDtoAfterMappingStep.getMetadata().get(AbstractConnectorType.ALERT_MORE_MAPPINGS);
Assert.assertEquals(Boolean.TRUE.toString(), moreMappings);
}
Aggregations