This project has retired. For details please refer to its Attic page.
AnnotationTest xref
View Javadoc
1   /*
2    * Copyright 2001-2009 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *      http://www.apache.org/licenses/LICENSE-2.0
8    * 
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.apache.juddi.v3.annotations;
16  
17  import java.util.Properties;
18  
19  import org.apache.juddi.v3.client.ClassUtil;
20  import org.junit.Assert;
21  import static org.junit.Assert.assertEquals;
22  import static org.junit.Assert.assertNotNull;
23  import static org.junit.Assert.assertNull;
24  import org.junit.Test;
25  import org.uddi.api_v3.BindingTemplate;
26  import org.uddi.api_v3.BusinessService;
27  import org.uddi.api_v3.CategoryBag;
28  import org.uddi.api_v3.KeyedReference;
29  
30  /**
31   * @author <a href="mailto:kstam@apache.org">Kurt T Stam</a>
32   */
33  public class AnnotationTest {
34  	
35  	 @Test
36  	 public void testParsingCategoryBagInput() {
37  		 AnnotationProcessor ap = new AnnotationProcessor();
38  		 String categoryBagStr="keyedReference=keyName=uddi-org:types:wsdl;keyValue=wsdlDeployment;tModelKey=uddi:uddi.org:categorization:types," +
39  		    "keyedReference=keyName=uddi-org:types:wsdl2;keyValue=wsdlDeployment2;tModelKey=uddi:uddi.org:categorization:types2";
40  		 CategoryBag categoryBag = ap.parseCategoryBag(categoryBagStr);
41  		 assertEquals(2,categoryBag.getKeyedReference().size());
42  		 KeyedReference keyedReference = categoryBag.getKeyedReference().get(0);
43  		 assertEquals("uddi-org:types:wsdl",keyedReference.getKeyName());
44  		 assertEquals("wsdlDeployment",keyedReference.getKeyValue());
45  		 assertEquals("uddi:uddi.org:categorization:types",keyedReference.getTModelKey());
46  		 KeyedReference keyedReference2 = categoryBag.getKeyedReference().get(1);
47  		 assertEquals("uddi-org:types:wsdl2",keyedReference2.getKeyName());
48  		 assertEquals("wsdlDeployment2",keyedReference2.getKeyValue());
49  		 assertEquals("uddi:uddi.org:categorization:types2",keyedReference2.getTModelKey());
50  	 }
51  	 
52  	 @Test
53       public void testReadingServiceBindingAnnotation() {
54  	     try {
55  	    	Class<?> classWithAnnotations = ClassUtil.forName(HelloWorldMockup.class.getName(), this.getClass());
56  	    	AnnotationProcessor ap = new AnnotationProcessor();
57  	    	BindingTemplate bindingTemplate = ap.parseServiceBinding(classWithAnnotations, "en", null, null);
58  	    	assertNotNull(bindingTemplate);
59  	    	//expecting references to two keys
60  	    	assertEquals(2, bindingTemplate.getTModelInstanceDetails().getTModelInstanceInfo().size());
61  	    	assertEquals("tModelKey1",bindingTemplate.getTModelInstanceDetails().getTModelInstanceInfo().get(0).getTModelKey());
62  	    	//expecting two KeyedReferences in the CategoryBag
63  	    	assertEquals(2, bindingTemplate.getCategoryBag().getKeyedReference().size());
64  	    	KeyedReference keyedReference2 = bindingTemplate.getCategoryBag().getKeyedReference().get(1);
65  			 assertEquals("uddi-org:types:wsdl2",keyedReference2.getKeyName());
66  			 assertEquals("wsdlDeployment2",keyedReference2.getKeyValue());
67  			 assertEquals("uddi:uddi.org:categorization:types2",keyedReference2.getTModelKey());
68  	     } catch (Exception e) {
69  	    	 //we should not have any issues reading the annotations
70  	         e.printStackTrace();
71  	         Assert.fail();
72  	     } 
73       }
74       
75       @Test
76       public void testReadingServiceAnnotation() {
77      	 try {
78  	    	 AnnotationProcessor ap = new AnnotationProcessor();
79  	    	 BusinessService service = ap.readServiceAnnotations(HelloWorldMockup.class.getName(),null);
80  	    	 assertNotNull(service);
81  	    	 assertEquals("HelloWorld",service.getName().get(0).getValue());
82  	    	 assertEquals(1,service.getBindingTemplates().getBindingTemplate().size());
83  	    	 assertNull(service.getCategoryBag());
84      	 } catch (Exception e) {
85  	    	 //we should not have any issues reading the annotations
86  	         e.printStackTrace();
87  	         Assert.fail();
88  	     } 
89       }
90       
91       @Test
92       public void testReadingServiceAnnotation2() {
93      	 try {
94  	    	 AnnotationProcessor ap = new AnnotationProcessor();
95  	    	 Properties properties = new Properties();
96  	    	 properties.put("serverName", "localhost");
97  	    	 properties.put("serverPort", "8080");
98  	    	 BusinessService service = ap.readServiceAnnotations(HelloWorldMockup2.class.getName(),properties);
99  	    	 assertNotNull(service);
100 	    	 assertEquals("HelloWorldMockup2",service.getName().get(0).getValue());
101 	    	 assertEquals(1,service.getBindingTemplates().getBindingTemplate().size());
102 	    	 BindingTemplate binding = service.getBindingTemplates().getBindingTemplate().get(0);
103 	    	 String endPoint = binding.getAccessPoint().getValue();
104 	    	 assertEquals("http://localhost:8080/subscription-listener/helloworld",endPoint);
105 	    	 String serviceKey = binding.getServiceKey();
106 	    	 assertEquals(service.getServiceKey(),serviceKey);
107 	    	 assertNull(service.getCategoryBag());
108     	 } catch (Exception e) {
109 	    	 //we should not have any issues reading the annotations
110 	         e.printStackTrace();
111 	         Assert.fail();
112 	     } 
113      }
114      
115   
116      
117    
118 	
119 }