Skip to content

Commit

Permalink
add test for AuthenticationProvider bundle names #3614
Browse files Browse the repository at this point in the history
  • Loading branch information
raprasad committed Jun 29, 2017
1 parent c9d7a64 commit f32940e
Showing 1 changed file with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package edu.harvard.iq.dataverse.authorization;

import edu.harvard.iq.dataverse.util.BundleUtil;
import java.util.AbstractMap.SimpleEntry;
import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author rmp553
*/
public class AuthenticationProviderTest {

public AuthenticationProviderTest() {
}

@BeforeClass
public static void setUpClass() {
}

@AfterClass
public static void tearDownClass() {
}

@Before
public void setUp() {
}

@After
public void tearDown() {
}

/**
* Create a map used to test known AuthenticationProvider ids
*
* @return
*/
private Map<String, String> getBundleTestMap(){
return Collections.unmodifiableMap(Stream.of(
new SimpleEntry<>("builtin", "authenticationProvider.name.builtin"),
new SimpleEntry<>("github", "authenticationProvider.name.github"),
new SimpleEntry<>("google", "authenticationProvider.name.google"),
new SimpleEntry<>("orcid", "authenticationProvider.name.orcid"),
new SimpleEntry<>("orcid-sandbox", "authenticationProvider.name.orcid-sandbox"),
new SimpleEntry<>("shib", "authenticationProvider.name.shib"))
.collect(Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue())));
}

/**
* Test of getFriendlyName method, of class AuthenticationProvider.
*/
@Test
public void testGetFriendlyName() {
System.out.println("getFriendlyName");

Map<String, String> bundleTestMap = this.getBundleTestMap();

// ------------------------------------------
// Test a null
// ------------------------------------------
String expResult = BundleUtil.getStringFromBundle("authenticationProvider.name.null");
assertEquals(expResult, AuthenticationProvider.getFriendlyName(null));

// ------------------------------------------
// Test an id w/o a bundle entry--should default to id
// ------------------------------------------
String idNotInBundle = "id-not-in-bundle-so-use-id";
String expResult2 = AuthenticationProvider.getFriendlyName(idNotInBundle);
assertEquals(expResult2, idNotInBundle);

// ------------------------------------------
// Iterate through the map and test each item
// ------------------------------------------
bundleTestMap.forEach((authProviderId, bundleName)->{
String expectedResult = BundleUtil.getStringFromBundle(bundleName);
assertEquals(expectedResult, AuthenticationProvider.getFriendlyName(authProviderId));
});

}



}

0 comments on commit f32940e

Please sign in to comment.