use of org.springframework.oxm.Unmarshaller in project spring-framework by spring-projects.
the class MarshallingHttpMessageConverterTests method readWithTypeMismatchException.
@Test(expected = TypeMismatchException.class)
public void readWithTypeMismatchException() throws Exception {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(new byte[0]);
Marshaller marshaller = mock(Marshaller.class);
Unmarshaller unmarshaller = mock(Unmarshaller.class);
given(unmarshaller.unmarshal(isA(StreamSource.class))).willReturn(Integer.valueOf(3));
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller, unmarshaller);
converter.read(String.class, inputMessage);
}
use of org.springframework.oxm.Unmarshaller in project spring-framework by spring-projects.
the class MarshallingHttpMessageConverterTests method readWithMarshallingFailureException.
@Test
public void readWithMarshallingFailureException() throws Exception {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(new byte[0]);
UnmarshallingFailureException ex = new UnmarshallingFailureException("forced");
Unmarshaller unmarshaller = mock(Unmarshaller.class);
given(unmarshaller.unmarshal(isA(StreamSource.class))).willThrow(ex);
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter();
converter.setUnmarshaller(unmarshaller);
try {
converter.read(Object.class, inputMessage);
fail("HttpMessageNotReadableException should be thrown");
} catch (HttpMessageNotReadableException e) {
assertTrue("Invalid exception hierarchy", e.getCause() == ex);
}
}
use of org.springframework.oxm.Unmarshaller in project spring-framework by spring-projects.
the class MarshallingHttpMessageConverterTests method read.
@Test
public void read() throws Exception {
String body = "<root>Hello World</root>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
Unmarshaller unmarshaller = mock(Unmarshaller.class);
given(unmarshaller.unmarshal(isA(StreamSource.class))).willReturn(body);
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter();
converter.setUnmarshaller(unmarshaller);
String result = (String) converter.read(Object.class, inputMessage);
assertEquals("Invalid result", body, result);
}
use of org.springframework.oxm.Unmarshaller in project uPortal by Jasig.
the class JaxbPortalDataHandlerServiceTest method testImportJarArchive.
@Test
public void testImportJarArchive() throws Exception {
final Unmarshaller unmarshaller = mock(Unmarshaller.class);
final List<IDataImporter<? extends Object>> importers = setupAllImporters(new MockDataImporterSetup() {
@Override
public void setup(IPortalDataType dataType, IDataImporter<? extends Object> dataImporter) {
when(dataImporter.getUnmarshaller()).thenReturn(unmarshaller);
}
});
this.dataImportExportService.setDataImporters(importers);
final Resource archiveResource = new ClassPathResource("/org/apereo/portal/io/xml/import_archive.jar");
final IPortalDataHandlerService.BatchImportOptions options = new IPortalDataHandlerService.BatchImportOptions();
options.setLogDirectoryParent(tempFolder.newFolder("jarArchiveImport"));
this.dataImportExportService.importDataArchive(archiveResource, options);
verify(unmarshaller, times(16)).unmarshal(any(Source.class));
}
use of org.springframework.oxm.Unmarshaller in project uPortal by Jasig.
the class JaxbPortalDataHandlerServiceTest method testImportZipArchive.
@Test
public void testImportZipArchive() throws Exception {
final Unmarshaller unmarshaller = mock(Unmarshaller.class);
final List<IDataImporter<? extends Object>> importers = setupAllImporters(new MockDataImporterSetup() {
@Override
public void setup(IPortalDataType dataType, IDataImporter<? extends Object> dataImporter) {
when(dataImporter.getUnmarshaller()).thenReturn(unmarshaller);
}
});
this.dataImportExportService.setDataImporters(importers);
final Resource archiveResource = new ClassPathResource("/org/apereo/portal/io/xml/import_archive.zip");
final IPortalDataHandlerService.BatchImportOptions options = new IPortalDataHandlerService.BatchImportOptions();
options.setLogDirectoryParent(tempFolder.newFolder("zipArchiveImport"));
this.dataImportExportService.importDataArchive(archiveResource, options);
verify(unmarshaller, times(16)).unmarshal(any(Source.class));
}
Aggregations