conversion from Java to Scala
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import com.oggio88.jpacrepo.service.PacmanServiceRemote;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import net.woggioni.jpacrepo.model.Hasher;
|
||||
import net.woggioni.jpacrepo.model.MD5InputStream;
|
||||
import net.woggioni.jpacrepo.model.Parser;
|
||||
import net.woggioni.jpacrepo.pacbase.PkgData;
|
||||
import net.woggioni.jpacrepo.service.PacmanServiceRemote;
|
||||
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
|
||||
import org.jboss.resteasy.plugins.providers.jackson.ResteasyJacksonProvider;
|
||||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||
import com.oggio88.jpacrepo.model.PkgData;
|
||||
import com.oggio88.jpacrepo.pacbase.Hasher;
|
||||
import com.oggio88.jpacrepo.pacbase.MD5InputStream;
|
||||
import com.oggio88.jpacrepo.pacbase.Parser;
|
||||
import com.oggio88.jpacrepo.service.PacmanServiceView;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.naming.*;
|
||||
@@ -22,16 +21,12 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.DigestInputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Created by walter on 29/03/15.
|
||||
*/
|
||||
public class ClientTest
|
||||
{
|
||||
@Test
|
||||
public void testGET() throws Exception
|
||||
public void testGET()
|
||||
{
|
||||
ResteasyProviderFactory instance = ResteasyProviderFactory.getInstance();
|
||||
RegisterBuiltin.register(instance);
|
||||
@@ -92,14 +87,14 @@ public class ClientTest
|
||||
System.out.println(Hasher.computeMD5(new FileInputStream(file)));
|
||||
|
||||
InputStream fis = new FileInputStream(file);
|
||||
MD5InputStream h = Hasher.createMD5InputStream(fis);
|
||||
MD5InputStream h = new MD5InputStream(fis);
|
||||
long a = new File(file).length();
|
||||
byte[] out = new byte[(int)a];
|
||||
h.read(out, 0, (int) a);
|
||||
System.out.println(h.digest());
|
||||
|
||||
PkgData p = new Parser().parseFile(new File(file));
|
||||
System.out.println(p.md5sum);
|
||||
PkgData p = Parser.parseFile(new File(file));
|
||||
System.out.println(p.md5sum());
|
||||
|
||||
}
|
||||
|
||||
@@ -125,26 +120,27 @@ public class ClientTest
|
||||
@Test
|
||||
public void invokeStatelessBean() throws Exception
|
||||
{
|
||||
// Let's lookup the remote stateless calculator
|
||||
|
||||
Properties prop = new Properties();
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream("jboss-ejb-client.properties");
|
||||
prop.load(in);
|
||||
prop.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
|
||||
|
||||
prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
|
||||
// prop.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
|
||||
prop.put(Context.PROVIDER_URL, "http-remoting://nuc:8080");
|
||||
prop.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
|
||||
// prop.put(Context.PROVIDER_URL, "http-remoting://nuc:8080");
|
||||
// prop.put(Context.PROVIDER_URL, "remote://odroid-u3:4447");
|
||||
prop.put(Context.SECURITY_PRINCIPAL, "walter");
|
||||
prop.put(Context.SECURITY_CREDENTIALS, "27ff5990757d1d");
|
||||
// prop.put(Context.SECURITY_PRINCIPAL, "admin");
|
||||
// prop.put(Context.SECURITY_CREDENTIALS, "123456");
|
||||
|
||||
prop.put("jboss.naming.client.ejb.context", true);
|
||||
Context context = new InitialContext(prop);
|
||||
Context ctx = new InitialContext(prop);
|
||||
traverseJndiNode("/", context);
|
||||
// final PacmanService stateService = (PacmanService) ctx.lookup("/jpacrepo-1.0/remote/PacmanServiceEJB!service.PacmanService");
|
||||
final PacmanServiceRemote service = (PacmanServiceRemote) ctx.lookup(
|
||||
"/jpacrepo-2.0/PacmanServiceEJB!com.oggio88.jpacrepo.service.PacmanServiceRemote"
|
||||
"/jpacrepo_2.12-2.0/PacmanServiceEJB!net.woggioni.jpacrepo.service.PacmanServiceRemote"
|
||||
);
|
||||
// List<PkgData> pkgs = service.searchPackage("google-earth", null, null, 1, 10);
|
||||
// System.out.println(new XStream().toXML(pkgs));
|
||||
|
@@ -1,13 +1,12 @@
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import net.woggioni.jpacrepo.model.Parser;
|
||||
import net.woggioni.jpacrepo.pacbase.PkgData;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.filefilter.DirectoryFileFilter;
|
||||
import org.apache.commons.io.filefilter.RegexFileFilter;
|
||||
import com.oggio88.jpacrepo.model.PkgData;
|
||||
import com.oggio88.jpacrepo.pacbase.Parser;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -18,14 +17,14 @@ import java.util.List;
|
||||
public class ParseTest
|
||||
{
|
||||
// @Test
|
||||
public void test() throws Exception
|
||||
public void test()
|
||||
{
|
||||
Collection<File> ls = FileUtils.listFiles(new File("/var/cache/pacman/pkg"), new RegexFileFilter(".*\\.pkg\\.tar\\.xz"), DirectoryFileFilter.DIRECTORY);
|
||||
int i = 0;
|
||||
List<PkgData> lista = new ArrayList<>();
|
||||
for (File file : ls)
|
||||
{
|
||||
PkgData data = new Parser().parseFile(file);
|
||||
PkgData data = Parser.parseFile(file);
|
||||
lista.add(data);
|
||||
//System.out.println(new XStream().toXML(data));
|
||||
// if(i++>10) break;
|
||||
@@ -34,13 +33,13 @@ public class ParseTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseTest() throws Exception
|
||||
public void parseTest()
|
||||
{
|
||||
String[] files = new String[]{"/home/walter/Scaricati/oh-my-zsh-git-3912.d310fac-1-any.pkg.tar.xz"};
|
||||
|
||||
for (String file : files)
|
||||
{
|
||||
PkgData data = new Parser().parseFile(new File(file));
|
||||
PkgData data = Parser.parseFile(new File(file));
|
||||
System.out.println(new XStream().toXML(data));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,16 @@
|
||||
package net.woggioni.jpacrepo.annotation;
|
||||
|
||||
import javax.enterprise.inject.Alternative;
|
||||
import javax.enterprise.inject.Stereotype;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
@Alternative
|
||||
@Stereotype
|
||||
@Retention(RUNTIME)
|
||||
@Target(TYPE)
|
||||
public @interface UnitTesting {
|
||||
}
|
6
src/test/resources/META-INF/beans.xml
Normal file
6
src/test/resources/META-INF/beans.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee">
|
||||
<alternatives>
|
||||
<stereotype>net.woggioni.jpacrepo.annotation.UnitTesting</stereotype>
|
||||
</alternatives>
|
||||
</beans>
|
24
src/test/resources/META-INF/persistence.xml
Normal file
24
src/test/resources/META-INF/persistence.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
|
||||
version="2.1">
|
||||
|
||||
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
|
||||
<class>net.woggioni.jpacrepo.pacbase.PkgData</class>
|
||||
<class>net.woggioni.jpacrepo.pacbase.PkgName</class>
|
||||
|
||||
<properties>
|
||||
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
|
||||
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:jpwdb;create=true;FILE_LOCK=NO"/>
|
||||
<property name="javax.persistence.jdbc.user" value="APP"/>
|
||||
<property name="javax.persistence.jdbc.password" value="APP"/>
|
||||
<property name="org.jboss.logging.provider" value="log4j2"/>
|
||||
<property name="javax.persistence.schema-generation.database.action" value="create"/>
|
||||
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
|
||||
<property name="hibernate.connection.isolation" value="1"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
</persistence>
|
17
src/test/resources/log4j2.xml
Normal file
17
src/test/resources/log4j2.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="INFO">
|
||||
<Properties>
|
||||
<Property name="log-path">$${env:APOLLO_ENVIRONMENT_ROOT:-build}/var/logs</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss,SSS} %highlight{[%p]} (%t) %c: %m%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<Root level="INFO">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
@@ -0,0 +1,11 @@
|
||||
package net.woggioni.jpacrepo.persistence
|
||||
|
||||
import javax.enterprise.inject.Produces
|
||||
import javax.persistence.Persistence
|
||||
import net.woggioni.jpacrepo.annotation.UnitTesting
|
||||
|
||||
class TestPersistenceProducer {
|
||||
@Produces
|
||||
@UnitTesting
|
||||
def createEntityManagerFactory = Persistence.createEntityManagerFactory("test")
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
package net.woggioni.jpacrepo.service
|
||||
|
||||
import javax.enterprise.util.TypeLiteral
|
||||
import net.woggioni.jpacrepo.context.ApplicationContext
|
||||
import net.woggioni.jpacrepo.factory.BeanFactory
|
||||
import net.woggioni.jpacrepo.persistence.TestPersistenceProducer
|
||||
import org.jboss.weld.environment.se.Weld
|
||||
import org.junit.Test
|
||||
|
||||
//object WeldContainer {
|
||||
// private val weld = new Weld
|
||||
// weld.disableDiscovery()
|
||||
//
|
||||
// weld.beanClasses(
|
||||
// classOf[TestPersistenceProducer],
|
||||
// classOf[PacmanServiceEJB],
|
||||
// classOf[ApplicationContext],
|
||||
// classOf[BeanFactory],
|
||||
// )
|
||||
//
|
||||
// private val count = new AtomicInteger(0)
|
||||
//}
|
||||
|
||||
//class WeldContainer extends AutoCloseable {
|
||||
//
|
||||
// val container = WeldContainer.weld.initialize()
|
||||
// WeldContainer.count.incrementAndGet()
|
||||
//
|
||||
// override def close(): Unit = {
|
||||
// container.close()
|
||||
// if(WeldContainer.count.decrementAndGet() == 0) {
|
||||
//// WeldContainer.weld.shutdown()
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
class PacmanServiceEJBTest {
|
||||
|
||||
private val weld = new Weld
|
||||
// weld.disableDiscovery()
|
||||
weld.alternatives(classOf[TestPersistenceProducer])
|
||||
////
|
||||
weld.beanClasses(
|
||||
classOf[PacmanServiceEJB],
|
||||
classOf[PacmanWebService],
|
||||
// classOf[ApplicationContext],
|
||||
classOf[BeanFactory],
|
||||
)
|
||||
|
||||
@Test
|
||||
def test = {
|
||||
val container = weld.initialize()
|
||||
try {
|
||||
val s = getClass.getResourceAsStream("/log4j2.xml")
|
||||
val service = container.select(new TypeLiteral[PacmanServiceView] {}).get()
|
||||
service.syncDB()
|
||||
} finally {
|
||||
container.close()
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package net.woggioni.jpacrepo.service
|
||||
|
||||
class PacmanWebServiceTest {
|
||||
|
||||
// val server = {
|
||||
// val server = new UndertowJaxrsServer()
|
||||
// server.start()
|
||||
// import org.jboss.resteasy.spi.ResteasyDeployment
|
||||
// val deployment = new ResteasyDeployment
|
||||
// deployment.setInjectorFactoryClass("org.jboss.resteasy.cdi.CdiInjectorFactory")
|
||||
// deployment.setApplicationClass(classOf[ApplicationConfig].getName)
|
||||
// val di: DeploymentInfo = server.undertowDeployment(deployment)
|
||||
// di.setClassLoader(classOf[ApplicationConfig].getClassLoader)
|
||||
// di.setContextPath("/jpacrepo")
|
||||
// di.setDeploymentName("jpacrepo")
|
||||
// di.addListeners(Servlets.listener(classOf[Listener]))
|
||||
// server.deploy(di)
|
||||
// server
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// def foo {
|
||||
// val client = ClientBuilder.newClient()
|
||||
// val webTarget = client.target(TestPortProvider.generateURL("/jpacrepo/rest/pkg/map"))
|
||||
// val response = webTarget.request().get()
|
||||
// val res = response.getEntity
|
||||
// response.getStatus
|
||||
// }
|
||||
}
|
Reference in New Issue
Block a user