@Override public CacheConfig getCacheConfig(String group) { return getCacheConfig(group, false); }
@Before public void setUp() throws Exception { command = spy(ListJndiBindingCommand.class); ccService = mock(InternalConfigurationPersistenceService.class); doReturn(ccService).when(command).getConfigurationPersistenceService(); cacheConfig = mock(CacheConfig.class); when(ccService.getCacheConfig("cluster")).thenReturn(cacheConfig); }
private void setupJDBCMappingOnRegion(String regionName) { doReturn(cacheConfig).when(ccService).getCacheConfig(null); doReturn(regionConfigList).when(cacheConfig).getRegions(); doReturn(regionName).when(regionConfig).getName(); doReturn(regionName).when(regionConfig).getId(); doReturn(cacheElementList).when(regionConfig).getCustomRegionElements(); doReturn("jdbc-mapping").when(cacheElement).getId(); }
@Test public void getNonExistingGroupConfigShouldReturnNull() { assertThat(service.getCacheConfig("non-existing-group")).isNull(); }
CacheConfig.AsyncEventQueue findAEQ(String aeqId) { CacheConfig.AsyncEventQueue queue = null; InternalConfigurationPersistenceService ccService = (InternalConfigurationPersistenceService) this.getConfigurationPersistenceService(); if (ccService == null) { return null; } Set<String> groups = ccService.getGroups(); for (String group : groups) { queue = CacheElement.findElement(ccService.getCacheConfig(group).getAsyncEventQueues(), aeqId); if (queue != null) { return queue; } } return queue; }
@Test public void updateShouldInsertIfNotExist() { doCallRealMethod().when(service).updateCacheConfig(any(), any()); doCallRealMethod().when(service).getCacheConfig(any()); Region region = mock(Region.class); doReturn(region).when(service).getConfigurationRegion(); service.updateCacheConfig("non-existing-group", cc -> cc); verify(region).put(eq("non-existing-group"), any()); }
@Test public void returnsErrorIfDataSourceAlreadyExistsAndIfUnspecified() { InternalConfigurationPersistenceService clusterConfigService = mock(InternalConfigurationPersistenceService.class); CacheConfig cacheConfig = mock(CacheConfig.class); when(cacheConfig.getJndiBindings()).thenReturn(bindings); bindings.add(binding); doReturn(clusterConfigService).when(command).getConfigurationPersistenceService(); doReturn(cacheConfig).when(clusterConfigService).getCacheConfig(any()); gfsh.executeAndAssertThat(command, COMMAND + " --name=name --url=url") .statusIsError().containsOutput("already exists."); }
@Test public void describeDataSourceWithNoClusterConfigFails() { doReturn(null).when(clusterConfigService).getCacheConfig(any()); ResultModel result = command.describeDataSource(DATA_SOURCE_NAME); assertThat(result.getStatus()).isEqualTo(Status.ERROR); assertThat(result.toString()).contains("Data source: " + DATA_SOURCE_NAME + " not found"); }
@Test public void listDataSourceWithNoClusterConfigIsOkWithNoDataSources() { doReturn(null).when(clusterConfigService).getCacheConfig(any()); ResultModel result = command.listDataSources(); assertThat(result.getStatus()).isEqualTo(Status.OK); assertThat(result.toString()).contains("No data sources found"); }
@Test public void checkForJDBCMappingWithNoCacheConfigDoesNotThrowException() { setupJDBCMappingOnRegion("regionName"); doReturn(null).when(ccService).getCacheConfig(null); command.checkForJDBCMapping("regionName"); }
@Test public void returnsErrorIfBindingAlreadyExistsAndIfUnspecified() { InternalConfigurationPersistenceService clusterConfigService = mock(InternalConfigurationPersistenceService.class); CacheConfig cacheConfig = mock(CacheConfig.class); when(cacheConfig.getJndiBindings()).thenReturn(bindings); bindings.add(binding); doReturn(clusterConfigService).when(command).getConfigurationPersistenceService(); doReturn(cacheConfig).when(clusterConfigService).getCacheConfig(any()); gfsh.executeAndAssertThat(command, COMMAND + " --type=SIMPLE --name=name --jdbc-driver-class=driver --connection-url=url") .statusIsError().containsOutput("already exists."); }
@Test public void skipsIfDataSourceAlreadyExistsAndIfSpecifiedTrue() { InternalConfigurationPersistenceService clusterConfigService = mock(InternalConfigurationPersistenceService.class); CacheConfig cacheConfig = mock(CacheConfig.class); when(cacheConfig.getJndiBindings()).thenReturn(bindings); bindings.add(binding); doReturn(clusterConfigService).when(command).getConfigurationPersistenceService(); doReturn(cacheConfig).when(clusterConfigService).getCacheConfig(any()); gfsh.executeAndAssertThat(command, COMMAND + " --name=name --url=url --if-not-exists=true") .statusIsSuccess().containsOutput("Skipping"); }
@Test public void skipsIfBindingAlreadyExistsAndIfSpecifiedTrue() { InternalConfigurationPersistenceService clusterConfigService = mock(InternalConfigurationPersistenceService.class); CacheConfig cacheConfig = mock(CacheConfig.class); when(cacheConfig.getJndiBindings()).thenReturn(bindings); bindings.add(binding); doReturn(clusterConfigService).when(command).getConfigurationPersistenceService(); doReturn(cacheConfig).when(clusterConfigService).getCacheConfig(any()); gfsh.executeAndAssertThat(command, COMMAND + " --type=SIMPLE --name=name --jdbc-driver-class=driver --connection-url=url --if-not-exists=true") .statusIsSuccess().containsOutput("Skipping"); }
@Test public void returnsErrorIfBindingAlreadyExistsAndIfSpecifiedFalse() { InternalConfigurationPersistenceService clusterConfigService = mock(InternalConfigurationPersistenceService.class); CacheConfig cacheConfig = mock(CacheConfig.class); when(cacheConfig.getJndiBindings()).thenReturn(bindings); bindings.add(binding); doReturn(clusterConfigService).when(command).getConfigurationPersistenceService(); doReturn(cacheConfig).when(clusterConfigService).getCacheConfig(any()); gfsh.executeAndAssertThat(command, COMMAND + " --type=SIMPLE --name=name --jdbc-driver-class=driver --connection-url=url --if-not-exists=false") .statusIsError().containsOutput("already exists."); }
@Test public void skipsIfBindingAlreadyExistsAndIfSpecified() { InternalConfigurationPersistenceService clusterConfigService = mock(InternalConfigurationPersistenceService.class); CacheConfig cacheConfig = mock(CacheConfig.class); doReturn(clusterConfigService).when(command).getConfigurationPersistenceService(); doReturn(cacheConfig).when(clusterConfigService).getCacheConfig(any()); when(cacheConfig.getJndiBindings()).thenReturn(bindings); bindings.add(binding); gfsh.executeAndAssertThat(command, COMMAND + " --type=SIMPLE --name=name --jdbc-driver-class=driver --connection-url=url --if-not-exists") .statusIsSuccess().containsOutput("Skipping"); }
@Test public void skipsIfDataSourceAlreadyExistsAndIfSpecified() { InternalConfigurationPersistenceService clusterConfigService = mock(InternalConfigurationPersistenceService.class); CacheConfig cacheConfig = mock(CacheConfig.class); doReturn(clusterConfigService).when(command).getConfigurationPersistenceService(); doReturn(cacheConfig).when(clusterConfigService).getCacheConfig(any()); when(cacheConfig.getJndiBindings()).thenReturn(bindings); bindings.add(binding); gfsh.executeAndAssertThat(command, COMMAND + " --name=name --url=url --if-not-exists") .statusIsSuccess().containsOutput("Skipping"); }
@Test public void returnsErrorIfDataSourceAlreadyExistsAndIfSpecifiedFalse() { InternalConfigurationPersistenceService clusterConfigService = mock(InternalConfigurationPersistenceService.class); CacheConfig cacheConfig = mock(CacheConfig.class); when(cacheConfig.getJndiBindings()).thenReturn(bindings); bindings.add(binding); doReturn(clusterConfigService).when(command).getConfigurationPersistenceService(); doReturn(cacheConfig).when(clusterConfigService).getCacheConfig(any()); gfsh.executeAndAssertThat(command, COMMAND + " --name=name --url=url --if-not-exists=false") .statusIsError().containsOutput("already exists."); }
@Test public void getExistingGroupConfigShouldReturnNullIfNoXml() { Configuration groupConfig = new Configuration("some-new-group"); doReturn(groupConfig).when(service).getConfiguration("some-new-group"); CacheConfig groupCacheConfig = service.getCacheConfig("some-new-group"); assertThat(groupCacheConfig).isNull(); }
@Before public void setUp() { command = spy(ListDataSourceCommand.class); binding = new JndiBindingsType.JndiBinding(); binding.setJndiName(DATA_SOURCE_NAME); binding.setType(DATASOURCE_TYPE.POOLED.getType()); binding.setConnectionUrl("myURL"); bindings = new ArrayList<>(); clusterConfigService = mock(InternalConfigurationPersistenceService.class); cacheConfig = mock(CacheConfig.class); when(cacheConfig.getJndiBindings()).thenReturn(bindings); bindings.add(binding); regionConfigs = new ArrayList<>(); when(cacheConfig.getRegions()).thenReturn(regionConfigs); doReturn(clusterConfigService).when(command).getConfigurationPersistenceService(); doReturn(cacheConfig).when(clusterConfigService).getCacheConfig(any()); }
@Before public void setUp() throws Exception { binding = new JndiBindingsType.JndiBinding(); binding.setJndiName("jndi-name"); binding.setType("SIMPLE"); binding.setJdbcDriverClass("org.postgresql.Driver"); binding.setConnectionUrl("jdbc:postgresql://localhost:5432/my_db"); binding.setUserName("MyUser"); bindings = new ArrayList<>(); command = spy(DescribeJndiBindingCommand.class); ccService = mock(InternalConfigurationPersistenceService.class); cacheConfig = mock(CacheConfig.class); doReturn(ccService).when(command).getConfigurationPersistenceService(); when(ccService.getCacheConfig("cluster")).thenReturn(cacheConfig); when(cacheConfig.getJndiBindings()).thenReturn(bindings); }