1 | package negotiator.repository;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 |
|
---|
5 | import java.io.StringReader;
|
---|
6 | import java.io.StringWriter;
|
---|
7 |
|
---|
8 | import javax.xml.bind.JAXBContext;
|
---|
9 | import javax.xml.bind.JAXBException;
|
---|
10 | import javax.xml.bind.Marshaller;
|
---|
11 | import javax.xml.bind.Unmarshaller;
|
---|
12 |
|
---|
13 | import org.junit.Test;
|
---|
14 |
|
---|
15 | import genius.core.boaframework.AcceptanceStrategy;
|
---|
16 | import genius.core.repository.boa.BoaRepItem;
|
---|
17 |
|
---|
18 | public class AcceptanceConditionRepItemTest {
|
---|
19 |
|
---|
20 | @Test
|
---|
21 | public void testDeserialize() throws JAXBException {
|
---|
22 | JAXBContext jaxbContext = JAXBContext.newInstance(BoaRepItem.class);
|
---|
23 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
---|
24 |
|
---|
25 | String TEXT = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
---|
26 | + "<boa classpath=\"class.path\"/>";
|
---|
27 | StringReader reader = new StringReader(TEXT);
|
---|
28 |
|
---|
29 | @SuppressWarnings("unchecked")
|
---|
30 | BoaRepItem<AcceptanceStrategy> element = (BoaRepItem<AcceptanceStrategy>) unmarshaller.unmarshal(reader);
|
---|
31 |
|
---|
32 | System.out.println(element);
|
---|
33 | assertEquals("class.path", element.getClassPath());
|
---|
34 | // The path does not exist, so this will throw.
|
---|
35 | // assertEquals("name", element.getName());
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Test
|
---|
39 | public void testSerialize() throws JAXBException {
|
---|
40 | BoaRepItem<AcceptanceStrategy> ac = new BoaRepItem<>("class.path");
|
---|
41 | StringWriter writer = new StringWriter();
|
---|
42 |
|
---|
43 | JAXBContext context = JAXBContext.newInstance(BoaRepItem.class);
|
---|
44 | Marshaller m = context.createMarshaller();
|
---|
45 | m.marshal(ac, writer);
|
---|
46 | System.out.println(writer.toString());
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Test
|
---|
50 | public void testDeserializeBoa() throws JAXBException {
|
---|
51 | JAXBContext jaxbContext = JAXBContext.newInstance(BoaRepItem.class);
|
---|
52 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
---|
53 |
|
---|
54 | String TEXT = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><boa classpath=\"class.path\"/>";
|
---|
55 | StringReader reader = new StringReader(TEXT);
|
---|
56 |
|
---|
57 | BoaRepItem<AcceptanceStrategy> element = (BoaRepItem<AcceptanceStrategy>) unmarshaller.unmarshal(reader);
|
---|
58 |
|
---|
59 | System.out.println(element);
|
---|
60 | assertEquals("class.path", element.getClassPath());
|
---|
61 | // The path does not exist, so this will throw.
|
---|
62 | // assertEquals("name", element.getName());
|
---|
63 | }
|
---|
64 |
|
---|
65 | }
|
---|