You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2015/05/27 05:23:12 UTC

tomee git commit: TOMEE-1593 using a linked set instead of a list for resources.xml

Repository: tomee
Updated Branches:
  refs/heads/master 5a2545310 -> 1c5a61370


TOMEE-1593 using a linked set instead of a list for resources.xml


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/1c5a6137
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/1c5a6137
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/1c5a6137

Branch: refs/heads/master
Commit: 1c5a613707e69533e79e4cd77737fcc57083f0c6
Parents: 5a25453
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Wed May 27 05:22:48 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Wed May 27 05:22:48 2015 +0200

----------------------------------------------------------------------
 .../org/apache/openejb/config/AppModule.java    |   3 +-
 .../openejb/resource/ResourceSortingTest.java   | 121 +++++++++++++++++++
 2 files changed, 123 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/1c5a6137/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java b/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java
index 42bbfb5..c5a647c 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java
@@ -37,6 +37,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -61,7 +62,7 @@ public class AppModule implements DeploymentModule {
     private final List<PersistenceModule> persistenceModules = new ArrayList<PersistenceModule>();
     private final Map<String, TransactionType> txTypeByUnit = new HashMap<String, TransactionType>();
     // TODO We could turn this into the Resources JAXB object and support containers and other things as well
-    private final Collection<Resource> resources = new HashSet<Resource>();
+    private final Collection<Resource> resources = new LinkedHashSet<>();
     private final Collection<Container> containers = new HashSet<Container>();
     private final Collection<Service> services = new HashSet<Service>();
     private final ClassLoader classLoader;

http://git-wip-us.apache.org/repos/asf/tomee/blob/1c5a6137/container/openejb-core/src/test/java/org/apache/openejb/resource/ResourceSortingTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/resource/ResourceSortingTest.java b/container/openejb-core/src/test/java/org/apache/openejb/resource/ResourceSortingTest.java
new file mode 100644
index 0000000..8da1009
--- /dev/null
+++ b/container/openejb-core/src/test/java/org/apache/openejb/resource/ResourceSortingTest.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openejb.resource;
+
+import org.apache.openejb.assembler.classic.ResourceInfo;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.config.sys.JaxbOpenejb;
+import org.apache.openejb.config.sys.Resources;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Module;
+import org.apache.openejb.testing.SimpleLog;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.xml.sax.SAXException;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import javax.xml.bind.JAXBException;
+import javax.xml.parsers.ParserConfigurationException;
+
+import static java.util.Arrays.asList;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+@SimpleLog
+@RunWith(ApplicationComposer.class)
+public class ResourceSortingTest {
+
+    public static final List<Character> LETTERS = asList('A', 'B', 'C', 'D', 'E');
+    public static final String BASE_NAME = "foo:bar=Hello";
+
+    @Module
+    public Resources r() throws JAXBException, SAXException, ParserConfigurationException {
+        final StringBuilder resourcesXml = new StringBuilder()
+                .append("<Resources>\n");
+        for (final Character c : LETTERS) {
+            resourcesXml.append("<Resource id=\"Hello").append(c)
+                    .append("\" class-name=\"org.apache.openejb.resource.ResourceSortingTest$Foo\">")
+                    .append("name foo:bar=Hello").append(c).append("</Resource>");
+        }
+        resourcesXml.append("</Resources>");
+        return JaxbOpenejb.unmarshal(Resources.class, new ByteArrayInputStream(resourcesXml.toString().getBytes()));
+    }
+
+    @Test
+    public void checkOrder() {
+        final Iterator<Character> letters = LETTERS.iterator();
+        final Iterator<String> ids = Foo.IDS.iterator();
+        while (letters.hasNext()) {
+            assertTrue(ids.hasNext());
+            assertEquals(BASE_NAME + letters.next(), ids.next());
+        }
+        assertFalse(letters.hasNext());
+    }
+
+    @Test
+    public void testRealWorld4() throws Exception {
+        final List<ResourceInfo> resources = new ArrayList<>();
+
+        resources.add(new ResourceInfo());
+        resources.get(0).id = "My JMS Connection Factory";
+        resources.get(0).properties = new Properties();
+        resources.get(0).properties.put("ResourceAdapter", "My JMS Resource Adapter");
+
+        resources.add(new ResourceInfo());
+        resources.get(1).id = "My Unmanaged DataSource";
+        resources.get(1).properties = new Properties();
+
+        resources.add(new ResourceInfo());
+        resources.get(2).id = "Test Resource";
+        resources.get(2).properties = new Properties();
+        resources.get(2).properties.put("ResourceAdapter", "My JMS Connection Factory");
+
+        resources.add(new ResourceInfo());
+        resources.get(3).id = "My DataSource";
+        resources.get(3).properties = new Properties();
+
+        resources.add(new ResourceInfo());
+        resources.get(4).id = "My JMS Resource Adapter";
+        resources.get(4).properties = new Properties();
+        resources.get(4).properties.put("DataSource", "My Unmanaged DataSource");
+
+        Collections.sort(resources, new ConfigurationFactory.ResourceInfoComparator(resources));
+
+        for (ResourceInfo i : resources) System.out.println(i.id);
+        assertEquals("My Unmanaged DataSource", resources.get(0).id);
+        assertEquals("My DataSource", resources.get(1).id);
+        assertEquals("My JMS Resource Adapter", resources.get(2).id);
+        assertEquals("My JMS Connection Factory", resources.get(3).id);
+        assertEquals("Test Resource", resources.get(4).id);
+    }
+
+    public static class Foo {
+        private static final List<String> IDS = new ArrayList<>();
+        private String name;
+
+        public void setName(String name) {
+            this.name = name;
+            IDS.add(name);
+        }
+    }
+}