use of opengrok.auth.plugin.util.WebHooks in project OpenGrok by OpenGrok.
the class ConfigurationTest method testEncodeDecode.
@Test
void testEncodeDecode() {
// Create an exception listener to detect errors while encoding and
// decoding
final LinkedList<Exception> exceptions = new LinkedList<>();
ExceptionListener listener = exceptions::addLast;
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLEncoder enc = new XMLEncoder(out);
enc.setExceptionListener(listener);
Configuration configuration1 = new Configuration();
configuration1.setInterval(500);
configuration1.setSearchTimeout(1000);
configuration1.setConnectTimeout(42);
configuration1.setCountLimit(10);
configuration1.setServers(new ArrayList<>(List.of(new LdapServer("http://server.com"))));
WebHooks webHooks = new WebHooks();
WebHook hook = new WebHook();
hook.setContent("foo");
hook.setURI("http://localhost:8080/source/api/v1/messages");
webHooks.setFail(hook);
configuration1.setWebHooks(webHooks);
enc.writeObject(configuration1);
enc.close();
// verify that the write didn't fail
if (!exceptions.isEmpty()) {
throw new AssertionError("Got " + exceptions.size() + " exception(s)", exceptions.getFirst());
}
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
XMLDecoder dec = new XMLDecoder(in, null, listener);
Configuration configuration2 = (Configuration) dec.readObject();
assertNotNull(configuration2);
assertEquals(configuration1.getXMLRepresentationAsString(), configuration2.getXMLRepresentationAsString());
dec.close();
// verify that the read didn't fail
if (!exceptions.isEmpty()) {
throw new AssertionError("Got " + exceptions.size() + " exception(s)", exceptions.getFirst());
}
}
Aggregations