Skip to content
Open
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
29 changes: 29 additions & 0 deletions tck/src/main/java/org/apache/jdo/tck/AbstractReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;
import javax.jdo.JDOFatalInternalException;
import javax.jdo.LegacyJava;
import org.apache.jdo.tck.util.DefaultListableInstanceFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;

/*
Expand Down Expand Up @@ -59,6 +60,22 @@ protected <T> T getBean(
return doPrivileged(() -> factory.getBean(name, clazz));
}

/**
* Get the named bean from the bean factory.
*
* @param factory the bean factory
* @param name the name of the bean
* @return the named object
*/
protected Object getBean(final DefaultListableInstanceFactory factory, final String name) {
return doPrivileged(() -> factory.getBean(name));
}

protected <T> T getBean(
final DefaultListableInstanceFactory factory, Class<T> clazz, final String name) {
return doPrivileged(() -> factory.getBean(name, clazz));
}

@SuppressWarnings("unchecked")
private static <T> T doPrivileged(PrivilegedAction<T> privilegedAction) {
try {
Expand All @@ -67,6 +84,7 @@ private static <T> T doPrivileged(PrivilegedAction<T> privilegedAction) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
e.printStackTrace();
throw new JDOFatalInternalException(e.getMessage());
}
}
Expand All @@ -82,6 +100,17 @@ protected List<Object> getRootList(DefaultListableBeanFactory factory) {
return (List<Object>) getBean(factory, ROOT_NAME);
}

/**
* Get the root object from the bean factory.
*
* @param factory the bean factory
* @return the List of objects
*/
@SuppressWarnings("unchecked")
protected List<Object> getRootList(DefaultListableInstanceFactory factory) {
return (List<Object>) getBean(factory, ROOT_NAME);
}

/**
* Get the named object from the Map of objects.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,47 @@

package org.apache.jdo.tck.pc.company;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import org.apache.jdo.tck.pc.company.data.NavigationTestData;
import org.apache.jdo.tck.pc.company.data.QueryTestData;
import org.apache.jdo.tck.pc.company.data.SampleQueryTestData;
import org.apache.jdo.tck.pc.company.data.SubqueryTestData;
import org.apache.jdo.tck.pc.mylib.MylibReader;
import org.apache.jdo.tck.util.ConversionHelper;
import org.apache.jdo.tck.util.DefaultListableInstanceFactory;
import org.apache.jdo.tck.util.JDOCustomDateEditor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;

/**
* Utility class to create a graph of company model instances from an xml representation.
*
* @author Michael Bouschen
*/
public class CompanyModelReader extends DefaultListableBeanFactory {
public class CompanyModelReader extends DefaultListableInstanceFactory {

private static final long serialVersionUID = 1L;

/** The name of the root list bean. */
public static final String ROOT_LIST_NAME = "root";
public static final String QUERY_TEST = "org/apache/jdo/tck/pc/company/companyForQueryTests.xml";
public static final String MYLIB_TEST = "org/apache/jdo/tck/pc/mylib/mylibForQueryTests.xml";
public static final String SAMPLE_QUERIES_TEST = "org/apache/jdo/tck/pc/company/companyForSampleQueriesTest.xml";
public static final String JDOQL_NAVIGATION_TESTS = "org/apache/jdo/tck/pc/company/companyForNavigationTests.xml";
public static final String JDOQL_SUBQUERIES_TESTS = "org/apache/jdo/tck/pc/company/companyForSubqueriesTests.xml";

/** The bean-factory name in the xml input files. */
public static final String BEAN_FACTORY_NAME = "companyFactory";
public static final String RELATIONSHIPS_ALL = "org/apache/jdo/tck/pc/company/companyAllRelationships.xml";
public static final String RELATIONSHIPS_1_1 = "org/apache/jdo/tck/pc/company/company1-1Relationships.xml";
public static final String RELATIONSHIPS_1_M = "org/apache/jdo/tck/pc/company/company1-MRelationships.xml";
public static final String EMBEDDED = "org/apache/jdo/tck/pc/company/companyEmbedded.xml";
public static final String RELATIONSHIPS_M_M = "org/apache/jdo/tck/pc/company/companyM-MRelationships.xml";
public static final String RELATIONSHIPS_NO = "org/apache/jdo/tck/pc/company/companyNoRelationships.xml";

/** The company factory instance. */
private CompanyFactory companyFactory;

/** Bean definition reader */
private final XmlBeanDefinitionReader reader;
private final CompanyModelReaderOld reader;

/**
* Create a CompanyModelReader for the specified resourceName.
Expand All @@ -65,9 +77,59 @@ public CompanyModelReader(String resourceName) {
*/
public CompanyModelReader(String resourceName, ClassLoader classLoader) {
super();
configureFactory();
this.reader = new XmlBeanDefinitionReader(this);
this.reader.loadBeanDefinitions(new ClassPathResource(resourceName, classLoader));
this.reset();
// configureFactory();
// reader = new CompanyModelReaderOld(resourceName, classLoader);

switch (resourceName) {
case RELATIONSHIPS_ALL:
case RELATIONSHIPS_1_1:
case RELATIONSHIPS_1_M:
case RELATIONSHIPS_M_M:
case RELATIONSHIPS_NO:
case EMBEDDED:
reader = new CompanyModelReaderOld(resourceName, classLoader);
break;
case JDOQL_NAVIGATION_TESTS:
configureFactory();
NavigationTestData.initNavigationTest(companyFactory, this);
reader = null;
break;
case JDOQL_SUBQUERIES_TESTS:
configureFactory();
SubqueryTestData.initSubqueryTest(companyFactory, this);
reader = null;
break;
case QUERY_TEST:
configureFactory();
QueryTestData.initQueryTest(companyFactory, this);
reader = null;
break;
case SAMPLE_QUERIES_TEST:
configureFactory();
SampleQueryTestData.initSampleQueryTest(companyFactory, this);
reader = null;
break;
case MYLIB_TEST:
configureFactory();
// TODO use companyModelFactory!
MylibReader.init(this);
this.reader = null;
break;
default:
reader = new CompanyModelReaderOld(resourceName, classLoader);
// this.reader = null;
System.err.println("ERROR: Not registered: " + resourceName);
//throw new IllegalArgumentException("Not registered: " + resourceName);
}
}


public <T> T getBean(String name, Class<T> clazz) {
if (reader != null) {
return reader.getBean(name, clazz);
}
return super.getBean(name, clazz);
}

/**
Expand All @@ -76,25 +138,36 @@ public CompanyModelReader(String resourceName, ClassLoader classLoader) {
*
* @return a list of root instances
*/
@SuppressWarnings("unchecked")
public List<Object> getRootList() {
return (List<Object>) getBean(ROOT_LIST_NAME);
if (reader != null) {
return reader.getRootList();
}
return super.getRootList();
}

/**
* Configure the CompanyModelReader, e.g. register CustomEditor classes to convert the string
* representation of a property into an instance of the right type.
*/
private void configureFactory() {
registerCustomEditor(Date.class, JDOCustomDateEditor.class);
// registerCustomEditor(Date.class, JDOCustomDateEditor.class);
companyFactory = CompanyFactoryRegistry.getInstance();
addSingleton(BEAN_FACTORY_NAME, companyFactory);
// addSingleton(BEAN_FACTORY_NAME, companyFactory);
}

/**
* @return Returns the tearDownClasses.
*/
public Class<?>[] getTearDownClassesFromFactory() {
if (reader != null) {
return reader.getTearDownClassesFromFactory();
}

for (Class<?> c : companyFactory.getTearDownClasses()) {
System.err.println("TearDownClass: " + c);
}
System.err.println("TearDownClass: " + Arrays.toString(companyFactory.getTearDownClasses()));
this.reset();
return companyFactory.getTearDownClasses();
}

Expand Down
Loading
Loading