java rewrite
This commit is contained in:
@@ -1,30 +1,39 @@
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
|
||||
import lombok.SneakyThrows;
|
||||
import net.woggioni.jpacrepo.model.Hasher;
|
||||
import net.woggioni.jpacrepo.model.MD5InputStream;
|
||||
import net.woggioni.jpacrepo.model.Parser;
|
||||
import net.woggioni.jpacrepo.pacbase.CompressionFormat;
|
||||
import net.woggioni.jpacrepo.pacbase.PkgData;
|
||||
import net.woggioni.jpacrepo.service.PacmanServiceRemote;
|
||||
import net.woggioni.jpacrepo.api.model.PkgData;
|
||||
import net.woggioni.jpacrepo.api.service.PacmanServiceRemote;
|
||||
import net.woggioni.jpacrepo.impl.model.CompressionFormatImpl;
|
||||
import net.woggioni.jpacrepo.impl.model.PkgDataImpl;
|
||||
import net.woggioni.jwo.Con;
|
||||
import net.woggioni.jwo.Fun;
|
||||
import net.woggioni.jwo.Hash;
|
||||
import net.woggioni.jwo.JWO;
|
||||
import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
|
||||
import org.jboss.resteasy.spi.ResteasyProviderFactory;
|
||||
|
||||
import javax.naming.*;
|
||||
import javax.ws.rs.client.*;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
|
||||
import jakarta.ws.rs.client.*;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.UriBuilder;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.DigestInputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Properties;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ClientTest {
|
||||
|
||||
@@ -59,8 +68,7 @@ public class ClientTest {
|
||||
}
|
||||
}
|
||||
|
||||
public void testPUT() throws Exception
|
||||
{
|
||||
public void testPUT() throws Exception {
|
||||
ResteasyProviderFactory instance = ResteasyProviderFactory.getInstance();
|
||||
RegisterBuiltin.register(instance);
|
||||
Client client = ClientBuilder.newClient();
|
||||
@@ -77,60 +85,39 @@ public class ClientTest {
|
||||
assert Response.Status.CREATED.getStatusCode() == response.getStatus();
|
||||
}
|
||||
|
||||
public void hashTest() throws Exception
|
||||
{
|
||||
String[] files = new String[]{"/var/cache/pacman/pkg/mesa-10.4.5-1-x86_64.pkg.tar.xz", "/var/cache/pacman/pkg/mesa-10.5.3-1-x86_64.pkg.tar.xz"};
|
||||
|
||||
for (String file : files)
|
||||
{
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
try (InputStream is = Files.newInputStream(Paths.get(file)))
|
||||
{
|
||||
DigestInputStream dis = new DigestInputStream(is, md);
|
||||
dis.on(true);
|
||||
// is.read();
|
||||
long a = new File(file).length();
|
||||
byte[] out = new byte[(int)a];
|
||||
dis.read(out, 0, (int) a);
|
||||
@Test
|
||||
public void hashTest(@TempDir Path testDir) {
|
||||
ClassLoader cl = getClass().getClassLoader();
|
||||
Stream.of("gvfs-nfs-1.50.2-1-x86_64.pkg.tar.zst")
|
||||
.forEach((Con<String>) resourceName -> {
|
||||
Path tmpFile = testDir.resolve(resourceName);
|
||||
try(InputStream is = cl.getResourceAsStream(resourceName)) {
|
||||
Files.copy(is, tmpFile);
|
||||
}
|
||||
System.out.println(Hasher.bytesToHex(md.digest()));
|
||||
|
||||
System.out.println(Hasher.computeMD5(new FileInputStream(file)));
|
||||
|
||||
InputStream fis = new FileInputStream(file);
|
||||
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());
|
||||
|
||||
Path path = Paths.get(file);
|
||||
PkgData p = Parser.parseFile(path, CompressionFormat.guess(path));
|
||||
System.out.println(p.md5sum());
|
||||
|
||||
}
|
||||
|
||||
Hash hash;
|
||||
try(InputStream is = Files.newInputStream(tmpFile)) {
|
||||
hash = Hash.md5(is);
|
||||
}
|
||||
PkgData p = PkgDataImpl.parseFile(tmpFile, CompressionFormatImpl.guess(tmpFile));
|
||||
Assertions.assertEquals(JWO.bytesToHex(hash.getBytes()), p.getMd5sum());
|
||||
});
|
||||
}
|
||||
|
||||
private static void traverseJndiNode(String nodeName, Context context)
|
||||
{
|
||||
try
|
||||
{
|
||||
private static void traverseJndiNode(String nodeName, Context context) {
|
||||
try {
|
||||
NamingEnumeration<NameClassPair> list = context.list(nodeName);
|
||||
while (list.hasMore())
|
||||
{
|
||||
while (list.hasMore()) {
|
||||
String childName = nodeName + "" + list.next().getName();
|
||||
System.out.println(childName);
|
||||
traverseJndiNode(childName, context);
|
||||
}
|
||||
} catch (NamingException ex)
|
||||
{
|
||||
} catch (NamingException ex) {
|
||||
// We reached a leaf
|
||||
}
|
||||
}
|
||||
|
||||
public void invokeStatelessBean() throws Exception
|
||||
{
|
||||
@Test
|
||||
public void invokeStatelessBean() throws Exception {
|
||||
Properties prop = new Properties();
|
||||
InputStream in = getClass().getClassLoader().getResourceAsStream("jboss-ejb-client.properties");
|
||||
prop.load(in);
|
||||
@@ -140,10 +127,10 @@ public class ClientTest {
|
||||
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(Context.SECURITY_PRINCIPAL, "walter");
|
||||
// prop.put(Context.SECURITY_CREDENTIALS, "27ff5990757d1d");
|
||||
prop.put(Context.SECURITY_PRINCIPAL, "luser");
|
||||
prop.put(Context.SECURITY_CREDENTIALS, "123456");
|
||||
|
||||
prop.put("jboss.naming.client.ejb.context", true);
|
||||
Context context = new InitialContext(prop);
|
||||
@@ -151,7 +138,7 @@ public class ClientTest {
|
||||
traverseJndiNode("/", context);
|
||||
// final PacmanService stateService = (PacmanService) ctx.lookup("/jpacrepo-1.0/remote/PacmanServiceEJB!service.PacmanService");
|
||||
final PacmanServiceRemote service = (PacmanServiceRemote) ctx.lookup(
|
||||
"/jpacrepo_2.12-2.0/PacmanServiceEJB!net.woggioni.jpacrepo.service.PacmanServiceRemote"
|
||||
"/jpacrepo-2.0-SNAPSHOT/PacmanServiceEJB!net.woggioni.jpacrepo.service.PacmanServiceRemote"
|
||||
);
|
||||
// List<PkgData> pkgs = service.searchPackage("google-earth", null, null, 1, 10);
|
||||
// System.out.println(new XStream().toXML(pkgs));
|
||||
|
Reference in New Issue
Block a user