org.testcontainers.shaded.com.google.common.collect.ImmutableList Java Examples
The following examples show how to use
org.testcontainers.shaded.com.google.common.collect.ImmutableList.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerIT.java From presto with Apache License 2.0 | 6 votes |
public Set<List<String>> execute(String sql) { try (Connection connection = getConnection(format("jdbc:presto://%s:%s", host, port), "test", null); Statement statement = connection.createStatement()) { try (ResultSet resultSet = statement.executeQuery(sql)) { ImmutableSet.Builder<List<String>> rows = ImmutableSet.builder(); final int columnCount = resultSet.getMetaData().getColumnCount(); while (resultSet.next()) { ImmutableList.Builder<String> row = ImmutableList.builder(); for (int column = 1; column <= columnCount; column++) { row.add(resultSet.getString(column)); } rows.add(row.build()); } return rows.build(); } } catch (SQLException e) { throw new RuntimeException(e); } }
Example #2
Source File: TestCredentialStoresTaskImpl.java From datacollector with Apache License 2.0 | 6 votes |
@Test public void testEventStateRegisteredOnManagedCredentialStorePresence() { StageLibraryDefinition libraryDef = Mockito.mock(StageLibraryDefinition.class); Mockito.when(libraryDef.getName()).thenReturn("lib"); CredentialStoreDefinition storeDef = CredentialStoreDefinitionExtractor.get().extract(libraryDef, MyManagedCredentialStore.class); Configuration conf = new Configuration(); conf.set(CredentialStoresTaskImpl.MANAGED_DEFAULT_CREDENTIAL_STORE_CONFIG, "id"); conf.set("credentialStores", "id"); conf.set("credentialStore.id.def", libraryDef.getName() + "::" + storeDef.getName()); conf.set("credentialStore.id.config.foo", "bar"); StageLibraryTask libraryTask = Mockito.mock(StageLibraryTask.class); Mockito.when(libraryTask.getCredentialStoreDefinitions()).thenReturn(ImmutableList.of(storeDef)); CredentialStoresTaskImpl storeTask = new CredentialStoresTaskImpl(null, conf, libraryTask, eventListenerManager); storeTask.initTask(); Mockito.verify(eventListenerManager).addStateEventListener(Mockito.any(PipelineCredentialCleaner.class)); Assert.assertEquals(1, eventListenerManager.getStateEventListenerList().size()); StateEventListener stateEventListener = eventListenerManager.getStateEventListenerList().get(0); Assert.assertTrue(stateEventListener instanceof PipelineCredentialCleaner); storeTask.stopTask(); }
Example #3
Source File: TestSnapshots.java From java-control-plane with Apache License 2.0 | 6 votes |
static Snapshot createSnapshot( boolean ads, String clusterName, String endpointAddress, int endpointPort, String listenerName, int listenerPort, String routeName, String version) { Cluster cluster = TestResources.createCluster(clusterName); ClusterLoadAssignment endpoint = TestResources.createEndpoint(clusterName, endpointAddress, endpointPort); Listener listener = TestResources.createListener(ads, listenerName, listenerPort, routeName); RouteConfiguration route = TestResources.createRoute(routeName, clusterName); return Snapshot.create( ImmutableList.of(cluster), ImmutableList.of(endpoint), ImmutableList.of(listener), ImmutableList.of(route), ImmutableList.of(), version); }
Example #4
Source File: TestSnapshots.java From java-control-plane with Apache License 2.0 | 6 votes |
static Snapshot createSnapshotNoEds( boolean ads, String clusterName, String endpointAddress, int endpointPort, String listenerName, int listenerPort, String routeName, String version) { Cluster cluster = TestResources.createCluster(clusterName, endpointAddress, endpointPort); Listener listener = TestResources.createListener(ads, listenerName, listenerPort, routeName); RouteConfiguration route = TestResources.createRoute(routeName, clusterName); return Snapshot.create( ImmutableList.of(cluster), ImmutableList.of(), ImmutableList.of(listener), ImmutableList.of(route), ImmutableList.of(), version); }
Example #5
Source File: TestCredentialStoresTaskImpl.java From datacollector with Apache License 2.0 | 6 votes |
@Test public void testManagedCredentialStoreConfiguredButNotPresent() { StageLibraryDefinition libraryDef = Mockito.mock(StageLibraryDefinition.class); Mockito.when(libraryDef.getName()).thenReturn("lib"); CredentialStoreDefinition storeDef = CredentialStoreDefinitionExtractor.get().extract(libraryDef, MyManagedCredentialStore.class); Configuration conf = new Configuration(); conf.set(CredentialStoresTaskImpl.MANAGED_DEFAULT_CREDENTIAL_STORE_CONFIG, CredentialStoresTaskImpl.MANAGED_DEFAULT_CREDENTIAL_STORE_CONFIG_DEFAULT); conf.set("credentialStores", "id"); conf.set("credentialStore.id.def", libraryDef.getName() + "::" + storeDef.getName()); conf.set("credentialStore.id.config.foo", "bar"); StageLibraryTask libraryTask = Mockito.mock(StageLibraryTask.class); Mockito.when(libraryTask.getCredentialStoreDefinitions()).thenReturn(ImmutableList.of(storeDef)); CredentialStoresTaskImpl storeTask = new CredentialStoresTaskImpl(null, conf, libraryTask, eventListenerManager); try { storeTask.initTask(); Assert.fail(); } catch (Exception e) { //Expected } }
Example #6
Source File: TestCredentialStoresTaskImpl.java From datacollector with Apache License 2.0 | 6 votes |
@Test public void testManagedCredentialStoreConfigured() { StageLibraryDefinition libraryDef = Mockito.mock(StageLibraryDefinition.class); Mockito.when(libraryDef.getName()).thenReturn("lib"); CredentialStoreDefinition storeDef = CredentialStoreDefinitionExtractor.get().extract(libraryDef, MyManagedCredentialStore.class); Configuration conf = new Configuration(); conf.set(CredentialStoresTaskImpl.MANAGED_DEFAULT_CREDENTIAL_STORE_CONFIG, "id"); conf.set("credentialStores", "id"); conf.set("credentialStore.id.def", libraryDef.getName() + "::" + storeDef.getName()); conf.set("credentialStore.id.config.foo", "bar"); StageLibraryTask libraryTask = Mockito.mock(StageLibraryTask.class); Mockito.when(libraryTask.getCredentialStoreDefinitions()).thenReturn(ImmutableList.of(storeDef)); CredentialStoresTaskImpl storeTask = new CredentialStoresTaskImpl(null, conf, libraryTask, eventListenerManager); storeTask.initTask(); CredentialStore store = storeTask.getStores().get("id"); Assert.assertEquals(1, storeTask.getConfiguredStoreDefinititions().size()); Assert.assertTrue(store instanceof ClassloaderInContextCredentialStore); Assert.assertTrue(Whitebox.getInternalState(store,"store") instanceof ManagedCredentialStore); storeTask.stopTask(); }
Example #7
Source File: RenewDomainCommandTest.java From nomulus with Apache License 2.0 | 6 votes |
private static List<DomainBase> persistThreeDomains() { ImmutableList.Builder<DomainBase> domains = new ImmutableList.Builder<>(); domains.add( persistActiveDomain( "domain1.tld", DateTime.parse("2014-09-05T05:05:05Z"), DateTime.parse("2015-09-05T05:05:05Z"))); domains.add( persistActiveDomain( "domain2.tld", DateTime.parse("2014-11-05T05:05:05Z"), DateTime.parse("2015-11-05T05:05:05Z"))); // The third domain is owned by a different registrar. domains.add( persistResource( newDomainBase("domain3.tld") .asBuilder() .setCreationTimeForTest(DateTime.parse("2015-01-05T05:05:05Z")) .setRegistrationExpirationTime(DateTime.parse("2016-01-05T05:05:05Z")) .setPersistedCurrentSponsorClientId("NewRegistrar") .build())); return domains.build(); }
Example #8
Source File: TestUtil.java From datacollector with Apache License 2.0 | 6 votes |
@Singleton @Override public CredentialStoresTask provide() { CredentialStoresTask credentialStoresTask = Mockito.mock(CredentialStoresTask.class); CredentialStoreDefinition credentialStoreDefinition = Mockito.mock(CredentialStoreDefinition.class); StageLibraryDefinition stageLibraryDefinition = Mockito.mock(StageLibraryDefinition.class); Mockito.when(stageLibraryDefinition.getName()).thenReturn("streamsets"); Mockito.when(stageLibraryDefinition.getClassLoader()).thenReturn(Thread.currentThread().getContextClassLoader()); Mockito.when(credentialStoreDefinition.getName()).thenReturn("streamsets"); Mockito.when(credentialStoreDefinition.getStageLibraryDefinition()).thenReturn(stageLibraryDefinition); Mockito.doReturn(MyManagedCredentialStore.class).when(credentialStoreDefinition).getStoreClass(); Mockito.when(credentialStoresTask.getConfiguredStoreDefinititions()).thenReturn(ImmutableList.of(credentialStoreDefinition)); Mockito.when(credentialStoresTask.getDefaultManagedCredentialStore()).thenReturn(INSTANCE); return credentialStoresTask; }
Example #9
Source File: TestFileAclStoreTask.java From datacollector with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public void testSaveAndFetchAcl() throws Exception { try { store.init(); createDefaultPipeline(store); PipelineConfiguration pc = store.load(TestFilePipelineStoreTask.DEFAULT_PIPELINE_NAME, FilePipelineStoreTask.REV); Acl acl = aclStore.createAcl( TestFilePipelineStoreTask.DEFAULT_PIPELINE_NAME, ResourceType.PIPELINE, System.currentTimeMillis(), "testUser" ); Acl fetchedAcl = aclStore.getAcl(TestFilePipelineStoreTask.DEFAULT_PIPELINE_NAME); Assert.assertNotNull(fetchedAcl); Assert.assertEquals(acl.getResourceId(), fetchedAcl.getResourceId()); Assert.assertEquals(acl.getPermissions().size(), fetchedAcl.getPermissions().size()); Assert.assertEquals("testUser", acl.getPermissions().get(0).getSubjectId()); Permission newUserPermission = new Permission(); newUserPermission.setSubjectId("user1"); newUserPermission.setSubjectType(SubjectType.USER); newUserPermission.setLastModifiedBy("testUser"); newUserPermission.setLastModifiedOn(System.currentTimeMillis()); newUserPermission.setActions(ImmutableList.of(Action.READ)); fetchedAcl.getPermissions().add(newUserPermission); aclStore.saveAcl(TestFilePipelineStoreTask.DEFAULT_PIPELINE_NAME, fetchedAcl); fetchedAcl = aclStore.getAcl(TestFilePipelineStoreTask.DEFAULT_PIPELINE_NAME); Assert.assertNotNull(fetchedAcl); Assert.assertEquals(2, fetchedAcl.getPermissions().size()); } finally { store.stop(); } }
Example #10
Source File: TestCredentialStoresTaskImpl.java From datacollector with Apache License 2.0 | 5 votes |
@Test public void testVaultELCredentialStoreRegistration() { StageLibraryDefinition libraryDef = Mockito.mock(StageLibraryDefinition.class); Mockito.when(libraryDef.getName()).thenReturn("lib"); CredentialStoreDefinition storeDef = CredentialStoreDefinitionExtractor.get().extract(libraryDef, MyCredentialStore.class); Configuration conf = new Configuration(); conf.set("credentialStores", "id"); conf.set("credentialStore.id.def", libraryDef.getName() + "::" + storeDef.getName()); conf.set("credentialStore.id.config.foo", "bar"); StageLibraryTask libraryTask = Mockito.mock(StageLibraryTask.class); Mockito.when(libraryTask.getCredentialStoreDefinitions()).thenReturn(ImmutableList.of(storeDef)); // testing no Vault EL impl registered CredentialStoresTaskImpl storeTask = new CredentialStoresTaskImpl(null, conf, libraryTask, eventListenerManager); storeTask.initTask(); Assert.assertNull(DataCollectorServices.instance().get(CredentialStoresTaskImpl.VAULT_CREDENTIAL_STORE_KEY)); storeTask.stopTask(); // testing Vault EL impl registered conf.set("vaultEL.credentialStore.id", "id"); storeTask = new CredentialStoresTaskImpl(null, conf, libraryTask, eventListenerManager); storeTask.initTask(); CredentialStore store = DataCollectorServices.instance().get(CredentialStoresTaskImpl.VAULT_CREDENTIAL_STORE_KEY); Assert.assertNotNull(store); storeTask.stopTask(); }
Example #11
Source File: TestCredentialStoresTaskImpl.java From datacollector with Apache License 2.0 | 5 votes |
@Test public void testLoadAndInitStoreGetDestroy() throws Exception { StageLibraryDefinition libraryDef = Mockito.mock(StageLibraryDefinition.class); Mockito.when(libraryDef.getName()).thenReturn("lib"); CredentialStoreDefinition storeDef = CredentialStoreDefinitionExtractor.get().extract(libraryDef, MyCredentialStore.class); Configuration conf = new Configuration(); conf.set("credentialStores", "id"); conf.set("credentialStore.id.def", libraryDef.getName() + "::" + storeDef.getName()); conf.set("credentialStore.id.config.foo", "bar"); StageLibraryTask libraryTask = Mockito.mock(StageLibraryTask.class); Mockito.when(libraryTask.getCredentialStoreDefinitions()).thenReturn(ImmutableList.of(storeDef)); CredentialStoresTaskImpl storeTask = new CredentialStoresTaskImpl(null, conf, libraryTask, eventListenerManager); storeTask.initTask(); CredentialStore store = storeTask.getStores().get("id"); Assert.assertEquals(1, storeTask.getConfiguredStoreDefinititions().size()); Assert.assertTrue(store instanceof ClassloaderInContextCredentialStore); GroupsInScope.execute(ImmutableSet.of("g"), () -> store.get("g", "n", "o")); // enforcing Fail try { GroupsInScope.execute(ImmutableSet.of("g"), () -> store.get("h", "n", "o")); Assert.fail(); } catch (Exception ex) { Assert.assertTrue("Got " + ex.getClass().getName(), ex instanceof StageException); } // not enforcing GroupsInScope.executeIgnoreGroups(() -> store.get("g", "n", "o")); storeTask.stopTask(); }
Example #12
Source File: TestElUtil.java From datacollector with Apache License 2.0 | 5 votes |
private Object evaluate(String el) throws Exception { StageDefinition sd = Mockito.mock(StageDefinition.class); Mockito.when(sd.getName()).thenReturn("stage"); ConfigDefinition cd = Mockito.mock(ConfigDefinition.class); Mockito.when(cd.getEvaluation()).thenReturn(ConfigDef.Evaluation.IMPLICIT); Mockito.when(cd.getName()).thenReturn("config"); Mockito.when(cd.getElDefs()).thenReturn(ImmutableList.of(CredentialEL.class)); Mockito.when(cd.getConfigField()).thenReturn(CV_FIELD); Mockito.when(cd.getType()).thenReturn(ConfigDef.Type.CREDENTIAL); return ElUtil.evaluate("Test", el, cd, Collections.emptyMap()); }
Example #13
Source File: TestRuleDefinitionsUpgrader.java From datacollector with Apache License 2.0 | 5 votes |
private RuleDefinitions getSchemaVersion2RuleDefinitions() { return new RuleDefinitions( 2, RuleDefinitionsConfigBean.VERSION, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), ImmutableList.of("[email protected]", "[email protected]"), UUID.randomUUID(), new ArrayList<>() ); }
Example #14
Source File: LDAPAuthenticationFallbackIT.java From datacollector with Apache License 2.0 | 5 votes |
@Parameterized.Parameters public static Collection<Object[]> data() throws Exception { return Arrays.asList(new Object[][]{ // {username, password, authentication success?, expected sdc role to be found} {"user1", "user1", true, ImmutableList.of("creator")}, // wrong password in server1, but correct in server2 {"user2", "user2", true, ImmutableList.of("admin")}, // user not found in server1, but found in server2 {"user3", "user3", true, ImmutableList.of("admin")}, // group is not mapped in server1 {"user4", "user4", true, ImmutableList.of("admin")}, // no group in server1, but found in server2 {"user3", "dummy", false, ImmutableList.of()}, // password is wrong. Auth failed on both servers {"user5", "user5", true, ImmutableList.of("manager", "admin")} // user found in both servers but roles are different }); }
Example #15
Source File: TestRuleDefinitionValidator.java From datacollector with Apache License 2.0 | 5 votes |
@Test public void testInValidConfiguration() { List<Config> rulesConfiguration = ImmutableList.of( new Config("emailIDs", ImmutableList.of("${USER_EMAIL_ID}")) ); RuleDefinitions ruleDefinitions = new RuleDefinitions( FilePipelineStoreTask.RULE_DEFINITIONS_SCHEMA_VERSION, RuleDefinitionsConfigBean.VERSION, Collections.<MetricsRuleDefinition>emptyList(), Collections.<DataRuleDefinition>emptyList(), Collections.<DriftRuleDefinition>emptyList(), null, UUID.randomUUID(), rulesConfiguration ); RuleDefinitionValidator ruleDefinitionValidator = new RuleDefinitionValidator( "pipelineId", ruleDefinitions, Collections.emptyMap() ); Assert.assertFalse(ruleDefinitionValidator.validateRuleDefinition()); Assert.assertNotNull(ruleDefinitions.getConfigIssues()); Assert.assertEquals(1, ruleDefinitions.getConfigIssues().size()); Assert.assertEquals("emailIDs", ruleDefinitions.getConfigIssues().get(0).getConfigName()); Assert.assertTrue( ruleDefinitions.getConfigIssues().get(0).getMessage().contains("'USER_EMAIL_ID' cannot be resolved") ); ruleDefinitionValidator = new RuleDefinitionValidator( "pipelineId", ruleDefinitions, ImmutableMap.of("USER_EMAIL_ID", "[email protected]") ); Assert.assertTrue(ruleDefinitionValidator.validateRuleDefinition()); Assert.assertNotNull(ruleDefinitions.getConfigIssues()); Assert.assertEquals(0, ruleDefinitions.getConfigIssues().size()); }
Example #16
Source File: PrefetchingDatabaseProviderTest.java From embedded-database-spring-test with Apache License 2.0 | 5 votes |
@Before public void setUp() { databaseProvider1 = spy(new TestDatabaseProvider(DatabaseType.valueOf("database1"), ProviderType.valueOf("provider1"))); databaseProvider2 = spy(new TestDatabaseProvider(DatabaseType.valueOf("database2"), ProviderType.valueOf("provider1"))); databaseProvider3 = spy(new TestDatabaseProvider(DatabaseType.valueOf("database2"), ProviderType.valueOf("provider2"))); when(databaseProviders.getIfAvailable()).thenReturn(ImmutableList.of(databaseProvider1, databaseProvider2, databaseProvider3)); this.prefetchingProvider = new PrefetchingDatabaseProvider(databaseProviders, new MockEnvironment()); }
Example #17
Source File: DiscoveryServerAdsWarmingClusterIT.java From java-control-plane with Apache License 2.0 | 5 votes |
private static Snapshot createSnapshotWithNotWorkingCluster(boolean ads, String clusterName, String endpointAddress, int endpointPort, String listenerName, int listenerPort, String routeName) { ConfigSource edsSource = ConfigSource.newBuilder() .setAds(AggregatedConfigSource.getDefaultInstance()) .build(); Cluster cluster = Cluster.newBuilder() .setName(clusterName) .setConnectTimeout(Durations.fromSeconds(RandomUtils.nextInt(5))) // we are enabling HTTP2 - communication with cluster won't work .setHttp2ProtocolOptions(Http2ProtocolOptions.newBuilder().build()) .setEdsClusterConfig(Cluster.EdsClusterConfig.newBuilder() .setEdsConfig(edsSource) .setServiceName(clusterName)) .setType(Cluster.DiscoveryType.EDS) .build(); ClusterLoadAssignment endpoint = TestResources.createEndpoint(clusterName, endpointAddress, endpointPort); Listener listener = TestResources.createListener(ads, listenerName, listenerPort, routeName); RouteConfiguration route = TestResources.createRoute(routeName, clusterName); // here we have new version of resources other than CDS. return Snapshot.create( ImmutableList.of(cluster), "1", ImmutableList.of(endpoint), "2", ImmutableList.of(listener), "2", ImmutableList.of(route), "2", ImmutableList.of(), "2"); }
Example #18
Source File: Commands.java From presto with Apache License 2.0 | 5 votes |
public static void runCommand(List<Module> modules, Class<? extends Runnable> commandExecution) { Bootstrap app = new Bootstrap( ImmutableList.<Module>builder() .addAll(modules) .add(binder -> binder.bind(commandExecution)) .build()); Injector injector = app .strictConfig() .initialize(); injector.getInstance(commandExecution) .run(); }
Example #19
Source File: TestClassloaderInContextCredentialStore.java From datacollector with Apache License 2.0 | 4 votes |
@Override public List<String> getNames() throws StageException { Assert.assertEquals(expectedClassLoader, Thread.currentThread().getContextClassLoader()); return ImmutableList.of("credential"); }
Example #20
Source File: Environment.java From presto with Apache License 2.0 | 4 votes |
public Collection<Container<?>> getContainers() { return ImmutableList.copyOf(containers.values()); }