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

Module Test code to support module setup is correct. #122

Merged
merged 1 commit into from
Jan 18, 2017

Conversation

michael-mclawhorn
Copy link
Contributor

No description provided.

Copy link
Collaborator

@cdeszaq cdeszaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More documentation needed. I think that will clear up much of my confusion. Also, should this live in the fili-system-config module, instead of fili-core, since it seems to be testing system config code?


import spock.lang.Specification

abstract class ModuleSetupSpec extends Specification {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description of what this base spec is for and how to use it would be good.

configurations.stream().map( {it.getString(MODULE_NAME_KEY)}).anyMatch({it.equals(getModuleName())})
}

abstract String getModuleName()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc on this is needed so that usage and contract is clear.

public static final String MODULE_NAME_KEY = "moduleName"
public static final String MODULE_RESOURCE_NAME = "/moduleConfig.properties"

def "Test that SystemConfig loads for this module"() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. "Test that" isn't helpful in the test name.
  2. It would be cool if the module name could be injected into here somehow? Perhaps via a where block that gets it's value from the getModuleName method?


def "Test that SystemConfig loads for this module"() {
expect:
SystemConfig.properties.getOrDefault("foo", "foo") == "foo"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was my first test, it tested that the applicationConfig or some other piece of conflictable-config didn't prevent SystemConfig from working
I'm sure there's a better way to do this.

SystemConfig.properties.getOrDefault("foo", "foo") == "foo"
}

def "Current module is loaded by ConfigResourceLoader"() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to replace "Current module" with an unrolled value from a where block that could source from the getModuleName() method.


def "Current module is loaded by ConfigResourceLoader"() {
setup:
List<Configuration> configurations = new ConfigResourceLoader().loadConfigurations(MODULE_RESOURCE_NAME)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should MODULE_RESOURCE_NAME be fixed or should it be dynamic based on what module is being tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's baked into ModuleLoader as a private constant

List<Configuration> configurations = new ConfigResourceLoader().loadConfigurations(MODULE_RESOURCE_NAME)

expect:
configurations.stream().map( {it.getString(MODULE_NAME_KEY)}).anyMatch({it.equals(getModuleName())})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing inside the calls is a little inconsistent.


class BardModuleSetupSpec extends ModuleSetupSpec {

String getModuleName() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs @Override

Copy link
Collaborator

@cdeszaq cdeszaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Though I still think these classes / tests belong in the system-config module instead of the fili-core module where the currently reside...

*
* @return The name of the module as configured in moduleConfig.properties
*/
abstract String getModuleName()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should move this to higher in the file so that people see this first.

Copy link
Collaborator

@garyluoex garyluoex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good starting point to test modules I guess, we can add more tests later on probably with the module template.

@michael-mclawhorn michael-mclawhorn merged commit 3336ae6 into master Jan 18, 2017
@michael-mclawhorn michael-mclawhorn deleted the ModuleTestCode branch January 20, 2017 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants