Search in sources :

Example 1 with ExternalUser

use of org.apereo.portal.io.xml.user.ExternalUser in project uPortal by Jasig.

the class JaxbPortalDataHandlerServiceTest method testUpgradeThenImport.

@Test
public void testUpgradeThenImport() throws Exception {
    final ClassPathResource importDataResource = new ClassPathResource("/org/apereo/portal/io/xml/user/test_3-2.user.xml");
    when(resourceLoader.getResource("classpath:/org/apereo/portal/io/xml/user/test_3-2.user.xml")).thenReturn(importDataResource);
    final ClassPathResource xslResource = new ClassPathResource("/org/apereo/portal/io/xml/user/upgrade-user_3-2.xsl");
    final IDataUpgrader xsltDataUpgrader = createXsltDataUpgrader(xslResource, UserPortalDataType.IMPORT_32_DATA_KEY);
    dataImportExportService.setDataUpgraders(Arrays.asList(xsltDataUpgrader));
    final Jaxb2Marshaller userJaxb2Marshaller = new Jaxb2Marshaller();
    userJaxb2Marshaller.setContextPath("org.apereo.portal.io.xml.user");
    userJaxb2Marshaller.afterPropertiesSet();
    final IDataImporter<ExternalUser> userDataImporter = mock(IDataImporter.class);
    when(userDataImporter.getImportDataKeys()).thenReturn(Collections.singleton(UserPortalDataType.IMPORT_40_DATA_KEY));
    when(userDataImporter.getUnmarshaller()).thenReturn(userJaxb2Marshaller);
    Collection<IDataImporter<?>> dataImporters = new LinkedList<IDataImporter<?>>();
    dataImporters.add(userDataImporter);
    dataImportExportService.setDataImporters(dataImporters);
    final Resource resource = resourceLoader.getResource("classpath:/org/apereo/portal/io/xml/user/test_3-2.user.xml");
    dataImportExportService.importData(resource);
    final ArgumentCaptor<ExternalUser> userArgumentCaptor = ArgumentCaptor.forClass(ExternalUser.class);
    verify(userDataImporter).importData(userArgumentCaptor.capture());
    final ExternalUser externalUser = userArgumentCaptor.getValue();
    assertNotNull(externalUser);
    assertEquals("student", externalUser.getUsername());
    assertEquals("defaultTemplateUser", externalUser.getDefaultUser());
    assertEquals("(MD5)mhmjKvf2F3gPizS9DrA+CsFmqj74oTSb", externalUser.getPassword());
    assertNull(externalUser.getLastPasswordChange());
}
Also used : ExternalUser(org.apereo.portal.io.xml.user.ExternalUser) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) Jaxb2Marshaller(org.springframework.oxm.jaxb.Jaxb2Marshaller) ClassPathResource(org.springframework.core.io.ClassPathResource) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

LinkedList (java.util.LinkedList)1 ExternalUser (org.apereo.portal.io.xml.user.ExternalUser)1 Test (org.junit.Test)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Resource (org.springframework.core.io.Resource)1 Jaxb2Marshaller (org.springframework.oxm.jaxb.Jaxb2Marshaller)1