Skip to content

Commit

Permalink
Addressing comments from code review.
Browse files Browse the repository at this point in the history
* Removing tabs and whitespaces.
* Adding a readme for generating the mock server keystore.
* Refactoring AdmiralClient a bit.

Change-Id: I6f7a6d75cdd0dbb1d9c434283d8c2b0e5ff4e61d
Reviewed-on: https://bellevue-ci.eng.vmware.com:8080/42309
PG-Verified: jenkins <[email protected]>
Bellevue-Verified: jenkins <[email protected]>
Closures-Verified: jenkins <[email protected]>
Upgrade-Verified: jenkins <[email protected]>
CS-Verified: jenkins <[email protected]>
Reviewed-by: Sergio Sanchez <[email protected]>
  • Loading branch information
martin-borisov committed Aug 22, 2018
1 parent 0e9bc29 commit 1a1ee50
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 167 deletions.
224 changes: 112 additions & 112 deletions test-usecase/pom.xml
Original file line number Diff line number Diff line change
@@ -1,125 +1,125 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.vmware.admiral</groupId>
<artifactId>admiral</artifactId>
<version>1.4.2-SNAPSHOT</version>
</parent>
<parent>
<groupId>com.vmware.admiral</groupId>
<artifactId>admiral</artifactId>
<version>1.4.2-SNAPSHOT</version>
</parent>

<artifactId>admiral-usecase-tests</artifactId>
<artifactId>admiral-usecase-tests</artifactId>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

<!-- Used for passing the admiral uber jar to the unit tests -->
<admiral.uber.jar.local.path>${project.build.directory}/bin</admiral.uber.jar.local.path>
<admiral.uber.jar.name>admiral-uber-jar-with-agent.jar</admiral.uber.jar.name>
</properties>
<!-- Used for passing the admiral uber jar to the unit tests -->
<admiral.uber.jar.local.path>${project.build.directory}/bin</admiral.uber.jar.local.path>
<admiral.uber.jar.name>admiral-uber-jar-with-agent.jar</admiral.uber.jar.name>
</properties>

<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.11.v20180605</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>fluent-hc</artifactId>
<version>4.5.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.11.v20180605</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>fluent-hc</artifactId>
<version>4.5.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>

<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<version>2.0.0.0</version>
<scope>test</scope>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<version>2.0.0.0</version>
<scope>test</scope>
</dependency>

<!-- Needed for running Admiral instances -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>admiral-host</artifactId>
<version>${project.version}</version>
<classifier>uber-jar-with-agent</classifier>
<scope>test</scope>
</dependency>
<!-- Needed for running Admiral instances -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>admiral-host</artifactId>
<version>${project.version}</version>
<classifier>uber-jar-with-agent</classifier>
<scope>test</scope>
</dependency>

</dependencies>
</dependencies>

<build>
<plugins>
<build>
<plugins>

<!--
Copy the Admiral jar to a local directory.
This in theory should also be possible with e.g.
${maven.dependency.com.vmware.admiral.admiral-host.uber-jar-with-agent.jar.path},
but it seems the property is not resolved in the surefire plugin.
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy</id>
<phase>generate-test-resources</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>admiral-host</artifactId>
<classifier>uber-jar-with-agent</classifier>
<overWrite>false</overWrite>
<outputDirectory>${admiral.uber.jar.local.path}</outputDirectory>
<destFileName>${admiral.uber.jar.name}</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</plugin>
<!--
Copy the Admiral jar to a local directory.
This in theory should also be possible with e.g.
${maven.dependency.com.vmware.admiral.admiral-host.uber-jar-with-agent.jar.path},
but it seems the property is not resolved in the surefire plugin.
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy</id>
<phase>generate-test-resources</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>admiral-host</artifactId>
<classifier>uber-jar-with-agent</classifier>
<overWrite>true</overWrite>
<outputDirectory>${admiral.uber.jar.local.path}</outputDirectory>
<destFileName>${admiral.uber.jar.name}</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</plugin>

<!-- Pass the admiral jar to the unit tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Suite.java</include>
</includes>
<systemPropertyVariables>
<admiral.jar.file.path>${admiral.uber.jar.local.path}/${admiral.uber.jar.name}</admiral.jar.file.path>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
<!-- Pass the admiral jar to the unit tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Suite.java</include>
</includes>
<systemPropertyVariables>
<admiral.jar.file.path>${admiral.uber.jar.local.path}/${admiral.uber.jar.name}</admiral.jar.file.path>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -394,18 +394,7 @@ private HttpResponse delete(String path) throws Exception {
Request req = Request.Delete(uri + basePath + path)
.addHeader("Content-Type", "application/json; charset=UTF-8");

switch (kind) {
case VRA:
req.addHeader("Authorization: ", format("{0} {1}", "Bearer ", token));
break;

case XENON:
default:
req.addHeader("x-xenon-auth-token", token);
break;
}

return execute(req).returnResponse();
return execute(addAuthHeader(req)).returnResponse();
}

private HttpResponse post(String path, String payload, Header... headers) throws Exception {
Expand All @@ -420,18 +409,7 @@ private HttpResponse post(String path, String payload, Header... headers) throws
}
}

switch (kind) {
case VRA:
req.addHeader("Authorization: ", format("{0} {1}", "Bearer ", token));
break;

case XENON:
default:
req.addHeader("x-xenon-auth-token", token);
break;
}

return execute(req).returnResponse();
return execute(addAuthHeader(req)).returnResponse();
}

private HttpResponse patch(String path, String payload, Header... headers) throws Exception {
Expand All @@ -446,18 +424,7 @@ private HttpResponse patch(String path, String payload, Header... headers) throw
}
}

switch (kind) {
case VRA:
req.addHeader("Authorization: ", format("{0} {1}", "Bearer ", token));
break;

case XENON:
default:
req.addHeader("x-xenon-auth-token", token);
break;
}

return execute(req).returnResponse();
return execute(addAuthHeader(req)).returnResponse();
}

private HttpResponse put(String path, String payload, Header... headers) throws Exception {
Expand All @@ -472,18 +439,7 @@ private HttpResponse put(String path, String payload, Header... headers) throws
}
}

switch (kind) {
case VRA:
req.addHeader("Authorization: ", format("{0} {1}", "Bearer ", token));
break;

case XENON:
default:
req.addHeader("x-xenon-auth-token", token);
break;
}

return execute(req).returnResponse();
return execute(addAuthHeader(req)).returnResponse();
}

private HttpResponse get(String path, Header... headers) throws Exception {
Expand All @@ -497,9 +453,14 @@ private HttpResponse get(String path, Header... headers) throws Exception {
}
}

return execute(addAuthHeader(req)).returnResponse();
}

private Request addAuthHeader(Request req) {

switch (kind) {
case VRA:
req.addHeader("Authorization", format("{0} {1}", "Bearer", token));
req.addHeader("Authorization: ", format("{0} {1}", "Bearer ", token));
break;

case XENON:
Expand All @@ -508,7 +469,7 @@ private HttpResponse get(String path, Header... headers) throws Exception {
break;
}

return execute(req).returnResponse();
return req;
}

private JsonElement handleResponse(HttpResponse res) throws AdmiralClientException {
Expand Down
19 changes: 19 additions & 0 deletions test-usecase/src/test/resources/environment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generating SSL keys for the mock server

Generate key pair.

```
openssl genrsa -aes128 -out jetty.key
```

Generate certificate from the keys.

```
openssl req -new -x509 -newkey rsa:2048 -sha256 -key jetty.key -out jetty.crt
```

Create a PKCS12 keystore with the private key and certificate.

```
openssl pkcs12 -inkey jetty.key -in jetty.crt -export -out jetty.pkcs12
```
10 changes: 5 additions & 5 deletions tools/build/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
</module>

<module name="TreeWalker">

<!-- Ignored to allow hamcrest style matchers in unit tests -->
<!--
<module name="AvoidStarImport"/>
-->

<module name="UnusedImports">
<property name="processJavadoc" value="true"/>
</module>
Expand All @@ -49,14 +49,14 @@
MOD_ASSIGN,SR_ASSIGN,BSR_ASSIGN,SL_ASSIGN,BXOR_ASSIGN,
BOR_ASSIGN,BAND_ASSIGN,LCURLY,RCURLY"/>
</module>

<module name="OneStatementPerLine"/>

<!-- Ignored to allow for less lines of code mainly in model classes -->
<!--
<module name="MultipleVariableDeclarations"/>
-->

<module name="ArrayTypeStyle"/>
<module name="MissingSwitchDefault"/>
<module name="FallThrough"/>
Expand Down

0 comments on commit 1a1ee50

Please sign in to comment.