org.testng.collections.Maps#newHashMap ( )源码实例Demo

下面列出了org.testng.collections.Maps#newHashMap ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: kop   文件: MemberMetadataTest.java
@Test
public void testMatchesSupportedProtocols() {
    Map<String, byte[]> protocols = Maps.newHashMap();
    protocols.put("range", new byte[0]);

    MemberMetadata member = newMember(protocols);

    assertTrue(member.matches(protocols));

    protocols = new HashMap<>();
    protocols.put("range", new byte[] { 0 });
    assertFalse(member.matches(protocols));

    protocols = new HashMap<>();
    protocols.put("roundrobin", new byte[0]);
    assertFalse(member.matches(protocols));

    protocols = new HashMap<>();
    protocols.put("range", new byte[0]);
    protocols.put("roundrobin", new byte[0]);
    assertFalse(member.matches(protocols));
}
 
源代码2 项目: q   文件: SolrIndexerTest.java
@Test
void createDocTest()
{
	BaseIndexer indexer = new SolrIndexer("", TEST1);
	List<String> languages = Lists.newArrayList();
	languages.add(LOCALE);
	Map<String, Object> createdDoc = indexer.createDoc(ID, ENGLISH_TITLE, SPANISH_TITLE, ALT_TITLE, languages);
	Map<String, Object> expectedDoc = Maps.newHashMap();
	expectedDoc.put(Properties.idField.get(), ID + "_" + TEST1);
	expectedDoc.put(Properties.titleFields.get().get(0) + "_en", ENGLISH_TITLE);
	Set<Object> localizedTitles = Sets.newHashSet();
	localizedTitles.add(SPANISH_TITLE);
	expectedDoc.put(Properties.titleFields.get().get(0) + "_es", localizedTitles);
	expectedDoc.put(Properties.docTypeFieldName.get(), TEST1);
	Assert.assertEquals(createdDoc, expectedDoc);

	StringBuilder jsonStringOfDoc = indexer.getJsonStringOfDoc(new ObjectMapper().valueToTree(createdDoc));
	Assert.assertEquals(jsonStringOfDoc.toString(), "[{\"query_testing_type\":\"test1\",\"title_en\":\"title en\",\"id\":\"123_test1\",\"title_es\":[\"title es\"]}]");
	
	String urlForAddingDoc = indexer.getUrlForAddingDoc(createdDoc);
	Assert.assertEquals(urlForAddingDoc, "http://localhost:8983/solr/qtest/update");

	String urlForCommitting = indexer.getUrlForCommitting();
	Assert.assertEquals(urlForCommitting, "http://localhost:8983/solr/qtest/update?commit=true");
}
 
源代码3 项目: pulsar   文件: TestCompaction.java
private static Map<Integer, String> consumeCompactedTopic(PulsarClient client,
                                                          String topic,
                                                          String subscription,
                                                          int numKeys) throws PulsarClientException {
    Map<Integer, String> keys = Maps.newHashMap();
    try (Consumer<byte[]> consumer = client.newConsumer()
         .readCompacted(true)
         .topic(topic)
         .subscriptionName(subscription)
         .subscribe()
    ) {
        for (int i = 0; i < numKeys; i++) {
            Message<byte[]> m = consumer.receive();
            keys.put(Integer.parseInt(m.getKey()), new String(m.getValue(), UTF_8));
        }
    }
    return keys;
}
 
源代码4 项目: pulsar   文件: AdminApiSchemaValidationEnforced.java
@Test
public void testDisableSchemaValidationEnforcedHasSchema() throws Exception {
    admin.namespaces().createNamespace("schema-validation-enforced/default-has-schema");
    String namespace = "schema-validation-enforced/default-has-schema";
    String topicName = "persistent://schema-validation-enforced/default-has-schema/test";
    assertFalse(admin.namespaces().getSchemaValidationEnforced(namespace));
    admin.namespaces().setSchemaValidationEnforced(namespace, false);
    try {
        admin.schemas().getSchemaInfo(topicName);
    } catch (PulsarAdminException.NotFoundException e) {
        assertTrue(e.getMessage().contains("HTTP 404 Not Found"));
    }
    Map<String, String> properties = Maps.newHashMap();
    SchemaInfo schemaInfo = new SchemaInfo();
    schemaInfo.setType(SchemaType.STRING);
    schemaInfo.setProperties(properties);
    schemaInfo.setName("test");
    schemaInfo.setSchema("".getBytes());
    PostSchemaPayload postSchemaPayload = new PostSchemaPayload("STRING", "", properties);
    admin.schemas().createSchema(topicName, postSchemaPayload);
    try (Producer p = pulsarClient.newProducer().topic(topicName).create()) {
        p.send("test schemaValidationEnforced".getBytes());
    }
    assertEquals(admin.schemas().getSchemaInfo(topicName), schemaInfo);
}
 
源代码5 项目: proxy   文件: UtilTest.java
@Test
public void defaultToEmptyCollectionsOnNullValueTest() throws Throwable {
    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(List.class, null).isEmpty());
    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(List.class, Lists.newArrayList("1")).contains("1"));

    Set<Object> set = Sets.newHashSet();
    set.add(1);
    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(Set.class, set).contains(1));
    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(Set.class, null).isEmpty());

    Map<Object, Object> map = Maps.newHashMap();
    map.put(1, 2);
    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(Map.class, map).containsKey(1));
    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(Map.class, map).containsValue(2));
    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(Map.class, null).isEmpty());

    Object[] arr = set.toArray(new Object[set.size()]);
    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(Object[].class, null).length == 0);
    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(Object[].class, arr).length == 1);

    Properties prop = new Properties();
    prop.put("1", "2");
    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(Properties.class, prop).containsKey("1"));
    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(Properties.class, prop).containsValue("2"));
    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(Properties.class, null).isEmpty());

    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(Collection.class, null).isEmpty());
    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(Collection.class, set).contains(1));

    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(String.class, null) == null);
    assertTrue(Util.defaultToEmptyCollectionsOnNullValue(String.class, "123").contentEquals("123"));

}
 
源代码6 项目: pulsar   文件: PulsarFunctionsTest.java
protected Map<String, String> produceSchemaInsertMessagesToInputTopic(String inputTopicName,
                                                                      int numMessages,
                                                                      Schema<Foo> schema) throws Exception {
    @Cleanup
    PulsarClient client = PulsarClient.builder()
        .serviceUrl(pulsarCluster.getPlainTextServiceUrl())
        .build();

    @Cleanup
    Producer<Foo> producer = client.newProducer(schema)
        .topic(inputTopicName)
        .create();

    LinkedHashMap<String, String> kvs = new LinkedHashMap<>();
    for (int i = 0; i < numMessages; i++) {
        String key = "key-" + i;

        JdbcPostgresSinkTester.Foo obj = new JdbcPostgresSinkTester.Foo();
        obj.setField1("field1_insert_" + i);
        obj.setField2("field2_insert_" + i);
        obj.setField3(i);
        String value = new String(schema.encode(obj));
        Map<String, String> properties = Maps.newHashMap();
        properties.put("ACTION", "INSERT");

        kvs.put(key, value);
        kvs.put("ACTION", "INSERT");
        producer.newMessage()
                .properties(properties)
                .key(key)
                .value(obj)
                .send();
    }
    return kvs;
}
 
源代码7 项目: q   文件: QueriesTest.java
@Test
void createDocTest()
{
	GoogleDataExtractor titleExtractor = Mockito.mock(GoogleDataExtractor.class);
	Map<String, Map<Integer, TitleWithQueries>> mapOfQueriesToTitles = Maps.newHashMap();
	
	Map<Integer, TitleWithQueries> titlesWithQueries = Maps.newHashMap();
	TitleWithQueries titleWithQueries = new TitleWithQueries(DATASET_ID);
	titleWithQueries.setValue(TitleWithQueries.ID, ID1);
	titleWithQueries.setValue(TitleWithQueries.TITLE_EN, ENGLISH_TITLE);
	titleWithQueries.setValue(TitleWithQueries.TITLE_LOCALE, SPANISH_TITLE);
	titleWithQueries.setValue(TitleWithQueries.Q_ + "regular", Q1);
	titlesWithQueries.put(1, titleWithQueries);

	TitleWithQueries titleWithQueries2 = new TitleWithQueries(DATASET_ID);
	titleWithQueries2.setValue(TitleWithQueries.ID, ID2);
	titleWithQueries2.setValue(TitleWithQueries.TITLE_EN, ENGLISH_TITLE);
	titleWithQueries2.setValue(TitleWithQueries.TITLE_LOCALE, SPANISH_TITLE);
	titleWithQueries2.setValue(TitleWithQueries.Q_ + "regular", Q1);
	titlesWithQueries.put(2, titleWithQueries2);

	mapOfQueriesToTitles.put(DATASET_ID, titlesWithQueries);

	Mockito.when(titleExtractor.getTitlesWithQueriesPerDataset()).thenReturn(mapOfQueriesToTitles);

	Queries queries = new Queries(DATASET_ID, TEST1, titleExtractor);
	queries.populateFromGoogleSpreadsheets();

	Map<String, Set<String>> queryToIdMap = queries.getQueryToIdMap();

	Map<String, Set<String>> expectedQueryToIdMap = Maps.newHashMap();
	Set<String> titles = Sets.newHashSet();
	titles.add(ID1+"_"+DATASET_ID);
	titles.add(ID2+"_"+DATASET_ID);
	expectedQueryToIdMap.put(Q1, titles);

	Assert.assertEquals(queryToIdMap, expectedQueryToIdMap);
}
 
源代码8 项目: qaf   文件: TestRunner.java
private Map<String, String> createGroups(String[] groups) {
  Map<String, String> result = Maps.newHashMap();

  // Groups that were passed on the command line
  for (String group : groups) {
    result.put(group, group);
  }

  // See if we have any MetaGroups and
  // expand them if they match one of the groups
  // we have just been passed
  List<String> unfinishedGroups = Lists.newArrayList();

  if (m_metaGroups.size() > 0) {
    collectGroups(groups, unfinishedGroups, result);

    // Do we need to loop over unfinished groups?
    while (unfinishedGroups.size() > 0) {
      String[] uGroups = unfinishedGroups.toArray(new String[unfinishedGroups.size()]);
      unfinishedGroups = Lists.newArrayList();
      collectGroups(uGroups, unfinishedGroups, result);
    }
  }

  //    Utils.dumpMap(result);
  return result;
}
 
源代码9 项目: pulsar   文件: ProxyWithAuthorizationNegTest.java
protected final void createAdminClient() throws Exception {
    Map<String, String> authParams = Maps.newHashMap();
    authParams.put("tlsCertFile", TLS_SUPERUSER_CLIENT_CERT_FILE_PATH);
    authParams.put("tlsKeyFile", TLS_SUPERUSER_CLIENT_KEY_FILE_PATH);

    admin = spy(PulsarAdmin.builder().serviceHttpUrl(brokerUrlTls.toString())
            .tlsTrustCertsFilePath(TLS_BROKER_TRUST_CERT_FILE_PATH).allowTlsInsecureConnection(true)
            .authentication(AuthenticationTls.class.getName(), authParams).build());
}
 
源代码10 项目: qaf   文件: TestRunner.java
@Override
public Collection<ITestNGMethod> getExcludedMethods() {
  Map<ITestNGMethod, ITestNGMethod> vResult = Maps.newHashMap();

  for (ITestNGMethod m : m_excludedMethods) {
    vResult.put(m, m);
  }

  return vResult.keySet();
}
 
源代码11 项目: pulsar   文件: PulsarFunctionsTest.java
protected Map<String, String> produceSchemaUpdateMessagesToInputTopic(String inputTopicName,
                                                                      int numMessages,
                                                                      Schema<Foo> schema) throws Exception {
    @Cleanup
    PulsarClient client = PulsarClient.builder()
            .serviceUrl(pulsarCluster.getPlainTextServiceUrl())
            .build();

    @Cleanup
    Producer<Foo> producer = client.newProducer(schema)
            .topic(inputTopicName)
            .create();

    LinkedHashMap<String, String> kvs = new LinkedHashMap<>();
    log.info("update start");
    for (int i = 0; i < numMessages; i++) {
        String key = "key-" + i;

        JdbcPostgresSinkTester.Foo obj = new JdbcPostgresSinkTester.Foo();
        obj.setField1("field1_insert_" + i);
        obj.setField2("field2_update_" + i);
        obj.setField3(i);
        String value = new String(schema.encode(obj));
        Map<String, String> properties = Maps.newHashMap();
        properties.put("ACTION", "UPDATE");

        kvs.put(key, value);
        kvs.put("ACTION", "UPDATE");
        producer.newMessage()
                .properties(properties)
                .key(key)
                .value(obj)
                .send();
    }
    log.info("update end");
    return kvs;
}
 
源代码12 项目: qaf   文件: Item.java
public static void main(String[] args) {
	Map<Object, Object> m = Maps.newHashMap();
	m.put("name", "a");
	m.put("uname", "a");

	m.put("id", 1);
	
  Item item = new Gson().fromJson(new Gson().toJson(m), Item.class);
  System.out.println(new Gson().toJson(item));
}
 
源代码13 项目: incubator-gobblin   文件: IntegrationJobTagSuite.java
/**
 * Create different jobs with different tags
 */
@Override
protected Map<String, Config> overrideJobConfigs(Config rawJobConfig) {
  Map<String, Config> jobConfigs = Maps.newHashMap();
  for(Map.Entry<String, String> assoc: JOB_TAG_ASSOCIATION.entrySet()) {
    Config newConfig = getConfigOverride(rawJobConfig, assoc.getKey(), assoc.getValue());
    jobConfigs.put(assoc.getKey(), newConfig);
  }
  return jobConfigs;
}
 
源代码14 项目: qaf   文件: CustomDataProvider.java
@DataProvider(name="dp-with-testngmethod-contex")
public Object[][] dataProviderForBDD(ITestNGMethod method, ITestContext contex){
	Map<Object, Object> m = Maps.newHashMap();
	m.put("method", method.getMethodName());
	m.put("contex", contex.getName());
	return new Object[][]{{m}};
}
 
源代码15 项目: qaf   文件: CustomDataProvider.java
@DataProvider(name="dp-for-filter")
public static Object[][] dataProviderToTestFilter(){
	Map<Object, Object> m = Maps.newHashMap();
	m.put("name", "a");
	m.put("uname", "a");

	m.put("id", 1);
	
	Map<Object, Object> m2 = Maps.newHashMap();
	m2.put("name", "b");
	m2.put("uname", "b");

	m2.put("id", 2);

	Map<Object, Object> m3 = Maps.newHashMap();
	m3.put("name", "c");
	m3.put("uname", "c");

	m3.put("id", 3);
	
	Map<Object, Object> m4 = Maps.newHashMap();
	m4.put("name", "d");
	m4.put("uname", "d");

	m4.put("id", 4);

	Map<Object, Object> m5 = Maps.newHashMap();
	m5.put("name", "e");
	m5.put("uname", "e");

	m5.put("id", 5);
	return new Object[][]{{m},{m2},{m3},{m4},{m5}};
}
 
源代码16 项目: pulsar   文件: KinesisSinkTest.java
@Test
public void testCredentialProvider() throws Exception {
    KinesisSink sink = new KinesisSink();

    final String accesKey = "ak";
    final String secretKey = "sk";
    Map<String, String> credentialParam = Maps.newHashMap();
    credentialParam.put(KinesisSink.ACCESS_KEY_NAME, accesKey);
    credentialParam.put(KinesisSink.SECRET_KEY_NAME, secretKey);
    String awsCredentialPluginParam = new Gson().toJson(credentialParam);
    AWSCredentialsProvider credentialProvider = sink.createCredentialProvider(null, awsCredentialPluginParam)
            .getCredentialProvider();
    Assert.assertEquals(credentialProvider.getCredentials().getAWSAccessKeyId(), accesKey);
    Assert.assertEquals(credentialProvider.getCredentials().getAWSSecretKey(), secretKey);

    credentialProvider = sink.createCredentialProvider(AwsCredentialProviderPluginImpl.class.getName(), "{}")
            .getCredentialProvider();
    Assert.assertNotNull(credentialProvider);
    Assert.assertEquals(credentialProvider.getCredentials().getAWSAccessKeyId(),
            AwsCredentialProviderPluginImpl.accessKey);
    Assert.assertEquals(credentialProvider.getCredentials().getAWSSecretKey(),
            AwsCredentialProviderPluginImpl.secretKey);
    Assert.assertEquals(((BasicSessionCredentials) credentialProvider.getCredentials()).getSessionToken(),
            AwsCredentialProviderPluginImpl.sessionToken);

    sink.close();
}
 
源代码17 项目: oxd   文件: UmaGetClaimsGatheringUrlTest.java
@Parameters({"host", "opHost", "paramRedirectUrl", "rsProtect"})
@Test
public void test_withCustomParameter(String host, String opHost, String paramRedirectUrl, String rsProtect) throws IOException {

    ClientInterface client = Tester.newClient(host);
    RegisterSiteResponse site = RegisterSiteTest.registerSite(client, opHost, paramRedirectUrl);

    RsProtectTest.protectResources(client, site, UmaFullTest.resourceList(rsProtect).getResources());

    final RsCheckAccessResponse checkAccess = RsCheckAccessTest.checkAccess(client, site, null);

    final RpGetClaimsGatheringUrlParams params = new RpGetClaimsGatheringUrlParams();
    params.setOxdId(site.getOxdId());
    params.setTicket(checkAccess.getTicket());
    params.setClaimsRedirectUri(paramRedirectUrl);

    Map<String, String> customParameterMap = Maps.newHashMap();
    customParameterMap.put("param1", "value1");
    customParameterMap.put("param2", "value2");
    params.setCustomParameters(customParameterMap);

    final RpGetClaimsGatheringUrlResponse response = client.umaRpGetClaimsGatheringUrl(Tester.getAuthorization(site), null, params);

    Map<String, String> parameters = CoreUtils.splitQuery(response.getUrl());

    assertTrue(StringUtils.isNotBlank(parameters.get("client_id")));
    assertTrue(StringUtils.isNotBlank(parameters.get("ticket")));
    assertTrue(StringUtils.isNotBlank(parameters.get("state")));
    assertTrue(StringUtils.isNotBlank(response.getState()));
    assertTrue(StringUtils.isNotBlank(parameters.get("param1")));
    assertTrue(StringUtils.isNotBlank(parameters.get("param2")));
    assertEquals(paramRedirectUrl, parameters.get("claims_redirect_uri"));
}
 
源代码18 项目: qaf   文件: CustomDataProvider.java
@DataProvider(name="dp-with-testngmethod")
public Object[][] dataProviderForBDD(ITestNGMethod method){
	Map<Object, Object> m = Maps.newHashMap();
	m.put("method", method.getMethodName());
	return new Object[][]{{m}};
}
 
源代码19 项目: qaf   文件: CustomDataProvider.java
@DataProvider(name="dp-with-method")
public Object[][] dataProviderForBDD(Method method){
	Map<Object, Object> m = Maps.newHashMap();
	m.put("method", method.getName());
	return new Object[][]{{m}};
}
 
源代码20 项目: pulsar   文件: UtilsTest.java
@Test
public void testJsonSerialization() throws Exception {

    final String[] keyNames = { "key1", "key2" };
    final String key1Value = "test1";
    final String key2Value = "test2";
    final byte[][] keyValues = { key1Value.getBytes(), key2Value.getBytes() };
    final String param = "param";
    final String algo = "algo";
    int batchSize = 10;
    int compressionMsgSize = 10;

    // serialize to json
    byte[] data = "payload".getBytes();
    Map<String, String> properties = Maps.newHashMap();
    properties.put("prop1", "value");
    Map<String, String> metadata1 = Maps.newHashMap();
    metadata1.put("version", "v1");
    metadata1.put("ckms", "cmks-1");
    Map<String, String> metadata2 = Maps.newHashMap();
    metadata2.put("version", "v2");
    metadata2.put("ckms", "cmks-2");
    Record<byte[]> recordCtx = createRecord(data, algo, keyNames, keyValues, param.getBytes(), metadata1, metadata2,
            batchSize, compressionMsgSize, properties, true);
    String json = Utils.serializeRecordToJson(recordCtx);

    // deserialize from json and assert
    KinesisMessageResponse kinesisJsonResponse = deSerializeRecordFromJson(json);
    assertEquals(data, getDecoder().decode(kinesisJsonResponse.getPayloadBase64()));
    EncryptionCtx encryptionCtxDeser = kinesisJsonResponse.getEncryptionCtx();
    assertEquals(key1Value.getBytes(),
            getDecoder().decode(encryptionCtxDeser.getKeysMapBase64().get(keyNames[0])));
    assertEquals(key2Value.getBytes(),
            getDecoder().decode(encryptionCtxDeser.getKeysMapBase64().get(keyNames[1])));
    assertEquals(param.getBytes(), getDecoder().decode(encryptionCtxDeser.getEncParamBase64()));
    assertEquals(algo, encryptionCtxDeser.getAlgorithm());
    assertEquals(metadata1, encryptionCtxDeser.getKeysMetadataMap().get(keyNames[0]));
    assertEquals(metadata2, encryptionCtxDeser.getKeysMetadataMap().get(keyNames[1]));
    assertEquals(properties, kinesisJsonResponse.getProperties());

}
 
 方法所在类
 同类方法