tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgallim...@apache.org
Subject [1/5] tomee git commit: TOMEE-1593 using a linked set instead of a list for resources.xml
Date Wed, 27 May 2015 13:48:49 GMT
Repository: tomee
Updated Branches:
  refs/heads/tomee-1.7.x d98d834af -> dc461c514


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

Conflicts:
	container/openejb-core/src/main/java/org/apache/openejb/config/AppModule.java


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

Branch: refs/heads/tomee-1.7.x
Commit: 32ffd568e0dce1251dd0902570de3a10af56f960
Parents: d98d834
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Wed May 27 05:22:48 2015 +0200
Committer: Jonathan Gallimore <jon@jrg.me.uk>
Committed: Wed May 27 13:56:31 2015 +0100

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


http://git-wip-us.apache.org/repos/asf/tomee/blob/32ffd568/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 7d71a80..9461f1f 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
@@ -36,6 +36,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;
@@ -59,7 +60,8 @@ 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<Resource>();
+    private final Collection<Container> containers = new HashSet<Container>();
     private final Collection<Service> services = new HashSet<Service>();
     private final ClassLoader classLoader;
     private EntityMappings cmpMappings;

http://git-wip-us.apache.org/repos/asf/tomee/blob/32ffd568/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);
+        }
+    }
+}


Mime
View raw message