org.apache.commons.collections4.map.HashedMap Java Examples

The following examples show how to use org.apache.commons.collections4.map.HashedMap. 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: ExternalSSOEnabledIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
private String genrateToken(){
    Map<String, Object> claims = new HashedMap<String, Object>();
    claims.put("jti","c7df0339-3847-450b-a925-628ef237953a");
    claims.put("sub","b6d62259-217b-4e96-8f49-e00c366e4fed");
    claims.put("scope","size = 5");
    claims.put("client_id", "edgecli");
    claims.put("azp","edgecli");
    claims.put("grant_type" ,"password");
    claims.put("user_id","b6d62259-217b-4e96-8f49-e00c366e4fed");
    claims.put( "origin","usergrid");
    claims.put("user_name","AyeshaSSOUser");
    claims.put("email", "[email protected]");
    claims.put( "rev_sig","dfe5d0d3");
    claims.put("iat","1466550862");
    claims.put("exp", System.currentTimeMillis() + 1000);
    claims.put("iss", "https://login.apigee.com/oauth/token");
    claims.put( "zid","uaa");
    claims.put( "aud"," size = 6");
    claims.put("grant_type","password");

    String jwt = Jwts.builder().setClaims(claims).signWith(SignatureAlgorithm.RS256, privateKey).compact();
    return jwt;

}
 
Example #2
Source File: ApigeeSSO2ProviderIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> createClaims(final String username, final String email, long exp ) {
    return new HashedMap<String, Object>() {{
            put("jti","c7df0339-3847-450b-a925-628ef237953a");
            put("sub","b6d62259-217b-4e96-8f49-e00c366e4fed");
            put("scope","size = 5");
            put("client_id", "dummy1");
            put("azp","dummy2");
            put("grant_type" ,"password");
            put("user_id","b6d62259-217b-4e96-8f49-e00c366e4fed");
            put("origin","usergrid");
            put("user_name", username );
            put("email", email);
            put("rev_sig","dfe5d0d3");
            put("exp", exp);
            put("iat", System.currentTimeMillis());
            put("iss", "https://jwt.example.com/token");
            put("zid","uaa");
            put("aud"," size = 6");
        }};
}
 
Example #3
Source File: Collections4.java    From Learn-Java-12-Programming with MIT License 6 votes vote down vote up
private static void iterableMap(){
    System.out.println("\niterableMap():");

    IterableMap<Integer, String> map =
            new HashedMap<>(Map.of(1, "one", 2, "two"));
    MapIterator it = map.mapIterator();
    while (it.hasNext()) {
        Object key = it.next();
        Object value = it.getValue();
        System.out.print(key + ", " + value + ", "); //prints: 2, two, 1, one,
        if(((Integer)key) == 2){
            it.setValue("three");
        }
    }
    System.out.println("\n" + map); //prints: {2=three, 1=one}
}
 
Example #4
Source File: ClockProP.java    From cache2k-benchmark with Apache License 2.0 6 votes vote down vote up
public ClockProP(int size, ClockPro.Tuning tuning) {
  this.size = size;
  this.clockMap = new HashedMap<Integer, CacheMetaData>();
  this.coldTarget = (int)(this.size * tuning.getColdRatio());
  this.hotTarget = this.size - this.coldTarget;
  this.coldSize = 0;
  this.hotSize = 0;
  this.testSize = 0;
  this.handHot = null;
  this.handCold = null;
  this.handTest = null;
  this.lru = null;
  this.demotionSize = 0;

  this.totalCount = 0;
  this.totalSize = 0;

  this.testAccess = 0;
  this.demoteHit = 0;
  this.coldHit = 0;
  this.hotHit = 0;
}
 
Example #5
Source File: ClockPro.java    From cache2k-benchmark with Apache License 2.0 6 votes vote down vote up
public ClockPro(int size, Tuning tuning) {
  this.size = size;
  this.clockMap = new HashedMap<>();
  this.coldTarget = (int)(this.size * tuning.getColdRatio());
  this.hotTarget = this.size - this.coldTarget;
  this.coldSize = 0;
  this.hotSize = 0;
  this.testSize = 0;
  this.handHot = null;
  this.handCold = null;
  this.handTest = null;
  this.lru = null;

  this.totalSize = 0;
  this.totalCount = 0;
  this.coldAccess = 0;
  this.coldHitTracked = 0;
  this.testExpire = 0;
  this.coldHit = 0;
  this.hotHit = 0;
}
 
Example #6
Source File: RxDocumentServiceRequestTest.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
@Test(groups = { "unit" }, dataProvider = "documentUrl")
public void addPreferHeader(String documentUrlWithId, String documentUrlWithName, OperationType operationType) {
    RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType,
                                                                       ResourceType.Document,
                                                                       documentUrlWithId,
                                                                       new HashedMap<String, String>());

    request.addPreferHeader("preferHeaderName1", "preferHeaderValue1");
    assertThat(request.getHeaders().size()).isEqualTo(1);
    assertThat(request.getHeaders().get(HttpConstants.HttpHeaders.PREFER))
            .isEqualTo("preferHeaderName1=preferHeaderValue1");

    request.addPreferHeader("preferHeaderName2", "preferHeaderValue2");
    assertThat(request.getHeaders().size()).isEqualTo(1);
    assertThat(request.getHeaders().get(HttpConstants.HttpHeaders.PREFER))
            .isEqualTo("preferHeaderName1=preferHeaderValue1;" + "preferHeaderName2=preferHeaderValue2");
}
 
Example #7
Source File: HashedMapTest.java    From JQF with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Fuzz
public void queryStringTest(@From(ArbitraryLengthStringGenerator.class) @Size(max=80) String queryString) {
    Assume.assumeTrue(queryString.length() > 0);
    String[] params = queryString.split("&");
    Map<String, String> map = new HashedMap<>();
    for (String param : params) {
        int eqIdx = param.indexOf('=');
        String key, value;
        if (eqIdx == -1 || eqIdx == 0) {
            continue;
        } else {
            key = param.substring(0, eqIdx);
            value = eqIdx < param.length()-1 ? param.substring(eqIdx+1) : "";
        }
        map.put(key, value);
    }
}
 
Example #8
Source File: GbGradebookData.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
private Map<String, Object> serializeSettings() {
	final Map<String, Object> result = new HashedMap();

	result.put("isCourseLetterGradeDisplayed", this.settings.isCourseLetterGradeDisplayed());
	result.put("isCourseAverageDisplayed", this.settings.isCourseAverageDisplayed());
	result.put("isCoursePointsDisplayed", this.settings.isCoursePointsDisplayed());
	result.put("isPointsGradeEntry", GradingType.valueOf(this.settings.getGradeType()).equals(GradingType.POINTS));
	result.put("isPercentageGradeEntry", GradingType.valueOf(this.settings.getGradeType()).equals(GradingType.PERCENTAGE));
	result.put("isCategoriesEnabled", GbCategoryType.valueOf(this.settings.getCategoryType()) != GbCategoryType.NO_CATEGORY);
	result.put("isCategoryTypeWeighted", GbCategoryType.valueOf(this.settings.getCategoryType()) == GbCategoryType.WEIGHTED_CATEGORY);
	result.put("isStudentOrderedByLastName", this.uiSettings.getNameSortOrder() == GbStudentNameSortOrder.LAST_NAME);
	result.put("isStudentOrderedByFirstName", this.uiSettings.getNameSortOrder() == GbStudentNameSortOrder.FIRST_NAME);
	result.put("isGroupedByCategory", this.uiSettings.isGroupedByCategory());
	result.put("isCourseGradeReleased", this.settings.isCourseGradeDisplayed());
	result.put("showPoints", this.uiSettings.getShowPoints());
	result.put("isUserAbleToEditAssessments", isUserAbleToEditAssessments());
	result.put("isStudentNumberVisible", this.isStudentNumberVisible);
	result.put("isSectionsVisible", this.isSectionsVisible && ServerConfigurationService.getBoolean("gradebookng.showSections", true));
	result.put("isSetUngradedToZeroEnabled", ServerConfigurationService.getBoolean(SAK_PROP_SHOW_SET_ZERO_SCORE, SAK_PROP_SHOW_SET_ZERO_SCORE_DEFAULT));
	result.put("isShowDisplayCourseGradeToStudentEnabled", ServerConfigurationService.getBoolean(SAK_PROP_SHOW_COURSE_GRADE_STUDENT, SAK_PROP_SHOW_COURSE_GRADE_STUDENT_DEFAULT));

	return result;
}
 
Example #9
Source File: GbGradebookData.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
private Map<String, Object> serializeSettings() {
	final Map<String, Object> result = new HashedMap();

	result.put("isCourseLetterGradeDisplayed", this.settings.isCourseLetterGradeDisplayed());
	result.put("isCourseAverageDisplayed", this.settings.isCourseAverageDisplayed());
	result.put("isCoursePointsDisplayed", this.settings.isCoursePointsDisplayed());
	result.put("isPointsGradeEntry", GradingType.valueOf(this.settings.getGradeType()).equals(GradingType.POINTS));
	result.put("isPercentageGradeEntry", GradingType.valueOf(this.settings.getGradeType()).equals(GradingType.PERCENTAGE));
	result.put("isCategoriesEnabled", GbCategoryType.valueOf(this.settings.getCategoryType()) != GbCategoryType.NO_CATEGORY);
	result.put("isCategoryTypeWeighted", GbCategoryType.valueOf(this.settings.getCategoryType()) == GbCategoryType.WEIGHTED_CATEGORY);
	result.put("isStudentOrderedByLastName", this.uiSettings.getNameSortOrder() == GbStudentNameSortOrder.LAST_NAME);
	result.put("isStudentOrderedByFirstName", this.uiSettings.getNameSortOrder() == GbStudentNameSortOrder.FIRST_NAME);
	result.put("isGroupedByCategory", this.uiSettings.isGroupedByCategory());
	result.put("isCourseGradeReleased", this.settings.isCourseGradeDisplayed());
	result.put("showPoints", this.uiSettings.getShowPoints());
	result.put("isUserAbleToEditAssessments", isUserAbleToEditAssessments());
	result.put("isStudentNumberVisible", this.isStudentNumberVisible);
	result.put("isSectionsVisible", this.isSectionsVisible && ServerConfigurationService.getBoolean("gradebookng.showSections", true));
	result.put("isSetUngradedToZeroEnabled", ServerConfigurationService.getBoolean(SAK_PROP_SHOW_SET_ZERO_SCORE, SAK_PROP_SHOW_SET_ZERO_SCORE_DEFAULT));
	result.put("isShowDisplayCourseGradeToStudentEnabled", ServerConfigurationService.getBoolean(SAK_PROP_SHOW_COURSE_GRADE_STUDENT, SAK_PROP_SHOW_COURSE_GRADE_STUDENT_DEFAULT));

	return result;
}
 
Example #10
Source File: HiveTestDataGenerator.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private HiveTestDataGenerator(Map<String, String> config) throws Exception {
  String root = getTempDir("");
  this.dbDir = root + "metastore_db";

  // metastore helper will create wh in a subdirectory
  String whDirBase = root + "warehouse";
  new File(whDirBase).mkdirs();

  Configuration conf = MetastoreConf.newMetastoreConf();

  // Force creating schemas. Note that JDO creates schema on demand
  MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.SCHEMA_VERIFICATION, false);
  MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.AUTO_CREATE_ALL, true);
  // Disable direct SQL as it might cause not all schemas to be created
  MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.TRY_DIRECT_SQL, false);
  MetastoreConf.setVar(conf, MetastoreConf.ConfVars.WAREHOUSE, whDirBase);
  MetastoreConf.setVar(conf, MetastoreConf.ConfVars.CONNECT_URL_KEY, String.format("jdbc:derby:;databaseName=%s;create=true", dbDir));
  HiveConf.setVar(conf, ConfVars.DYNAMICPARTITIONINGMODE, "nonstrict");
  if (config != null) {
    config.forEach((k, v) -> conf.set(k, v));
  }

  this.port = MetaStoreTestUtils.startMetaStoreWithRetry(HadoopThriftAuthBridge.getBridge(), conf);
  this.whDir = MetastoreConf.getVar(conf, MetastoreConf.ConfVars.WAREHOUSE);

  this.config = new HashedMap<>();
  this.config.put(FileSystem.FS_DEFAULT_NAME_KEY, "file:///");
}
 
Example #11
Source File: ClockProA.java    From cache2k-benchmark with Apache License 2.0 5 votes vote down vote up
public ClockProA(int size, ClockPro.Tuning tuning) {
  this.size = size;
  this.clockMap = new HashedMap<>();
  this.coldTarget = (int)(this.size * tuning.getColdRatio());
  this.hotTarget = this.size - this.coldTarget;
  this.coldSize = 0;
  this.hotSize = 0;
  this.testSize = 0;
  this.handHot = null;
  this.handCold = null;
  this.handTest = null;
  this.lru = null;
}
 
Example #12
Source File: ClockLIRS.java    From cache2k-benchmark with Apache License 2.0 5 votes vote down vote up
public ClockLIRS(int size, ClockPro.Tuning tuning) {
  this.size = size;
  this.clockMap = new HashedMap<>();
  this.coldTarget = (int)(this.size * tuning.getColdRatio());
  this.hotTarget = this.size - this.coldTarget;
  this.coldSize = 0;
  this.hotSize = 0;
  this.testSize = 0;
  this.handHot = null;
  this.handCold = null;
  this.handTest = null;
  this.lru = null;
}
 
Example #13
Source File: OUsersCommonUtils.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private static Map<String, String> getLocalizedStrings(OrienteerWebApplication app, String key, List<String> tags) {
    Map<String, String> localized = new HashedMap<>(3);
    for (String tag : tags) {
        localized.put(tag, getString(app, key, Locale.forLanguageTag(tag)));
    }
    return localized;
}
 
Example #14
Source File: IterateThroughHashMapTest.java    From java_in_examples with Apache License 2.0 5 votes vote down vote up
@TearDown(Level.Iteration)
public void tearDown() {
    map = new HashMap<>(size);
    iterableMap = new HashedMap<>(size);
    mutableMap = UnifiedMap.newMap(size);
    for (int i = 0; i < size; i++) {
        map.put(i, i);
        mutableMap.put(i, i);
        iterableMap.put(i, i);
    }
}
 
Example #15
Source File: RxDocumentServiceRequestTest.java    From azure-cosmosdb-java with MIT License 5 votes vote down vote up
/**
 * This will cover sanity for most of the combination of different source with various
 * operation.
 * @param resourceUrl Resource Url
 * @param resourceType Resource Type
 * @param operationType Operation type
 */
@Test(groups = { "unit" }, dataProvider = "resourceUrlWithOperationType")
public void createDifferentResourceRequestWithDiffOperation(String resourceUrl, ResourceType resourceType,
        OperationType operationType) {
    RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType, resourceType, resourceUrl,
            new HashedMap<String, String>(), AuthorizationTokenType.PrimaryMasterKey);
    assertThat(resourceUrl.contains(request.getResourceAddress())).isTrue();
    assertThat(resourceUrl.contains(request.getResourceId())).isTrue();
    assertThat(request.getResourceType()).isEqualTo(resourceType);
    assertThat(request.getOperationType()).isEqualTo(operationType);
    assertThat(request.getHeaders()).isNotNull();
}
 
Example #16
Source File: EventLoggingListener.java    From inception with Apache License 2.0 5 votes vote down vote up
public EventLoggingListener(
        @Autowired EventRepository aRepo,
        @Lazy @Autowired(required = false) List<EventLoggingAdapter<?>> aAdapters)
{
    repo = aRepo;
    adapterProxy = aAdapters;
    adapterCache = new HashedMap<>();
    
    queue = new ConcurrentLinkedDeque<>();
    
    scheduler = Executors.newSingleThreadScheduledExecutor();
    scheduler.scheduleAtFixedRate(() -> flush(), 1, 1, TimeUnit.SECONDS);
}
 
Example #17
Source File: PolyvUtil.java    From roncoo-education with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static PolyvSignResult getSignForH5(PolyvSign bo, String useid, String secretkey) {
    // 根据时间戳、vid、密钥生成sign值
    String ts = String.valueOf(System.currentTimeMillis());
    // 获取播放token
    Map<String, Object> map = new HashedMap<>();
    map.put("userId", useid);
    map.put("videoId", bo.getVid());
    map.put("ts", ts);
    map.put("viewerIp", "127.0.0.1");
    map.put("viewerName", bo.getUserNo());
    map.put("extraParams", "HTML5");
    map.put("viewerId", bo.getUserNo());
    logger.info("保利威视,map:map={}", map);
    String concated = "extraParams" + map.get("extraParams") + "ts" + map.get("ts") + "userId" + map.get("userId") + "videoId" + map.get("videoId") + "viewerId" + map.get("viewerId") + "viewerIp" + map.get("viewerIp") + "viewerName" + map.get("viewerName");
    map.put("sign", MD5Util.MD5(secretkey + concated + secretkey).toUpperCase());
    String result = post(SystemUtil.POLYV_GETTOKEN, map);
    logger.info("保利威视,获取token接口:result={}", result);
    Map<String, Object> resultMap = JSONUtil.parseObject(result, HashMap.class);
    int code = Integer.valueOf(resultMap.get("code").toString()).intValue();
    if (code != 200) {
        return null;
    }
    Map<String, Object> data = (Map<String, Object>) resultMap.get("data");
    if (data == null || data.isEmpty()) {
        return null;
    }
    PolyvSignResult dto = new PolyvSignResult();
    dto.setSign(MD5Util.MD5(secretkey + bo.getVid() + ts));
    dto.setTs(ts);
    dto.setToken(data.get("token").toString());
    return dto;
}
 
Example #18
Source File: AnalysisManager.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public AnalysisManager(Program program, AnalysisRecipe recipe) {
	this.recipe = recipe;
	taskManager = GTaskManagerFactory.getTaskManager(program);
	triggerMap = new HashedMap<AnalyzerType, List<AnalyzerScheduler>>();
	initialize();
}
 
Example #19
Source File: RxDocumentServiceRequestTest.java    From azure-cosmosdb-java with MIT License 4 votes vote down vote up
@Test(groups = { "unit" }, dataProvider = "documentUrl")
public void isValidAddress(String documentUrlWithId, String documentUrlWithName, OperationType operationType) {
    RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType,
                                                                       ResourceType.Document,
                                                                       documentUrlWithId,
                                                                       new HashedMap<String, String>());

    assertThat(request.isValidAddress(ResourceType.Database)).isTrue();
    assertThat(request.isValidAddress(ResourceType.DocumentCollection)).isTrue();
    assertThat(request.isValidAddress(ResourceType.Document)).isTrue();
    assertThat(request.isValidAddress(ResourceType.Unknown)).isTrue();
    assertThat(request.isValidAddress(ResourceType.User)).isFalse();
    assertThat(request.isValidAddress(ResourceType.Trigger)).isFalse();
    assertThat(request.isValidAddress(ResourceType.Offer)).isFalse();
    assertThat(request.isValidAddress(ResourceType.Permission)).isFalse();
    assertThat(request.isValidAddress(ResourceType.Attachment)).isFalse();
    assertThat(request.isValidAddress(ResourceType.StoredProcedure)).isFalse();
    assertThat(request.isValidAddress(ResourceType.Conflict)).isFalse();
    assertThat(request.isValidAddress(ResourceType.PartitionKeyRange)).isFalse();

    request = RxDocumentServiceRequest.create(operationType,
                                              ResourceType.Document,
                                              documentUrlWithName,
                                              new HashedMap<String, String>());

    assertThat(request.isValidAddress(ResourceType.Document)).isTrue();
    assertThat(request.isValidAddress(ResourceType.Unknown)).isTrue();
    String collectionFullName = "/dbs/testDB/colls/testColl/";
    request = RxDocumentServiceRequest.create(operationType, ResourceType.DocumentCollection, collectionFullName,
            new HashedMap<String, String>());

    assertThat(request.isValidAddress(ResourceType.DocumentCollection)).isTrue();
    assertThat(request.isValidAddress(ResourceType.Unknown)).isTrue();

    String databaseFullName = "/dbs/testDB";
    request = RxDocumentServiceRequest.create(operationType,
                                              ResourceType.Database,
                                              databaseFullName,
                                              new HashedMap<String, String>());

    assertThat(request.isValidAddress(ResourceType.Database)).isTrue();
    assertThat(request.isValidAddress(ResourceType.Unknown)).isTrue();

    String permissionFullName = "/dbs/testDB/users/testUser/permissions/testPermission";
    request = RxDocumentServiceRequest.create(operationType,
                                              ResourceType.Permission,
                                              permissionFullName,
                                              new HashedMap<String, String>());

    assertThat(request.isValidAddress(ResourceType.Permission)).isTrue();
    assertThat(request.isValidAddress(ResourceType.Unknown)).isTrue();

    String triggerFullName = "/dbs/testDB/colls/testUser/triggers/testTrigger";
    request = RxDocumentServiceRequest.create(operationType,
                                              ResourceType.Trigger,
                                              triggerFullName,
                                              new HashedMap<String, String>());

    assertThat(request.isValidAddress(ResourceType.Trigger)).isTrue();
    assertThat(request.isValidAddress(ResourceType.Unknown)).isTrue();

    String attachmentFullName = "/dbs/testDB/colls/testUser/docs/testDoc/attachments/testAttachment";
    request = RxDocumentServiceRequest.create(operationType,
                                              ResourceType.Attachment,
                                              attachmentFullName,
                                              new HashedMap<String, String>());

    assertThat(request.isValidAddress(ResourceType.Attachment)).isTrue();
    assertThat(request.isValidAddress(ResourceType.Unknown)).isTrue();
}
 
Example #20
Source File: RxDocumentServiceRequestTest.java    From azure-cosmosdb-java with MIT License 4 votes vote down vote up
/**
 * This test case will cover various create method through resource url with name in detail for document resource.
 * @param documentUrlWithId Document url with id
 * @param documentUrlWithName Document url with name
 * @param operationType Operation type
 */
@Test(groups = { "unit" }, dataProvider = "documentUrl")
public void createWithResourceNameURL(String documentUrlWithId, String documentUrlWithName,
        OperationType operationType) {

    RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType,
                                                                       ResourceType.Document,
                                                                       documentUrlWithName,
                                                                       new HashedMap<String, String>(), AuthorizationTokenType.PrimaryMasterKey);

    assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.PrimaryMasterKey);
    assertThat(request.getResourceAddress())
            .isEqualTo(StringUtils.removeEnd(StringUtils.removeStart(documentUrlWithName, Paths.ROOT), Paths.ROOT));
    assertThat(request.getResourceId()).isNull();

    Document document = getDocumentDefinition();
    Observable<byte[]> inputStream = Observable.just(document.toJson().getBytes(StandardCharsets.UTF_8));
    request = RxDocumentServiceRequest.create(operationType,
                                              ResourceType.Document,
                                              documentUrlWithName,
                                              inputStream,
                                              new HashedMap<String, String>(),
                                              AuthorizationTokenType.SecondaryMasterKey);

    assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.SecondaryMasterKey);
    assertThat(request.getResourceAddress())
            .isEqualTo(StringUtils.removeEnd(StringUtils.removeStart(documentUrlWithName, Paths.ROOT), Paths.ROOT));
    assertThat(request.getResourceId()).isNull();
    assertThat(request.getContentObservable()).isEqualTo(inputStream);

    // Creating one request without giving AuthorizationTokenType , it should take
    // PrimaryMasterKey by default
    request = RxDocumentServiceRequest.create(operationType,
                                              ResourceType.Document,
                                              documentUrlWithName,
                                              new HashedMap<String, String>());

    assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.PrimaryMasterKey);
    assertThat(request.getResourceAddress())
            .isEqualTo(StringUtils.removeEnd(StringUtils.removeStart(documentUrlWithName, Paths.ROOT), Paths.ROOT));
    assertThat(request.getResourceId()).isNull();
}
 
Example #21
Source File: RxDocumentServiceRequestTest.java    From azure-cosmosdb-java with MIT License 4 votes vote down vote up
/**
 * This test case will cover various create methods through resource url with Id in detail for document resource.
 * @param documentUrlWithId Document url with id
 * @param documentUrlWithName Document url with name
 * @param operationType Operation type
 */
@Test(groups = { "unit" }, dataProvider = "documentUrl")
public void createWithResourceIdURL(String documentUrlWithId, String documentUrlWithName,
        OperationType operationType) {

    RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType,
                                                                       ResourceType.Document,
                                                                       documentUrlWithId,
                                                                       new HashedMap<String, String>(), AuthorizationTokenType.PrimaryMasterKey);

    assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.PrimaryMasterKey);
    assertThat(request.getResourceAddress()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA==");
    assertThat(request.getResourceId()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA==");

    request = RxDocumentServiceRequest.create(operationType, "IXYFAOHEBPMBAAAAAAAAAA==", ResourceType.Document,
            new HashedMap<String, String>(), AuthorizationTokenType.PrimaryReadonlyMasterKey);
    assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.PrimaryReadonlyMasterKey);
    assertThat(request.getResourceAddress()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA==");
    assertThat(request.getResourceId()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA==");

    Document document = getDocumentDefinition();
    request = RxDocumentServiceRequest.create(operationType, document, ResourceType.Document, documentUrlWithId,
            new HashedMap<String, String>(), AuthorizationTokenType.Invalid);
    assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.Invalid);
    assertThat(request.getResourceAddress()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA==");
    assertThat(request.getResourceId()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA==");
    assertThat(request.getContent()).isEqualTo(document.toJson().getBytes(StandardCharsets.UTF_8));

    Observable<byte[]> inputStream = Observable.just(document.toJson().getBytes(StandardCharsets.UTF_8));
    request = RxDocumentServiceRequest.create(operationType, ResourceType.Document, documentUrlWithId, inputStream,
            new HashedMap<String, String>(), AuthorizationTokenType.SecondaryMasterKey);
    assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.SecondaryMasterKey);
    assertThat(request.getResourceAddress()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA==");
    assertThat(request.getResourceId()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA==");
    assertThat(request.getContentObservable()).isEqualTo(inputStream);

    // Creating one request without giving AuthorizationTokenType , it should take
    // PrimaryMasterKey by default
    request = RxDocumentServiceRequest.create(operationType,
                                              ResourceType.Document,
                                              documentUrlWithId,
                                              new HashedMap<String, String>());

    assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.PrimaryMasterKey);
    assertThat(request.getResourceAddress()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA==");
    assertThat(request.getResourceId()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA==");

}