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

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

commit acb431b0bf963b1d19f2ca670a3037ccd0a0464e
Author: Martin Stockhammer <[email protected]>
AuthorDate: Wed May 1 17:54:38 2019 +0200

    Fixing unit tests for upload
---
 .../apache/archiva/upload/UploadArtifactsTest.java | 108 ---------------------
 .../test/resources/spring-context-test-upload.xml  |  47 +++++++--
 2 files changed, 38 insertions(+), 117 deletions(-)

diff --git 
a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/upload/UploadArtifactsTest.java
 
b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/upload/UploadArtifactsTest.java
index b754a40..1b341f3 100644
--- 
a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/upload/UploadArtifactsTest.java
+++ 
b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/upload/UploadArtifactsTest.java
@@ -19,25 +19,11 @@ package org.apache.archiva.upload;
  */
 
 import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
-import org.apache.archiva.admin.model.beans.RemoteRepository;
-import org.apache.archiva.redback.rest.api.model.User;
-import org.apache.archiva.redback.rest.api.services.RoleManagementService;
-import org.apache.archiva.redback.rest.api.services.UserService;
 import org.apache.archiva.redback.rest.services.AbstractRestServicesTest;
-import org.apache.archiva.redback.rest.services.FakeCreateAdminService;
-import org.apache.archiva.remotedownload.AbstractDownloadTest;
 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
-import org.apache.archiva.security.common.ArchivaRoleConstants;
 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
 import org.apache.archiva.web.api.FileUploadService;
-import org.apache.archiva.web.api.RuntimeInfoService;
-import org.apache.archiva.web.model.ApplicationRuntimeInfo;
 import org.apache.archiva.web.model.FileMetadata;
-import org.apache.catalina.Context;
-import org.apache.catalina.LifecycleException;
-import org.apache.catalina.deploy.ApplicationParameter;
-import org.apache.catalina.startup.Tomcat;
-import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.SystemUtils;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
@@ -47,38 +33,15 @@ import org.apache.cxf.jaxrs.ext.multipart.AttachmentBuilder;
 import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
 import org.apache.cxf.message.Message;
-import org.apache.cxf.transport.servlet.CXFServlet;
-import org.apache.maven.wagon.providers.http.HttpWagon;
-import org.apache.maven.wagon.repository.Repository;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.bridge.SLF4JBridgeHandler;
-import org.springframework.web.context.ContextLoaderListener;
 
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.File;
 import java.io.IOException;
 import java.net.URLEncoder;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.nio.file.StandardCopyOption;
 import java.util.Collections;
-import java.util.List;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
 
 /**
  * @author Olivier Lamy
@@ -87,78 +50,7 @@ import java.util.zip.ZipFile;
 public class UploadArtifactsTest
     extends AbstractRestServicesTest
 {
-    private Tomcat tomcat;
 
-    @Override
-    @Before
-    public void startServer( )
-        throws Exception
-    {
-        System.setProperty( 
"org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true" );
-        System.setProperty("appserver.base", 
Paths.get("target/appserver-base").toAbsolutePath().toString());
-        Path appServerBase = Paths.get("target/appserver-base");
-        FileUtils.deleteDirectory(appServerBase.toAbsolutePath().toFile());
-        Path confDir = appServerBase.resolve( "conf" );
-        if ( !Files.exists(confDir))
-        {
-            Files.createDirectories(confDir);
-        }
-        Path log4jCfg = Paths.get( "src/test/resources/log4j2-test.xml" );
-        Path log4jCfgDst = confDir.resolve( log4jCfg.getFileName( ) );
-
-        Files.copy( log4jCfg, log4jCfgDst, StandardCopyOption.REPLACE_EXISTING 
);
-
-        Path archivaCfg = Paths.get( "src/test/resources/archiva.xml" );
-        Files.copy( archivaCfg, confDir.resolve( archivaCfg.getFileName( ) ), 
StandardCopyOption.REPLACE_EXISTING );
-
-        Path jcrDirectory = appServerBase.resolve("jcr" );
-
-        if ( Files.exists(jcrDirectory) )
-        {
-            FileUtils.deleteDirectory( jcrDirectory.toAbsolutePath().toFile() 
);
-        }
-        // We have to activate this to verify the bad path traversal 
protection. We cannot rely on
-        // the application server only.
-
-        SLF4JBridgeHandler.removeHandlersForRootLogger();
-        SLF4JBridgeHandler.install();
-        this.tomcat = new Tomcat();
-        this.tomcat.setBaseDir(System.getProperty("java.io.tmpdir"));
-        this.tomcat.setPort(0);
-        this.tomcat.setSilent(false);
-        Context context = this.tomcat.addContext("", 
System.getProperty("java.io.tmpdir"));
-        ApplicationParameter applicationParameter = new ApplicationParameter();
-        applicationParameter.setName("contextConfigLocation");
-        applicationParameter.setValue(this.getSpringConfigLocation());
-        context.addApplicationParameter(applicationParameter);
-        context.addApplicationListener(ContextLoaderListener.class.getName());
-        Tomcat.addServlet(context, "cxf", new CXFServlet());
-        context.addServletMapping("/" + this.getRestServicesPath() + "/*", 
"cxf");
-        this.tomcat.start();
-        this.port = this.tomcat.getConnector().getLocalPort();
-        this.log.info("start server on port {}", this.port);
-        UserService userService = this.getUserService();
-        User adminUser = new User();
-        adminUser.setUsername("admin");
-        adminUser.setPassword("rose210208");
-        adminUser.setFullName("the admin user");
-        adminUser.setEmail("[email protected]");
-        userService.createAdminUser(adminUser);
-        FakeCreateAdminService fakeCreateAdminService = 
this.getFakeCreateAdminService();
-        // super.startServer( );
-    }
-
-    @After
-    public void stop( ) {
-        if (this.tomcat != null) {
-            try {
-                this.tomcat.stop();
-            } catch (LifecycleException e) {
-                //
-            }
-        }
-        System.clearProperty( 
"org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH" );
-    }
 
     @Override
     protected String getSpringConfigLocation( )
diff --git 
a/archiva-modules/archiva-web/archiva-web-common/src/test/resources/spring-context-test-upload.xml
 
b/archiva-modules/archiva-web/archiva-web-common/src/test/resources/spring-context-test-upload.xml
index 0e2e156..dbdfa6b 100644
--- 
a/archiva-modules/archiva-web/archiva-web-common/src/test/resources/spring-context-test-upload.xml
+++ 
b/archiva-modules/archiva-web/archiva-web-common/src/test/resources/spring-context-test-upload.xml
@@ -20,11 +20,13 @@
   -->
 <beans xmlns="http://www.springframework.org/schema/beans";
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-       xmlns:context="http://www.springframework.org/schema/context";
+       xmlns:context="http://www.springframework.org/schema/context"; 
xmlns:tx="http://www.springframework.org/schema/tx";
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context
-           
http://www.springframework.org/schema/context/spring-context-3.0.xsd";
+           http://www.springframework.org/schema/context/spring-context-3.0.xsd
+           http://www.springframework.org/schema/tx
+           http://www.springframework.org/schema/tx/spring-tx.xsd";
        default-lazy-init="true">
 
   <context:annotation-config/>
@@ -79,16 +81,43 @@
     <property name="queue" ref="taskQueue#repository-scanning"/>
   </bean>
 
-  <bean id="repository" class="org.apache.jackrabbit.core.RepositoryImpl" 
destroy-method="shutdown">
-    <constructor-arg ref="config"/>
-  </bean>
-  <bean id="config" class="org.apache.jackrabbit.core.config.RepositoryConfig" 
factory-method="create">
-    <constructor-arg value="${basedir}/src/test/repository.xml"/>
-    <constructor-arg value="${appserver.base}/jcr"/>
-  </bean>
+
 
   <alias name="repositorySessionFactory#jcr" alias="repositorySessionFactory"/>
   <alias name="userConfiguration#archiva" alias="userConfiguration#default"/>
   <alias name="authorizer#rbac" alias="authorizer#default"/>
   <alias name="userManager#configurable" alias="userManager#default"/>
+
+  <!--  ***
+      JPA settings
+      *** -->
+  <bean name="entityManagerFactory" 
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+    <property name="jpaVendorAdapter" >
+      <bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter" />
+    </property>
+    <property name="persistenceXmlLocation" 
value="classpath:META-INF/persistence-hsqldb.xml" />
+    <property name="jpaPropertyMap">
+      <map>
+        <entry key="openjpa.ConnectionURL" 
value="jdbc:hsqldb:mem:redback_database" />
+        <entry key="openjpa.ConnectionDriverName" 
value="org.hsqldb.jdbcDriver" />
+        <entry key="openjpa.ConnectionUserName" value="sa" />
+        <entry key="openjpa.ConnectionPassword" value="" />
+        <entry key="openjpa.Log" 
value="${openjpa.Log:DefaultLevel=INFO,Runtime=ERROR,Tool=ERROR,SQL=ERROR,Schema=ERROR,MetaData=ERROR}"
 />
+        <entry key="openjpa.jdbc.SynchronizeMappings" 
value="buildSchema(ForeignKeys=true)" />
+        <entry key="openjpa.jdbc.MappingDefaults"
+               
value="ForeignKeyDeleteAction=restrict,JoinForeignKeyDeleteAction=restrict"/>
+      </map>
+    </property>
+
+  </bean>
+
+  <bean name="transactionManager" 
class="org.springframework.orm.jpa.JpaTransactionManager" >
+    <property name="entityManagerFactory" ref="entityManagerFactory" />
+  </bean>
+
+  <tx:annotation-driven />
+  <!--  ***
+        End of JPA settings
+        *** -->
+
 </beans>
\ No newline at end of file

Reply via email to