This project has retired. For details please refer to its
Attic page.
GetPublisherDetailTest xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.apache.juddi.api_v3;
16
17 import java.io.StringReader;
18 import java.io.StringWriter;
19 import java.text.SimpleDateFormat;
20 import java.util.ArrayList;
21 import java.util.Date;
22 import java.util.List;
23 import javax.xml.bind.JAXB;
24
25 import javax.xml.bind.JAXBContext;
26 import javax.xml.bind.JAXBElement;
27 import javax.xml.bind.JAXBException;
28 import javax.xml.bind.Marshaller;
29 import javax.xml.bind.Unmarshaller;
30 import javax.xml.namespace.QName;
31 import javax.xml.transform.stream.StreamSource;
32
33 import static junit.framework.Assert.fail;
34 import static junit.framework.Assert.assertEquals;
35 import static junit.framework.Assert.assertTrue;
36 import org.junit.Ignore;
37
38 import org.junit.Test;
39 import org.uddi.api_v3.AuthToken;
40 import org.uddi.api_v3.Contact;
41 import org.uddi.api_v3.ObjectFactory;
42 import org.uddi.api_v3.PersonName;
43 import org.uddi.repl_v3.CommunicationGraph;
44 import org.uddi.repl_v3.Operator;
45 import org.uddi.repl_v3.OperatorStatusType;
46 import org.uddi.repl_v3.ReplicationConfiguration;
47
48
49
50
51
52
53 public class GetPublisherDetailTest {
54
55 private final static String EXPECTED_XML_FRAGMENT1 = "<fragment xmlns:ns2=\"http://www.w3.org/2000/09/xmldsig#\" xmlns:ns3=\"urn:uddi-org:api_v3\">\n"
56 +" <ns3:authInfo>AuthInfo String</ns3:authInfo>\n"
57 +"</fragment>";
58 private final static String EXPECTED_XML_FRAGMENT2 = "<fragment xmlns:ns3=\"urn:uddi-org:api_v3\" xmlns:ns2=\"http://www.w3.org/2000/09/xmldsig#\">\n"
59 +" <ns3:authInfo>AuthInfo String</ns3:authInfo>\n"
60 +"</fragment>";
61 private final static String UTF8_WORD = "メインページ";
62
63 private final static String EXPECTED_UTF8_XML_FRAGMENT1 = "<fragment xmlns:ns2=\"http://www.w3.org/2000/09/xmldsig#\" xmlns:ns3=\"urn:uddi-org:api_v3\">\n"
64 +" <ns3:authInfo>" + UTF8_WORD + "</ns3:authInfo>\n"
65 +"</fragment>";
66 private final static String EXPECTED_UTF8_XML_FRAGMENT2 = "<fragment xmlns:ns3=\"urn:uddi-org:api_v3\" xmlns:ns2=\"http://www.w3.org/2000/09/xmldsig#\">\n"
67 +" <ns3:authInfo>" + UTF8_WORD + "</ns3:authInfo>\n"
68 +"</fragment>";
69
70
71
72 @Test
73 public void marshall()
74 {
75 try {
76 JAXBContext jaxbContext=JAXBContext.newInstance("org.apache.juddi.api_v3");
77 Marshaller marshaller = jaxbContext.createMarshaller();
78 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
79 marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
80 marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
81 ObjectFactory factory = new ObjectFactory();
82 GetPublisherDetail getPublisherDetail = new GetPublisherDetail();
83 getPublisherDetail.authInfo = "some token";
84
85 StringWriter writer = new StringWriter();
86 JAXBElement<GetPublisherDetail> element = new JAXBElement<GetPublisherDetail>(new QName("","fragment"),GetPublisherDetail.class,getPublisherDetail);
87 marshaller.marshal(element,writer);
88 String actualXml=writer.toString();
89 System.out.println(actualXml);
90
91
92 } catch (JAXBException jaxbe) {
93 jaxbe.printStackTrace();
94
95 fail("No exception should be thrown");
96 }
97 }
98
99 @Test
100 public void marshallReplicationMessage() throws Exception{
101 ReplicationConfiguration r = new ReplicationConfiguration();
102 r.setCommunicationGraph(new CommunicationGraph());
103 Operator op = new Operator();
104 op.setOperatorNodeID("a node");
105 op.setSoapReplicationURL("http://localhost/services/replication");
106
107 op.getContact().add(new Contact());
108 op.getContact().get(0).getPersonName().add(new PersonName("Unknown", null));
109 op.setOperatorStatus(OperatorStatusType.NORMAL);
110
111 r.getOperator().add(op);
112 r.getCommunicationGraph().getNode().add("a node");
113 r.getCommunicationGraph().getControlledMessage().add("*");
114 r.setSerialNumber(0);
115 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddkkmmZ");
116 r.setTimeOfConfigurationUpdate(sdf.format(new Date()));
117 r.setRegistryContact(new org.uddi.repl_v3.ReplicationConfiguration.RegistryContact());
118 r.getRegistryContact().setContact(new Contact());
119 r.getRegistryContact().getContact().getPersonName().add(new PersonName("Unknown", null));
120 JAXB.marshal(r, System.out);
121 }
122 @Test
123 @Ignore
124 public void testWithCXFMarhsaller() throws Exception{
125 org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(null, this, null, this);
126 }
127
128
129 }