You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juddi.apache.org by al...@apache.org on 2013/10/28 13:28:22 UTC

svn commit: r1536327 - /juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/mapping/WADL2UDDITest.java

Author: alexoree
Date: Mon Oct 28 12:28:22 2013
New Revision: 1536327

URL: http://svn.apache.org/r1536327
Log:
JUDDI-674 added more unit tests, pulling a wadl from the cxf project

Modified:
    juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/mapping/WADL2UDDITest.java

Modified: juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/mapping/WADL2UDDITest.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/mapping/WADL2UDDITest.java?rev=1536327&r1=1536326&r2=1536327&view=diff
==============================================================================
--- juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/mapping/WADL2UDDITest.java (original)
+++ juddi/trunk/juddi-client/src/test/java/org/apache/juddi/v3/client/mapping/WADL2UDDITest.java Mon Oct 28 12:28:22 2013
@@ -16,10 +16,12 @@
 package org.apache.juddi.v3.client.mapping;
 
 import java.io.File;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.List;
 import java.util.Properties;
-import java.util.Set;
+import java.util.logging.Logger;
 import javax.xml.namespace.QName;
 import org.apache.juddi.jaxb.PrintUDDI;
 import org.apache.juddi.v3.client.config.UDDIClerk;
@@ -36,18 +38,19 @@ import org.uddi.api_v3.TModel;
  */
 public class WADL2UDDITest {
 
+    static final Logger log = Logger.getLogger(WADL2UDDITest.class.getCanonicalName());
     static PrintUDDI<TModel> pTModel = new PrintUDDI<TModel>();
     static Properties properties = new Properties();
-    
-  
+
     /**
      * tests loading a wadl from a file
-     * @throws Exception 
+     *
+     * @throws Exception
      */
     @Test
     public void Test1() throws Exception {
-        
-        
+        log.info("Test1 read from file");
+
         Application app = WADL2UDDI.ParseWadl(new File("src/test/resources/wadl/cxf.wadl"));
         Assert.assertNotNull(app);
         Assert.assertNotNull(app);
@@ -69,7 +72,7 @@ public class WADL2UDDITest {
         WADL2UDDI wadl2UDDI = new WADL2UDDI(null, new URLLocalizerDefaultImpl(), properties);
 
         Assert.assertNotNull(wadl2UDDI);
-        
+
         BusinessService businessServices = wadl2UDDI.createBusinessService(new QName("CXF.Sample.WADL.namespace", "Servicename"), app);
 
         Assert.assertNotNull(businessServices);
@@ -78,9 +81,9 @@ public class WADL2UDDITest {
         Assert.assertNotNull(businessServices.getBindingTemplates().getBindingTemplate().get(0));
         Assert.assertNotNull(businessServices.getBindingTemplates().getBindingTemplate().get(0).getAccessPoint());
         Assert.assertNotNull(businessServices.getBindingTemplates().getBindingTemplate().get(0).getAccessPoint().getValue());
-        
-        
-        
+
+
+
 
         PrintUDDI<BusinessService> servicePrinter = new PrintUDDI<BusinessService>();
 
@@ -89,4 +92,85 @@ public class WADL2UDDITest {
 
 
     }
+
+    private static boolean IsReachable(String url) {
+        System.out.println("Testing connectivity to " + url);
+        try {
+            //make a URL to a known source
+            URL url2 = new URL(url);
+
+            //open a connection to that source
+            HttpURLConnection urlConnect = (HttpURLConnection) url2.openConnection();
+
+            //trying to retrieve data from the source. If there
+            //is no connection, this line will fail
+            Object objData = urlConnect.getContent();
+            urlConnect.disconnect();
+
+        } catch (Exception e) {
+            System.out.println("Connectivity failed " + e.getMessage());
+            return false;
+        }
+        System.out.println("Connectivity passed");
+        return true;
+
+    }
+
+    /**
+     * normally, this test will work correctly if and only if you're connected
+     * to the big bad internet. if you happen to be offline, this test will
+     * fail.
+     */
+    @Test
+    public void Test2readFromURL() throws MalformedURLException, Exception {
+        log.info("Test2 read from URL");
+        boolean b = IsReachable("http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/resources/wadl/bookstoreImportResource.wadl");
+        if (!b) {
+            System.out.println("Skipping test for a remote WADL due to connectivity problems");
+        }
+
+
+        org.junit.Assume.assumeTrue(b);
+
+
+        Application app = WADL2UDDI.ParseWadl(new URL("http://svn.apache.org/repos/asf/cxf/trunk/systests/jaxrs/src/test/resources/wadl/bookstoreImportResource.wadl"));
+        Assert.assertNotNull(app);
+        Assert.assertNotNull(app);
+        List<URL> urls = WADL2UDDI.GetBaseAddresses(app);
+        URL url = urls.get(0);
+        String domain = url.getHost();
+        PrintUDDI<TModel> tmodelPrinter = new PrintUDDI<TModel>();
+        TModel keygen = UDDIClerk.createKeyGenator("uddi:" + domain + ":keygenerator", domain, "en");
+        //save the keygen
+        SaveTModel stm = new SaveTModel();
+        stm.getTModel().add(keygen);
+        System.out.println(tmodelPrinter.print(keygen));
+
+        properties.put("keyDomain", domain);
+        properties.put("businessName", domain);
+        properties.put("serverName", url.getHost());
+        properties.put("serverPort", url.getPort());
+        //wsdlURL = wsdlDefinition.getDocumentBaseURI();
+        WADL2UDDI wadl2UDDI = new WADL2UDDI(null, new URLLocalizerDefaultImpl(), properties);
+
+        Assert.assertNotNull(wadl2UDDI);
+
+        BusinessService businessServices = wadl2UDDI.createBusinessService(new QName("CXF.Sample.WADL.namespace", "Servicename"), app);
+
+        Assert.assertNotNull(businessServices);
+        Assert.assertNotNull(businessServices.getBindingTemplates());
+        Assert.assertNotNull(businessServices.getName().get(0));
+        Assert.assertNotNull(businessServices.getBindingTemplates().getBindingTemplate().get(0));
+        Assert.assertNotNull(businessServices.getBindingTemplates().getBindingTemplate().get(0).getAccessPoint());
+        Assert.assertNotNull(businessServices.getBindingTemplates().getBindingTemplate().get(0).getAccessPoint().getValue());
+
+
+
+
+        PrintUDDI<BusinessService> servicePrinter = new PrintUDDI<BusinessService>();
+
+        System.out.println(servicePrinter.print(businessServices));
+
+
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@juddi.apache.org
For additional commands, e-mail: commits-help@juddi.apache.org