summaryrefslogtreecommitdiffstats
blob: 9e93b37f476fa6b2a56b3d62bdf14b9f938433da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Copyright (c) 2015 Tarun Gupta.
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

package com.isode.stroke.parser.payloadparsers;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.isode.stroke.elements.InBandRegistrationPayload;
import com.isode.stroke.elements.Form;
import com.isode.stroke.parser.payloadparsers.InBandRegistrationPayloadParser;
import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
import com.isode.stroke.eventloop.DummyEventLoop;

public class InBandRegistrationPayloadParserTest {

	public InBandRegistrationPayloadParserTest() {

	}

	@Test
	public void testParse() {
		DummyEventLoop eventLoop = new DummyEventLoop();
		PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
		assertNotNull(parser.parse("<query xmlns=\"jabber:iq:register\">" +
								"<registered/>" +
								"</query>"));

		InBandRegistrationPayload payload = (InBandRegistrationPayload)parser.getPayload();
		assertNotNull(payload);
		assertTrue(payload.isRegistered());
	}

	@Test
	public void testParse_Form() {
		DummyEventLoop eventLoop = new DummyEventLoop();
		PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
		assertNotNull(parser.parse("<query xmlns=\"jabber:iq:register\">" +
									"<instructions>Use the enclosed form to register.</instructions>" +
									"<x type=\"form\" xmlns=\"jabber:x:data\">" +
									"<title>Contest Registration</title>" +
									"<field type=\"hidden\" var=\"FORM_TYPE\">" +
									"<value>jabber:iq:register</value>" +
									"</field>" +
									"</x>" +
									"</query>"));

		InBandRegistrationPayload payload = (InBandRegistrationPayload)parser.getPayload();
		assertNotNull(payload);
		assertEquals("Use the enclosed form to register.", payload.getInstructions());

		Form form = payload.getForm();
		assertNotNull(form);
		assertEquals("Contest Registration", form.getTitle());
		assertEquals(Form.Type.FORM_TYPE, form.getType());
		assertEquals("jabber:iq:register", form.getFormType());

	}
}