Skip to content

Commit

Permalink
Fixes unused imports, small code issues
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Reinhart <patrick@reini.net>
  • Loading branch information
reinhapa committed Jan 11, 2024
1 parent 8b7c03b commit fb84125
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

import org.exist.util.io.ContentFile;

/**
* @author <a href="mailto:patrick@reini.net">Patrick Reinhart</a>
*/
public final class CachedContentFile extends AbstractCachedResult {
private final ContentFile result;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import static org.easymock.EasyMock.aryEq;
Expand Down Expand Up @@ -116,11 +115,9 @@ static byte[] write(int ch) {
reportMatcher(new IArgumentMatcher() {
@Override
public boolean matches(Object o) {
if (o instanceof byte[] data) {
if (data.length == 1) {
data[0] = (byte) ch;
return true;
}
if (o instanceof byte[] data && data.length == 1) {
data[0] = (byte) ch;
return true;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import static org.easymock.EasyMock.verify;
import static org.assertj.core.api.Assertions.*;

/**
* @author <a href="mailto:patrick@reini.net">Patrick Reinhart</a>
*/
@ExtendWith(EasyMockExtension.class)
class CachedContentFileTest {
@Mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@

import static org.assertj.core.api.Assertions.*;

/**
* @author <a href="mailto:patrick@reini.net">Patrick Reinhart</a>
*/
class QueryResultCacheTest {
QueryResultCache cache = new QueryResultCache();
TestCachedResult cachedResult = new TestCachedResult();
Expand All @@ -44,7 +47,7 @@ void testGet() {
}

@Test
void TestGetResult() {
void testGetResult() {
assertThat(cache.getResult(-1)).isNull();
assertThat(cache.getResult(0)).isNull();
assertThat(cache.getResult(1)).isNull();
Expand Down
56 changes: 52 additions & 4 deletions exist-core/src/test/java/org/exist/xmlrpc/XmlRpcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.*;

import java.util.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.junit.After;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -323,7 +328,7 @@ public void uploadCompressedAndDownload() throws IOException, XmlRpcException {
// 2) download
final List<Object> params = new ArrayList<>();
params.add(resURI);
params.add(Collections.emptyMap());
params.add(Map.of());
Map table = (Map) xmlrpc.execute("getDocumentData", params);
try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
long offset = (int) table.get("offset");
Expand Down Expand Up @@ -473,6 +478,7 @@ public void testAddAccount() throws MalformedURLException, XmlRpcException {
String passwd = "pass";
String simpleMd5 = MessageDigester.md5(passwd, true);
String digest = MessageDigester.md5(user + ":exist:" + passwd, false);

List<Object> params = new ArrayList<>(12);
params.add("rudi");
params.add(simpleMd5);
Expand All @@ -482,13 +488,37 @@ public void testAddAccount() throws MalformedURLException, XmlRpcException {
params.add(Permission.DEFAULT_UMASK);
params.add(new HashMap<>());

XmlRpcClient xmlrpc = getClient();
final XmlRpcClient xmlrpc = getClient();
xmlrpc.execute("addAccount", params);

XmlRpcClientConfigImpl config = (XmlRpcClientConfigImpl) xmlrpc.getClientConfig();
config.setBasicUserName("admin");
config.setBasicPassword("");
xmlrpc.execute("sync", Collections.EMPTY_LIST);
assertThat(xmlrpc.execute("sync", List.of())).isEqualTo(TRUE);

Object[] accounts = (Object[])xmlrpc.execute("getAccounts", List.of());
assertThat(accounts).hasSize(5);

for (Object account : accounts) {
Map<String, Object> accountInfo = (Map<String, Object>)account;
assertThat(accountInfo).hasSize(9);
String name = (String)accountInfo.get("name");
assertThat((Map<String, Object>)xmlrpc.execute("getAccount", List.of(name)))
.containsExactlyEntriesOf(accountInfo);
}
}

@Test
public void testGetGroups() throws XmlRpcException, MalformedURLException {
final XmlRpcClient xmlrpc = getClient();

Object[] groups = (Object[])xmlrpc.execute("getGroups", List.of());
assertThat(groups).containsExactly("dba", "guest", "nogroup");

for (Object groupName : groups) {
assertThat((Map<String, Object>)xmlrpc.execute("getGroup", List.of(groupName)))
.hasSize(5).containsEntry("name", groupName);
}
}

@Test
Expand Down Expand Up @@ -731,6 +761,24 @@ public void testListCollectionPermissions() throws XmlRpcException, MalformedUR
assertThat((Map<String, List>)xmlrpc.execute("listCollectionPermissions", params)).isNotEmpty();
}

@Test
public void testGetCreationDate() throws XmlRpcException, MalformedURLException {
final XmlRpcClient xmlrpc = storeData();

List<Object> params = new ArrayList<>();
params.add(TARGET_COLLECTION.toString());
assertThat((Date)xmlrpc.execute("getCreationDate", params)).isNotNull();
}

@Test
public void testGetTimestamps() throws XmlRpcException, MalformedURLException {
final XmlRpcClient xmlrpc = storeData();

List<Object> params = new ArrayList<>();
params.add(TARGET_RESOURCE.toString());
assertThat((Object[])xmlrpc.execute("getTimestamps", params)).isNotEmpty();
}

private String generateXml(final int minBytes) {
int bytes = 0;
final StringBuilder builder = new StringBuilder("<container>");
Expand Down

0 comments on commit fb84125

Please sign in to comment.