@Test
public void testBuildEnvironmentFor() throws Exception {
TreeNodeMetadataValue allShouldBeExposed = new TreeNodeMetadataValue("allExposed", "");
allShouldBeExposed.setExposeToEnvironment(true);
StringMetadataValue exposedParentExposed = new StringMetadataValue(
"exposedParentExposed", "", "exposedParentExposedValue", true);
StringMetadataValue notExposedParentExposed = new StringMetadataValue(
"notExposedParentExposed", "", "notExposedParentExposedValue", false);
allShouldBeExposed.addChild(exposedParentExposed);
allShouldBeExposed.addChild(notExposedParentExposed);
TreeNodeMetadataValue allShouldNotBeExposed = new TreeNodeMetadataValue("notAllExposed", "");
StringMetadataValue exposedParentNotExposed = new StringMetadataValue(
"exposedParentNotExposed", "", "exposedParentNotExposedValue", true);
StringMetadataValue notExposedParentNotExposed = new StringMetadataValue(
"notExposedParentNotExposed", "", "notExposedParentNotExposedValue", false);
allShouldBeExposed.addChild(exposedParentExposed);
allShouldBeExposed.addChild(notExposedParentExposed);
allShouldNotBeExposed.addChild(exposedParentNotExposed);
allShouldNotBeExposed.addChild(notExposedParentNotExposed);
MetadataBuildAction buildAction = new MetadataBuildAction();
buildAction.addChild(allShouldBeExposed);
buildAction.addChild(allShouldNotBeExposed);
AbstractBuild build = mock(AbstractBuild.class);
when(build.getAction(MetadataBuildAction.class)).thenReturn(buildAction);
MetadataEnvironmentContributor contributor = new MetadataEnvironmentContributor();
EnvVars variables = new EnvVars();
contributor.buildEnvironmentFor(build, variables, null);
assertEquals(exposedParentExposed.getValue(), variables.get(exposedParentExposed.getEnvironmentName()));
assertEquals(notExposedParentExposed.getValue(), variables.get(notExposedParentExposed.getEnvironmentName()));
assertEquals(exposedParentNotExposed.getValue(), variables.get(exposedParentNotExposed.getEnvironmentName()));
assertEquals(null, variables.get(notExposedParentNotExposed.getEnvironmentName()));
}