-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more ways to configure wsman-cli test system
Besides using the property file to configure the target winrm test system, also allow use of maven properties.
- Loading branch information
Showing
6 changed files
with
179 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
wsman-cli/src/test/java/org/apifocal/wsman/cli/PropfileWinRMFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2016 apifocal. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package org.apifocal.wsman.cli; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Provides WinRM test fixture from a properties file. | ||
*/ | ||
public class PropfileWinRMFixture implements WinRMFixture { | ||
|
||
@Override | ||
public WsmanCli createClient() throws IOException { | ||
//load user configuration | ||
Properties prop = new Properties(); | ||
InputStream is = getClass().getClassLoader().getResourceAsStream("configTests.properties"); | ||
if (is != null) { | ||
prop.load(is); | ||
} else { | ||
throw new FileNotFoundException("tests config file missing"); | ||
} | ||
|
||
WsmanCli cli = new WsmanCli(); | ||
cli.host = prop.getProperty(WINRM_HOST); | ||
cli.port = Integer.parseInt(prop.getProperty(WINRM_PORT)); | ||
cli.user = prop.getProperty(WINRM_USER); | ||
cli.pass = prop.getProperty(WINRM_PASS); | ||
cli.transport = Transport.plaintext; | ||
//cli.cmd = prop.getProperty(WINRM_CMD); | ||
//cli.cmdArgs = Arrays.asList(prop.getProperty(WINRM_CMDARGS).split(" ")); | ||
|
||
return cli; | ||
} | ||
|
||
} |
71 changes: 71 additions & 0 deletions
71
wsman-cli/src/test/java/org/apifocal/wsman/cli/SyspropsWinRMFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2016 apifocal. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package org.apifocal.wsman.cli; | ||
|
||
/** | ||
* Provides WinRM test fixture from a set of Java system properties. | ||
* | ||
* Usage sample: | ||
* | ||
* In pom.xml: | ||
* | ||
* <code> | ||
* <properties> | ||
* <winrm.host>localhost</winrm.host> <!-- some defaults -- > | ||
* <winrm.host>localhost</winrm.host> | ||
* ....... | ||
* </properties> | ||
* ...... | ||
* <plugin> | ||
* <groupId>org.apache.maven.plugins</groupId> | ||
* <artifactId>maven-surefire-plugin</artifactId> | ||
* <configuration> | ||
* <systemProperties> | ||
* <property> | ||
* <name>winrm.host</name> | ||
* <value>${winrm.host}</value> | ||
* </property> | ||
* <property> | ||
* <name>winrm.port</name> | ||
* <value>${winrm.port}</value> | ||
* </property> | ||
* ...... | ||
* </systemProperties> | ||
* </configuration> | ||
* </plugin> | ||
* </code> | ||
* | ||
* Next run it with: | ||
* | ||
* <code>mvn -Dwinrm.host=someHost test </code> | ||
*/ | ||
public class SyspropsWinRMFixture implements WinRMFixture { | ||
|
||
@Override | ||
public WsmanCli createClient() { | ||
WsmanCli cli = new WsmanCli(); | ||
cli.host = System.getProperty(WINRM_HOST); | ||
cli.port = Integer.parseInt(System.getProperty(WINRM_PORT)); | ||
cli.user = System.getProperty(WINRM_USER); | ||
cli.pass = System.getProperty(WINRM_PASS); | ||
cli.transport = Transport.plaintext; | ||
//cli.cmd = prop.getProperty("cmd"); | ||
//cli.cmdArgs = Arrays.asList(prop.getProperty("cmdArgs").split(" ")); | ||
|
||
return cli; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
wsman-cli/src/test/java/org/apifocal/wsman/cli/WinRMFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2016 apifocal. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package org.apifocal.wsman.cli; | ||
|
||
/** | ||
* The WinRM system for tests. | ||
*/ | ||
public interface WinRMFixture { | ||
|
||
// convenience common property names for various config files | ||
public static final String WINRM_HOST = "winrm.host"; | ||
public static final String WINRM_PORT = "winrm.port"; | ||
public static final String WINRM_USER = "winrm.user"; | ||
public static final String WINRM_PASS = "winrm.pass"; | ||
public static final String WINRM_CMD = "winrm.cmd"; | ||
public static final String WINRM_CMDARGS = "winrm.cmdArgs"; | ||
|
||
/** | ||
* Create a configured client for tests. | ||
* @return A configured {@link WsmanCli} | ||
* @throws java.lang.Exception On exceptions | ||
*/ | ||
WsmanCli createClient() throws Exception; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
host=localhost | ||
port=5985 | ||
user=username | ||
pass=password | ||
#cmd=ipconfig | ||
#cmdArgs=/all | ||
winrm.host=localhost | ||
winrm.port=5985 | ||
winrm.user=username | ||
winrm.pass=password | ||
#winrm.cmd=ipconfig | ||
#winrm.cmdArgs=/all |