/*
* Copyright 2011 DTO Solutions, Inc. (http://dtosolutions.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* TestFileNodesProviderFactory.java
*
* User: Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
* Created: 7/21/11 9:07 AM
*
*/
package com.dtolabs.rundeck.core.resources;
import com.dtolabs.rundeck.core.common.Framework;
import com.dtolabs.rundeck.core.common.FrameworkProject;
import com.dtolabs.rundeck.core.tools.AbstractBaseTest;
import com.dtolabs.rundeck.core.utils.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
/**
* TestFileNodesProviderFactory is ...
*
* @author Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
*/
public class TestFileResourceModelSourceFactory extends AbstractBaseTest {
public static final String PROJ_NAME = "TestFileNodesProviderFactory";
public TestFileResourceModelSourceFactory(String name) {
super(name);
}
public void setUp() {
super.setUp();
final Framework frameworkInstance = getFrameworkInstance();
final FrameworkProject frameworkProject = frameworkInstance.getFrameworkProjectMgr().createFrameworkProject(
PROJ_NAME);
File resourcesfile = new File(frameworkProject.getNodesResourceFilePath());
//copy test nodes to resources file
try {
FileUtils.copyFileStreams(new File("src/test/resources/com/dtolabs/rundeck/core/common/test-nodes1.xml"),
resourcesfile);
} catch (IOException e) {
throw new RuntimeException("Caught Setup exception: " + e.getMessage(), e);
}
}
public void tearDown() throws Exception {
super.tearDown();
File projectdir = new File(getFrameworkProjectsBase(), PROJ_NAME);
FileUtils.deleteDir(projectdir);
}
public void testCreateNodesProvider() throws Exception {
final FileResourceModelSourceFactory fileNodesProviderFactory = new FileResourceModelSourceFactory(getFrameworkInstance());
{
Properties props = new Properties();
props.put("project", PROJ_NAME);
props.put("file", "src/test/resources/com/dtolabs/rundeck/core/common/test-nodes1.xml");
final ResourceModelSource nodesProvider = fileNodesProviderFactory.createResourceModelSource(props);
assertNotNull(nodesProvider);
}
}
}