Skip to content

Commit

Permalink
JDO-844: Add SampleReadQuery test methods with variables of type Stri…
Browse files Browse the repository at this point in the history
…ng (#97)

* JDO-844: Add SampleReadQuery test methods with variables of type String

* JDO-844: added code review comments from Tilmann
  • Loading branch information
mboapache authored Nov 12, 2024
1 parent ad37e97 commit a7bd089
Show file tree
Hide file tree
Showing 41 changed files with 890 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public class FetchGroupTest extends JDO_Test {
"middlename",
"birthdate",
"address",
"phoneNumbers"
"phoneNumbers",
"languages"
};
/** Address address is of type Address and is a relationship */
protected final String[] relationshipMembers =
Expand All @@ -112,9 +113,11 @@ public class FetchGroupTest extends JDO_Test {
"hradvisees",
"address"
};
/** Map phoneNumbers is not a relationship but is multivalued */
/** Map phoneNumbers and set languages are not relationships but are multivalued */
protected final String[] multivaluedMembers =
new String[] {"reviewedProjects", "projects", "team", "hradvisees", "phoneNumbers"};
new String[] {
"reviewedProjects", "projects", "team", "hradvisees", "phoneNumbers", "languages"
};

protected final String[] allButMultivaluedMembers =
new String[] {
Expand Down Expand Up @@ -336,16 +339,21 @@ public void testRemoveMembers() {
Set<String> expectedSet = new HashSet<>();
expectedSet.addAll(Arrays.asList(basicMembers));
expectedSet.add("phoneNumbers");
expectedSet.add("languages");
Assertions.assertEquals(
expectedSet,
members,
"FetchGroup should contain basic members " + "plus address plus phoneNumbers.\n");
"FetchGroup should contain basic members "
+ "plus address plus phoneNumbers and languages.\n");
fg.removeMembers(basicMembers);
members = fg.getMembers();
expectedSet = new HashSet<>();
expectedSet.add("phoneNumbers");
expectedSet.add("languages");
Assertions.assertEquals(
expectedSet, members, "FetchGroup should contain address plus phoneNumbers.\n");
expectedSet,
members,
"FetchGroup should contain address plus phoneNumbers and languages.\n");
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected void insertObjects(boolean sharedPC) {

while (!attemptsComplete()) {
try {
Thread.sleep(100);
Thread.sleep(200);
} catch (InterruptedException ex) {
logger.debug("interrupted while waiting for threads to insert");
}
Expand Down
5 changes: 5 additions & 0 deletions tck/src/main/java/org/apache/jdo/tck/pc/company/IPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Date;
import java.util.Map;
import java.util.Set;

/**
* This interface represents the persistent state of Person. Javadoc was deliberately omitted
Expand All @@ -40,6 +41,8 @@ public interface IPerson {

Map<String, String> getPhoneNumbers();

Set<String> getLanguages();

void setPersonid(long personid);

void setLastname(String lastname);
Expand All @@ -53,4 +56,6 @@ public interface IPerson {
void setBirthdate(Date birthdate);

void setPhoneNumbers(Map<String, String> phoneNumbers);

void setLanguages(Set<String> languages);
}
5 changes: 5 additions & 0 deletions tck/src/main/java/org/apache/jdo/tck/pc/company/PIPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Date;
import java.util.Map;
import java.util.Set;

/**
* This interface represents the persistent state of Person. Javadoc was deliberately omitted
Expand All @@ -40,6 +41,8 @@ public interface PIPerson extends IPerson {

Map<String, String> getPhoneNumbers();

Set<String> getLanguages();

void setPersonid(long personid);

void setLastname(String lastname);
Expand All @@ -53,4 +56,6 @@ public interface PIPerson extends IPerson {
void setBirthdate(Date birthdate);

void setPhoneNumbers(Map<String, String> phoneNumbers);

void setLanguages(Set<String> languages);
}
26 changes: 25 additions & 1 deletion tck/src/main/java/org/apache/jdo/tck/pc/company/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.jdo.annotations.PersistenceCapable;
import org.apache.jdo.tck.util.DeepEquality;
import org.apache.jdo.tck.util.EqualityHelper;
Expand All @@ -46,6 +48,8 @@ public class Person
// to phone numbers specified as String
private Map<String, String> phoneNumbers = new HashMap<>();

private Set<String> languages = new HashSet<>();

/** This is the JDO-required no-args constructor. */
protected Person() {}

Expand Down Expand Up @@ -261,6 +265,24 @@ public void setPhoneNumbers(Map<String, String> phoneNumbers) {
this.phoneNumbers = (phoneNumbers != null) ? new HashMap<>(phoneNumbers) : null;
}

/**
* Get the set of languages as an unmodifiable set.
*
* @return The set of languages, as an unmodifiable set.
*/
public Set<String> getLanguages() {
return Collections.unmodifiableSet(languages);
}

/**
* Set the languages set to be in this person.
*
* @param languages The set of languages for this person.
*/
public void setLanguages(Set<String> languages) {
this.languages = new HashSet(languages);
}

/**
* Returns a String representation of a <code>Person</code> object.
*
Expand All @@ -282,6 +304,7 @@ protected String getFieldRepr() {
rc.append(", ").append(firstname);
rc.append(", born ").append(JDOCustomDateEditor.getDateRepr(birthdate));
rc.append(", phone ").append(phoneNumbers);
rc.append(", languages ").append(languages);
return rc.toString();
}

Expand All @@ -304,7 +327,8 @@ public boolean deepCompareFields(Object other, EqualityHelper helper) {
& helper.equals(middlename, otherPerson.getMiddlename(), where + ".middlename")
& helper.equals(birthdate, otherPerson.getBirthdate(), where + ".birthdate")
& helper.deepEquals(address, otherPerson.getAddress(), where + ".address")
& helper.deepEquals(phoneNumbers, otherPerson.getPhoneNumbers(), where + ".phoneNumbers");
& helper.deepEquals(phoneNumbers, otherPerson.getPhoneNumbers(), where + ".phoneNumbers")
& helper.deepEquals(languages, otherPerson.getLanguages(), where + ".languages");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.jdo.annotations.Column;
import javax.jdo.annotations.Element;
import javax.jdo.annotations.Embedded;
import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.InheritanceStrategy;
Expand Down Expand Up @@ -86,6 +89,11 @@ public class FCAppPerson
@Value(types = java.lang.String.class, column = "PHONENO")
private Map<String, String> phoneNumbers = new HashMap<>();

@Persistent(table = "employee_languages")
@Join(column = "EMPID")
@Element(types = java.lang.String.class, column = "LANGUAGE")
private Set<String> languages = new HashSet<>();

/** This is the JDO-required no-args constructor. */
protected FCAppPerson() {}

Expand Down Expand Up @@ -301,6 +309,24 @@ public void setPhoneNumbers(Map<String, String> phoneNumbers) {
this.phoneNumbers = (phoneNumbers != null) ? new HashMap<>(phoneNumbers) : null;
}

/**
* Get the map of languages as an unmodifiable Set.
*
* @return The set of languages, as an unmodifiable set.
*/
public Set<String> getLanguages() {
return Collections.unmodifiableSet(languages);
}

/**
* Set the languages set to be in this person.
*
* @param languages The map of phoneNumbers for this person.
*/
public void setLanguages(Set<String> languages) {
this.languages = new HashSet(languages);
}

/**
* Returns a String representation of a <code>FCAppPerson</code> object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.jdo.annotations.Column;
import javax.jdo.annotations.Element;
import javax.jdo.annotations.Embedded;
import javax.jdo.annotations.Join;
import javax.jdo.annotations.Key;
Expand Down Expand Up @@ -82,6 +85,11 @@ public class FCDSPerson
@Value(types = java.lang.String.class, column = "PHONENO")
private Map<String, String> phoneNumbers = new HashMap<>();

@Persistent(table = "employee_languages")
@Join(column = "EMPID")
@Element(types = java.lang.String.class, column = "LANGUAGE")
private Set<String> languages = new HashSet<>();

/** This is the JDO-required no-args constructor. */
protected FCDSPerson() {}

Expand Down Expand Up @@ -297,6 +305,24 @@ public void setPhoneNumbers(Map<String, String> phoneNumbers) {
this.phoneNumbers = (phoneNumbers != null) ? new HashMap<>(phoneNumbers) : null;
}

/**
* Get the map of languages as an unmodifiable Set.
*
* @return The set of languages, as an unmodifiable set.
*/
public Set<String> getLanguages() {
return Collections.unmodifiableSet(languages);
}

/**
* Set the languages set to be in this person.
*
* @param languages The map of phoneNumbers for this person.
*/
public void setLanguages(Set<String> languages) {
this.languages = new HashSet(languages);
}

/**
* Returns a String representation of a <code>FCDSPerson</code> object.
*
Expand All @@ -318,6 +344,7 @@ protected String getFieldRepr() {
rc.append(", ").append(firstname);
rc.append(", born ").append(JDOCustomDateEditor.getDateRepr(birthdate));
rc.append(", phone ").append(phoneNumbers);
rc.append(", languages ").append(languages);
return rc.toString();
}

Expand All @@ -340,7 +367,8 @@ public boolean deepCompareFields(Object other, EqualityHelper helper) {
& helper.equals(middlename, otherPerson.getMiddlename(), where + ".middlename")
& helper.equals(birthdate, otherPerson.getBirthdate(), where + ".birthdate")
& helper.deepEquals(address, otherPerson.getAddress(), where + ".address")
& helper.deepEquals(phoneNumbers, otherPerson.getPhoneNumbers(), where + ".phoneNumbers");
& helper.deepEquals(phoneNumbers, otherPerson.getPhoneNumbers(), where + ".phoneNumbers")
& helper.deepEquals(languages, otherPerson.getLanguages(), where + ".languages");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,30 @@
package org.apache.jdo.tck.pc.companyAnnotatedJPA;

import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.ElementCollection;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.Table;
Expand Down Expand Up @@ -90,6 +96,10 @@ public class JPAAppPerson
@MapKey(name = "type")
private Map<String, JPAAppPhoneNumber> phoneNumbers = new HashMap<>();

@ElementCollection
@CollectionTable(name = "employee_languages", joinColumns = @JoinColumn(name = "EMPID"))
private Set<String> languages = new HashSet<>();

/** This is the JDO-required no-args constructor. */
protected JPAAppPerson() {}

Expand Down Expand Up @@ -305,6 +315,24 @@ public void setPhoneNumbers(Map<String, String> phoneNumbers) {
this.phoneNumbers = (phoneNumbers != null) ? convertString2Phone(phoneNumbers) : null;
}

/**
* Get the map of languages as an unmodifiable Set.
*
* @return The set of languages, as an unmodifiable set.
*/
public Set<String> getLanguages() {
return Collections.unmodifiableSet(languages);
}

/**
* Set the languages set to be in this person.
*
* @param languages The map of phoneNumbers for this person.
*/
public void setLanguages(Set<String> languages) {
this.languages = new HashSet(languages);
}

/**
* Converts HashMap of String, String to HashMap of String, JPAAppPhoneNmber
*
Expand Down Expand Up @@ -360,6 +388,7 @@ protected String getFieldRepr() {
rc.append(", ").append(firstname);
rc.append(", born ").append(JDOCustomDateEditor.getDateRepr(birthdate));
rc.append(", phone ").append(convertPhone2String(phoneNumbers));
rc.append(", languages ").append(languages);
return rc.toString();
}

Expand All @@ -385,7 +414,8 @@ public boolean deepCompareFields(Object other, EqualityHelper helper) {
& helper.deepEquals(
convertPhone2String(phoneNumbers),
otherPerson.getPhoneNumbers(),
where + ".phoneNumbers");
where + ".phoneNumbers")
& helper.deepEquals(languages, otherPerson.getLanguages(), where + ".languages");
}

/**
Expand Down
Loading

0 comments on commit a7bd089

Please sign in to comment.