Skip to content

Commit 35c0e76

Browse files
authored
Merge pull request #2 from sachinmaske/master
New Annotation DevTestVirtualServiceV3 to deploy VS with V3 API
2 parents 6f0a884 + 10f7639 commit 35c0e76

File tree

158 files changed

+7681
-406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+7681
-406
lines changed

README.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Add below dependency with scope test in your **pom file** :
3434
<dependency>
3535
<groupId>com.ca.devtest.sv.devtools</groupId>
3636
<artifactId>devtest-unit-test-java</artifactId>
37-
<version>1.3.2</version>
37+
<version>1.4.0</version>
3838
</dependency>
3939
4040
----

devtest-unit-test-java/pom.xml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,19 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.ca.devtest.sv.devtools</groupId>
55
<artifactId>devtest-unit-test-java</artifactId>
6-
<version>1.3.2</version>
6+
<version>1.4.0</version>
7+
<build>
8+
<plugins>
9+
<plugin>
10+
<groupId>org.apache.maven.plugins</groupId>
11+
<artifactId>maven-compiler-plugin</artifactId>
12+
<configuration>
13+
<source>1.8</source>
14+
<target>1.8</target>
15+
</configuration>
16+
</plugin>
17+
</plugins>
18+
</build>
719
<name>devtest-unit-test-java</name>
820
<packaging>jar</packaging>
921

@@ -18,11 +30,23 @@ This API will cover same scope as WirMock or MokServer</description>
1830

1931
</properties>
2032
<dependencies>
33+
<dependency>
34+
<groupId>com.fasterxml.jackson.core</groupId>
35+
<artifactId>jackson-databind</artifactId>
36+
<version>2.13.3</version>
37+
</dependency>
2138
<dependency>
2239
<groupId>org.slf4j</groupId>
2340
<artifactId>slf4j-api</artifactId>
2441
<version>1.7.25</version>
2542
</dependency>
43+
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
44+
<dependency>
45+
<groupId>org.slf4j</groupId>
46+
<artifactId>slf4j-simple</artifactId>
47+
<version>1.7.36</version>
48+
<scope>test</scope>
49+
</dependency>
2650
<dependency>
2751
<groupId>org.apache.httpcomponents</groupId>
2852
<artifactId>httpcore</artifactId>
@@ -42,7 +66,7 @@ This API will cover same scope as WirMock or MokServer</description>
4266
<dependency>
4367
<groupId>commons-io</groupId>
4468
<artifactId>commons-io</artifactId>
45-
<version>2.5</version>
69+
<version>2.7</version>
4670
</dependency>
4771
<dependency>
4872
<groupId>org.apache.velocity</groupId>
@@ -52,7 +76,7 @@ This API will cover same scope as WirMock or MokServer</description>
5276
<dependency>
5377
<groupId>org.aeonbits.owner</groupId>
5478
<artifactId>owner</artifactId>
55-
<version>1.0.6</version>
79+
<version>1.0.12</version>
5680
</dependency>
5781
<dependency>
5882
<groupId>com.jayway.jsonpath</groupId>
@@ -62,10 +86,8 @@ This API will cover same scope as WirMock or MokServer</description>
6286
<dependency>
6387
<groupId>junit</groupId>
6488
<artifactId>junit</artifactId>
65-
<version>4.12</version>
89+
<version>4.13.1</version>
6690
</dependency>
67-
68-
6991
</dependencies>
7092

7193
<profiles>

devtest-unit-test-java/settings.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
4+
https://maven.apache.org/xsd/settings-1.0.0.xsd">
5+
<servers>
6+
<server>
7+
<id>photon-releases</id>
8+
<username>${ARTIFACTORY_USER}</username>
9+
<password>${ARTIFACTORY_APIKEY}</password>
10+
<filePermissions>664</filePermissions>
11+
<directoryPermissions>775</directoryPermissions>
12+
<configuration></configuration>
13+
</server>
14+
<server>
15+
<id>plugin-dependencies</id>
16+
<username>${ARTIFACTORY_USER}</username>
17+
<password>${ARTIFACTORY_APIKEY}</password>
18+
<filePermissions>664</filePermissions>
19+
<directoryPermissions>775</directoryPermissions>
20+
<configuration></configuration>
21+
</server>
22+
<!-- To publish a snapshot of your project -->
23+
<server>
24+
<id>snapshot-local</id>
25+
<username>${ARTIFACTORY_USER}</username>
26+
<password>${ARTIFACTORY_APIKEY}</password>
27+
</server>
28+
<!-- To stage a release of your project -->
29+
<server>
30+
<id>release-local</id>
31+
<username>${ARTIFACTORY_USER}</username>
32+
<password>${ARTIFACTORY_APIKEY}</password>
33+
</server>
34+
</servers>
35+
</settings>

devtest-unit-test-java/src/main/java/com/ca/devtest/sv/devtools/DevTestClient.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.ca.devtest.sv.devtools.services.builder.VirtualServiceBuilder;
1414
import com.ca.devtest.sv.devtools.services.builder.VirtualServiceRRPairsBuilder;
1515
import com.ca.devtest.sv.devtools.services.builder.VirtualServiceVSMVSIBuilder;
16+
import com.ca.devtest.sv.devtools.services.builder.v3.VirtualServiceV3Builder;
1617

1718
/**
1819
* @author gaspa03
@@ -26,20 +27,20 @@ public class DevTestClient {
2627
private File rrPairsFolder;
2728
private TransportProtocolDefinitionImpl transportProtocol;
2829

29-
private VirtualServiceBuilder virtualServiceBuilder= null;
30+
private final VirtualServiceBuilder virtualServiceBuilder= null;
3031

3132

3233
// private File zipFile
3334

3435
/**
35-
* @param registryHostName
36-
* @param vseName
3736
* @param userName
3837
* @param password
3938
* @param group
4039
*/
41-
public DevTestClient(String registryHostName, String vseNname, String userName, String password, String group) {
42-
this.vse = new VirtualServiceEnvironment(registryHostName, vseNname,userName,password, group);
40+
public DevTestClient(String proptocol, String registryHostName, String vseNname, String userName, String password,
41+
String group, String keystore, String keystorePassword) {
42+
this.vse = new VirtualServiceEnvironment( proptocol ,registryHostName, vseNname,userName,password,
43+
group, keystore, keystorePassword);
4344
this.virtualServices = new HashMap<String, VirtualService>();
4445
}
4546

@@ -57,7 +58,6 @@ public VirtualServiceBuilder fromRRPairs(String serviceName, File rrPairsFolder)
5758

5859
/**
5960
* @param serviceName
60-
* @param rrPairsFolder
6161
* @return
6262
* @throws IOException
6363
*/
@@ -66,6 +66,10 @@ public VirtualServiceBuilder fromVSMVSI(String serviceName, File workingFolder)
6666
return new VirtualServiceVSMVSIBuilder(serviceName, getVse(), workingFolder);
6767
}
6868

69+
public VirtualServiceV3Builder withV3API(String serviceName, File workingDir){
70+
return new VirtualServiceV3Builder(serviceName, getVse(), workingDir);
71+
}
72+
6973
protected VirtualServiceEnvironment getVse() {
7074
return vse;
7175
}

devtest-unit-test-java/src/main/java/com/ca/devtest/sv/devtools/SVasCodeConfig.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.ca.devtest.sv.devtools;
2+
import com.ca.devtest.sv.devtools.utils.CryptUtil;
23
import org.aeonbits.owner.Config;
34
import org.aeonbits.owner.Config.LoadPolicy;
45
import org.aeonbits.owner.Config.LoadType;
56
import org.aeonbits.owner.Config.Sources;
67

8+
@Config.HotReload(1)
79
@LoadPolicy(LoadType.MERGE)
810
@Sources({"classpath:local-svascode.properties","classpath:svascode.properties"})
11+
@Config.DecryptorClass( CryptUtil.class )
912
public interface SVasCodeConfig extends Config {
1013

1114

@@ -52,6 +55,7 @@ public interface SVasCodeConfig extends Config {
5255
* @return devtest password
5356
*/
5457
@Key("devtest.password")
58+
@EncryptedValue
5559
String password();
5660

5761
/**
@@ -76,6 +80,28 @@ public interface SVasCodeConfig extends Config {
7680
*/
7781
@Key("devtest.embeddedVse")
7882
boolean embeddedVse();
79-
8083

84+
/**
85+
* Keystore
86+
*
87+
* @return return keystore
88+
*/
89+
@Key("devtest.keystore")
90+
String keystore();
91+
92+
/**
93+
* Keystore password
94+
*
95+
* @return return keystore password
96+
*/
97+
@Key("devtest.keystorePassword")
98+
@EncryptedValue
99+
String keystorePassword();
100+
101+
/**
102+
* Undeploy existing Virtual Service
103+
* @return true if existing Virtual Service should be undeplopyed
104+
*/
105+
@Key("devtest.undeploy.ifexists")
106+
String undeployIfExist();
81107
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.ca.devtest.sv.devtools;
2+
3+
import com.ca.devtest.sv.devtools.utils.CryptUtil;
4+
5+
import java.io.File;
6+
import java.io.FileInputStream;
7+
import java.io.FileOutputStream;
8+
import java.io.OutputStream;
9+
import java.io.IOException;
10+
import java.net.URL;
11+
import java.util.Properties;
12+
import java.util.concurrent.atomic.AtomicBoolean;
13+
14+
15+
public class SVasCodeConfigHandler {
16+
public static final String ENCRYPT_VALUES_ENDING_WITH = "password";
17+
public static final String LOCAL_PROPERTY_FILE = "local-svascode.properties";
18+
public static final String DEFAULT_PROPERTY_FILE = "svascode.properties";
19+
public SVasCodeConfigHandler(){
20+
}
21+
22+
/***
23+
* Returns true if properties encryption is successful else returns false
24+
*
25+
* @return boolean value
26+
*/
27+
public boolean encryptProperties(){
28+
boolean localFileModified = modifyPropertyFile(LOCAL_PROPERTY_FILE);
29+
boolean defaultFileModified = modifyPropertyFile(DEFAULT_PROPERTY_FILE);
30+
return localFileModified || defaultFileModified;
31+
}
32+
33+
/***
34+
* Encrypts properties of given file
35+
*
36+
* @param propertyFile
37+
* @return
38+
*/
39+
public boolean modifyPropertyFile(String propertyFile) {
40+
URL url = getClass().getClassLoader().getResource(propertyFile);
41+
if(url == null ){
42+
return false;
43+
}
44+
AtomicBoolean needUpdate= new AtomicBoolean(false);
45+
FileInputStream fis = null;
46+
OutputStream fos = null;
47+
try {
48+
File file = new File(url.toURI());
49+
Properties properties = new Properties();
50+
fis=new FileInputStream(file);
51+
properties.load(fis);
52+
fis.close();
53+
properties.forEach((key, value)-> {
54+
if(key.toString().toLowerCase().endsWith(ENCRYPT_VALUES_ENDING_WITH)){
55+
CryptUtil cryptUtil = new CryptUtil();
56+
if(!cryptUtil.isEncrypted(value.toString())) {
57+
properties.setProperty(key.toString(),cryptUtil.encrypt(value.toString()));
58+
needUpdate.set(true);
59+
}
60+
}
61+
});
62+
if(!needUpdate.get()){
63+
return false;
64+
}
65+
fos = new FileOutputStream(file);
66+
properties.store(fos,"encrypt properties");
67+
}catch (Exception e){
68+
return false;
69+
}finally {
70+
if(fis !=null) {
71+
try {
72+
fis.close();
73+
} catch (IOException e) {
74+
throw new RuntimeException(e);
75+
}
76+
}
77+
if(fos != null) {
78+
try {
79+
fos.close();
80+
} catch (IOException e) {
81+
throw new RuntimeException(e);
82+
}
83+
}
84+
}
85+
return true;
86+
}
87+
}

0 commit comments

Comments
 (0)