private static GenericConversionService safeConversionService() { final GenericConversionService converter = new GenericConversionService(); converter.addConverter(Object.class, byte[].class, new SerializingConverter()); final DeserializingConverter byteConverter = new DeserializingConverter(); converter.addConverter(byte[].class, Object.class, (byte[] bytes) -> { try { return byteConverter.convert(bytes); } catch (SerializationFailedException e) { LOG.error("Could not extract attribute: {}", e.getMessage()); return null; } }); return converter; }
@Test public void serializeAndDeserializeString() { SerializingConverter toBytes = new SerializingConverter(); byte[] bytes = toBytes.convert("Testing"); DeserializingConverter fromBytes = new DeserializingConverter(); assertEquals("Testing", fromBytes.convert(bytes)); }
@Test public void nonSerializableObject() { SerializingConverter toBytes = new SerializingConverter(); try { toBytes.convert(new Object()); fail("Expected IllegalArgumentException"); } catch (SerializationFailedException e) { assertNotNull(e.getCause()); assertTrue(e.getCause() instanceof IllegalArgumentException); } }
@Test public void nonSerializableField() { SerializingConverter toBytes = new SerializingConverter(); try { toBytes.convert(new UnSerializable()); fail("Expected SerializationFailureException"); } catch (SerializationFailedException e) { assertNotNull(e.getCause()); assertTrue(e.getCause() instanceof NotSerializableException); } }
@Test @EnqueueRequests({ "getContributingUrls302", "getContributingUrls200", "getContributingUrls404", "getContributingUrls404", "getContributingUrls302", "getContributingUrls200", "getContributingUrls404" }) public void getContributingUrls() { // make sure we use GitHubHost and not the GitHubApiHost oauthConfig.setGitHubApiHost("donotuse"); oauthConfig.setGitHubHost(server.getServer().getHostName()); service = new MylynGitHubApi(oauthConfig); List<String> repositoryIds = Arrays.asList("spring-projects/has-md", "spring-projects/has-adoc", "spring-projects/no-contributor"); ContributingUrlsResponse urls = service.getContributingUrls(repositoryIds); assertThat(urls.getAsciidoc()).containsExactly( server.getServerUrl() + "/spring-projects/has-adoc/edit/master/CONTRIBUTING.adoc", server.getServerUrl() + "/spring-projects/no-contributor/new/master?filename=CONTRIBUTING.adoc"); assertThat(urls.getMarkdown()).containsOnly(server.getServerUrl() + "/spring-projects/has-md/edit/master/CONTRIBUTING.md"); SerializingConverter converter = new SerializingConverter(); // ensure we can serialize the result as it is placed in FlashMap assertThat(converter.convert(urls.getMarkdown())).isNotNull(); assertThat(converter.convert(urls.getAsciidoc())).isNotNull(); }
private GenericConversionService createConversionServiceWithBeanClassLoader() { GenericConversionService conversionService = new GenericConversionService(); conversionService.addConverter(Object.class, byte[].class, new SerializingConverter()); conversionService.addConverter(byte[].class, Object.class, new DeserializingConverter(this.classLoader)); return conversionService; }
private static GenericConversionService createDefaultConversionService() { GenericConversionService converter = new GenericConversionService(); converter.addConverter(Object.class, byte[].class, new SerializingConverter()); converter.addConverter(byte[].class, Object.class, new DeserializingConverter()); return converter; }
public JdkTarantoolSerializer() { this(new SerializingConverter(), new DeserializingConverter()); }
public JdkMongoSessionConverter(Duration maxInactiveInterval) { this(new SerializingConverter(), new DeserializingConverter(), maxInactiveInterval); }
@Test(expected = IllegalArgumentException.class) public void constructorNullDeserializer() { new JdkMongoSessionConverter(new SerializingConverter(), null, inactiveInterval); }