Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ObjectDataSetDecorator #41

Open
bidorffOL opened this issue Dec 3, 2014 · 2 comments
Open

Add support for ObjectDataSetDecorator #41

bidorffOL opened this issue Dec 3, 2014 · 2 comments

Comments

@bidorffOL
Copy link

Hi,

Looking at DBUnit's documentation, I saw that ReplacementDataSet not only supported String values but also Objects, is any way to see an ObjectDataSetDecorator supported by spring-dbunit in the future ?

From what I saw, its implementation would be quite simple:

public interface ObjectDataSetDecorator {

    Object getObjectToReplace();

    Object getObjectReplacement();
}

As for DbUnitDatabasePopulator.decorateDataSetIfNeeded, it would have to be refactored:

    private IDataSet decorateDataSetIfNeeded(IDataSet dataSet,
            Class<? extends DataSetDecorator>[] decorators,
            Class<? extends ObjectDataSetDecorator>[] objectDecorators) {

        IDataSet resultDataSet = null;

        if (decorators != null && decorators.length > 0) {
            if (resultDataSet == null)
                resultDataSet = new ReplacementDataSet(dataSet);

            for (Class<? extends DataSetDecorator> decoratorClass : decorators) {
                try {
                    DataSetDecorator decorator = decoratorClass.newInstance();
                    resultDataSet.addReplacementSubstring(
                            decorator.getStringToReplace(),
                            decorator.getStringReplacement());
                } catch (InstantiationException e) {
                    LOGGER.error("Could not instantiate DataSetDecorator {}"
                            + decoratorClass, e);
                } catch (IllegalAccessException e) {
                    LOGGER.error("Could not instantiate DataSetDecorator {}"
                            + decoratorClass, e);
                }
            }
        }

        if (objectDecorators != null && objectDecorators.length > 0) {
            if (resultDataSet == null)
                resultDataSet = new ReplacementDataSet(dataSet);

            for (Class<? extends ObjectDataSetDecorator> decoratorClass : objectDecorators) {
                try {
                    ObjectDataSetDecorator decorator = decoratorClass.newInstance();
                    resultDataSet.addReplacementObject(
                            decorator.getObjectToReplace(),
                            decorator.getObjectReplacement());
                } catch (InstantiationException e) {
                    LOGGER.error("Could not instantiate ObjectDataSetDecorator {}"
                            + decoratorClass, e);
                } catch (IllegalAccessException e) {
                    LOGGER.error("Could not instantiate ObjectDataSetDecorator {}"
                            + decoratorClass, e);
                }
            }
        }

        if (resultDataSet == null)
            resultDataSet = dataSet,

        return resultDataSet;
    }

Unfortunalely, I have no experience whatsoever using Git and I fail to send you a pull-request :(

Thank you for considering this feature.

@rsertelon rsertelon self-assigned this Dec 4, 2014
@rsertelon
Copy link
Contributor

Hi, as mentioned in #40 I don't have much time to work on this project right now.

As there are now 2 issues waiting, I will try to find some time. I don't know if it will be before 2015, I'll keep you updated.

@bidorffOL
Copy link
Author

Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants