Skip to content

Commit

Permalink
Make repo tests passing
Browse files Browse the repository at this point in the history
The implementation is still very fragile/incomplete: provisioning
tests are failing. Moreover, RAssignment-RAssignmentExtension
relation is artificially made 1:N (instead of 1:1); until appropriate
hibernate annotations are found.
  • Loading branch information
mederly committed Jan 31, 2018
1 parent 4e1271b commit e7b4073
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 80 deletions.
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2010-2018 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.evolveum.midpoint.repo.sql;

import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;

import java.io.File;

/**
* @author mederly
*/
@ContextConfiguration(locations = {"../../../../../ctx-test.xml"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class DeleteTestSimple extends BaseSQLRepoTest {

private static final Trace LOGGER = TraceManager.getTrace(DeleteTestSimple.class);

@Test
public void delete001() throws Exception {
PrismObject<UserType> user = prismContext.parseObject(new File(FOLDER_BASIC, "user0.xml"));

OperationResult result = new OperationResult("Delete Test");
String oid = repositoryService.addObject(user, null, result);
LOGGER.info("*** deleteObject ***");

// Session session = open();
// CriteriaQuery<RAssignment> aQ = session.getCriteriaBuilder().createQuery(RAssignment.class);
// aQ.select(aQ.from(RAssignment.class));
// List<RAssignment> aList = session.createQuery(aQ).getResultList();
// System.out.println("RAssignment: " + aList);
//
// CriteriaQuery<RAssignmentExtension> aeQ = session.getCriteriaBuilder().createQuery(RAssignmentExtension.class);
// aeQ.select(aeQ.from(RAssignmentExtension.class));
// List<RAssignmentExtension> aeList = session.createQuery(aeQ).getResultList();
// System.out.println("RAssignmentExtension: " + aeList);
//
// CriteriaQuery<RAExtBoolean> aebQ = session.getCriteriaBuilder().createQuery(RAExtBoolean.class);
// aebQ.select(aebQ.from(RAExtBoolean.class));
// List<RAExtBoolean> aebList = session.createQuery(aebQ).getResultList();
// System.out.println("RAExtBoolean: " + aebList);
//
// session.getTransaction().commit();

repositoryService.deleteObject(UserType.class, oid, result);
}
}
Expand Up @@ -23,6 +23,10 @@
import com.evolveum.midpoint.prism.schema.SchemaRegistry;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.repo.sql.data.common.any.RAExtBoolean;
import com.evolveum.midpoint.repo.sql.data.common.any.RAssignmentExtension;
import com.evolveum.midpoint.repo.sql.data.common.any.RExtItem;
import com.evolveum.midpoint.repo.sql.data.common.container.RAssignment;
import com.evolveum.midpoint.repo.sql.query.QueryException;
import com.evolveum.midpoint.repo.sql.query.RQuery;
import com.evolveum.midpoint.repo.sql.query2.QueryEngine2;
Expand Down Expand Up @@ -59,6 +63,7 @@
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import javax.persistence.criteria.CriteriaQuery;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import java.io.File;
Expand Down Expand Up @@ -3095,6 +3100,22 @@ public void test640queryAssignmentExtensionBoolean() throws Exception {
" b.value = :value";
assertEqualsIgnoreWhitespace(expected, real);

// include dependency on for this code org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
// CriteriaQuery<RAssignment> aQ = session.getCriteriaBuilder().createQuery(RAssignment.class);
// aQ.select(aQ.from(RAssignment.class));
// List<RAssignment> aList = session.createQuery(aQ).getResultList();
// System.out.println("RAssignment: " + aList);
//
// CriteriaQuery<RAssignmentExtension> aeQ = session.getCriteriaBuilder().createQuery(RAssignmentExtension.class);
// aeQ.select(aeQ.from(RAssignmentExtension.class));
// List<RAssignmentExtension> aeList = session.createQuery(aeQ).getResultList();
// System.out.println("RAssignmentExtension: " + aeList);
//
// CriteriaQuery<RAExtBoolean> aebQ = session.getCriteriaBuilder().createQuery(RAExtBoolean.class);
// aebQ.select(aebQ.from(RAExtBoolean.class));
// List<RAExtBoolean> aebList = session.createQuery(aebQ).getResultList();
// System.out.println("RAExtBoolean: " + aebList);
//
OperationResult result = new OperationResult("search");
List<PrismObject<UserType>> objects = repositoryService.searchObjects(UserType.class,
objectQuery, null, result);
Expand Down
25 changes: 25 additions & 0 deletions repo/repo-sql-impl-test/src/test/resources/basic/user0.xml
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<!--
~ Copyright (c) 2010-2018 Evolveum
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<user>
<name>user0</name>
<assignment id="1">
<extension>
<skipAutogeneration>true</skipAutogeneration>
</extension>
</assignment>
</user>
Expand Up @@ -20,6 +20,7 @@
import com.evolveum.midpoint.repo.sql.data.common.type.RAssignmentExtensionType;
import com.evolveum.midpoint.repo.sql.data.common.type.RObjectExtensionType;

import java.beans.Transient;
import java.util.Objects;

abstract public class RAExtBase<T> extends RAnyBase<T> implements RAExtValue<T> {
Expand All @@ -34,6 +35,16 @@ public RAssignmentExtension getAnyContainer() {
return anyContainer;
}

// @Transient
// public String getAssignmentOwnerOid() {
// return anyContainer != null ? anyContainer.getAssignmentOwnerOid() : null;
// }

// @Transient
// public Integer getAssignmentId() {
// return anyContainer != null ? anyContainer.getAssignmentId() : null;
// }

@Override
public void setAnyContainer(RAssignmentExtension anyContainer) {
this.anyContainer = anyContainer;
Expand All @@ -58,13 +69,22 @@ public boolean equals(Object o) {
if (!super.equals(o))
return false;
RAExtBase<?> raExtBase = (RAExtBase<?>) o;
return Objects.equals(getAnyContainer(), raExtBase.getAnyContainer()) &&
return /*Objects.equals(getAssignmentOwnerOid(), raExtBase.getAssignmentOwnerOid()) &&
Objects.equals(getAssignmentId(), raExtBase.getAssignmentId()) && */
getExtensionType() == raExtBase.getExtensionType();
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), getAnyContainer(), getExtensionType());
return Objects.hash(super.hashCode(), /*getAssignmentOwnerOid(), getAssignmentId(), */ getExtensionType());
}

@Override
public String toString() {
return getClass().getSimpleName() + "{" +
"item=" + getItem() +
", value=" + getValue() +
'}';
}

// public RObject getOwner() {
Expand Down
Expand Up @@ -42,7 +42,7 @@ public RAExtBoolean(Boolean value) {

@Id
// @MapsId("owner")
@ManyToOne(fetch = FetchType.LAZY, optional = false, cascade = {CascadeType.PERSIST})
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumns(value = {
@JoinColumn(name = "anyContainer_owner_owner_oid", referencedColumnName = "owner_owner_oid"),
@JoinColumn(name = "anyContainer_owner_id", referencedColumnName = "owner_id") },
Expand Down

0 comments on commit e7b4073

Please sign in to comment.