Search in sources :

Example 6 with IdentityProviderNameEntity

use of org.orcid.persistence.jpa.entities.IdentityProviderNameEntity in project ORCID-Source by ORCID.

the class IdentityProviderManagerTest method testCreateEntityFromXml.

@Test
public void testCreateEntityFromXml() throws SAXException, IOException, ParserConfigurationException {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    dbFactory.setNamespaceAware(true);
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(getClass().getResourceAsStream("example_idp.xml"));
    Element idpElement = doc.getDocumentElement();
    IdentityProviderEntity result = identityProviderManager.createEntityFromXml(idpElement);
    assertNotNull(result);
    assertEquals("https://idp.example.ch/idp/shibboleth", result.getProviderid());
    List<IdentityProviderNameEntity> names = result.getNames();
    assertNotNull(names);
    assertEquals(4, names.size());
    Map<String, IdentityProviderNameEntity> mapByLang = names.stream().collect(Collectors.toMap(IdentityProviderNameEntity::getLang, Function.identity()));
    assertEquals("Universität Example Display", mapByLang.get("de").getDisplayName());
    assertEquals("University of Example Display", mapByLang.get("en").getDisplayName());
    assertEquals("Université de Example Display", mapByLang.get("fr").getDisplayName());
    assertEquals("Università di Example Display", mapByLang.get("it").getDisplayName());
    assertEquals("Universität Example Display", result.getDisplayName());
    assertEquals("support@example.ch", result.getSupportEmail());
    assertNull(result.getAdminEmail());
    assertEquals("technical@example.ch", result.getTechEmail());
}
Also used : IdentityProviderNameEntity(org.orcid.persistence.jpa.entities.IdentityProviderNameEntity) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) IdentityProviderEntity(org.orcid.persistence.jpa.entities.IdentityProviderEntity) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

IdentityProviderNameEntity (org.orcid.persistence.jpa.entities.IdentityProviderNameEntity)6 IdentityProviderEntity (org.orcid.persistence.jpa.entities.IdentityProviderEntity)4 Element (org.w3c.dom.Element)4 Document (org.w3c.dom.Document)3 ArrayList (java.util.ArrayList)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 XPath (javax.xml.xpath.XPath)2 XPathExpression (javax.xml.xpath.XPathExpression)2 Test (org.junit.Test)2 NodeList (org.w3c.dom.NodeList)2 Client (com.sun.jersey.api.client.Client)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 WebResource (com.sun.jersey.api.client.WebResource)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Pattern (java.util.regex.Pattern)1