/** * @return The default {@link DataSetLoadStrategy} class as configured in unitils */ protected DataSetLoadStrategy getDefaultDataSetLoadStrategy() { Class<? extends DataSetLoadStrategy> dataSetLoadStrategyClassName = getClassWithName(getAnnotationPropertyDefault(DbUnitModule.class, DataSet.class, "loadStrategy", configuration)); return createInstanceOfType(dataSetLoadStrategyClassName, false); }
/** * Initializes this module using the given configuration. * * @param configuration The configuration, not null */ @Override public void init(Properties configuration) { defaultAnnotationPropertyValues = getAnnotationPropertyDefaults(InjectModule.class, configuration, InjectInto.class, InjectIntoStatic.class, InjectIntoByType.class, InjectIntoStaticByType.class); createTestedObjectsIfNullEnabled = PropertyUtils.getBoolean(PROPKEY_CREATE_TESTEDOBJECTS_IF_NULL_ENABLED, configuration); }
/** * @param testClass The test class, not null * @return The test class's custom configuration method, if any */ protected Method getCustomConfigMethod(Class<?> testClass) { Set<Method> annotatedMethods = AnnotationUtils.getMethodsAnnotatedWith(testClass, JpaEntityManagerFactory.class); for (Method annotatedMethod : annotatedMethods) { if (isCustomConfigMethod(annotatedMethod)) { return annotatedMethod; } } return null; }
public static void injectIntoAnnotatedFields(Object objectToInject, Object target, Class<? extends Annotation> annotation) { Set<Field> annotatedFields = AnnotationUtils.getFieldsAnnotatedWith(target.getClass(), annotation); for (Field annotatedField : annotatedFields) { setFieldValue(target, annotatedField, objectToInject); } }
/** * @param configuration The Unitils configuration, not null */ public void init(Properties configuration) { super.init(configuration); String configurationImplClassName = getString(PROPKEY_CONFIGURATION_CLASS_NAME, configuration); configurationObjectClass = ReflectionUtils.getClassWithName(configurationImplClassName); }
protected List<ConversionStrategy<?>> createConversionStrategies(Properties configuration, String propertyName) { List<String> conversionStrategyClassNames = getStringList(propertyName, configuration); List<ConversionStrategy<?>> conversionStrategies = new ArrayList<ConversionStrategy<?>>(conversionStrategyClassNames.size()); for (String conversionStrategyClassName : conversionStrategyClassNames) { ConversionStrategy<?> conversionStrategy = createInstanceOfType(conversionStrategyClassName, false); conversionStrategies.add(conversionStrategy); } return conversionStrategies; } }
protected boolean useScriptFileLastModificationDates() { return PropertyUtils.getBoolean(PROPKEY_USESCRIPTFILELASTMODIFICATIONDATES, configuration); }
/** * Creates the DbUnit dataset operation for loading a data set for the given method. If a value for loadStrategy is found on an * annotation, this class is used, otherwise the configured default class will be used. * * @param testMethod The method, not null * @param testClass The test class, not null * @return The DbUnit operation, not null */ @SuppressWarnings({ "unchecked" }) protected DataSetLoadStrategy getDataSetLoadStrategy(Method testMethod, Class<?> testClass, DataSet dataSet) { Class<? extends DataSetLoadStrategy> dataSetOperationClass = dataSet.loadStrategy(); dataSetOperationClass = (Class<? extends DataSetLoadStrategy>) getClassValueReplaceDefault(DataSet.class, "loadStrategy", dataSetOperationClass, defaultAnnotationPropertyValues, DataSetLoadStrategy.class); return createInstanceOfType(dataSetOperationClass, false); }
/** * Initializes the generator by retrieving the name for the DTD file. * * @param configuration The config, not null */ @Override protected void doInit(Properties configuration) { dtdFileName = PropertyUtils.getString(PROPKEY_DTD_FILENAME, configuration); }
/** * Creates an instance of {@link org.unitils.orm.common.spring.OrmSpringSupport}, that * implements the dependency to the {@link org.unitils.spring.SpringModule}. If the * {@link org.unitils.spring.SpringModule} is not active, or if a dependency of * {@link org.unitils.orm.common.spring.OrmSpringSupport} could not be found in the classpath, * the instance is not loaded. */ protected void initOrmSpringSupport() { if (!isSpringModuleEnabled()) { return; } ormSpringSupport = createInstanceOfType(getOrmSpringSupportImplClassName(), false); }
/** * @param testObject The test object, not null * @param testMethod The test method, not null * @return The {@link TransactionMode} for the given object */ protected TransactionMode getTransactionMode(Object testObject, Method testMethod) { TransactionMode transactionMode = getMethodOrClassLevelAnnotationProperty(Transactional.class, "value", DEFAULT, testMethod, testObject.getClass()); transactionMode = getEnumValueReplaceDefault(Transactional.class, "value", transactionMode, defaultAnnotationPropertyValues); return transactionMode; }
/** * @return The default {@link DataSetFactory} class as configured in unitils */ protected DataSetFactory getDefaultDataSetFactory() { Class<? extends DataSetFactory> dataSetFactoryClass = getClassWithName(getAnnotationPropertyDefault(DbUnitModule.class, DataSet.class, "factory", configuration)); return getDataSetFactory(dataSetFactoryClass); }
/** * Initializes the DbUnitModule using the given Configuration * * @param configuration The config, not null */ @Override @SuppressWarnings("unchecked") public void init(Properties configuration) { this.configuration = configuration; defaultAnnotationPropertyValues = getAnnotationPropertyDefaults(DbUnitModule.class, configuration, DataSet.class, ExpectedDataSet.class); }
/** * Get the configured DataSetFactory for the given method * * @param annotationClass The class of the annotation, i.e. DataSet.class or ExpectedDataSet.class * @param testMethod The method for which we need the configured DataSetFactory * @param testClass The class that is looked for class-level annotations * @return The configured DataSetFactory */ @SuppressWarnings("unchecked") protected DataSetFactory getDataSetFactory(Class<? extends Annotation> annotationClass, Method testMethod, Class<?> testClass) { Class<? extends DataSetFactory> dataSetFactoryClass = getMethodOrClassLevelAnnotationProperty(annotationClass, "factory", DataSetFactory.class, testMethod, testClass); dataSetFactoryClass = (Class<? extends DataSetFactory>) getClassValueReplaceDefault(annotationClass, "factory", dataSetFactoryClass, defaultAnnotationPropertyValues, DataSetFactory.class); return getDataSetFactory(dataSetFactoryClass); }
/** * This method will do the initialization. * * This method checks if the user gives a smtp port otherwise the default smtp port (25) will be used. * * @param configuration : The {@link org.unitils.core.Unitils} configuraiton. * * @see org.unitils.core.Module#init(java.util.Properties) */ @Override public void init(Properties configuration) { port = PropertyUtils.getInt(SMTP_DEFAULT_PORT, 25, configuration); }
/** * @param field The field that declared this mock object, null if there is no field (or not known) * @return The type of the object to inject (i.e. the mocked type), not null. */ public Type getObjectToInjectType(Field field) { if (field == null) { return mockedType; } return getGenericType(field); }
/** * Creates a new instance * * @param persistenceUnitName The name of the persistence unit, as defined in the persistence config file * @param configFile The name of the persistence.xml file. May be null: in this case, we try to find a * persistence.xml file in the default location META-INF/persistence.xml * @param configMethod Custom configuration method, null if not available */ public JpaConfig(String persistenceUnitName, String configFile, Method configMethod) { super(CollectionUtils.asSet(configFile), configMethod); this.persistenceUnitName = persistenceUnitName; }
/** * Initializes the lowest acceptable sequence value using the given configuration object * * @param configuration The config, not null */ @Override protected void doInit(Properties configuration) { lowestAcceptableSequenceValue = PropertyUtils.getLong(PROPKEY_LOWEST_ACCEPTABLE_SEQUENCE_VALUE, configuration); }
/** * All the elements with the @BaseUrlString will be initialised with the base url value of the unitils.properties. * * @param testObject : the testobject. */ public void initBaseUrl(Object testObject) { Set<Field> fields = AnnotationUtils.getFieldsAnnotatedWith(testObject.getClass(), BaseUrl.class); for (Field field : fields) { ReflectionUtils.setFieldValue(testObject, field, baseUrl); } }
/** * Initializes the generator. * * @param configuration The config, not null */ @Override protected void doInit(Properties configuration) { xsdDirectoryName = PropertyUtils.getString(PROPKEY_XSD_DIR_NAME, configuration); complexTypeSuffix = PropertyUtils.getString(PROPKEY_XSD_COMPLEX_TYPE_SUFFIX, configuration); }