Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable a bunch of tests. #2075

Merged
merged 4 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
*/
package org.fcrepo.auth.webac;

import static java.util.stream.Stream.of;
import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static org.apache.jena.riot.WebContent.contentTypeSPARQLUpdate;
import static org.fcrepo.auth.common.ServletContainerAuthFilter.FEDORA_ADMIN_ROLE;
import static org.fcrepo.auth.common.ServletContainerAuthFilter.FEDORA_USER_ROLE;
Expand All @@ -26,11 +23,9 @@
import static org.mockito.Mockito.when;
import static org.springframework.test.util.ReflectionTestUtils.setField;

import org.fcrepo.config.FedoraPropsConfig;
import org.fcrepo.kernel.api.TransactionManager;
import org.fcrepo.kernel.api.exception.PathNotFoundException;
import org.fcrepo.kernel.api.identifiers.FedoraId;
import org.fcrepo.kernel.api.models.ResourceFactory;
import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static java.util.stream.Stream.of;

import java.net.URI;
import java.util.ArrayList;
Expand All @@ -41,13 +36,17 @@
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.subject.support.SubjectThreadState;
import org.fcrepo.config.FedoraPropsConfig;
import org.fcrepo.kernel.api.Transaction;
import org.fcrepo.kernel.api.models.Container;
import org.fcrepo.kernel.api.TransactionManager;
import org.fcrepo.kernel.api.exception.PathNotFoundException;
import org.fcrepo.kernel.api.identifiers.FedoraId;
import org.fcrepo.kernel.api.models.Binary;
import org.fcrepo.kernel.api.models.Container;
import org.fcrepo.kernel.api.models.FedoraResource;
import org.fcrepo.kernel.api.models.ResourceFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -544,7 +543,6 @@ public void testAuthUserReadAppendPatchSparqlNoContent() throws Exception {
assertEquals(SC_OK, response.getStatus());
}

@Ignore // TODO FIX THIS TEST
@Test
public void testAuthUserReadAppendPatchSparqlInvalidContent() throws Exception {
setupAuthUserReadAppend();
Expand All @@ -557,7 +555,6 @@ public void testAuthUserReadAppendPatchSparqlInvalidContent() throws Exception {
assertEquals(SC_FORBIDDEN, response.getStatus());
}

@Ignore // TODO FIX THIS TEST
@Test
public void testAuthUserReadAppendPatchSparqlInsert() throws Exception {
setupAuthUserReadAppend();
Expand All @@ -572,7 +569,6 @@ public void testAuthUserReadAppendPatchSparqlInsert() throws Exception {
assertEquals(SC_OK, response.getStatus());
}

@Ignore // TODO FIX THIS TEST
@Test
public void testAuthUserReadAppendPatchSparqlDelete() throws Exception {
setupAuthUserReadAppend();
Expand All @@ -587,7 +583,6 @@ public void testAuthUserReadAppendPatchSparqlDelete() throws Exception {
assertEquals(SC_FORBIDDEN, response.getStatus());
}

@Ignore // TODO FIX THIS TEST
@Test
public void testAuthUserAppendPostContainer() throws Exception {
setupAuthUserAppendOnly();
Expand All @@ -609,7 +604,6 @@ public void testAuthUserAppendPostBinary() throws Exception {
assertEquals(SC_FORBIDDEN, response.getStatus());
}

@Ignore // TODO FIX THIS TEST
@Test
public void testAuthUserAppendDelete() throws Exception {
setupAuthUserAppendOnly();
Expand All @@ -620,7 +614,6 @@ public void testAuthUserAppendDelete() throws Exception {
assertEquals(SC_FORBIDDEN, response.getStatus());
}

@Ignore // TODO FIX THIS TEST
@Test
public void testAuthUserReadAppendPostContainer() throws Exception {
setupAuthUserReadAppend();
Expand All @@ -642,7 +635,6 @@ public void testAuthUserReadAppendPostBinary() throws Exception {
assertEquals(SC_FORBIDDEN, response.getStatus());
}

@Ignore // TODO FIX THIS TEST
@Test
public void testAuthUserReadAppendDelete() throws Exception {
setupAuthUserReadAppend();
Expand Down Expand Up @@ -720,7 +712,6 @@ public void testAuthUserReadWritePut() throws Exception {
assertEquals(SC_OK, response.getStatus());
}

@Ignore // TODO FIX THIS TEST
@Test
public void testAuthUserReadWritePatch() throws Exception {
setupAuthUserReadWrite();
Expand All @@ -730,7 +721,6 @@ public void testAuthUserReadWritePatch() throws Exception {
assertEquals(SC_OK, response.getStatus());
}

@Ignore // TODO FIX THIS TEST
@Test
public void testAuthUserReadWriteDelete() throws Exception {
setupAuthUserReadWrite();
Expand All @@ -740,7 +730,6 @@ public void testAuthUserReadWriteDelete() throws Exception {
assertEquals(SC_OK, response.getStatus());
}

@Ignore // TODO FIX THIS TEST
@Test
public void testAuthUserReadAppendWriteDelete() throws Exception {
setupAuthUserReadAppendWrite();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package org.fcrepo.auth.webac;

import static java.util.Collections.singletonList;
import static org.apache.jena.graph.NodeFactory.createURI;
import static org.apache.jena.rdf.model.ModelFactory.createDefaultModel;
import static org.apache.jena.riot.Lang.TTL;
Expand All @@ -22,6 +21,8 @@
import static org.mockito.Mockito.when;
import static org.springframework.test.util.ReflectionTestUtils.setField;

import static java.util.Collections.singletonList;

import java.net.URI;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand All @@ -30,6 +31,12 @@
import java.util.Map;
import java.util.Optional;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.apache.jena.graph.Triple;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr;
import org.fcrepo.config.AuthPropsConfig;
import org.fcrepo.kernel.api.RdfStream;
import org.fcrepo.kernel.api.Transaction;
Expand All @@ -40,23 +47,14 @@
import org.fcrepo.kernel.api.models.FedoraResource;
import org.fcrepo.kernel.api.models.ResourceFactory;
import org.fcrepo.kernel.api.rdf.DefaultRdfStream;

import org.apache.jena.graph.Triple;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.riot.Lang;
import org.apache.jena.riot.RDFDataMgr;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.RestoreSystemProperties;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;

/**
* @author acoburn
* @since 9/3/15
Expand Down Expand Up @@ -134,7 +132,6 @@ public void noAclTest() throws RepositoryException {
assertOnlyDefaultAgentInRoles(roles);
}

@Ignore // TODO FIX THIS TEST
@Test
public void acl01ParentTest() throws RepositoryException {
final String agent = "user01";
Expand All @@ -148,7 +145,6 @@ public void acl01ParentTest() throws RepositoryException {
when(mockResource.getId()).thenReturn(addPrefix(accessTo));
when(mockResource.getContainer()).thenReturn(mockParentResource);
when(mockResource.getOriginalResource()).thenReturn(mockResource);
when(mockResource.getAcl()).thenReturn(mockAclResource);

when(mockParentResource.getId()).thenReturn(addPrefix(parentPath));
when(mockParentResource.getAcl()).thenReturn(mockAclResource);
Expand Down Expand Up @@ -228,7 +224,6 @@ public void acl01Test1() throws RepositoryException, PathNotFoundException {
assertTrue("The agent should be able to write", roles.get(agent).contains(WEBAC_MODE_WRITE_VALUE));
}

@Ignore // TODO FIX THIS TEST
@Test
public void acl01Test2() throws RepositoryException, PathNotFoundException {
final String accessTo = "/webacl_box2";
Expand Down Expand Up @@ -489,7 +484,6 @@ public void acl09Test1() throws RepositoryException, PathNotFoundException {
* the rdf:type of foaf:Group. This test mocks a resource that is not of the type
* foaf:Group and therefore should retrieve zero agents.
*/
@Ignore // TODO FIX THIS TEST
@Test
public void acl09Test2() throws RepositoryException, PathNotFoundException {
final String accessTo = "/anotherCollection";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,70 @@
import static org.apache.jena.graph.NodeFactory.createLiteral;
import static org.apache.jena.graph.NodeFactory.createURI;
import static org.apache.jena.vocabulary.RDF.type;
import static java.util.Collections.singletonMap;
import static java.util.stream.Stream.of;
import static javax.ws.rs.core.MediaType.TEXT_HTML_TYPE;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE;

import static org.fcrepo.http.commons.session.TransactionConstants.ATOMIC_ID_HEADER;
import static org.fcrepo.kernel.api.FedoraTypes.FEDORA_ID_PREFIX;
import static org.fcrepo.kernel.api.RdfLexicon.FEDORA_BINARY;
import static org.fcrepo.kernel.api.RdfLexicon.FEDORA_CONTAINER;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.springframework.test.util.ReflectionTestUtils.setField;

import static javax.ws.rs.core.MediaType.TEXT_HTML_TYPE;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE;
import static java.util.Collections.singletonMap;
import static java.util.stream.Stream.of;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Writer;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.net.URI;
import java.nio.file.Path;
import java.util.Map;
import java.util.stream.Stream;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;

import com.google.common.collect.ImmutableMap;
import org.apache.jena.graph.Triple;
import org.apache.velocity.Template;
import org.apache.velocity.context.Context;
import org.fcrepo.config.FedoraPropsConfig;
import org.fcrepo.config.OcflPropsConfig;
import org.fcrepo.config.SystemInfoConfig;
import org.fcrepo.http.commons.responses.HtmlTemplate;
import org.fcrepo.http.commons.responses.RdfNamespacedStream;
import org.fcrepo.kernel.api.RdfStream;
import org.fcrepo.kernel.api.Transaction;
import org.fcrepo.kernel.api.identifiers.FedoraId;
import org.fcrepo.kernel.api.models.FedoraResource;
import org.fcrepo.kernel.api.models.ResourceFactory;
import org.fcrepo.kernel.api.rdf.DefaultRdfStream;

import org.apache.velocity.Template;
import org.apache.velocity.context.Context;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;

import com.google.common.collect.ImmutableMap;
import org.apache.jena.graph.Triple;

/**
* <p>BaseHtmlProviderTest class.</p>
*
* @author awoods
*/
@Ignore // TODO fix these tests
@RunWith(MockitoJUnitRunner.class)
public class StreamingBaseHtmlProviderTest {

Expand All @@ -74,28 +83,75 @@ public class StreamingBaseHtmlProviderTest {
@Mock
private UriInfo mockUriInfo;

@Mock
private SystemInfoConfig mockSystemInfoConfig;

@Mock
private ResourceFactory mockResourceFactory;

@Mock
private FedoraResource mockResource1;

@Mock
private FedoraResource mockResource2;

@Mock
private HttpServletRequest mockRequest;

@Mock
private FedoraPropsConfig mockFedoraPropsConfig;

@Before
public void setup() throws Exception {

final Stream<Triple> triples = of(new Triple(createURI("test:subject"), createURI("test:predicate"),
createLiteral("test:object")), new Triple(createURI("test:subject"), type.asNode(),
final var namespaces = Map.of("test", "info");
final var base_uri = "http://localhost:8080/rest/";
final var external_id1 = base_uri + "subject";
final var external_id2 = base_uri + "subject2";
final var internal_id1 = FEDORA_ID_PREFIX + "/subject";
final var internal_id2 = FEDORA_ID_PREFIX + "/subject2";
final Stream<Triple> triples = of(new Triple(createURI(external_id1), createURI("test:predicate"),
createLiteral("test:object")), new Triple(createURI(external_id1), type.asNode(),
FEDORA_BINARY.asNode()));
final Stream<Triple> triples2 = of(new Triple(createURI("test:subject2"), type.asNode(),
final Stream<Triple> triples2 = of(new Triple(createURI(external_id2), type.asNode(),
FEDORA_CONTAINER.asNode()));
@SuppressWarnings("resource")
final DefaultRdfStream stream = new DefaultRdfStream(createURI("test:subject"), triples);
final DefaultRdfStream stream = new DefaultRdfStream(createURI(external_id1), triples);
@SuppressWarnings("resource")
final DefaultRdfStream stream2 = new DefaultRdfStream(createURI("test:subject2"), triples2);
testData = new RdfNamespacedStream(stream, null);
final DefaultRdfStream stream2 = new DefaultRdfStream(createURI(external_id2), triples2);
testData = new RdfNamespacedStream(stream, namespaces);

testData2 = new RdfNamespacedStream(stream2, null);
testData2 = new RdfNamespacedStream(stream2, namespaces);

final URI baseUri = URI.create("http://localhost:8080/rest/");
final URI baseUri = URI.create(base_uri);
final UriBuilder baseUriBuilder = UriBuilder.fromUri(baseUri);
when(mockUriInfo.getBaseUri()).thenReturn(baseUri);
when(mockUriInfo.getBaseUriBuilder()).thenReturn(baseUriBuilder);
when(mockSystemInfoConfig.getGitCommit()).thenReturn("some-commit");
when(mockSystemInfoConfig.getImplementationVersion()).thenReturn("some-version");
when(mockRequest.getHeader(ATOMIC_ID_HEADER)).thenReturn(null);

when(mockResource1.isOriginalResource()).thenReturn(true);
when(mockResource1.getDescribedResource()).thenReturn(mockResource1);
when(mockResource2.isOriginalResource()).thenReturn(true);
when(mockResource2.getDescribedResource()).thenReturn(mockResource2);

when(mockResourceFactory.getResource(org.mockito.ArgumentMatchers.any(Transaction.class),
eq(FedoraId.create(internal_id1)))).thenReturn(mockResource1);
when(mockResourceFactory.getResource(org.mockito.ArgumentMatchers.any(Transaction.class),
eq(FedoraId.create(internal_id2)))).thenReturn(mockResource2);

when(mockFedoraPropsConfig.getVelocityLog()).thenReturn(Path.of("/logs"));
final var ocflProps = new OcflPropsConfig();
ocflProps.setAutoVersioningEnabled(true);
setField(testProvider, "ocflPropsConfig", ocflProps);
setField(testProvider, "fedoraPropsConfig", mockFedoraPropsConfig);

setField(testProvider, "uriInfo", mockUriInfo);
setField(testProvider, "systemInfoConfig", mockSystemInfoConfig);
setField(testProvider, "request", mockRequest);
setField(testProvider, "resourceFactory", mockResourceFactory);
testProvider.init();
}

@Test
Expand Down Expand Up @@ -139,8 +195,7 @@ public Object answer(final InvocationOnMock invocation) {
return "I am pretending to merge a template for you.";
}
}).when(mockTemplate).merge(isA(Context.class), isA(Writer.class));
setField(testProvider, "templatesMap", singletonMap(FEDORA_BINARY.getURI(),
mockTemplate));
setField(testProvider, "templatesMap", singletonMap(FEDORA_BINARY.getURI(), mockTemplate));
testProvider.writeTo(testData, RdfNamespacedStream.class, mock(Type.class),
new Annotation[]{}, MediaType.valueOf("text/html"),
new MultivaluedHashMap<>(), outStream);
Expand Down
Loading
Loading