001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.client; 019 020import static org.junit.Assert.assertEquals; 021import static org.junit.Assert.assertTrue; 022 023import java.util.HashMap; 024import java.util.Map; 025 026import org.junit.Test; 027 028/** 029 * @author bbpennel 030 */ 031public class HeaderHelpersTest { 032 033 @Test 034 public void testFormatQualityValues() { 035 final Map<String, Double> qualityMap = new HashMap<>(); 036 qualityMap.put("md5", 1.0); 037 038 assertEquals("md5;q=1.0", HeaderHelpers.formatQualityValues(qualityMap)); 039 } 040 041 @Test 042 public void testFormatQualityValuesNoQValue() { 043 final Map<String, Double> qualityMap = new HashMap<>(); 044 qualityMap.put("md5", null); 045 046 assertEquals("md5", HeaderHelpers.formatQualityValues(qualityMap)); 047 } 048 049 @Test 050 public void testFormatQualityValuesMultipleWithDifferentQ() { 051 final Map<String, String> qualityMap = new HashMap<>(); 052 qualityMap.put("md5", "1.0"); 053 qualityMap.put("sha-512", "0.4"); 054 055 final String result = HeaderHelpers.formatQualityValues(qualityMap); 056 assertTrue(result.contains("md5;q=1.0")); 057 assertTrue(result.contains("sha-512;q=0.4")); 058 } 059 060 @Test 061 public void testFormatQualityValuesMultipleSameQ() { 062 final Map<String, Double> qualityMap = new HashMap<>(); 063 qualityMap.put("md5", 1.0); 064 qualityMap.put("sha", 1.0); 065 qualityMap.put("sha-512", 0.4); 066 067 final String result = HeaderHelpers.formatQualityValues(qualityMap); 068 // can't guarantee order 069 assertTrue(result.contains("md5,sha;q=1.0") || result.contains("sha,md5;q=1.0")); 070 assertTrue(result.contains("sha-512;q=0.4")); 071 } 072 073 @Test 074 public void testFormatQualityValuesMultipleQ() { 075 final Map<String, Double> qualityMap = new HashMap<>(); 076 qualityMap.put("md5", null); 077 qualityMap.put("sha", null); 078 079 final String result = HeaderHelpers.formatQualityValues(qualityMap); 080 // can't guarantee order 081 assertTrue(result.contains("md5,sha") || result.contains("sha,md5")); 082 } 083}