You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by ta...@apache.org on 2019/10/08 08:44:08 UTC

[deltaspike] branch master updated: DELTASPIKE-1388 - Fix initialization issue when using repos extended on interface.

This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/deltaspike.git


The following commit(s) were added to refs/heads/master by this push:
     new ae9f752  DELTASPIKE-1388 - Fix initialization issue when using repos extended on interface.
     new 7cfff5a  Merge pull request #97 from twyszomirski/DELTASPIKE-1388
ae9f752 is described below

commit ae9f7523ffee786576ee76429d9632f90f4e8b1b
Author: Tomasz Wyszomirski <tw...@psi.pl>
AuthorDate: Thu Oct 3 09:25:47 2019 +0200

    DELTASPIKE-1388 - Fix initialization issue when using repos extended on interface.
---
 .../data/impl/meta/EntityMetadataInitializer.java  |  2 +-
 .../data/impl/RepositoryExtensionTest.java         | 40 ++++++++++++++++++----
 .../data/test/service/BaseRepositoryInterface.java | 30 ++++++++++++++++
 .../test/service/ExtendedRepositoryInterface2.java | 32 +++++++++++++++++
 4 files changed, 96 insertions(+), 8 deletions(-)

diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/EntityMetadataInitializer.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/EntityMetadataInitializer.java
index 98edcbc..52b9764 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/EntityMetadataInitializer.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/EntityMetadataInitializer.java
@@ -71,7 +71,7 @@ public class EntityMetadataInitializer
         }
         for (Type intf : repositoryClass.getGenericInterfaces())
         {
-            entityMetadata = extractFromType(intf);
+            entityMetadata = extract( (Class< ? >)intf );
             if (entityMetadata != null)
             {
                 return entityMetadata;
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/RepositoryExtensionTest.java b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/RepositoryExtensionTest.java
index 6b22985..eff4a80 100755
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/RepositoryExtensionTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/RepositoryExtensionTest.java
@@ -18,14 +18,11 @@
  */
 package org.apache.deltaspike.data.impl;
 
-import static org.apache.deltaspike.data.test.util.TestDeployments.initDeployment;
-import static org.junit.Assert.assertNotNull;
-
-import javax.enterprise.inject.Instance;
-import javax.inject.Inject;
-
+import org.apache.deltaspike.data.test.TransactionalTestCase;
 import org.apache.deltaspike.data.test.domain.Simple;
+import org.apache.deltaspike.data.test.service.BaseRepositoryInterface;
 import org.apache.deltaspike.data.test.service.ExtendedRepositoryInterface;
+import org.apache.deltaspike.data.test.service.ExtendedRepositoryInterface2;
 import org.apache.deltaspike.data.test.service.RepositoryInterface;
 import org.apache.deltaspike.data.test.service.SimpleRepository;
 import org.apache.deltaspike.test.category.WebProfileCategory;
@@ -36,17 +33,28 @@ import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;
 
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+import static org.apache.deltaspike.data.test.util.TestDeployments.initDeployment;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
 @RunWith(Arquillian.class)
 @Category(WebProfileCategory.class)
-public class RepositoryExtensionTest
+public class RepositoryExtensionTest extends TransactionalTestCase
 {
 
+    private static final String NAME = "a_simple";
+
     @Deployment
     public static Archive<?> deployment()
     {
         return initDeployment()
                 .addClasses(RepositoryInterface.class,
+                            BaseRepositoryInterface.class,
                             ExtendedRepositoryInterface.class,
+                            ExtendedRepositoryInterface2.class,
                             SimpleRepository.class)
                 .addPackages(true, Simple.class.getPackage());
     }
@@ -60,6 +68,9 @@ public class RepositoryExtensionTest
     @Inject
     Instance<SimpleRepository> extendedClassRepo;
 
+    @Inject
+    private ExtendedRepositoryInterface2 repoOnInterface;
+
     @Test
     public void should_inject()
     {
@@ -68,4 +79,19 @@ public class RepositoryExtensionTest
         assertNotNull(extendedClassRepo.get());
     }
 
+    @Test
+    public void should_work_based_on_interface()
+    {
+        testData.createSimple( NAME );
+        Simple find = repoOnInterface.findByName( NAME );
+        assertNotNull(find);
+        assertEquals( NAME, find.getName() );
+
+        repoOnInterface.deleteAll();
+
+        long count = repoOnInterface.count(  );
+        assertEquals(0, count );
+
+    }
+
 }
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/BaseRepositoryInterface.java b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/BaseRepositoryInterface.java
new file mode 100644
index 0000000..14ffc7c
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/BaseRepositoryInterface.java
@@ -0,0 +1,30 @@
+/*
+ * 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.deltaspike.data.test.service;
+
+import org.apache.deltaspike.data.api.EntityManagerDelegate;
+import org.apache.deltaspike.data.api.EntityRepository;
+import org.apache.deltaspike.data.api.Repository;
+import org.apache.deltaspike.data.test.domain.Simple;
+
+@Repository
+public interface BaseRepositoryInterface extends EntityRepository<Simple, Long>, EntityManagerDelegate<Simple>
+{
+    Simple findByName( String name );
+}
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryInterface2.java b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryInterface2.java
new file mode 100644
index 0000000..02cc9e3
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/ExtendedRepositoryInterface2.java
@@ -0,0 +1,32 @@
+/*
+ * 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.deltaspike.data.test.service;
+
+import org.apache.deltaspike.data.api.Modifying;
+import org.apache.deltaspike.data.api.Query;
+import org.apache.deltaspike.data.api.Repository;
+
+@Repository
+public interface ExtendedRepositoryInterface2 extends BaseRepositoryInterface
+{
+    @Modifying
+    @Query( "delete from Simple")
+    int deleteAll();
+}
+