use of com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity in project hub-alert by blackducksoftware.
the class SettingsProxyCrudActionsTest method createTest.
@Test
public void createTest() {
UUID uuid = UUID.randomUUID();
SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
SettingsProxyConfigurationEntity entity = createSettingsProxyConfigurationEntity(uuid);
Mockito.when(settingsProxyConfigurationRepository.existsByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME)).thenReturn(false);
Mockito.when(settingsProxyConfigurationRepository.save(Mockito.any())).thenReturn(entity);
Mockito.when(settingsProxyConfigurationRepository.getOne(uuid)).thenReturn(entity);
SettingsProxyConfigAccessor settingsProxyConfigAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
SettingsProxyCrudActions configActions = new SettingsProxyCrudActions(authorizationManager, settingsProxyConfigAccessor, settingsProxyValidator, settingsDescriptorKey);
ActionResponse<SettingsProxyModel> actionResponse = configActions.create(createSettingsProxyModel());
Mockito.verify(nonProxyHostsConfigurationRepository).saveAll(Mockito.any());
assertTrue(actionResponse.isSuccessful());
assertTrue(actionResponse.hasContent());
assertEquals(HttpStatus.OK, actionResponse.getHttpStatus());
assertModelObfuscated(actionResponse);
}
use of com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity in project hub-alert by blackducksoftware.
the class SettingsProxyCrudActionsTest method updateTest.
@Test
public void updateTest() {
UUID uuid = UUID.randomUUID();
SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
SettingsProxyConfigurationEntity entity = createSettingsProxyConfigurationEntity(uuid);
Mockito.when(settingsProxyConfigurationRepository.findByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME)).thenReturn(Optional.of(entity));
Mockito.when(settingsProxyConfigurationRepository.existsByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME)).thenReturn(true);
Mockito.when(settingsProxyConfigurationRepository.save(Mockito.any())).thenReturn(entity);
Mockito.when(settingsProxyConfigurationRepository.getOne(uuid)).thenReturn(entity);
SettingsProxyConfigAccessor settingsProxyConfigAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
SettingsProxyCrudActions configActions = new SettingsProxyCrudActions(authorizationManager, settingsProxyConfigAccessor, settingsProxyValidator, settingsDescriptorKey);
SettingsProxyModel settingsProxyModel = createSettingsProxyModel();
ActionResponse<SettingsProxyModel> actionResponse = configActions.update(settingsProxyModel);
Mockito.verify(nonProxyHostsConfigurationRepository).saveAll(Mockito.any());
assertTrue(actionResponse.isSuccessful());
assertTrue(actionResponse.hasContent());
assertEquals(HttpStatus.OK, actionResponse.getHttpStatus());
assertModelObfuscated(actionResponse);
}
use of com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity in project hub-alert by blackducksoftware.
the class ProxyConfigurationModelSaveActionsTest method createTest.
@Test
void createTest() {
AtomicReference<SettingsProxyConfigurationEntity> savedEntity = new AtomicReference<>();
AtomicReference<NonProxyHostConfigurationEntity> savedNonProxyHostEntity = new AtomicReference<>();
SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
Mockito.when(settingsProxyConfigurationRepository.save(Mockito.any(SettingsProxyConfigurationEntity.class))).thenAnswer(invocation -> {
savedEntity.set(invocation.getArgument(0));
return savedEntity.get();
});
Mockito.when(nonProxyHostsConfigurationRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
Iterable<NonProxyHostConfigurationEntity> iterable = invocation.getArgument(0);
for (NonProxyHostConfigurationEntity entity : iterable) {
savedNonProxyHostEntity.set(entity);
}
return List.of(savedNonProxyHostEntity.get());
});
SettingsProxyConfigAccessor configurationAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
SettingsProxyCrudActions settingsProxyCrudActions = new SettingsProxyCrudActions(authorizationManager, configurationAccessor, validator, settingsDescriptorKey);
ProxyConfigurationModelSaveActions saveActions = new ProxyConfigurationModelSaveActions(converter, settingsProxyCrudActions);
saveActions.createConcreteModel(createDefaultConfigurationModel());
SettingsProxyConfigurationEntity actualEntity = savedEntity.get();
assertEquals(TEST_PROXY_HOST, actualEntity.getHost());
assertEquals(Integer.valueOf(TEST_PROXY_PORT), actualEntity.getPort());
assertEquals(TEST_PROXY_USERNAME, actualEntity.getUsername());
assertEquals(TEST_PROXY_PASSWORD, encryptionUtility.decrypt(actualEntity.getPassword()));
NonProxyHostConfigurationEntity actualNonProxyHosts = savedNonProxyHostEntity.get();
assertNotNull(actualNonProxyHosts);
assertEquals(TEST_PROXY_NON_PROXY_HOST, actualNonProxyHosts.getHostnamePattern());
}
use of com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity in project hub-alert by blackducksoftware.
the class ProxyConfigurationModelSaveActionsTest method updateTest.
@Test
void updateTest() {
AtomicReference<SettingsProxyConfigurationEntity> savedEntity = new AtomicReference<>();
AtomicReference<NonProxyHostConfigurationEntity> savedNonProxyHostEntity = new AtomicReference<>();
SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
Mockito.when(settingsProxyConfigurationRepository.save(Mockito.any(SettingsProxyConfigurationEntity.class))).thenAnswer(invocation -> {
savedEntity.set(invocation.getArgument(0));
return savedEntity.get();
});
Mockito.when(settingsProxyConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
Mockito.when(settingsProxyConfigurationRepository.existsByName(Mockito.anyString())).thenAnswer(invocation -> savedEntity.get() != null);
Mockito.when(nonProxyHostsConfigurationRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
Iterable<NonProxyHostConfigurationEntity> iterable = invocation.getArgument(0);
for (NonProxyHostConfigurationEntity entity : iterable) {
savedNonProxyHostEntity.set(entity);
}
return List.of(savedNonProxyHostEntity.get());
});
SettingsProxyConfigAccessor configurationAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
SettingsProxyCrudActions settingsProxyCrudActions = new SettingsProxyCrudActions(authorizationManager, configurationAccessor, validator, settingsDescriptorKey);
ProxyConfigurationModelSaveActions saveActions = new ProxyConfigurationModelSaveActions(converter, settingsProxyCrudActions);
String newHost = "updatedHost";
String newPort = "1234";
ConfigurationModel configurationModel = createDefaultConfigurationModel();
saveActions.createConcreteModel(configurationModel);
updateField(configurationModel, ProxyConfigurationModelConverter.FIELD_KEY_HOST, newHost);
updateField(configurationModel, ProxyConfigurationModelConverter.FIELD_KEY_PORT, newPort);
saveActions.updateConcreteModel(configurationModel);
SettingsProxyConfigurationEntity actualEntity = savedEntity.get();
assertEquals(newHost, actualEntity.getHost());
assertEquals(Integer.valueOf(newPort), actualEntity.getPort());
assertEquals(TEST_PROXY_USERNAME, actualEntity.getUsername());
assertEquals(TEST_PROXY_PASSWORD, encryptionUtility.decrypt(actualEntity.getPassword()));
NonProxyHostConfigurationEntity actualNonProxyHosts = savedNonProxyHostEntity.get();
assertNotNull(actualNonProxyHosts);
assertEquals(TEST_PROXY_NON_PROXY_HOST, actualNonProxyHosts.getHostnamePattern());
}
Aggregations