Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
ledsoft committed Sep 13, 2021
2 parents c791449 + 4e061a7 commit def5485
Show file tree
Hide file tree
Showing 27 changed files with 127 additions and 139 deletions.
4 changes: 4 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# JOPA - Release Notes

## 0.17.1 - September 13, 2021
- Switch back to the resurrected official [aspectj-maven-plugin](https://github.com/mojohaus/aspectj-maven-plugin) which allows running on JDK up to 16.
- Dependency updates: RDF4J 3.7.2, OWL API 5.1.19.

## 0.17.0 - June 29, 2021
- Add support for SPARQL-based entity attributes (Feature #65).
- Add support for Criteria API (Feature #20).
Expand Down
2 changes: 1 addition & 1 deletion jopa-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cz.cvut.kbss.jopa</groupId>
<artifactId>jopa-all</artifactId>
<version>0.17.0</version>
<version>0.17.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion jopa-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cz.cvut.kbss.jopa</groupId>
<artifactId>jopa-all</artifactId>
<version>0.17.0</version>
<version>0.17.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions jopa-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cz.cvut.kbss.jopa</groupId>
<artifactId>jopa-all</artifactId>
<version>0.17.0</version>
<version>0.17.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -70,7 +70,7 @@
</executions>
</plugin>
<plugin>
<groupId>com.nickwongdev</groupId>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<configuration combine.self="override">
<complianceLevel>${jdk.version}</complianceLevel>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Copyright (C) 2020 Czech Technical University in Prague
*
* <p>
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* <p>
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
Expand All @@ -15,7 +15,6 @@
package cz.cvut.kbss.jopa.oom;

import cz.cvut.kbss.jopa.exceptions.StorageAccessException;
import cz.cvut.kbss.jopa.model.MetamodelImpl;
import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
import cz.cvut.kbss.jopa.model.metamodel.*;
import cz.cvut.kbss.jopa.oom.exceptions.EntityDeconstructionException;
Expand Down Expand Up @@ -46,7 +45,6 @@ public class ObjectOntologyMapperImpl implements ObjectOntologyMapper, EntityMap
private final UnitOfWorkImpl uow;
private final CacheManager cache;
private final Connection storageConnection;
private final MetamodelImpl metamodel;

private final AxiomDescriptorFactory descriptorFactory;
private final EntityConstructor entityBuilder;
Expand All @@ -61,19 +59,18 @@ public ObjectOntologyMapperImpl(UnitOfWorkImpl uow, Connection connection) {
this.uow = Objects.requireNonNull(uow);
this.cache = uow.getLiveObjectCache();
this.storageConnection = Objects.requireNonNull(connection);
this.metamodel = uow.getMetamodel();
this.descriptorFactory = new AxiomDescriptorFactory();
this.instanceRegistry = new HashMap<>();
this.pendingReferences = new PendingReferenceRegistry();
this.entityBuilder = new EntityConstructor(this);
this.entityBreaker = new EntityDeconstructor(this);

this.defaultInstanceLoader = DefaultInstanceLoader.builder().connection(storageConnection).metamodel(metamodel)
.descriptorFactory(descriptorFactory)
.entityBuilder(entityBuilder).cache(cache).build();
this.twoStepInstanceLoader = TwoStepInstanceLoader.builder().connection(storageConnection).metamodel(metamodel)
.descriptorFactory(descriptorFactory)
.entityBuilder(entityBuilder).cache(cache).build();
this.defaultInstanceLoader = DefaultInstanceLoader.builder().connection(storageConnection).metamodel(uow.getMetamodel())
.descriptorFactory(descriptorFactory)
.entityBuilder(entityBuilder).cache(cache).build();
this.twoStepInstanceLoader = TwoStepInstanceLoader.builder().connection(storageConnection).metamodel(uow.getMetamodel())
.descriptorFactory(descriptorFactory)
.entityBuilder(entityBuilder).cache(cache).build();
}

@Override
Expand Down Expand Up @@ -129,7 +126,7 @@ public <T> T loadReference(LoadingParameters<T> loadingParameters) {

@Override
public <T> EntityTypeImpl<T> getEntityType(Class<T> cls) {
return metamodel.entity(cls);
return uow.getMetamodel().entity(cls);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ protected static Constructor<?> getDeclaredConstructorFor(final Class<?> javaCla
} catch (NoSuchMethodException e) {
// No constructor matching the argument types
return null;
} catch (RuntimeException e) {
// Constructor cannot be resolved for some other reason
LOG.warn("Unable to get constructor for arguments of type {}. Got runtime exception {}.", args, e);
return null;
}
return c;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ Object buildClone(Object cloneOwner, Field field, Object original, CloneConfigur
if (clone == null) {
if (singletonMapClass.isInstance(orig)) {
clone = buildSingletonClone(cloneOwner, field, orig, configuration);
} else {
} else if (Collections.emptyMap().equals(orig)) {
clone = orig;
}
else {
throw new IllegalArgumentException("Unsupported map type " + origCls);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Copyright (C) 2020 Czech Technical University in Prague
*
* <p>
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* <p>
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
Expand All @@ -24,7 +24,6 @@
import cz.cvut.kbss.ontodriver.model.Value;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
Expand Down Expand Up @@ -89,17 +88,9 @@ public static boolean assertionsCorrespondToProperties(Map properties, Map<Asser
public static void setMock(Object target, Field field, Object mock) throws Exception {
assert field != null;
field.setAccessible(true);
removeFinalModifier(field);
field.set(target, mock);
}

private static void removeFinalModifier(Field field) throws Exception {
// remove final modifier from field
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
}

public static Set<Class<?>> getManagedTypes() {
if (managedTypes == null) {
initManagedTypes();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Copyright (C) 2020 Czech Technical University in Prague
*
* <p>
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* <p>
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
Expand All @@ -29,25 +29,34 @@
import cz.cvut.kbss.jopa.model.descriptors.EntityDescriptor;
import cz.cvut.kbss.jopa.sessions.*;
import cz.cvut.kbss.jopa.transactions.EntityTransaction;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;

import java.lang.reflect.Field;
import java.util.Collections;

import static org.junit.Assert.assertSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.*;

/**
* Verifies entity lifecycle listener behavior w.r.t. the JPA 2.1 spec.
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
public class EntityLifecycleListenersTest {

private Descriptor descriptor;

@Mock
private EntityTransaction transactionMock;

@Mock
private MetamodelImpl metamodelMock;

Expand All @@ -60,20 +69,19 @@ public class EntityLifecycleListenersTest {
@Mock
private EntityManagerImpl emMock;

private UnitOfWorkImpl uow;

private ParentListener parentListenerMock;
private ConcreteListener concreteListenerMock;
private AnotherListener anotherListenerMock;

private UnitOfWorkImpl uow;

@Before
@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.openMocks(this);
Mockito.lenient();
this.descriptor = new EntityDescriptor();
final ServerSessionStub serverSessionStub = spy(new ServerSessionStub(storageMock));
when(serverSessionStub.getMetamodel()).thenReturn(metamodelMock);
when(serverSessionStub.getLiveObjectCache()).thenReturn(mock(CacheManager.class));
final EntityTransaction transactionMock = mock(EntityTransaction.class);
when(emMock.getTransaction()).thenReturn(transactionMock);
when(transactionMock.isActive()).thenReturn(true);
final MetamodelMocks mocks = new MetamodelMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ void setUp() throws Exception {
mocks.setMocks(metamodelMock);
this.etAMock = mocks.forOwlClassA().entityType();
when(descriptorFactoryMock.createForEntityLoading(loadingParameters, etAMock)).thenReturn(axiomDescriptor);
when(
descriptorFactoryMock.createForFieldLoading(IDENTIFIER, OWLClassA.getTypesField(),
aDescriptor, mocks.forOwlClassA().entityType())).thenReturn(axiomDescriptor);
when(descriptorFactoryMock.createForFieldLoading(IDENTIFIER, OWLClassA.getTypesField(),
aDescriptor, mocks.forOwlClassA().entityType())).thenReturn(axiomDescriptor);
entityA.setTypes(null);
this.mapper = new ObjectOntologyMapperImpl(uowMock, connectionMock);
TestEnvironmentUtils.setMock(mapper,
Expand Down Expand Up @@ -490,8 +489,6 @@ void checkForUnpersistedChangesThrowsPendingPersistExceptionWhenThereArePendingC

@Test
void removeEntityRemovesPendingReferenceWhenOwnerIsRemoved() throws Exception {
final OWLClassD owner = new OWLClassD(IDENTIFIER);
owner.setOwlClassA(entityA);
final Assertion assertion =
Assertion.createObjectPropertyAssertion(URI.create(Vocabulary.P_HAS_A), false);
final Descriptor descriptor = new EntityDescriptor();
Expand All @@ -503,8 +500,9 @@ void removeEntityRemovesPendingReferenceWhenOwnerIsRemoved() throws Exception {
.createForEntityLoading(new LoadingParameters<>(OWLClassD.class, IDENTIFIER, descriptor, true),
metamodelMock.entity(OWLClassD.class))).thenReturn(axiomDescriptor);

mapper.removeEntity(IDENTIFIER, OWLClassD.class, descriptor);
final PendingReferenceRegistry registry = getPendingAssertionRegistry();
assertTrue(registry.getPendingResources().contains(entityA));
mapper.removeEntity(IDENTIFIER, OWLClassD.class, descriptor);
assertFalse(registry.getPendingResources().contains(entityA));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import cz.cvut.kbss.jopa.sessions.change.ChangeRecordImpl;
import cz.cvut.kbss.jopa.sessions.change.ChangeSetFactory;
import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

Expand All @@ -39,7 +39,7 @@
import java.util.*;
import java.util.Map.Entry;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

public class CloneBuilderTest {
Expand All @@ -63,7 +63,7 @@ public class CloneBuilderTest {

private MetamodelMocks metamodelMocks;

@BeforeClass
@BeforeAll
public static void setUpBeforeClass() {
initManagedTypes();
defaultDescriptor = new EntityDescriptor();
Expand All @@ -82,7 +82,7 @@ private static void initManagedTypes() {
managedTypes.add(OWLClassQ.class);
}

@Before
@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.openMocks(this);
when(uow.isEntityType(any())).thenAnswer(invocation -> {
Expand Down Expand Up @@ -117,10 +117,6 @@ private void initValues() {
types.add("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityU");
types.add("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityX");
entityA.setTypes(types);
OWLClassA t2 = new OWLClassA();
final URI pk2 = URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityAA");
t2.setUri(pk2);
t2.setStringAttribute("TEST2");
entityB = new OWLClassB();
entityB.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityB"));
entityB.setStringAttribute("someString");
Expand All @@ -147,20 +143,19 @@ public void testBuildClone() {
assertEquals(entityA.getTypes(), res.getTypes());
}

@Test(expected = NullPointerException.class)
@Test
public void testBuildCloneNullOriginal() {
builder.buildClone(null, new CloneConfiguration(defaultDescriptor));
fail("This line should not have been reached.");
assertThrows(NullPointerException.class, () -> builder.buildClone(null, new CloneConfiguration(defaultDescriptor)));
}

@Test(expected = NullPointerException.class)
@Test
public void testBuildCloneNullContextUri() {
builder.buildClone(entityA, null);
assertThrows(NullPointerException.class, () -> builder.buildClone(entityA, null));
}

@Test(expected = NullPointerException.class)
public void testBuildCloneNullCloneOwner() throws Exception {
builder.buildClone(null, OWLClassB.getPropertiesField(), entityB, defaultDescriptor);
@Test
public void testBuildCloneNullCloneOwner() {
assertThrows(NullPointerException.class, () -> builder.buildClone(null, OWLClassB.getPropertiesField(), entityB, defaultDescriptor));
}

@Test
Expand Down Expand Up @@ -428,7 +423,7 @@ public void testMergeChangesRefListFromNull() {
assertNotNull(entityC.getReferencedList());
for (int i = 0; i < c.getReferencedList().size(); i++) {
assertEquals(c.getReferencedList().get(i).getUri(), entityC.getReferencedList().get(i)
.getUri());
.getUri());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ protected ConnectionWrapper acquireConnection() {
return connection;
}

@Override
public MetamodelImpl getMetamodel() {
// Just exporting API as public so that we can stub it with Mockito
return null;
}

@Override
public boolean isEntityType(Class<?> cls) {
return TestEnvironmentUtils.getManagedTypes().contains(cls);
Expand Down
Loading

0 comments on commit def5485

Please sign in to comment.