onami-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sclas...@apache.org
Subject svn commit: r1594024 - in /onami/sandbox/persist/src: main/java/org/apache/onami/persist/ test/java/org/apache/onami/persist/
Date Mon, 12 May 2014 16:27:12 GMT
Author: sclassen
Date: Mon May 12 16:27:11 2014
New Revision: 1594024

URL: http://svn.apache.org/r1594024
Log:
onami-persist: reduced visibility of JndiLookupHelper and introduced interface for PersistenceFilter

Added:
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilterImpl.java
  (with props)
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceFilterImplTest.java
  (with props)
Removed:
    onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceFilterTest.java
Modified:
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/JndiLookupHelper.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java
    onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceModule.java

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/JndiLookupHelper.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/JndiLookupHelper.java?rev=1594024&r1=1594023&r2=1594024&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/JndiLookupHelper.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/JndiLookupHelper.java Mon
May 12 16:27:11 2014
@@ -28,7 +28,7 @@ import javax.naming.NamingException;
  * Helper class which does a JNDI lookup and handles exceptions.
  */
 @Singleton
-public class JndiLookupHelper
+class JndiLookupHelper
 {
 
     /**

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java?rev=1594024&r1=1594023&r2=1594024&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilter.java Mon
May 12 16:27:11 2014
@@ -19,17 +19,7 @@ package org.apache.onami.persist;
  * under the License.
  */
 
-import com.google.inject.Inject;
-
 import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import java.io.IOException;
-
-import static org.apache.onami.persist.Preconditions.checkNotNull;
 
 /**
  * Filter for use in container.
@@ -47,61 +37,7 @@ import static org.apache.onami.persist.P
  *  }
  * </pre>
  */
-public class PersistenceFilter
-    implements Filter
+public interface PersistenceFilter
+    extends Filter
 {
-
-    /**
-     * Container of all known persistence unit and units of work.
-     */
-    private final AllPersistenceUnits persistenceUnitsContainer;
-
-    /**
-     * Constructor.
-     *
-     * @param persistenceUnitsContainer container of all known persistence unit and units
of work.
-     */
-    @Inject
-    PersistenceFilter( AllPersistenceUnits persistenceUnitsContainer )
-    {
-        checkNotNull( persistenceUnitsContainer );
-        this.persistenceUnitsContainer = persistenceUnitsContainer;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    // @Override
-    public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain
)
-        throws IOException, ServletException
-    {
-        try
-        {
-            persistenceUnitsContainer.beginAllInactiveUnitsOfWork();
-            chain.doFilter( request, response );
-        }
-        finally
-        {
-            persistenceUnitsContainer.endAllUnitsOfWork();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    // @Override
-    public void init( FilterConfig filterConfig )
-        throws ServletException
-    {
-        persistenceUnitsContainer.startAllStoppedPersistenceServices();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    // @Override
-    public void destroy()
-    {
-        persistenceUnitsContainer.stopAllPersistenceServices();
-    }
 }

Added: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilterImpl.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilterImpl.java?rev=1594024&view=auto
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilterImpl.java
(added)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilterImpl.java
Mon May 12 16:27:11 2014
@@ -0,0 +1,94 @@
+package org.apache.onami.persist;
+
+/*
+ * 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.
+ */
+
+import com.google.inject.Inject;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import java.io.IOException;
+
+import static org.apache.onami.persist.Preconditions.checkNotNull;
+
+/**
+ * Implementation of {@link PersistenceFilter}.
+ */
+public class PersistenceFilterImpl
+    implements PersistenceFilter
+{
+
+    /**
+     * Container of all known persistence unit and units of work.
+     */
+    private final AllPersistenceUnits persistenceUnitsContainer;
+
+    /**
+     * Constructor.
+     *
+     * @param persistenceUnitsContainer container of all known persistence unit and units
of work.
+     */
+    @Inject
+    PersistenceFilterImpl( AllPersistenceUnits persistenceUnitsContainer )
+    {
+        checkNotNull( persistenceUnitsContainer );
+        this.persistenceUnitsContainer = persistenceUnitsContainer;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void doFilter( ServletRequest request, ServletResponse response, FilterChain chain
)
+        throws IOException, ServletException
+    {
+        try
+        {
+            persistenceUnitsContainer.beginAllInactiveUnitsOfWork();
+            chain.doFilter( request, response );
+        }
+        finally
+        {
+            persistenceUnitsContainer.endAllUnitsOfWork();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void init( FilterConfig filterConfig )
+        throws ServletException
+    {
+        persistenceUnitsContainer.startAllStoppedPersistenceServices();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    // @Override
+    public void destroy()
+    {
+        persistenceUnitsContainer.stopAllPersistenceServices();
+    }
+}

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilterImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilterImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceFilterImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceModule.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceModule.java?rev=1594024&r1=1594023&r2=1594024&view=diff
==============================================================================
--- onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceModule.java (original)
+++ onami/sandbox/persist/src/main/java/org/apache/onami/persist/PersistenceModule.java Mon
May 12 16:27:11 2014
@@ -72,6 +72,8 @@ public abstract class PersistenceModule
     {
         configurePersistence();
 
+        bind( PersistenceFilter.class ).to( PersistenceFilterImpl.class );
+
         final AllPersistenceUnits allPersistenceUnits = new AllPersistenceUnits();
         bind( AllPersistenceServices.class ).toInstance( allPersistenceUnits );
         bind( AllUnitsOfWork.class ).toInstance( allPersistenceUnits );

Added: onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceFilterImplTest.java
URL: http://svn.apache.org/viewvc/onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceFilterImplTest.java?rev=1594024&view=auto
==============================================================================
--- onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceFilterImplTest.java
(added)
+++ onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceFilterImplTest.java
Mon May 12 16:27:11 2014
@@ -0,0 +1,111 @@
+package org.apache.onami.persist;
+
+/*
+ * 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.
+ */
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InOrder;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import static org.mockito.Mockito.*;
+
+/**
+ * Test for {@link PersistenceFilterImpl}.
+ */
+public class PersistenceFilterImplTest
+{
+    private PersistenceFilterImpl sut;
+
+    private AllPersistenceUnits persistenceUnitsContainer;
+
+    @Before
+    public void setUp()
+        throws Exception
+    {
+        persistenceUnitsContainer = mock( AllPersistenceUnits.class );
+        sut = new PersistenceFilterImpl( persistenceUnitsContainer );
+    }
+
+    @Test
+    public void initShouldStartService()
+        throws Exception
+    {
+        sut.init( mock( FilterConfig.class ) );
+        verify( persistenceUnitsContainer ).startAllStoppedPersistenceServices();
+    }
+
+    @Test
+    public void destroyShouldStopService()
+    {
+        sut.destroy();
+        verify( persistenceUnitsContainer ).stopAllPersistenceServices();
+    }
+
+    @Test
+    public void doFilterShouldSpanUnitOfWork()
+        throws Exception
+    {
+        // given
+        final FilterChain chain = mock( FilterChain.class );
+        final InOrder inOrder = inOrder( persistenceUnitsContainer, chain );
+
+        final ServletRequest request = mock( ServletRequest.class );
+        final ServletResponse response = mock( ServletResponse.class );
+
+        // when
+        sut.doFilter( request, response, chain );
+
+        // then
+        inOrder.verify( persistenceUnitsContainer ).beginAllInactiveUnitsOfWork();
+        inOrder.verify( chain ).doFilter( request, response );
+        inOrder.verify( persistenceUnitsContainer ).endAllUnitsOfWork();
+    }
+
+    @Test(expected = RuntimeException.class)
+    public void doFilterShouldEndUnitOfWorkInCaseOfException()
+        throws Exception
+    {
+        // given
+        final FilterChain chain = mock( FilterChain.class );
+        final InOrder inOrder = inOrder( persistenceUnitsContainer, chain );
+
+        final ServletRequest request = mock( ServletRequest.class );
+        final ServletResponse response = mock( ServletResponse.class );
+
+        doThrow( new RuntimeException() ).when( chain ).doFilter( request, response );
+
+        // when
+        try
+        {
+            sut.doFilter( request, response, chain );
+        }
+        // then
+        finally
+        {
+            inOrder.verify( persistenceUnitsContainer ).beginAllInactiveUnitsOfWork();
+            inOrder.verify( chain ).doFilter( request, response );
+            inOrder.verify( persistenceUnitsContainer ).endAllUnitsOfWork();
+        }
+    }
+}

Propchange: onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceFilterImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceFilterImplTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: onami/sandbox/persist/src/test/java/org/apache/onami/persist/PersistenceFilterImplTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message