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 2014/11/13 04:22:56 UTC

juddi git commit: JUDDI-890 fixed an issue with juddi-gui from the saveConfiguration code change. Adding test cases for configuration loading

Repository: juddi
Updated Branches:
  refs/heads/master 36661e157 -> 197e1d1d6


JUDDI-890 fixed an issue with juddi-gui from the saveConfiguration code change. Adding test cases for configuration loading


Project: http://git-wip-us.apache.org/repos/asf/juddi/repo
Commit: http://git-wip-us.apache.org/repos/asf/juddi/commit/197e1d1d
Tree: http://git-wip-us.apache.org/repos/asf/juddi/tree/197e1d1d
Diff: http://git-wip-us.apache.org/repos/asf/juddi/diff/197e1d1d

Branch: refs/heads/master
Commit: 197e1d1d6ba0780e395dd5ce4915276c39becbbb
Parents: 36661e1
Author: alexoree <al...@apache.org>
Authored: Wed Nov 12 22:22:25 2014 -0500
Committer: alexoree <al...@apache.org>
Committed: Wed Nov 12 22:22:25 2014 -0500

----------------------------------------------------------------------
 .../juddi/v3/client/config/ClientConfig.java    |  26 +-
 .../v3/client/config/MisconfigurationTest.java  |  44 ++++
 .../v3/client/config/SaveConfigurationTest.java | 244 +++++++++++++++++++
 juddi-gui/src/main/webapp/ajax/settings.jsp     |   2 +-
 4 files changed, 314 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/juddi/blob/197e1d1d/juddi-client/src/main/java/org/apache/juddi/v3/client/config/ClientConfig.java
----------------------------------------------------------------------
diff --git a/juddi-client/src/main/java/org/apache/juddi/v3/client/config/ClientConfig.java b/juddi-client/src/main/java/org/apache/juddi/v3/client/config/ClientConfig.java
index e842772..2bb4a3d 100644
--- a/juddi-client/src/main/java/org/apache/juddi/v3/client/config/ClientConfig.java
+++ b/juddi-client/src/main/java/org/apache/juddi/v3/client/config/ClientConfig.java
@@ -86,7 +86,9 @@ public class ClientConfig {
         /**
          * Attempts to save any changes made to the configuration back to disk
          * Revised in 3.2.1 to reconstruct the file from the in memory data
-         * structure, enable you to programmatically add nodes
+         * structure, enable you to programmatically add nodes.
+         * <br><br>
+         * For previous functionality see, saveConfigRaw()
          *
          * @throws ConfigurationException
          */
@@ -127,7 +129,29 @@ public class ClientConfig {
 
                 saveConfiguration.save(configurationFile);
         }
+        
+        /**
+         * Use this method to attempt to save the jUDDI configuration file after
+         * you've modified it using the Apache Commons Configuration settings.
+         * This is especially useful if you've constructed a user interface for manipulating
+         * the configuration like a properties sheet and is used by the juddi-gui (web ui)
+         * @since 3.2.1
+         * @throws org.apache.commons.configuration.ConfigurationException
+         */
+        public void saveConfigRaw() throws ConfigurationException{
+         XMLConfiguration saveConfiguration = new XMLConfiguration(configurationFile);
+            Configuration cc = new CompositeConfiguration(saveConfiguration);
+            Iterator<String> keys = this.config.getKeys();
+            while (keys.hasNext()){
+                String key = keys.next();
+                if (key.startsWith("client") || key.startsWith("config"))
+                {
+                    cc.setProperty(key, config.getProperty(key));
+                }
+            }
+            saveConfiguration.save();
 
+        }
         protected void readConfig(Properties properties) throws ConfigurationException {
                 uddiNodes = readNodeConfig(config, properties);
                 uddiClerks = readClerkConfig(config, uddiNodes);

http://git-wip-us.apache.org/repos/asf/juddi/blob/197e1d1d/juddi-client/src/test/java/org/apache/juddi/v3/client/config/MisconfigurationTest.java
----------------------------------------------------------------------
diff --git a/juddi-client/src/test/java/org/apache/juddi/v3/client/config/MisconfigurationTest.java b/juddi-client/src/test/java/org/apache/juddi/v3/client/config/MisconfigurationTest.java
new file mode 100644
index 0000000..cf8013d
--- /dev/null
+++ b/juddi-client/src/test/java/org/apache/juddi/v3/client/config/MisconfigurationTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.juddi.v3.client.config;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.juddi.v3.client.transport.Transport;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author Alex O'Ree
+ */
+public class MisconfigurationTest {
+
+        @Test//(expected = ConfigurationException.class)
+        public void TestMissingClerk() throws ConfigurationException{
+                UDDIClient client = new UDDIClient("META-INF/uddi.xml");
+                UDDIClerk clerk = client.getClerk("missingClerk");
+                Assert.assertNull("this should be null", clerk);
+        }
+        
+        @Test(expected = ConfigurationException.class)
+        public void TestMissingTransportClass() throws ConfigurationException{
+                UDDIClient client = new UDDIClient("META-INF/configtests.xml");
+                UDDIClerk clerk = client.getClerk("missingTransport");
+                Transport transport = client.getTransport("missingTransport");
+                Assert.fail("this should have thrown an exception");
+        }
+}

http://git-wip-us.apache.org/repos/asf/juddi/blob/197e1d1d/juddi-client/src/test/java/org/apache/juddi/v3/client/config/SaveConfigurationTest.java
----------------------------------------------------------------------
diff --git a/juddi-client/src/test/java/org/apache/juddi/v3/client/config/SaveConfigurationTest.java b/juddi-client/src/test/java/org/apache/juddi/v3/client/config/SaveConfigurationTest.java
new file mode 100644
index 0000000..ffe5aa4
--- /dev/null
+++ b/juddi-client/src/test/java/org/apache/juddi/v3/client/config/SaveConfigurationTest.java
@@ -0,0 +1,244 @@
+/*
+ * Copyright 2014 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.juddi.v3.client.config;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import org.apache.juddi.api_v3.Node;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test cases for JUDDI-890 when saving a config with node/properties defined,
+ * the output is concat'd
+ *
+ * @author Alex O'Ree
+ */
+public class SaveConfigurationTest {
+
+        @BeforeClass
+        public static void setUpClass() {
+        }
+
+        @AfterClass
+        public static void tearDownClass() {
+        }
+
+        @Before
+        public void setUp() {
+        }
+
+        @After
+        public void tearDown() {
+        }
+
+        static Node getCloudInstance() {
+                Node n = new Node();
+                n.setName(UUID.randomUUID().toString() + "juddicloud");
+                n.setCustodyTransferUrl("http://uddi-jbossoverlord.rhcloud.com/services/custody-transfer");
+                n.setDescription("juddicloud");
+                n.setProxyTransport("org.apache.juddi.v3.client.transport.JAXWSTransport");
+                n.setInquiryUrl("http://uddi-jbossoverlord.rhcloud.com/services/inquiry");
+                n.setJuddiApiUrl("http://uddi-jbossoverlord.rhcloud.com/services/juddi-api");
+                n.setPublishUrl("http://uddi-jbossoverlord.rhcloud.com/services/publish");
+                n.setSecurityUrl("http://uddi-jbossoverlord.rhcloud.com/services/security");
+                n.setSubscriptionListenerUrl("http://uddi-jbossoverlord.rhcloud.com/services/subscription-listener");
+                n.setSubscriptionUrl("http://uddi-jbossoverlord.rhcloud.com/services/subscription");
+                n.setReplicationUrl("uddi-jbossoverlord.rhcloud.com/services/replication");
+                return n;
+        }
+
+        @Test
+        public void openAndSave() throws Exception {
+                System.out.println("openAndSave");
+                try {
+                        UDDIClient client = new UDDIClient("META-INF/uddi.xml");
+                        List<Node> before = client.getClientConfig().getUDDINodeList();
+                        client.getClientConfig().saveConfig();
+                        client = null;
+
+                        client = new UDDIClient("META-INF/uddi.xml");
+                        List<Node> after = client.getClientConfig().getUDDINodeList();
+
+                        compareNodes(before, after);
+                } catch (Exception ex) {
+                        ex.printStackTrace();
+                        Assert.fail(ex.getMessage());
+                }
+        }
+
+        @Test
+        public void openAddNodeAndSave() throws Exception {
+                System.out.println("openAddNodeAndSave");
+                UDDIClient client = new UDDIClient("META-INF/uddi.xml");
+                List<Node> before = client.getClientConfig().getUDDINodeList();
+                client.getClientConfig().addUDDINode(new UDDINode(getCloudInstance()));
+                client.getClientConfig().saveConfig();
+                List<Node> afterAdding = client.getClientConfig().getUDDINodeList();
+                client = null;
+
+                Assert.assertTrue(before.size() != afterAdding.size());
+
+                client = new UDDIClient("META-INF/uddi.xml");
+                List<Node> after = client.getClientConfig().getUDDINodeList();
+
+                compareNodes(afterAdding, after);
+        }
+
+        private void compareNodes(List<Node> before, List<Node> after) {
+
+                if (before == null && after == null) {
+                        return;
+                }
+                if (before != null && after == null) {
+                        Assert.fail("after is null, read error?");
+                }
+                if (before == null && after != null) {
+                        Assert.fail("unexpected before is null and after isn't, read error?");
+                }
+
+                Assert.assertTrue(before.size() == after.size());
+
+                //this is because saving/opening the config file does not preserve order
+                Map<String, Node> aftermap = new HashMap<String, Node>();
+
+                for (int i = 0; i < after.size(); i++) {
+                        aftermap.put(after.get(i).getName(), after.get(i));
+                }
+ 
+                for (int i = 0; i < before.size(); i++) {
+                        compare(before.get(i), aftermap.get(before.get(i).getName()));
+                }
+        }
+
+        private void compare(Node get, Node get0) {
+                Assert.assertNotNull(get);
+                Assert.assertNotNull(get0);
+
+                Assert.assertNotNull(get0.getClientName());
+                Assert.assertNotNull(get.getClientName());
+
+                Assert.assertNotNull(get0.getName());
+                Assert.assertNotNull(get.getName());
+
+                if (!get.getName().equals(get0.getName())) {
+                        Assert.fail("getName: " + get.getName() + " <> " + get0.getName());
+                }
+
+                if (!get.getClientName().equals(get0.getClientName())) {
+                        Assert.fail("getClientName");
+                }
+
+                if (get.getCustodyTransferUrl() == null && get0.getCustodyTransferUrl() != null) {
+                        Assert.fail("getCustodyTransferUrl");
+                }
+
+                if (get.getCustodyTransferUrl() != null && !get.getCustodyTransferUrl().equals(get0.getCustodyTransferUrl())) {
+                        Assert.fail("getCustodyTransferUrl");
+                }
+
+                if (get.getDescription() == null && get0.getDescription() != null) {
+                        Assert.fail("getDescription");
+                }
+
+                if (get.getDescription() != null && !get.getDescription().equals(get0.getDescription())) {
+                        Assert.fail("getDescription");
+                }
+
+                if (get.getFactoryInitial() == null && get0.getFactoryInitial() != null) {
+                        Assert.fail("getFactoryInitial");
+                }
+                if (get.getFactoryInitial() != null && !get.getFactoryInitial().equals(get0.getFactoryInitial())) {
+                        Assert.fail("getFactoryInitial");
+                }
+                if (get.getFactoryNamingProvider() == null && get0.getFactoryNamingProvider() != null) {
+                        Assert.fail("getFactoryNamingProvider");
+                }
+                if (get.getFactoryNamingProvider() != null && !get.getFactoryNamingProvider().equals(get0.getFactoryNamingProvider())) {
+                        Assert.fail("getFactoryNamingProvider");
+                }
+                if (get.getFactoryURLPkgs() == null && get0.getFactoryURLPkgs() != null) {
+                        Assert.fail("getFactoryURLPkgs");
+                }
+                if (get.getFactoryURLPkgs() != null && !get.getFactoryURLPkgs().equals(get0.getFactoryURLPkgs())) {
+                        Assert.fail("getFactoryURLPkgs");
+                }
+
+                if (get.getInquiryUrl() != null && !get.getInquiryUrl().equals(get0.getInquiryUrl())) {
+                        Assert.fail("getInquiryUrl");
+                }
+
+                if (get.getJuddiApiUrl() == null && get0.getJuddiApiUrl() != null) {
+                        Assert.fail("getJuddiApiUrl");
+                }
+
+                if (get.getJuddiApiUrl() != null && !get.getJuddiApiUrl().equals(get0.getJuddiApiUrl())) {
+                        Assert.fail("getJuddiApiUrl");
+                }
+
+                if (get.getProxyTransport() != null && !get.getProxyTransport().equals(get0.getProxyTransport())) {
+                        Assert.fail("getProxyTransport");
+                }
+
+                if (get.getPublishUrl() == null && get0.getPublishUrl() != null) {
+                        Assert.fail("getPublishUrl");
+                }
+
+                if (get.getPublishUrl() != null && !get.getPublishUrl().equals(get0.getPublishUrl())) {
+                        Assert.fail("getPublishUrl");
+                }
+
+                if (get.getReplicationUrl() == null && get0.getReplicationUrl() != null) {
+                        Assert.fail("getReplicationUrl");
+                }
+
+                if (get.getReplicationUrl() != null && !get.getReplicationUrl().equals(get0.getReplicationUrl())) {
+                        Assert.fail("getReplicationUrl");
+                }
+
+                if (get.getSecurityUrl() == null && get0.getSecurityUrl() != null) {
+                        Assert.fail("getSecurityUrl");
+                }
+
+                if (get.getSecurityUrl() != null && !get.getSecurityUrl().equals(get0.getSecurityUrl())) {
+                        Assert.fail("getSecurityUrl");
+                }
+
+                if (get.getSubscriptionListenerUrl() == null && get0.getSubscriptionListenerUrl() != null) {
+                        Assert.fail("getSubscriptionListenerUrl");
+                }
+
+                if (get.getSubscriptionListenerUrl() != null && !get.getSubscriptionListenerUrl().equals(get0.getSubscriptionListenerUrl())) {
+                        Assert.fail("getSubscriptionListenerUrl");
+                }
+
+                if (get.getSubscriptionUrl() == null && get0.getSubscriptionUrl() != null) {
+                        Assert.fail("getSubscriptionUrl");
+                }
+
+                if (get.getSubscriptionUrl() != null && !get.getSubscriptionUrl().equals(get0.getSubscriptionUrl())) {
+                        Assert.fail("getSubscriptionUrl");
+                }
+
+        }
+}

http://git-wip-us.apache.org/repos/asf/juddi/blob/197e1d1d/juddi-gui/src/main/webapp/ajax/settings.jsp
----------------------------------------------------------------------
diff --git a/juddi-gui/src/main/webapp/ajax/settings.jsp b/juddi-gui/src/main/webapp/ajax/settings.jsp
index 80cd887..d5c4045 100644
--- a/juddi-gui/src/main/webapp/ajax/settings.jsp
+++ b/juddi-gui/src/main/webapp/ajax/settings.jsp
@@ -50,7 +50,7 @@
                 }
             }
             try {
-                x.GetJuddiClientConfig().saveConfig();
+                x.GetJuddiClientConfig().saveConfigRaw();
                 out.write(ResourceLoader.GetResource(session, "actions.saved"));
             } catch (Exception ex) {
                 response.setStatus(406);


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